SV3 logo

quoteBuyExactAvmOut

Quote the USDC that must be paid to mint an exact AVM amount.

Inverse of exact-input buy. Sizes gross USDC (including the 1.25% buy fee) so the curve mints exactly amount AVM.

Use this when the user typed a token amount. On-chain that is buyWithExactAvmTokensOut. prepareBuyForReserveBudget also uses this selector, but sizes AVM from a USDC budget.

Import

import { quoteBuyExactAvmOut } from "@repo/contract-client/math";

Usage

import { parseAvm } from "@repo/contract-client";
import { quoteBuyExactAvmOut } from "@repo/contract-client/math";

const quote = quoteBuyExactAvmOut(snapshot, parseAvm("1000"));

quote.avmOut; // equals the amount you asked for
quote.grossReserveInRaw; // USDC the wallet must have, including fee
quote.curveReserveInRaw; // USDC that actually hits the curve
quote.priceImpact.totalPriceImpactWad;

Return Value

BuyExactOutQuote

FieldMeaning
kind'buyExactAvmOut'
avmOutExact tokens minted
grossReserveInRawGross USDC in (fee-inclusive)
curveReserveInRawGross minus buy fee
fees / priceImpact / nextSpotPriceWad / provenanceSame shape as exact-input

Gross is computed with minGrossForNet so the fee-exclusive curve cost is covered.

Parameters

snapshot

  • Type: MarketSnapshot
quoteBuyExactAvmOut(snapshot, parseAvm("1000"));

amount

  • Type: AvmAtoms

Exact AVM to mint, 18 decimals. Must imply gross USDC ≥ 100 raw.

quoteBuyExactAvmOut(snapshot, asAvmAtoms(10n ** 18n));

Error

ErrorWhen
UnsupportedCurveRevisionErrorUnsupported snapshot.math
ProtocolRevertError BelowMinimumImplied gross USDC < 100
ProtocolRevertError CanaryCapExceededSupply cap would be breached

Tips

  • Exact-output is how you keep a USDC cap: quote exact-in to learn avmOut, then submit exact-out with maxIn = budget.