> ## Documentation Index
> Fetch the complete documentation index at: https://docs.raydium.io/llms.txt
> Use this file to discover all available pages before exploring further.

# AMM v4 instructions

> Every AMM v4 instruction with its arguments, the pool and OpenBook accounts it expects, and the pre/post conditions on each.

<Info>
  As of the 2026-07 program upgrade, AMM v4's OpenBook / Serum dependency has been **removed**. The legacy v1 `SwapBaseIn` / `SwapBaseOut`, `Deposit`, and `Withdraw` instructions **keep their old account layouts** for backwards compatibility: the market accounts are still accepted in their old positions, but they are **no longer validated or used** (no CPI is issued). New integrations should use the V2 swap entrypoints, which omit the market accounts entirely. Several instructions have been removed and now revert — see the [changelog entry](/reference/changelog/2026-07-22-amm-v4-openbook-removal). The account lists below use the field names from the Raydium SDK; the underlying IDL sometimes uses `serum_*` prefixes.
</Info>

## Instruction inventory

| Group          | Instruction           | tag | Notes                                                                             |
| -------------- | --------------------- | --- | --------------------------------------------------------------------------------- |
| Pool lifecycle | `Initialize2`         | 1   | Only pool-creation instruction (UI defaults to CPMM for new pools).               |
| Liquidity      | `Deposit`             | 3   | Add liquidity, receive LP. Layout unchanged (market accounts ignored).            |
| Liquidity      | `Withdraw`            | 4   | Burn LP, receive both sides pro-rata. Layout unchanged (market accounts ignored). |
| Swap           | `SwapBaseIn`          | 9   | Exact-input swap. v1 layout unchanged; market accounts accepted but ignored.      |
| Swap           | `SwapBaseOut`         | 11  | Exact-output swap. Same as above.                                                 |
| Swap           | `SwapBaseInV2`        | 16  | **Recommended.** Exact-input swap without the market accounts.                    |
| Swap           | `SwapBaseOutV2`       | 17  | **Recommended.** Exact-output swap without the market accounts.                   |
| Upkeep         | `SetParams`           | 6   | Admin: change pool parameters. **Layout + `param` values changed** (breaking).    |
| Upkeep         | `WithdrawPnl`         | 7   | Sweep accrued protocol PnL. **Account layout changed** (breaking).                |
| Upkeep         | `CreateConfigAccount` | 14  | Admin: initialize the program-level `AmmConfig` PDA.                              |
| Upkeep         | `UpdateConfigAccount` | 15  | Admin: change program-level config params.                                        |

The SDK exposes builders for the user-facing instructions only. Upkeep instructions are typically invoked by the Raydium keeper.

**Removed / no longer callable** (they now revert with `unimplemented!`, and their client builders were deleted): `Initialize` (tag 0, use `Initialize2`), `MonitorStep` (2), `MigrateToOpenBook` (5), `WithdrawSrm` (8), `PreInitialize` (10, use `Initialize2`), `SimulateInfo` (12), `AdminCancelOrders` (13).

## `Initialize2`

Bootstrap a new AMM v4 pool bound to an existing OpenBook market.

**Arguments**

```
nonce:        u8
open_time:    u64
init_pc_amount:   u64
init_coin_amount: u64
```

**Accounts** (writable `W`, signer `S`)

| #  | Name                         | W | S | Notes                                         |
| -- | ---------------------------- | - | - | --------------------------------------------- |
| 1  | `token_program`              |   |   | SPL Token.                                    |
| 2  | `system_program`             |   |   |                                               |
| 3  | `rent`                       |   |   |                                               |
| 4  | `amm`                        | W |   | `AmmInfo` account (seeded key).               |
| 5  | `amm_authority`              |   |   | Program PDA.                                  |
| 6  | `amm_open_orders`            | W |   | OpenBook `OpenOrders` (seeded).               |
| 7  | `lp_mint`                    | W |   |                                               |
| 8  | `coin_mint`                  |   |   |                                               |
| 9  | `pc_mint`                    |   |   |                                               |
| 10 | `pool_coin_token_account`    | W |   |                                               |
| 11 | `pool_pc_token_account`      | W |   |                                               |
| 12 | `pool_withdraw_queue`        | W |   |                                               |
| 13 | `pool_target_orders_account` | W |   |                                               |
| 14 | `pool_lp_token_account`      | W |   | Creator's LP ATA.                             |
| 15 | `pool_temp_lp_token_account` | W |   | Scratch account.                              |
| 16 | `market_program`             |   |   | OpenBook program.                             |
| 17 | `market`                     |   |   | OpenBook market.                              |
| 18 | `user_wallet`                | W | S | Creator. Pays rent and funds initial deposit. |
| 19 | `user_token_coin`            | W |   |                                               |
| 20 | `user_token_pc`              | W |   |                                               |

**Postconditions**

* `lp_supply = sqrt(init_coin_amount × init_pc_amount) − INIT_BURN`, where `INIT_BURN` ≈ 100 LP units are kept out of circulation.
* No OpenBook orders are posted (the order-book grid has been removed). `market_program` / `market` are still passed but only stored as reference fields; `coin_lot_size` / `pc_lot_size` / `min_size` are initialized to `0`.

**Common errors** — `InvalidInput` (mismatched decimals, non-sorted), `NotAllowed`.

## `Deposit`

Add liquidity.

**Arguments**

```
max_coin_amount: u64
max_pc_amount:   u64
base_side:       u64    // 0 = base on coin, 1 = base on pc
// (some SDK variants also accept other_amount_min)
```

**Accounts** (abridged)

| #  | Name                      | W | S |
| -- | ------------------------- | - | - |
| 1  | `token_program`           |   |   |
| 2  | `amm`                     | W |   |
| 3  | `amm_authority`           |   |   |
| 4  | `amm_open_orders`         |   |   |
| 5  | `amm_target_orders`       | W |   |
| 6  | `lp_mint`                 | W |   |
| 7  | `pool_coin_token_account` | W |   |
| 8  | `pool_pc_token_account`   | W |   |
| 9  | `market`                  |   |   |
| 10 | `user_coin_token_account` | W |   |
| 11 | `user_pc_token_account`   | W |   |
| 12 | `user_lp_token_account`   | W |   |
| 13 | `user_owner`              |   | S |

**Math** — standard pro-rata. Using the pool's *effective* reserves (vaults + on-book), the SDK computes the coin/pc pair that yields the given LP amount and checks it against `max_*`. Reverts with `ExceededSlippage` if either side exceeds the cap.

## `Withdraw`

Burn LP, receive both sides.

**Arguments**

```
amount: u64    // LP to burn
```

**Accounts** — like `Deposit` with the direction reversed; `lp_mint` is writable for burn, the user ATAs are receivers. The account layout is unchanged (market accounts still passed positionally, ignored). There is no longer any settle-from-OpenBook step — the pro-rata math uses the vault balances directly.

## `SwapBaseIn`

Exact-input swap. Always an **AMM-path** swap (does not route through OpenBook matching).

<Note>
  **Use the V2 variants for new code.** Since AMM v4's OpenBook dependency has been removed, the V1 entrypoints (`SwapBaseIn`, `SwapBaseOut`) still expect the full 17-account list (or 18 with the optional target-orders account), but the OpenBook/market accounts are now **accepted positionally and ignored** — they are not validated and no CPI is issued. Passing a wrong account *count* still reverts with `WrongAccountsNumber`, but the market account *contents* are no longer checked. New integrations should use [`SwapBaseInV2` / `SwapBaseOutV2`](#swapbaseinv2-swapbaseoutv2), which take a much smaller account list and represent the canonical execution path today. The V1 forms are documented here for completeness and for reading existing on-chain transactions.
</Note>

**Arguments**

```
amount_in:            u64
minimum_amount_out:   u64
```

**Accounts** (abridged)

| #  | Name                        | W | S |
| -- | --------------------------- | - | - |
| 1  | `token_program`             |   |   |
| 2  | `amm`                       | W |   |
| 3  | `amm_authority`             |   |   |
| 4  | `amm_open_orders`           | W |   |
| 5  | `amm_target_orders`         | W |   |
| 6  | `pool_coin_token_account`   | W |   |
| 7  | `pool_pc_token_account`     | W |   |
| 8  | `market_program`            |   |   |
| 9  | `market`                    | W |   |
| 10 | `market_bids`               | W |   |
| 11 | `market_asks`               | W |   |
| 12 | `market_event_queue`        | W |   |
| 13 | `market_coin_vault`         | W |   |
| 14 | `market_pc_vault`           | W |   |
| 15 | `market_vault_signer`       |   |   |
| 16 | `user_source_token_account` | W |   |
| 17 | `user_dest_token_account`   | W |   |
| 18 | `user_owner`                |   | S |

**Math** — see [`products/amm-v4/math`](/products/amm-v4/math).

**Preconditions**

* `amm.status` allows swap (bit 0 of the status bitmask not set).
* `amm.state_data.pool_open_time <= now`.
* `amount_in > 0`.
* `user_source_token_account` holds at least `amount_in`.

**Postconditions**

* User loses `amount_in` of source token, gains `amount_out ≥ minimum_amount_out` of dest token.
* `need_take_pnl_*` incremented by the protocol fee share.
* Note: the `state_data.swap_*_in_amount` / `swap_*_out_amount` analytics counters are **no longer updated** — their values are frozen. Use trade logs for volume analytics.

**Common errors** — `ExceededSlippage`, `InvalidInput`, `InvalidStatus`, `NotAllowed` (coin/pc mint identical).

## `SwapBaseOut`

Exact-output, inverse of `SwapBaseIn`. Same accounts.

**Arguments**

```
max_amount_in: u64
amount_out:    u64
```

## `SwapBaseInV2` / `SwapBaseOutV2`

Variant swap entrypoints (tags **16** / **17**) that **skip the OpenBook accounts entirely**. The math is identical to the V1 path, but the account list shrinks to just the AMM side and the user — **8 accounts, and `amm_open_orders` is not passed**:

| # | Name                        | W | S |
| - | --------------------------- | - | - |
| 1 | `token_program`             |   |   |
| 2 | `amm`                       | W |   |
| 3 | `amm_authority`             |   |   |
| 4 | `pool_coin_token_account`   | W |   |
| 5 | `pool_pc_token_account`     | W |   |
| 6 | `user_source_token_account` | W |   |
| 7 | `user_dest_token_account`   | W |   |
| 8 | `user_owner`                |   | S |

Pool reserves are now the vault balances (minus pending PnL), so quote math is straightforward and identical to the v1 path. Use V2 to save compute and avoid passing the (now-ignored) market accounts. The Raydium router always uses the V2 form when routing through AMM v4.

Arguments are the same as the V1 forms (`amount_in / minimum_amount_out` for `SwapBaseInV2`; `max_amount_in / amount_out` for `SwapBaseOutV2`).

## `MonitorStep` and other removed instructions

<Warning>
  **Removed — no longer callable.** As of the 2026-07 upgrade, `MonitorStep` (tag 2) has been removed from the program and now **reverts** (`unimplemented!`) if invoked. Its client builder was also deleted. The same applies to `MigrateToOpenBook` (5), `WithdrawSrm` (8), `SimulateInfo` (12), `AdminCancelOrders` (13), and the legacy `Initialize` (0) / `PreInitialize` (10) pool-creation entrypoints — use `Initialize2` instead.
</Warning>

Historically, `MonitorStep` cranked the pool's OpenBook interaction: it settled filled orders (moving proceeds from the market vaults into the pool vaults via OpenBook CPI), cancelled stale orders, and posted new orders to close the gap between `target_orders` and `amm_open_orders`. With the OpenBook dependency removed, there is nothing to crank and the instruction is gone. Any keeper or integration that still calls it must remove the call.

## `WithdrawPnl` / `TakePnl`

Admin sweep of accrued protocol fees.

**Arguments**

* `WithdrawPnl` takes no args; it reads `need_take_pnl_*` and moves those exact amounts.

<Warning>
  **Breaking change (admin only).** The account list dropped from 17 (+1 optional) to **10** — `amm_open_orders` and all six market accounts were removed — with **no compatibility parsing**. The old layout misaligns (old #5 was `amm_open_orders`, now `pool_coin_token_account`) and fails with errors such as `InvalidCoinVault`. Admin tooling must be updated.
</Warning>

**Accounts** (new 10-account layout)

| #  | Name                      | W | S |                 |
| -- | ------------------------- | - | - | --------------- |
| 1  | `token_program`           |   |   |                 |
| 2  | `amm`                     | W |   |                 |
| 3  | `amm_config`              |   |   |                 |
| 4  | `amm_authority`           |   |   |                 |
| 5  | `pool_coin_token_account` | W |   |                 |
| 6  | `pool_pc_token_account`   | W |   |                 |
| 7  | `pnl_coin_token_account`  | W |   | Recipient.      |
| 8  | `pnl_pc_token_account`    | W |   |                 |
| 9  | `pnl_owner`               |   | S | Admin multisig. |
| 10 | `amm_target_orders`       | W |   |                 |

**Effect**

* Transfers `need_take_pnl_coin` from `pool_coin_token_account` to `pnl_coin_token_account`.
* Same for pc.
* Zeros `need_take_pnl_coin` and `need_take_pnl_pc`.
* **Logic change**: if the vault balance is insufficient to cover accrued PnL, the instruction returns `TakePnlError` directly (it no longer manipulates order-book state).

No change to reserves since accrued PnL was already excluded from the invariant.

## `SetParams`

Admin param changes, called by the Raydium multisig. Arguments are a `param: u8` tag + payload.

<Warning>
  **Breaking change (admin only).** The account list was reduced to just `[amm (W), admin (S)]` (the authority, open-orders, target-orders, vault, and all market accounts were removed). The `param` enum was **renumbered and trimmed**: `Status` = 0, `State` = 1, `Fees` = **2** (was 9), `SetOpenTime` = **3** (was 11). All order-book-grid params and `AmmOwner`, `LastOrderDistance`, `UpdateOpenOrder` were removed, and the `SetParamsInstruction` struct dropped `new_pubkey` and `last_order_distance`. Admin tooling must be updated.
</Warning>

## State-change matrix

The OpenBook column is gone — no instruction touches an order book anymore.

| Instruction                     | `lp_mint` supply              | Vaults                                   | PnL counters |
| ------------------------------- | ----------------------------- | ---------------------------------------- | ------------ |
| `Initialize2`                   | init supply minted to creator | `+ init_coin_amount`, `+ init_pc_amount` | 0            |
| `Deposit`                       | +                             | + both                                   | —            |
| `Withdraw`                      | −                             | − both                                   | —            |
| `SwapBaseIn` / `SwapBaseInV2`   | —                             | + in, − out                              | + pnl share  |
| `SwapBaseOut` / `SwapBaseOutV2` | —                             | + in, − out                              | + pnl share  |
| `WithdrawPnl`                   | —                             | − (pnl swept)                            | 0            |
| `SetParams`                     | —                             | —                                        | —            |

## Where to go next

* [`products/amm-v4/code-demos`](/products/amm-v4/code-demos) — TypeScript examples for swap and LP flows.
* [`products/amm-v4/fees`](/products/amm-v4/fees) — `WithdrawPnl` details and the fee split.
* [`reference/error-codes`](/reference/error-codes) — forward-reference table (AMM v4 errors are listed on that page).

Sources:

* [Raydium AMM program — `raydium-io/raydium-amm`](https://github.com/raydium-io/raydium-amm)
* Raydium SDK v2 `Liquidity` module
* OpenBook program — account validations on the market side
