quoteBuyExactReserveIn
Quote AVM minted for an exact USDC input from a market snapshot.
Given a pinned MarketSnapshot and a gross USDC amount, returns tokens out, the curve leg after the 1.25% buy fee, the fee split, next spot, and Uniswap-style price impact. No RPC.
This is the slider function for "I will spend this USDC." To submit that ticket, prefer prepareBuyForReserveBudget, which keeps the cap by encoding the cheaper exact-output selector.
Import
import { quoteBuyExactReserveIn } from "@repo/contract-client/math";
Usage
import { parseUsdc } from "@repo/contract-client";
import { quoteBuyExactReserveIn } from "@repo/contract-client/math";
const quote = quoteBuyExactReserveIn(snapshot, parseUsdc("1"));
quote.avmOut;
quote.curveReserveInRaw;
quote.fees.totalRaw;
quote.fees.protocolRaw;
quote.fees.creatorRaw;
quote.fees.floorRaw;
quote.priceImpact.totalPriceImpactWad;
quote.nextSpotPriceWad;
Gross USDC is split: 1.25% fee, remainder is curve input. Settlement below 100 raw (0.0001 USDC) reverts with BelowMinimum.
Return Value
BuyExactInQuote
| Field | Type | Meaning |
|---|---|---|
kind | 'buyExactReserveIn' | Discriminator |
grossReserveInRaw | UsdcRaw | What you passed in |
curveReserveInRaw | UsdcRaw | Gross minus buy fee |
avmOut | AvmAtoms | Tokens minted |
fees | FeeBreakdown | Protocol / creator / floor split |
priceImpact | TradePriceImpact | Uniswap-style impact; see tradePriceImpact |
nextSpotPriceWad | Wad | Spot after the mint |
nextFloorPriceWad | Wad | Unchanged on a buy |
provenance | QuoteProvenance | Block pin, revision, warnings |
Parameters
snapshot
- Type:
MarketSnapshot
Frozen market state from getQuoteState or getTradeContext. snapshot.math must be a supported revision.
quoteBuyExactReserveIn(snapshot, parseUsdc("1"));
amount
- Type:
UsdcRaw
Gross USDC in, 6 decimals. Brand with parseUsdc('1') or asUsdcRaw(1_000_000n). Must be ≥ MIN_SETTLEMENT_RAW (100).
quoteBuyExactReserveIn(snapshot, asUsdcRaw(1_000_000n));
Error
| Error | When |
|---|---|
UnsupportedCurveRevisionError | snapshot.math is not supported |
ProtocolRevertError BelowMinimum | amount < 100 |
ProtocolRevertError ZeroAmount | Fee consumes the whole input |
Tips
priceImpact.totalPriceImpactWadis not the ABIpriceImpactWadfield. The ABI value is the absolute spot delta, exported here aspriceImpact.spotPriceDeltaWad.- Same math is available as
sv3.quote.buyExactReserveIn({ market, amount })if you pass a market address and want the SDK to load the snapshot.