SV3 logo

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

FieldTypeMeaning
kind'buyExactReserveIn'Discriminator
grossReserveInRawUsdcRawWhat you passed in
curveReserveInRawUsdcRawGross minus buy fee
avmOutAvmAtomsTokens minted
feesFeeBreakdownProtocol / creator / floor split
priceImpactTradePriceImpactUniswap-style impact; see tradePriceImpact
nextSpotPriceWadWadSpot after the mint
nextFloorPriceWadWadUnchanged on a buy
provenanceQuoteProvenanceBlock 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

ErrorWhen
UnsupportedCurveRevisionErrorsnapshot.math is not supported
ProtocolRevertError BelowMinimumamount < 100
ProtocolRevertError ZeroAmountFee consumes the whole input

Tips

  • priceImpact.totalPriceImpactWad is not the ABI priceImpactWad field. The ABI value is the absolute spot delta, exported here as priceImpact.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.