Query editor
withstatic as (selectbegin['{{blockchain}}'] as ts_from, date_trunc('{{timebox}}', timestamp '{{displayed period from}}') as displayed_from, depth['{{timebox}}'] as depth_back_seconds, to_unixtime(next['{{timebox}}']) - to_unixtime(now()) as seconds_left_in_timebox, split('{{blockchain}}', ',') as blockchains, split('{{swap mode}}', ',') as modesfrom query_3298581), swaps as (select*, block_time > date_add('second', -static.depth_back_seconds, now()) as last_period, row_number() over(partition by user order by block_time, call_trace_address) as user_rn_asc, row_number() over(partition by user order by block_time desc, call_trace_address) as user_rn_desc, rank() over(partition by user order by date_trunc('{{timebox}}', block_time)) as user_timebox_rnk, coalesce(element_at(flags, 'first'), true) as first_executionfrom 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, array_position(static.blockchains, blockchain) > 0)and if(array_position(static.modes, '= all =') > 0, true, array_position(static.modes, mode) > 0)), agg as (selectdate_trunc('{{timebox}}', block_time) as time, count_if(first_execution and not coalesce(element_at(flags, 'contracts_only'), false)) as swaps_total, count_if(first_execution and not coalesce(element_at(flags, 'contracts_only'), false) and user_timebox_rnk = 1) as swaps_newbies, count_if(first_execution and (protocol = 'AR' or coalesce(element_at(flags, 'second_side'), false))) as swaps_ar, count_if(first_execution and (protocol = 'AR' or coalesce(element_at(flags, 'second_side'), false)) and coalesce(element_at(flags, 'direct'), false)) as swaps_ar_direct, count_if(first_execution and (protocol = 'AR' or coalesce(element_at(flags, 'second_side'), false)) and not coalesce(element_at(flags, 'direct'), false)) as swaps_ar_external, count_if(first_execution and coalesce(element_at(flags, 'fusion'), false)) as swaps_lop_fusion, count_if(first_execution and coalesce(element_at(flags, 'cross_chain'), false)) as swaps_lop_cross_chain, count_if(first_execution and coalesce(element_at(flags, 'contracts_only'), false)) as swaps_lop_rfq, count_if(first_execution and protocol = 'LO' and not coalesce(element_at(flags, 'fusion'), false) and not coalesce(element_at(flags, 'contracts_only'), false) and not coalesce(element_at(flags, 'second_side'), false)) as swaps_lop_common, count(distinct user) filter(where not coalesce(element_at(flags, 'contracts_only'), false)) as users_total, count(distinct user) filter(where not coalesce(element_at(flags, 'contracts_only'), false) and user_rn_asc = 1) as users_new, count(distinct user) filter(where (protocol = 'AR' or coalesce(element_at(flags, 'second_side'), false))) as users_ar, count(distinct user) filter(where (protocol = 'AR' or coalesce(element_at(flags, 'second_side'), false)) and coalesce(element_at(flags, 'direct'), false)) as users_ar_direct, count(distinct user) filter(where (protocol = 'AR' or coalesce(element_at(flags, 'second_side'), false)) and not coalesce(element_at(flags, 'direct'), false)) as users_ar_external, count(distinct user) filter(where coalesce(element_at(flags, 'fusion'), false)) as users_lop_fusion, count(distinct user) filter(where coalesce(element_at(flags, 'cross_chain'), false)) as users_lop_cross_chain, count(distinct user) filter(where coalesce(element_at(flags, 'contracts_only'), false)) as users_lop_rfq, count(distinct user) filter(where protocol = 'LO' and not coalesce(element_at(flags, 'fusion'), false) and not coalesce(element_at(flags, 'contracts_only'), false) and not coalesce(element_at(flags, 'second_side'), false)) as users_lop_common, sum(amount_usd) filter(where not coalesce(element_at(flags, 'contracts_only'), false)) as volume_total, sum(amount_usd) filter(where not coalesce(element_at(flags, 'contracts_only'), false) and user_timebox_rnk = 1) as volume_newbies, sum(amount_usd) filter(where (protocol = 'AR' or coalesce(element_at(flags, 'second_side'), false))) as volume_ar, sum(amount_usd) filter(where (protocol = 'AR' or coalesce(element_at(flags, 'second_side'), false)) and coalesce(element_at(flags, 'direct'), false)) as volume_ar_direct, sum(amount_usd) filter(where (protocol = 'AR' or coalesce(element_at(flags, 'second_side'), false)) and not coalesce(element_at(flags, 'direct'), false)) as volume_ar_external, sum(amount_usd) filter(where coalesce(element_at(flags, 'fusion'), false)) as volume_lop_fusion