Query editor
-- Amp Holders Over Time-- Dune query 381317: https://dune.com/queries/381317-- From dashboard: https://dune.com/ampdotxyz/amp-token---- Daily count of addresses holding any AMP, where effective holdings =-- wallet balance + staked in Flexa Capacity v2 + staked in Flexa Capacity v3. An address that stakes its entire balance still counts as-- a holder (staking moves tokens to the custodian, but they remain the-- staker's AMP).---- Flow ledger per address:-- * wallet: every AMP transfer, +to / -from-- * v2 stake: transfers into the v2 Collateral Manager credit the staker,-- transfers out debit the recipient (net zero vs the wallet leg,-- so staking does not change effective holdings)-- * v3 stake: decoded pool events (anvil_ethereum.timebasedcollateralpool_evt_*):-- CollateralStaked(account, token, amount, poolUnitsIssued) -> +units-- UnstakeInitiated(account, token, unitsToUnstake, ...) -> -units-- Units are 1:1 with AMP until a pool claim or reset (none to date).-- Between unstake initiation and token release the tokens are in-- transit and count for neither leg.---- Counting uses threshold-crossing events (+1 when an address rises above the-- threshold, -1 when it falls below) with a running sum over a daily calendar,-- instead of materializing one row per holder per day.WITHflows AS (-- wallet leg: single transfer scan, both sidesSELECTDATE_TRUNC('day', tr.evt_block_time) AS day,f.address,f.amountFROM erc20_ethereum.evt_Transfer trCROSS JOIN UNNEST(ARRAY[ROW(tr."from", -CAST(tr.value AS int256)),ROW(tr."to", CAST(tr.value AS int256))]) AS f(address, amount)WHERE tr.contract_address = 0xff20817765cb7f73d4bde2e66e067e58d11095c2UNION ALL-- v2 staking leg: net AMP moved into/out of the Collateral Manager,-- credited to the staker / debited from the withdrawal recipientSELECTDATE_TRUNC('day', tr.evt_block_time) AS day,f.address,f.amountFROM erc20_ethereum.evt_Transfer trCROSS JOIN UNNEST(ARRAY[ROW(CASE WHEN tr."to" = 0x706d7f8b3445d8dfc790c524e3990ef014e7c578THEN tr."from" END, CAST(tr.value AS int256)),ROW(CASE WHEN tr."from" = 0x706d7f8b3445d8dfc790c524e3990ef014e7c578THEN tr."to" END, -CAST(tr.value AS int256))]) AS f(address, amount)WHERE tr.contract_address = 0xff20817765cb7f73d4bde2e66e067e58d11095c2AND (tr."to" = 0x706d7f8b3445d8dfc790c524e3990ef014e7c578OR tr."from" = 0x706d7f8b3445d8dfc790c524e3990ef014e7c578)