Query editor
-- D1 (daily version, with event-day USD): actual ETH retained by each ETHRegistrarController per tx (traces in minus refunds out), classified by the events in that tx.-- Why: controller v4 NameRenewed.cost = msg.value (pre-refund), so event-based renewal totals are inflated by bulk-renew excess.-- Cash basis = revenue actually collected. Withdraw txs (no NameRegistered/NameRenewed) are excluded here and measured in the routing query.with ctl as (select * from (values(0xf0ad5cad05e10572efceb849f6ff0c68f9700455,'v1'),(0xb22c1c159d12461ea124b0deb4b5b93020e6ad16,'v2'),(0x283af0b28c62c092c9727f1ee09c02ca627eb7f5,'v3'),(0x253553366da8546fc250f225fe3d25d0c782303b,'v4'),(0x59e16fccd424cc24e280be16e11bcd56fb0ce547,'v5')) as t(addr, v)),ev as (select evt_tx_hash tx, 'reg' k from ethereumnameservice_ethereum.ethregistrarcontroller_1_evt_nameregistered where evt_block_time>=timestamp '2021-11-01'union all select evt_tx_hash,'reg' from ethereumnameservice_ethereum.ethregistrarcontroller_2_evt_nameregistered where evt_block_time>=timestamp '2021-11-01'union all select evt_tx_hash,'reg' from ethereumnameservice_ethereum.ethregistrarcontroller_3_evt_nameregistered where evt_block_time>=timestamp '2021-11-01'union all select evt_tx_hash,'reg' from ethereumnameservice_ethereum.ethregistrarcontroller_4_evt_nameregistered where evt_block_time>=timestamp '2021-11-01'union all select evt_tx_hash,'reg' from ethereumnameservice_ethereum.ethregistrarcontroller_5_evt_nameregistered where evt_block_time>=timestamp '2021-11-01'union all select evt_tx_hash,'ren' from ethereumnameservice_ethereum.ethregistrarcontroller_1_evt_namerenewed where evt_block_time>=timestamp '2021-11-01'union all select evt_tx_hash,'ren' from ethereumnameservice_ethereum.ethregistrarcontroller_2_evt_namerenewed where evt_block_time>=timestamp '2021-11-01'union all select evt_tx_hash,'ren' from ethereumnameservice_ethereum.ethregistrarcontroller_3_evt_namerenewed where evt_block_time>=timestamp '2021-11-01'union all select evt_tx_hash,'ren' from ethereumnameservice_ethereum.ethregistrarcontroller_4_evt_namerenewed where evt_block_time>=timestamp '2021-11-01'union all select evt_tx_hash,'ren' from ethereumnameservice_ethereum.ethregistrarcontroller_5_evt_namerenewed where evt_block_time>=timestamp '2021-11-01'),txk as (select tx, max(case when k='reg' then 1 else 0 end) has_reg, max(case when k='ren' then 1 else 0 end) has_ren from ev group by 1),eth_price as (select date_trunc('day',minute) day, avg(price) eth_usd from prices.usdwhere blockchain='ethereum' and contract_address=0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2 and minute>=timestamp '2021-11-01' group by 1),tr as (select date_trunc('day', t.block_time) day, t.tx_hash, c.v,sum(case when t."to" = c.addr then t.value/1e18 else 0 end) eth_in,sum(case when t."from" = c.addr then t.value/1e18 else 0 end) eth_outfrom ethereum.traces t join ctl c on (t."to" = c.addr or t."from" = c.addr)where t.block_time >= timestamp '2021-11-01' and t.value > 0 and t.success and t.call_type <> 'delegatecall'group by 1,2,3)select tr.day, tr.v controller,case when k.has_reg=1 and k.has_ren=1 then 'mixed' when k.has_reg=1 then 'reg' when k.has_ren=1 then 'ren' else 'none' end kind,count(*) n_tx, sum(eth_in) eth_in, sum(eth_out) eth_out, sum(eth_in-eth_out) eth_net, sum((eth_in-eth_out)*p.eth_usd) usd_netfrom tr left join txk k on tr.tx_hash = k.tx left join eth_price p on p.day = tr.daygroup by 1,2,3 order by 1,2,3