getMaxActions
Largest borrow, withdraw, repay, shrink, and surrender with the limiting reason.
Read-only sizing for a position ticket. Does not send. A market or global pause zeros every max.
Use this to clamp sliders before calling quoteBorrow / shrink / surrender. The client helper sv3.position.getMaxActions(market, owner) loads getAccountContext and calls this.
Import
import { getMaxActions } from "@repo/contract-client/math";
Usage
const max = getMaxActions(snapshot, position, walletUsdc);
max.maxBorrowGrossRaw;
max.maxWithdrawFreeAvm;
max.maxRepayRaw;
max.maxShrinkCollateralAvm;
max.maxSurrenderDebtRaw;
max.limiting.borrow;
// 'capacity' | 'reserve' | 'paused' | 'min-settlement' | …
Return Value
MaxActions
| Field | Meaning |
|---|---|
maxBorrowGrossRaw | Gross USDC that can still be drawn |
maxWithdrawFreeAvm | AVM not locking debt |
maxRepayRaw | min(debt, walletReserve) unless paused |
maxShrinkCollateralAvm | Collateral that can be sold |
maxSurrenderDebtRaw | Debt that can be cancelled |
limiting.* | Why that max is what it is |
Parameters
snapshot
- Type:
MarketSnapshot
Floor, pause flags, liquid reserve.
getMaxActions(snapshot, position, walletUsdc);
position
- Type:
PersonalPosition
walletReserve (optional)
- Type:
bigint - Default:
0n
Wallet USDC, used only for repay sizing.
getMaxActions(snapshot, position, context.reserveBalance);
Error
UnsupportedCurveRevisionError if snapshot.math is unknown.
Tips
limiting.borrow === 'min-settlement'means capacity is below100raw — show "cannot borrow" rather than a tiny slider.- On-chain debt and backing caps also appear as limiting reasons (
market-debt-cap,protocol-debt-cap) when the snapshot carries them.