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
| Error | When |
|---|---|
WalletClientRequiredError | No wallet / account on the client |
ProtocolRevertError BelowMinimum | Budget too small to mint |
InvalidDeadlineError | Client deadline config is out of range |
Other prepare helpers
| Method | User intent | On-chain selector |
|---|---|---|
prepareBuyForReserveBudget | Spend at most this USDC | buyWithExactAvmTokensOut |
prepareBuyExactReserveIn | Spend exactly this USDC | buyWithExactReserveTokensIn |
prepareBuyExactAvmOut | Mint exactly this AVM | buyWithExactAvmTokensOut |
prepareSellExactAvmIn | Sell exactly this AVM | sellWithExactAvmTokensIn |
prepareSellForNetTarget | Receive at least this USDC | cheaper sell path |
prepareSellExactReserveOut | Receive exactly this USDC | sellWithExactReserveTokensOut |
prepareRedeemAtFloor | Redeem at floor | redeemAtFloorWithExactAvmTokensIn |
All take { market, amount, slippageBps } and return PreparedAction. None of them send.
Tips
- Re-quote if the snapshot is stale.
executePreparedthrowsStaleStateErrorwhenstateNoncemoved, unless you passacceptStale: true. - Exact-output sells are the expensive selector. Prefer
prepareSellExactAvmInunless the user typed a USDC target.