Query editor
-- ENS DAO — Endowment DeFi Yield (monthly, on-chain accounting) v2-- Owner: coltron (public). Repo: ens-foundation-skill/pipeline/sql/ens_endowment_yield_v2.sql---- Same logic as query 8164884 (Part A canonical), parameterised by date, plus a month-end NAV column.-- Source: Steakhouse's on-chain accounting of the endowment Safe, dune.steakhouse.result_ens_accounting_main.-- yield = sum(amount) on accounts 32321* (investment P&L: staking / lending / vault appreciation)-- + 32322* (reward tokens). Mark-to-market (M2M ledger, other 3xxx accounts) is excluded.-- lm = the one-off Aave USDS liquidity-mining accrual (transaction ACCRUAL-LMREWARDS-AETHUSDS-1,-- 145,411.34 USD) is removed from the booked line and spread evenly over its earning window-- (2025-08-01 → 2026-02-27, 210 days) so no single month carries it.-- nav = cumulative sum of all postings to asset accounts (1xxxxx) through the last posting of the month,-- in USD. Ties to the Steakhouse monthly deck's "endowment assets" (Aug-2026: 92.3M).-- Parameters: {{period_start}} / {{period_end}} (text, 'YYYY-MM-DD'; end exclusive). Data starts 2023-03.with params as (select timestamp '{{period_start}}' as t0, timestamp '{{period_end}}' as t1),src as (select ts, account, amount, transactionfrom dune.steakhouse.result_ens_accounting_mainwhere wallet = '0x4f2083f5fbede34c2714affb3105539775f7fe64'),base as (select date_trunc('month', ts) as month, sum(amount) as booked_yieldfrom src, paramswhere (cast(account as varchar) like '32321%' or cast(account as varchar) like '32322%')and transaction != 'ACCRUAL-LMREWARDS-AETHUSDS-1'and ts >= t0 and ts < t1group by 1),lm as (select date_trunc('month', d) as month, sum(145411.33742432442 / 210) as lm_rewardfrom unnest(sequence(timestamp '2025-08-01', timestamp '2026-02-27', interval '1' day)) as t(d), paramswhere d >= t0 and d < t1group by 1),assets_monthly as (select date_trunc('month', ts) as month, sum(amount) as net_postedfrom src where cast(account as varchar) like '1%'group by 1),nav as (select month, sum(net_posted) over (order by month rows between unbounded preceding and current row) as nav_usdfrom assets_monthly),months as (select month from base union select month from lm)select m.month,round(coalesce(b.booked_yield, 0), 0) as booked_yield_usd,round(coalesce(l.lm_reward, 0), 0) as lm_reward_usd,round(coalesce(b.booked_yield, 0) + coalesce(l.lm_reward, 0), 0) as total_yield_usd,round(n.nav_usd, 0) as nav_month_end_usd,round((coalesce(b.booked_yield, 0) + coalesce(l.lm_reward, 0)) / nullif(n.nav_usd, 0) * 100, 3) as yield_pct_of_navfrom months mleft join base b on b.month = m.monthleft join lm l on l.month = m.monthleft join nav n on n.month = m.monthorder by 1