# OpenBook v2 decoder (Carbon 2.0)

> Decode OpenBook v2 instructions, accounts and events in Rust with carbon-openbook-v2-decoder 2.0.0. Program ID opnb2LAfJYbRMAHHvqjCwQxanZn7ReEHp1k81EohpZb.

`carbon-openbook-v2-decoder` decodes the instructions, accounts and events of the OpenBook v2 program (`opnb2LAfJYbRMAHHvqjCwQxanZn7ReEHp1k81EohpZb`): 29 instructions, 6 account types, 8 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-openbook-v2-decoder`](https://crates.io/crates/carbon-openbook-v2-decoder/2.0.0) 2.0.0                 |
| Install          | `cargo add carbon-openbook-v2-decoder@2.0.0`                                                                    |
| Program ID       | `opnb2LAfJYbRMAHHvqjCwQxanZn7ReEHp1k81EohpZb` (`carbon_openbook_v2_decoder::PROGRAM_ID`)                        |
| Category         | [DEX & AMM](https://carbon.sevenlabs.org/decoders/dex-and-amm.md)                                               |
| Decoder          | `carbon_openbook_v2_decoder::OpenbookV2Decoder`                                                                 |
| Instruction enum | `instructions::OpenbookV2Instruction`                                                                           |
| Account enum     | `accounts::OpenbookV2Account`                                                                                   |
| Event enum       | `instructions::CpiEvent`                                                                                        |
| Features         | `serde`, `postgres`, `graphql` (none enabled by default)                                                        |
| API docs         | [docs.rs/carbon-openbook-v2-decoder/2.0.0](https://docs.rs/carbon-openbook-v2-decoder/2.0.0)                    |
| Source           | [decoders/openbook-v2-decoder](https://github.com/sevenlabs-hq/carbon/tree/v2.0.0/decoders/openbook-v2-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), [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 CPMM](https://carbon.sevenlabs.org/decoders/raydium-cpmm.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).

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 OpenBook v2 transactions from the public RPC and prints every decoded `Deposit` instruction. Add the dependencies:

```sh
cargo add carbon-core@2.0.0 carbon-openbook-v2-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_openbook_v2_decoder::{
        instructions::OpenbookV2Instruction, OpenbookV2Decoder, 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(OpenbookV2Decoder, InstructionLogger)
        .build()?
        .run()
        .await
}

struct InstructionLogger;

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

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

Each `Deposit` instruction prints one line with the transaction signature and the decoded `Deposit` 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 `OpenbookV2Instruction::CpiEvent { data: CpiEvent::DepositLog(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).

### 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 `Market` 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_openbook_v2_decoder::{accounts::OpenbookV2Account, OpenbookV2Decoder, 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(OpenbookV2Decoder, AccountLogger)
        .build()?
        .run()
        .await
}

struct AccountLogger;

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

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

Each update to a `Market` 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 `OpenbookV2Instruction`. Each is `OpenbookV2Instruction::<Variant> { program_id, data, accounts }`, where `data` and `accounts` are the types listed under the variant, exported from `carbon_openbook_v2_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 `opnb2LAfJYbRMAHHvqjCwQxanZn7ReEHp1k81EohpZb`.
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.

### `CancelAllAndPlaceOrders`

> _From the program's IDL:_
>
> Cancel orders and place multiple orders.

Discriminator `809bde3cba28e132` · data `CancelAllAndPlaceOrders` · accounts `CancelAllAndPlaceOrdersInstructionAccounts`.

| Field         | Type                                                       |
| ------------- | ---------------------------------------------------------- |
| `orders_type` | [`PlaceOrderType`](#placeordertype)                        |
| `bids`        | [`Vec<PlaceMultipleOrdersArgs>`](#placemultipleordersargs) |
| `asks`        | [`Vec<PlaceMultipleOrdersArgs>`](#placemultipleordersargs) |
| `limit`       | `u8`                                                       |

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

Fields of `CancelAllAndPlaceOrdersInstructionAccounts`, in account order:

| #   | Field                 | Type               |
| --- | --------------------- | ------------------ |
| 0   | `signer`              | `Pubkey`           |
| 1   | `open_orders_account` | `Pubkey`           |
| 2   | `open_orders_admin`   | `Option<Pubkey>`   |
| 3   | `user_quote_account`  | `Pubkey`           |
| 4   | `user_base_account`   | `Pubkey`           |
| 5   | `market`              | `Pubkey`           |
| 6   | `bids`                | `Pubkey`           |
| 7   | `asks`                | `Pubkey`           |
| 8   | `event_heap`          | `Pubkey`           |
| 9   | `market_quote_vault`  | `Pubkey`           |
| 10  | `market_base_vault`   | `Pubkey`           |
| 11  | `oracle_a`            | `Option<Pubkey>`   |
| 12  | `oracle_b`            | `Option<Pubkey>`   |
| 13  | `token_program`       | `Pubkey`           |
| 14… | `remaining`           | `Vec<AccountMeta>` |

### `CancelAllOrders`

> _From the program's IDL:_
>
> Cancel up to `limit` orders, optionally filtering by side

Discriminator `c453f3ab1164a08f` · data `CancelAllOrders` · accounts `CancelAllOrdersInstructionAccounts`.

| Field         | Type                    |
| ------------- | ----------------------- |
| `side_option` | [`Option<Side>`](#side) |
| `limit`       | `u8`                    |

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

Fields of `CancelAllOrdersInstructionAccounts`, in account order:

| #  | Field                 | Type               |
| -- | --------------------- | ------------------ |
| 0  | `signer`              | `Pubkey`           |
| 1  | `open_orders_account` | `Pubkey`           |
| 2  | `market`              | `Pubkey`           |
| 3  | `bids`                | `Pubkey`           |
| 4  | `asks`                | `Pubkey`           |
| 5… | `remaining`           | `Vec<AccountMeta>` |

### `CancelOrder`

> _From the program's IDL:_
>
> Cancel an order by its `order_id`.\
> Note that this doesn't emit an [`OutEvent`](crate::state::OutEvent) because a maker knows that they will be passing in their own\
> [`OpenOrdersAccount`](crate::state::OpenOrdersAccount).

Discriminator `5f81edf00831df84` · data `CancelOrder` · accounts `CancelOrderInstructionAccounts`.

| Field      | Type   |
| ---------- | ------ |
| `order_id` | `u128` |

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

Fields of `CancelOrderInstructionAccounts`, in account order:

| #  | Field                 | Type               |
| -- | --------------------- | ------------------ |
| 0  | `signer`              | `Pubkey`           |
| 1  | `open_orders_account` | `Pubkey`           |
| 2  | `market`              | `Pubkey`           |
| 3  | `bids`                | `Pubkey`           |
| 4  | `asks`                | `Pubkey`           |
| 5… | `remaining`           | `Vec<AccountMeta>` |

### `CancelOrderByClientOrderId`

> _From the program's IDL:_
>
> Cancel an order by its `client_order_id`.\
> Note that this doesn't emit an [`OutEvent`](crate::state::OutEvent) because a maker knows that they will be passing in their own\
> [`OpenOrdersAccount`](crate::state::OpenOrdersAccount).

Discriminator `73b2c908afb77b77` · data `CancelOrderByClientOrderId` · accounts `CancelOrderByClientOrderIdInstructionAccounts`.

| Field             | Type  |
| ----------------- | ----- |
| `client_order_id` | `u64` |

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

Fields of `CancelOrderByClientOrderIdInstructionAccounts`, in account order:

| #  | Field                 | Type               |
| -- | --------------------- | ------------------ |
| 0  | `signer`              | `Pubkey`           |
| 1  | `open_orders_account` | `Pubkey`           |
| 2  | `market`              | `Pubkey`           |
| 3  | `bids`                | `Pubkey`           |
| 4  | `asks`                | `Pubkey`           |
| 5… | `remaining`           | `Vec<AccountMeta>` |

### `CloseMarket`

> _From the program's IDL:_
>
> Close a [`Market`](crate::state::Market) (only\
> [`close_market_admin`](crate::state::Market::close_market_admin)).

Discriminator `589af8ba300e7bf4` · data `CloseMarket` · accounts `CloseMarketInstructionAccounts`.

No data fields.

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

Fields of `CloseMarketInstructionAccounts`, in account order:

| #  | Field                | Type               |
| -- | -------------------- | ------------------ |
| 0  | `close_market_admin` | `Pubkey`           |
| 1  | `market`             | `Pubkey`           |
| 2  | `bids`               | `Pubkey`           |
| 3  | `asks`               | `Pubkey`           |
| 4  | `event_heap`         | `Pubkey`           |
| 5  | `sol_destination`    | `Pubkey`           |
| 6  | `token_program`      | `Pubkey`           |
| 7… | `remaining`          | `Vec<AccountMeta>` |

### `CloseOpenOrdersAccount`

> _From the program's IDL:_
>
> Close an [`OpenOrdersAccount`](crate::state::OpenOrdersAccount).

Discriminator `b04a73d236b35b67` · data `CloseOpenOrdersAccount` · accounts `CloseOpenOrdersAccountInstructionAccounts`.

No data fields.

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

Fields of `CloseOpenOrdersAccountInstructionAccounts`, in account order:

| #  | Field                 | Type               |
| -- | --------------------- | ------------------ |
| 0  | `owner`               | `Pubkey`           |
| 1  | `open_orders_indexer` | `Pubkey`           |
| 2  | `open_orders_account` | `Pubkey`           |
| 3  | `sol_destination`     | `Pubkey`           |
| 4  | `system_program`      | `Pubkey`           |
| 5… | `remaining`           | `Vec<AccountMeta>` |

### `CloseOpenOrdersIndexer`

> _From the program's IDL:_
>
> Close an [`OpenOrdersIndexer`](crate::state::OpenOrdersIndexer) account.

Discriminator `67f9e5e7f7fdc588` · data `CloseOpenOrdersIndexer` · accounts `CloseOpenOrdersIndexerInstructionAccounts`.

No data fields.

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

Fields of `CloseOpenOrdersIndexerInstructionAccounts`, in account order:

| #  | Field                 | Type               |
| -- | --------------------- | ------------------ |
| 0  | `owner`               | `Pubkey`           |
| 1  | `open_orders_indexer` | `Pubkey`           |
| 2  | `sol_destination`     | `Pubkey`           |
| 3  | `token_program`       | `Pubkey`           |
| 4… | `remaining`           | `Vec<AccountMeta>` |

### `ConsumeEvents`

> _From the program's IDL:_
>
> Process up to `limit` [events](crate::state::AnyEvent).\
> When a user places a 'take' order, they do not know beforehand which market maker will have placed the 'make' order that they get executed against. This prevents them from passing in a market maker's\
> [`OpenOrdersAccount`](crate::state::OpenOrdersAccount), which is needed to credit/debit the relevant tokens to/from the maker. As such, Openbook uses a 'crank' system, where `place_order` only emits events, and `consume_events` handles token settlement.\
> Currently, there are two types of events:\
> [`FillEvent`](crate::state::FillEvent)s and [`OutEvent`](crate::state::OutEvent)s.\
> A `FillEvent` is emitted when an order is filled, and it is handled by debiting whatever the taker is selling from the taker and crediting it to the maker, and debiting whatever the taker is buying from the maker and crediting it to the taker. Note that _no tokens are moved_, these are just debits and credits to each party's\
> [`Position`](crate::state::Position). An `OutEvent` is emitted when a limit order needs to be removed from the book during a `place_order` invocation, and it is handled by crediting whatever the maker would have sold (quote token in a bid, base token in an ask) back to the maker.

Discriminator `dd91b1341f2f3fc9` · data `ConsumeEvents` · accounts `ConsumeEventsInstructionAccounts`.

| Field   | Type  |
| ------- | ----- |
| `limit` | `u64` |

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

Fields of `ConsumeEventsInstructionAccounts`, in account order:

| #  | Field                  | Type               |
| -- | ---------------------- | ------------------ |
| 0  | `consume_events_admin` | `Option<Pubkey>`   |
| 1  | `market`               | `Pubkey`           |
| 2  | `event_heap`           | `Pubkey`           |
| 3… | `remaining`            | `Vec<AccountMeta>` |

### `ConsumeGivenEvents`

> _From the program's IDL:_
>
> Process the [events](crate::state::AnyEvent) at the given positions.

Discriminator `d1e336046dac2947` · data `ConsumeGivenEvents` · accounts `ConsumeGivenEventsInstructionAccounts`.

| Field   | Type       |
| ------- | ---------- |
| `slots` | `Vec<u64>` |

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

Fields of `ConsumeGivenEventsInstructionAccounts`, in account order:

| #  | Field                  | Type               |
| -- | ---------------------- | ------------------ |
| 0  | `consume_events_admin` | `Option<Pubkey>`   |
| 1  | `market`               | `Pubkey`           |
| 2  | `event_heap`           | `Pubkey`           |
| 3… | `remaining`            | `Vec<AccountMeta>` |

### `CreateMarket`

> _From the program's IDL:_
>
> Create a [`Market`](crate::state::Market) for a given token pair.

Discriminator `67e261ebc8bcfbfe` · data `CreateMarket` · accounts `CreateMarketInstructionAccounts`.

| Field            | Type                                        |
| ---------------- | ------------------------------------------- |
| `name`           | `String`                                    |
| `oracle_config`  | [`OracleConfigParams`](#oracleconfigparams) |
| `quote_lot_size` | `i64`                                       |
| `base_lot_size`  | `i64`                                       |
| `maker_fee`      | `i64`                                       |
| `taker_fee`      | `i64`                                       |
| `time_expiry`    | `i64`                                       |

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

Fields of `CreateMarketInstructionAccounts`, in account order:

| #   | Field                      | Type               |
| --- | -------------------------- | ------------------ |
| 0   | `market`                   | `Pubkey`           |
| 1   | `market_authority`         | `Pubkey`           |
| 2   | `bids`                     | `Pubkey`           |
| 3   | `asks`                     | `Pubkey`           |
| 4   | `event_heap`               | `Pubkey`           |
| 5   | `payer`                    | `Pubkey`           |
| 6   | `market_base_vault`        | `Pubkey`           |
| 7   | `market_quote_vault`       | `Pubkey`           |
| 8   | `base_mint`                | `Pubkey`           |
| 9   | `quote_mint`               | `Pubkey`           |
| 10  | `system_program`           | `Pubkey`           |
| 11  | `token_program`            | `Pubkey`           |
| 12  | `associated_token_program` | `Pubkey`           |
| 13  | `oracle_a`                 | `Option<Pubkey>`   |
| 14  | `oracle_b`                 | `Option<Pubkey>`   |
| 15  | `collect_fee_admin`        | `Pubkey`           |
| 16  | `open_orders_admin`        | `Option<Pubkey>`   |
| 17  | `consume_events_admin`     | `Option<Pubkey>`   |
| 18  | `close_market_admin`       | `Option<Pubkey>`   |
| 19  | `event_authority`          | `Pubkey`           |
| 20  | `program`                  | `Pubkey`           |
| 21… | `remaining`                | `Vec<AccountMeta>` |

### `CreateOpenOrdersAccount`

> _From the program's IDL:_
>
> Create an [`OpenOrdersAccount`](crate::state::OpenOrdersAccount).

Discriminator `ccb5afde287dbc47` · data `CreateOpenOrdersAccount` · accounts `CreateOpenOrdersAccountInstructionAccounts`.

| Field  | Type     |
| ------ | -------- |
| `name` | `String` |

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

Fields of `CreateOpenOrdersAccountInstructionAccounts`, in account order:

| #  | Field                 | Type               |
| -- | --------------------- | ------------------ |
| 0  | `payer`               | `Pubkey`           |
| 1  | `owner`               | `Pubkey`           |
| 2  | `delegate_account`    | `Option<Pubkey>`   |
| 3  | `open_orders_indexer` | `Pubkey`           |
| 4  | `open_orders_account` | `Pubkey`           |
| 5  | `market`              | `Pubkey`           |
| 6  | `system_program`      | `Pubkey`           |
| 7… | `remaining`           | `Vec<AccountMeta>` |

### `CreateOpenOrdersIndexer`

> _From the program's IDL:_
>
> Create an [`OpenOrdersIndexer`](crate::state::OpenOrdersIndexer) account.

Discriminator `404099ffd947f985` · data `CreateOpenOrdersIndexer` · accounts `CreateOpenOrdersIndexerInstructionAccounts`.

No data fields.

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

Fields of `CreateOpenOrdersIndexerInstructionAccounts`, in account order:

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

### `Deposit`

> _From the program's IDL:_
>
> Deposit a certain amount of `base` and `quote` lamports into one's\
> [`Position`](crate::state::Position).\
> Makers might wish to `deposit`, rather than have actual tokens moved for each trade, in order to reduce CUs.

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

| Field          | Type  |
| -------------- | ----- |
| `base_amount`  | `u64` |
| `quote_amount` | `u64` |

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

Fields of `DepositInstructionAccounts`, in account order:

| #  | Field                 | Type               |
| -- | --------------------- | ------------------ |
| 0  | `owner`               | `Pubkey`           |
| 1  | `user_base_account`   | `Pubkey`           |
| 2  | `user_quote_account`  | `Pubkey`           |
| 3  | `open_orders_account` | `Pubkey`           |
| 4  | `market`              | `Pubkey`           |
| 5  | `market_base_vault`   | `Pubkey`           |
| 6  | `market_quote_vault`  | `Pubkey`           |
| 7  | `token_program`       | `Pubkey`           |
| 8… | `remaining`           | `Vec<AccountMeta>` |

### `EditOrder`

> _From the program's IDL:_
>
> Edit an order.

Discriminator `fed0761dadf8c846` · data `EditOrder` · accounts `EditOrderInstructionAccounts`.

| Field                  | Type                                |
| ---------------------- | ----------------------------------- |
| `client_order_id`      | `u64`                               |
| `expected_cancel_size` | `i64`                               |
| `place_order`          | [`PlaceOrderArgs`](#placeorderargs) |

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

Fields of `EditOrderInstructionAccounts`, in account order:

| #   | Field                 | Type               |
| --- | --------------------- | ------------------ |
| 0   | `signer`              | `Pubkey`           |
| 1   | `open_orders_account` | `Pubkey`           |
| 2   | `open_orders_admin`   | `Option<Pubkey>`   |
| 3   | `user_token_account`  | `Pubkey`           |
| 4   | `market`              | `Pubkey`           |
| 5   | `bids`                | `Pubkey`           |
| 6   | `asks`                | `Pubkey`           |
| 7   | `event_heap`          | `Pubkey`           |
| 8   | `market_vault`        | `Pubkey`           |
| 9   | `oracle_a`            | `Option<Pubkey>`   |
| 10  | `oracle_b`            | `Option<Pubkey>`   |
| 11  | `token_program`       | `Pubkey`           |
| 12… | `remaining`           | `Vec<AccountMeta>` |

### `EditOrderPegged`

> _From the program's IDL:_
>
> Edit an order pegged.

Discriminator `3ebb7d451add9d85` · data `EditOrderPegged` · accounts `EditOrderPeggedInstructionAccounts`.

| Field                  | Type                                            |
| ---------------------- | ----------------------------------------------- |
| `client_order_id`      | `u64`                                           |
| `expected_cancel_size` | `i64`                                           |
| `place_order`          | [`PlaceOrderPeggedArgs`](#placeorderpeggedargs) |

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

Fields of `EditOrderPeggedInstructionAccounts`, in account order:

| #   | Field                 | Type               |
| --- | --------------------- | ------------------ |
| 0   | `signer`              | `Pubkey`           |
| 1   | `open_orders_account` | `Pubkey`           |
| 2   | `open_orders_admin`   | `Option<Pubkey>`   |
| 3   | `user_token_account`  | `Pubkey`           |
| 4   | `market`              | `Pubkey`           |
| 5   | `bids`                | `Pubkey`           |
| 6   | `asks`                | `Pubkey`           |
| 7   | `event_heap`          | `Pubkey`           |
| 8   | `market_vault`        | `Pubkey`           |
| 9   | `oracle_a`            | `Option<Pubkey>`   |
| 10  | `oracle_b`            | `Option<Pubkey>`   |
| 11  | `token_program`       | `Pubkey`           |
| 12… | `remaining`           | `Vec<AccountMeta>` |

### `PlaceOrder`

> _From the program's IDL:_
>
> Place an order.\
> Different types of orders have different effects on the order book, as described in [`PlaceOrderType`](crate::state::PlaceOrderType).\
> `price_lots` refers to the price in lots: the number of quote lots per base lot. It is ignored for `PlaceOrderType::Market` orders.\
> `expiry_timestamp` is a unix timestamp for when this order should expire. If 0 is passed in, the order will never expire. If the time is in the past, the instruction is skipped. Timestamps in the future are reduced to now + 65,535s.\
> `limit` determines the maximum number of orders from the book to fill, and can be used to limit CU spent. When the limit is reached, processing stops and the instruction succeeds.

Discriminator `33c29baf6d82606a` · data `PlaceOrder` · accounts `PlaceOrderInstructionAccounts`.

| Field  | Type                                |
| ------ | ----------------------------------- |
| `args` | [`PlaceOrderArgs`](#placeorderargs) |

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

Fields of `PlaceOrderInstructionAccounts`, in account order:

| #   | Field                 | Type               |
| --- | --------------------- | ------------------ |
| 0   | `signer`              | `Pubkey`           |
| 1   | `open_orders_account` | `Pubkey`           |
| 2   | `open_orders_admin`   | `Option<Pubkey>`   |
| 3   | `user_token_account`  | `Pubkey`           |
| 4   | `market`              | `Pubkey`           |
| 5   | `bids`                | `Pubkey`           |
| 6   | `asks`                | `Pubkey`           |
| 7   | `event_heap`          | `Pubkey`           |
| 8   | `market_vault`        | `Pubkey`           |
| 9   | `oracle_a`            | `Option<Pubkey>`   |
| 10  | `oracle_b`            | `Option<Pubkey>`   |
| 11  | `token_program`       | `Pubkey`           |
| 12… | `remaining`           | `Vec<AccountMeta>` |

### `PlaceOrderPegged`

> _From the program's IDL:_
>
> Place an oracle-peg order.

Discriminator `8db9fb3f4a55d291` · data `PlaceOrderPegged` · accounts `PlaceOrderPeggedInstructionAccounts`.

| Field  | Type                                            |
| ------ | ----------------------------------------------- |
| `args` | [`PlaceOrderPeggedArgs`](#placeorderpeggedargs) |

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

Fields of `PlaceOrderPeggedInstructionAccounts`, in account order:

| #   | Field                 | Type               |
| --- | --------------------- | ------------------ |
| 0   | `signer`              | `Pubkey`           |
| 1   | `open_orders_account` | `Pubkey`           |
| 2   | `open_orders_admin`   | `Option<Pubkey>`   |
| 3   | `user_token_account`  | `Pubkey`           |
| 4   | `market`              | `Pubkey`           |
| 5   | `bids`                | `Pubkey`           |
| 6   | `asks`                | `Pubkey`           |
| 7   | `event_heap`          | `Pubkey`           |
| 8   | `market_vault`        | `Pubkey`           |
| 9   | `oracle_a`            | `Option<Pubkey>`   |
| 10  | `oracle_b`            | `Option<Pubkey>`   |
| 11  | `token_program`       | `Pubkey`           |
| 12… | `remaining`           | `Vec<AccountMeta>` |

### `PlaceOrders`

> _From the program's IDL:_
>
> Place multiple orders

Discriminator `3c3f327b0cc53cbe` · data `PlaceOrders` · accounts `PlaceOrdersInstructionAccounts`.

| Field         | Type                                                       |
| ------------- | ---------------------------------------------------------- |
| `orders_type` | [`PlaceOrderType`](#placeordertype)                        |
| `bids`        | [`Vec<PlaceMultipleOrdersArgs>`](#placemultipleordersargs) |
| `asks`        | [`Vec<PlaceMultipleOrdersArgs>`](#placemultipleordersargs) |
| `limit`       | `u8`                                                       |

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

Fields of `PlaceOrdersInstructionAccounts`, in account order:

| #   | Field                 | Type               |
| --- | --------------------- | ------------------ |
| 0   | `signer`              | `Pubkey`           |
| 1   | `open_orders_account` | `Pubkey`           |
| 2   | `open_orders_admin`   | `Option<Pubkey>`   |
| 3   | `user_quote_account`  | `Pubkey`           |
| 4   | `user_base_account`   | `Pubkey`           |
| 5   | `market`              | `Pubkey`           |
| 6   | `bids`                | `Pubkey`           |
| 7   | `asks`                | `Pubkey`           |
| 8   | `event_heap`          | `Pubkey`           |
| 9   | `market_quote_vault`  | `Pubkey`           |
| 10  | `market_base_vault`   | `Pubkey`           |
| 11  | `oracle_a`            | `Option<Pubkey>`   |
| 12  | `oracle_b`            | `Option<Pubkey>`   |
| 13  | `token_program`       | `Pubkey`           |
| 14… | `remaining`           | `Vec<AccountMeta>` |

### `PlaceTakeOrder`

> _From the program's IDL:_
>
> Place an order that shall take existing liquidity off of the book, not add a new order off the book.\
> This type of order allows for instant token settlement for the taker.

Discriminator `032c47031ac7cb55` · data `PlaceTakeOrder` · accounts `PlaceTakeOrderInstructionAccounts`.

| Field  | Type                                        |
| ------ | ------------------------------------------- |
| `args` | [`PlaceTakeOrderArgs`](#placetakeorderargs) |

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

Fields of `PlaceTakeOrderInstructionAccounts`, in account order:

| #   | Field                | Type               |
| --- | -------------------- | ------------------ |
| 0   | `signer`             | `Pubkey`           |
| 1   | `penalty_payer`      | `Pubkey`           |
| 2   | `market`             | `Pubkey`           |
| 3   | `market_authority`   | `Pubkey`           |
| 4   | `bids`               | `Pubkey`           |
| 5   | `asks`               | `Pubkey`           |
| 6   | `market_base_vault`  | `Pubkey`           |
| 7   | `market_quote_vault` | `Pubkey`           |
| 8   | `event_heap`         | `Pubkey`           |
| 9   | `user_base_account`  | `Pubkey`           |
| 10  | `user_quote_account` | `Pubkey`           |
| 11  | `oracle_a`           | `Option<Pubkey>`   |
| 12  | `oracle_b`           | `Option<Pubkey>`   |
| 13  | `token_program`      | `Pubkey`           |
| 14  | `system_program`     | `Pubkey`           |
| 15  | `open_orders_admin`  | `Option<Pubkey>`   |
| 16… | `remaining`          | `Vec<AccountMeta>` |

### `PruneOrders`

> _From the program's IDL:_
>
> Remove orders from the book when the market is expired (only\
> [`close_market_admin`](crate::state::Market::close_market_admin)).

Discriminator `1bd59fbf0c747079` · data `PruneOrders` · accounts `PruneOrdersInstructionAccounts`.

| Field   | Type |
| ------- | ---- |
| `limit` | `u8` |

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

Fields of `PruneOrdersInstructionAccounts`, in account order:

| #  | Field                 | Type               |
| -- | --------------------- | ------------------ |
| 0  | `close_market_admin`  | `Pubkey`           |
| 1  | `open_orders_account` | `Pubkey`           |
| 2  | `market`              | `Pubkey`           |
| 3  | `bids`                | `Pubkey`           |
| 4  | `asks`                | `Pubkey`           |
| 5… | `remaining`           | `Vec<AccountMeta>` |

### `Refill`

> _From the program's IDL:_
>
> Refill a certain amount of `base` and `quote` lamports. The amount being passed is the total lamports that the [`Position`](crate::state::Position) will have. Makers might wish to `refill`, rather than have actual tokens moved for each trade, in order to reduce CUs.

Discriminator `80cf8e0b36e826c9` · data `Refill` · accounts `RefillInstructionAccounts`.

| Field          | Type  |
| -------------- | ----- |
| `base_amount`  | `u64` |
| `quote_amount` | `u64` |

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

Fields of `RefillInstructionAccounts`, in account order:

| #  | Field                 | Type               |
| -- | --------------------- | ------------------ |
| 0  | `owner`               | `Pubkey`           |
| 1  | `user_base_account`   | `Pubkey`           |
| 2  | `user_quote_account`  | `Pubkey`           |
| 3  | `open_orders_account` | `Pubkey`           |
| 4  | `market`              | `Pubkey`           |
| 5  | `market_base_vault`   | `Pubkey`           |
| 6  | `market_quote_vault`  | `Pubkey`           |
| 7  | `token_program`       | `Pubkey`           |
| 8… | `remaining`           | `Vec<AccountMeta>` |

### `SetDelegate`

> _From the program's IDL:_
>
> Update the [`delegate`](crate::state::OpenOrdersAccount::delegate) of an open orders account.

Discriminator `f21e2e4c6ceb80b5` · data `SetDelegate` · accounts `SetDelegateInstructionAccounts`.

No data fields.

Required accounts: 2 (3 listed); extras go to `remaining`.

Fields of `SetDelegateInstructionAccounts`, in account order:

| #  | Field                 | Type               |
| -- | --------------------- | ------------------ |
| 0  | `owner`               | `Pubkey`           |
| 1  | `open_orders_account` | `Pubkey`           |
| 2  | `delegate_account`    | `Option<Pubkey>`   |
| 3… | `remaining`           | `Vec<AccountMeta>` |

### `SetMarketExpired`

> _From the program's IDL:_
>
> Set market to expired before pruning orders and closing the market (only\
> [`close_market_admin`](crate::state::Market::close_market_admin)).

Discriminator `db52dbec3c73c540` · data `SetMarketExpired` · accounts `SetMarketExpiredInstructionAccounts`.

No data fields.

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

Fields of `SetMarketExpiredInstructionAccounts`, in account order:

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

### `SettleFunds`

> _From the program's IDL:_
>
> Withdraw any available tokens.

Discriminator `ee40a3604bab1021` · data `SettleFunds` · accounts `SettleFundsInstructionAccounts`.

No data fields.

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

Fields of `SettleFundsInstructionAccounts`, in account order:

| #   | Field                 | Type               |
| --- | --------------------- | ------------------ |
| 0   | `owner`               | `Pubkey`           |
| 1   | `penalty_payer`       | `Pubkey`           |
| 2   | `open_orders_account` | `Pubkey`           |
| 3   | `market`              | `Pubkey`           |
| 4   | `market_authority`    | `Pubkey`           |
| 5   | `market_base_vault`   | `Pubkey`           |
| 6   | `market_quote_vault`  | `Pubkey`           |
| 7   | `user_base_account`   | `Pubkey`           |
| 8   | `user_quote_account`  | `Pubkey`           |
| 9   | `referrer_account`    | `Option<Pubkey>`   |
| 10  | `token_program`       | `Pubkey`           |
| 11  | `system_program`      | `Pubkey`           |
| 12… | `remaining`           | `Vec<AccountMeta>` |

### `SettleFundsExpired`

> _From the program's IDL:_
>
> Withdraw any available tokens when the market is expired (only\
> [`close_market_admin`](crate::state::Market::close_market_admin)).

Discriminator `6b123845e43837a4` · data `SettleFundsExpired` · accounts `SettleFundsExpiredInstructionAccounts`.

No data fields.

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

Fields of `SettleFundsExpiredInstructionAccounts`, in account order:

| #   | Field                 | Type               |
| --- | --------------------- | ------------------ |
| 0   | `close_market_admin`  | `Pubkey`           |
| 1   | `owner`               | `Pubkey`           |
| 2   | `penalty_payer`       | `Pubkey`           |
| 3   | `open_orders_account` | `Pubkey`           |
| 4   | `market`              | `Pubkey`           |
| 5   | `market_authority`    | `Pubkey`           |
| 6   | `market_base_vault`   | `Pubkey`           |
| 7   | `market_quote_vault`  | `Pubkey`           |
| 8   | `user_base_account`   | `Pubkey`           |
| 9   | `user_quote_account`  | `Pubkey`           |
| 10  | `referrer_account`    | `Option<Pubkey>`   |
| 11  | `token_program`       | `Pubkey`           |
| 12  | `system_program`      | `Pubkey`           |
| 13… | `remaining`           | `Vec<AccountMeta>` |

### `StubOracleClose`

Discriminator `5c892d032d3c75e0` · data `StubOracleClose` · accounts `StubOracleCloseInstructionAccounts`.

No data fields.

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

Fields of `StubOracleCloseInstructionAccounts`, in account order:

| #  | Field             | Type               |
| -- | ----------------- | ------------------ |
| 0  | `owner`           | `Pubkey`           |
| 1  | `oracle`          | `Pubkey`           |
| 2  | `sol_destination` | `Pubkey`           |
| 3  | `token_program`   | `Pubkey`           |
| 4… | `remaining`       | `Vec<AccountMeta>` |

### `StubOracleCreate`

Discriminator `ac3f65538d4cc7d8` · data `StubOracleCreate` · accounts `StubOracleCreateInstructionAccounts`.

| Field   | Type  |
| ------- | ----- |
| `price` | `f64` |

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

Fields of `StubOracleCreateInstructionAccounts`, in account order:

| #  | Field            | Type               |
| -- | ---------------- | ------------------ |
| 0  | `payer`          | `Pubkey`           |
| 1  | `owner`          | `Pubkey`           |
| 2  | `oracle`         | `Pubkey`           |
| 3  | `mint`           | `Pubkey`           |
| 4  | `system_program` | `Pubkey`           |
| 5… | `remaining`      | `Vec<AccountMeta>` |

### `StubOracleSet`

Discriminator `6dc64f7941caa18e` · data `StubOracleSet` · accounts `StubOracleSetInstructionAccounts`.

| Field   | Type  |
| ------- | ----- |
| `price` | `f64` |

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

Fields of `StubOracleSetInstructionAccounts`, in account order:

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

### `SweepFees`

> _From the program's IDL:_
>
> Sweep fees, as a [`Market`](crate::state::Market)'s admin.

Discriminator `afe1624776422294` · data `SweepFees` · accounts `SweepFeesInstructionAccounts`.

No data fields.

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

Fields of `SweepFeesInstructionAccounts`, in account order:

| #  | Field                    | Type               |
| -- | ------------------------ | ------------------ |
| 0  | `collect_fee_admin`      | `Pubkey`           |
| 1  | `market`                 | `Pubkey`           |
| 2  | `market_authority`       | `Pubkey`           |
| 3  | `market_quote_vault`     | `Pubkey`           |
| 4  | `token_receiver_account` | `Pubkey`           |
| 5  | `token_program`          | `Pubkey`           |
| 6… | `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 `OpenbookV2Account`. Each wraps a boxed struct from `carbon_openbook_v2_decoder::accounts::<module>`. `decode_account` only considers accounts owned by `PROGRAM_ID` and returns the first variant that matches.

### `BookSide`

Discriminator `482ce18db2826139` · `accounts::book_side::BookSide`.

| Field            | Type                                   |
| ---------------- | -------------------------------------- |
| `roots`          | [`[OrderTreeRoot; 2]`](#ordertreeroot) |
| `reserved_roots` | [`[OrderTreeRoot; 4]`](#ordertreeroot) |
| `reserved`       | `[u8; 256]`                            |
| `nodes`          | [`OrderTreeNodes`](#ordertreenodes)    |

### `EventHeap`

> _From the program's IDL:_
>
> Container for the different EventTypes.\
> Events are stored in a fixed-array of nodes. Free nodes are connected by a single-linked list starting at free_head while used nodes form a circular doubly-linked list starting at used_head.

Discriminator `773b3d13a55439af` · `accounts::event_heap::EventHeap`.

| Field      | Type                                  |
| ---------- | ------------------------------------- |
| `header`   | [`EventHeapHeader`](#eventheapheader) |
| `nodes`    | [`[EventNode; 600]`](#eventnode)      |
| `reserved` | `[u8; 64]`                            |

### `Market`

Discriminator `dbbed53700e3c69a` · `accounts::market::Market`.

| Field                      | Type                                          | Description                                                                                                                                                                                                                                                                          |
| -------------------------- | --------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `bump`                     | `u8`                                          | PDA bump                                                                                                                                                                                                                                                                             |
| `base_decimals`            | `u8`                                          | Number of decimals used for the base token. Used to convert the oracle's price into a native/native price.                                                                                                                                                                           |
| `quote_decimals`           | `u8`                                          |                                                                                                                                                                                                                                                                                      |
| `padding1`                 | `[u8; 5]`                                     |                                                                                                                                                                                                                                                                                      |
| `market_authority`         | `Pubkey`                                      |                                                                                                                                                                                                                                                                                      |
| `time_expiry`              | `i64`                                         | No expiry = 0. Market will expire and no trading allowed after time_expiry                                                                                                                                                                                                           |
| `collect_fee_admin`        | `Pubkey`                                      | Admin who can collect fees from the market                                                                                                                                                                                                                                           |
| `open_orders_admin`        | [`NonZeroPubkeyOption`](#nonzeropubkeyoption) | Admin who must sign off on all order creations                                                                                                                                                                                                                                       |
| `consume_events_admin`     | [`NonZeroPubkeyOption`](#nonzeropubkeyoption) | Admin who must sign off on all event consumptions                                                                                                                                                                                                                                    |
| `close_market_admin`       | [`NonZeroPubkeyOption`](#nonzeropubkeyoption) | Admin who can set market expired, prune orders and close the market                                                                                                                                                                                                                  |
| `name`                     | `[u8; 16]`                                    | Name. Trailing zero bytes are ignored.                                                                                                                                                                                                                                               |
| `bids`                     | `Pubkey`                                      | Address of the BookSide account for bids                                                                                                                                                                                                                                             |
| `asks`                     | `Pubkey`                                      | Address of the BookSide account for asks                                                                                                                                                                                                                                             |
| `event_heap`               | `Pubkey`                                      | Address of the EventHeap account                                                                                                                                                                                                                                                     |
| `oracle_a`                 | [`NonZeroPubkeyOption`](#nonzeropubkeyoption) | Oracles account address                                                                                                                                                                                                                                                              |
| `oracle_b`                 | [`NonZeroPubkeyOption`](#nonzeropubkeyoption) |                                                                                                                                                                                                                                                                                      |
| `oracle_config`            | [`OracleConfig`](#oracleconfig)               | Oracle configuration                                                                                                                                                                                                                                                                 |
| `quote_lot_size`           | `i64`                                         | Number of quote native in a quote lot. Must be a power of 10. Primarily useful for increasing the tick size on the market: A lot price of 1 becomes a native price of quote_lot_size/base_lot_size becomes a ui price of quote_lot_size\*base_decimals/base_lot_size/quote_decimals. |
| `base_lot_size`            | `i64`                                         | Number of base native in a base lot. Must be a power of 10. Example: If base decimals for the underlying asset is 6, base lot size is 100 and and base position lots is 10_000 then base position native is 1_000_000 and base position ui is 1.                                     |
| `seq_num`                  | `u64`                                         | Total number of orders seen                                                                                                                                                                                                                                                          |
| `registration_time`        | `i64`                                         | Timestamp in seconds that the market was registered at.                                                                                                                                                                                                                              |
| `maker_fee`                | `i64`                                         | Fees Fee (in 10^-6) when matching maker orders. maker_fee < 0 it means some of the taker_fees goes to the maker maker_fee > 0, it means no taker_fee to the maker, and maker fee goes to the referral                                                                                |
| `taker_fee`                | `i64`                                         | Fee (in 10^-6) for taker orders, always >= 0.                                                                                                                                                                                                                                        |
| `fees_accrued`             | `u128`                                        | Total fees accrued in native quote                                                                                                                                                                                                                                                   |
| `fees_to_referrers`        | `u128`                                        | Total fees settled in native quote                                                                                                                                                                                                                                                   |
| `referrer_rebates_accrued` | `u64`                                         | Referrer rebates to be distributed                                                                                                                                                                                                                                                   |
| `fees_available`           | `u64`                                         | Fees generated and available to withdraw via sweep_fees                                                                                                                                                                                                                              |
| `maker_volume`             | `u128`                                        | Cumulative maker volume (same as taker volume) in quote native units                                                                                                                                                                                                                 |
| `taker_volume_wo_oo`       | `u128`                                        | Cumulative taker volume in quote native units due to place take orders                                                                                                                                                                                                               |
| `base_mint`                | `Pubkey`                                      |                                                                                                                                                                                                                                                                                      |
| `quote_mint`               | `Pubkey`                                      |                                                                                                                                                                                                                                                                                      |
| `market_base_vault`        | `Pubkey`                                      |                                                                                                                                                                                                                                                                                      |
| `base_deposit_total`       | `u64`                                         |                                                                                                                                                                                                                                                                                      |
| `market_quote_vault`       | `Pubkey`                                      |                                                                                                                                                                                                                                                                                      |
| `quote_deposit_total`      | `u64`                                         |                                                                                                                                                                                                                                                                                      |
| `reserved`                 | `[u8; 128]`                                   |                                                                                                                                                                                                                                                                                      |

### `OpenOrdersAccount`

Discriminator `ffc24e7b1069d0a5` · `accounts::open_orders_account::OpenOrdersAccount`.

| Field         | Type                                          |
| ------------- | --------------------------------------------- |
| `owner`       | `Pubkey`                                      |
| `market`      | `Pubkey`                                      |
| `name`        | `[u8; 32]`                                    |
| `delegate`    | [`NonZeroPubkeyOption`](#nonzeropubkeyoption) |
| `account_num` | `u32`                                         |
| `bump`        | `u8`                                          |
| `version`     | `u8`                                          |
| `padding`     | `[u8; 2]`                                     |
| `position`    | [`Position`](#position)                       |
| `open_orders` | [`[OpenOrder; 24]`](#openorder)               |

### `OpenOrdersIndexer`

Discriminator `c35380d5cc5b1396` · `accounts::open_orders_indexer::OpenOrdersIndexer`.

| Field             | Type          |
| ----------------- | ------------- |
| `bump`            | `u8`          |
| `created_counter` | `u32`         |
| `addresses`       | `Vec<Pubkey>` |

### `StubOracle`

Discriminator `e0fbfe63b1ae8904` · `accounts::stub_oracle::StubOracle`.

| Field              | Type        |
| ------------------ | ----------- |
| `owner`            | `Pubkey`    |
| `mint`             | `Pubkey`    |
| `price`            | `f64`       |
| `last_update_ts`   | `i64`       |
| `last_update_slot` | `u64`       |
| `deviation`        | `f64`       |
| `reserved`         | `[u8; 104]` |

## Events

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

### `DepositLog`

Discriminator `8dbaa8fc6c8d485e` · `events::deposit_log::DepositLogEvent`.

| Field                 | Type     |
| --------------------- | -------- |
| `open_orders_account` | `Pubkey` |
| `signer`              | `Pubkey` |
| `base_amount`         | `u64`    |
| `quote_amount`        | `u64`    |

### `FillLog`

Discriminator `9617299498a2d740` · `events::fill_log::FillLogEvent`.

| Field                   | Type     |
| ----------------------- | -------- |
| `market`                | `Pubkey` |
| `taker_side`            | `u8`     |
| `maker_slot`            | `u8`     |
| `maker_out`             | `bool`   |
| `timestamp`             | `u64`    |
| `seq_num`               | `u64`    |
| `maker`                 | `Pubkey` |
| `maker_client_order_id` | `u64`    |
| `maker_fee`             | `u64`    |
| `maker_timestamp`       | `u64`    |
| `taker`                 | `Pubkey` |
| `taker_client_order_id` | `u64`    |
| `taker_fee_ceil`        | `u64`    |
| `price`                 | `i64`    |
| `quantity`              | `i64`    |

### `MarketMetaDataLog`

Discriminator `d157d4eca43a3c75` · `events::market_meta_data_log::MarketMetaDataLogEvent`.

| Field            | Type     |
| ---------------- | -------- |
| `market`         | `Pubkey` |
| `name`           | `String` |
| `base_mint`      | `Pubkey` |
| `quote_mint`     | `Pubkey` |
| `base_decimals`  | `u8`     |
| `quote_decimals` | `u8`     |
| `base_lot_size`  | `i64`    |
| `quote_lot_size` | `i64`    |

### `TotalOrderFillEvent`

Discriminator `08eb303aae4c9c69` · `events::total_order_fill_event::TotalOrderFillEventEvent`.

| Field                     | Type     |
| ------------------------- | -------- |
| `side`                    | `u8`     |
| `taker`                   | `Pubkey` |
| `total_quantity_paid`     | `u64`    |
| `total_quantity_received` | `u64`    |
| `fees`                    | `u64`    |

### `SetDelegateLog`

Discriminator `3582975c6d399170` · `events::set_delegate_log::SetDelegateLogEvent`.

| Field                 | Type             |
| --------------------- | ---------------- |
| `open_orders_account` | `Pubkey`         |
| `delegate`            | `Option<Pubkey>` |

### `SettleFundsLog`

Discriminator `0a32f075ed43e6e9` · `events::settle_funds_log::SettleFundsLogEvent`.

| Field                 | Type             |
| --------------------- | ---------------- |
| `open_orders_account` | `Pubkey`         |
| `base_native`         | `u64`            |
| `quote_native`        | `u64`            |
| `referrer_rebate`     | `u64`            |
| `referrer`            | `Option<Pubkey>` |

### `SweepFeesLog`

Discriminator `d2f21a4d5e30ff3d` · `events::sweep_fees_log::SweepFeesLogEvent`.

| Field      | Type     |
| ---------- | -------- |
| `market`   | `Pubkey` |
| `amount`   | `u64`    |
| `receiver` | `Pubkey` |

### `OpenOrdersPositionLog`

Discriminator `c4f99421a8e44906` · `events::open_orders_position_log::OpenOrdersPositionLogEvent`.

| Field                        | Type     |
| ---------------------------- | -------- |
| `owner`                      | `Pubkey` |
| `open_orders_account_num`    | `u32`    |
| `market`                     | `Pubkey` |
| `bids_base_lots`             | `i64`    |
| `bids_quote_lots`            | `i64`    |
| `asks_base_lots`             | `i64`    |
| `base_free_native`           | `u64`    |
| `quote_free_native`          | `u64`    |
| `locked_maker_fees`          | `u64`    |
| `referrer_rebates_available` | `u64`    |
| `maker_volume`               | `u128`   |
| `taker_volume`               | `u128`   |

## Types

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

### `AnyEvent`

Struct `types::AnyEvent`.

| Field        | Type        |
| ------------ | ----------- |
| `event_type` | `u8`        |
| `padding`    | `[u8; 143]` |

### `AnyNode`

Struct `types::AnyNode`.

| Field  | Type       |
| ------ | ---------- |
| `tag`  | `u8`       |
| `data` | `[u8; 87]` |

### `BookSideOrderTree`

Enum `types::BookSideOrderTree`.

| Variant        |
| -------------- |
| `Fixed`        |
| `OraclePegged` |

### `DepositLog`

Struct `types::DepositLog`. Same fields as the [`DepositLog`](#depositlog) event.

### `EventHeapHeader`

Struct `types::EventHeapHeader`.

| Field       | Type  |
| ----------- | ----- |
| `free_head` | `u16` |
| `used_head` | `u16` |
| `count`     | `u16` |
| `padd`      | `u16` |
| `seq_num`   | `u64` |

### `EventNode`

Struct `types::EventNode`.

| Field   | Type                    |
| ------- | ----------------------- |
| `next`  | `u16`                   |
| `prev`  | `u16`                   |
| `pad`   | `[u8; 4]`               |
| `event` | [`AnyEvent`](#anyevent) |

### `EventType`

Enum `types::EventType`.

| Variant |
| ------- |
| `Fill`  |
| `Out`   |

### `FillEvent`

Struct `types::FillEvent`.

| Field                   | Type      |
| ----------------------- | --------- |
| `event_type`            | `u8`      |
| `taker_side`            | `u8`      |
| `maker_out`             | `u8`      |
| `maker_slot`            | `u8`      |
| `padding`               | `[u8; 4]` |
| `timestamp`             | `u64`     |
| `seq_num`               | `u64`     |
| `maker`                 | `Pubkey`  |
| `maker_timestamp`       | `u64`     |
| `taker`                 | `Pubkey`  |
| `taker_client_order_id` | `u64`     |
| `price`                 | `i64`     |
| `peg_limit`             | `i64`     |
| `quantity`              | `i64`     |
| `maker_client_order_id` | `u64`     |
| `reserved`              | `[u8; 8]` |

### `FillLog`

Struct `types::FillLog`. Same fields as the [`FillLog`](#filllog) event.

### `I80F48`

> _From the program's IDL:_
>
> Nothing in Rust shall use these types. They only exist so that the Anchor\
> IDL knows about them and typescript can deserialize it.

Struct `types::I80F48`.

| Field | Type   |
| ----- | ------ |
| `val` | `i128` |

### `InnerNode`

> _From the program's IDL:_
>
> InnerNodes and LeafNodes compose the binary tree of orders.\
> Each InnerNode has exactly two children, which are either InnerNodes themselves, or LeafNodes. The children share the top `prefix_len` bits of `key`. The left child has a 0 in the next bit, and the right a 1.

Struct `types::InnerNode`.

| Field                   | Type       | Description                                                                                                                                                              |
| ----------------------- | ---------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `tag`                   | `u8`       |                                                                                                                                                                          |
| `padding`               | `[u8; 3]`  |                                                                                                                                                                          |
| `prefix_len`            | `u32`      | number of highest `key` bits that all children share e.g. if it's 2, the two highest bits of `key` will be the same on all children                                      |
| `key`                   | `u128`     | only the top `prefix_len` bits of `key` are relevant                                                                                                                     |
| `children`              | `[u32; 2]` | indexes into `BookSide::nodes`                                                                                                                                           |
| `child_earliest_expiry` | `[u64; 2]` | The earliest expiry timestamp for the left and right subtrees. Needed to be able to find and remove expired orders without having to iterate through the whole bookside. |
| `reserved`              | `[u8; 40]` |                                                                                                                                                                          |

### `LeafNode`

> _From the program's IDL:_
>
> LeafNodes represent an order in the binary tree

Struct `types::LeafNode`.

| Field             | Type      | Description                                                                                                                                                           |
| ----------------- | --------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `tag`             | `u8`      | NodeTag                                                                                                                                                               |
| `owner_slot`      | `u8`      | Index into the owning OpenOrdersAccount's OpenOrders                                                                                                                  |
| `time_in_force`   | `u16`     | Time in seconds after `timestamp` at which the order expires. A value of 0 means no expiry.                                                                           |
| `padding`         | `[u8; 4]` |                                                                                                                                                                       |
| `key`             | `u128`    | The binary tree key, see new_node_key()                                                                                                                               |
| `owner`           | `Pubkey`  | Address of the owning OpenOrdersAccount                                                                                                                               |
| `quantity`        | `i64`     | Number of base lots to buy or sell, always >=1                                                                                                                        |
| `timestamp`       | `u64`     | The time the order was placed                                                                                                                                         |
| `peg_limit`       | `i64`     | If the effective price of an oracle pegged order exceeds this limit, it will be considered invalid and may be removed. Only applicable in the oracle_pegged OrderTree |
| `client_order_id` | `u64`     | User defined id for this order, used in FillEvents                                                                                                                    |

### `MarketMetaDataLog`

Struct `types::MarketMetaDataLog`. Same fields as the [`MarketMetaDataLog`](#marketmetadatalog) event.

### `NodeTag`

Enum `types::NodeTag`.

| Variant         |
| --------------- |
| `Uninitialized` |
| `InnerNode`     |
| `LeafNode`      |
| `FreeNode`      |
| `LastFreeNode`  |

### `NonZeroPubkeyOption`

> _From the program's IDL:_
>
> Like `Option`, but implemented for `Pubkey` to be used with `zero_copy`

Struct `types::NonZeroPubkeyOption`.

| Field | Type     |
| ----- | -------- |
| `key` | `Pubkey` |

### `OpenOrder`

Struct `types::OpenOrder`.

| Field           | Type      | Description                              |
| --------------- | --------- | ---------------------------------------- |
| `id`            | `u128`    |                                          |
| `client_id`     | `u64`     |                                          |
| `locked_price`  | `i64`     | Price at which user's assets were locked |
| `is_free`       | `u8`      |                                          |
| `side_and_tree` | `u8`      |                                          |
| `padding`       | `[u8; 6]` |                                          |

### `OpenOrdersPositionLog`

Struct `types::OpenOrdersPositionLog`. Same fields as the [`OpenOrdersPositionLog`](#openorderspositionlog) event.

### `OracleConfig`

Struct `types::OracleConfig`.

| Field                 | Type       |
| --------------------- | ---------- |
| `conf_filter`         | `f64`      |
| `max_staleness_slots` | `i64`      |
| `reserved`            | `[u8; 72]` |

### `OracleConfigParams`

Struct `types::OracleConfigParams`.

| Field                 | Type          |
| --------------------- | ------------- |
| `conf_filter`         | `f32`         |
| `max_staleness_slots` | `Option<u32>` |

### `OracleType`

Enum `types::OracleType`.

| Variant         |
| --------------- |
| `Pyth`          |
| `Stub`          |
| `SwitchboardV1` |
| `SwitchboardV2` |
| `RaydiumCLMM`   |

### `OrderParams`

Enum `types::OrderParams`.

| Variant             | Fields                                                                                          |
| ------------------- | ----------------------------------------------------------------------------------------------- |
| `Market`            |                                                                                                 |
| `ImmediateOrCancel` | `price_lots`: `i64`                                                                             |
| `Fixed`             | `price_lots`: `i64`, `order_type`: [`PostOrderType`](#postordertype)                            |
| `OraclePegged`      | `price_offset_lots`: `i64`, `order_type`: [`PostOrderType`](#postordertype), `peg_limit`: `i64` |

### `OrderState`

Enum `types::OrderState`.

| Variant   |
| --------- |
| `Valid`   |
| `Invalid` |
| `Skipped` |

### `OrderTreeNodes`

> _From the program's IDL:_
>
> A binary tree on AnyNode::key()\
> The key encodes the price in the top 64 bits.

Struct `types::OrderTreeNodes`.

| Field             | Type                          |
| ----------------- | ----------------------------- |
| `order_tree_type` | `u8`                          |
| `padding`         | `[u8; 3]`                     |
| `bump_index`      | `u32`                         |
| `free_list_len`   | `u32`                         |
| `free_list_head`  | `u32`                         |
| `reserved`        | `[u8; 512]`                   |
| `nodes`           | [`[AnyNode; 1024]`](#anynode) |

### `OrderTreeRoot`

Struct `types::OrderTreeRoot`.

| Field        | Type  |
| ------------ | ----- |
| `maybe_node` | `u32` |
| `leaf_count` | `u32` |

### `OrderTreeType`

Enum `types::OrderTreeType`.

| Variant |
| ------- |
| `Bids`  |
| `Asks`  |

### `OutEvent`

Struct `types::OutEvent`.

| Field        | Type       |
| ------------ | ---------- |
| `event_type` | `u8`       |
| `side`       | `u8`       |
| `owner_slot` | `u8`       |
| `padding0`   | `[u8; 5]`  |
| `timestamp`  | `u64`      |
| `seq_num`    | `u64`      |
| `owner`      | `Pubkey`   |
| `quantity`   | `i64`      |
| `padding1`   | `[u8; 80]` |

### `PlaceMultipleOrdersArgs`

Struct `types::PlaceMultipleOrdersArgs`.

| Field                           | Type  |
| ------------------------------- | ----- |
| `price_lots`                    | `i64` |
| `max_quote_lots_including_fees` | `i64` |
| `expiry_timestamp`              | `u64` |

### `PlaceOrderArgs`

Struct `types::PlaceOrderArgs`.

| Field                           | Type                                      |
| ------------------------------- | ----------------------------------------- |
| `side`                          | [`Side`](#side)                           |
| `price_lots`                    | `i64`                                     |
| `max_base_lots`                 | `i64`                                     |
| `max_quote_lots_including_fees` | `i64`                                     |
| `client_order_id`               | `u64`                                     |
| `order_type`                    | [`PlaceOrderType`](#placeordertype)       |
| `expiry_timestamp`              | `u64`                                     |
| `self_trade_behavior`           | [`SelfTradeBehavior`](#selftradebehavior) |
| `limit`                         | `u8`                                      |

### `PlaceOrderPeggedArgs`

Struct `types::PlaceOrderPeggedArgs`.

| Field                           | Type                                      |
| ------------------------------- | ----------------------------------------- |
| `side`                          | [`Side`](#side)                           |
| `price_offset_lots`             | `i64`                                     |
| `peg_limit`                     | `i64`                                     |
| `max_base_lots`                 | `i64`                                     |
| `max_quote_lots_including_fees` | `i64`                                     |
| `client_order_id`               | `u64`                                     |
| `order_type`                    | [`PlaceOrderType`](#placeordertype)       |
| `expiry_timestamp`              | `u64`                                     |
| `self_trade_behavior`           | [`SelfTradeBehavior`](#selftradebehavior) |
| `limit`                         | `u8`                                      |

### `PlaceOrderType`

Enum `types::PlaceOrderType`.

| Variant             |
| ------------------- |
| `Limit`             |
| `ImmediateOrCancel` |
| `PostOnly`          |
| `Market`            |
| `PostOnlySlide`     |

### `PlaceTakeOrderArgs`

Struct `types::PlaceTakeOrderArgs`.

| Field                           | Type                                |
| ------------------------------- | ----------------------------------- |
| `side`                          | [`Side`](#side)                     |
| `price_lots`                    | `i64`                               |
| `max_base_lots`                 | `i64`                               |
| `max_quote_lots_including_fees` | `i64`                               |
| `order_type`                    | [`PlaceOrderType`](#placeordertype) |
| `limit`                         | `u8`                                |

### `Position`

Struct `types::Position`.

| Field                        | Type       | Description                                                                                                          |
| ---------------------------- | ---------- | -------------------------------------------------------------------------------------------------------------------- |
| `bids_base_lots`             | `i64`      | Base lots in open bids                                                                                               |
| `asks_base_lots`             | `i64`      | Base lots in open asks                                                                                               |
| `base_free_native`           | `u64`      |                                                                                                                      |
| `quote_free_native`          | `u64`      |                                                                                                                      |
| `locked_maker_fees`          | `u64`      |                                                                                                                      |
| `referrer_rebates_available` | `u64`      |                                                                                                                      |
| `penalty_heap_count`         | `u64`      | Count of ixs when events are added to the heap To avoid this, send remaining accounts in order to process the events |
| `maker_volume`               | `u128`     | Cumulative maker volume in quote native units (display only)                                                         |
| `taker_volume`               | `u128`     | Cumulative taker volume in quote native units (display only)                                                         |
| `bids_quote_lots`            | `i64`      | Quote lots in open bids                                                                                              |
| `reserved`                   | `[u8; 64]` |                                                                                                                      |

### `PostOrderType`

Enum `types::PostOrderType`.

| Variant         |
| --------------- |
| `Limit`         |
| `PostOnly`      |
| `PostOnlySlide` |

### `SelfTradeBehavior`

> _From the program's IDL:_
>
> Self trade behavior controls how taker orders interact with resting limit orders of the same account. This setting has no influence on placing a resting or oracle pegged limit order that does not match immediately, instead it's the responsibility of the user to correctly configure his taker orders.

Enum `types::SelfTradeBehavior`.

| Variant            |
| ------------------ |
| `DecrementTake`    |
| `CancelProvide`    |
| `AbortTransaction` |

### `SetDelegateLog`

Struct `types::SetDelegateLog`. Same fields as the [`SetDelegateLog`](#setdelegatelog) event.

### `SettleFundsLog`

Struct `types::SettleFundsLog`. Same fields as the [`SettleFundsLog`](#settlefundslog) event.

### `Side`

Enum `types::Side`.

| Variant |
| ------- |
| `Bid`   |
| `Ask`   |

### `SideAndOrderTree`

> _From the program's IDL:_
>
> SideAndOrderTree is a storage optimization, so we don't need two bytes for the data

Enum `types::SideAndOrderTree`.

| Variant           |
| ----------------- |
| `BidFixed`        |
| `AskFixed`        |
| `BidOraclePegged` |
| `AskOraclePegged` |

### `SweepFeesLog`

Struct `types::SweepFeesLog`. Same fields as the [`SweepFeesLog`](#sweepfeeslog) event.

### `TotalOrderFillEvent`

Struct `types::TotalOrderFillEvent`. Same fields as the [`TotalOrderFillEvent`](#totalorderfillevent) event.

---

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