SV3 logo

quoteBorrow

Quote a non-recourse USDC advance against pledged AVM collateral.

Increases position debt by amount. Net USDC out is amount minus the 3% advance fee. Spot does not move, so priceImpact is null (not zero).

Local math refuses over-capacity even if an on-chain quoter still returns a struct. Capacity is borrowCapacity: floor value of collateral minus existing debt.

The position has no interest and no due date. Locked tokens stay pledged until repay, shrink, or quoteSurrender.

Import

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

Usage

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

const quote = quoteBorrow(snapshot, position, parseUsdc("10"));

quote.grossDebtIncreaseRaw;
quote.netReserveOutRaw;
quote.borrowCapacityRaw;
quote.fees.totalRaw; // 3% of gross
quote.position.debtRaw; // previous + amount
quote.priceImpact; // null

Load position from getAccountContext. Size the slider with getMaxActions.

Return Value

BorrowQuote

FieldMeaning
kind'borrow'
grossDebtIncreaseRawDebt added (the amount you passed)
netReserveOutRawUSDC the wallet receives
borrowCapacityRawCapacity before this borrow
fees3% split (protocol / creator / floor)
positionResulting collateral (unchanged) and debt
priceImpactnull

Parameters

snapshot

  • Type: MarketSnapshot

Needs floorPriceWad and balances.liquidReserveRaw. The liquid reserve must cover net out plus withdrawable fee legs.

quoteBorrow(snapshot, position, parseUsdc("10"));

position

  • Type: PersonalPosition

{ owner, collateralAvm, debtRaw }.

quoteBorrow(snapshot, account.position, parseUsdc("10"));

amount

  • Type: UsdcRaw

Gross debt increase. ≥ 100 raw and ≤ remaining capacity.

quoteBorrow(snapshot, position, asUsdcRaw(10_000_000n));

Error

ErrorWhen
ProtocolRevertError BelowMinimumamount < 100
ProtocolRevertError BorrowCapacityExceededamount > capacity
ProtocolRevertError InsufficientBackingLiquid reserve cannot pay net + fees

Tips

  • Borrow does not mint. Collateral must already sit in the position (from a buy-and-pledge / expand, or a prior deposit).
  • Fee surplus from the 3% still goes toward future floor raises, same as trade fees.