Query editor
-- Attributed reward payouts. Paste in Dune as its own query; every other file in-- sql/rewards/ reads it back as query_0000000. Dashboard title: test---- Dune parameters:-- Ga5ErptAQ5oHwB7G195UEq9FeJ5UNDoV9SCRCpebFeG7 HcRLc9VDgjLeK154xDawfb1dmVJ98DoSqcwTHGqiDeJR (ZCAT)-- A7bdiYdS5GjqGFtxf17ppRHtDKPkkRqbKtR27dxvQXaS A7bdiYdS5GjqGFtxf17ppRHtDKPkkRqbKtR27dxvQXaS (ZEC, classic SPL)-- 5KXDF6QnqhBj72hDtJNkkpFaQVUfbFXNybMsp3DiK6tD 5KXDF6QnqhBj72hDtJNkkpFaQVUfbFXNybMsp3DiK6tD-- 0.7 0.5 (calibrated -- see threshold_sweep.sql)-- 2026-08-06 2026-08-30 (the pair's launch day)---- Set every parameter's default value before running. Dune substitutes an empty-- string for a blank parameter, which matches no rows and looks like "no results"-- rather than an error. 2026-08-06 is not optional either: without it this-- scans the whole of tokens_solana.transfers.---- Why attribution is needed: StonkFun pays every reward coin quoted in the same-- asset out of one token account, and the payout transaction names no reward-- coin -- it is ~20 bare transferChecked instructions, no memo, no CPI. For ZEC,-- ZCAT is only 77% of the volume and 61% of the payouts leaving that account, so-- filtering on the distributor alone overstates ZCAT by 29% and 65%.---- What makes it tractable: one transaction pays holders of exactly one coin, and-- the holder list is walked in descending balance order. So the batch, not the-- wallet, is the unit of attribution -- a wallet can hold several coins quoted in-- the same asset, but a batch belongs to one of them. A simple majority is the-- rule: 0.5 is where ZEC, payout count and wallet count all match StonkFun at-- once. Stricter thresholds drop the tail of the holder list, where wallets that-- have since sold carry a zero balance forward and score low.WITH payouts AS (SELECTblock_time,tx_id,to_owner AS wallet,amount_display AS amountFROM tokens_solana.transfersWHERE token_mint_address = 'A7bdiYdS5GjqGFtxf17ppRHtDKPkkRqbKtR27dxvQXaS'AND from_owner = '5KXDF6QnqhBj72hDtJNkkpFaQVUfbFXNybMsp3DiK6tD'AND action = 'transfer'AND to_owner IS NOT NULLAND block_time >= TIMESTAMP '2026-08-06'),-- solana_utils.daily_balances carries a row only when an address's balance-- CHANGED that day -- it is sourced from solana.account_activity and is not a-- carry-forward snapshot. Verified: summing token_balance per day gives 963M,-- 737M, 591M, 653M ... while ZCAT's supply is a constant ~968.9M.---- So matching a payout to a same-day balance row would only catch wallets that-- happened to trade ZCAT that day. Receiving a ZEC reward does not touch a-- wallet's ZCAT balance, so almost every real holder would look like a-- non-holder. Carry the last known balance forward into spans instead.balance_spans AS (SELECTtoken_balance_owner AS wallet,day AS valid_from,coalesce(lead(day) OVER (PARTITION BY token_balance_owner ORDER BY day),TIMESTAMP '2999-01-01') AS valid_to,