Query editor
WITH target_token AS (-- 1. Hardcode the cRECY Celo addressSELECT 0x34c11a932853ae24e845ad4b633e3cef91afe583 AS contract_address),crecy_trades AS (-- 2. Pull every trade involving cRECY across ALL decentralized exchanges on CeloSELECTblock_time,project AS dex_name,CASEWHEN token_bought_address = (SELECT contract_address FROM target_token) THEN token_sold_addressELSE token_bought_addressEND AS paired_token,-- Calculate the exact ratio. dex.trades amounts are already decimal-adjusted!CASEWHEN token_bought_address = (SELECT contract_address FROM target_token)THEN token_sold_amount / NULLIF(token_bought_amount, 0)ELSE token_bought_amount / NULLIF(token_sold_amount, 0)END AS raw_ratioFROM dex.tradesWHERE blockchain = 'celo'AND (token_bought_address = (SELECT contract_address FROM target_token)OR token_sold_address = (SELECT contract_address FROM target_token))),paired_prices AS (-- 3. Fetch Daily USD Prices for the Paired TokensSELECTdate_trunc('day', timestamp) AS day,contract_address,price AS usd_priceFROM prices.dayWHERE blockchain = 'celo'),priced_swaps AS (-- 4. Calculate the exact USD price for every single swapSELECTct.block_time,date_trunc('day', ct.block_time) AS day,ct.dex_name,ROUND(ct.raw_ratio * pp.usd_price, 4) AS swap_price_usdFROM crecy_trades ctINNER JOIN paired_prices ppON ct.paired_token = pp.contract_addressAND date_trunc('day', ct.block_time) = pp.day),daily_history AS (-- 5. Aggregate into daily averages with 4 decimals, excluding 2026-05-22SELECTday,ROUND(AVG(swap_price_usd), 4) AS daily_avg_price_usdFROM priced_swapsWHERE day <> DATE '2026-05-22'GROUP BY day),date_range AS (-- 6. Get min and max dates as DATE typeSELECTCAST(MIN(day) AS date) AS min_day,CAST(CURRENT_DATE AS date) AS max_dayFROM daily_history