Query editor
withswaps as (select*, if(block_time > now() - interval '2' year, true, false) as period_2y, if(block_time > now() - interval '1' year, true, false) as period_1y, if(block_time > now() - interval '6' month, true, false) as period_6m, if(block_time > now() - interval '3' month, true, false) as period_3m, if(cardinality(call_trace_address) = 0, true, false) as direct, row_number() over(partition by user order by block_time, call_trace_address) as user_rnfrom oneinch.swapswhere if('{{blockchain}}' = 'all', true, blockchain = '{{blockchain}}')), agg as (selectupper(split_part(blockchain, '_', 1)) as blockchain, count(*) as swaps_total, count_if(protocol = 'AR') as swaps_ar, count_if(protocol = 'LOP' and not fusion and not contracts_only) as swaps_lop_common, count_if(fusion) as swaps_lop_fusion, count_if(contracts_only) as swaps_lop_rfq, count_if(not contracts_only) as swaps_user, count_if(period_1y) as swaps_1y_total, count_if(period_1y and protocol = 'AR') as swaps_1y_ar, count_if(period_1y and protocol = 'LOP' and not fusion and not contracts_only) as swaps_1y_lop_common, count_if(period_1y and fusion) as swaps_1y_lop_fusion, count_if(period_1y and contracts_only) as swaps_1y_lop_rfq, count_if(period_1y and not contracts_only) as swaps_1y_user, count_if(period_2y and not period_1y) as swaps_1y_p_total, count_if(period_2y and not period_1y and protocol = 'AR') as swaps_1y_p_ar, count_if(period_2y and not period_1y and protocol = 'LOP' and not fusion and not contracts_only) as swaps_1y_p_lop_common, count_if(period_2y and not period_1y and fusion) as swaps_1y_p_lop_fusion, count_if(period_2y and not period_1y and contracts_only) as swaps_1y_p_lop_rfq, count_if(period_2y and not period_1y and not contracts_only) as swaps_1y_p_user, count_if(period_3m) as swaps_3m_total, count_if(period_3m and protocol = 'AR') as swaps_3m_ar, count_if(period_3m and protocol = 'LOP' and not fusion and not contracts_only) as swaps_3m_lop_common, count_if(period_3m and fusion) as swaps_3m_lop_fusion, count_if(period_3m and contracts_only) as swaps_3m_lop_rfq, count_if(period_3m and not contracts_only) as swaps_3m_user, count_if(period_6m and not period_3m) as swaps_3m_p_total, count_if(period_6m and not period_3m and protocol = 'AR') as swaps_3m_p_ar, count_if(period_6m and not period_3m and protocol = 'LOP' and not fusion and not contracts_only) as swaps_3m_p_lop_common, count_if(period_6m and not period_3m and fusion) as swaps_3m_p_lop_fusion, count_if(period_6m and not period_3m and contracts_only) as swaps_3m_p_lop_rfq, count_if(period_6m and not period_3m and not contracts_only) as swaps_3m_p_user, count(distinct user) as accounts_total, count(distinct user) filter(where protocol = 'AR') as accounts_ar, count(distinct user) filter(where protocol = 'LOP' and not fusion and not contracts_only) as accounts_lop_common, count(distinct user) filter(where fusion) as accounts_lop_fusion, count(distinct user) filter(where contracts_only) as accounts_lop_rfq, count(distinct user) filter(where not contracts_only) as accounts_user