# Raydium CPMM decoder (Carbon 2.0)

> Decode Raydium CPMM instructions, accounts and events in Rust with carbon-raydium-cpmm-decoder 2.0.0. Program ID CPMMoo8L3F4NbTegBCKVNunggL7H1ZpdTHKxQB5qKP1C.

`carbon-raydium-cpmm-decoder` decodes the instructions, accounts and events of the Raydium CPMM program (`CPMMoo8L3F4NbTegBCKVNunggL7H1ZpdTHKxQB5qKP1C`): 14 instructions, 4 account types, 2 events. It is generated with Codama from the program's IDL; see [decoders](https://carbon.sevenlabs.org/concepts/decoders.md) for how decoders plug into a pipeline.

|                  |                                                                                                                   |
| ---------------- | ----------------------------------------------------------------------------------------------------------------- |
| Crate            | [`carbon-raydium-cpmm-decoder`](https://crates.io/crates/carbon-raydium-cpmm-decoder/2.0.0) 2.0.0                 |
| Install          | `cargo add carbon-raydium-cpmm-decoder@2.0.0`                                                                     |
| Program ID       | `CPMMoo8L3F4NbTegBCKVNunggL7H1ZpdTHKxQB5qKP1C` (`carbon_raydium_cpmm_decoder::PROGRAM_ID`)                        |
| Category         | [DEX & AMM](https://carbon.sevenlabs.org/decoders/dex-and-amm.md)                                                 |
| Decoder          | `carbon_raydium_cpmm_decoder::RaydiumCpmmDecoder`                                                                 |
| Instruction enum | `instructions::RaydiumCpmmInstruction`                                                                            |
| Account enum     | `accounts::RaydiumCpmmAccount`                                                                                    |
| Event enum       | `instructions::CpiEvent`                                                                                          |
| Features         | `serde`, `postgres`, `graphql` (none enabled by default)                                                          |
| API docs         | [docs.rs/carbon-raydium-cpmm-decoder/2.0.0](https://docs.rs/carbon-raydium-cpmm-decoder/2.0.0)                    |
| Source           | [decoders/raydium-cpmm-decoder](https://github.com/sevenlabs-hq/carbon/tree/v2.0.0/decoders/raydium-cpmm-decoder) |

Other DEX and AMM decoders: [BonkSwap](https://carbon.sevenlabs.org/decoders/bonkswap.md), [FluxBeam](https://carbon.sevenlabs.org/decoders/fluxbeam.md), [Gavel](https://carbon.sevenlabs.org/decoders/gavel.md), [Heaven](https://carbon.sevenlabs.org/decoders/heaven.md), [Jupiter Limit Order](https://carbon.sevenlabs.org/decoders/jupiter-limit-order.md), [Jupiter Limit Order v2](https://carbon.sevenlabs.org/decoders/jupiter-limit-order-2.md), [Kamino Limit Order](https://carbon.sevenlabs.org/decoders/kamino-limit-order.md), [Lifinity AMM v2](https://carbon.sevenlabs.org/decoders/lifinity-amm-v2.md), [Meteora DAMM v2](https://carbon.sevenlabs.org/decoders/meteora-damm-v2.md), [Meteora DLMM](https://carbon.sevenlabs.org/decoders/meteora-dlmm.md), [Meteora Pools](https://carbon.sevenlabs.org/decoders/meteora-pools.md), [OpenBook v2](https://carbon.sevenlabs.org/decoders/openbook-v2.md), [Orca Whirlpools](https://carbon.sevenlabs.org/decoders/orca-whirlpool.md), [PancakeSwap](https://carbon.sevenlabs.org/decoders/pancake-swap.md), [Phoenix v1](https://carbon.sevenlabs.org/decoders/phoenix-v1.md), [PumpSwap](https://carbon.sevenlabs.org/decoders/pump-swap.md), [Raydium AMM v4](https://carbon.sevenlabs.org/decoders/raydium-amm-v4.md), [Raydium CLMM](https://carbon.sevenlabs.org/decoders/raydium-clmm.md), [Raydium Stable Swap](https://carbon.sevenlabs.org/decoders/raydium-stable-swap.md), [Stabble Stable Swap](https://carbon.sevenlabs.org/decoders/stabble-stable-swap.md), [Stabble Weighted Swap](https://carbon.sevenlabs.org/decoders/stabble-weighted-swap.md). To decode several in one pipeline, see [dEX and AMM decoders](https://carbon.sevenlabs.org/decoders/dex-and-amm.md).

Guide: [Index swaps across DEXs](https://carbon.sevenlabs.org/guides/index-dex-swaps.md).

The `serde` feature derives `Serialize`/`Deserialize` on every type, `postgres` adds tables and processors for [Postgres](https://carbon.sevenlabs.org/guides/postgres.md), and `graphql` adds a schema for the [GraphQL server](https://carbon.sevenlabs.org/guides/graphql.md).

## Usage

This program crawls recent Raydium CPMM transactions from the public RPC and prints every decoded `SwapBaseInput` instruction. Add the dependencies:

```sh
cargo add carbon-core@2.0.0 carbon-raydium-cpmm-decoder@2.0.0 carbon-rpc-transaction-crawler-datasource@2.0.0 carbon-log-metrics@2.0.0 env_logger tokio --features tokio/full
```

`src/main.rs`:

```rust
use {
    carbon_core::{
        error::CarbonResult, instruction::InstructionProcessorInputType, pipeline::Pipeline,
        processor::Processor,
    },
    carbon_log_metrics::LogMetrics,
    carbon_raydium_cpmm_decoder::{
        instructions::RaydiumCpmmInstruction, RaydiumCpmmDecoder, PROGRAM_ID,
    },
    carbon_rpc_transaction_crawler_datasource::{ConnectionConfig, Filters, RpcTransactionCrawler},
    std::sync::Arc,
};

#[tokio::main]
async fn main() -> CarbonResult<()> {
    env_logger::init();

    // Fetches the program's recent transactions over JSON-RPC, newest first.
    let datasource = RpcTransactionCrawler::new(
        "https://api.mainnet-beta.solana.com".to_string(),
        PROGRAM_ID,
        ConnectionConfig::default(),
        Filters::new(None, None, None),
        None,
    );

    Pipeline::builder()
        .datasource(datasource)
        .metrics(Arc::new(LogMetrics::new()))
        .instruction(RaydiumCpmmDecoder, InstructionLogger)
        .build()?
        .run()
        .await
}

struct InstructionLogger;

impl Processor<InstructionProcessorInputType<'_, RaydiumCpmmInstruction>> for InstructionLogger {
    async fn process(
        &mut self,
        input: &InstructionProcessorInputType<'_, RaydiumCpmmInstruction>,
    ) -> CarbonResult<()> {
        let signature = input.metadata.transaction_metadata.signature;
        if let RaydiumCpmmInstruction::SwapBaseInput { data, accounts, .. } = input.decoded_instruction {
            println!("swap_base_input {signature}: {data:?} payer={}", accounts.payer);
        }
        Ok(())
    }
}
```

```sh
RUST_LOG=info cargo run
```

Each `SwapBaseInput` instruction prints one line with the transaction signature and the decoded `SwapBaseInput` data. The public endpoint rate-limits requests, so the first lines can take a while; use your own RPC URL for anything beyond a test. See [stream with RPC](https://carbon.sevenlabs.org/guides/stream-with-rpc.md) for the crawler options.

Raydium CPMM publishes its events with Anchor's `emit!`, as `Program data:` log lines, so they never arrive as the `CpiEvent` instruction. Decode them from the instruction that emitted them with [`decode_log_events`](https://carbon.sevenlabs.org/concepts/instructions.md#log-events); [index swaps across DEXs](https://carbon.sevenlabs.org/guides/index-dex-swaps.md) has a complete example. The event types are listed under [Events](#events).

### Decode accounts

The transaction crawler emits transactions only. To decode accounts, use a datasource that emits account updates. This program subscribes to the program's accounts with `programSubscribe` on the public WebSocket endpoint and prints every decoded `PoolState` account as it changes. Add the datasource and the Solana RPC types it takes:

```sh
cargo add carbon-rpc-program-subscribe-datasource@2.0.0 solana-client@4.2.2
```

`src/main.rs`:

```rust
use {
    carbon_core::{
        account::AccountProcessorInputType, error::CarbonResult, pipeline::Pipeline,
        processor::Processor,
    },
    carbon_log_metrics::LogMetrics,
    carbon_raydium_cpmm_decoder::{accounts::RaydiumCpmmAccount, RaydiumCpmmDecoder, PROGRAM_ID},
    carbon_rpc_program_subscribe_datasource::{Filters, RpcProgramSubscribe},
    solana_client::rpc_config::{RpcAccountInfoConfig, RpcProgramAccountsConfig, UiAccountEncoding},
    std::sync::Arc,
};

#[tokio::main]
async fn main() -> CarbonResult<()> {
    env_logger::init();

    // Streams every change to an account owned by the program (programSubscribe).
    let config = RpcProgramAccountsConfig {
        account_config: RpcAccountInfoConfig {
            encoding: Some(UiAccountEncoding::Base64),
            ..Default::default()
        },
        ..Default::default()
    };
    let datasource = RpcProgramSubscribe::new(
        "wss://api.mainnet-beta.solana.com".to_string(),
        Filters::new(PROGRAM_ID, Some(config)),
    );

    Pipeline::builder()
        .datasource(datasource)
        .metrics(Arc::new(LogMetrics::new()))
        .account(RaydiumCpmmDecoder, AccountLogger)
        .build()?
        .run()
        .await
}

struct AccountLogger;

impl Processor<AccountProcessorInputType<'_, RaydiumCpmmAccount>> for AccountLogger {
    async fn process(
        &mut self,
        input: &AccountProcessorInputType<'_, RaydiumCpmmAccount>,
    ) -> CarbonResult<()> {
        if let RaydiumCpmmAccount::PoolState(pool_state) = &input.decoded_account.data {
            println!("pool_state {}: {pool_state:?}", input.metadata.pubkey);
        }
        Ok(())
    }
}
```

```sh
RUST_LOG=info cargo run
```

Each update to a `PoolState` account prints its address and decoded fields; the program runs until you stop it. Cargo resolves `solana-client` to 4.2.2, the exact version the datasource pins, so both use the same `RpcProgramAccountsConfig` type. To load every existing account once instead of streaming changes, see [load account state](https://carbon.sevenlabs.org/guides/load-account-state.md).

## Instructions

Variants of `RaydiumCpmmInstruction`. Each is `RaydiumCpmmInstruction::<Variant> { program_id, data, accounts }`, where `data` and `accounts` are the types listed under the variant, exported from `carbon_raydium_cpmm_decoder::instructions`. Discriminators are the leading bytes of the instruction data, in hex.

**How an instruction decodes.** The decoder returns a variant only when all of these hold; otherwise the instruction is skipped and no processor is called:

1. The instruction's program ID is `CPMMoo8L3F4NbTegBCKVNunggL7H1ZpdTHKxQB5qKP1C`.
2. The data starts with the variant's discriminator, and the rest deserializes into its data type.
3. The instruction has at least as many accounts as the variant requires (the "Required accounts" count under each variant).

**Accounts.** They are matched by position, in the order listed. An account marked _optional_ is `None` only when the instruction ends before it; Anchor programs pass the program ID as a placeholder for an omitted optional account, so check for `Some(PROGRAM_ID)` too. Accounts after the listed ones are in `accounts.remaining` as `AccountMeta`s. The decoder doesn't record whether an account signed or was writable: read that from `input.raw_instruction.accounts[i].is_signer` and `.is_writable`, which follow the same order. It doesn't check signer, writable, owner or PDA constraints either; the program enforced those when the transaction executed, so a decoded instruction from a successful transaction already satisfied them.

### `ClosePermissionPda`

> _From the program's IDL:_
>
> Close a permission account
>
> **Arguments**
>
> - `ctx`- The context of accounts

Discriminator `9c5420764587467b` · data `ClosePermissionPda` · accounts `ClosePermissionPdaInstructionAccounts`.

No data fields.

Required accounts: 4; extras go to `remaining`.

Fields of `ClosePermissionPdaInstructionAccounts`, in account order:

| #  | Field                  | Type               |
| -- | ---------------------- | ------------------ |
| 0  | `owner`                | `Pubkey`           |
| 1  | `permission_authority` | `Pubkey`           |
| 2  | `permission`           | `Pubkey`           |
| 3  | `system_program`       | `Pubkey`           |
| 4… | `remaining`            | `Vec<AccountMeta>` |

### `CollectCreatorFee`

> _From the program's IDL:_
>
> Collect the creator fee
>
> **Arguments**
>
> - `ctx` - The context of accounts

Discriminator `1416567bc61cdb84` · data `CollectCreatorFee` · accounts `CollectCreatorFeeInstructionAccounts`.

No data fields.

Required accounts: 14; extras go to `remaining`.

Fields of `CollectCreatorFeeInstructionAccounts`, in account order:

| #   | Field                      | Type               |
| --- | -------------------------- | ------------------ |
| 0   | `creator`                  | `Pubkey`           |
| 1   | `authority`                | `Pubkey`           |
| 2   | `pool_state`               | `Pubkey`           |
| 3   | `amm_config`               | `Pubkey`           |
| 4   | `token0_vault`             | `Pubkey`           |
| 5   | `token1_vault`             | `Pubkey`           |
| 6   | `vault0_mint`              | `Pubkey`           |
| 7   | `vault1_mint`              | `Pubkey`           |
| 8   | `creator_token0`           | `Pubkey`           |
| 9   | `creator_token1`           | `Pubkey`           |
| 10  | `token0_program`           | `Pubkey`           |
| 11  | `token1_program`           | `Pubkey`           |
| 12  | `associated_token_program` | `Pubkey`           |
| 13  | `system_program`           | `Pubkey`           |
| 14… | `remaining`                | `Vec<AccountMeta>` |

### `CollectFundFee`

> _From the program's IDL:_
>
> Collect the fund fee accrued to the pool
>
> **Arguments**
>
> - `ctx` - The context of accounts
> - `amount_0_requested` - The maximum amount of token_0 to send, can be 0 to
>   collect fees in only token_1
> - `amount_1_requested` - The maximum amount of token_1 to send, can be 0 to collect fees in only token_0

Discriminator `a78a4e95dfc2067e` · data `CollectFundFee` · accounts `CollectFundFeeInstructionAccounts`.

| Field               | Type  |
| ------------------- | ----- |
| `amount0_requested` | `u64` |
| `amount1_requested` | `u64` |

Required accounts: 12; extras go to `remaining`.

Fields of `CollectFundFeeInstructionAccounts`, in account order:

| #   | Field                      | Type               |
| --- | -------------------------- | ------------------ |
| 0   | `owner`                    | `Pubkey`           |
| 1   | `authority`                | `Pubkey`           |
| 2   | `pool_state`               | `Pubkey`           |
| 3   | `amm_config`               | `Pubkey`           |
| 4   | `token0_vault`             | `Pubkey`           |
| 5   | `token1_vault`             | `Pubkey`           |
| 6   | `vault0_mint`              | `Pubkey`           |
| 7   | `vault1_mint`              | `Pubkey`           |
| 8   | `recipient_token0_account` | `Pubkey`           |
| 9   | `recipient_token1_account` | `Pubkey`           |
| 10  | `token_program`            | `Pubkey`           |
| 11  | `token_program2022`        | `Pubkey`           |
| 12… | `remaining`                | `Vec<AccountMeta>` |

### `CollectProtocolFee`

> _From the program's IDL:_
>
> Collect the protocol fee accrued to the pool
>
> **Arguments**
>
> - `ctx` - The context of accounts
> - `amount_0_requested` - The maximum amount of token_0 to send, can be 0 to
>   collect fees in only token_1
> - `amount_1_requested` - The maximum amount of token_1 to send, can be 0 to collect fees in only token_0

Discriminator `8888fcddc2427e59` · data `CollectProtocolFee` · accounts `CollectProtocolFeeInstructionAccounts`.

| Field               | Type  |
| ------------------- | ----- |
| `amount0_requested` | `u64` |
| `amount1_requested` | `u64` |

Required accounts: 12; extras go to `remaining`.

Fields of `CollectProtocolFeeInstructionAccounts`, in account order:

| #   | Field                      | Type               |
| --- | -------------------------- | ------------------ |
| 0   | `owner`                    | `Pubkey`           |
| 1   | `authority`                | `Pubkey`           |
| 2   | `pool_state`               | `Pubkey`           |
| 3   | `amm_config`               | `Pubkey`           |
| 4   | `token0_vault`             | `Pubkey`           |
| 5   | `token1_vault`             | `Pubkey`           |
| 6   | `vault0_mint`              | `Pubkey`           |
| 7   | `vault1_mint`              | `Pubkey`           |
| 8   | `recipient_token0_account` | `Pubkey`           |
| 9   | `recipient_token1_account` | `Pubkey`           |
| 10  | `token_program`            | `Pubkey`           |
| 11  | `token_program2022`        | `Pubkey`           |
| 12… | `remaining`                | `Vec<AccountMeta>` |

### `CreateAmmConfig`

> _From the program's IDL:_
>
> **Arguments**
>
> - `ctx`- The accounts needed by instruction.
> - `index` - The index of amm config, there may be multiple config.
> - `trade_fee_rate` - Trade fee rate, can be changed.
> - `protocol_fee_rate` - The rate of protocol fee within trade fee.
> - `fund_fee_rate` - The rate of fund fee within trade fee.

Discriminator `8934edd4d7756c68` · data `CreateAmmConfig` · accounts `CreateAmmConfigInstructionAccounts`.

| Field               | Type  |
| ------------------- | ----- |
| `index`             | `u16` |
| `trade_fee_rate`    | `u64` |
| `protocol_fee_rate` | `u64` |
| `fund_fee_rate`     | `u64` |
| `create_pool_fee`   | `u64` |
| `creator_fee_rate`  | `u64` |

Required accounts: 3; extras go to `remaining`.

Fields of `CreateAmmConfigInstructionAccounts`, in account order:

| #  | Field            | Type               |
| -- | ---------------- | ------------------ |
| 0  | `owner`          | `Pubkey`           |
| 1  | `amm_config`     | `Pubkey`           |
| 2  | `system_program` | `Pubkey`           |
| 3… | `remaining`      | `Vec<AccountMeta>` |

### `CreatePermissionPda`

> _From the program's IDL:_
>
> Create a permission account
>
> **Arguments**
>
> - `ctx`- The context of accounts

Discriminator `878802d889a9b5ca` · data `CreatePermissionPda` · accounts `CreatePermissionPdaInstructionAccounts`.

No data fields.

Required accounts: 4; extras go to `remaining`.

Fields of `CreatePermissionPdaInstructionAccounts`, in account order:

| #  | Field                  | Type               |
| -- | ---------------------- | ------------------ |
| 0  | `owner`                | `Pubkey`           |
| 1  | `permission_authority` | `Pubkey`           |
| 2  | `permission`           | `Pubkey`           |
| 3  | `system_program`       | `Pubkey`           |
| 4… | `remaining`            | `Vec<AccountMeta>` |

### `Deposit`

> _From the program's IDL:_
>
> Deposit lp token to the pool
>
> **Arguments**
>
> - `ctx`- The context of accounts
> - `lp_token_amount` - Increased number of LPs
> - `maximum_token_0_amount` -  Maximum token 0 amount to deposit, prevents
>   excessive slippage
> - `maximum_token_1_amount` - Maximum token 1 amount to deposit, prevents excessive slippage

Discriminator `f223c68952e1f2b6` · data `Deposit` · accounts `DepositInstructionAccounts`.

| Field                   | Type  |
| ----------------------- | ----- |
| `lp_token_amount`       | `u64` |
| `maximum_token0_amount` | `u64` |
| `maximum_token1_amount` | `u64` |

Required accounts: 13; extras go to `remaining`.

Fields of `DepositInstructionAccounts`, in account order:

| #   | Field               | Type               |
| --- | ------------------- | ------------------ |
| 0   | `owner`             | `Pubkey`           |
| 1   | `authority`         | `Pubkey`           |
| 2   | `pool_state`        | `Pubkey`           |
| 3   | `owner_lp_token`    | `Pubkey`           |
| 4   | `token0_account`    | `Pubkey`           |
| 5   | `token1_account`    | `Pubkey`           |
| 6   | `token0_vault`      | `Pubkey`           |
| 7   | `token1_vault`      | `Pubkey`           |
| 8   | `token_program`     | `Pubkey`           |
| 9   | `token_program2022` | `Pubkey`           |
| 10  | `vault0_mint`       | `Pubkey`           |
| 11  | `vault1_mint`       | `Pubkey`           |
| 12  | `lp_mint`           | `Pubkey`           |
| 13… | `remaining`         | `Vec<AccountMeta>` |

### `Initialize`

> _From the program's IDL:_
>
> Creates a pool for the given token pair and the initial price
>
> **Arguments**
>
> - `ctx`- The context of accounts
> - `init_amount_0` - the initial amount_0 to deposit
> - `init_amount_1` - the initial amount_1 to deposit
> - `open_time` - the timestamp allowed for swap

Discriminator `afaf6d1f0d989bed` · data `Initialize` · accounts `InitializeInstructionAccounts`.

| Field          | Type  |
| -------------- | ----- |
| `init_amount0` | `u64` |
| `init_amount1` | `u64` |
| `open_time`    | `u64` |

Required accounts: 20; extras go to `remaining`.

Fields of `InitializeInstructionAccounts`, in account order:

| #   | Field                      | Type               |
| --- | -------------------------- | ------------------ |
| 0   | `creator`                  | `Pubkey`           |
| 1   | `amm_config`               | `Pubkey`           |
| 2   | `authority`                | `Pubkey`           |
| 3   | `pool_state`               | `Pubkey`           |
| 4   | `token0_mint`              | `Pubkey`           |
| 5   | `token1_mint`              | `Pubkey`           |
| 6   | `lp_mint`                  | `Pubkey`           |
| 7   | `creator_token0`           | `Pubkey`           |
| 8   | `creator_token1`           | `Pubkey`           |
| 9   | `creator_lp_token`         | `Pubkey`           |
| 10  | `token0_vault`             | `Pubkey`           |
| 11  | `token1_vault`             | `Pubkey`           |
| 12  | `create_pool_fee`          | `Pubkey`           |
| 13  | `observation_state`        | `Pubkey`           |
| 14  | `token_program`            | `Pubkey`           |
| 15  | `token0_program`           | `Pubkey`           |
| 16  | `token1_program`           | `Pubkey`           |
| 17  | `associated_token_program` | `Pubkey`           |
| 18  | `system_program`           | `Pubkey`           |
| 19  | `rent`                     | `Pubkey`           |
| 20… | `remaining`                | `Vec<AccountMeta>` |

### `InitializeWithPermission`

> _From the program's IDL:_
>
> Create a pool with permission
>
> **Arguments**
>
> - `ctx`- The context of accounts
> - `init_amount_0` - the initial amount_0 to deposit
> - `init_amount_1` - the initial amount_1 to deposit
> - `open_time` - the timestamp allowed for swap
> - `creator_fee_on` - creator fee model, 0：both token0 and token1 (depends
>   on the input), 1: only token0, 2: only token1

Discriminator `3f37fe4131b25979` · data `InitializeWithPermission` · accounts `InitializeWithPermissionInstructionAccounts`.

| Field            | Type                            |
| ---------------- | ------------------------------- |
| `init_amount0`   | `u64`                           |
| `init_amount1`   | `u64`                           |
| `open_time`      | `u64`                           |
| `creator_fee_on` | [`CreatorFeeOn`](#creatorfeeon) |

Required accounts: 21; extras go to `remaining`.

Fields of `InitializeWithPermissionInstructionAccounts`, in account order:

| #   | Field                      | Type               |
| --- | -------------------------- | ------------------ |
| 0   | `payer`                    | `Pubkey`           |
| 1   | `creator`                  | `Pubkey`           |
| 2   | `amm_config`               | `Pubkey`           |
| 3   | `authority`                | `Pubkey`           |
| 4   | `pool_state`               | `Pubkey`           |
| 5   | `token0_mint`              | `Pubkey`           |
| 6   | `token1_mint`              | `Pubkey`           |
| 7   | `lp_mint`                  | `Pubkey`           |
| 8   | `payer_token0`             | `Pubkey`           |
| 9   | `payer_token1`             | `Pubkey`           |
| 10  | `payer_lp_token`           | `Pubkey`           |
| 11  | `token0_vault`             | `Pubkey`           |
| 12  | `token1_vault`             | `Pubkey`           |
| 13  | `create_pool_fee`          | `Pubkey`           |
| 14  | `observation_state`        | `Pubkey`           |
| 15  | `permission`               | `Pubkey`           |
| 16  | `token_program`            | `Pubkey`           |
| 17  | `token0_program`           | `Pubkey`           |
| 18  | `token1_program`           | `Pubkey`           |
| 19  | `associated_token_program` | `Pubkey`           |
| 20  | `system_program`           | `Pubkey`           |
| 21… | `remaining`                | `Vec<AccountMeta>` |

### `SwapBaseInput`

> _From the program's IDL:_
>
> Swap the tokens in the pool base input amount
>
> **Arguments**
>
> - `ctx`- The context of accounts
> - `amount_in` -  input amount to transfer, output to DESTINATION is based on
>   the exchange rate
> - `minimum_amount_out` -  Minimum amount of output token, prevents excessive slippage

Discriminator `8fbe5adac41e33de` · data `SwapBaseInput` · accounts `SwapBaseInputInstructionAccounts`.

| Field                | Type  |
| -------------------- | ----- |
| `amount_in`          | `u64` |
| `minimum_amount_out` | `u64` |

Required accounts: 13; extras go to `remaining`.

Fields of `SwapBaseInputInstructionAccounts`, in account order:

| #   | Field                  | Type               |
| --- | ---------------------- | ------------------ |
| 0   | `payer`                | `Pubkey`           |
| 1   | `authority`            | `Pubkey`           |
| 2   | `amm_config`           | `Pubkey`           |
| 3   | `pool_state`           | `Pubkey`           |
| 4   | `input_token_account`  | `Pubkey`           |
| 5   | `output_token_account` | `Pubkey`           |
| 6   | `input_vault`          | `Pubkey`           |
| 7   | `output_vault`         | `Pubkey`           |
| 8   | `input_token_program`  | `Pubkey`           |
| 9   | `output_token_program` | `Pubkey`           |
| 10  | `input_token_mint`     | `Pubkey`           |
| 11  | `output_token_mint`    | `Pubkey`           |
| 12  | `observation_state`    | `Pubkey`           |
| 13… | `remaining`            | `Vec<AccountMeta>` |

### `SwapBaseOutput`

> _From the program's IDL:_
>
> Swap the tokens in the pool base output amount
>
> **Arguments**
>
> - `ctx`- The context of accounts
> - `max_amount_in` -  input amount prevents excessive slippage
> - `amount_out` -  amount of output token

Discriminator `37d96256a34ab4ad` · data `SwapBaseOutput` · accounts `SwapBaseOutputInstructionAccounts`.

| Field           | Type  |
| --------------- | ----- |
| `max_amount_in` | `u64` |
| `amount_out`    | `u64` |

Required accounts: 13; extras go to `remaining`.

Fields of `SwapBaseOutputInstructionAccounts`, in account order:

| #   | Field                  | Type               |
| --- | ---------------------- | ------------------ |
| 0   | `payer`                | `Pubkey`           |
| 1   | `authority`            | `Pubkey`           |
| 2   | `amm_config`           | `Pubkey`           |
| 3   | `pool_state`           | `Pubkey`           |
| 4   | `input_token_account`  | `Pubkey`           |
| 5   | `output_token_account` | `Pubkey`           |
| 6   | `input_vault`          | `Pubkey`           |
| 7   | `output_vault`         | `Pubkey`           |
| 8   | `input_token_program`  | `Pubkey`           |
| 9   | `output_token_program` | `Pubkey`           |
| 10  | `input_token_mint`     | `Pubkey`           |
| 11  | `output_token_mint`    | `Pubkey`           |
| 12  | `observation_state`    | `Pubkey`           |
| 13… | `remaining`            | `Vec<AccountMeta>` |

### `UpdateAmmConfig`

> _From the program's IDL:_
>
> Updates the owner of the amm config\
> Must be called by the current owner or admin
>
> **Arguments**
>
> - `ctx`- The context of accounts
> - `trade_fee_rate`- The new trade fee rate of amm config, be set when
>   `param` is 0
> - `protocol_fee_rate`- The new protocol fee rate of amm config, be set when `param` is 1
> - `fund_fee_rate`- The new fund fee rate of amm config, be set when `param` is 2
> - `new_owner`- The config's new owner, be set when `param` is 3
> - `new_fund_owner`- The config's new fund owner, be set when `param` is 4
> - `param`- The value can be 0 | 1 | 2 | 3 | 4, otherwise will report a error

Discriminator `313cae889a1c74c8` · data `UpdateAmmConfig` · accounts `UpdateAmmConfigInstructionAccounts`.

| Field   | Type  |
| ------- | ----- |
| `param` | `u8`  |
| `value` | `u64` |

Required accounts: 2; extras go to `remaining`.

Fields of `UpdateAmmConfigInstructionAccounts`, in account order:

| #  | Field        | Type               |
| -- | ------------ | ------------------ |
| 0  | `owner`      | `Pubkey`           |
| 1  | `amm_config` | `Pubkey`           |
| 2… | `remaining`  | `Vec<AccountMeta>` |

### `UpdatePoolStatus`

> _From the program's IDL:_
>
> Update pool status for given value
>
> **Arguments**
>
> - `ctx`- The context of accounts
> - `status` - The value of status

Discriminator `82576c062ee0757b` · data `UpdatePoolStatus` · accounts `UpdatePoolStatusInstructionAccounts`.

| Field    | Type |
| -------- | ---- |
| `status` | `u8` |

Required accounts: 2; extras go to `remaining`.

Fields of `UpdatePoolStatusInstructionAccounts`, in account order:

| #  | Field        | Type               |
| -- | ------------ | ------------------ |
| 0  | `authority`  | `Pubkey`           |
| 1  | `pool_state` | `Pubkey`           |
| 2… | `remaining`  | `Vec<AccountMeta>` |

### `Withdraw`

> _From the program's IDL:_
>
> Withdraw lp for token0 and token1
>
> **Arguments**
>
> - `ctx`- The context of accounts
> - `lp_token_amount` - Amount of pool tokens to burn. User receives an output
>   of token a and b based on the percentage of the pool tokens that are returned.
> - `minimum_token_0_amount` -  Minimum amount of token 0 to receive, prevents excessive slippage
> - `minimum_token_1_amount` -  Minimum amount of token 1 to receive, prevents excessive slippage

Discriminator `b712469c946da122` · data `Withdraw` · accounts `WithdrawInstructionAccounts`.

| Field                   | Type  |
| ----------------------- | ----- |
| `lp_token_amount`       | `u64` |
| `minimum_token0_amount` | `u64` |
| `minimum_token1_amount` | `u64` |

Required accounts: 14; extras go to `remaining`.

Fields of `WithdrawInstructionAccounts`, in account order:

| #   | Field               | Type               |
| --- | ------------------- | ------------------ |
| 0   | `owner`             | `Pubkey`           |
| 1   | `authority`         | `Pubkey`           |
| 2   | `pool_state`        | `Pubkey`           |
| 3   | `owner_lp_token`    | `Pubkey`           |
| 4   | `token0_account`    | `Pubkey`           |
| 5   | `token1_account`    | `Pubkey`           |
| 6   | `token0_vault`      | `Pubkey`           |
| 7   | `token1_vault`      | `Pubkey`           |
| 8   | `token_program`     | `Pubkey`           |
| 9   | `token_program2022` | `Pubkey`           |
| 10  | `vault0_mint`       | `Pubkey`           |
| 11  | `vault1_mint`       | `Pubkey`           |
| 12  | `lp_mint`           | `Pubkey`           |
| 13  | `memo_program`      | `Pubkey`           |
| 14… | `remaining`         | `Vec<AccountMeta>` |

### `CpiEvent`

Anchor self-CPI that carries one of the program's [events](#events). `data` is the `CpiEvent` enum.

Discriminator `e445a52e51cb9a1d` · data `CpiEvent` · accounts `CpiEventInstructionAccounts`.

Required accounts: 2; extras go to `remaining`.

Fields of `CpiEventInstructionAccounts`, in account order:

| #  | Field             | Type               |
| -- | ----------------- | ------------------ |
| 0  | `program`         | `Pubkey`           |
| 1  | `event_authority` | `Pubkey`           |
| 2… | `remaining`       | `Vec<AccountMeta>` |

## Accounts

Variants of `RaydiumCpmmAccount`. Each wraps a boxed struct from `carbon_raydium_cpmm_decoder::accounts::<module>`. `decode_account` only considers accounts owned by `PROGRAM_ID` and returns the first variant that matches.

### `AmmConfig`

Discriminator `daf42168cbcb2b6f` · `accounts::amm_config::AmmConfig`.

| Field                 | Type        | Description                                                      |
| --------------------- | ----------- | ---------------------------------------------------------------- |
| `bump`                | `u8`        | Bump to identify PDA                                             |
| `disable_create_pool` | `bool`      | Status to control if new pool can be create                      |
| `index`               | `u16`       | Config index                                                     |
| `trade_fee_rate`      | `u64`       | The trade fee, denominated in hundredths of a bip (10^-6)        |
| `protocol_fee_rate`   | `u64`       | The protocol fee                                                 |
| `fund_fee_rate`       | `u64`       | The fund fee, denominated in hundredths of a bip (10^-6)         |
| `create_pool_fee`     | `u64`       | Fee for create a new pool                                        |
| `protocol_owner`      | `Pubkey`    | Address of the protocol fee owner                                |
| `fund_owner`          | `Pubkey`    | Address of the fund fee owner                                    |
| `creator_fee_rate`    | `u64`       | The pool creator fee, denominated in hundredths of a bip (10^-6) |
| `padding`             | `[u64; 15]` | padding                                                          |

### `ObservationState`

Discriminator `7aaec5358109a584` · `accounts::observation_state::ObservationState`.

| Field                   | Type                                 | Description                                               |
| ----------------------- | ------------------------------------ | --------------------------------------------------------- |
| `initialized`           | `bool`                               | Whether the ObservationState is initialized               |
| `observation_index`     | `u16`                                | the most-recently updated index of the observations array |
| `pool_id`               | `Pubkey`                             |                                                           |
| `observations`          | [`[Observation; 100]`](#observation) | observation array                                         |
| `last_update_timestamp` | `u64`                                | the last update timestamp                                 |
| `padding`               | `[u64; 3]`                           | padding for feature update                                |

### `Permission`

Discriminator `e0531c4f0afda11c` · `accounts::permission::Permission`.

| Field       | Type        | Description |
| ----------- | ----------- | ----------- |
| `authority` | `Pubkey`    | authority   |
| `padding`   | `[u64; 30]` | padding     |

### `PoolState`

Discriminator `f7ede3f5d7c3de46` · `accounts::pool_state::PoolState`.

| Field                  | Type        | Description                                                                                                                                                                                   |
| ---------------------- | ----------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `amm_config`           | `Pubkey`    | Which config the pool belongs                                                                                                                                                                 |
| `pool_creator`         | `Pubkey`    | pool creator                                                                                                                                                                                  |
| `token0_vault`         | `Pubkey`    | Token A                                                                                                                                                                                       |
| `token1_vault`         | `Pubkey`    | Token B                                                                                                                                                                                       |
| `lp_mint`              | `Pubkey`    | Pool tokens are issued when A or B tokens are deposited. Pool tokens can be withdrawn back to the original A or B token.                                                                      |
| `token0_mint`          | `Pubkey`    | Mint information for token A                                                                                                                                                                  |
| `token1_mint`          | `Pubkey`    | Mint information for token B                                                                                                                                                                  |
| `token0_program`       | `Pubkey`    | token_0 program                                                                                                                                                                               |
| `token1_program`       | `Pubkey`    | token_1 program                                                                                                                                                                               |
| `observation_key`      | `Pubkey`    | observation account to store oracle data                                                                                                                                                      |
| `auth_bump`            | `u8`        |                                                                                                                                                                                               |
| `status`               | `u8`        | Bitwise representation of the state of the pool bit0, 1: disable deposit(value is 1), 0: normal bit1, 1: disable withdraw(value is 2), 0: normal bit2, 1: disable swap(value is 4), 0: normal |
| `lp_mint_decimals`     | `u8`        |                                                                                                                                                                                               |
| `mint0_decimals`       | `u8`        | mint0 and mint1 decimals                                                                                                                                                                      |
| `mint1_decimals`       | `u8`        |                                                                                                                                                                                               |
| `lp_supply`            | `u64`       | True circulating supply without burns and lock ups                                                                                                                                            |
| `protocol_fees_token0` | `u64`       | The amounts of token_0 and token_1 that are owed to the liquidity provider.                                                                                                                   |
| `protocol_fees_token1` | `u64`       |                                                                                                                                                                                               |
| `fund_fees_token0`     | `u64`       |                                                                                                                                                                                               |
| `fund_fees_token1`     | `u64`       |                                                                                                                                                                                               |
| `open_time`            | `u64`       | The timestamp allowed for swap in the pool.                                                                                                                                                   |
| `recent_epoch`         | `u64`       | recent epoch                                                                                                                                                                                  |
| `creator_fee_on`       | `u8`        | Creator fee collect mode 0: both token_0 and token_1 can be used as trade fees. It depends on what the input token is when swapping 1: only token_0 as trade fee 2: only token_1 as trade fee |
| `enable_creator_fee`   | `bool`      |                                                                                                                                                                                               |
| `padding1`             | `[u8; 6]`   |                                                                                                                                                                                               |
| `creator_fees_token0`  | `u64`       |                                                                                                                                                                                               |
| `creator_fees_token1`  | `u64`       |                                                                                                                                                                                               |
| `padding`              | `[u64; 28]` | padding for future updates                                                                                                                                                                    |

## Events

Structs in `carbon_raydium_cpmm_decoder::events::<module>`, also listed as variants of `instructions::CpiEvent`. Raydium CPMM logs these events with `emit!` rather than emitting them through a self-CPI, so read them with [`decode_log_events`](https://carbon.sevenlabs.org/concepts/instructions.md#log-events) on the instruction that logged them. The discriminator is the event's 8-byte discriminator at the start of the logged data.

### `LpChangeEvent`

Discriminator `79a3cdc939da753c` · `events::lp_change_event::LpChangeEventEvent`.

| Field                 | Type     | Description                           |
| --------------------- | -------- | ------------------------------------- |
| `pool_id`             | `Pubkey` |                                       |
| `lp_amount_before`    | `u64`    |                                       |
| `token0_vault_before` | `u64`    | pool vault sub trade fees             |
| `token1_vault_before` | `u64`    | pool vault sub trade fees             |
| `token0_amount`       | `u64`    | calculate result without transfer fee |
| `token1_amount`       | `u64`    | calculate result without transfer fee |
| `token0_transfer_fee` | `u64`    |                                       |
| `token1_transfer_fee` | `u64`    |                                       |
| `change_type`         | `u8`     |                                       |

### `SwapEvent`

Discriminator `40c6cde8260871e2` · `events::swap_event::SwapEventEvent`.

| Field                  | Type     | Description                           |
| ---------------------- | -------- | ------------------------------------- |
| `pool_id`              | `Pubkey` |                                       |
| `input_vault_before`   | `u64`    | pool vault sub trade fees             |
| `output_vault_before`  | `u64`    | pool vault sub trade fees             |
| `input_amount`         | `u64`    | calculate result without transfer fee |
| `output_amount`        | `u64`    | calculate result without transfer fee |
| `input_transfer_fee`   | `u64`    |                                       |
| `output_transfer_fee`  | `u64`    |                                       |
| `base_input`           | `bool`   |                                       |
| `input_mint`           | `Pubkey` |                                       |
| `output_mint`          | `Pubkey` |                                       |
| `trade_fee`            | `u64`    |                                       |
| `creator_fee`          | `u64`    | Amount of fee tokens going to creator |
| `creator_fee_on_input` | `bool`   |                                       |

## Types

Types used by the instructions, accounts and events above, exported from `carbon_raydium_cpmm_decoder::types`.

### `CreatorFeeOn`

Enum `types::CreatorFeeOn`.

| Variant      |
| ------------ |
| `BothToken`  |
| `OnlyToken0` |
| `OnlyToken1` |

### `LpChangeEvent`

> _From the program's IDL:_
>
> Emitted when deposit and withdraw

Struct `types::LpChangeEvent`. Same fields as the [`LpChangeEvent`](#lpchangeevent) event.

### `Observation`

> _From the program's IDL:_
>
> The element of observations in ObservationState

Struct `types::Observation`.

| Field                         | Type   | Description                                                                                        |
| ----------------------------- | ------ | -------------------------------------------------------------------------------------------------- |
| `block_timestamp`             | `u64`  | The block timestamp of the observation                                                             |
| `cumulative_token0_price_x32` | `u128` | the cumulative of token0 price during the duration time, Q32.32, the remaining 64 bit for overflow |
| `cumulative_token1_price_x32` | `u128` | the cumulative of token1 price during the duration time, Q32.32, the remaining 64 bit for overflow |

### `SwapEvent`

> _From the program's IDL:_
>
> Emitted when swap

Struct `types::SwapEvent`. Same fields as the [`SwapEvent`](#swapevent) event.

---

Carbon 2.0.0 documentation · Web: https://carbon.sevenlabs.org/decoders/raydium-cpmm · Last updated 2026-11-09 · Index of all pages: https://carbon.sevenlabs.org/llms.txt
