SV3 logo

quoteExpandExactReserveIn

Quote a buy of AVM with exact USDC, pledged as collateral, plus a borrow.

One local quote for a loop: spend reserveFromUser USDC on a curve buy, pledge the minted AVM, then borrow grossDebtIncrease USDC against the new collateral.

Composes quoteBuyExactReserveIn then quoteBorrow on the post-buy position. priceImpact is the buy impact; the borrow still has no impact of its own.

Import

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

Usage

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

const quote = quoteExpandExactReserveIn(snapshot, position, {
  reserveFromUser: parseUsdc("10"),
  grossDebtIncrease: parseUsdc("5"),
});

quote.collateralAdded;
quote.reserveFromUserRaw;
quote.grossDebtIncreaseRaw;
quote.tradeFees;
quote.borrowFees;
quote.position;
quote.priceImpact.totalPriceImpactWad;

Return Value

ExpandQuote with kind: 'expandExactReserveIn'

FieldMeaning
reserveFromUserRawUSDC spent on the buy
grossDebtIncreaseRawDebt added
collateralAddedAVM minted and pledged
tradeFees1.25% buy fee
borrowFees3% advance fee
positionAfter both legs
priceImpactFrom the buy

Parameters

snapshot

  • Type: MarketSnapshot
quoteExpandExactReserveIn(snapshot, position, {
  reserveFromUser: parseUsdc("10"),
  grossDebtIncrease: parseUsdc("5"),
});

position

  • Type: PersonalPosition

Existing pledge. May be empty.

params.reserveFromUser

  • Type: UsdcRaw

Gross USDC for the buy leg.

params.grossDebtIncrease

  • Type: UsdcRaw

Gross borrow after the mint is pledged. Capacity is evaluated on the new collateral.

Error

Whatever the nested buy or borrow throws: BelowMinimum, BorrowCapacityExceeded, InsufficientBacking.

Tips

  • Size grossDebtIncrease from borrowCapacity of the post-buy position, not the current one.
  • Exact-AVM variant: quoteExpandExactAvmOut.