Query editor
WITH-- cUSD market price derived from pool trades-- Pool: 0xf428bec5f1971186f0921226cd57e6d81e4a28ef (MegaETH)-- cUSD: 0xcccc62962d17b8914c62d74ffb843d73b2a3ccccmarket_price AS (SELECTDATE_TRUNC('day', block_time) AS day,AVG(CASE-- Selling cUSD → buying the other token: price of cUSD = amount_out / amount_inWHEN token_sold_address = 0xcccc62962d17b8914c62d74ffb843d73b2a3ccccTHEN token_bought_amount / NULLIF(token_sold_amount, 0)-- Buying cUSD → selling the other token: price of cUSD = amount_in / amount_outWHEN token_bought_address = 0xcccc62962d17b8914c62d74ffb843d73b2a3ccccTHEN token_sold_amount / NULLIF(token_bought_amount, 0)END) AS cusd_market_price_usdFROM dex.tradesWHEREproject_contract_address = 0xf428bec5f1971186f0921226cd57e6d81e4a28efAND block_time >= NOW() - INTERVAL '90' DAY-- Filter out outliers / bad dataAND (CASEWHEN token_sold_address = 0xcccc62962d17b8914c62d74ffb843d73b2a3ccccTHEN token_bought_amount / NULLIF(token_sold_amount, 0)WHEN token_bought_address = 0xcccc62962d17b8914c62d74ffb843d73b2a3ccccTHEN token_sold_amount / NULLIF(token_bought_amount, 0)END) BETWEEN 0.85 AND 1.15GROUP BY 1),-- Daily trade volume for contextdaily_volume AS (SELECTDATE_TRUNC('day', block_time) AS day,COUNT(*) AS trade_count,SUM(amount_usd) AS volume_usdFROM dex.tradesWHEREproject_contract_address = 0xf428bec5f1971186f0921226cd57e6d81e4a28efAND block_time >= NOW() - INTERVAL '90' DAYGROUP BY 1),-- Rolling 7-day volatility of the peg deviationpeg_with_stats AS (SELECTm.day,m.cusd_market_price_usd,-- Deviation from $1 peg (basis points: 1 bp = 0.0001)(m.cusd_market_price_usd - 1.0) AS peg_deviation,(m.cusd_market_price_usd - 1.0) * 10000 AS peg_deviation_bps,-- 7-day rolling stddev of price as a volatility proxySTDDEV(m.cusd_market_price_usd) OVER (ORDER BY m.dayROWS BETWEEN 6 PRECEDING AND CURRENT ROW) AS rolling_7d_volatility,v.trade_count,