Query editor
-- ENS DAO — Protocol Revenue (monthly, cash-accurate) v2-- Owner: coltron (public). Repo: ens-foundation-skill/pipeline/sql/ens_protocol_revenue_v2.sql---- What it measures: ETH actually RETAINED by the ETHRegistrarControllers (v1–v5) per month = protocol revenue-- on a cash basis at payment time, split into registrations (base price), expired-name premium and renewals.---- Why not the decoded events alone (as in query 8163671): the v4 controller's NameRenewed event logs `cost` =-- msg.value, not the price. The bulk-renewal contract 0x78fe…90b2 over-sent ~1 ETH per name from Dec-2024 to-- Sep-2025 and was refunded in the same transaction, so event-based renewal revenue is inflated 40–300x in that-- window. Cash in minus refunds out is immune to that quirk and to the v5 NameRegistered premium omission.---- Method-- cash : per (tx, controller) from ethereum.traces: value in to the controller minus value out of the-- controller in the same tx, EXCLUDING sweeps (withdraw() to the owner: root multisig / DAO wallet /-- Registrar Manager / endowment — the owner() of the controller at the time).-- split : per (tx, controller) from the decoded NameRegistered / NameRenewed events (base, premium, renew).-- The cash total is pro-rated across the three event components. Where a tx has cash but no decoded-- event (should be ~0) the amount lands in `unattributed_eth` so the total is still cash-exact.-- USD : event-day average WETH price from prices.usd.---- Parameters: {{period_start}} / {{period_end}} (text, 'YYYY-MM-DD'; end exclusive).-- Validation: see ens-foundation-skill/pipeline/sql/VALIDATION.md (target ≤2%/month vs Etherscan-derived controller cash).with params as (select timestamp '{{period_start}}' as t0, timestamp '{{period_end}}' as t1),controllers as (select * from (values(0xF0AD5cAd05e10572EfcEB849f6Ff0c68f9700455, 'v1'),(0xB22c1C159d12461EA124b0deb4b5b93020E6Ad16, 'v2'),(0x283Af0B28c62C092C9727F1Ee09c02CA627EB7F5, 'v3'),(0x253553366Da8546fC250F225fe3d25d0C782303b, 'v4'),(0x59E16fcCd424Cc24e280Be16E11Bcd56fb0CE547, 'v5')) as t(addr, ctrl)),-- destinations of withdraw() sweeps over the controllers' life (owner at the time). Out-traces to these are NOT refunds.sweep_dest as (select * from (values(0x911143d946ba5d467bfc476491fdb235fef4d667), -- legacy root multisig (v1/v2 owner)(0xCF60916b6CB4753f58533808fA610FcbD4098Ec0), -- ENS root multisig (v3 owner pre-DAO)(0xFe89cc7aBB2C4183683ab71653C4cdc9B02D44b7), -- wallet.ensdao.eth (owner Nov-2021 → Apr-2026)(0x62627681d92e36b9aee1d9a6bf181373ccd42552), -- Registrar Manager (owner since EP 6.39, Apr-2026)(0x4f2083f5fBede34c2714AfFb3105539775f7FE64) -- endowment.ensdao.eth (sweep destination via Registrar Manager)) as t(addr)),eth_price as (select date_trunc('day', minute) as day, avg(price) as eth_usdfrom prices.usd, paramswhere blockchain = 'ethereum' and contract_address = 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2and minute >= t0 and minute < t1group by 1),tr as ( -- every successful value-bearing trace touching a controllerselect t.block_time, t.tx_hash, c.ctrl, c.addr,case when t."to" = c.addr then cast(t.value as double) / 1e18 else 0 end as v_in,case when t."from" = c.addr then cast(t.value as double) / 1e18 else 0 end as v_out,case when t."from" = c.addr and t."to" in (select addr from sweep_dest) then 1 else 0 end as is_sweepfrom ethereum.traces tjoin controllers c on (t."to" = c.addr or t."from" = c.addr)cross join params