Query editor
with b as (select * from dune.okxweb3wallet.result_xl_uni_xs_trades_1109_1122),ms0 as (select lower(tx_hash) h, competitor, platform_type from dune.okxweb3wallet.fct_ms_trades_part1 where chain='xlayer' and block_time >= timestamp '2026-11-08 00:00' and block_time < timestamp '2026-11-24 00:00'union all select lower(tx_hash), competitor, platform_type from dune.okxweb3wallet.fct_ms_trades_part2 where chain='xlayer' and block_time >= timestamp '2026-11-08 00:00' and block_time < timestamp '2026-11-24 00:00'),ms as (select h, max(case when platform_type in ('C_End','ALL') then competitor end) c_comp, max(case when platform_type='B_End' then competitor end) b_comp from ms0 group by 1),lg as (select tx_from, contract_address pool, to_unixtime(block_time) ts from xlayer.logswhere block_date >= date '2026-11-07' and block_date <= date '2026-11-23'and topic0 in (0x7a53080ba414158be7ec69b987b5fb7d07dee101fe85488f0853ae16239d0bde, 0x0c396cd989a39f4459b5fa1aed6a9a8dcdbc45908acfd67e028cd568da98982c)and contract_address in (select distinct pool from b)),pm as (select pool, max(xa) xa from b group by 1),lpo as (select distinct lg.tx_from ent, lg.pool, pm.xa, lg.ts from lg join pm on pm.pool=lg.pool),lpb as (select ent, pool, xa, ts, floor(ts/600)+d bk from lpo cross join unnest(array[-1,0,1]) as v(d)),bt as (select tx_hash, evt_index, tx_from, pool, xa, to_unixtime(block_time) ts from b where tx_from in (select ent from lpo)),lpf as (select bt.tx_hash, bt.evt_index, bool_or(abs(bt.ts-lpb.ts)<=600 and (lpb.pool=bt.pool or lpb.xa=bt.xa)) lpfrom bt join lpb on lpb.ent=bt.tx_from and lpb.bk=floor(bt.ts/600) group by 1,2),tx as (select tx_hash, count(*) nsw, count(distinct pool) npool,cardinality(array_intersect(array_agg(distinct case when side='buy' then xa end), array_agg(distinct case when side='sell' then xa end))) nbothfrom b group by 1),fq as (select tx_from, count(distinct tx_hash) ntx from b group by 1),c as (select b.*, ms.c_comp, ms.b_comp, coalesce(lpf.lp,false) lp, tx.nsw, tx.nboth, fq.ntx,case when b.tx_to = 0x7c5bee2a8091c3ef39072f64f18fac913060aeaf then 'OKX DEX 路由' when b.tx_to = b.pool then '直调池子' else '其他合约' end entryfrom b left join ms on ms.h = lower('0x'||to_hex(b.tx_hash)) left join lpf on lpf.tx_hash=b.tx_hash and lpf.evt_index=b.evt_indexjoin tx on tx.tx_hash=b.tx_hash join fq on fq.tx_from=b.tx_from),k as (select *, case when c_comp is not null then 'C' when lp then 'L' else 'B' end k3,case when nboth>0 then 'cycle' when nsw>=2 then 'multi' else 'single' end intent,case when ntx>=280 then 'HF' else 'low' end hf from c)select k3, coalesce(c_comp, b_comp, '-') comp, entry, intent, hf, ptype, sym, sum(usd) usd, count(*) n, count(distinct tx_from) naddr, count(distinct tx_hash) ntxfrom k group by 1,2,3,4,5,6,7