Query editor
withstatic as (selectsplit('{{blockchain}}', ',') as blockchains, split('{{swap mode}}', ',') as modes), decimals as (selectupper(split_part(blockchain, '_', 1)) as blockchain, native_token_symbol, max(decimals) as decimalsfrom tokens.erc20join (select blockchain, wrapped_native_token_address as contract_address, native_token_symbol from oneinch.blockchains) using(blockchain, contract_address)group by blockchain, native_token_symbol), swaps as (select*, row_number() over(partition by user order by block_time, call_trace_address) as user_rn, coalesce(element_at(flags, 'first'), true) as first_execution-- , get_href(get_chain_explorer_tx_hash(blockchain, (cast(tx_hash as varchar))), concat(cast(substr(tx_hash, 1, 2) as varchar), '…', substr(cast(tx_hash as varchar), 63))) as tx_linkfrom oneinch.swaps, staticwheretrueand tx_success and call_successand not coalesce(element_at(flags, 'second_side'), false)and if(array_position(static.blockchains, '= all =') > 0, true, cardinality(array_intersect(array[blockchain], static.blockchains)) > 0)and if(array_position(static.modes, '= all =') > 0, true, cardinality(array_intersect(array['', if(protocol = 'AR' or flags['second_side'], 'classic'), if(protocol = 'LOP' and not coalesce(element_at(flags, 'fusion'), false) and not coalesce(element_at(flags, 'cross_chain'), false), 'limits'), if(coalesce(element_at(flags, 'fusion'), false), 'fusion'), if(coalesce(element_at(flags, 'cross_chain'), false) and dst_blockchain is not null, 'fusion+')], static.modes)) > 0)), agg as (selectupper(split_part(blockchain, '_', 1)) as blockchain, count_if(first_execution and not coalesce(element_at(flags, 'contracts_only'), false)) as swaps_total, count_if(first_execution and coalesce(element_at(flags, 'direct'), false) and not coalesce(element_at(flags, 'contracts_only'), false)) as swaps_direct, count_if(first_execution and protocol = 'AR') as swaps_router, count_if(first_execution and protocol = 'LOP' and not coalesce(element_at(flags, 'fusion'), false) and not coalesce(element_at(flags, 'contracts_only'), false)) as swaps_user_limits, count_if(first_execution and coalesce(element_at(flags, 'fusion'), false)) as swaps_fusion, count_if(first_execution and coalesce(element_at(flags, 'contracts_only'), false)) as swaps_rfq_limits, count_if(first_execution and coalesce(element_at(flags, 'cross_chain'), false) and dst_blockchain is not null) as swaps_cross_chain, count(distinct user) filter(where not coalesce(element_at(flags, 'contracts_only'), false)) as users_total, count(distinct user) filter(where coalesce(element_at(flags, 'direct'), false) and not coalesce(element_at(flags, 'contracts_only'), false)) as users_direct, count(distinct user) filter(where protocol = 'AR') as users_router, count(distinct user) filter(where protocol = 'LOP' and not coalesce(element_at(flags, 'fusion'), false) and not coalesce(element_at(flags, 'contracts_only'), false)) as users_user_limits, count(distinct user) filter(where coalesce(element_at(flags, 'fusion'), false)) as users_fusion, count(distinct user) filter(where coalesce(element_at(flags, 'contracts_only'), false)) as users_rfq_limits, count(distinct user) filter(where coalesce(element_at(flags, 'cross_chain'), false) and dst_blockchain is not null) as users_cross_chain, sum(amount_usd) filter(where not coalesce(element_at(flags, 'contracts_only'), false)) as volume_total, sum(amount_usd) filter(where coalesce(element_at(flags, 'direct'), false) and not coalesce(element_at(flags, 'contracts_only'), false)) as volume_direct