Query editor
-- Expanded 1/128 sample; compute P&L only for M12-retained January entrants.-- Snapshot cohort avoids rescanning 13 months of historical first trades.-- All Solana DEXs; pump-suffix tokens are a memecoin proxy.-- Per-wallet P&L sums all token positions BEFORE classifying profitability.-- Unpriced residual holdings are marked at zero, with explicit coverage flags.-- Negative inventory signals missing acquisition basis; those wallets remain-- in retention but are excluded from the profitability denominator downstream.WITH cohort AS (SELECT walletFROM dune.defiance_cr.dataset_trader_retention_m12_wallets_20260905WHERE venue = 'Solana memecoins'), position_ledger AS (SELECT t.trader_id AS wallet, l.token_id,sum(IF(l.is_buy, t.amount_usd, 0)) AS buy_usd,sum(IF(NOT l.is_buy, t.amount_usd, 0)) AS sell_usd,sum(IF(l.is_buy, l.quantity, -l.quantity)) AS net_tokens,sum(IF(l.is_buy, l.quantity, 0)) AS bought_tokens,max(IF(date_diff('month', DATE '2025-01-01', CAST(t.block_time AS date)) = 0, 1, 0)) AS m0,max(IF(date_diff('month', DATE '2025-01-01', CAST(t.block_time AS date)) = 1, 1, 0)) AS m1,max(IF(date_diff('month', DATE '2025-01-01', CAST(t.block_time AS date)) = 2, 1, 0)) AS m2,max(IF(date_diff('month', DATE '2025-01-01', CAST(t.block_time AS date)) = 3, 1, 0)) AS m3,max(IF(date_diff('month', DATE '2025-01-01', CAST(t.block_time AS date)) = 4, 1, 0)) AS m4,max(IF(date_diff('month', DATE '2025-01-01', CAST(t.block_time AS date)) = 5, 1, 0)) AS m5,max(IF(date_diff('month', DATE '2025-01-01', CAST(t.block_time AS date)) = 6, 1, 0)) AS m6,max(IF(date_diff('month', DATE '2025-01-01', CAST(t.block_time AS date)) = 7, 1, 0)) AS m7,max(IF(date_diff('month', DATE '2025-01-01', CAST(t.block_time AS date)) = 8, 1, 0)) AS m8,max(IF(date_diff('month', DATE '2025-01-01', CAST(t.block_time AS date)) = 9, 1, 0)) AS m9,max(IF(date_diff('month', DATE '2025-01-01', CAST(t.block_time AS date)) = 10, 1, 0)) AS m10,max(IF(date_diff('month', DATE '2025-01-01', CAST(t.block_time AS date)) = 11, 1, 0)) AS m11,max(IF(date_diff('month', DATE '2025-01-01', CAST(t.block_time AS date)) = 12, 1, 0)) AS m12,count(*) AS trade_legs,count_if(t.amount_usd IS NULL OR l.quantity IS NULL) AS invalid_rows,min(t.block_time) AS first_trade,max(t.block_time) AS last_tradeFROM dex_solana.trades tJOIN cohort c ON t.trader_id = c.walletCROSS JOIN UNNEST(ARRAY[ROW(t.token_bought_mint_address, t.token_bought_amount, true),ROW(t.token_sold_mint_address, t.token_sold_amount, false)]) AS l(token_id, quantity, is_buy)WHERE t.block_month >= DATE '2025-01-01'AND t.block_month < DATE '2026-02-01'AND t.block_date >= DATE '2025-01-01' AND t.block_date < DATE '2026-02-01'AND t.block_time >= TIMESTAMP '2025-01-01'AND t.block_time < TIMESTAMP '2026-02-01'AND varbinary_substring(xxhash64(to_utf8(t.trader_id)), 1, 1) < 0x02AND (t.token_bought_mint_address LIKE '%pump' OR t.token_sold_mint_address LIKE '%pump')AND l.token_id LIKE '%pump'GROUP BY 1, 2), cutoff_prices AS (SELECT contract_address_varchar AS token_id, max(price) AS mark_priceFROM prices.dayWHERE blockchain = 'solana'AND timestamp >= TIMESTAMP '2026-01-31'AND timestamp < TIMESTAMP '2026-02-01'GROUP BY 1), marked AS (SELECT l.*, p.mark_price,net_tokens < -greatest(0.000001, bought_tokens * 0.00000001) AS negative_inventory,abs(net_tokens) > greatest(0.000001, bought_tokens * 0.00000001) AS has_inventory