SV3 logo

getAccountContext

Load a trade context plus the account's SV3 position, free collateral, and borrow capacity.

Uses the same block pin as getTradeContext, then adds the personal position used by borrow, expand, shrink, surrender, and physical-long leverage quotes.

Import

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

Usage

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

const account = await sv3.market.getAccountContext(market, owner);

account.position.collateralAvm;
account.position.debtRaw;
account.freeCollateral;
account.borrowCapacity;
account.capHeadroom;

const max = getMaxActions(account.snapshot, account.position, account.reserveBalance);
const quote = quoteBorrow(account.snapshot, account.position, parseUsdc("10"));

sv3.position.get(market, owner) returns only the position. sv3.position.getMaxActions(market, owner) loads this context and runs getMaxActions for you.

Return Value

Promise<AccountContext> — a TradeContext plus:

FieldMeaning
position{ owner, collateralAvm, debtRaw }
freeCollateralAVM that is not locking debt
borrowCapacityAdditional USDC that can be drawn at the current floor
capHeadroomMinimum live market/protocol backing and debt headroom

Parameters

market

  • Type: Address
const account = await sv3.market.getAccountContext(market, owner);

owner

  • Type: Address

Position owner. Usually the connected wallet.

const account = await sv3.market.getAccountContext(market, "0x…");

Tips

  • An empty position is still a valid object (collateralAvm = 0n, debtRaw = 0n). You do not need a null check before quoteBorrow.
  • Size tickets with getMaxActions so the slider cannot exceed capacity, pause, or min settlement.