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'
| Field | Meaning |
|---|---|
reserveFromUserRaw | USDC spent on the buy |
grossDebtIncreaseRaw | Debt added |
collateralAdded | AVM minted and pledged |
tradeFees | 1.25% buy fee |
borrowFees | 3% advance fee |
position | After both legs |
priceImpact | From 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
grossDebtIncreasefromborrowCapacityof the post-buy position, not the current one. - Exact-AVM variant: quoteExpandExactAvmOut.