Query editor
with t as (select block_date, tx_hash, tx_to, evt_index, token_sold_address ts, token_bought_address tb,token_sold_amount sa, token_bought_amount bafrom dex.tradeswhere blockchain = 'base' and block_month >= date '2026-10-01'and block_date >= date '2026-10-26' and block_date < date '2026-12-05'),g as (select block_date, tx_hash, tx_to, count(*) n,array_agg(ts order by evt_index) tss, array_agg(tb order by evt_index) tbs,min_by(sa, evt_index) a_in, max_by(ba, evt_index) a_outfrom t group by 1, 2, 3having count(*) between 2 and 4),c as (select block_date, tx_hash, tx_to, n, tss[1] tok, a_out - a_in dfrom gwhere tss[1] = tbs[n] and tss[1] in (0x4200000000000000000000000000000000000006, 0x833589fcd6edb6e08f4c7c32d4f71b54bda02913)and all_match(sequence(1, n - 1), i -> tbs[i] = tss[i + 1])and a_out > a_in and (a_out - a_in) < 0.5 * a_in),p as (select cast(timestamp as date) d, avg(price) px from prices.daywhere blockchain = 'base' and contract_address = 0x4200000000000000000000000000000000000006and timestamp >= timestamp '2026-10-26'group by 1),v as (select date_trunc('week', c.block_date) wk, c.tx_to bot, c.n,c.d * case when c.tok = 0x833589fcd6edb6e08f4c7c32d4f71b54bda02913 then 1 else p.px end usdfrom c join p on p.d = c.block_date),bw as (select wk, bot, count(*) arbs, sum(usd) usd from v where usd < 50000 group by 1, 2),q as (select *, arbs + coalesce(lag(arbs) over (partition by bot order by wk), 0) arbs14 from bw),r as (select *, row_number() over (partition by wk order by usd desc) rk from q where arbs14 >= 14)select wk, count(*) n_bots, sum(arbs) n_arbs, sum(usd) gross_usd,max(case when rk = 1 then usd end) r1, max(case when rk = 10 then usd end) r10,max(case when rk = 30 then usd end) r30, max(case when rk = 50 then usd end) r50, max(case when rk = 100 then usd end) r100,sum(case when rk <= 5 then usd end) / sum(usd) top5_sharefrom r group by 1 order by 1