Query editor
WITH-- 1. Calculate Daily Gas Consumed on the Ethereum Mainnet (~100 Billion daily)eth_gas AS (SELECTDATE_TRUNC('day', time) AS date,SUM(CAST(gas_used AS DOUBLE)) AS total_daily_gasFROM ethereum.blocksWHERE time >= CURRENT_DATE - INTERVAL '365' DAYGROUP BY 1),-- 2. Fetch Daily ETH Token Price using Standardized Native Keyeth_price AS (SELECTDATE_TRUNC('day', timestamp) AS date,AVG(price) AS token_priceFROM prices.dayWHERE blockchain = 'ethereum'AND contract_address = 0x0000000000000000000000000000000000000000AND timestamp >= CURRENT_DATE - INTERVAL '365' DAYGROUP BY 1),-- 3. Merge Datasets and Compute the Raw Valuation Ratioraw_metrics AS (SELECTg.date,-- Formula: Total Gas / (Price * 120M Circulating Supply)(g.total_daily_gas / (p.token_price * 120000000.0)) AS raw_ratioFROM eth_gas gJOIN eth_price p ON g.date = p.date)-- 4. Apply 7-Day Moving Average Line & Hardcode Alert ThresholdSELECTdate,-- Removed the multiplier to keep values matching a raw baselineAVG(raw_ratio) OVER (ORDER BY dateROWS BETWEEN 6 PRECEDING AND CURRENT ROW) AS eth_utility_scaled_7d_sma,-- Perfectly balanced baseline adjusted to split right through the center of the raw scale0.22 AS balanced_alert_thresholdFROM raw_metricsORDER BY date DESC;