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
- quoteBuyExactReserveIn — exact USDC in, AVM out
- quoteBuyExactAvmOut — exact AVM out, USDC in
- quoteSellExactAvmIn — exact AVM in, USDC out
- quoteSellExactReserveOut — exact USDC out, AVM in (expensive selector)
- quoteRedeemAtFloor — redeem at floor, spot unchanged
Positions
- quoteBorrow — non-recourse USDC advance
- quoteExpandExactReserveIn / quoteExpandExactAvmOut — buy then borrow
- quoteShrinkExactAvmIn / quoteShrinkExactReserveOut — sell then repay
- quoteSurrender — burn collateral to cancel debt
- getMaxActions — largest legal size and why
- freeCollateral · lockedCollateral · borrowCapacity
Curve
- priceAtSupply — spot on the piecewise line
- areaAtSupply — integral of that price
- supplyForPrice — inverse
- sampleCurve — many supplies at once
- launchPreset · validateState · assertMathRevision
Backing, fees, units
- requiredBacking · floorLiability
- floorValueDown · collateralForDebtUp
- splitFee · minGrossForNet
- rawToWad · wadToRaw · mulDiv
- simulateSequence
- maxTradeForPriceImpact
- tradePriceImpact
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.