SV3 logo

prepareBuyForReserveBudget

Prepare a buy that spends at most a USDC budget by submitting the cheaper exact-output selector.

Keeps the user's USDC cap. Quotes an exact-input buy locally, then encodes buyWithExactAvmTokensOut so the wallet spends at most amount and receives the quoted AVM.

This is the helper you want for a "I will spend $10" ticket. The SDK has no hidden slippage default — slippageBps is required.

Does not send. Pass the result to getRequirements, then executePrepared.

Import

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

Usage

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

const prepared = await sv3.trade.prepareBuyForReserveBudget({
  market,
  amount: parseUsdc("10"),
  slippageBps: 100n, // 1%
});

prepared.to;
prepared.data;
prepared.functionName; // 'buyWithExactAvmTokensOut'
prepared.constraints.maxIn;
prepared.quoteContext;

prepareBuyExactReserveIn instead encodes buyWithExactReserveTokensIn (exact USDC in, min AVM out). See prepareBuyExactReserveIn.

Return Value

Promise<PreparedAction>

Frozen calldata: to, data, value (0n), functionName, args, deadline, constraints (maxIn, marketStateNonce, marketStateHash), and the quoteContext used to build it.

Parameters

market

  • Type: Address

FloorMarket proxy.

await sv3.trade.prepareBuyForReserveBudget({
  market,
  amount: parseUsdc("10"),
  slippageBps: 100n,
});

amount

  • Type: bigint (UsdcRaw)

Gross USDC budget, 6 decimals. Must be ≥ 100 (MIN_SETTLEMENT_RAW).

await sv3.trade.prepareBuyForReserveBudget({
  market,
  amount: parseUsdc("10"),
  slippageBps: 100n,
});

slippageBps

  • Type: bigint
  • Required — no default

Basis points of tolerance applied when encoding limits. 100n is 1%.

await sv3.trade.prepareBuyForReserveBudget({
  market,
  amount: parseUsdc("10"),
  slippageBps: 50n,
});

Error

ErrorWhen
WalletClientRequiredErrorNo wallet / account on the client
ProtocolRevertError BelowMinimumBudget too small to mint
InvalidDeadlineErrorClient deadline config is out of range

Other prepare helpers

MethodUser intentOn-chain selector
prepareBuyForReserveBudgetSpend at most this USDCbuyWithExactAvmTokensOut
prepareBuyExactReserveInSpend exactly this USDCbuyWithExactReserveTokensIn
prepareBuyExactAvmOutMint exactly this AVMbuyWithExactAvmTokensOut
prepareSellExactAvmInSell exactly this AVMsellWithExactAvmTokensIn
prepareSellForNetTargetReceive at least this USDCcheaper sell path
prepareSellExactReserveOutReceive exactly this USDCsellWithExactReserveTokensOut
prepareRedeemAtFloorRedeem at floorredeemAtFloorWithExactAvmTokensIn

All take { market, amount, slippageBps } and return PreparedAction. None of them send.

Tips

  • Re-quote if the snapshot is stale. executePrepared throws StaleStateError when stateNonce moved, unless you pass acceptStale: true.
  • Exact-output sells are the expensive selector. Prefer prepareSellExactAvmIn unless the user typed a USDC target.