Query editor
WITH bot_attacks AS (SELECTd.project AS dex_name,d.tx_hash,d.amount_usdFROM dex.trades dINNER JOIN ethereum.transactions tON d.tx_hash = t.hashAND d.block_date = t.block_dateAND t.block_date >= CURRENT_DATE - INTERVAL '3' dayWHERE d.blockchain = 'ethereum'AND d.block_time >= CURRENT_DATE - INTERVAL '3' day-- Proxy, not ground truth: >20 Gwei priority fee captures searchers,-- their victims, liquidations and merely urgent users alike.AND t.priority_fee_per_gas > 20000000000),dex_stats AS (SELECTdex_name,-- dex.trades is one row per swap LEG, so a multi-hop route counts-- more than once. distinct_txs is the transaction-level figure.COUNT(*) AS trade_legs,COUNT(DISTINCT tx_hash) AS distinct_txs,-- amount_usd is notional swap size, NOT extracted profit.COUNT(amount_usd) AS legs_priced,APPROX_PERCENTILE(amount_usd, 0.5) AS median_size_usd,AVG(amount_usd) AS avg_size_usd,MAX(amount_usd) AS max_size_usd,SUM(amount_usd) AS total_size_usdFROM bot_attacksGROUP BY dex_name)SELECTdex_name,trade_legs,distinct_txs,-- >1.0 means routing inflates this venue's countCAST(trade_legs AS DOUBLE) / NULLIF(distinct_txs, 0) AS legs_per_tx,CAST(trade_legs AS DOUBLE) / SUM(trade_legs) OVER () * 100 AS share_pct,legs_priced,median_size_usd,avg_size_usd,max_size_usd,-- share of this venue's notional coming from its single largest trademax_size_usd / NULLIF(total_size_usd, 0) * 100 AS top_trade_pctFROM dex_statsORDER BY trade_legs DESCLIMIT 10