Query editor
with b as (select * from dune.okxweb3wallet.result_xl_uni_xs_trades_1109_1122),ob as (select * from b where tx_to = 0x7c5bee2a8091c3ef39072f64f18fac913060aeaf),legs as (select tx_hash, xa tok, sum(xamt) amt from ob group by 1,2 union all select tx_hash, oa, sum(oamt) from ob group by 1,2),lg as (select tx_hash, tok, max(amt) amt from legs group by 1,2),pools as (select distinct pool from b),dec as (select contract_address, decimals from tokens.erc20 where blockchain='xlayer'),tr as (select e.evt_tx_hash, e."to" t, e.contract_address tok, cast(e.value as double)/power(10, coalesce(dec.decimals,18)) vfrom erc20_xlayer.evt_transfer e left join dec on dec.contract_address=e.contract_addresswhere e.evt_block_date >= date '2026-11-08' and e.evt_block_date <= date '2026-11-22' and e.evt_tx_hash in (select distinct tx_hash from ob)),fx as (select tr.evt_tx_hash h, tr.t, tr.v/lg.amt ratio from tr join lg on lg.tx_hash=tr.evt_tx_hash and lg.tok=tr.tok where tr.t not in (select pool from pools) and lg.amt>0),fee as (select h,bool_or(t = 0x7797c4a7f786f77dbce13d71d2c710310cb92aa3 and ratio between 0.001 and 0.005) okxfee,bool_or(t in (0x89d4c1d921cd444b6b049ff6122b171d0bee6dca,0x6652ded658b37ab426689efe0aa091ea19f482d3,0x7fc8fd8bb3192e2d62a3d8d97d9a7924d4bae58b,0x9594b2e6fca5a5e900ae4c3615c6376959bf2a52,0x32fdfc55303263157b91976ae4dee3ddae0e02a9,0xafe1a819eef752318d210d4ed84a16e97c19e8b3,0xbe1d55f69b8c8fded2c87266e2c7f3510a25d05f,0xc57a71fb984b322b0c2afbd92f581773a4a3160e,0x4fec966f98d8530507787d947d1ab24fa145a999,0xa0d75c866ae7e97cffe075b2da78c45399f17777,0x04dd5a0a3c69da1d3debaffe9ccd2e2df9122842,0x39e96a7da66c04215d74b631e3a4fe10a614e4a1,0x4812c22f74076de33c0c145878565d6dd5b619aa,0xf0535b852481a4172a617f27b9bc990bfd633b26,0xf11820a799f368e6a693655166dfb226293654a1,0x3cda2119f653cf0c249e321184d19d745761399c,0x1a265976bdefcdc90e833da91c266f29e60de3d4)and ratio between 0.0004 and 0.03) intfeefrom fx group by 1),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 from ms0 group by 1),lgv 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 pool from pools)),pm as (select pool, max(xa) xa from b group by 1),lpo as (select distinct lgv.tx_from ent, lgv.pool, pm.xa, lgv.ts from lgv join pm on pm.pool=lgv.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,cardinality(array_intersect(array_agg(distinct case when side='buy' then xa end), array_agg(distinct case when side='sell' then xa end))) nboth from 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, coalesce(fee.okxfee,false) okxfee, coalesce(fee.intfee,false) intfee, coalesce(lpf.lp,false) lp, tx.nsw, tx.nboth, fq.ntx,case when b.tx_to = 0x7c5bee2a8091c3ef39072f64f18fac913060aeaf then 'OKX DEX 路由' else '其他合约' end entryfrom b left join ms on ms.h = lower('0x'||to_hex(b.tx_hash)) left join fee on fee.h=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 okxfee then 'C' when intfee then 'C' when c_comp is not null then 'C' when lp then 'L' else 'B' end k3,case when okxfee then 'OKX 钱包' when intfee then '经 OKX DEX API 的收费集成方' when c_comp is not null then c_comp when lp then 'LP' when entry='OKX DEX 路由' then 'OKX DEX API(未收费)' else '自建合约等' end sub,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, sub, 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