Query editor
withL as (select * from dune.fadz2323.result_base_liq_open_race_events),S as (select * from dune.fadz2323.result_base_liq_open_race_svr),X as (select * from dune.fadz2323.result_base_liq_open_race_txs),tb as (select tx, sum(bonus_usd) tx_bonus from L group by 1),vol as (select d, case when rng >= approx_percentile(rng, 0.75) over () then 'volatile' else 'calm' end vdayfrom (select date_trunc('day', timestamp) d, (max(price)-min(price))/min(price) rngfrom prices.hour where blockchain = 'base' and contract_address = 0xcbb7c0000ab88b473b1f5afd9ef808440eed33bfand timestamp >= timestamp '2026-10-01' and timestamp < timestamp '2026-12-04'group by 1) z),ndays as (select count_if(vday='calm') n_calm, count_if(vday='volatile') n_vol from vol),e as (select L.*, X.prio_usd / nullif(tb.tx_bonus,0) prio_pct, X.n_loser_senders, v.vday,casewhen (S.last_atlas_ts is not null and L.ts - S.last_atlas_ts <= 10) or (S.last_s_ts is not null and L.ts - S.last_s_ts <= 10) then 'leftover'when S.lag_fb_mapped is not null or (S.svr_agg is null and S.lag_fb_any <= 3) then 'fallback'when S.nonsvr_hit >= 0 then 'non_svr'else 'drift' end cls,case when L.bonus_usd < 100 then '1_<100' when L.bonus_usd < 1000 then '2_100-1k' when L.bonus_usd < 10000 then '3_1k-10k' else '4_>=10k' end band,casewhen L.mkey = 0x9103c3b4e834476c9a62ea009ba2c884ee42e94e6e314a26f04d312434191836 then 'M cbBTC/USDC 86'when L.mkey = 0x0ca10126f6c94cbd9cf0a48cc9516ae5e3dec5aa68303e6d988ee37c5149bf0d then 'M cbETH/USDC 77'when L.mkey = 0xd4a903dc6d949519060c7707f9604fdc9772c046e05c2e3a8fce0bd7196e4109 then 'M cbXRP/USDC 62.5'when L.mkey = 0x8793cf302b8ffd655ab97bd1c695dbd967807e8367a65cb2f4edaf1380ba1bda then 'M WETH/USDC 86'when L.proto = 'morpho' and L.lltv <= 0.63 then 'M long-tail 62.5 other'when L.proto = 'morpho' then 'M other'when L.proto = 'aave' then 'Aave all'else 'Compound all' end mgroupfrom L join S on S.tx = L.tx and S.ei = L.eileft join X on X.tx = L.txleft join tb on tb.tx = L.txleft join vol v on v.d = date_trunc('day', L.t)where not L.is_atlas and L.t < timestamp '2026-12-04'),w as (select mgroup, band, winner, sum(bonus_usd) wb from e group by grouping sets ((mgroup, band, winner), (band, winner))),t1 as (select coalesce(mgroup,'ALL') mgroup, band, max(wb)/nullif(sum(wb),0) top1 from w group by 1,2)select coalesce(e.mgroup,'ALL') mgroup, e.band, count(*) n, round(sum(bonus_usd)) bonus,count(distinct winner) winners, round(sum(bonus_usd)/count(distinct winner)) bonus_per_winner, round(max(t1.top1),2) top1,round(approx_percentile(prio_pct, 0.5),3) med_prio_pct, approx_percentile(n_loser_senders, 0.5) med_losers,round(sum(case when cls='leftover' then bonus_usd end)/sum(bonus_usd),2) sh_leftover,round(sum(case when cls='fallback' then bonus_usd end)/sum(bonus_usd),2) sh_fallback,round(sum(case when cls='non_svr' then bonus_usd end)/sum(bonus_usd),2) sh_nonsvr,round(sum(case when cls='drift' then bonus_usd end)/sum(bonus_usd),2) sh_drift,round(sum(case when vday='calm' then bonus_usd else 0 end)/max(nd.n_calm)*30) mo_calm,round(sum(case when vday='volatile' then bonus_usd else 0 end)/max(nd.n_vol)*30) mo_volatile,round(sum(case when t < timestamp '2026-11-01' then bonus_usd else 0 end)) oct_total,round(sum(case when t >= timestamp '2026-11-01' and t < timestamp '2026-12-01' then bonus_usd else 0 end)) nov_total,max(nd.n_calm) n_calm_days, max(nd.n_vol) n_vol_daysfrom e cross join ndays ndleft join t1 on t1.mgroup = coalesce(e.mgroup,'ALL') and t1.band = e.bandgroup by grouping sets ((e.mgroup, e.band), (e.band))having sum(bonus_usd) >= 1000order by 1, 2