Query editor
with ev as (select *,case when debt_usd is not null and coll_usd is not null and debt_usd < 1e9 and coll_usd < 2*debt_usd + 1000 then greatest(coll_usd - debt_usd, 0) end bonus,case when proto <> 'aave' then protowhen mkt = 0x87870Bca3F3fD6335C3F4ce8392D69350B4fA4E2 then 'aave_core'when mkt = 0x4e033931ad43597d96D6bcc25c280717730B58B1 then 'aave_prime'when mkt = 0x0AA97c284e98396202b6A04024F5E2c65026F3c0 then 'aave_etherfi'when mkt = 0xAe05Cd22df81871bc7cC2a04BeCfb516bFe332C8 then 'aave_horizon'else 'aave_other' end mlabelfrom dune.fadz2323.result_eth_liq_oct_dec_2026),t as (select h, min(mlabel) mlabel, min(bn) bn, min(txi) txi, min(liquidator) liq, max_by(coll, coalesce(bonus, 0)) coll,count(*) n_ev, count(bonus) n_priced, sum(bonus) bonus,max(eth_usd) eth_usd, max(gas_used) gas_used, max(priority_fee_per_gas) prio, max(cb_eth) cb_eth,max(svr_idx) svr_idx, max(svr_feed) svr_feed, max(rf_idx) rf_idx, max(rf_eth) rf_ethfrom ev group by h),tx as (select *, (gas_used * prio / 1e18 + cb_eth) * eth_usd builder_usd,case when svr_idx is null then 'none' when txi - svr_idx = 1 then 'gap1' when txi - svr_idx <= 5 then 'gap2_5' else 'gap6p' end svr_cls,case when bonus < 1000 then 'a:<1k' when bonus < 10000 then 'b:1k-10k' else 'c:>=10k' end bktfrom t where n_ev = n_priced and eth_usd is not null),sym as (select contract_address, max(symbol) symbol from tokens.erc20 where blockchain = 'ethereum' and contract_address in (select coll from tx) group by 1),a as (select 'MKT_SVRCLS' sec, mlabel k1, svr_cls k2, count(*) n_tx, sum(bonus) bonus, sum(builder_usd) builder, count(distinct liq) winners, count_if(rf_idx > txi) n_with_refund_afterfrom tx group by grouping sets ((mlabel, svr_cls), (mlabel))),b as (select 'COLL' sec, coalesce(s.symbol, to_hex(tx.coll)) || '|' || mlabel k1, svr_cls k2, count(*) n_tx, sum(bonus) bonus, sum(builder_usd) builder, count(distinct liq) winners, count_if(rf_idx > txi) n_with_refund_afterfrom tx left join sym s on s.contract_address = tx.collgroup by 1, 2, 3),c as (select 'SVR_BKT' sec, case when mlabel like 'aave%' then 'aave' else mlabel end || '|' || bkt k1, case when svr_cls = 'gap1' then 'svr' else 'nonsvr' end k2,count(*) n_tx, sum(bonus) bonus, sum(builder_usd) builder, count(distinct liq) winners, count_if(rf_idx > txi) n_with_refund_afterfrom tx group by 1, 2, 3),d as (select 'REFUND_USD_SVR_BLOCKS' sec, 'all' k1, 'all' k2, count(*) n_tx, sum(rf_eth * eth_usd) bonus, null builder, null winners, null n_with_refund_afterfrom (select bn, max(rf_eth) rf_eth, max(eth_usd) eth_usd from tx where svr_cls = 'gap1' group by bn)),e as (select 'SVR_FEED' sec, to_hex(svr_feed) k1, 'gap1' k2, count(*) n_tx, sum(bonus) bonus, sum(builder_usd) builder, count(distinct liq) winners, null n_with_refund_afterfrom tx where svr_cls = 'gap1' group by 1, 2, 3)select * from a union all select * from (select * from b where bonus > 15000) union all select * from c union all select * from d union all select * from eorder by 1, 2, 3