Query editor
WITH latest_day AS (-- First, find the most recent day that had a successful executeSwap callSELECTMAX(date_trunc('day', t.block_time)) AS dayFROMbase.traces tWHEREt."to" = 0x1D3F8fcfE508D7031c242E213B27FbE432f52c67AND substring(t.input from 1 for 4) = 0x37941a72 -- executeSwap()AND t.success = trueAND t.block_time >= TIMESTAMP '2025-09-09 00:00:00'),transfers_with_usd_value AS (-- Next, find all transfers and their USD value at the time of the swapSELECT-- This is the key change: Multiply the CBBTC amount by its price(CAST(transfer.value AS DOUBLE) / 1e8) * p.price AS usd_valueFROMbase.traces tINNER JOIN-- We link the function call to the token transfererc20_base.evt_Transfer transfer ON transfer.evt_tx_hash = t.tx_hashJOINlatest_day l ON date_trunc('day', t.block_time) = l.dayLEFT JOIN-- NEW: Join with historical pricesprices.usd p ON p.minute = date_trunc('minute', t.block_time) -- at the exact minuteAND p.contract_address = 0xcbb7c0000ab88b473b1f5afd9ef808440eed33bf -- of CBBTCAND p.blockchain = 'base'WHEREt."to" = 0x1D3F8fcfE508D7031c242E213B27FbE432f52c67AND substring(t.input from 1 for 4) = 0x37941a72 -- executeSwap()AND t.success = true-- This is the CBBTC transfer event TO your contractAND transfer."to" = 0x1D3F8fcfE508D7031c242E213B27FbE432f52c67AND transfer.contract_address = 0xcbb7c0000ab88b473b1f5afd9ef808440eed33bf -- CBBTC token)-- Finally, calculate the average of all those USD valuesSELECTAVG(usd_value) AS "Average Swap Size in USD (Latest Day)"FROMtransfers_with_usd_value