Query editor
WITHlsts as (--s/o ashpool https://x.com/solanobahn/status/1706340214699159859?s=20SELECT*FROM (values('9eG63CdHjsfhHmobHgLtESGC8GabbmRcaSpHAZrtmhco', 'Du3Ysj1wKbxPKkuPPnvzQLQh8oMSVifs3jGZjJWXFmHN', 'mSOL'),('W1ZQRwUfSkDKy2oefRBUWph82Vr2zg9txWMA8RQazN5', '3Kwv3pEAuoe4WevPB4rgMBTZndGDb53XT7qwQKnvHPfX','stSOL'),('6iQKfEyhr3bZMotVkW6beNZz5CPAkiwvgV2CTje9pVSS', 'BgKUXdS29YcHCFrPm5M8oLHiTzZaMDjsebggjoaQ6KFL', 'jito'),('6WecYymEARvjG5ZyqkrVQ6YkhPfujNzWpSPwNKXHCbV2', 'rsrxDvYUXjH1RQj2Ke36LNZEVqGztATxFkqNukERqFT', 'bSOL'),('HbJTxftxnXgpePCshA8FubsRj9MW4kfPscfuUfn44fnt', 'AXu3DTw9AFq9FDTzX4vqA3XiT7LjrS5DpbsZaPpEx6qR', 'jSOL'),('AzZRvyyMHBm8EHEksWxq4ozFL7JxLMydCDMGhqM6BVck', '4sDXGroVt7ba45rzXtNto97QjG1rHm8Py3v56Mgg16Nc', 'scnSOL'),('3b7XQeZ8nSMyjcQGTFJS5kBw4pXS2SqtB9ooHCnF2xV9', 'AWDrV3Va8RKGMAo9bi5iYhqhETRsTT7NasRFC22uBj4A', 'mrgnLST')) as v(authority, reserve, lst)), program_accounts as (SELECTdistinctstake_account_raw as address, authority --authorities can change, we need to get these authorities BY DATE.FROM dune.dune.result_solana_stake_accounts_authoritiesWHERE authority IN (SELECT authority FROM lsts)and latest = 1 --might lose some historical balances that were only temporarily authed to an LST?UNIONSELECTreserve as address, authorityFROM lsts), times as (--daysSELECTq.time, l.authorityFROM query_2254698 q, lsts lWHERE time >= timestamp '{{Start Date}}'), rolling_diff as (with stake_diff as (SELECTbal.day, pa.authority, COALESCE(sol_balance - lag(sol_balance,1) over (partition by bal.address order by day asc nulls first), sol_balance) as sol_balance_diff --coalesce so that first deposit is counted into diffFROM solana_utils.daily_balances balJOIN program_accounts pa ON pa.address = bal.addressWHERE bal.token_mint_address is null)SELECTday, authority, total_sol_balance_diff, sum(total_sol_balance_diff) over (partition by authority order by day asc nulls first) as total_sol_balance --partition by voteFROM (SELECTday