Query editor
/*-- @title: ENS - Accounting - Revenues-- @description: Calculates accounting entries (revenues and liabilities) based on registrations and renewals-- @author: Steakhouse Financial-- @notes: First transfer was on 2019-05-04; applying a filter from 2019-01-01-- @version:- 1.0 - 2023-08-03 - Initial release- 2.0 - 2024-03-07 - Improving performance & adding comments- 3.0 - 2024-04-16 - Resolved incorrect M2M Accruel- 4.0 - 2025-01-03 - Fix rogue contract for renewal revenues- 5.0 - 2025-03-06 - Correct positioning for contract address and tx_hash- 6.0 - 2025-04-05 - Fix the columns for unions- 7.0 - 2025-11-07 - Split query- 8.0 - 2026-11-10 - Multi-token revenues for the ENSv2 registrar (USDC / DAI paid straight to EnDAOment)-> token-aware decimals, prices and cash account (121 ETH / 111001 USDC / 111002 DAI)-> wallet = where the cash lands (controller for v1, EnDAOment for v2)-> liability M2M only for non-stable tokens-> registration / renewal branches collapsed into one (tpe from view_type), logic unchanged*/WITH revenues_periods AS (SELECT periodFROM unnest(sequence(date '2019-01-01', current_date, interval '1' day)) AS t(period)),-- Only ETH otherwise change the rest of the queryrevenues_tokens AS (SELECT token_address as contract_address, symbol, decimals, power(10, decimals) AS divisor,CASE token_addressWHEN 0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2 THEN 121 -- 'WETH'WHEN 0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48 THEN 111001 -- 'USDC'WHEN 0x6b175474e89094c44da98b954eedeac495271d0f THEN 111002 -- 'DAI'END as account,casewhen "type" = 'usd-stablecoin' then trueelse falseend as is_stableFROM dune.steakhouse.result_token_infoWHERE blockchain = 'ethereum'AND token_address IN (0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2, -- WETH0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48, -- USDC0x6b175474e89094c44da98b954eedeac495271d0f -- DAI)),revenues_prices AS (SELECT DATE_TRUNC('day', minute) AS period, contract_address, priceFROM prices.usdINNER JOIN revenues_tokens USING (contract_address)WHERE blockchain = 'ethereum'AND minute > date '2019-01-01'AND EXTRACT(hour FROM minute) = 23AND EXTRACT(minute FROM minute) = 59AND not is_stableUNION ALL-- stablecoins fixed at 1 (same convention as transfers / expenses)SELECT period, contract_address, 1.0 AS priceFROM revenues_tokensCROSS JOIN UNNEST(sequence(date '2026-10-01', current_date - interval '1' day, interval '1' day)) AS _u(period)WHERE is_stable