Query editor
WITH raw_events AS (-- Combine Mint (Inflow) eventsSELECTevt_block_time,contract_address AS pool_address,amount0,amount1,'mint' AS event_typeFROM aerodrome_base.pool_evt_mintWHERE evt_block_time >= TIMESTAMP '2025-01-01'UNION ALL-- Combine Burn (Outflow) eventsSELECTevt_block_time,contract_address AS pool_address,amount0,amount1,'burn' AS event_typeFROM aerodrome_base.pool_evt_burnWHERE evt_block_time >= TIMESTAMP '2025-01-01'),events_with_tokens AS (SELECTe.evt_block_time,e.event_type,e.amount0,e.amount1,p.token0,p.token1FROM raw_events eLEFT JOIN aerodrome_base.PoolFactory_evt_PoolCreated pON e.pool_address = p.pool),priced_events AS (SELECTDATE_TRUNC('day', e.evt_block_time) AS day,e.event_type,(e.amount0 / POWER(10, COALESCE(p0.decimals, 18))) * COALESCE(p0.price, 0) AS token0_usd,(e.amount1 / POWER(10, COALESCE(p1.decimals, 18))) * COALESCE(p1.price, 0) AS token1_usdFROM events_with_tokens eLEFT JOIN prices.day p0ON p0.blockchain = 'base'AND p0.contract_address = e.token0AND p0.timestamp = DATE_TRUNC('day', e.evt_block_time)LEFT JOIN prices.day p1ON p1.blockchain = 'base'AND p1.contract_address = e.token1AND p1.timestamp = DATE_TRUNC('day', e.evt_block_time)),-- NEW STEP: Drop individual corrupted transactions before summing them upfiltered_priced_events AS (SELECT *FROM priced_events-- If an individual token side calculated over $50M USD, it's a data glitch. Nuke it.WHERE token0_usd < 50000000