> ## 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.

# CPMM instructions

> Every instruction on the CPMM program, with its arguments, account list, pre/post conditions, and the errors it can return.

> [!NOTE]
>
> This page is the authoritative instruction reference. For code that actually composes these instructions, see [`products/cpmm/code-demos`](https://docs.raydium.io/products/cpmm/code-demos). For error-code meanings see [`reference/error-codes`](https://docs.raydium.io/reference/error-codes).
>
> The 2026-09 program upgrade rebuilt CPMM on Anchor 1.0.2 / Solana 3.1.10, added the admin instruction `CollectExcessLamports`, removed the hardcoded Token-2022 mint whitelist, and changed what `CreateAmmConfig` writes into `protocol_owner` / `fund_owner`. No user-facing instruction changed its accounts, arguments or math. See the [2026-09-09 changelog entry](https://docs.raydium.io/reference/changelog/2026-09-09-cpmm-anchor-1-and-excess-lamports.md).
>
> The 2026-10-30 upgrade adds [`InitializeV2`](#initializev2): permissionless pool creation where the creator chooses whether to enable the creator fee and on which side. It is purely additive. `Initialize`, `InitializeWithPermission` and every other instruction keep their discriminators, accounts and arguments. See the [2026-10-30 changelog entry](https://docs.raydium.io/reference/changelog/2026-10-30-cpmm-initialize-v2.md).

> [!WARNING]
>
> **Both creator-fee collection instructions changed their account lists on 2026-09-19.** `CollectCreatorFee` gains `creator_fee_share`; `CollectCreatorFeePermissionless` gains `amm_config` **and** `creator_fee_share`. Both are **appended after `system_program`**, so every account an existing client already passes keeps its index — but the new accounts are mandatory, so a transaction built against the older layout comes up short and is rejected with Anchor's `AccountNotEnoughKeys` (`3005`). Two admin instructions — `CreateCreatorFeeShare` and `CloseCreatorFeeShare` — are added, and `UpdateAmmConfig` takes a new `param = 8`. See the [2026-09-19 changelog entry](https://docs.raydium.io/reference/changelog/2026-09-19-cpmm-creator-fee-protocol-share.md).

## Instruction summary

| Discriminator name | Who signs | What it does |
| - | - | - |
| `Initialize` | pool creator | Create a new CPMM pool from two mints and an `AmmConfig`. Permissionless; anyone can call it. Hardcodes `enable_creator_fee = false` on the new pool. The `pool_state` account can be either the canonical PDA or a fresh random keypair (see Initialize accounts). |
| `InitializeV2` | pool creator | Same as `Initialize`, plus an optional `creator_fee_on` argument. Permissionless. `Some(...)` stores `enable_creator_fee = true` with the chosen side; `None` stores the same creator-fee settings as `Initialize`. Same accounts as `Initialize` minus the trailing `rent` sysvar. Added 2026-10-30. |
| `InitializeWithPermission` | payer + a holder of a `Permission` PDA | Permissioned variant of `Initialize`. The caller (`payer`) must own a `Permission` PDA derived from their own pubkey. Used by platforms that need gated pool creation (e.g. LaunchLab graduations). Lets the caller pin `creator_fee_on` (`BothToken` / `OnlyToken0` / `OnlyToken1`) and forces `enable_creator_fee = true` on the new pool. The `creator` field on `pool_state` is set to a separately-passed `creator` account, not the payer. Same canonical-PDA-or-random-keypair flexibility for `pool_state` as `Initialize`. |
| `Deposit` | LP | Add liquidity in both tokens; receive LP tokens. |
| `Withdraw` | LP | Burn LP tokens; receive both underlying tokens pro-rata. |
| `SwapBaseInput` | swapper | Exact-input swap (`amount_in` in, ≥ `minimum_amount_out` out). |
| `SwapBaseOutput` | swapper | Exact-output swap (≤ `maximum_amount_in` in, `amount_out` out). |
| `CollectProtocolFee` | `protocol_owner` (from `AmmConfig`) | Sweep accrued protocol fees from vaults. |
| `CollectFundFee` | `fund_owner` (from `AmmConfig`) | Sweep accrued fund fees from vaults. |
| `CollectCreatorFee` | `pool_creator` | Sweep accrued creator fees (if creator fee was enabled), net of the protocol's share, which is booked into the pool's protocol bucket. |
| `CollectCreatorFeePermissionless` | any payer | Sweep accrued creator fees to the `pool_creator`'s canonical token accounts, net of the same protocol share. The payer can create missing recipient ATAs but cannot redirect the transfer. |
| `UpdatePoolStatus` | `admin` | Pause / resume specific operations on a pool via a bitmask. |
| `UpdateAmmConfig` | `admin` | Change fee rates or the protocol/fund owner on an `AmmConfig`. |
| `CreateAmmConfig` | `admin` | Create a new fee tier (new `AmmConfig` account). |
| `CreatePermissionPda` | `admin` or delegated permission-PDA creator | Mint a `Permission` PDA that allows a specific authority to call `InitializeWithPermission`. |
| `ClosePermissionPda` | `admin` or the dedicated permission-PDA creator | Revoke a previously-issued `Permission` PDA. Since the 2026-09 upgrade the dedicated creator authority may also close a grant it issued; it was admin-only before. |
| `CreateSupportMintAssociated` | `admin` or the dedicated support-mint owner | Register a Token-2022 mint that would otherwise fail the extension allow-list, by creating its `SupportMintAssociated` PDA. |
| `CloseSupportMintAssociated` | `admin` or the dedicated support-mint owner | Remove a mint's registration. |
| `CollectExcessLamports` | `admin` or the dedicated collect-lamports wallet | Sweep lamports above the rent-exempt minimum from CPMM-controlled vaults, LP mints and PDAs. Added 2026-09. |
| `CreateCreatorFeeShare` | `admin` or the dedicated creator-fee-share owner | Set a custom protocol share of the creator fee for one `(creator, amm_config)` pair, overriding `AmmConfig.creator_fee_share_rate`. Added 2026-09-19. |
| `CloseCreatorFeeShare` | `admin` or the dedicated creator-fee-share owner | Remove that override; the pair falls back to the config default. Added 2026-09-19. |

Status bitmask: each pool's `status` is a `u8` where bit 0 = deposit disabled, bit 1 = withdraw disabled, bit 2 = swap disabled (`PoolStatusBitIndex { Deposit, Withdraw, Swap }` in the program). A clear bit means the operation is allowed; a set bit means it is paused. `UpdatePoolStatus` takes a raw `u8` and overwrites the existing value.

The next sections go through each in detail. Account ordering follows the CPMM IDL; the SDK and the Rust client in `raydium-cp-swap/programs/cp-swap/src/instructions` match this order.

## `Initialize`

Create a new CPMM pool.

**Arguments**

```
init_amount_0: u64
init_amount_1: u64
open_time:     u64   // Unix timestamp; swaps rejected before this
```

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

| # | Name | W | S | Notes |
| - | - | - | - | - |
| 1 | `creator` | W | S | Pays rent; recorded as `pool_state.pool_creator`. |
| 2 | `amm_config` | | | The chosen fee tier. |
| 3 | `authority` | | | CPMM global authority PDA. |
| 4 | `pool_state` | W | S\* | `init`ed here. **Either** the canonical PDA `["pool", amm_config, token_0_mint, token_1_mint]` **or** a fresh random keypair — when not the canonical PDA, the program requires `pool_state` to sign (`require_eq!(pool_account_info.is_signer, true)`). The random-keypair path lets a creator dodge front-running attempts on the canonical PDA. The downstream PDAs (`lp_mint`, `vaults`, `observation_state`) are derived from `pool_state.key()` either way. |
| 5 | `token_0_mint` | | | Sorted: `token_0_mint < token_1_mint`. |
| 6 | `token_1_mint` | | | |
| 7 | `lp_mint` | W | | `init`ed here. Authority set to `authority`. |
| 8 | `creator_token_0` | W | | Source ATA for `init_amount_0`. |
| 9 | `creator_token_1` | W | | Source ATA for `init_amount_1`. |
| 10 | `creator_lp_token` | W | | Creator's ATA on `lp_mint`. `init` (not `init_if_needed`) — it must not already exist, which it cannot, since `lp_mint` is created in this same instruction. |
| 11 | `token_0_vault` | W | | `init`ed here. Owned by `authority`. |
| 12 | `token_1_vault` | W | | |
| 13 | `create_pool_fee` | W | | Destination ATA for the `create_pool_fee` paid by the creator. |
| 14 | `observation_state` | W | | `init`ed here. |
| 15 | `token_program` | | | SPL Token (for LP mint). |
| 16 | `token_0_program` | | | SPL Token or Token-2022. |
| 17 | `token_1_program` | | | SPL Token or Token-2022. |
| 18 | `associated_token_program` | | | |
| 19 | `system_program` | | | |
| 20 | `rent` | | | |

`*` `pool_state` signs only on the random-keypair path; the canonical-PDA path runs without `pool_state` signing.

**Preconditions**

* Mints are sorted (`token_0_mint < token_1_mint` by byte order).
* Neither mint uses an extension outside the CPMM allow-list (`TransferFeeConfig`, `MetadataPointer`, `TokenMetadata`, `InterestBearingConfig`, `ScaledUiAmount`) — see [`products/cpmm/accounts`](https://docs.raydium.io/products/cpmm/accounts#vaults-and-token-2022). A mint whose `SupportMintAssociated` PDA (seed `[b"support_mint", mint]`) exists skips the extension check — **but you must append that PDA to `remaining_accounts`**. The program only scans the accounts you pass and never loads the PDA itself, so relying on the registry without supplying the account still fails with `NotSupportMint` (`6007`). Order does not matter (matching is by key); pass one entry per mint that needs the bypass. That registry is the only bypass since the 2026-09 upgrade removed the hardcoded four-mint whitelist.
* `creator` has at least `init_amount_0` and `init_amount_1` in the respective ATAs.
* `amm_config.disable_create_pool == false`.

**Postconditions**

* `pool_state.lp_supply = sqrt(init_amount_0 * init_amount_1)` — the **full** square root. The creator is minted `lp_supply − 100`; the 100 locked base units are counted in `lp_supply` but never minted.
* So `lp_mint.supply == pool_state.lp_supply − 100` for the life of the pool. All LP-share math (deposit, withdraw) divides by `lp_supply`, so use that field and do not substitute the mint's on-chain supply. Reverts with `InitLpAmountTooLess` if `sqrt(...) < 100`.
* `observation_state` is initialized; `observation_index = 0` and `pool_id = pool_state.key()`.
* `create_pool_fee` lamports are transferred from the creator to the receiver and synced as native SOL (it is a wSOL ATA).
* The pool's status bitmask is `0` (deposit / withdraw / swap all enabled).
* `enable_creator_fee = false` and `creator_fee_on = BothToken`. `Initialize` does **not** support enabling the creator fee. Use [`InitializeV2`](#initializev2) to enable it without a permission grant.
* `open_time` is bumped to `block_timestamp + 1` if the caller passed a value `<= block_timestamp`. Swaps are rejected before `open_time`; deposits and withdrawals work immediately.

**Common errors** (full list in [`reference/error-codes`](https://docs.raydium.io/reference/error-codes))

* `InvalidInput` — mints unsorted, or identical mints.
* `NotSupportMint` — blocked Token-2022 extension.
* `ExceededSlippage` — rarely; if `init_amount_0/1` result in zero LP due to decimals mismatch.

## `InitializeV2`

Create a new CPMM pool and choose its creator-fee settings. Added in the 2026-10-30 upgrade.

`InitializeV2` runs the same creation flow as `Initialize`. The only difference is what it writes into `enable_creator_fee` and `creator_fee_on` on the new pool. Before this instruction, only `InitializeWithPermission` could create a pool with the creator fee enabled, and that path needs an admin-issued `Permission` PDA.

**Arguments**

```
init_amount_0:  u64
init_amount_1:  u64
open_time:      u64                    // Unix timestamp; swaps rejected before this
creator_fee_on: Option<CreatorFeeOn>   // None = creator fee off
                                       // Some(BothToken | OnlyToken0 | OnlyToken1) = creator fee on
```

`CreatorFeeOn` is a Borsh enum, so the argument encodes as one tag byte for the `Option`, plus one variant byte when it is `Some`:

| Value | Bytes | Stored on `pool_state` |
| - | - | - |
| `None` | `00` | `enable_creator_fee = false`, `creator_fee_on = 0` (`BothToken`) |
| `Some(BothToken)` | `01 00` | `enable_creator_fee = true`, `creator_fee_on = 0` |
| `Some(OnlyToken0)` | `01 01` | `enable_creator_fee = true`, `creator_fee_on = 1` |
| `Some(OnlyToken1)` | `01 02` | `enable_creator_fee = true`, `creator_fee_on = 2` |

Any other byte fails Anchor's argument deserialization before the handler runs.

Discriminator: `initialize_v2` → `[67, 153, 175, 39, 218, 16, 38, 32]`.

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

The first 19 accounts are identical to [`Initialize`](#initialize), in the same order. `InitializeV2` drops only the trailing `rent` sysvar.

| # | Name | W | S | Notes |
| - | - | - | - | - |
| 1 | `creator` | W | S | Pays rent, the create-pool fee and the initial liquidity. Recorded as `pool_state.pool_creator`, so the creator fee goes to this signer. |
| 2 | `amm_config` | | | The chosen fee tier. Its `creator_fee_rate` is the rate the pool charges. |
| 3 | `authority` | | | CPMM global authority PDA. |
| 4 | `pool_state` | W | S\* | Canonical PDA **or** a fresh random keypair, exactly as on `Initialize`. |
| 5 | `token_0_mint` | | | Sorted: `token_0_mint < token_1_mint`. |
| 6 | `token_1_mint` | | | |
| 7 | `lp_mint` | W | | `init`ed here. |
| 8 | `creator_token_0` | W | | Source account for `init_amount_0`. |
| 9 | `creator_token_1` | W | | Source account for `init_amount_1`. |
| 10 | `creator_lp_token` | W | | Creator's ATA on `lp_mint`. `init`ed here. |
| 11 | `token_0_vault` | W | | `init`ed here. |
| 12 | `token_1_vault` | W | | |
| 13 | `create_pool_fee` | W | | Destination for the `create_pool_fee`. |
| 14 | `observation_state` | W | | `init`ed here. |
| 15 | `token_program` | | | SPL Token (for LP mint). |
| 16 | `token_0_program` | | | SPL Token or Token-2022. |
| 17 | `token_1_program` | | | SPL Token or Token-2022. |
| 18 | `associated_token_program` | | | |
| 19 | `system_program` | | | |

`*` `pool_state` signs only on the random-keypair path.

`remaining_accounts` work the same way as on `Initialize`: append the `SupportMintAssociated` PDA for any Token-2022 mint that needs the registry bypass.

> [!NOTE]
>
> Because the first 19 accounts match, you can adapt an existing `Initialize` builder: change the discriminator, append the `creator_fee_on` bytes, and drop `rent`. If you leave `rent` in, Anchor passes it through as a `remaining_accounts` entry, and the support-mint scan skips it because it is not a CPMM-owned account. Drop it anyway to save the account slot.

**Preconditions** — the same as `Initialize`. There is no permission check and no new constraint on `creator_fee_on`.

**Postconditions** — the same as `Initialize`, except:

* `enable_creator_fee` and `creator_fee_on` are set from the argument, as in the table above.
* `pool_creator` is always the signing `creator`. On `InitializeWithPermission` the creator is a separate, non-signing account; on `InitializeV2` it cannot be set to anyone else.

> [!NOTE]
>
> **Enabling the creator fee does not choose its rate.** The pool charges `AmmConfig.creator_fee_rate` of the fee tier it binds to. On a tier where that rate is `0`, an enabled pool accrues nothing. Read the config before you pick a tier. The choice is also permanent: no instruction changes `enable_creator_fee` or `creator_fee_on` after creation. See [`products/cpmm/fees`](https://docs.raydium.io/products/cpmm/fees#creator-fee).

When the fee is enabled, swaps accrue it to `creator_fees_token_{0,1}`. The creator collects it through `CollectCreatorFee` or `CollectCreatorFeePermissionless`, and the protocol share from the 2026-09-19 upgrade applies as usual.

**Common errors** — the same as `Initialize`.

## `Deposit`

Add liquidity in both tokens proportional to the pool.

**Arguments**

```
lp_token_amount:   u64   // how many LP tokens to mint to the LP
maximum_token_0:   u64
maximum_token_1:   u64
```

**Accounts**

| # | Name | W | S |
| - | - | - | - |
| 1 | `owner` | | S |
| 2 | `authority` | | |
| 3 | `pool_state` | W | |
| 4 | `owner_lp_token` | W | |
| 5 | `token_0_account` | W | |
| 6 | `token_1_account` | W | |
| 7 | `token_0_vault` | W | |
| 8 | `token_1_vault` | W | |
| 9 | `token_program` | | |
| 10 | `token_program_2022` | | |
| 11 | `vault_0_mint` | | |
| 12 | `vault_1_mint` | | |
| 13 | `lp_mint` | W | |

**Math**

```
total_0 = vault_0 − protocol_fees_0 − fund_fees_0 − creator_fees_0    // same for side 1

needed_token_0 = ceil(lp_token_amount * total_0 / lp_supply)
transfer_0     = needed_token_0 + inverse_transfer_fee(needed_token_0) // Token-2022
require(transfer_0 <= maximum_token_0, "ExceededSlippage")             // same for side 1
```

Two details worth pinning down: the pro-rata base is the **fee-excluded** vault total (`vault_amount_without_fee`, i.e. the raw balance minus the accrued protocol, fund and creator counters), not the raw vault balance; and the slippage cap is checked against what the payer actually transfers, *after* the Token-2022 transfer fee is added on, not against the gross vault movement.

No change to `k`'s proportionality — both totals and `lp_supply` scale by the same factor.

**Postconditions**

* `lp_supply += lp_token_amount`.
* `vault_0 += needed_token_0` (net of any Token-2022 transfer fee on input).
* `vault_1 += needed_token_1` (net of any Token-2022 transfer fee on input).

**Common errors** — `ExceededSlippage`, `ZeroTradingTokens`, `InvalidStatus` if deposit is paused.

## `Withdraw`

Burn LP tokens and receive both underlying tokens pro-rata.

**Arguments**

```
lp_token_amount:   u64
minimum_token_0:   u64
minimum_token_1:   u64
```

**Accounts**

| # | Name | W | S |
| - | - | - | - |
| 1 | `owner` | | S |
| 2 | `authority` | | |
| 3 | `pool_state` | W | |
| 4 | `owner_lp_token` | W | |
| 5 | `token_0_account` | W | |
| 6 | `token_1_account` | W | |
| 7 | `token_0_vault` | W | |
| 8 | `token_1_vault` | W | |
| 9 | `token_program` | | |
| 10 | `token_program_2022` | | |
| 11 | `vault_0_mint` | | |
| 12 | `vault_1_mint` | | |
| 13 | `lp_mint` | W | |
| 14 | `memo_program` | | |

The first 13 accounts are identical to `Deposit`, and `lp_mint` is writable because the LP tokens are burned. `Withdraw` additionally takes a 14th account, `memo_program` (constrained `address = memo::ID`) — `Deposit` does not. A 13-account `Withdraw` fails Anchor deserialization, so the LP cannot exit.

**Math**

```
total_0 = vault_0 − protocol_fees_0 − fund_fees_0 − creator_fees_0    // same for side 1

out_token_0     = min(total_0, floor(lp_token_amount * total_0 / lp_supply))
receive_token_0 = out_token_0 − transfer_fee(out_token_0)             // Token-2022
require(receive_token_0 >= minimum_token_0, "ExceededSlippage")       // same for side 1

// As with Deposit: the base is the fee-excluded vault total, and the floor is
// checked against what the LP actually receives, after the transfer fee.
```

**Postconditions**

* `lp_supply -= lp_token_amount`.
* Vaults send `out_token_0` / `out_token_1` (gross; the user receives net of any Token-2022 transfer fee).

## `SwapBaseInput`

Exact-input swap.

**Arguments**

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

**Accounts**

| # | Name | W | S |
| - | - | - | - |
| 1 | `payer` | | S |
| 2 | `authority` | | |
| 3 | `amm_config` | | |
| 4 | `pool_state` | W | |
| 5 | `input_token_account` | W | |
| 6 | `output_token_account` | W | |
| 7 | `input_vault` | W | |
| 8 | `output_vault` | W | |
| 9 | `input_token_program` | | |
| 10 | `output_token_program` | | |
| 11 | `input_token_mint` | | |
| 12 | `output_token_mint` | | |
| 13 | `observation_state` | W | |

The ordering **input → output** is by the user's direction, not by the pool's canonical `token_0 / token_1`. The program figures out which vault is which by matching mints.

**Math** — see [`products/cpmm/math`](https://docs.raydium.io/products/cpmm/math).

**Preconditions**

* `open_time <= now`.
* `pool_status` allows swap.
* Neither mint paused or frozen for this authority.
* `amount_in > 0`.

**Common errors**

* `ExceededSlippage` — `amount_out < minimum_amount_out`.
* `ZeroTradingTokens` — the trade rounds to zero.
* `NotApproved` — pool is paused for swaps via `UpdatePoolStatus`.
* `InvalidInput` — mints do not match either of the pool's vault mints.

## `SwapBaseOutput`

Exact-output swap.

**Arguments**

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

**Accounts** — same as `SwapBaseInput`.

**Math** — inverse curve with ceiling, see [`products/cpmm/math`](https://docs.raydium.io/products/cpmm/math).

**Common errors** — `ExceededSlippage` (`gross_in > max_amount_in`), `ZeroTradingTokens`, `InvalidInput`, `NotApproved`.

## `CollectProtocolFee`

Sweep accrued protocol fees from the vaults to the protocol destination.

**Arguments** — none.

**Accounts**

| # | Name | W | S | Notes |
| - | - | - | - | - |
| 1 | `owner` | | S | Must equal `amm_config.protocol_owner` **or** the program's hardcoded admin key. |
| 2 | `authority` | | | |
| 3 | `pool_state` | W | | |
| 4 | `amm_config` | | | |
| 5 | `token_0_vault` | W | | |
| 6 | `token_1_vault` | W | | |
| 7 | `vault_0_mint` | | | |
| 8 | `vault_1_mint` | | | |
| 9 | `recipient_token_0_account` | W | | |
| 10 | `recipient_token_1_account` | W | | |
| 11 | `token_program` | | | |
| 12 | `token_program_2022` | | | |

**Effect**

```
transfer pool_state.protocol_fees_token0 from vault_0 to recipient_0
transfer pool_state.protocol_fees_token1 from vault_1 to recipient_1
pool_state.protocol_fees_token0 = 0
pool_state.protocol_fees_token1 = 0
```

No change to the curve's effective balances (accrued fees were already excluded).

**Common error** — `InvalidOwner` (`6001`) if the signer is neither `amm_config.protocol_owner` nor the program admin. (There is no `NotApproved` on this path.)

## `CollectFundFee`

Same shape as `CollectProtocolFee` but signed by `amm_config.fund_owner` — or, again, the program admin — and zeroing the `fund_fees_*` counters. Same `InvalidOwner` on a wrong signer.

## `CollectCreatorFee`

Signed by `pool_state.pool_creator`. It settles the accrued creator fee and transfers the creator's part to the creator's token accounts.

**Arguments** — none.

**Accounts**

| # | Name | W | S | Notes |
| - | - | - | - | - |
| 1 | `creator` | W | S | Constrained `address = pool_state.pool_creator`. |
| 2 | `authority` | | | CPMM global vault authority PDA. |
| 3 | `pool_state` | W | | Holds the accrued creator-fee counters. |
| 4 | `amm_config` | | | Constrained `address = pool_state.amm_config`. Carries the default `creator_fee_share_rate`. |
| 5 | `token_0_vault` | W | | Must match the pool's token 0 vault. |
| 6 | `token_1_vault` | W | | Must match the pool's token 1 vault. |
| 7 | `vault_0_mint` | | | Must match `token_0_vault.mint`. |
| 8 | `vault_1_mint` | | | Must match `token_1_vault.mint`. |
| 9 | `creator_token_0` | W | | Destination for the creator's part of token 0. |
| 10 | `creator_token_1` | W | | Destination for the creator's part of token 1. |
| 11 | `token_0_program` | | | SPL Token or Token-2022, matching token 0. |
| 12 | `token_1_program` | | | SPL Token or Token-2022, matching token 1. |
| 13 | `associated_token_program` | | | |
| 14 | `system_program` | | | |
| 15 | `creator_fee_share` | | | **Added 2026-09-19**, appended after `system_program`. PDA at `["creator_fee_share", creator, amm_config]`. Must be passed on every call, but is **not required to exist** — when it is empty or not owned by CPMM the program falls back to `amm_config.creator_fee_share_rate`. The seed constraint still applies, so the address must be the canonical PDA. |

**Effect**

```
share_rate = creator_fee_share.share_rate   (if the account exists)
           | amm_config.creator_fee_share_rate   (otherwise)

shared_i  = floor(creator_fees_token_i * share_rate / 1_000_000)
creator_i = creator_fees_token_i - shared_i

transfer creator_i from vault_i to creator_token_i
pool_state.protocol_fees_token_i += shared_i     // stays in the vault
pool_state.creator_fees_token_i   = 0
pool_state.recent_epoch = current epoch
```

The protocol's share never leaves the vault here — it is re-labelled as a protocol fee and waits for `CollectProtocolFee`. Both counters are already excluded from the curve's view of the vault, so the pool's price does not move. Full derivation in [`products/cpmm/fees`](https://docs.raydium.io/products/cpmm/fees#protocol-share-of-the-creator-fee).

**Common errors** — `NoFeeCollect` when both creator counters are zero (checked before the split), `InvalidInput` (`6003`) if the resolved `share_rate` exceeds `1_000_000`, `MathOverflow` (`6011`) if booking the share would overflow `protocol_fees_token_*`, and Anchor's `ConstraintSeeds` error if `creator_fee_share` is not the canonical PDA.

## `CollectCreatorFeePermissionless`

Anyone can trigger creator-fee collection. The instruction always sends the creator's part to the canonical associated token accounts owned by `pool_state.pool_creator`; the caller cannot choose another creator or destination. If either ATA is missing, the payer funds its creation.

The original `CollectCreatorFee` remains callable, so a creator who wants to sign for their own collection still can.

**Arguments** — none.

**Accounts**

| # | Name | W | S | Notes |
| - | - | - | - | - |
| 1 | `payer` | W | S | Any signer; funds missing creator ATAs. |
| 2 | `creator` | | | Must equal `pool_state.pool_creator`; does not sign. |
| 3 | `authority` | | | CPMM global vault authority PDA. |
| 4 | `pool_state` | W | | Holds the accrued creator-fee counters. |
| 5 | `token_0_vault` | W | | Must match the pool's token 0 vault. |
| 6 | `token_1_vault` | W | | Must match the pool's token 1 vault. |
| 7 | `vault_0_mint` | | | Must match `token_0_vault.mint`. |
| 8 | `vault_1_mint` | | | Must match `token_1_vault.mint`. |
| 9 | `creator_token_0` | W | | Creator's canonical ATA for `vault_0_mint`; created if missing. |
| 10 | `creator_token_1` | W | | Creator's canonical ATA for `vault_1_mint`; created if missing. |
| 11 | `token_0_program` | | | SPL Token or Token-2022, matching token 0. |
| 12 | `token_1_program` | | | SPL Token or Token-2022, matching token 1. |
| 13 | `associated_token_program` | | | Creates a missing recipient ATA. |
| 14 | `system_program` | | | Funds account creation from `payer`. |
| 15 | `amm_config` | | | **Added 2026-09-19**, appended after `system_program`. Constrained `address = pool_state.amm_config`. |
| 16 | `creator_fee_share` | | | **Added 2026-09-19**, appended last. Same PDA and same optional-existence rule as on `CollectCreatorFee`. |

> [!WARNING]
>
> The two new accounts are **appended after `system_program`**, not inserted. Every account from `payer` through `system_program` keeps the position it had before the upgrade, so the break is a clean one: a transaction built against the pre-upgrade fourteen-account layout does not misread a vault as a config — it simply passes too few accounts and Anchor rejects it with `AccountNotEnoughKeys` (`3005`) before any constraint runs. The accounts are still mandatory, so append both and refresh the IDL; there is no compatibility path for the old layout.

**Effect** — identical to `CollectCreatorFee` above: the share is resolved from `creator_fee_share` or `amm_config`, the protocol's part is booked into `protocol_fees_token_{0,1}`, the creator's part is transferred to the creator ATAs, both creator counters are zeroed, and `recent_epoch` is updated. Returns `NoFeeCollect` when both counters are zero.

## `UpdatePoolStatus`

Pause or resume individual operations on a pool. The `status` field is a bitmask:

| Bit | Flag | Effect when set |
| - | - | - |
| 0 | `DEPOSIT_DISABLED` | `Deposit` rejects with `NotApproved`. |
| 1 | `WITHDRAW_DISABLED` | `Withdraw` rejects. |
| 2 | `SWAP_DISABLED` | `SwapBaseInput` / `SwapBaseOutput` reject. |

**Arguments**

```
status: u8      // new bitmask
```

**Accounts**

| # | Name | W | S | Notes |
| - | - | - | - | - |
| 1 | `authority` | | S | Must match the admin key on the CPMM program. |
| 2 | `pool_state` | W | | |

The admin key is a pubkey **compiled into the program** (`crate::admin::ID`), not the BPF upgrade authority — changing it requires a program upgrade. See [`reference/program-addresses`](https://docs.raydium.io/reference/program-addresses) for the value and [`security/admin-and-multisig`](https://docs.raydium.io/security/admin-and-multisig) for who holds it.

## `CreateAmmConfig`

Create a new fee tier.

**Arguments**

```
index:             u16
trade_fee_rate:    u64
protocol_fee_rate: u64
fund_fee_rate:     u64
create_pool_fee:   u64
creator_fee_rate:  u64
```

**Accounts**

| # | Name | W | S | Notes |
| - | - | - | - | - |
| 1 | `owner` | W | S | Admin. |
| 2 | `amm_config` | W | | `init`ed here. |
| 3 | `system_program` | | | |

**Preconditions**

* No existing `AmmConfig` with the same `index`.
* `protocol_fee_rate + fund_fee_rate <= FEE_RATE_DENOMINATOR_VALUE`.

> [!NOTE]
>
> **Changed in 2026-09: the new config's fee owners no longer come from the signer.** `create_amm_config` now writes the program's hardcoded `protocol_fee_owner::ID` into `protocol_owner` and `fund_fee_owner::ID` into `fund_owner`, instead of copying the admin signer's key into both. Addresses are in [`reference/program-addresses`](https://docs.raydium.io/reference/program-addresses#cpmm-fee-owner-wallets).
>
> Consequences: fees on a newly created `AmmConfig` land in the dedicated fee wallets rather than the admin's. The admin does remain an accepted *signer* for collection — `CollectProtocolFee` / `CollectFundFee` accept `amm_config.protocol_owner` / `fund_owner` **or** `crate::admin::ID` — so nothing has to be rotated to sweep; what changed is only where the proceeds go by default. **Existing `AmmConfig` accounts are not rewritten** — whatever is stored on them still governs, so always read `protocol_owner` / `fund_owner` off the account instead of assuming either value. `UpdateAmmConfig` params `3` and `4` still rotate them.

## `UpdateAmmConfig`

Change fee rates or ownership on an existing `AmmConfig`. Takes a `param: u8` (which field to update) and a `value: u64`. The full dispatch table:

* `param = 0` → `trade_fee_rate` (asserts `trade_fee_rate + creator_fee_rate < 1_000_000`)
* `param = 1` → `protocol_fee_rate` (asserts `≤ 1_000_000` and `+ fund_fee_rate ≤ 1_000_000`)
* `param = 2` → `fund_fee_rate` (asserts `≤ 1_000_000` and `+ protocol_fee_rate ≤ 1_000_000`)
* `param = 3` → `protocol_owner`. The new key is **not** in `value`: append it as `remaining_accounts[0]` (read-only is fine). It must not be the default pubkey, and omitting the account panics on an `unwrap()`.
* `param = 4` → `fund_owner`. Same mechanism as `3`.
* `param = 5` → `create_pool_fee`
* `param = 6` → `disable_create_pool` (any non-zero `value` disables)
* `param = 7` → `creator_fee_rate` (asserts `creator_fee_rate + trade_fee_rate < 1_000_000`)
* `param = 8` → `creator_fee_share_rate` (asserts `≤ 1_000_000`). Added 2026-09-19. The protocol's default share **of the creator fee** on this tier; see [`products/cpmm/fees`](https://docs.raydium.io/products/cpmm/fees#protocol-share-of-the-creator-fee). It is not related to `protocol_fee_rate`, which splits the trade fee.

Any other `param` returns `InvalidInput`.

Changes are signed by the admin and affect **every pool bound to this `AmmConfig`** on the next swap. No migration; pools simply read the new values.

## `CreateCreatorFeeShare`

Set a custom protocol share of the creator fee for one `(creator, amm_config)` pair, overriding `AmmConfig.creator_fee_share_rate` for every pool that creator owns on that fee tier. Added in the 2026-09-19 creator-fee-share upgrade.

**Arguments**

```
share_rate: u64   // protocol's share OF the creator fee, over FEE_RATE_DENOMINATOR = 1_000_000
```

**Accounts**

| # | Name | W | S | Notes |
| - | - | - | - | - |
| 1 | `owner` | W | S | Must be the CPMM program admin **or** the dedicated creator-fee-share owner — see [`reference/program-addresses`](https://docs.raydium.io/reference/program-addresses#cpmm-creator-fee-share-authority). Any other signer fails with `InvalidOwner` (`6001`). Pays rent. |
| 2 | `creator` | | | The pool creator the rate applies to. Unchecked — it does not have to be an existing pool creator, and it does not sign. |
| 3 | `amm_config` | | | The fee tier the rate applies to. |
| 4 | `creator_fee_share` | W | | `init`ed here at `["creator_fee_share", creator, amm_config]`, `space = 145`. |
| 5 | `system_program` | | | |

**Preconditions**

* `share_rate <= 1_000_000`, otherwise `InvalidInput` (`6003`).
* The PDA must not already exist — Anchor's `init` fails on a second call for the same pair. To change a rate, close the account and create it again.

**Postconditions**

* `creator_fee_share` stores `bump`, `creator`, `amm_config` and `share_rate`.
* Every subsequent `CollectCreatorFee` / `CollectCreatorFeePermissionless` on a pool created by `creator` under `amm_config` resolves the share from this account instead of the config.

> [!NOTE]
>
> The pool creator is not a party to this instruction and does not sign it. The rate is read at collection time, so an override created after fees have already accrued applies to that accrued balance too.

## `CloseCreatorFeeShare`

Remove the override. The pair falls back to `AmmConfig.creator_fee_share_rate`.

**Arguments** — none.

**Accounts**

| # | Name | W | S | Notes |
| - | - | - | - | - |
| 1 | `owner` | W | S | Same two accepted signers as `CreateCreatorFeeShare`; receives the rent. |
| 2 | `creator` | | | The pool creator the rate applied to. |
| 3 | `amm_config` | | | The fee tier the rate applied to. |
| 4 | `creator_fee_share` | W | | Closed to `owner`. Must be the canonical PDA for the pair. |
| 5 | `system_program` | | | |

**Postconditions**

* The account is closed and its lamports go to `owner`.
* Collections for that pair resolve the share from `amm_config.creator_fee_share_rate` again — which is `0` unless an admin has set `UpdateAmmConfig` param `8`.

## `CollectExcessLamports`

Admin sweep of lamports sitting above the rent-exempt minimum on accounts CPMM controls. Added in the 2026-09 upgrade so the protocol can reclaim the over-funding that the [SIMD-0437 rent reduction](https://docs.raydium.io/solana-fundamentals/rent-and-reclaimable-rent.md) leaves behind on accounts created before each step.

Only the excess moves. Token balances, account data, owners, pool state and the curve are untouched, and the instruction is a no-op against an account already at its minimum — so it is safe to re-run after each rollout step.

**Arguments** — none.

**Accounts**

| # | Name | W | S | Notes |
| - | - | - | - | - |
| 1 | `collect_lamports_wallet` | W | S | Destination for every swept lamport. Must be either the CPMM program admin or the dedicated collect-lamports wallet — see [`reference/program-addresses`](https://docs.raydium.io/reference/program-addresses#excess-lamports-collection-wallets). Any other signer fails with `InvalidOwner`. |
| 2 | `authority` | | | The CPMM vault-and-LP-mint authority PDA at seed `[b"vault_and_lp_mint_auth_seed"]`. It signs the token-program CPIs. |
| 3 | `token_program` | | | SPL Token. |
| 4 | `token_program_2022` | | | Token-2022. Both are required unconditionally; the program picks per source account. |
| 5.. | `remaining_accounts` | W | | `M` source accounts to sweep, any number, any order. |

> [!NOTE]
>
> **Ordering fix, 2026-09-19.** The program now makes two passes over `remaining_accounts` — every token-program CPI first, then the direct debits of CPMM-owned PDAs. Interleaving them aborted with the runtime's `UnbalancedInstruction` ("sum of account balances before and after instruction do not match") whenever a PDA was debited ahead of a CPI, because the caller's pending lamport changes are only flushed into accounts a CPI actually carries. Callers do not have to group or sort the list themselves.

**How each source account is handled**

The program dispatches on the source account's `owner`:

| Source account owner | Handling |
| - | - |
| SPL Token or Token-2022, non-native token account or mint — pool vaults and LP mints | CPI `WithdrawExcessLamports` (token-program discriminant `38`), signed by `authority`. |
| SPL Token or Token-2022, **native** (wSOL) token account | `WithdrawExcessLamports` rejects native accounts. The program CPIs `SyncNative`, measures how much the wrapped `amount` grew, `UnwrapLamports` (discriminant `45`) for exactly that delta, then requires the wrapped balance to equal its pre-sync value — otherwise `LamportsCalculateError` (`6015`). A SOL-side pool vault therefore keeps its full liquidity. |
| The CPMM program itself — `PoolState`, `AmmConfig`, `ObservationState`, `Permission`, `SupportMintAssociated` | The program debits the account directly down to `rent.minimum_balance(data_len)`. |
| Anything else | **Skipped silently.** No error, no lamports moved. |

Because it takes an unbounded `remaining_accounts` list, transaction size is the real limit — the same constraint as the wallet-side sweep described in [`solana-fundamentals/rent-and-reclaimable-rent`](https://docs.raydium.io/solana-fundamentals/rent-and-reclaimable-rent#batching-how-many-fit-in-one-transaction).

**Common errors** — `InvalidOwner` (`6001`, wrong signer), `LamportsCalculateError` (`6015`, the wSOL round-trip did not net to zero), and `InsufficientFunds` from the program-owned path when an account holds less than its own rent minimum.

**No SDK builder.** `@raydium-io/raydium-sdk-v2` does not ship a builder for this instruction, and neither does the `raydium-sdk-V2-demo` repo — it is an admin path. Encode it by hand, the way the wallet-side sweep in [`solana-fundamentals/rent-and-reclaimable-rent`](https://docs.raydium.io/solana-fundamentals/rent-and-reclaimable-rent#building-the-instruction) does for the token-program instruction.

## State-change matrix

| Instruction | `lp_supply` | Vault balances | Accrued-fee fields | `observation` |
| - | - | - | - | - |
| `Initialize` | + init LP | + `init_amount_{0,1}` | 0 | init |
| `InitializeV2` | + init LP | + `init_amount_{0,1}` | 0 | init |
| `InitializeWithPermission` | + init LP | + `init_amount_{0,1}` | 0 | init |
| `Deposit` | + | + both | — | — |
| `Withdraw` | − | − both | — | — |
| `SwapBaseInput` | — | + in, − out | + `trade_fee` split into protocol/fund; + `creator_fee` if enabled | + (if interval elapsed) |
| `SwapBaseOutput` | — | + in, − out | + `trade_fee` split into protocol/fund; + `creator_fee` if enabled | + (if interval elapsed) |
| `CollectProtocolFee` | — | − (by protocol buckets) | `protocol_*` → 0 | — |
| `CollectFundFee` | — | − (by fund buckets) | `fund_*` → 0 | — |
| `CollectCreatorFee` | — | − (by the creator's part only) | `creator_*` → 0; `protocol_*` += the shared part | — |
| `CollectCreatorFeePermissionless` | — | − (by the creator's part only) | `creator_*` → 0; `protocol_*` += the shared part | — |
| `UpdatePoolStatus` | — | — | — | — |
| `CreateCreatorFeeShare` | — | — | — | — |
| `CloseCreatorFeeShare` | — | — | — | — |
| `CollectExcessLamports` | — | — (token balances unchanged) | — | — |

## Where to go next

* [`products/cpmm/code-demos`](https://docs.raydium.io/products/cpmm/code-demos) — runnable TypeScript samples for the above.
* [`reference/error-codes`](https://docs.raydium.io/reference/error-codes) — the complete Anchor error table.
* [`products/cpmm/fees`](https://docs.raydium.io/products/cpmm/fees) — the fee-accrual model that the `Collect*Fee` instructions drain.

Sources:

* [`raydium-io/raydium-cp-swap` — instructions](https://github.com/raydium-io/raydium-cp-swap/tree/master/programs/cp-swap/src/instructions)
* [Raydium SDK v2 — `@raydium-io/raydium-sdk-v2`](https://github.com/raydium-io/raydium-sdk-V2)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.