quoteShrinkExactAvmIn
Quote selling an exact AVM amount of collateral and optionally repaying debt.
Removes collateralRemoved AVM from the position via a curve sell, then applies debtDecrease as a repay from the sell proceeds. Any leftover net USDC is netReserveToUserRaw.
priceImpact is the sell impact. You cannot remove more AVM than the position holds.
Import
import { quoteShrinkExactAvmIn } from "@repo/contract-client/math";
Usage
import { parseAvm, parseUsdc } from "@repo/contract-client";
import { quoteShrinkExactAvmIn } from "@repo/contract-client/math";
const quote = quoteShrinkExactAvmIn(snapshot, position, {
collateralRemoved: parseAvm("100"),
debtDecrease: parseUsdc("5"),
});
quote.collateralRemoved;
quote.debtDecreaseRaw;
quote.netReserveToUserRaw;
quote.position;
quote.priceImpact.totalPriceImpactWad;
If debtDecrease exceeds current debt, it is clamped to position.debtRaw.
Return Value
ShrinkQuote with kind: 'shrinkExactAvmIn'
| Field | Meaning |
|---|---|
collateralRemoved | AVM sold |
debtDecreaseRaw | Debt actually repaid |
netReserveToUserRaw | Sell proceeds minus repay (floored at 0) |
position | After both legs |
priceImpact | From the sell |
Parameters
snapshot
- Type:
MarketSnapshot
position
- Type:
PersonalPosition
Must hold at least collateralRemoved.
params.collateralRemoved
- Type:
AvmAtoms
params.debtDecrease
- Type:
UsdcRaw
quoteShrinkExactAvmIn(snapshot, position, {
collateralRemoved: parseAvm("100"),
debtDecrease: parseUsdc("5"),
});
Error
InsufficientFreeCollateral if collateralRemoved > position.collateralAvm. Nested sell errors if the curve payout is too small.