Query editor
with xs as (select addr, sym from query_9228665),st as (select * from (values (0x4ae46a509f6b1d9056937ba4500cb143933d2dc8),(0xb6ceceab302e2e4948951ee7843fc24e92933061)) v(a)),d as (select * from dex.trades where blockchain='xlayer' and project='uniswap' and block_month = date '2026-11-01'and block_time >= timestamp '2026-11-08 16:00' and block_time < timestamp '2026-11-22 16:00'and (token_bought_address in (select addr from xs) or token_sold_address in (select addr from xs))),t as (select d.*,case when token_bought_address in (select addr from xs) then token_bought_address else token_sold_address end xa,case when token_bought_address in (select addr from xs) then token_bought_amount else token_sold_amount end xamt,case when token_bought_address in (select addr from xs) then token_sold_address else token_bought_address end oa,case when token_bought_address in (select addr from xs) then token_sold_amount else token_bought_amount end oamt,case when token_bought_address in (select addr from xs) then token_sold_symbol else token_bought_symbol end osym,case when token_bought_address in (select addr from xs) then 'buy' else 'sell' end side,(token_bought_address in (select addr from xs) and token_sold_address in (select addr from xs)) xxfrom d),t2 as (select *, (oa in (select a from st) or osym in ('USD₮0','USDT','USDC','USDG')) ostable from t),ph as (select xa, date_trunc('hour', block_time) h, approx_percentile(oamt/xamt, 0.5) px from t2 where ostable and not xx and xamt>0 and oamt>0.5 group by 1,2),pdy as (select xa, date_trunc('day', block_time) dd, approx_percentile(oamt/xamt, 0.5) px from t2 where ostable and not xx and xamt>0 and oamt>0.5 group by 1,2),r as (select t2.*, xs.sym,case when ostable and not xx then oamt else xamt*coalesce(ph.px, pdy.px) end usd,case when xx then 'xStock-xStock' when ostable then 'stable' when osym in ('xBTC','xETH','xSOL','WOKB','OKB') then 'major' else 'long-tail' end ptype,date(block_time + interval '8' hour) d8,at_timezone(block_time, 'America/New_York') etfrom t2 join xs on xs.addr=t2.xa left join ph on ph.xa=t2.xa and ph.h=date_trunc('hour', t2.block_time) left join pdy on pdy.xa=t2.xa and pdy.dd=date_trunc('day', t2.block_time)),r2 as (select *, case when day_of_week(et) in (6,7) then 'weekend' when (hour(et)*60+minute(et)) between 570 and 959 then 'regular' else 'offhours' end sess from r),fq as (select tx_from, count(distinct tx_hash) ntx from r2 group by 1)select 'tot' part, '-' k1, '-' k2, sum(usd) usd, cast(count(*) as double) n, cast(count(distinct tx_from) as double) n2, cast(count(distinct project_contract_address) as double) n3 from r2union all select 'unpriced', '-', '-', cast(count_if(usd is null) as double), cast(count(*) as double), 0, 0 from r2union all select 'tok', sym, '-', sum(usd), count(*), count(distinct tx_from), count(distinct project_contract_address) from r2 group by 2union all select 'ver', version, '-', sum(usd), count(*), count(distinct tx_from), count(distinct project_contract_address) from r2 group by 2union all select 'ptype', ptype, '-', sum(usd), count(*), count(distinct tx_from), count(distinct project_contract_address) from r2 group by 2union all select 'other', osym, ptype, sum(usd), count(*), count(distinct tx_from), 0 from r2 group by 2,3union all select 'day', cast(d8 as varchar), '-', sum(usd), count(*), count(distinct tx_from), 0 from r2 group by 2union all select 'sess', sess, '-', sum(usd), count(*), count(distinct date_trunc('hour', et)), 0 from r2 group by 2union all select 'pool', lower(to_hex(project_contract_address)), max(sym)||'/'||max(osym)||' v'||max(version), sum(usd), count(*), count(distinct tx_from), approx_percentile(usd,0.5) from r2 group by 2union all select 'size', case when usd<10 then '1 <10' when usd<100 then '2 10-100' when usd<1000 then '3 100-1k' when usd<10000 then '4 1k-10k' else '5 >=10k' end, '-', sum(usd), count(*), 0, 0 from r2 group by 2union all select 'side', side, '-', sum(usd), count(*), 0, 0 from r2 where not xx group by 2union all select 'txto', lower(to_hex(tx_to)), '-', sum(usd), count(*), count(distinct tx_from), count(distinct tx_hash) from r2 group by 2union all select 'freq', case when f.ntx>=280 then 'HF' else 'low' end, '-', sum(usd), count(*), count(distinct r2.tx_from), 0 from r2 join fq f on f.tx_from=r2.tx_from group by 2