Methodology: reconciling DB-side P&L to on-chain USDC delta within $0.02 across 320 trades #4
manja316
started this conversation in
Show and tell
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Posting the full methodology in case anyone is trying to reconcile their own Polymarket trade history to wallet USDC delta and wants something to crib from. This is the actual procedure I used on my 320-trade self-audit that surfaced the
+$34.31 DB → -$90.72 on-chaindivergence (the onepnl-truthtellerwas built to find).Inputs
Three sources, all pulled read-only:
/data/tradesfor the wallet (paginated,taker_only=true)./data/transactionsfor the same wallet (every USDC in/out, including fees and rebates).min(trade_ts)andmax(trade_ts)— single number from Polygonscan.If (1) + (2) don't reconcile to (3) within a few cents, the bot's reported P&L is fiction.
Reconciliation steps
side: BUY/SELLon the maker, buttaker_sideis what mattered for me. I flip everything to taker frame soBUY = USDC out, SELL = USDC in.(order_id, maker_order_id, transaction_hash, log_index). Keep row with largestmatch_amount. Without this, partial fills double-count by ~12% in my dataset.(tx_hash, log_index)alone —op_hashis not a primary key in proxy-wallet flows.Σ(sell_proceeds) − Σ(buy_cost) − Σ(fees), then sum across markets whereredeemed_at IS NOT NULLorcurrent_position == 0.Σ(current_position × mid_price)from/clob/pricesnapshot.realized + unrealized − initial_USDC == current_USDC(on-chain). In my data this landed at $0.02 — within the rounding noise from the 6-decimal USDC representation.What I expected vs what I found
The fee gap was the single biggest contributor. Bot was logging
fee = 0.4%on every trade per its config; chain said the realized fill price was also hit with maker-spread crossing on retry. Two different leaks, both invisible from inside the bot's own logs.Edge case I'm still unsure about
When a proxy-wallet
executeTransactionbundles multiple maker fills, I count each maker fill independently in step 2. I have not confirmed whether deduping at bundle level would change totals — it didn't on my N=320 set but I'd take a data point from anyone running ≥1k trades.Repro
Read-only. Outputs a markdown report with the by-exit-reason table that's the actually-useful one. If your numbers reconcile cleanly, great — your bot is honest. If they don't, the breakdown shows you where the leak is.
Drop your numbers below if you run it. Trying to collect n≥10 reconciled wallets to publish a slippage index (see Discussion #3).
Beta Was this translation helpful? Give feedback.
All reactions