Query editor
/** NoteBelow, we grab the fee tier from Swap() event and multiply that with the swap amount (amount_usd from dex.trades) to get the swap feeAlthough it accounts for dynamic fee situation, it does NOT 100% capture the swap feeAs it does NOT account for scnearios of exactInput vs. exactOutput, which need to take differentiate amount0 and amount1 being swappedBut in reality, as usd prices is hard to get, this approximation is good enough and probably the most realistic way to get as an accurate swap fee as possible*/with swap_fees as (select evt_tx_hash, evt_index, evt_block_number, fee / 1e6 as fee_tier, id as pool, 'arbitrum' as chain from uniswap_v4_arbitrum.PoolManager_evt_SwapUNION ALLselect evt_tx_hash, evt_index, evt_block_number, fee / 1e6 as fee_tier, id as pool, 'base' as chain from uniswap_v4_base.PoolManager_evt_SwapUNION ALLselect evt_tx_hash, evt_index, evt_block_number, fee / 1e6 as fee_tier, id as pool, 'polygon' as chain from uniswap_v4_polygon.PoolManager_evt_SwapUNION ALLselect evt_tx_hash, evt_index, evt_block_number, fee / 1e6 as fee_tier, id as pool, 'bnb' as chain from uniswap_v4_bnb.PoolManager_evt_SwapUNION ALLselect evt_tx_hash, evt_index, evt_block_number, fee / 1e6 as fee_tier, id as pool, 'optimism' as chain from uniswap_v4_optimism.PoolManager_evt_SwapUNION ALLselect evt_tx_hash, evt_index, evt_block_number, fee / 1e6 as fee_tier, id as pool, 'avalanche_c' as chain from uniswap_v4_avalanche_c.PoolManager_evt_SwapUNION ALLselect evt_tx_hash, evt_index, evt_block_number, fee / 1e6 as fee_tier, id as pool, 'worldchain' as chain from uniswap_v4_worldchain.PoolManager_evt_SwapUNION ALLselect evt_tx_hash, evt_index, evt_block_number, fee / 1e6 as fee_tier, id as pool, 'zora' as chain from uniswap_v4_zora.PoolManager_evt_SwapUNION ALLselect evt_tx_hash, evt_index, evt_block_number, fee / 1e6 as fee_tier, id as pool, 'blast' as chain from uniswap_v4_blast.PoolManager_evt_SwapUNION ALLselect evt_tx_hash, evt_index, evt_block_number, fee / 1e6 as fee_tier, id as pool, 'ethereum' as chain from uniswap_v4_ethereum.PoolManager_evt_SwapUNION ALLselect evt_tx_hash, evt_index, evt_block_number, fee / 1e6 as fee_tier, id as pool, 'ink' as chain from uniswap_v4_ink.PoolManager_evt_SwapUNION ALLselect evt_tx_hash, evt_index, evt_block_number, fee / 1e6 as fee_tier, id as pool, 'unichain' as chain from uniswap_v4_unichain.PoolManager_evt_Swap)-- select * from swap_fees, base as (select f.*, t.block_date, t.amount_usd as swap_amount_usd, cast(t.amount_usd as double) * cast(f.fee_tier as double) as swap_fee_usdfrom swap_fees fjoin dex.trades t on t.block_number = f.evt_block_numberand t.blockchain = f.chainand t.tx_hash = f.evt_tx_hashand t.evt_index = f.evt_index)select chain, block_date, sum(swap_fee_usd) as total_swap_fee_usdfrom basegroup by 1,2