Query editor
-- [CA] WASH — Wash-trading metrics per chain/day (reusable)-- Stage 4.5 of the methodology, formalised after the 2026-09-06 case-- (Ethereum DEX volume $156.07B = x98 the 30d median with NORMAL trade and-- trader counts -> synthetic volume, not a market event).---- Output is one row per (blockchain, day) with the inputs needed to compute a-- wash share. Thresholds are applied LOCALLY by scripts/wash_check.py so they-- can be tuned without re-running the query.---- Signals produced:-- vol_total - gross volume-- vol_hft - volume from addresses doing >100 swaps that day-- traders_hft - how many such addresses-- vol_self - volume where tx_from = tx_to (self-trade)-- vol_top1 - largest single-trader volume (concentration)-- vol_round - volume in "round" USD amounts---- ⚠️ BUG FIXED (2026-09-15, first run 248 rows, execution 01M2JRJTT6C063JAF55DQSZ2J6):-- v1 wrote `SUM(CASE WHEN swaps_of_trader > 100 THEN trader_vol ...)`, where-- `trader_vol` is the per-trader DAILY TOTAL. Because the window column is-- repeated on every trade row, that sum multiplied each HFT trader's total by-- their own trade count -> vol_hft came out 600x LARGER than vol_total-- (arbitrum: 50.58e9 vs 84.9e6) and traders_hft (117 210) exceeded traders-- (8 043). v2 sums `amount_usd` (per-trade) instead, and counts DISTINCT-- traders. Never SUM a window aggregate over the rows that produced it.---- WINDOW: 30 days, matching the M1 daily mart, so wash shares can be joined to-- M1 row-for-row. For H13 (full train window) use the long-window variant.SELECT date_trunc('day', block_time) AS day,blockchain,SUM(amount_usd) AS vol_total,COUNT(*) AS swaps_total,COUNT(DISTINCT tx_from) AS traders,SUM(CASE WHEN swaps_of_trader > 100 THEN amount_usd ELSE 0 END) AS vol_hft,COUNT(DISTINCT CASE WHEN swaps_of_trader > 100 THEN tx_from END) AS traders_hft,SUM(CASE WHEN tx_from = tx_to THEN amount_usd ELSE 0 END) AS vol_self,MAX(trader_vol) AS vol_top1,SUM(CASE WHEN amount_usd >= 1000AND amount_usd / 1000 = FLOOR(amount_usd / 1000)THEN amount_usd ELSE 0 END) AS vol_roundFROM (SELECT block_time, blockchain, amount_usd, tx_from, tx_to,COUNT(*) OVER (PARTITION BY blockchain,date_trunc('day', block_time),tx_from) AS swaps_of_trader,SUM(amount_usd) OVER (PARTITION BY blockchain,date_trunc('day', block_time),tx_from) AS trader_volFROM dex.tradesWHERE blockchain IN ('ethereum', 'base', 'arbitrum', 'polygon','bnb', 'optimism', 'avalanche_c', 'unichain')AND block_month >= date_trunc('month', now() - interval '32' day)AND block_time >= now() - interval '30' day)GROUP BY 1, 2ORDER BY 1 DESC, 2