Query editor
/* ============================================================================Query 13 — Capital deployed through Revert on Uniswap, net of withdrawalsVisualization: stacked area, x = day, y = deployed_usd, group by venue.----------------------------------------------------------------------------Same standing-balance definition as Queries 10 to 12, for Uniswap v3 and v4.A position counts from the moment it is opened through a Revert contract, andevery later increase and decrease counts wherever it was sent from.v3 values the two legs from the pool's tokens via dex.pools and prices.day.v4 has no per-position token amounts in its events, so value comes from thenet ERC20 flow across the PoolManager singleton in the same transaction.========================================================================== */WITH days AS (SELECT CAST(timestamp AS date) AS day FROM utils.daysWHERE timestamp >= TIMESTAMP '2024-09-01 00:00'AND timestamp <= CAST(current_date AS timestamp))/* Prices are a 7-day rolling MEDIAN, not the daily average.Dune's prices.day on Base carries single-day spikes on thinly traded tokensthat are off by orders of magnitude: RLUSD, a stablecoin, peaks at$623,541,814; SOL at $65,670,340; WBTC at $11,681,212; MOBY at $5,149,375.One such day on one position put this chart at $2.36 QUADRILLION and flattenedevery real series to nothing. A median over the surrounding week removes anisolated spike while leaving a genuine move intact. It is not a blocklist,because the problem is not a handful of tokens.On top of the median, a unit-price ceiling of $200,000. The median removes anisolated spike but not a price that is wrong for months: MOBY sits at$5,149,375 a token for most of its history, and that alone put this chart at$2.36 quadrillion. No fungible token on these chains genuinely trades above$200,000 a unit; the wrapped-BTC variants top out near $124,000, which is theheadroom this leaves. A token over the ceiling is treated as unpriced, so itsleg contributes zero and the position is understated rather than deleted. */, px_raw AS (SELECT CAST(date_trunc('day', timestamp) AS date) AS day, blockchain, contract_address,avg(price) AS price, max(decimals) AS decimalsFROM prices.dayWHERE blockchain IN ('base') AND timestamp >= TIMESTAMP '2024-09-01 00:00'GROUP BY 1, 2, 3), px_win AS (SELECT day, blockchain, contract_address, decimals,array_sort(array_agg(price) OVER (PARTITION BY blockchain, contract_address ORDER BY dayROWS BETWEEN 3 PRECEDING AND 3 FOLLOWING)) AS wFROM px_raw), px AS (SELECT day, blockchain, contract_address, decimals,CASE WHEN element_at(w, (cardinality(w) + 1) / 2) > 200000 THEN NULLELSE element_at(w, (cardinality(w) + 1) / 2) END AS priceFROM px_win), px_last AS (-- most recent known price per token, used when the current day has noneSELECT blockchain, contract_address, max_by(price, day) AS price, max(decimals) AS decimalsFROM px WHERE price IS NOT NULL GROUP BY 1, 2), rc_base AS (SELECT * FROM (VALUES (0x98ec492942090364ac0736ef1a741ae6c92ec790),(0x5b2f7cc65f8eb6222289c714547b9ab22db86be5),(0x36aeae0e411a1e28372e0d66f02e57744ebe7599),(0x5e97a478184993d3e376eec00b603f80463d9b23),(0x16e0b91ce6f1c426df6e2a5a295d113e8f596a93),(0xa387ad72dacc3c884e601ef946bdef739d72a372),(0x0bf485bd7ebb82e282f72e7d14822c680e3f7bec),(0xca7134443f4bd65c4f7ab30983858c239d88b906),(0x043e2ff28db24061d46629b999a358a24c784c69),(0xa8549424b20a514eb9e7a829ec013065bef9dc1d),(0xde3dee3fbd8fd798e69f13de3745867b2b345d6a),(0x5b3b61342c09c9455bd1913cf0be4c13c053d046)) AS t(addr)), inc_base AS (SELECT contract_address AS mgr, tokenId, evt_tx_hash, evt_tx_to, evt_block_time,