---
title: Math
description: Pure bigint quotes and curve helpers. No RPC. Pass a MarketSnapshot.
---

> **For AI agents:** the complete documentation index is at [llms.txt](/llms.txt). Append `.md` to any page URL for its markdown version.

`@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](/developers/get-trade-context), then call these while the user types.

Each function has its own page in this section (same shape as [viem action docs](https://viem.sh/docs/actions/public/getBalance): Import, Usage, Return Value, Parameters, Error).

<Note>
  Amounts are branded bigints. Parse UI strings with [`parseUsdc`](/developers/parse-usdc) /
  `parseAvm`. Do not pass JavaScript numbers.
</Note>

## Trades

- [quoteBuyExactReserveIn](/developers/math/quote-buy-exact-reserve-in) — exact USDC in, AVM out
- [quoteBuyExactAvmOut](/developers/math/quote-buy-exact-avm-out) — exact AVM out, USDC in
- [quoteSellExactAvmIn](/developers/math/quote-sell-exact-avm-in) — exact AVM in, USDC out
- [quoteSellExactReserveOut](/developers/math/quote-sell-exact-reserve-out) — exact USDC out, AVM in (expensive selector)
- [quoteRedeemAtFloor](/developers/math/quote-redeem-at-floor) — redeem at floor, spot unchanged

## Positions

- [quoteBorrow](/developers/math/quote-borrow) — non-recourse USDC advance
- [quoteExpandExactReserveIn](/developers/math/quote-expand-exact-reserve-in) / [quoteExpandExactAvmOut](/developers/math/quote-expand-exact-avm-out) — buy then borrow
- [quoteShrinkExactAvmIn](/developers/math/quote-shrink-exact-avm-in) / [quoteShrinkExactReserveOut](/developers/math/quote-shrink-exact-reserve-out) — sell then repay
- [quoteSurrender](/developers/math/quote-surrender) — burn collateral to cancel debt
- [getMaxActions](/developers/math/get-max-actions) — largest legal size and why
- [freeCollateral](/developers/math/free-collateral) · [lockedCollateral](/developers/math/locked-collateral) · [borrowCapacity](/developers/math/borrow-capacity)

## Curve

- [priceAtSupply](/developers/math/price-at-supply) — spot on the piecewise line
- [areaAtSupply](/developers/math/area-at-supply) — integral of that price
- [supplyForPrice](/developers/math/supply-for-price) — inverse
- [sampleCurve](/developers/math/sample-curve) — many supplies at once
- [launchPreset](/developers/math/launch-preset) · [validateState](/developers/math/validate-state) · [assertMathRevision](/developers/math/assert-math-revision)

## Backing, fees, units

- [requiredBacking](/developers/math/required-backing) · [floorLiability](/developers/math/floor-liability)
- [floorValueDown](/developers/math/floor-value-down) · [collateralForDebtUp](/developers/math/collateral-for-debt-up)
- [splitFee](/developers/math/split-fee) · [minGrossForNet](/developers/math/min-gross-for-net)
- [rawToWad](/developers/math/raw-to-wad) · [wadToRaw](/developers/math/wad-to-raw) · [mulDiv](/developers/math/mul-div)
- [simulateSequence](/developers/math/simulate-sequence)
- [maxTradeForPriceImpact](/developers/math/max-trade-for-price-impact)
- [tradePriceImpact](/developers/math/trade-price-impact)

## 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`.
