Query editor
-- Stonks Exchange — the RECENT tail of the trade history: the last twelve days.---- Twelve days is not a display window, it is the safety margin. The settled half is rebuilt weekly-- with a two-day cutoff, so it can sit up to nine days behind; a tail shorter than that would leave-- a hole between the two exactly where nobody would look for it. Twelve covers nine with room.---- Scanning twelve days of dex.trades instead of the whole history is what makes an hourly refresh-- affordable.---- 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 >= greatest(DATE '2026-08-17', current_date - INTERVAL '12' 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.*,tr.quote_amount * p.price AS usdFROM trades trLEFT JOIN prices.minute p