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>
| Field | Meaning |
|---|---|
snapshot | Frozen MarketSnapshot |
account | Address you passed |
reserveBalance / avmBalance | Wallet balances |
reserveAllowance / avmAllowance | Allowance to the market |
reservePermitNonce / avmPermitNonce | EIP-2612 nonces |
codeSize | 0n for an EOA |
capHeadroom | Remaining 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.reserveAllowanceandcontext.reservePermitNonceinto getRequirements. Do not issue a hidden approve. codeSize > 0nmeans a contract wallet. With defaultpermitCapability: 'none', that route is allowance, not permit.