Query editor
with--https://dune.com/queries/3137373defi_program_accounts as (SELECT * FROM dune.dune.result_solana_defi_token_accounts), lsts as (SELECTlst_mint as token_mint_address, lstFROM query_3711279 --stake pool lstUNION ALLSELECTlst_mint as token_mint_address, lstFROM query_3708918 --single validator lst), times as (--weeksSELECTq.time, s.address, s.token_mint_address, s.domain, s.nameFROM query_2254709 q, defi_program_accounts s --weeks-- FROM query_2254711 q, defi_program_accounts s --monthsWHERE time >= timestamp '{{Start Date}}'), weekly_balances as (SELECTdate_trunc('week',day) as week, address, max_by(token_balance, day) as token_balanceFROM solana_utils.daily_balancesWHERE address IN (SELECT address from defi_program_accountsWHERE domain not in ('PERP','NFT','MULTISIG') --perps TVL is not captured correctly right now, NFTs don't relate to LSTs. Multisigs are noisy)group by 1,2), rolling_liquidity as (--forward and backfill value across all timeSELECTtime, time_join, address, token_mint_address, domain, name, coalesce(token_balance, lag(token_balance, 1) IGNORE NULLS OVER (partition by address ORDER BY time asc nulls first)) as balanceFROM (SELECTt.time, case when t.time != date_trunc('day',now()) AND t.time = date_trunc('week',now()) --if week is same but day isn't, then use current day for price joinsthen date_trunc('day',now())else t.time endas time_join --we want to get latest day of prices so that the weekly USD value/price matches the latest USD value/price.