SV3 logo

quoteSellExactReserveOut

Quote the AVM that must be burned to take home an exact net USDC amount.

Exact-output curve sell. Sizes avmIn so that net USDC (after the 1.25% sell fee) equals amount. This is the expensive selector: the user burns whatever AVM it takes.

The quote attaches warning exact-out-sell-expensive. Prefer quoteSellExactAvmIn unless the UI is a "I want $X out" ticket.

Import

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

Usage

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

const quote = quoteSellExactReserveOut(snapshot, parseUsdc("10"));

quote.netReserveOutRaw; // the $10 you asked for
quote.avmIn; // tokens burned
quote.grossReserveOutRaw;
quote.residualRaw;
quote.provenance.warnings; // includes exact-out-sell-expensive

Return Value

SellExactOutQuote

FieldMeaning
kind'sellExactReserveOut'
netReserveOutRawTarget proceeds
grossReserveOutRawCurve payout before fee
avmInTokens that must be burned
residualRawRounding dust kept in the market
priceImpact / nextEngine / provenanceSame family as other sells

Parameters

snapshot

  • Type: MarketSnapshot
quoteSellExactReserveOut(snapshot, parseUsdc("10"));

amount

  • Type: UsdcRaw

Net USDC the wallet should receive. Must be ≥ 100 raw.

quoteSellExactReserveOut(snapshot, asUsdcRaw(10_000_000n));

Error

ErrorWhen
ProtocolRevertError BelowMinimumTarget too small
ProtocolRevertError ZeroAmountCurve cannot pay that much

Tips

  • prepareSellForNetTarget is the prepare helper that uses this intent without forcing the expensive selector when an exact-in sell is cheaper.