Query editor
WITH threshold_config AS (SELECT1000 as danger_bot_tx_threshold,500 as danger_tip_gwei_threshold,500 as warning_bot_tx_threshold,200 as warning_tip_gwei_threshold),hourly_stats AS (SELECTdate_trunc('hour', block_time) as hour,AVG(priority_fee_per_gas / 1e9) as avg_tip_gwei,MAX(priority_fee_per_gas / 1e9) as max_tip_gweiFROM ethereum.transactionsWHERE block_time >= CURRENT_TIMESTAMP - INTERVAL '1' DAYAND priority_fee_per_gas IS NOT NULLGROUP BY date_trunc('hour', block_time)),bot_txs AS (SELECTdate_trunc('hour', t.block_time) as hour,COUNT(*) as bot_tx_count,SUM(CAST(t.priority_fee_per_gas AS DOUBLE) * CAST(t.gas_used AS DOUBLE) / 1e18) as eth_burned_by_botsFROM ethereum.transactions tINNER JOIN hourly_stats hON date_trunc('hour', t.block_time) = h.hourWHERE t.block_time >= CURRENT_TIMESTAMP - INTERVAL '1' DAYAND t.priority_fee_per_gas IS NOT NULLAND CAST(t.priority_fee_per_gas AS DOUBLE) / 1e9 > 5 * h.avg_tip_gweiGROUP BY date_trunc('hour', t.block_time)),with_averages AS (SELECTh.hour as date_utc,h.avg_tip_gwei,h.max_tip_gwei,COALESCE(b.bot_tx_count, 0) as bot_tx_count,COALESCE(b.eth_burned_by_bots, 0) as eth_burned_by_bots,AVG(COALESCE(b.bot_tx_count, 0)) OVER (ORDER BY h.hourROWS BETWEEN 168 PRECEDING AND 1 PRECEDING) as avg_7d_bot_tx_count,AVG(h.max_tip_gwei) OVER (ORDER BY h.hourROWS BETWEEN 168 PRECEDING AND 1 PRECEDING) as avg_7d_max_tipFROM hourly_stats hLEFT JOIN bot_txs b ON h.hour = b.hour),with_deviations AS (SELECTdate_utc,avg_tip_gwei,max_tip_gwei,bot_tx_count,eth_burned_by_bots,avg_7d_bot_tx_count,avg_7d_max_tip,CASEWHEN avg_7d_bot_tx_count = 0 OR avg_7d_bot_tx_count IS NULL THEN NULLELSE ROUND((bot_tx_count - avg_7d_bot_tx_count) / avg_7d_bot_tx_count * 100, 1)