SV3 logo

Math

Pure bigint quotes and curve helpers. No RPC. Pass a MarketSnapshot.

@repo/contract-client/math is a TypeScript port of the on-chain integer rules. It never takes a PublicClient. Unknown curve revisions throw instead of reusing v1 math.

Load state once with getTradeContext, then call these while the user types.

Each function has its own page in this section (same shape as viem action docs: Import, Usage, Return Value, Parameters, Error).

Amounts are branded bigints. Parse UI strings with parseUsdc / parseAvm. Do not pass JavaScript numbers.

Trades

Positions

Perps

  • Perps leverage — 1×–3.3× bounds and collateral-first physical-long / offset-short quotes
  • quoteLongByLeverage uses AccountContext, including live market/protocol debt and backing headroom
  • quoteShortByLeverage uses PerpMarketContext, including live policies, active and surrendered offset, and market/protocol escrow caps

Curve

Backing, fees, units

Client vs /math

sv3.quote.buyExactReserveIn({ market, amount }) calls the same function after loading a snapshot if you passed an address. For a slider, load once and import from /math.