Query editor
withstatic as (selectperiod['{{selected period}}'] as period, split('{{swap mode}}', ',') as modes, split('{{blockchain}}', ',') as blockchainsfrom query_3298581), 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 (selectswaps.*, block_time > now() - static.period - interval '1' hour as period, 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 block_time > now() - 2 * static.period - interval '1' hourand 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, array_position(static.modes, mode) > 0)), agg as (selectupper(split_part(blockchain, '_', 1)) as blockchain, count_if(first_execution and period and not coalesce(element_at(flags, 'contracts_only'), false)) as swaps_period_total, count_if(first_execution and period and coalesce(element_at(flags, 'direct'), false) and not coalesce(element_at(flags, 'contracts_only'), false)) as swaps_period_direct, count_if(first_execution and period and user_rn = 1 and not coalesce(element_at(flags, 'contracts_only'), false)) as swaps_period_beginners, count_if(first_execution and period and protocol = 'AR') as swaps_period_router, count_if(first_execution and period and protocol = 'LO' and not coalesce(element_at(flags, 'fusion'), false) and not coalesce(element_at(flags, 'contracts_only'), false)) as swaps_period_user_limits, count_if(first_execution and period and coalesce(element_at(flags, 'fusion'), false)) as swaps_period_fusion, count_if(first_execution and period and coalesce(element_at(flags, 'contracts_only'), false)) as swaps_period_rfq_limits, count_if(first_execution and period and coalesce(element_at(flags, 'cross_chain'), false) and dst_blockchain is not null) as swaps_period_cross_chain, count_if(first_execution and not period and not coalesce(element_at(flags, 'contracts_only'), false)) as swaps_previous_total, count_if(first_execution and not period and coalesce(element_at(flags, 'direct'), false) and not coalesce(element_at(flags, 'contracts_only'), false)) as swaps_previous_direct, count_if(first_execution and not period and user_rn = 1 and not coalesce(element_at(flags, 'contracts_only'), false)) as swaps_previous_beginners, count_if(first_execution and not period and protocol = 'AR') as swaps_previous_router, count_if(first_execution and not period and protocol = 'LO' and not coalesce(element_at(flags, 'fusion'), false) and not coalesce(element_at(flags, 'contracts_only'), false)) as swaps_previous_user_limits, count_if(first_execution and not period and coalesce(element_at(flags, 'fusion'), false)) as swaps_previous_fusion, count_if(first_execution and not period and coalesce(element_at(flags, 'contracts_only'), false)) as swaps_previous_rfq_limits, count_if(first_execution and not period and coalesce(element_at(flags, 'cross_chain'), false) and dst_blockchain is not null) as swaps_previous_cross_chain, count(distinct user) filter(where period and not coalesce(element_at(flags, 'contracts_only'), false)) as users_period_total