Query editor
-- Full 1/128 January entrant sample: compute P&L for every entrant, including inactive wallets.-- 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 wallet,TRY_CAST(activity_mask AS bigint) AS activity_mask,TRY_CAST(entry_volume_usd AS double) AS entry_volume_usdFROM dune.defiance_cr.dataset_trader_retention_wallet_snapshot_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,count_if(t.amount_usd IS NULL OR l.quantity IS NULL) AS invalid_rowsFROM 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 '2025-08-01'AND t.block_date >= DATE '2025-01-01' AND t.block_date < DATE '2025-08-01'AND t.block_time >= TIMESTAMP '2025-01-01'AND t.block_time < TIMESTAMP '2025-08-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 '2025-07-31'AND timestamp < TIMESTAMP '2025-08-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_inventoryFROM position_ledger lLEFT JOIN cutoff_prices p ON l.token_id = p.token_id), wallet_pnl AS (SELECT wallet,sum(buy_usd) AS buy_usd, sum(sell_usd) AS sell_usd,sum(sell_usd - buy_usd + IF(has_inventory, net_tokens * coalesce(mark_price, 0), 0)) AS pnl_estimate_usd,sum(IF(has_inventory, net_tokens * coalesce(mark_price, 0), 0)) AS marked_inventory_usd,count_if(negative_inventory) AS negative_inventory_positions,count_if(has_inventory AND mark_price IS NULL) AS unpriced_positions,sum(invalid_rows) AS invalid_trade_rowsFROM markedGROUP BY wallet), wallets AS (