Query editor
WITH DPX_additions AS (WITH l1 as (SELECTtr.evt_tx_hash as hash,tr.evt_block_time as time,cast(tr.value as double)/1e18 * p.price as DPX_amount_USD --summing because two different additions in each txnFROM erc20_arbitrum.evt_Transfer trLEFT JOIN prices.usd p ON date_trunc('minute', p.minute) = date_trunc('minute', tr.evt_block_time) AND p.contract_address = 0x6C2C06790b3E3E3c38e12Ee22F8183b37a13EE55 AND p.blockchain = 'arbitrum'WHERE tr.contract_address = 0x6C2C06790b3E3E3c38e12Ee22F8183b37a13EE55 --DPX token contract addressAND tr."to" = 0x0C1Cf6883efA1B496B01f654E247B9b419873054 --DPX/WETH pool sushiswap addressAND tr.evt_tx_hash IN (--inside of the parantheses your transactionsselectcall_tx_hashfrom jones_token_arbitrum.DpxEthBullVault_call_autoCompound))select * from l1 whereDPX_amount_USD in (Select min(DPX_amount_USD) FROM l1 group by hash) -- -- by this line, we are selecting one of DPX_additions for each txn, (which is less one)),WETH_additions AS (SELECTtr.evt_tx_hash as hash,tr.evt_block_time as time,cast(tr.value as double)/1e18 * p.price as WETH_amount_USDFROM erc20_arbitrum.evt_Transfer trLEFT JOIN prices.usd p ON date_trunc('minute', p.minute) = date_trunc('minute', tr.evt_block_time) AND p.contract_address = 0x82aF49447D8a07e3bd95BD0d56f35241523fBab1 AND p.blockchain = 'arbitrum'WHERE tr.contract_address = 0x82aF49447D8a07e3bd95BD0d56f35241523fBab1 --WETH token contract addressAND tr."to" = 0x0C1Cf6883efA1B496B01f654E247B9b419873054 --DPX/WETH pool sushiswap addressAND tr.evt_tx_hash IN (--inside of the parantheses your transactionsselectcall_tx_hashfrom jones_token_arbitrum.DpxEthBullVault_call_autoCompound)),gas AS (SELECTatr.hash as hash,atr.block_time,cast(atr.gas_used as double)/1e10 * p.price as gas_USDFROM arbitrum.transactions atrLEFT JOIN prices.usd p ON date_trunc('minute', p.minute) = date_trunc('minute', atr.block_time) AND p.contract_address = 0x82aF49447D8a07e3bd95BD0d56f35241523fBab1 AND p.blockchain = 'arbitrum'WHERE atr.hash IN (selectcall_tx_hashfrom jones_token_arbitrum.DpxEthBullVault_call_autoCompound))SELECTdpx.hash as hash,weth.time as time,dpx.DPX_amount_USD + weth.WETH_amount_USD AS total_addition_USD,g.gas_USD as gas_in_USDFROM DPX_additions dpxLEFT JOIN WETH_additions weth ON dpx.hash = weth.hashLEFT JOIN gas g ON dpx.hash = g.hash