Query editor
-- January 2025 entrant cohort; follow-up through July 31, 2025 UTC.-- In V1 OrderFilled, every wallet's own order appears in maker, including the-- taker-summary event. Expanding maker AND taker double-counts these records.-- query_8616810 independently reconstructs the first-trade cohort, not a cached expensive calculation.-- Estimated trade-inventory P&L: sells - buys + remaining shares * cutoff mark.-- Resolved shares use their actual settlement value only if resolved by cutoff.-- Do not also add redemptions: that would count the same payout twice.WITH cohort AS (SELECT from_hex(substr(wallet, 3)) AS wallet FROM query_8616810), position_ledger AS (SELECT t.maker AS wallet, CAST(t.asset_id AS varchar) AS token_id,sum(IF(t.maker_side = 'BUY', t.amount, 0)) AS buy_usd,sum(IF(t.maker_side = 'SELL', t.amount, 0)) AS sell_usd,sum(IF(t.maker_side = 'BUY', t.shares, -t.shares)) AS net_shares,sum(IF(t.maker_side = 'BUY', t.shares, 0)) AS bought_shares,max(IF(month(t.block_time) = 1, 1, 0)) AS m0,max(IF(month(t.block_time) = 2, 1, 0)) AS m1,max(IF(month(t.block_time) = 3, 1, 0)) AS m2,max(IF(month(t.block_time) = 4, 1, 0)) AS m3,max(IF(month(t.block_time) = 5, 1, 0)) AS m4,max(IF(month(t.block_time) = 6, 1, 0)) AS m5,max(IF(month(t.block_time) = 7, 1, 0)) AS m6,count(*) AS fills,count_if(t.amount IS NULL OR t.shares IS NULL OR t.maker_side NOT IN ('BUY', 'SELL')) AS invalid_rows,min(t.block_time) AS first_trade,max(t.block_time) AS last_tradeFROM polymarket_polygon.market_trades tJOIN cohort c ON c.wallet = t.makerWHERE t.block_month >= DATE '2025-01-01'AND t.block_month < DATE '2025-08-01'AND t.block_time >= TIMESTAMP '2025-01-01'AND t.block_time < TIMESTAMP '2025-08-01'AND t.contract_version = 'v1'AND t.asset_id IS NOT NULLGROUP BY 1, 2), resolved AS (SELECT CAST(token_id AS varchar) AS token_id,max(settlement_value) AS settlement_priceFROM polymarket_polygon.market_detailsWHERE resolved_on_timestamp < TIMESTAMP '2025-08-01'AND token_id IS NOT NULLGROUP BY 1), cutoff_prices AS (SELECT CAST(token_id AS varchar) AS token_id, max_by(price, hour) AS last_priceFROM polymarket_polygon.market_prices_hourlyWHERE block_month = DATE '2025-07-01'AND hour >= TIMESTAMP '2025-07-29'AND hour < TIMESTAMP '2025-08-01'AND token_id IS NOT NULLGROUP BY 1), marked AS (SELECT l.*, coalesce(r.settlement_price, p.last_price) AS mark_price,net_shares < -greatest(0.000001, bought_shares * 0.00000001) AS negative_inventory,abs(net_shares) > greatest(0.000001, bought_shares * 0.00000001) AS has_inventoryFROM position_ledger lLEFT JOIN resolved r ON l.token_id = r.token_idLEFT JOIN cutoff_prices p ON l.token_id = p.token_id)SELECT 'Polymarket V1' AS venue, CAST(wallet AS varchar) AS wallet,min(first_trade) AS first_trade, max(last_trade) AS last_trade,