---
title: simulateSequence
description: Apply a list of local actions to a snapshot and collect quotes.
---

> **For AI agents:** the complete documentation index is at [llms.txt](/llms.txt). Append `.md` to any page URL for its markdown version.

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

```ts
import { simulateSequence } from "@repo/contract-client/math";
```

## Usage

```ts
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.

```ts
simulateSequence(snapshot, actions);
```

### actions

- **Type:** `readonly MathAction[]`

Discriminated steps. Amounts are branded bigints.

```ts
simulateSequence(snapshot, [{ type: "buyExactReserveIn", amount: parseUsdc("1") }]);
```

## Error

Whatever the nested `quote*` throws (`BelowMinimum`, `BorrowCapacityExceeded`, …).
