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_timeboxfrom query_3298581), swaps as (select*, if(cardinality(call_trace_address) = 0, true, false) as direct, block_time > date_add('second', -(select depth_back_seconds from static), now()) as last_period, row_number() over(partition by blockchain, user order by block_time, call_trace_address) as user_rn_asc, row_number() over(partition by blockchain, 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, row_number() over(partition by swap_id order by block_time) as swap_rnfrom oneinch.swapswhereif('{{blockchain}}' = 'all', true, blockchain = '{{blockchain}}')andcase '{{swap protocol or mode}}'when 'all' then truewhen 'router' then protocol = 'AR'when 'limits' then protocol = 'LOP'when 'fusion' then fusionend), agg as (selectdate_trunc('{{timebox}}', block_time) as time, count_if(not contracts_only) as swaps_total, count_if(not contracts_only and user_timebox_rnk = 1) as swaps_newbies, count_if(protocol = 'AR') as swaps_ar, count_if(protocol = 'AR' and direct) as swaps_ar_direct, count_if(protocol = 'AR' and not direct) as swaps_ar_external, count_if(fusion) as swaps_lop_fusion, count_if(contracts_only) as swaps_lop_rfq, count_if(protocol = 'LOP' and not fusion and not contracts_only) as swaps_lop_common, count(distinct (blockchain, user)) filter(where not contracts_only) as users_total, count(distinct (blockchain, user)) filter(where not contracts_only and user_rn_asc = 1) as users_new, count(distinct (blockchain, user)) filter(where protocol = 'AR') as users_ar, count(distinct (blockchain, user)) filter(where protocol = 'AR' and direct) as users_ar_direct, count(distinct (blockchain, user)) filter(where protocol = 'AR' and not direct) as users_ar_external, count(distinct (blockchain, user)) filter(where fusion) as users_lop_fusion, count(distinct (blockchain, user)) filter(where contracts_only) as users_lop_rfq, count(distinct (blockchain, user)) filter(where protocol = 'LOP' and not fusion and not contracts_only) as users_lop_common, sum(amount_usd) filter(where not contracts_only) as volume_total, sum(amount_usd) filter(where not contracts_only and user_timebox_rnk = 1) as volume_newbies, sum(amount_usd) filter(where protocol = 'AR') as volume_ar, sum(amount_usd) filter(where protocol = 'AR' and direct) as volume_ar_direct, sum(amount_usd) filter(where protocol = 'AR' and not direct) as volume_ar_external, sum(amount_usd) filter(where fusion) as volume_lop_fusion, sum(amount_usd) filter(where contracts_only) as volume_lop_rfq