Query editor
WITH usdf_trades AS (SELECTDATE_TRUNC('day', t.block_time) AS dt,t.blockchain,t.project_contract_address,t.token_pair, -- human-readable pool labelt.amount_usd,-- Slippage proxy vs $1 on the USDF leg (only when USDF is on that side)CASEWHEN (t.blockchain = 'ethereum' AND t.token_bought_address = 0xFa2B947eEc368f42195f24F36d2aF29f7c24CeC2)OR (t.blockchain = 'bnb' AND t.token_bought_address = 0xb3b02e4a9fb2bd28cc2ff97b0ab3f6b3ec1ee9d2)THEN (t.token_bought_amount - t.amount_usd) / NULLIF(t.amount_usd, 0)WHEN (t.blockchain = 'ethereum' AND t.token_sold_address = 0xFa2B947eEc368f42195f24F36d2aF29f7c24CeC2)OR (t.blockchain = 'bnb' AND t.token_sold_address = 0xb3b02e4a9fb2bd28cc2ff97b0ab3f6b3ec1ee9d2)THEN (t.amount_usd - t.token_sold_amount) / NULLIF(t.amount_usd, 0)ELSE NULLEND AS slippage_pct,-- Trade-size buckets (USD notional)CASEWHEN t.amount_usd >= 10000 AND t.amount_usd < 50000 THEN 'small'WHEN t.amount_usd >= 50000 AND t.amount_usd < 250000 THEN 'mid'WHEN t.amount_usd >= 250000 AND t.amount_usd < 1000000 THEN 'large'WHEN t.amount_usd >= 1000000 THEN 'whale'ELSE NULLEND AS size_binFROM dex.trades tWHERE t.blockchain IN ('ethereum','bnb')AND t.amount_usd IS NOT NULLAND t.amount_usd >= 10000AND (-- USDF (ETH)(t.blockchain = 'ethereum' AND (t.token_bought_address = 0xFa2B947eEc368f42195f24F36d2aF29f7c24CeC2OR t.token_sold_address = 0xFa2B947eEc368f42195f24F36d2aF29f7c24CeC2))-- USDF (BNB)OR (t.blockchain = 'bnb' AND (t.token_bought_address = 0xb3b02e4a9fb2bd28cc2ff97b0ab3f6b3ec1ee9d2OR t.token_sold_address = 0xb3b02e4a9fb2bd28cc2ff97b0ab3f6b3ec1ee9d2)))),btc_daily_prices AS (SELECTDATE_TRUNC('day', minute) AS dt,MAX(price) AS btc_priceFROM prices.usdWHERE symbol = 'BTC' AND price IS NOT NULLGROUP BY 1),btc_returns AS (SELECTdt,LN(btc_price / LAG(btc_price) OVER (ORDER BY dt)) AS log_returnFROM btc_daily_prices),btc_volatility AS (SELECT