Reference
Trading SDK
The private workspace package @zoltar/trading-shared holds the pure Trading math that the UI and the Solidity parity tests share. All chain quantities are bigint.
Pure math
Module @zoltar/trading-shared/trading/math mirrors the quote and price functions of TwoWayConstantProductMath. It has no counterpart of the library's initial-odds and proportional-deposit functions; the UI estimates those in ui/trading/ts/features/live/liquidityEstimate.ts.
quoteExactInput(reserveIn, reserveOut, amountIn, feeBps)andquoteExactOutput(reserveIn, reserveOut, amountOut, feeBps)return aSwapQuote,{ amountIn, amountOut, netInput, feeAmount }, with the contract's floor (exact input) and ceil (exact output) rounding. They throw on empty reserves, an out-of-range output, orfeeBps ≥ 10,000.conditionalYesBps(yesReserve, noReserve)returns the Conditional Yes price in basis points, floor-rounded.
Position quotes
Module @zoltar/trading-shared/trading/positions takes { yesReserve, noReserve, feeBps } and a longOutcome of 'YES' or 'NO':
quoteEnterPosition(longOutcome, completeSetShares, reserves)mirrorsenterPositionafter minting and returns anEnterPositionQuote:longOutcome,completeSetShares,oppositeSharesSwapped,additionalLongShares,totalLongShares,invalidInsurance,feeAmount,conditionalYesBpsBefore, andconditionalYesBpsAfter.quoteExitPosition(longOutcome, completeSetShares, reserves)mirrors the insured exit and returns anExitPositionQuote:longOutcome,completeSetShares,longSharesSwapped,totalLongShares,invalidRequired,feeAmount,conditionalYesBpsBefore, andconditionalYesBpsAfter.largestExitForLongShares({ ...reserves, longOutcome, longShares, completeSetCap? })binary-searches the largest complete-set amount whose total long-share cost fits withinlongSharesand stays below the opposite reserve. The optionalcompleteSetCapbounds the result further.maximumInsuredExit({ ...reserves, longOutcome, longBalance, invalidBalance })callslargestExitForLongShareswith the long balance aslongSharesand the Invalid balance ascompleteSetCap.
Receive request encoding
Module @zoltar/trading-shared/trading/receiveRequest exports encodeReceiveRequest(request), which ABI-encodes the data argument for a share transfer to the router. The request, typed ReceiveRequest, is a positional tuple in the field order of the router's ReceiveRequest struct, which the router reference lists.
Transaction helpers
Transaction-facing helpers live in the Trading UI at ui/trading/ts/protocol/tradeQuote.ts, not in the shared package:
minimumAfterSlippage(amount, slippageBps?)floors andmaximumAfterSlippage(amount, slippageBps?)ceils a bound; slippage defaults toUI_SLIPPAGE_BPS(50).requireTransactionSlippageBpsthrows outsideMINIMUM_SLIPPAGE_BPS(1) toMAXIMUM_SLIPPAGE_BPS(500).stableSimulation(client, simulate)reads the latest block withlatestBlockIdentity(client)and passes itsblockNumber,blockHash, andblockTimestamptosimulate, whose reads must all use that block number. A reorg during those reads is not detected.simulateWithDeadline(client, expiry, simulate, resolveDeadline?)does the same and also resolvesexpiry, aTransactionExpirythat is either an absolute deadline or{ validityMinutes }between 1 and 1,440 (requireTransactionValidityMinutes), against the pinned block's timestamp. The optionalresolveDeadline(block, requestedDeadline)can replace that deadline, andsimulatereceives(block, deadline).retainApprovedMinimum(approved, refreshed, label)andretainApprovedMaximum(approved, refreshed, label)return the approved bound, or throw when the submission-time simulation no longer satisfies it.
Pure math is a responsive preview only. A quote does not expire when a new block arrives: immediately before wallet submission the client simulates the actual call again at the latest block, and submits with the bounds and deadline approved in the quote only if that simulation succeeds within them.