Query editor
WITHcore AS ( -- core apxUSD/apyUSD addresses per chain (NOT the dataset's stale derivative rows)SELECT chain, symbol, addressFROM dune.apyx_fi.dataset_apyx_tokensWHERE symbol IN ('apxUSD', 'apyUSD')AND chain IN ('ethereum','base'-- , 'bnb' -- TODO: uncomment once dataset_apyx_tokens holds BNB rows)),-- Curated address -> (venue, role) for the NON-DEX venues. `role` drives the apyUSD layer:-- vault -> the apxUSD backing (decomposed across apyUSD holders, never a bucket itself)-- redemption -> apxUSD in the async unlock pipeline (UnlockReceipt + UnlockToken); its own bucket-- commit -> apxUSD committed via CommitToken (apxUSD only — apyUSD is not committable); own bucket-- venue -> a downstream venue (Pendle / Morpho / Royco). DEX pools are detected dynamically.venue_map AS (SELECT * FROM (VALUES('ethereum', 0x38eeb52f0771140d10c4e9a9a72349a329fe8a6a, 'apyUSD', 'vault'), -- apyUSD ERC-4626 vault('base', 0x2c271ddf484ac0386d216eb7eb9ff02d4dc0f6aa, 'apyUSD', 'vault'), -- apyUSD vault (Base)-- , ('bnb', 0x<apyUSD vault, bnb>, 'apyUSD', 'vault') -- TODO: BNB('ethereum', 0x9bf51f33955ec70f87c4b5c49441815589043237, 'apyUSD', 'redemption'), -- UnlockReceipt (escrow)('ethereum', 0x93775e2dfa4e716c361a1f53f212c7ae031bf4e6, 'apyUSD', 'redemption'), -- UnlockToken('ethereum', 0x17122d869d981d184118b301313bcd157c79871e, 'apyUSD', 'commit'), -- CommitToken: apxUSD (commit — apxUSD only)('ethereum', 0x4f116ee5bcd227d1a1c4f57918d694a4abe7b3fc, 'Pendle', 'venue'), -- Pendle SY-apxUSD('ethereum', 0x04f8dca7bccd8997ac57ca6fef7c705e17d6bcb6, 'Pendle', 'venue'), -- Pendle SY-apyUSD('ethereum', 0xbbbbbbbbbb9cc5e90e3b3af64bdaf62c37eeffcb, 'Morpho', 'venue'), -- Morpho Blue singleton-- Royco apyUSD combined-TVL custodian. NOTE: the senior/junior tranche TOKENS-- (0xbd373c9d3d8976a4fecc504a93c768bbe8c3227c, 0xab2ab53e1e2e2c5d7202918ec8c873712bcc4a2d)-- custody nothing themselves; this contract holds the pooled apyUSD.('ethereum', 0xcfbdea0990f21b103c8d123d0d5273b4ea269cb4, 'Royco', 'venue')) AS t(chain, address, venue, role)),-- Every DEX pool that has traded apxUSD or apyUSD, per chain (Curve, Uniswap V2/V3/V4, …).-- Same discovery as Aggregated DEX Pool Composition, but we do NOT exclude the V4 singleton here.dex_pools AS (SELECT DISTINCT d.blockchain AS chain, d.project_contract_address AS poolFROM dex.trades dINNER JOIN core cON c.chain = d.blockchainAND (d.token_bought_address = c.address OR d.token_sold_address = c.address)WHERE d.blockchain IN ('ethereum','base'-- , 'bnb' -- TODO: uncomment once dataset_apyx_tokens holds BNB rows)AND d.block_month >= DATE '2026-02-01'AND d.block_date >= DATE '2026-02-01'),-- ONE scan of tokens.transfers; unpivot each transfer into a +to / -from leg -> net balance per holder.balances AS (SELECTt.blockchain AS chain,c.symbol AS token,leg.holder,SUM(leg.amt) / 1e18 AS bal,MAX(t.block_time) AS last_timeFROM tokens.transfers tINNER JOIN core cON t.contract_address = c.address