Derive once

Prices, positions, cost basis and PnL are computed in one BigInt-exact package that both the server and the client run — so your venue's numbers equal everyone else's, exactly.

@prophecy-dev/connect-core is a pure fold: trades in, positions with cost basis and PnL out. No network, no database, no framework. BigInt throughout — no floats anywhere near a balance.

Both the API and the SDK run this code. Not equivalent code — the same code.

The rule

Derive once. Never re-derive a number in a frontend.

If your venue computes a user’s PnL from a trade list you fetched, you have created a second answer. It will agree with ours right up until a rounding rule, a fee, or a settlement edge case differs — and then you are showing a user a number that our leaderboard disagrees with, and one of you is wrong in a way neither can debug.

Ask Connect for the derived value. That’s what it’s for.

The trap this is protecting you from

A CPMM market is one pool per event. Volume is an event-level quantity, and it’s exposed on each outcome for convenience — so summing volume across an event’s outcomes multiplies it by the number of outcomes.

The general form of the rule is: one source of truth per quantity, at its natural grain. Event volume is event-grain. A position is wallet-and-market-grain. Read each at the grain it exists at, and don’t aggregate across a grain boundary to synthesise a number that already exists.

Prices

Prices are derived server-side, so every venue quotes the same odds at the same moment. For a CPMM that means straight from the pool’s reserves:

price_i = (1 / r_i) / Σ(1 / r_j)

You get them from useOdds regardless of the market’s structure — which is the point of asking for the derived value instead of computing it. A CPMM prices from reserves; an order-book market prices from the book, and the same hook will keep returning a price. Code that reads reserves itself is code that breaks when the structure changes.

Displayed odds are not a fill price. On a CPMM at small size the two are close enough to treat alike; on a book they are not. The number you show a user before they confirm should always come from the quote for their size — which is what the {c} checkout drawer already does.

See Live Odds for the live version, and Single Market for the market view around it.