SV3 logo

getAccountContext

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

Same block-pinned multicall as getTradeContext, plus the personal position used by borrow, expand, shrink, and surrender 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;

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

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.