Query editor
-- ENS DAO Treasury ETH Balance Over Time (Monthly)-- Tracks net ETH flowing into DAO wallets from protocol registrar contracts-- Uses ethereum.transactions for ETH value received by DAO walletsWITH dao_wallets AS (SELECT wallet FROM (VALUES(0xfe89cc7abb2c4183683ab71653c4cdc9b02d44b7),(0xcf60916b6cb4753f58533808fa610fcbd4098ec0),(0x911143d946ba5d467bfc476491fdb235fef4d667)) AS t(wallet)),-- Monthly stablecoin net flows (in - out) for DAO walletsstable_monthly AS (SELECTDATE_TRUNC('month', t.block_time) AS month,SUM(CASE WHEN t."to" IN (SELECT wallet FROM dao_wallets) AND t."from" NOT IN (SELECT wallet FROM dao_wallets)THEN COALESCE(t.amount_usd, CASE WHEN LOWER(t.symbol) IN ('usdc','dai','usdt','frax','lusd','gusd') THEN t.amount ELSE 0 END)ELSE 0 END) -SUM(CASE WHEN t."from" IN (SELECT wallet FROM dao_wallets) AND t."to" NOT IN (SELECT wallet FROM dao_wallets)THEN COALESCE(t.amount_usd, CASE WHEN LOWER(t.symbol) IN ('usdc','dai','usdt','frax','lusd','gusd') THEN t.amount ELSE 0 END)ELSE 0 END) AS net_stable_usdFROM tokens.transfers tWHERE t.blockchain = 'ethereum'AND LOWER(t.symbol) IN ('usdc','dai','usdt','frax','lusd','gusd')AND (t."to" IN (SELECT wallet FROM dao_wallets) OR t."from" IN (SELECT wallet FROM dao_wallets))AND t.block_time >= TIMESTAMP '2019-01-01'GROUP BY 1),-- Monthly protocol revenue (ETH)eth_price AS (SELECT DATE_TRUNC('month', minute) AS month, AVG(price) AS eth_usdFROM prices.usdWHERE blockchain = 'ethereum'AND contract_address = 0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2GROUP BY 1),protocol_revenue_monthly AS (SELECTDATE_TRUNC('month', evt_block_time) AS month,SUM(CAST(cost AS DOUBLE) / 1e18) AS eth_inFROM ethereumnameservice_ethereum.ethregistrarcontroller_1_evt_nameregisteredGROUP BY 1UNION ALLSELECT DATE_TRUNC('month', evt_block_time), SUM(CAST(cost AS DOUBLE) / 1e18)FROM ethereumnameservice_ethereum.ethregistrarcontroller_1_evt_namerenewed GROUP BY 1UNION ALLSELECT DATE_TRUNC('month', evt_block_time), SUM(CAST(cost AS DOUBLE) / 1e18)FROM ethereumnameservice_ethereum.ethregistrarcontroller_3_evt_nameregistered GROUP BY 1UNION ALLSELECT DATE_TRUNC('month', evt_block_time), SUM(CAST(cost AS DOUBLE) / 1e18)FROM ethereumnameservice_ethereum.ethregistrarcontroller_3_evt_namerenewed GROUP BY 1UNION ALL