Query editor
with t as (select block_date, tx_hash, tx_to, evt_index,case when token_sold_address in (0x0000000000000000000000000000000000000000, 0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee) then 0x4200000000000000000000000000000000000006 else token_sold_address end ts,case when token_bought_address in (0x0000000000000000000000000000000000000000, 0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee) then 0x4200000000000000000000000000000000000006 else token_bought_address end tb,token_sold_amount sa, token_bought_amount bafrom dex.tradeswhere blockchain = 'base'and block_month in (date '2025-01-01',date '2025-02-01',date '2025-03-01',date '2025-04-01',date '2025-05-01',date '2025-06-01',date '2025-07-01',date '2025-08-01',date '2025-09-01',date '2025-10-01',date '2025-11-01',date '2025-12-01',date '2026-01-01',date '2026-02-01',date '2026-03-01',date '2026-04-01',date '2026-05-01',date '2026-06-01',date '2026-07-01',date '2026-08-01',date '2026-09-01',date '2026-10-01',date '2026-11-01',date '2026-12-01')and block_date in (date '2025-01-08',date '2025-01-29',date '2025-02-19',date '2025-03-12',date '2025-04-02',date '2025-04-23',date '2025-05-14',date '2025-06-04',date '2025-06-25',date '2025-07-16',date '2025-08-06',date '2025-08-27',date '2025-09-17',date '2025-10-08',date '2025-10-29',date '2025-11-19',date '2025-12-10',date '2025-12-31',date '2026-01-21',date '2026-02-11',date '2026-03-04',date '2026-03-25',date '2026-04-15',date '2026-05-06',date '2026-05-27',date '2026-06-17',date '2026-07-08',date '2026-07-29',date '2026-08-19',date '2026-09-09',date '2026-09-30',date '2026-10-21',date '2026-10-28',date '2026-11-04',date '2026-11-11',date '2026-11-18',date '2026-11-25',date '2026-12-02')),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 '2025-01-01'group by 1),v as (select c.block_date dd, c.tx_to bot,c.d * case when c.tok = 0x833589fcd6edb6e08f4c7c32d4f71b54bda02913 then 1 else p.px end usdfrom c join p on p.d = c.block_date),bd as (select dd, bot, count(*) arbs, sum(usd) usd from v where usd < 50000 group by 1, 2),r as (select *, row_number() over (partition by dd order by usd desc) rk from bd where arbs >= 2)select dd, 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,sum(case when rk <= 5 then usd end) / sum(usd) top5_sharefrom r group by 1 order by 1