Query editor
with studied (pool_code, pool_label, pool_addr, orig) as (values (1, 'UniV3 0.05%', 0x88e6a0c2ddd26feeb64f039a2c41296fcb3f5640, 1),(2, 'UniV3 0.30%', 0x8ad599c3a0ff1de082011efddc58f1908eb6e6d8, 1),(4, 'Curve ETH/stETH', 0xdc24316b9ae028f1497c275eb9192a3ea0f67022, 1),(8, 'Balancer 80/20 BAL/WETH', 0x5c6ee304399dbdb9c8ef030ab642b10820db8f56, 1),(16, 'UniV3 0.01%', 0xe0554a476a092703abdb3ef35c80e0d76d32939f, 0),(32, 'UniV3 1.00%', 0x7bea39867e4169dbe237d55c8242a8f2fcdcc387, 0)),base as (select t.tx_hash, t.block_time, t.evt_index, t.project, t.project_contract_address,t.token_sold_address, t.token_bought_address, t.amount_usdfrom dex.trades twhere t.blockchain = 'ethereum'and t.block_month between date '2026-05-01' and date '2026-08-01'and t.block_time >= timestamp '2026-05-30' and t.block_time < timestamp '2026-08-23'and t.project not in ('origin_arm','metric','lista_smartswap')),legs as (select * from base where tx_hash in (select tx_hash from base where project_contract_address in (select pool_addr from studied))),tx as (select tx_hash, min(block_time) as bt, count(*) as n_legs,min_by(token_sold_address, evt_index) as first_sold,max_by(token_bought_address, evt_index) as last_bought,min_by(amount_usd, evt_index) as first_usd,max_by(amount_usd, evt_index) as last_usdfrom legs group by tx_hash having count(*) >= 2),arb as (select tx_hash, bt, last_usd - first_usd as profit_usd from tx where first_sold = last_bought and last_usd > first_usd),touch as (select a.tx_hash, s.pool_code, s.pool_label, s.orig, sum(l.amount_usd) as pool_vol, count(*) as pool_legsfrom arb a join legs l on l.tx_hash = a.tx_hash join studied s on s.pool_addr = l.project_contract_addressgroup by 1, 2, 3, 4),rk as (select t.*,case when orig = 1 then row_number() over (partition by tx_hash, orig order by pool_vol desc, pool_label asc) end as rk4,row_number() over (partition by tx_hash order by pool_vol desc, pool_label asc) as rk6from touch t),arbrows as (select 'arb' as typ, to_hex(a.tx_hash) as h, cast(date(a.bt) as varchar) as d, r.pool_code as pc, r.pool_vol as vol, r.pool_legs as nlegs,case when r.rk4 = 1 then 1 else 0 end as cr4, case when r.rk6 = 1 then 1 else 0 end as cr6, a.profit_usd as pfrom arb a join rk r on r.tx_hash = a.tx_hash),dayrows as (select 'day' as typ, '' as h, cast(date(b.block_time) as varchar) as d, s.pool_code as pc, sum(b.amount_usd) as vol, count(*) as nlegs,0 as cr4, 0 as cr6, cast(null as double) as pfrom base b join studied s on s.pool_addr = b.project_contract_addresswhere s.pool_code in (1, 2, 16, 32)group by 3, 4)select * from arbrows union all select * from dayrows