Query editor
withpools as (SELECT * FROM query_3087382), sell_nft_base as (SELECT'sell' as trade_category,sp_start.call_trace_address_filled as swap_trace_address,sp.call_trace_address as info_trace_address,roy.call_trace_address as royalty_call_trace_address,sp.numItems,sp_start.nftIds,sp.output_protocolFee/(sp.protocolFeeMultiplier/1e18) as spotPrice --sp.spotPrice --for some reason spot price is sometimes inaccurate? https://explorer.phalcon.xyz/tx/eth/0x20f4cf9aecae7d26ee170fbbf8017fb290bc6ce0caeae30ad2ae085d214d04d3,sp.feeMultiplier,sp.protocolFeeMultiplier,sp.output_tradeFee,sp.output_protocolFee,COALESCE(case when cardinality(roy.output_1) = 0 then null else roy.output_1[1] end,cast(0 as uint256)) as royalty_fee_amount_raw,p.token,p.nft_type,p.nft_contract_address,p.pool_type,p.bonding_curve_type,p.pool_address,sp.call_tx_hash,sp.call_block_timeFROM (SELECT*--need this for a clean join below on trace_address, since top level calls are empty for trace address, case when cardinality(call_trace_address) = 0 then array[0] else call_trace_address end as call_trace_address_filledFROM sudoswap_v2_ethereum.LSSVMPair_call_swapNFTsForToken) sp_startLEFT JOIN (--each curve calculates info with all the data we need before a swap.SELECT * FROM sudoswap_v2_ethereum.ExponentialCurve_call_getSellInfoUNION ALLSELECT * FROM sudoswap_v2_ethereum.LinearCurve_call_getSellInfoUNION ALLSELECT * FROM sudoswap_v2_ethereum.XykCurve_call_getSellInfoUNION ALLSELECT * FROM sudoswap_v2_ethereum.GDACurve_call_getSellInfo) sp ON sp_start.call_tx_hash = sp.call_tx_hashAND sp_start.call_block_number = sp.call_block_numberAND sp_start.call_trace_address_filled = slice(sp.call_trace_address,1,cardinality(sp_start.call_trace_address_filled))--royalty is only called once per NFT contract, even if there are multiple token idsLEFT JOIN sudoswap_v2_ethereum.RoyaltyEngine_call_getRoyalty royON roy.call_tx_hash = sp.call_tx_hashAND roy.call_block_number = sp.call_block_numberAND sp_start.call_trace_address_filled = slice(roy.call_trace_address,1,cardinality(sp_start.call_trace_address_filled))AND cardinality(roy.output_0) is not null --ignore if no royalty returned.LEFT JOIN pools p ON p.pool_address = sp_start.contract_address-- WHERE sp.contract_address = 0xcdb8f114d2fb28a4b85bb1ab6e09444006ef5385-- WHERE sp_start.call_tx_hash = 0x20f4cf9aecae7d26ee170fbbf8017fb290bc6ce0caeae30ad2ae085d214d04d3), buy_nft_base as (SELECT'buy' as trade_category