Query editor
with xs as (select addr, sym from query_9228665),u 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 12:00' and block_time < timestamp '2026-11-22 20:00'),stb as (select * from (values (0x4ae46a509f6b1d9056937ba4500cb143933d2dc8),(0xb6ceceab302e2e4948951ee7843fc24e92933061)) v(a)),legs as (select token_bought_address tk, token_bought_amount ta, token_sold_amount sa, block_time from u where (token_sold_address in (select a from stb) or token_sold_symbol='USD₮0') and token_bought_amount>0 and token_sold_amount>0.5union all select token_sold_address, token_sold_amount, token_bought_amount, block_time from u where (token_bought_address in (select a from stb) or token_bought_symbol='USD₮0') and token_sold_amount>0 and token_bought_amount>0.5),ph as (select tk, date_trunc('hour', block_time) h, approx_percentile(sa/ta, 0.5) px from legs group by 1,2),pdy as (select tk, date_trunc('day', block_time) dd, approx_percentile(sa/ta, 0.5) px from legs group by 1,2),d as (select * from u where 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.*,(token_bought_address in (select addr from xs)) xb,(token_bought_address in (select addr from xs) and token_sold_address in (select addr from xs)) xx from d),t2 as (select block_time, tx_hash, evt_index, version, project_contract_address pool, tx_from, tx_to, taker,case when xb then token_bought_address else token_sold_address end xa,case when xb then token_bought_amount else token_sold_amount end xamt,case when xb then token_sold_address else token_bought_address end oa,case when xb then token_sold_amount else token_bought_amount end oamt,case when xb then token_sold_symbol else token_bought_symbol end osym,case when xb then 'buy' else 'sell' end side, xx, amount_usd from t),r as (select t2.*, xs.sym,(t2.oa in (select a from stb) or t2.osym='USD₮0') ost,coalesce(case when (t2.oa in (select a from stb) or t2.osym='USD₮0') then t2.oamt end, t2.xamt*p1.px, t2.oamt*p2.px, t2.xamt*q1.px, t2.oamt*q2.px, t2.amount_usd) usdfrom t2 join xs on xs.addr=t2.xaleft join ph p1 on p1.tk=t2.xa and p1.h=date_trunc('hour',t2.block_time)left join ph p2 on p2.tk=t2.oa and p2.h=date_trunc('hour',t2.block_time)left join pdy q1 on q1.tk=t2.xa and q1.dd=date_trunc('day',t2.block_time)left join pdy q2 on q2.tk=t2.oa and q2.dd=date_trunc('day',t2.block_time))select block_time, tx_hash, evt_index, version, pool, tx_from, tx_to, taker, xa, sym, xamt, oa, osym, oamt, side, xx,case when xx then 'xStock-xStock' when ost then 'stable' when osym in ('xBTC','xETH','xSOL','WOKB','OKB') then 'major' else 'long-tail' end ptype,usd from r