Query editor
-- ===========================================================================-- Historical netted per-owner balances for a Solana (pump.fun) token at a cutoff-- ----------------------------------------------------------------------------- Paste this into Dune query 9052381 (or a new query), then add these PARAMETERS-- with these exact names so the API can run it:-- token_mint (Text) the mint / contract address-- floor_time (Text) 'YYYY-MM-DD HH:MM:SS' UTC = launch time (lower bound)-- cutoff_time (Text) 'YYYY-MM-DD HH:MM:SS' UTC = launch time + age-- exclude_csv (Text) comma-separated addresses to pre-drop; may be empty-- supply_ui (Text) total supply in UI units; echoed for standalone use---- The floor_time + block_date bounds prune partitions so the query stays cheap-- and runs under free/standard per-query resource caps. The token has no-- transfers before launch, so flooring at (launch - 1 day) loses nothing.---- WHAT THIS DOES — and the division of labour:-- Dune does the one thing only a full balance index can: net EVERY transfer-- (DEX trades AND direct wallet-to-wallet moves) up to the cutoff into a balance-- per owner. It returns the top-40 candidate owners. The Python caller-- (pumpfun_extract.py) then applies the SAME on-curve / owning-program-- classifier the live metric uses to drop AMM-pool and bonding-curve PDAs, and-- sums the top-10 surviving WALLETS over supply. Pool exclusion lives in Python-- (it needs ed25519 on-curve math Trino can't do), so both the live and the-- at-age metric exclude pools by identical logic.---- Why net flows (not RPC trade-replay): a correct historical snapshot must net-- inbound AND outbound transfers. Early holders move tokens by direct transfer;-- replaying only curve/AMM trades misses those and massively overstates-- concentration (observed ~90% replay vs ~35% true). tokens_solana.transfers-- captures direct transfers, so summing +in / -out gives the real balance.---- SCHEMA NOTE (verified live 2026-11-01 against tokens_solana.transfers):-- columns token_mint_address, from_owner, to_owner, and TWO amount columns —-- `amount` (raw integer units) and `amount_display` (decimal-adjusted UI units).-- We use amount_display so balances are UI units, comparable to supply_ui.-- ===========================================================================WITH xfers AS (SELECT amount_display AS amt, from_owner, to_ownerFROM tokens_solana.transfersWHERE token_mint_address = '{{token_mint}}'AND block_date >= date(CAST('{{floor_time}}' AS timestamp))AND block_date <= date(CAST('{{cutoff_time}}' AS timestamp))AND block_time >= CAST('{{floor_time}}' AS timestamp)AND block_time <= CAST('{{cutoff_time}}' AS timestamp)),flows AS ( -- +amount to receiver, -amount from senderSELECT to_owner AS owner, amt AS delta FROM xfers WHERE to_owner IS NOT NULLUNION ALLSELECT from_owner AS owner, -1 * amt AS delta FROM xfers WHERE from_owner IS NOT NULL),bal AS (SELECT owner, SUM(delta) AS balanceFROM flowsGROUP BY ownerHAVING SUM(delta) > 1e-6 -- positive holders only (drop dust/closed)),excl AS ( -- caller-supplied pre-excludes (curve/pools)SELECT TRIM(a) AS addrFROM UNNEST(SPLIT('{{exclude_csv}}', ',')) AS t(a)WHERE TRIM(a) <> ''