SV3 logo

getTradeContext

Load a market snapshot together with the account balances needed to quote and send.

One block-pinned multicall for a trade ticket: market snapshot, wallet USDC and AVM balances, allowances to the market, permit nonces, whether the account is a contract, and cap headroom.

After this returns, repeated quote* calls on context.snapshot must not call RPC.

Import

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

Usage

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

const context = await sv3.market.getTradeContext(market, account);
const quote = quoteBuyExactReserveIn(context.snapshot, parseUsdc("1"));

For positions, use getAccountContext — it adds position, freeCollateral, and borrowCapacity.

Return Value

Promise<TradeContext>

FieldMeaning
snapshotFrozen MarketSnapshot
accountAddress you passed
reserveBalance / avmBalanceWallet balances
reserveAllowance / avmAllowanceAllowance to the market
reservePermitNonce / avmPermitNonceEIP-2612 nonces
codeSize0n for an EOA
capHeadroomRemaining market backing and debt caps

Parameters

market

  • Type: Address

The FloorMarket proxy.

const context = await sv3.market.getTradeContext(market, account);

account

  • Type: Address

The wallet whose balances and allowances are included.

const context = await sv3.market.getTradeContext(market, "0x…");

Tips

  • Pass context.reserveAllowance and context.reservePermitNonce into getRequirements. Do not issue a hidden approve.
  • codeSize > 0n means a contract wallet. With default permitCapability: 'none', that route is allowance, not permit.