Query editor
-- ENS referral fee backtest: trailing 365d TRUE net protocol revenue x payout scenarios-- Revenue = net ETH retained by all three .eth registrar controllers, per-tx netting-- (inflows minus same-tx refunds). Avoids the 2023 controller NameRenewed msg.value bug-- that overstates event-based renewal revenue. Withdraw-only txs excluded by eth_in > 0.WITH tx_net AS (SELECT tx_hash, min(block_time) AS bt,sum(CASE WHEN "to" IN (0x253553366Da8546fC250F225fe3d25d0C782303b,0x283Af0B28c62C092C9727F1Ee09c02CA627eb7F5,0x59E16fcCd424Cc24e280Be16E11Bcd56fb0CE547) THEN value ELSE uint256 '0' END)/1e18 AS eth_in,sum(CASE WHEN "from" IN (0x253553366Da8546fC250F225fe3d25d0C782303b,0x283Af0B28c62C092C9727F1Ee09c02CA627eb7F5,0x59E16fcCd424Cc24e280Be16E11Bcd56fb0CE547) THEN value ELSE uint256 '0' END)/1e18 AS eth_outFROM ethereum.tracesWHERE ("to" IN (0x253553366Da8546fC250F225fe3d25d0C782303b,0x283Af0B28c62C092C9727F1Ee09c02CA627eb7F5,0x59E16fcCd424Cc24e280Be16E11Bcd56fb0CE547)OR "from" IN (0x253553366Da8546fC250F225fe3d25d0C782303b,0x283Af0B28c62C092C9727F1Ee09c02CA627eb7F5,0x59E16fcCd424Cc24e280Be16E11Bcd56fb0CE547))AND value > uint256 '0' AND success AND call_type = 'call'AND block_time >= now() - interval '365' dayGROUP BY 1),rev AS (SELECT sum(t.eth_in - t.eth_out) AS net_eth,sum((t.eth_in - t.eth_out) * p.price) AS net_usdFROM tx_net tLEFT JOIN prices.day p ON p.blockchain = 'ethereum'AND p.contract_address = 0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2AND p.timestamp = date_trunc('day', t.bt)WHERE t.eth_in > 0),scenarios(fee_rate, coverage) AS (VALUES (0.05, 1.00), (0.08, 1.00), (0.10, 1.00),(0.05, 0.25), (0.08, 0.25), (0.10, 0.25))SELECTformat('%.0f%%', s.fee_rate * 100) AS fee_rate,format('%.0f%%', s.coverage * 100) AS coverage,round(r.net_eth * s.fee_rate * s.coverage, 1) AS payout_eth,round(r.net_usd * s.fee_rate * s.coverage, 0) AS payout_usd,format('%.2f%%', s.fee_rate * s.coverage * 100) AS pct_of_revenue,round(r.net_usd * (1 - s.fee_rate * s.coverage), 0) AS net_retained_usd,round(r.net_eth, 1) AS total_revenue_eth,round(r.net_usd, 0) AS total_revenue_usdFROM scenarios s CROSS JOIN rev rORDER BY s.coverage DESC, s.fee_rate