Query editor
-- Amp Holders & Stakers-- Dune query 2262211: https://dune.com/queries/2262211-- From dashboard: https://dune.com/ampdotxyz/amp-token---- One row per address: AMP wallet balance, staked amount (Flexa Capacity v2 + v3),-- combined total, USD value, first-received / last-activity dates, and a label.-- * first_received: date of first incoming AMP transfer (or first v3 stake event-- if earlier / no transfer exists for the address), linked to its tx on Etherscan-- * last_activity: date of latest AMP transfer in either direction or v3-- stake/unstake event, linked to its tx on Etherscan and suffixed with the-- activity kind: (in) / (out) / (stake) / (unstake). Transfers to/from the-- v2 Collateral Manager count as stake/unstake; on a same-block tie the v3-- event kind wins over its own transfer leg.-- * balance: net of all AMP ERC-20 transfers (single scan, +to / -from)-- * v2 staked: net AMP transferred to/from the v2 Collateral Manager-- * v3 staked: decoded pool events (anvil_ethereum.timebasedcollateralpool_evt_*):-- CollateralStaked(account, token, amount, poolUnitsIssued) -> +units issued-- UnstakeInitiated(account, token, unitsToUnstake, ...) -> -units queued-- Covers every entry path (stake, depositAndStake, stakeReleasableTokensFrom,-- multisig / ERC-4337 wrappers) and credits the actual staking account rather-- than the transaction sender. Units convert 1:1 to AMP until a pool claim or-- reset changes the ratio (none have occurred to date).WITH-- every AMP transfer, emitted once per side (single table scan)transfer_flows AS (-- kind: transfers to/from the v2 Collateral Manager are v2 stakes/unstakes,-- everything else is a plain out/inSELECT f.holder, f.amount, f.kind, tr.evt_block_time AS block_time, tr.evt_tx_hash AS tx_hashFROM erc20_ethereum.evt_Transfer trCROSS JOIN UNNEST(ARRAY[ROW(tr."from", -CAST(tr.value AS int256),CASE WHEN tr."to" = 0x706d7f8b3445d8dfc790c524e3990ef014e7c578THEN 'stake' ELSE 'out' END),ROW(tr."to", CAST(tr.value AS int256),CASE WHEN tr."from" = 0x706d7f8b3445d8dfc790c524e3990ef014e7c578THEN 'unstake' ELSE 'in' END)]) AS f(holder, amount, kind)WHERE tr.contract_address = 0xff20817765cb7f73d4bde2e66e067e58d11095c2),holders_grouped AS (SELECT holder, SUM(amount) / 1e18 AS balanceFROM transfer_flowsGROUP BY 1HAVING SUM(amount) > CAST(0 AS int256)),-- first incoming AMP transfer and latest AMP transfer (either direction) per-- address, each with its transaction hash (MIN_BY/MAX_BY ignore NULL keys, so-- the outgoing-only CASE rows don't affect the "first received" pick)transfer_dates AS (SELECTholder,MIN(CASE WHEN amount > CAST(0 AS int256) THEN block_time END) AS first_received_at,MIN_BY(tx_hash,CASE WHEN amount > CAST(0 AS int256) THEN block_time END) AS first_received_tx,MAX(block_time) AS last_transfer_at,MAX_BY(tx_hash, block_time) AS last_transfer_tx,