SV3 logo

quoteExpandExactAvmOut

Quote a buy of an exact AVM amount, pledged as collateral, plus a borrow.

Same loop as quoteExpandExactReserveIn, but the buy leg is exact-output: mint collateralAdded AVM, then borrow grossDebtIncrease.

reserveFromUserRaw on the result is the implied gross USDC of that buy.

Import

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

Usage

import { parseAvm, parseUsdc } from "@repo/contract-client";
import { quoteExpandExactAvmOut } from "@repo/contract-client/math";

const quote = quoteExpandExactAvmOut(snapshot, position, {
  collateralAdded: parseAvm("1000"),
  grossDebtIncrease: parseUsdc("5"),
});

quote.reserveFromUserRaw;
quote.collateralAdded;
quote.borrowFees;
quote.position;

Return Value

ExpandQuote with kind: 'expandExactAvmOut'. Fields match the exact-input expand helper.

Parameters

snapshot

  • Type: MarketSnapshot

position

  • Type: PersonalPosition

params.collateralAdded

  • Type: AvmAtoms

Exact AVM to mint and pledge.

params.grossDebtIncrease

  • Type: UsdcRaw

Gross borrow against the new collateral.

quoteExpandExactAvmOut(snapshot, position, {
  collateralAdded: parseAvm("1000"),
  grossDebtIncrease: parseUsdc("5"),
});

Error

Nested buy / borrow errors (BelowMinimum, CanaryCapExceeded, BorrowCapacityExceeded, InsufficientBacking).