Query editor
-- Stonks Exchange — the SETTLED part of the trade history: everything older than two days.---- Split out from the recent tail because rebuilding the whole series was the single most expensive-- thing on this account — 16.5 credits a run against a 4,000/month allowance, and growing with every-- day of history. This half is rebuilt WEEKLY; the tail carries the freshness. Cost now stops-- growing with history instead of climbing forever.---- Its cutoff is two days back AT BUILD TIME, so between weekly rebuilds it reaches at worst nine-- days behind today. The tail's window is deliberately much wider than that, which is what-- guarantees the two always overlap and never leave a gap.---- Volume deliberately does NOT come from the StonkTradeRouter's own Buy/Sell events: those fire-- only for trades routed through our UI, and miss anything that reaches the pool from DexScreener,-- an aggregator, or a bot. The pool is the honest denominator, so this reads dex.trades and keeps-- "came through our router" as a separate metric elsewhere.---- dex.trades.amount_usd is unusable here. It is populated for the WETH-quoted pools and null for-- every equity- and STONKEX-quoted one, which would have silently reported a third of real volume.-- The USD figure below is built from the quote leg against prices.minute, which does carry all of-- them (AAPLc, NVDAc, cbZEC, STONKEX included).WITH launches AS (-- Reads the materialized launches table, not the query that builds it. As a nested view every-- downstream chart re-decoded the launcher's logs and re-ran three token joins before it could-- start; against the matview the same join is a scan of a few hundred rows.SELECT token, quote, pool, quote_symbol, token_symbol, quote_categoryFROM dune.stonks_exchange.result_stonks_launches),trades AS (SELECTt.block_time,t.block_date,t.tx_hash,t.tx_from AS trader,l.token,l.token_symbol,l.quote,l.quote_symbol,l.quote_category,l.pool,-- Buying the coin spends the quote; selling it returns quote. Naming the side from the-- quote leg keeps this correct whichever token0/token1 ordering the pool ended up with.CASE WHEN t.token_bought_address = l.quote THEN 'sell' ELSE 'buy' END AS side,CASE WHEN t.token_bought_address = l.quoteTHEN t.token_bought_amount ELSE t.token_sold_amount END AS quote_amount,CASE WHEN t.token_bought_address = l.tokenTHEN t.token_bought_amount ELSE t.token_sold_amount END AS token_amountFROM dex.trades tJOIN launches l ON t.project_contract_address = l.poolWHERE t.blockchain = 'base'AND t.block_date >= DATE '2026-08-17'AND t.block_date < current_date - INTERVAL '2' DAY)-- prices.minute is filtered on its own partition columns (blockchain + timestamp) and joined-- directly. Restricting it instead with `contract_address IN (SELECT ... FROM launches)` reads as-- the tighter filter but defeats partition pruning: the planner cannot resolve the subquery before-- the scan, so it walks every token on every chain and the query goes from seconds to minutes.SELECTtr.*,