# OKX DEX decoder (Carbon 2.0)

> Decode OKX DEX instructions, accounts and events in Rust with carbon-okx-dex-decoder 2.0.0. Program ID 6m2CDdhRgxpH4WjvdzxAYbGxwdGUz5MziiL5jek2kBma.

`carbon-okx-dex-decoder` decodes the instructions, accounts and events of the OKX DEX program (`6m2CDdhRgxpH4WjvdzxAYbGxwdGUz5MziiL5jek2kBma`): 14 instructions, 2 events. It decodes no accounts: `OkxDexAccount` has no variants. 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-okx-dex-decoder`](https://crates.io/crates/carbon-okx-dex-decoder/2.0.0) 2.0.0                 |
| Install          | `cargo add carbon-okx-dex-decoder@2.0.0`                                                                |
| Program ID       | `6m2CDdhRgxpH4WjvdzxAYbGxwdGUz5MziiL5jek2kBma` (`carbon_okx_dex_decoder::PROGRAM_ID`)                   |
| Category         | [Aggregators & routing](https://carbon.sevenlabs.org/decoders/aggregators.md)                           |
| Decoder          | `carbon_okx_dex_decoder::OkxDexDecoder`                                                                 |
| Instruction enum | `instructions::OkxDexInstruction`                                                                       |
| Account enum     | `accounts::OkxDexAccount` (no variants)                                                                 |
| Event enum       | `instructions::CpiEvent`                                                                                |
| Features         | `serde`, `postgres`, `graphql` (none enabled by default)                                                |
| API docs         | [docs.rs/carbon-okx-dex-decoder/2.0.0](https://docs.rs/carbon-okx-dex-decoder/2.0.0)                    |
| Source           | [decoders/okx-dex-decoder](https://github.com/sevenlabs-hq/carbon/tree/v2.0.0/decoders/okx-dex-decoder) |

Other aggregator and routing decoders: [DFlow Aggregator v4](https://carbon.sevenlabs.org/decoders/dflow-aggregator-v4.md), [Jupiter Swap](https://carbon.sevenlabs.org/decoders/jupiter-swap.md), [OnChain Labs DEX v2](https://carbon.sevenlabs.org/decoders/onchain-labs-dex-v2.md). To decode several in one pipeline, see [aggregator and routing decoders](https://carbon.sevenlabs.org/decoders/aggregators.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 OKX DEX transactions from the public RPC and prints every decoded `Swap` instruction. Add the dependencies:

```sh
cargo add carbon-core@2.0.0 carbon-okx-dex-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_okx_dex_decoder::{instructions::OkxDexInstruction, OkxDexDecoder, 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(OkxDexDecoder, InstructionLogger)
        .build()?
        .run()
        .await
}

struct InstructionLogger;

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

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

Each `Swap` instruction prints one line with the transaction signature and the decoded `Swap` 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.

Events published with Anchor's `emit_cpi!` arrive as the `CpiEvent` instruction. Match them with `OkxDexInstruction::CpiEvent { data: CpiEvent::SwapEvent(event), .. }` (import `instructions::CpiEvent`); see [Events](#events). If `CpiEvent` never arrives, the program logs its events with `emit!` instead: decode them with [`decode_log_events`](https://carbon.sevenlabs.org/concepts/instructions.md#log-events).

## Instructions

Variants of `OkxDexInstruction`. Each is `OkxDexInstruction::<Variant> { program_id, data, accounts }`, where `data` and `accounts` are the types listed under the variant, exported from `carbon_okx_dex_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 `6m2CDdhRgxpH4WjvdzxAYbGxwdGUz5MziiL5jek2kBma`.
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.

### `Claim`

Discriminator `3ec6d6c1d59f6cd2` · data `Claim` · accounts `ClaimInstructionAccounts`.

No data fields.

Required accounts: 8 (9 listed); extras go to `remaining`.

Fields of `ClaimInstructionAccounts`, in account order:

| #  | Field                       | Type               |
| -- | --------------------------- | ------------------ |
| 0  | `signer`                    | `Pubkey`           |
| 1  | `receiver`                  | `Pubkey`           |
| 2  | `source_token_account`      | `Option<Pubkey>`   |
| 3  | `destination_token_account` | `Option<Pubkey>`   |
| 4  | `sa_authority`              | `Pubkey`           |
| 5  | `token_mint`                | `Option<Pubkey>`   |
| 6  | `token_program`             | `Option<Pubkey>`   |
| 7  | `system_program`            | `Pubkey`           |
| 8  | `associated_token_program`  | `Option<Pubkey>`   |
| 9… | `remaining`                 | `Vec<AccountMeta>` |

### `ClaimCashbackPumpfun`

Discriminator `5301f57dc9cfd1f9` · data `ClaimCashbackPumpfun` · accounts `ClaimCashbackPumpfunInstructionAccounts`.

No data fields.

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

Fields of `ClaimCashbackPumpfunInstructionAccounts`, in account order:

| #  | Field                     | Type               |
| -- | ------------------------- | ------------------ |
| 0  | `signer`                  | `Pubkey`           |
| 1  | `sa_authority`            | `Pubkey`           |
| 2  | `user_volume_accumulator` | `Pubkey`           |
| 3  | `receiver`                | `Pubkey`           |
| 4  | `event_authority`         | `Pubkey`           |
| 5  | `system_program`          | `Pubkey`           |
| 6  | `pumpfun_program`         | `Pubkey`           |
| 7… | `remaining`               | `Vec<AccountMeta>` |

### `ClaimCashbackPumpswap`

Discriminator `fdf2b0add94e6419` · data `ClaimCashbackPumpswap` · accounts `ClaimCashbackPumpswapInstructionAccounts`.

No data fields.

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

Fields of `ClaimCashbackPumpswapInstructionAccounts`, in account order:

| #   | Field                     | Type               |
| --- | ------------------------- | ------------------ |
| 0   | `signer`                  | `Pubkey`           |
| 1   | `sa_authority`            | `Pubkey`           |
| 2   | `user_volume_accumulator` | `Pubkey`           |
| 3   | `wsol_mint`               | `Pubkey`           |
| 4   | `spl_token_program`       | `Pubkey`           |
| 5   | `uva_wsol_ata`            | `Pubkey`           |
| 6   | `sa_wsol_ata`             | `Pubkey`           |
| 7   | `receiver_wsol_ata`       | `Pubkey`           |
| 8   | `system_program`          | `Pubkey`           |
| 9   | `event_authority`         | `Pubkey`           |
| 10  | `pumpswap_program`        | `Pubkey`           |
| 11… | `remaining`               | `Vec<AccountMeta>` |

### `CreateTokenAccount`

Discriminator `93f17b64f484ae76` · data `CreateTokenAccount` · accounts `CreateTokenAccountInstructionAccounts`.

| Field  | Type |
| ------ | ---- |
| `bump` | `u8` |

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

Fields of `CreateTokenAccountInstructionAccounts`, in account order:

| #  | Field            | Type               |
| -- | ---------------- | ------------------ |
| 0  | `payer`          | `Pubkey`           |
| 1  | `owner`          | `Pubkey`           |
| 2  | `token_account`  | `Pubkey`           |
| 3  | `token_mint`     | `Pubkey`           |
| 4  | `token_program`  | `Pubkey`           |
| 5  | `system_program` | `Pubkey`           |
| 6… | `remaining`      | `Vec<AccountMeta>` |

### `CreateTokenAccountWithSeed`

Discriminator `7dbfef8c420809e4` · data `CreateTokenAccountWithSeed` · accounts `CreateTokenAccountWithSeedInstructionAccounts`.

| Field  | Type  |
| ------ | ----- |
| `bump` | `u8`  |
| `seed` | `u32` |

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

Fields of `CreateTokenAccountWithSeedInstructionAccounts`, in account order:

| #  | Field            | Type               |
| -- | ---------------- | ------------------ |
| 0  | `payer`          | `Pubkey`           |
| 1  | `owner`          | `Pubkey`           |
| 2  | `token_account`  | `Pubkey`           |
| 3  | `token_mint`     | `Pubkey`           |
| 4  | `token_program`  | `Pubkey`           |
| 5  | `system_program` | `Pubkey`           |
| 6… | `remaining`      | `Vec<AccountMeta>` |

### `ProxySwap`

Discriminator `132c829448382cee` · data `ProxySwap` · accounts `ProxySwapInstructionAccounts`.

| Field      | Type                    |
| ---------- | ----------------------- |
| `data`     | [`SwapArgs`](#swapargs) |
| `order_id` | `u64`                   |

Required accounts: 5 (12 listed); extras go to `remaining`.

Fields of `ProxySwapInstructionAccounts`, in account order:

| #   | Field                       | Type               |
| --- | --------------------------- | ------------------ |
| 0   | `payer`                     | `Pubkey`           |
| 1   | `source_token_account`      | `Pubkey`           |
| 2   | `destination_token_account` | `Pubkey`           |
| 3   | `source_mint`               | `Pubkey`           |
| 4   | `destination_mint`          | `Pubkey`           |
| 5   | `sa_authority`              | `Option<Pubkey>`   |
| 6   | `source_token_sa`           | `Option<Pubkey>`   |
| 7   | `destination_token_sa`      | `Option<Pubkey>`   |
| 8   | `source_token_program`      | `Option<Pubkey>`   |
| 9   | `destination_token_program` | `Option<Pubkey>`   |
| 10  | `associated_token_program`  | `Option<Pubkey>`   |
| 11  | `system_program`            | `Option<Pubkey>`   |
| 12… | `remaining`                 | `Vec<AccountMeta>` |

### `Swap`

Discriminator `f8c69e91e17587c8` · data `Swap` · accounts `SwapInstructionAccounts`.

| Field      | Type                    |
| ---------- | ----------------------- |
| `data`     | [`SwapArgs`](#swapargs) |
| `order_id` | `u64`                   |

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

Fields of `SwapInstructionAccounts`, in account order:

| #  | Field                       | Type               |
| -- | --------------------------- | ------------------ |
| 0  | `payer`                     | `Pubkey`           |
| 1  | `source_token_account`      | `Pubkey`           |
| 2  | `destination_token_account` | `Pubkey`           |
| 3  | `source_mint`               | `Pubkey`           |
| 4  | `destination_mint`          | `Pubkey`           |
| 5… | `remaining`                 | `Vec<AccountMeta>` |

### `SwapTobV3`

Discriminator `0ebf2cf68ee1e09d` · data `SwapTobV3` · accounts `SwapTobV3InstructionAccounts`.

| Field               | Type                    |
| ------------------- | ----------------------- |
| `args`              | [`SwapArgs`](#swapargs) |
| `commission_info`   | `u32`                   |
| `trim_rate`         | `u8`                    |
| `platform_fee_rate` | `u16`                   |
| `order_id`          | `u64`                   |

Required accounts: 5 (14 listed); extras go to `remaining`.

Fields of `SwapTobV3InstructionAccounts`, in account order:

| #   | Field                       | Type               |
| --- | --------------------------- | ------------------ |
| 0   | `payer`                     | `Pubkey`           |
| 1   | `source_token_account`      | `Pubkey`           |
| 2   | `destination_token_account` | `Pubkey`           |
| 3   | `source_mint`               | `Pubkey`           |
| 4   | `destination_mint`          | `Pubkey`           |
| 5   | `commission_account`        | `Option<Pubkey>`   |
| 6   | `platform_fee_account`      | `Option<Pubkey>`   |
| 7   | `sa_authority`              | `Option<Pubkey>`   |
| 8   | `source_token_sa`           | `Option<Pubkey>`   |
| 9   | `destination_token_sa`      | `Option<Pubkey>`   |
| 10  | `source_token_program`      | `Option<Pubkey>`   |
| 11  | `destination_token_program` | `Option<Pubkey>`   |
| 12  | `associated_token_program`  | `Option<Pubkey>`   |
| 13  | `system_program`            | `Option<Pubkey>`   |
| 14… | `remaining`                 | `Vec<AccountMeta>` |

### `SwapTobV3Enhanced`

Discriminator `ec479b44c6620e76` · data `SwapTobV3Enhanced` · accounts `SwapTobV3EnhancedInstructionAccounts`.

| Field               | Type                    |
| ------------------- | ----------------------- |
| `args`              | [`SwapArgs`](#swapargs) |
| `commission_info`   | `u32`                   |
| `trim_rate`         | `u8`                    |
| `charge_rate`       | `u16`                   |
| `platform_fee_rate` | `u16`                   |
| `order_id`          | `u64`                   |

Required accounts: 5 (14 listed); extras go to `remaining`.

Fields of `SwapTobV3EnhancedInstructionAccounts`, in account order:

| #   | Field                       | Type               |
| --- | --------------------------- | ------------------ |
| 0   | `payer`                     | `Pubkey`           |
| 1   | `source_token_account`      | `Pubkey`           |
| 2   | `destination_token_account` | `Pubkey`           |
| 3   | `source_mint`               | `Pubkey`           |
| 4   | `destination_mint`          | `Pubkey`           |
| 5   | `commission_account`        | `Option<Pubkey>`   |
| 6   | `platform_fee_account`      | `Option<Pubkey>`   |
| 7   | `sa_authority`              | `Option<Pubkey>`   |
| 8   | `source_token_sa`           | `Option<Pubkey>`   |
| 9   | `destination_token_sa`      | `Option<Pubkey>`   |
| 10  | `source_token_program`      | `Option<Pubkey>`   |
| 11  | `destination_token_program` | `Option<Pubkey>`   |
| 12  | `associated_token_program`  | `Option<Pubkey>`   |
| 13  | `system_program`            | `Option<Pubkey>`   |
| 14… | `remaining`                 | `Vec<AccountMeta>` |

### `SwapTobV3WithReceiver`

> _From the program's IDL:_
>
> Swap ToB with optional specified receiver
>
> - For normal token swaps: sol_receiver should be None
> - For swap to SOL with custom receiver: sol_receiver should be Some and acc_close_flag must be true

Discriminator `3f72f6833302f71d` · data `SwapTobV3WithReceiver` · accounts `SwapTobV3WithReceiverInstructionAccounts`.

| Field               | Type                    |
| ------------------- | ----------------------- |
| `args`              | [`SwapArgs`](#swapargs) |
| `commission_info`   | `u32`                   |
| `trim_rate`         | `u8`                    |
| `platform_fee_rate` | `u16`                   |
| `order_id`          | `u64`                   |

Required accounts: 5 (15 listed); extras go to `remaining`.

Fields of `SwapTobV3WithReceiverInstructionAccounts`, in account order:

| #   | Field                       | Type               |
| --- | --------------------------- | ------------------ |
| 0   | `payer`                     | `Pubkey`           |
| 1   | `source_token_account`      | `Pubkey`           |
| 2   | `destination_token_account` | `Pubkey`           |
| 3   | `source_mint`               | `Pubkey`           |
| 4   | `destination_mint`          | `Pubkey`           |
| 5   | `commission_account`        | `Option<Pubkey>`   |
| 6   | `platform_fee_account`      | `Option<Pubkey>`   |
| 7   | `sa_authority`              | `Option<Pubkey>`   |
| 8   | `source_token_sa`           | `Option<Pubkey>`   |
| 9   | `destination_token_sa`      | `Option<Pubkey>`   |
| 10  | `source_token_program`      | `Option<Pubkey>`   |
| 11  | `destination_token_program` | `Option<Pubkey>`   |
| 12  | `associated_token_program`  | `Option<Pubkey>`   |
| 13  | `system_program`            | `Option<Pubkey>`   |
| 14  | `sol_receiver`              | `Option<Pubkey>`   |
| 15… | `remaining`                 | `Vec<AccountMeta>` |

### `SwapV3`

Discriminator `f0e02621b01ff1af` · data `SwapV3` · accounts `SwapV3InstructionAccounts`.

| Field               | Type                    |
| ------------------- | ----------------------- |
| `args`              | [`SwapArgs`](#swapargs) |
| `commission_info`   | `u32`                   |
| `platform_fee_rate` | `u16`                   |
| `order_id`          | `u64`                   |

Required accounts: 5 (14 listed); extras go to `remaining`.

Fields of `SwapV3InstructionAccounts`, in account order:

| #   | Field                       | Type               |
| --- | --------------------------- | ------------------ |
| 0   | `payer`                     | `Pubkey`           |
| 1   | `source_token_account`      | `Pubkey`           |
| 2   | `destination_token_account` | `Pubkey`           |
| 3   | `source_mint`               | `Pubkey`           |
| 4   | `destination_mint`          | `Pubkey`           |
| 5   | `commission_account`        | `Option<Pubkey>`   |
| 6   | `platform_fee_account`      | `Option<Pubkey>`   |
| 7   | `sa_authority`              | `Option<Pubkey>`   |
| 8   | `source_token_sa`           | `Option<Pubkey>`   |
| 9   | `destination_token_sa`      | `Option<Pubkey>`   |
| 10  | `source_token_program`      | `Option<Pubkey>`   |
| 11  | `destination_token_program` | `Option<Pubkey>`   |
| 12  | `associated_token_program`  | `Option<Pubkey>`   |
| 13  | `system_program`            | `Option<Pubkey>`   |
| 14… | `remaining`                 | `Vec<AccountMeta>` |

### `SwapV3WithCpiEvent`

Discriminator `b8684f9c6bb6788a` · data `SwapV3WithCpiEvent` · accounts `SwapV3WithCpiEventInstructionAccounts`.

| Field               | Type                    |
| ------------------- | ----------------------- |
| `args`              | [`SwapArgs`](#swapargs) |
| `commission_info`   | `u32`                   |
| `platform_fee_rate` | `u16`                   |
| `order_id`          | `u64`                   |

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

Fields of `SwapV3WithCpiEventInstructionAccounts`, in account order:

| #   | Field                       | Type               |
| --- | --------------------------- | ------------------ |
| 0   | `payer`                     | `Pubkey`           |
| 1   | `source_token_account`      | `Pubkey`           |
| 2   | `destination_token_account` | `Pubkey`           |
| 3   | `source_mint`               | `Pubkey`           |
| 4   | `destination_mint`          | `Pubkey`           |
| 5   | `commission_account`        | `Option<Pubkey>`   |
| 6   | `platform_fee_account`      | `Option<Pubkey>`   |
| 7   | `sa_authority`              | `Option<Pubkey>`   |
| 8   | `source_token_sa`           | `Option<Pubkey>`   |
| 9   | `destination_token_sa`      | `Option<Pubkey>`   |
| 10  | `source_token_program`      | `Option<Pubkey>`   |
| 11  | `destination_token_program` | `Option<Pubkey>`   |
| 12  | `associated_token_program`  | `Option<Pubkey>`   |
| 13  | `system_program`            | `Option<Pubkey>`   |
| 14  | `event_authority`           | `Pubkey`           |
| 15  | `program`                   | `Pubkey`           |
| 16… | `remaining`                 | `Vec<AccountMeta>` |

### `WrapUnwrapV3`

Discriminator `b4b2bf3646080de0` · data `WrapUnwrapV3` · accounts `WrapUnwrapV3InstructionAccounts`.

| Field  | Type                                                      |
| ------ | --------------------------------------------------------- |
| `args` | [`PlatformFeeWrapUnwrapArgs`](#platformfeewrapunwrapargs) |

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

Fields of `WrapUnwrapV3InstructionAccounts`, in account order:

| #   | Field                  | Type               |
| --- | ---------------------- | ------------------ |
| 0   | `payer`                | `Pubkey`           |
| 1   | `payer_wsol_account`   | `Pubkey`           |
| 2   | `wsol_mint`            | `Pubkey`           |
| 3   | `temp_wsol_account`    | `Option<Pubkey>`   |
| 4   | `commission_account`   | `Option<Pubkey>`   |
| 5   | `platform_fee_account` | `Option<Pubkey>`   |
| 6   | `authority_pda`        | `Option<Pubkey>`   |
| 7   | `wsol_sa`              | `Option<Pubkey>`   |
| 8   | `token_program`        | `Pubkey`           |
| 9   | `system_program`       | `Pubkey`           |
| 10… | `remaining`            | `Vec<AccountMeta>` |

### `WrapUnwrapV3WithReceiver`

> _From the program's IDL:_
>
> Wrap/Unwrap with optional specified receiver
>
> - Wrap (SOL -> WSOL): receiver is WSOL token account (ATA)
> - Unwrap (WSOL -> SOL): receiver is system account (EOA)
>
> Transfer amount:
>
> - From fee: amount_in
> - To fee: amount_in - fees

Discriminator `46d3bea52f28d55f` · data `WrapUnwrapV3WithReceiver` · accounts `WrapUnwrapV3WithReceiverInstructionAccounts`.

| Field  | Type                                                      |
| ------ | --------------------------------------------------------- |
| `args` | [`PlatformFeeWrapUnwrapArgs`](#platformfeewrapunwrapargs) |

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

Fields of `WrapUnwrapV3WithReceiverInstructionAccounts`, in account order:

| #   | Field                  | Type               |
| --- | ---------------------- | ------------------ |
| 0   | `payer`                | `Pubkey`           |
| 1   | `payer_wsol_account`   | `Pubkey`           |
| 2   | `wsol_mint`            | `Pubkey`           |
| 3   | `temp_wsol_account`    | `Option<Pubkey>`   |
| 4   | `commission_account`   | `Option<Pubkey>`   |
| 5   | `platform_fee_account` | `Option<Pubkey>`   |
| 6   | `authority_pda`        | `Option<Pubkey>`   |
| 7   | `wsol_sa`              | `Option<Pubkey>`   |
| 8   | `token_program`        | `Pubkey`           |
| 9   | `system_program`       | `Pubkey`           |
| 10  | `receiver`             | `Pubkey`           |
| 11… | `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>` |

## Events

Variants of `instructions::CpiEvent`, decoded from the `CpiEvent` instruction. Each wraps a struct from `carbon_okx_dex_decoder::events::<module>`. The discriminator is the 8-byte event discriminator that follows the `e445a52e51cb9a1d` CPI-event tag.

### `SwapEvent`

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

| Field        | Type          |
| ------------ | ------------- |
| `dex`        | [`Dex`](#dex) |
| `amount_in`  | `u64`         |
| `amount_out` | `u64`         |

### `SwapWithFeesCpiEvent`

Discriminator `bd61430c25d1f71d` · `events::swap_with_fees_cpi_event::SwapWithFeesCpiEventEvent`.

| Field                             | Type     |
| --------------------------------- | -------- |
| `order_id`                        | `u64`    |
| `source_mint`                     | `Pubkey` |
| `destination_mint`                | `Pubkey` |
| `source_token_account_owner`      | `Pubkey` |
| `destination_token_account_owner` | `Pubkey` |
| `amount_in`                       | `u64`    |
| `source_token_change`             | `u64`    |
| `destination_token_change`        | `u64`    |
| `commission_direction`            | `bool`   |
| `commission_rate`                 | `u32`    |
| `commission_amount`               | `u64`    |
| `commission_account`              | `Pubkey` |
| `platform_fee_rate`               | `u16`    |
| `platform_fee_amount`             | `u64`    |
| `platform_fee_account`            | `Pubkey` |
| `trim_rate`                       | `u8`     |
| `trim_amount`                     | `u64`    |
| `trim_account`                    | `Pubkey` |

## Types

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

### `Dex`

Enum `types::Dex`.

| Variant                        | Fields                                                                                                                                                                                                                   |
| ------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `SplTokenSwap`                 |                                                                                                                                                                                                                          |
| `StableSwap`                   |                                                                                                                                                                                                                          |
| `Whirlpool`                    |                                                                                                                                                                                                                          |
| `MeteoraDynamicpool`           |                                                                                                                                                                                                                          |
| `RaydiumSwap`                  |                                                                                                                                                                                                                          |
| `RaydiumStableSwap`            |                                                                                                                                                                                                                          |
| `RaydiumClmmSwap`              |                                                                                                                                                                                                                          |
| `AldrinExchangeV1`             |                                                                                                                                                                                                                          |
| `AldrinExchangeV2`             |                                                                                                                                                                                                                          |
| `LifinityV1`                   |                                                                                                                                                                                                                          |
| `LifinityV2`                   |                                                                                                                                                                                                                          |
| `RaydiumClmmSwapV2`            |                                                                                                                                                                                                                          |
| `FluxBeam`                     |                                                                                                                                                                                                                          |
| `MeteoraDlmm`                  |                                                                                                                                                                                                                          |
| `RaydiumCpmmSwap`              |                                                                                                                                                                                                                          |
| `OpenBookV2`                   |                                                                                                                                                                                                                          |
| `WhirlpoolV2`                  |                                                                                                                                                                                                                          |
| `Phoenix`                      |                                                                                                                                                                                                                          |
| `ObricV2`                      |                                                                                                                                                                                                                          |
| `SanctumAddLiq`                |                                                                                                                                                                                                                          |
| `SanctumRemoveLiq`             |                                                                                                                                                                                                                          |
| `SanctumNonWsolSwap`           |                                                                                                                                                                                                                          |
| `SanctumWsolSwap`              |                                                                                                                                                                                                                          |
| `PumpfunBuy`                   |                                                                                                                                                                                                                          |
| `PumpfunSell`                  |                                                                                                                                                                                                                          |
| `StabbleSwap`                  |                                                                                                                                                                                                                          |
| `SanctumRouter`                |                                                                                                                                                                                                                          |
| `MeteoraVaultDeposit`          |                                                                                                                                                                                                                          |
| `MeteoraVaultWithdraw`         |                                                                                                                                                                                                                          |
| `Saros`                        |                                                                                                                                                                                                                          |
| `MeteoraLst`                   |                                                                                                                                                                                                                          |
| `Solfi`                        |                                                                                                                                                                                                                          |
| `QualiaSwap`                   |                                                                                                                                                                                                                          |
| `Zerofi`                       |                                                                                                                                                                                                                          |
| `PumpfunammBuy`                |                                                                                                                                                                                                                          |
| `PumpfunammSell`               |                                                                                                                                                                                                                          |
| `Virtuals`                     |                                                                                                                                                                                                                          |
| `VertigoBuy`                   |                                                                                                                                                                                                                          |
| `VertigoSell`                  |                                                                                                                                                                                                                          |
| `PerpetualsAddLiq`             |                                                                                                                                                                                                                          |
| `PerpetualsRemoveLiq`          |                                                                                                                                                                                                                          |
| `PerpetualsSwap`               |                                                                                                                                                                                                                          |
| `RaydiumLaunchpad`             |                                                                                                                                                                                                                          |
| `LetsBonkFun`                  |                                                                                                                                                                                                                          |
| `Woofi`                        |                                                                                                                                                                                                                          |
| `MeteoraDbc`                   |                                                                                                                                                                                                                          |
| `MeteoraDlmmSwap2`             |                                                                                                                                                                                                                          |
| `MeteoraDAMMV2`                |                                                                                                                                                                                                                          |
| `Gavel`                        |                                                                                                                                                                                                                          |
| `BoopfunBuy`                   |                                                                                                                                                                                                                          |
| `BoopfunSell`                  |                                                                                                                                                                                                                          |
| `MeteoraDbc2`                  |                                                                                                                                                                                                                          |
| `GooseFX`                      |                                                                                                                                                                                                                          |
| `Dooar`                        |                                                                                                                                                                                                                          |
| `Numeraire`                    |                                                                                                                                                                                                                          |
| `SaberDecimalWrapperDeposit`   |                                                                                                                                                                                                                          |
| `SaberDecimalWrapperWithdraw`  |                                                                                                                                                                                                                          |
| `SarosDlmm`                    |                                                                                                                                                                                                                          |
| `OneDexSwap`                   |                                                                                                                                                                                                                          |
| `Manifest`                     |                                                                                                                                                                                                                          |
| `ByrealClmm`                   |                                                                                                                                                                                                                          |
| `PancakeSwapV3Swap`            |                                                                                                                                                                                                                          |
| `PancakeSwapV3SwapV2`          |                                                                                                                                                                                                                          |
| `Tessera`                      |                                                                                                                                                                                                                          |
| `SolRfq`                       | `rfq_id`: `u64`, `expected_maker_amount`: `u64`, `expected_taker_amount`: `u64`, `maker_send_amount`: `u64`, `taker_send_amount`: `u64`, `expiry`: `u64`, `maker_use_native_sol`: `bool`, `taker_use_native_sol`: `bool` |
| `PumpfunBuy2`                  |                                                                                                                                                                                                                          |
| `PumpfunammBuy2`               |                                                                                                                                                                                                                          |
| `Humidifi`                     |                                                                                                                                                                                                                          |
| `HeavenBuy`                    |                                                                                                                                                                                                                          |
| `HeavenSell`                   |                                                                                                                                                                                                                          |
| `SolfiV2`                      |                                                                                                                                                                                                                          |
| `PumpfunBuy3`                  |                                                                                                                                                                                                                          |
| `PumpfunSell3`                 |                                                                                                                                                                                                                          |
| `PumpfunammBuy3`               |                                                                                                                                                                                                                          |
| `PumpfunammSell3`              |                                                                                                                                                                                                                          |
| `Goonfi`                       |                                                                                                                                                                                                                          |
| `MoonitBuy`                    |                                                                                                                                                                                                                          |
| `MoonitSell`                   |                                                                                                                                                                                                                          |
| `RaydiumSwapV2`                |                                                                                                                                                                                                                          |
| `Whalestreet`                  |                                                                                                                                                                                                                          |
| `SugarMoneyBuy`                | `bonding_curve_bump`: `u8`, `bonding_curve_sol_associated_account_bump`: `u8`                                                                                                                                            |
| `SugarMoneySell`               | `bonding_curve_bump`: `u8`, `bonding_curve_sol_associated_account_bump`: `u8`                                                                                                                                            |
| `MeteoraDAMMV2Swap2`           |                                                                                                                                                                                                                          |
| `AlphaQ`                       |                                                                                                                                                                                                                          |
| `FutarchyAmm`                  |                                                                                                                                                                                                                          |
| `PumpfunSell2`                 |                                                                                                                                                                                                                          |
| `HumidifiSwap2`                | `swap_id`: `u64`                                                                                                                                                                                                         |
| `Scorch`                       | `id`: `u128`                                                                                                                                                                                                             |
| `JupiterLendDeposit`           |                                                                                                                                                                                                                          |
| `JupiterLendRedeem`            |                                                                                                                                                                                                                          |
| `TaurusFi`                     |                                                                                                                                                                                                                          |
| `BisonFi`                      |                                                                                                                                                                                                                          |
| `GoonfiV2`                     |                                                                                                                                                                                                                          |
| `Quantum`                      |                                                                                                                                                                                                                          |
| `BoopfunBuy2`                  |                                                                                                                                                                                                                          |
| `BoopfunSell2`                 |                                                                                                                                                                                                                          |
| `ByrealClmm2`                  |                                                                                                                                                                                                                          |
| `Dooar2`                       |                                                                                                                                                                                                                          |
| `HeavenBuy2`                   |                                                                                                                                                                                                                          |
| `HeavenSell2`                  |                                                                                                                                                                                                                          |
| `MoonitBuy2`                   |                                                                                                                                                                                                                          |
| `MoonitSell2`                  |                                                                                                                                                                                                                          |
| `SaberDecimalWrapperDeposit2`  |                                                                                                                                                                                                                          |
| `SaberDecimalWrapperWithdraw2` |                                                                                                                                                                                                                          |
| `ByrealPropAmm`                |                                                                                                                                                                                                                          |
| `SanctumPrefundSwapViaStake`   | `swap_id`: `u64`                                                                                                                                                                                                         |
| `AbyssAmm`                     |                                                                                                                                                                                                                          |
| `Aquifer`                      |                                                                                                                                                                                                                          |
| `WhalestreetV2`                | `auth_amount_in`: `u64`, `auth`: `u64`                                                                                                                                                                                   |
| `SolfiV2WithSig`               | `unix_timestamp`: `u64`, `msg_amount_in`: `u64`, `expect_amount_out`: `u64`, `slippage`: `u16`, `user_request_slot`: `u64`, `signature`: `[u8; 64]`, `recovery_id`: `u8`                                                 |

### `PlatformFeeWrapUnwrapArgs`

Struct `types::PlatformFeeWrapUnwrapArgs`.

| Field               | Type   |
| ------------------- | ------ |
| `order_id`          | `u64`  |
| `amount_in`         | `u64`  |
| `commission_info`   | `u32`  |
| `platform_fee_rate` | `u16`  |
| `tob`               | `bool` |

### `Route`

Struct `types::Route`.

| Field     | Type               |
| --------- | ------------------ |
| `dexes`   | [`Vec<Dex>`](#dex) |
| `weights` | `Vec<u8>`          |

### `SwapArgs`

Struct `types::SwapArgs`.

| Field               | Type                        |
| ------------------- | --------------------------- |
| `amount_in`         | `u64`                       |
| `expect_amount_out` | `u64`                       |
| `min_return`        | `u64`                       |
| `amounts`           | `Vec<u64>`                  |
| `routes`            | [`Vec<Vec<Route>>`](#route) |

### `SwapEvent`

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

### `SwapWithFeesCpiEvent`

Struct `types::SwapWithFeesCpiEvent`. Same fields as the [`SwapWithFeesCpiEvent`](#swapwithfeescpievent) event.

---

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