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
| Field | Meaning |
|---|---|
kind | 'buyExactAvmOut' |
avmOut | Exact tokens minted |
grossReserveInRaw | Gross USDC in (fee-inclusive) |
curveReserveInRaw | Gross minus buy fee |
fees / priceImpact / nextSpotPriceWad / provenance | Same 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
| Error | When |
|---|---|
UnsupportedCurveRevisionError | Unsupported snapshot.math |
ProtocolRevertError BelowMinimum | Implied gross USDC < 100 |
ProtocolRevertError CanaryCapExceeded | Supply cap would be breached |
Tips
- Exact-output is how you keep a USDC cap: quote exact-in to learn
avmOut, then submit exact-out withmaxIn = budget.