SV3 logo

quoteShrinkExactReserveOut

Quote shrinking a position so the wallet receives an exact net USDC amount.

Inverse shrink: sell whatever AVM is needed so that sell proceeds cover debtDecrease plus netReserveToUser. Uses quoteSellExactReserveOut under the hood (expensive sell selector).

Fails if the implied AVM exceeds position collateral.

Import

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

Usage

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

const quote = quoteShrinkExactReserveOut(snapshot, position, {
  netReserveToUser: parseUsdc("8"),
  debtDecrease: parseUsdc("2"),
});

quote.collateralRemoved;
quote.debtDecreaseRaw;
quote.netReserveToUserRaw;

Return Value

ShrinkQuote with kind: 'shrinkExactReserveOut'. Same fields as quoteShrinkExactAvmIn.

Parameters

snapshot

  • Type: MarketSnapshot

position

  • Type: PersonalPosition

params.netReserveToUser

  • Type: UsdcRaw

USDC that should remain after repay.

params.debtDecrease

  • Type: UsdcRaw

Clamped to current debt.

quoteShrinkExactReserveOut(snapshot, position, {
  netReserveToUser: parseUsdc("8"),
  debtDecrease: parseUsdc("2"),
});

Error

InsufficientFreeCollateral if the implied sell burns more AVM than the position holds. Nested exact-out sell errors otherwise.

Tips