Query editor
-- ============================================================================-- WALLET-SET RESEARCH (owner 2026-09-02): ten selection variants in ONE pass over the August-- layer, output = (variant, rank, wallet) ONLY (~15k rows x 3 cols -> ~45k datapoints; reading-- results is billed per datapoint, see REBUILD.md s5).---- Source: dune.scopix_team.result_rh_t01b (wallet x token, sliding 31-day window, FLOW s3). SELECTION WINDOW =-- positions FIRST BOUGHT before 2026-08-16 (5-day quarantine before the Aug 21+ evaluation-- window). Caveat (documented): sells after Aug 15 of positions opened before it still count in-- realized PnL — the layer carries no sell timestamps; accepted for the free first pass.---- Gates mirror queries/own_dex_L3_leaderboard.sql byte-for-byte in semantics (pnl, closed,-- vol_share, is_sniper, deployer/anomalous class); extra follower metrics: median closed-cycle-- multiple (approx_percentile), share of cycles >= 1.5x, weeks with positive realized PnL.-- ============================================================================WITH chunks AS (-- TWO CHUNKS, NOT ONE MATVIEW (2026-09-18). A single 31-day layer stopped fitting cluster-- memory once the universe grew 58%: 31 days and 18 days both failed with `exceeds cluster-- capacity`, while 16 days built (11.58M rows, 117.8 credits). So the window is assembled from-- two builds of the SAME SQL with only its three dates moved:-- result_rh_t01b 2026-09-03 .. 2026-09-19 (16 days, the live layer)-- result_rh_t01b_aug 2026-08-19 .. 2026-09-03 (15 days, 02a_layer_L2_chunk_aug.sql)-- UNION ALL, never UNION: the rows are DISJOINT by construction (the windows do not overlap),-- so a distinct would only pay to prove that.-- ⚠️ `first_buy IS NULL OR ...` IS NOT DEFENSIVE PADDING — MEASURED 2026-09-18. A row with-- SELLS BUT NO BUYS in its window has `first_buy = NULL` (582,417 such rows in the September-- chunk alone), and `NULL < TIMESTAMP` is NULL, so a bare comparison DROPS every one of them.-- That silently decapitates positions that straddle the chunk boundary: 119,646 positions held-- by 51,680 wallets were bought in August and sold in September, and without this clause the-- September half never reaches the merge — the position reads as still OPEN and the wallet-- fails the v8 closed-cycle gate for a sale it actually made.---- The selection bound lives HERE, in the literal form `first_buy < TIMESTAMP '...'`, because-- analysis/wallet-sets/rank_cut.py rewrites exactly that string and asserts it appears ONCE.-- Writing it as `MIN(first_buy) < ...` in the HAVING below hid it from the tool, which then-- refused to run rather than silently ranking on the wrong date -- the assert did its job.-- Filtering before the aggregate is also cheaper: fewer rows reach the GROUP BY.SELECT wallet, token, token_first_trade, first_buy,bought_qty, bought_usd, sold_qty, sold_usd, legsFROM dune.scopix_team.result_rh_t01bWHERE (first_buy IS NULL OR first_buy < TIMESTAMP '2026-09-12 00:00:00')UNION ALLSELECT wallet, token, token_first_trade, first_buy,bought_qty, bought_usd, sold_qty, sold_usd, legsFROM dune.scopix_team.result_rh_t01b_augWHERE (first_buy IS NULL OR first_buy < TIMESTAMP '2026-09-12 00:00:00')),src AS (-- RE-AGGREGATE ACROSS THE CHUNK BOUNDARY. A wallet that bought a token in August AND in-- September has ONE row per chunk, and every gate below assumes ONE row per (wallet, token):-- without this, its volume would be split in two, its `legs` halved, and a position closed-- across the boundary would look like two unfinished ones. Sums add; the two timestamps take-- the EARLIEST, which is what both mean (`first_buy` = when this wallet first bought,-- `token_first_trade` = the token's first priced trade seen by the layer).SELECT wallet, token,MIN(token_first_trade) AS token_first_trade,MIN(first_buy) AS first_buy,SUM(bought_qty) AS bought_qty,SUM(bought_usd) AS bought_usd,SUM(sold_qty) AS sold_qty,SUM(sold_usd) AS sold_usd,