Query editor
-- This query calculates the daily median market price of the WELL token on Base-- using the dex.trades table for maximum accuracy.WITH-- Calculate the median price of WELL in terms of WETH from all trades on Base.well_weth_daily_price AS (SELECTDATE_TRUNC('day', block_time) AS day,APPROX_PERCENTILE(-- Price = WETH amount / WELL amountCASEWHEN token_bought_address = 0xA88594D404727625A9437C3f886C7643872296AE THEN token_sold_amount / token_bought_amountWHEN token_sold_address = 0xA88594D404727625A9437C3f886C7643872296AE THEN token_bought_amount / token_sold_amountEND,0.5) AS well_in_wethFROM dex.tradesWHEREblockchain = 'base'AND ((token_bought_address = 0xA88594D404727625A9437C3f886C7643872296AE AND token_sold_address = 0x4200000000000000000000000000000000000006) OR(token_bought_address = 0x4200000000000000000000000000000000000006 AND token_sold_address = 0xA88594D404727625A9437C3f886C7643872296AE))AND token_bought_amount > 0 AND token_sold_amount > 0GROUP BY 1),-- Get the daily price of WETH in USD.weth_daily_price AS (SELECTDATE_TRUNC('day', minute) AS day,APPROX_PERCENTILE(price, 0.5) AS weth_in_usdFROM prices.usdWHERE contract_address = 0x4200000000000000000000000000000000000006 -- WETH on BaseAND blockchain = 'base'GROUP BY 1)-- Combine them to get the final WELL price in USD.SELECTw.day,w.weth_in_usd * p.well_in_weth AS well_market_price_usdFROM weth_daily_price wJOIN well_weth_daily_price p ON w.day = p.dayWHERE w.day >= CAST('2025-06-12' AS TIMESTAMP) -- Filter for recent activityORDER BY 1 DESC