simulateSequence
Apply a list of local actions to a snapshot and collect quotes.
Off-chain scenario tool. Updates supply (and spot) between steps. Not an on-chain multicall and not a transaction bundler.
Use it for charts and "what if the user buys then sells" previews. Each step is a normal quote* and can throw the same errors.
Import
import { simulateSequence } from "@repo/contract-client/math";
Usage
import { parseUsdc, parseAvm } from "@repo/contract-client";
import { simulateSequence } from "@repo/contract-client/math";
const { snapshot: next, quotes } = simulateSequence(snapshot, [
{ type: "buyExactReserveIn", amount: parseUsdc("10") },
{ type: "sellExactAvmIn", amount: parseAvm("100") },
]);
quotes[0].kind;
next.spotPriceWad;
next.curveSupply;
Supported type values: buyExactReserveIn, buyExactAvmOut, sellExactAvmIn, sellExactReserveOut, redeemAtFloor, borrow, expandExactReserveIn, expandExactAvmOut, shrinkExactAvmIn, shrinkExactReserveOut, surrender. Position steps also take position: PersonalPosition.
Return Value
{ snapshot, quotes }
snapshot is the state after the last action. quotes is 1:1 with actions.
Parameters
snapshot
- Type:
MarketSnapshot
Starting state.
simulateSequence(snapshot, actions);
actions
- Type:
readonly MathAction[]
Discriminated steps. Amounts are branded bigints.
simulateSequence(snapshot, [{ type: "buyExactReserveIn", amount: parseUsdc("1") }]);
Error
Whatever the nested quote* throws (BelowMinimum, BorrowCapacityExceeded, …).