Query editor
/*-- @title: ENS - Endowment-- @description: Calculates the daily balance of the ENS Endowment Wallet by accounting category.-- @author: Steakhouse Financial-- @notes:- ENS Endowment wallet created on Jan-20-2023-- @version:- 2.0 - 2024-02-19 - Added comment header, added contract & wallet description- 1.0 - ????-??-?? - Initial version*/with entries as (select cast(account as varchar) account, ts, amountfrom dune.steakhouse.result_ens_accounting_mainwhere wallet = '0x4f2083f5fbede34c2714affb3105539775f7fe64' -- ENS EnDAOment walletand cast(account as varchar) like '1%'),accounts as (select * from query_2181835 -- ENS Chart of Accounts),items as (select account, date(ts) as period, amount as amountfrom entriesunion allselect account, period, null as amountfrom (select distinct account from entries) itemscross join (select distinct date(ts) as period from entries) periods),group_by as (select account, period, sum(amount) as amountfrom itemsgroup by 1, 2),balances as (select account, period, sum(amount) over (partition by account order by period asc) as balancefrom group_by)selectcoalesce(account_label, account) as item,cast(period as timestamp) as period,case when abs(balance) < 1 then 0 else balance end as balancefrom balancesleft join accounts using (account)order by account asc