Query editor
-- Calculates metrics based on the project of the top layer of a transaction, regardless of whether it routes through other dex aggregatorswithstatic as (selectsplit('{{blockchain}}', ',') as blockchains, '{{date_granularity}}' as date_granularity, (select start_date['{{period}}'] from "query_5633784") as start_date)-- All Fusion txs are in dex_aggregator.trades but tagged as 1inch, fusion_txs as (select distincttx_hash, blockchain, '1inch fusion' as projectfrom oneinch.swaps, staticwherecoalesce(element_at(flags, 'fusion'), false) = trueand block_time >= static.start_dateand if(array_position(static.blockchains, '-=All=-') > 0, true, array_position(static.blockchains, blockchain) > 0))-- Some, not all uniswap x txs are in dex_aggregator.trades, uniswap_x_txs as (select *from "query_5602624(period='{{period}}')", staticwhere if(array_position(static.blockchains, '-=All=-') > 0, true, array_position(static.blockchains, blockchain) > 0))-- Separate 1inch from fusion and remove uniswap X txs for now, dex_agg_trades_prep as (selectt.block_time,t.blockchain,t.tx_hash,t.evt_index,t.trace_address,lower(coalesce(f.project, if(t.project='1inch', '1inch (excl. Fusion)', t.project))) as project,t.amount_usd,t.token_sold_symbol,t.token_bought_symbol,t.token_sold_amount,t.token_bought_amount,t.taker as trader,static.date_granularityfrom dex_aggregator.trades as tcross join staticleft join fusion_txs as fon t.tx_hash = f.tx_hashand t.blockchain = f.blockchainleft join uniswap_x_txs as uon t.tx_hash = u.tx_hashand t.blockchain = u.blockchainwheret.block_time >= static.start_dateand if(array_position(static.blockchains, '-=All=-') > 0, true, array_position(static.blockchains, t.blockchain) > 0)and u.tx_hash is nulland t.amount_usd < 1e9 -- filtering out all trades more than 1b dollars, which are probably just due to bogus prices)-- Only keep project with earliest trace_address for each tx, dex_agg_trades_prep_2 as (select *from (