Query editor
-- Kelly Edge Trader Ranking for Polymarket-- Ranks wallets by Kelly edge (skill-adjusted profitability accounting for odds paid)-- Uses actual Dune polymarket_polygon schema---- Key insight: taker is ALWAYS the buyer, maker is ALWAYS the seller.-- Selling Yes at price P = Buying No at price (1-P).WITH resolved AS (SELECTr.conditionId AS condition_id,r.payoutNumerators,r.evt_block_time AS resolution_timeFROM polymarket_polygon.ctf_evt_conditionresolution rWHERE r.evt_block_time >= NOW() - INTERVAL '180' DAY),-- Map each condition_id to its two outcome names with slot assignmentoutcome_slots AS (SELECTcondition_id,token_outcome,ROW_NUMBER() OVER (PARTITION BY condition_id ORDER BY token_outcome) AS slotFROM polymarket_polygon.market_tradesWHERE block_time >= NOW() - INTERVAL '180' DAYGROUP BY condition_id, token_outcome),-- Build complement mapping: for each outcome, what is the other outcome?complement_map AS (SELECTa.condition_id,a.token_outcome AS outcome,b.token_outcome AS complement_outcomeFROM outcome_slots aINNER JOIN outcome_slots bON a.condition_id = b.condition_id AND a.slot != b.slot),-- Determine winning outcome name per resolved marketwinning_outcomes AS (SELECTr.condition_id,os.token_outcome AS winning_outcomeFROM resolved rINNER JOIN outcome_slots osON r.condition_id = os.condition_idWHERE (r.payoutNumerators[1] = UINT256 '1' AND os.slot = 1)OR (r.payoutNumerators[2] = UINT256 '1' AND os.slot = 2)),-- All trades from both buyer and seller perspectives-- Buyer (taker): buys token_outcome at price-- Seller (maker): sells token_outcome at price = buys complement at (1-price)trades AS (-- Buy side: taker buys token_outcome at priceSELECTtaker AS trader,condition_id,question,token_outcome,