Four failure modes that make DB-recorded P&L lie to you (and how to detect each on-chain) #5
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 these as a checklist for anyone running a Polymarket bot off DB-recorded fills. After auditing 320 trades on our own account with
pnl-truthteller, the DB-vs-on-chain delta closed to within $0.02 — but only after we caught these four failure modes that almost everyone has at least one of:1. Partial fills counted as separate orders. CLOB returns multiple
tradesfor oneorder_idwhen liquidity is fragmented across the book. If youINSERTper trade event without anON CONFLICTon(order_id, trade_id), you double-count fills. We saw a +$11 phantom profit from this on one market.2. Redemptions logged as trades. When a market resolves and you redeem winning shares for USDC, the contract call looks structurally similar to a sell. If your event listener doesn't filter by
event_signature, redemptions go into the trade table at $1.00/share — but your cost basis is whatever you actually paid. Looks like pure profit. Isn't — that profit is already accounted for in the unrealized P&L of the position.3. Gas + fee asymmetry between sides. Buys deduct gas from your USDC. Sells add USDC net of gas. If you record
fill_priceas the order price (not the realized cash flow), you're under-counting cost on buys and over-counting proceeds on sells. Net effect: DB looks ~0.6% better than reality, consistently.4. Fills against your own orders during inventory rebalances. If you run two strategies that occasionally cross each other's quotes, both DBs record the trade at face value. On-chain it's a wash minus 2× fees. We caught this only because the on-chain USDC delta wouldn't reconcile — DB said +$23, chain said −$0.40.
The tool runs the four checks against any wallet:
Output is per-market with the delta flagged. Source: https://github.com/luciferforge/pnl-truthteller
What's the worst DB-vs-chain delta you've personally caught? Curious if anyone has a failure mode that isn't on this list.
Beta Was this translation helpful? Give feedback.
All reactions