Query editor
/*-- @title: Accounting-- @author: Steakhouse Financial-- @description: Generates double-entry accounting, which serves as the basis for calculating the profit & loss and balance sheet-- @notes: N/A-- @version:1.0 - 2023-10-23 - Initial version2.0 - 2024-07-03 - Using accounting v23.0 - 2024-10-28 - Add in SSR view4.0 - 2024-10-30 - Merge query5.0 - 2025-05-05 - Update the SSR view6.0 - 2025-05-10 - Add SKY token7.0 - 2025-08-05 - Add token price for SKY*/withtoken_addresses as (select token, price_address as addr from query_3150055 -- Treasury ERC20s (ie: ENS, AAVE, COMP, stkAAVE)union allselect 'MKR' as token, 0x9f8f72aa9304c8b593d555f12ef6589cc3a579a2 as addrunion allselect 'ETH' as token, 0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2 as addrunion allselect 'DAI' as token, 0x6b175474e89094c44da98b954eedeac495271d0f as addrunion allselect 'USDS' as token, 0xdc035d45d973e3ec169d2276ddab16f1e407384f as addrunion allselect 'SKY' as token, 0x56072C95FAA701256059aa122697B133aDEd9279 as addr),token_prices as (selectminute as ts,t.token,case when t.token IN ('DAI', 'USDS') then 1 else price end as pricefrom prices.usd pinner join token_addresses ton p.contract_address = t.addrwhere blockchain = 'ethereum'and minute >= timestamp '2019-11-01'union all--ENS price history doesn't go back far enough, so manually inputting the first value from 2021-12-17 00:00select timestamp '2021-11-09 00:02' as ts, 'ENS' as token, 44.3 as priceunion all--SKY price history doesn't go back far enough, so manually inputting price of MKR / 24000 at '2024-09-17 12:00'select timestamp '2024-09-17 12:00' as ts, 'SKY' as token, 0.0635042 price),coa as (select account_id, account_label from query_3689733 -- Sky - Chart of Accounts),eth_prices as (select * from token_prices where token = 'ETH'),-- mark-to-market filling for assets, liabilities and equity (create x9999 records for every treasury token)m2m_filling as (selectp.ts,null as hash,coa.account_id,0 as value,p.token,