Query editor
-- [CA] S-DATA-02 — New pools: TRUE age + first 30min / 1h / 24h metrics -> H1, H2---- WHY THE OBVIOUS VERSION IS WRONG: Q6 (8725759) took the first trade INSIDE a-- 30d window, so every pool that already existed was dated to the window edge-- and counted as "new". Fix: scan a WIDER window (120d) and keep only pools-- whose first trade lands inside the last 90d AND strictly after the 120d-- boundary. A pool whose first seen trade IS the boundary is older than the-- scan, so its true age is unknown -> excluded, never guessed.---- H1: >=50 unique buyers AND >=$50k volume in the first 60 min -> P(+50% / 24h).-- H2: LP locked/burned AND top-1 holder <20% -> lower rug rate.-- This query supplies the SIGNAL side only. Two things are deliberately NOT-- here: (a) the OUTCOME side (price at t0 and t0+24h) is joined locally from-- prices.hour by token address; (b) top-1 HOLDER share needs token balances-- (S-DATA-08 territory), not DEX trades.---- Single scan of dex.trades: t0 is attached with a window function so the-- table is read ONCE (a self-join CTE would be inlined and scanned twice,-- roughly doubling the credit cost).SELECT blockchain,project_contract_address,MAX(project) AS project,MIN(t0) AS first_trade,MAX(token_sold_address) AS token_a,MAX(token_bought_address) AS token_b,-- first 30 minutesSUM(CASE WHEN block_time <= t0 + INTERVAL '30' MINUTE THEN amount_usd ELSE 0 END) AS vol_30m,COUNT_IF(block_time <= t0 + INTERVAL '30' MINUTE) AS trades_30m,COUNT(DISTINCT CASE WHEN block_time <= t0 + INTERVAL '30' MINUTETHEN tx_from END) AS buyers_30m,-- first hourSUM(CASE WHEN block_time <= t0 + INTERVAL '1' HOUR THEN amount_usd ELSE 0 END) AS vol_1h,COUNT_IF(block_time <= t0 + INTERVAL '1' HOUR) AS trades_1h,COUNT(DISTINCT CASE WHEN block_time <= t0 + INTERVAL '1' HOURTHEN tx_from END) AS buyers_1h,-- first 24 hoursSUM(CASE WHEN block_time <= t0 + INTERVAL '24' HOUR THEN amount_usd ELSE 0 END) AS vol_24h,COUNT_IF(block_time <= t0 + INTERVAL '24' HOUR) AS trades_24h,COUNT(DISTINCT CASE WHEN block_time <= t0 + INTERVAL '24' HOURTHEN tx_from END) AS buyers_24h,COUNT(DISTINCT CASE WHEN block_time <= t0 + INTERVAL '24' HOURTHEN tx_to END) AS sellers_24h,-- lifetime inside the scanned windowSUM(amount_usd) AS vol_window_total,COUNT(*) AS trades_window_total,date_diff('minute', MIN(t0), MAX(block_time)) AS lifetime_minFROM (SELECT blockchain, project, project_contract_address, block_time, amount_usd,tx_from, tx_to, token_sold_address, token_bought_address,MIN(block_time) OVER (PARTITION BY blockchain,project_contract_address) AS t0FROM dex.tradesWHERE blockchain IN ('ethereum', 'base')AND block_month >= date_trunc('month', now() - INTERVAL '125' DAY)AND block_time >= now() - INTERVAL '120' DAY) xWHERE t0 >= now() - INTERVAL '90' DAYAND t0 > now() - INTERVAL '119' DAYGROUP BY 1, 2HAVING SUM(amount_usd) >= 10000 -- drop dust launches (keeps the row count sane)