Query editor
-- Amp DEX Liquidity-- Dune query 2813063: https://dune.com/queries/2813063-- From dashboard: https://dune.com/ampdotxyz/amp-token---- TVL of AMP liquidity pools per DEX. Pools are discovered dynamically from-- factory creation events (any new AMP pool is picked up automatically):-- Uniswap V2 / Sushi: factory_evt_paircreated (token0/token1 = AMP)-- Uniswap V3: factory_evt_poolcreated (token0/token1 = AMP)-- Bancor: legacy static list (protocol deprecated, no new pools)-- TVL for those pools = current balance of every token the pool holds-- (reconstructed from transfers), valued at prices.usd_latest.---- Uniswap V4 is a singleton: all pools' tokens sit inside the PoolManager, so-- per-pool address balances don't exist. The PoolManager's AMP balance is an-- exact measure of the AMP side of all v4 AMP pools; total v4 TVL is-- approximated as 2x that (balanced-liquidity assumption -- exact for the AMP-- side, approximate for the paired side).WITHpools AS (SELECT 'Uniswap V2' AS dex, pair AS poolFROM uniswap_v2_ethereum.factory_evt_paircreatedWHERE token0 = 0xfF20817765cB7f73d4bde2e66e067E58D11095C2OR token1 = 0xfF20817765cB7f73d4bde2e66e067E58D11095C2UNION ALLSELECT 'Uniswap V3', poolFROM uniswap_v3_ethereum.factory_evt_poolcreatedWHERE token0 = 0xfF20817765cB7f73d4bde2e66e067E58D11095C2OR token1 = 0xfF20817765cB7f73d4bde2e66e067E58D11095C2UNION ALLSELECT 'Sushi', pairFROM sushi_ethereum.factory_evt_paircreatedWHERE token0 = 0xfF20817765cB7f73d4bde2e66e067E58D11095C2OR token1 = 0xfF20817765cB7f73d4bde2e66e067E58D11095C2UNION ALL-- Bancor v2/v3 AMP pools (deprecated protocol; addresses are final)SELECT 'Bancor', poolFROM (VALUES(0x0f4a8a06c22ba49e98d15223a701062c40873f7a),(0x6a74941c1cf4151b3f15cdd84ee3abde713a999b),(0x2f9ec37d6ccfff1cab21733bdadede11c823ccb0)) AS v(pool)),-- every token flow in/out of any pool (single transfer scan, both sides)legs AS (SELECT f.dex, tr.contract_address AS token_address, f.amountFROM erc20_ethereum.evt_Transfer trLEFT JOIN pools pt ON pt.pool = tr."to"LEFT JOIN pools pf ON pf.pool = tr."from"CROSS JOIN UNNEST(ARRAY[ROW(pt.dex, CAST(tr.value AS int256)),ROW(pf.dex, -CAST(tr.value AS int256))]