OpenBook v2 decoder

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

On this page

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 for how decoders plug into a pipeline.

Cratecarbon-openbook-v2-decoder 2.0.0
Installcargo add carbon-openbook-v2-decoder@2.0.0
Program IDopnb2LAfJYbRMAHHvqjCwQxanZn7ReEHp1k81EohpZb (carbon_openbook_v2_decoder::PROGRAM_ID)
CategoryDEX & AMM
Decodercarbon_openbook_v2_decoder::OpenbookV2Decoder
Instruction enuminstructions::OpenbookV2Instruction
Account enumaccounts::OpenbookV2Account
Event enuminstructions::CpiEvent
Featuresserde, postgres, graphql (none enabled by default)
API docsdocs.rs/carbon-openbook-v2-decoder/2.0.0
Sourcedecoders/openbook-v2-decoder

Other DEX and AMM decoders: BonkSwap, FluxBeam, Gavel, Heaven, Jupiter Limit Order, Jupiter Limit Order v2, Kamino Limit Order, Lifinity AMM v2, Meteora DAMM v2, Meteora DLMM, Meteora Pools, Orca Whirlpools, PancakeSwap, Phoenix v1, PumpSwap, Raydium AMM v4, Raydium CLMM, Raydium CPMM, Raydium Stable Swap, Stabble Stable Swap, Stabble Weighted Swap. To decode several in one pipeline, see dEX and AMM decoders.

The serde feature derives Serialize/Deserialize on every type, postgres adds tables and processors for Postgres, and graphql adds a schema for the GraphQL server.

Usage#

This program crawls recent OpenBook v2 transactions from the public RPC and prints every decoded Deposit instruction. Add the dependencies:

Terminal
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
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(())
    }
}
Terminal
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 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. If CpiEvent never arrives, the program logs its events with emit! instead: decode them with decode_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:

Terminal
cargo add carbon-rpc-program-subscribe-datasource@2.0.0 solana-client@4.2.2
src/main.rs
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(())
    }
}
Terminal
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.

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

Required accounts: 14; extras go to remaining.

Fields of CancelAllAndPlaceOrdersInstructionAccounts, in account order:

#FieldType
0signerPubkey
1open_orders_accountPubkey
2open_orders_adminOption<Pubkey>
3user_quote_accountPubkey
4user_base_accountPubkey
5marketPubkey
6bidsPubkey
7asksPubkey
8event_heapPubkey
9market_quote_vaultPubkey
10market_base_vaultPubkey
11oracle_aOption<Pubkey>
12oracle_bOption<Pubkey>
13token_programPubkey
14…remainingVec<AccountMeta>

CancelAllOrders#

From the program's IDL:

Cancel up to limit orders, optionally filtering by side

Discriminator c453f3ab1164a08f · data CancelAllOrders · accounts CancelAllOrdersInstructionAccounts.

FieldType
side_optionOption<Side>
limitu8

Required accounts: 5; extras go to remaining.

Fields of CancelAllOrdersInstructionAccounts, in account order:

#FieldType
0signerPubkey
1open_orders_accountPubkey
2marketPubkey
3bidsPubkey
4asksPubkey
5…remainingVec<AccountMeta>

CancelOrder#

From the program's IDL:

Cancel an order by its order_id.
Note that this doesn't emit an OutEvent because a maker knows that they will be passing in their own
OpenOrdersAccount.

Discriminator 5f81edf00831df84 · data CancelOrder · accounts CancelOrderInstructionAccounts.

FieldType
order_idu128

Required accounts: 5; extras go to remaining.

Fields of CancelOrderInstructionAccounts, in account order:

#FieldType
0signerPubkey
1open_orders_accountPubkey
2marketPubkey
3bidsPubkey
4asksPubkey
5…remainingVec<AccountMeta>

CancelOrderByClientOrderId#

From the program's IDL:

Cancel an order by its client_order_id.
Note that this doesn't emit an OutEvent because a maker knows that they will be passing in their own
OpenOrdersAccount.

Discriminator 73b2c908afb77b77 · data CancelOrderByClientOrderId · accounts CancelOrderByClientOrderIdInstructionAccounts.

FieldType
client_order_idu64

Required accounts: 5; extras go to remaining.

Fields of CancelOrderByClientOrderIdInstructionAccounts, in account order:

#FieldType
0signerPubkey
1open_orders_accountPubkey
2marketPubkey
3bidsPubkey
4asksPubkey
5…remainingVec<AccountMeta>

CloseMarket#

From the program's IDL:

Close a Market (only
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:

#FieldType
0close_market_adminPubkey
1marketPubkey
2bidsPubkey
3asksPubkey
4event_heapPubkey
5sol_destinationPubkey
6token_programPubkey
7…remainingVec<AccountMeta>

CloseOpenOrdersAccount#

From the program's IDL:

Close an OpenOrdersAccount.

Discriminator b04a73d236b35b67 · data CloseOpenOrdersAccount · accounts CloseOpenOrdersAccountInstructionAccounts.

No data fields.

Required accounts: 5; extras go to remaining.

Fields of CloseOpenOrdersAccountInstructionAccounts, in account order:

#FieldType
0ownerPubkey
1open_orders_indexerPubkey
2open_orders_accountPubkey
3sol_destinationPubkey
4system_programPubkey
5…remainingVec<AccountMeta>

CloseOpenOrdersIndexer#

From the program's IDL:

Close an OpenOrdersIndexer account.

Discriminator 67f9e5e7f7fdc588 · data CloseOpenOrdersIndexer · accounts CloseOpenOrdersIndexerInstructionAccounts.

No data fields.

Required accounts: 4; extras go to remaining.

Fields of CloseOpenOrdersIndexerInstructionAccounts, in account order:

#FieldType
0ownerPubkey
1open_orders_indexerPubkey
2sol_destinationPubkey
3token_programPubkey
4…remainingVec<AccountMeta>

ConsumeEvents#

From the program's IDL:

Process up to limit events.
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, 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:
FillEvents and OutEvents.
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. 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.

FieldType
limitu64

Required accounts: 3; extras go to remaining.

Fields of ConsumeEventsInstructionAccounts, in account order:

#FieldType
0consume_events_adminOption<Pubkey>
1marketPubkey
2event_heapPubkey
3…remainingVec<AccountMeta>

ConsumeGivenEvents#

From the program's IDL:

Process the events at the given positions.

Discriminator d1e336046dac2947 · data ConsumeGivenEvents · accounts ConsumeGivenEventsInstructionAccounts.

FieldType
slotsVec<u64>

Required accounts: 3; extras go to remaining.

Fields of ConsumeGivenEventsInstructionAccounts, in account order:

#FieldType
0consume_events_adminOption<Pubkey>
1marketPubkey
2event_heapPubkey
3…remainingVec<AccountMeta>

CreateMarket#

From the program's IDL:

Create a Market for a given token pair.

Discriminator 67e261ebc8bcfbfe · data CreateMarket · accounts CreateMarketInstructionAccounts.

FieldType
nameString
oracle_configOracleConfigParams
quote_lot_sizei64
base_lot_sizei64
maker_feei64
taker_feei64
time_expiryi64

Required accounts: 21; extras go to remaining.

Fields of CreateMarketInstructionAccounts, in account order:

#FieldType
0marketPubkey
1market_authorityPubkey
2bidsPubkey
3asksPubkey
4event_heapPubkey
5payerPubkey
6market_base_vaultPubkey
7market_quote_vaultPubkey
8base_mintPubkey
9quote_mintPubkey
10system_programPubkey
11token_programPubkey
12associated_token_programPubkey
13oracle_aOption<Pubkey>
14oracle_bOption<Pubkey>
15collect_fee_adminPubkey
16open_orders_adminOption<Pubkey>
17consume_events_adminOption<Pubkey>
18close_market_adminOption<Pubkey>
19event_authorityPubkey
20programPubkey
21…remainingVec<AccountMeta>

CreateOpenOrdersAccount#

From the program's IDL:

Create an OpenOrdersAccount.

Discriminator ccb5afde287dbc47 · data CreateOpenOrdersAccount · accounts CreateOpenOrdersAccountInstructionAccounts.

FieldType
nameString

Required accounts: 7; extras go to remaining.

Fields of CreateOpenOrdersAccountInstructionAccounts, in account order:

#FieldType
0payerPubkey
1ownerPubkey
2delegate_accountOption<Pubkey>
3open_orders_indexerPubkey
4open_orders_accountPubkey
5marketPubkey
6system_programPubkey
7…remainingVec<AccountMeta>

CreateOpenOrdersIndexer#

From the program's IDL:

Create an OpenOrdersIndexer account.

Discriminator 404099ffd947f985 · data CreateOpenOrdersIndexer · accounts CreateOpenOrdersIndexerInstructionAccounts.

No data fields.

Required accounts: 4; extras go to remaining.

Fields of CreateOpenOrdersIndexerInstructionAccounts, in account order:

#FieldType
0payerPubkey
1ownerPubkey
2open_orders_indexerPubkey
3system_programPubkey
4…remainingVec<AccountMeta>

Deposit#

From the program's IDL:

Deposit a certain amount of base and quote lamports into one's
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.

FieldType
base_amountu64
quote_amountu64

Required accounts: 8; extras go to remaining.

Fields of DepositInstructionAccounts, in account order:

#FieldType
0ownerPubkey
1user_base_accountPubkey
2user_quote_accountPubkey
3open_orders_accountPubkey
4marketPubkey
5market_base_vaultPubkey
6market_quote_vaultPubkey
7token_programPubkey
8…remainingVec<AccountMeta>

EditOrder#

From the program's IDL:

Edit an order.

Discriminator fed0761dadf8c846 · data EditOrder · accounts EditOrderInstructionAccounts.

FieldType
client_order_idu64
expected_cancel_sizei64
place_orderPlaceOrderArgs

Required accounts: 12; extras go to remaining.

Fields of EditOrderInstructionAccounts, in account order:

#FieldType
0signerPubkey
1open_orders_accountPubkey
2open_orders_adminOption<Pubkey>
3user_token_accountPubkey
4marketPubkey
5bidsPubkey
6asksPubkey
7event_heapPubkey
8market_vaultPubkey
9oracle_aOption<Pubkey>
10oracle_bOption<Pubkey>
11token_programPubkey
12…remainingVec<AccountMeta>

EditOrderPegged#

From the program's IDL:

Edit an order pegged.

Discriminator 3ebb7d451add9d85 · data EditOrderPegged · accounts EditOrderPeggedInstructionAccounts.

FieldType
client_order_idu64
expected_cancel_sizei64
place_orderPlaceOrderPeggedArgs

Required accounts: 12; extras go to remaining.

Fields of EditOrderPeggedInstructionAccounts, in account order:

#FieldType
0signerPubkey
1open_orders_accountPubkey
2open_orders_adminOption<Pubkey>
3user_token_accountPubkey
4marketPubkey
5bidsPubkey
6asksPubkey
7event_heapPubkey
8market_vaultPubkey
9oracle_aOption<Pubkey>
10oracle_bOption<Pubkey>
11token_programPubkey
12…remainingVec<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.
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.

FieldType
argsPlaceOrderArgs

Required accounts: 12; extras go to remaining.

Fields of PlaceOrderInstructionAccounts, in account order:

#FieldType
0signerPubkey
1open_orders_accountPubkey
2open_orders_adminOption<Pubkey>
3user_token_accountPubkey
4marketPubkey
5bidsPubkey
6asksPubkey
7event_heapPubkey
8market_vaultPubkey
9oracle_aOption<Pubkey>
10oracle_bOption<Pubkey>
11token_programPubkey
12…remainingVec<AccountMeta>

PlaceOrderPegged#

From the program's IDL:

Place an oracle-peg order.

Discriminator 8db9fb3f4a55d291 · data PlaceOrderPegged · accounts PlaceOrderPeggedInstructionAccounts.

Required accounts: 12; extras go to remaining.

Fields of PlaceOrderPeggedInstructionAccounts, in account order:

#FieldType
0signerPubkey
1open_orders_accountPubkey
2open_orders_adminOption<Pubkey>
3user_token_accountPubkey
4marketPubkey
5bidsPubkey
6asksPubkey
7event_heapPubkey
8market_vaultPubkey
9oracle_aOption<Pubkey>
10oracle_bOption<Pubkey>
11token_programPubkey
12…remainingVec<AccountMeta>

PlaceOrders#

From the program's IDL:

Place multiple orders

Discriminator 3c3f327b0cc53cbe · data PlaceOrders · accounts PlaceOrdersInstructionAccounts.

Required accounts: 14; extras go to remaining.

Fields of PlaceOrdersInstructionAccounts, in account order:

#FieldType
0signerPubkey
1open_orders_accountPubkey
2open_orders_adminOption<Pubkey>
3user_quote_accountPubkey
4user_base_accountPubkey
5marketPubkey
6bidsPubkey
7asksPubkey
8event_heapPubkey
9market_quote_vaultPubkey
10market_base_vaultPubkey
11oracle_aOption<Pubkey>
12oracle_bOption<Pubkey>
13token_programPubkey
14…remainingVec<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.

FieldType
argsPlaceTakeOrderArgs

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

Fields of PlaceTakeOrderInstructionAccounts, in account order:

#FieldType
0signerPubkey
1penalty_payerPubkey
2marketPubkey
3market_authorityPubkey
4bidsPubkey
5asksPubkey
6market_base_vaultPubkey
7market_quote_vaultPubkey
8event_heapPubkey
9user_base_accountPubkey
10user_quote_accountPubkey
11oracle_aOption<Pubkey>
12oracle_bOption<Pubkey>
13token_programPubkey
14system_programPubkey
15open_orders_adminOption<Pubkey>
16…remainingVec<AccountMeta>

PruneOrders#

From the program's IDL:

Remove orders from the book when the market is expired (only
close_market_admin).

Discriminator 1bd59fbf0c747079 · data PruneOrders · accounts PruneOrdersInstructionAccounts.

FieldType
limitu8

Required accounts: 5; extras go to remaining.

Fields of PruneOrdersInstructionAccounts, in account order:

#FieldType
0close_market_adminPubkey
1open_orders_accountPubkey
2marketPubkey
3bidsPubkey
4asksPubkey
5…remainingVec<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 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.

FieldType
base_amountu64
quote_amountu64

Required accounts: 8; extras go to remaining.

Fields of RefillInstructionAccounts, in account order:

#FieldType
0ownerPubkey
1user_base_accountPubkey
2user_quote_accountPubkey
3open_orders_accountPubkey
4marketPubkey
5market_base_vaultPubkey
6market_quote_vaultPubkey
7token_programPubkey
8…remainingVec<AccountMeta>

SetDelegate#

From the program's IDL:

Update the 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:

#FieldType
0ownerPubkey
1open_orders_accountPubkey
2delegate_accountOption<Pubkey>
3…remainingVec<AccountMeta>

SetMarketExpired#

From the program's IDL:

Set market to expired before pruning orders and closing the market (only
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:

#FieldType
0close_market_adminPubkey
1marketPubkey
2…remainingVec<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:

#FieldType
0ownerPubkey
1penalty_payerPubkey
2open_orders_accountPubkey
3marketPubkey
4market_authorityPubkey
5market_base_vaultPubkey
6market_quote_vaultPubkey
7user_base_accountPubkey
8user_quote_accountPubkey
9referrer_accountOption<Pubkey>
10token_programPubkey
11system_programPubkey
12…remainingVec<AccountMeta>

SettleFundsExpired#

From the program's IDL:

Withdraw any available tokens when the market is expired (only
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:

#FieldType
0close_market_adminPubkey
1ownerPubkey
2penalty_payerPubkey
3open_orders_accountPubkey
4marketPubkey
5market_authorityPubkey
6market_base_vaultPubkey
7market_quote_vaultPubkey
8user_base_accountPubkey
9user_quote_accountPubkey
10referrer_accountOption<Pubkey>
11token_programPubkey
12system_programPubkey
13…remainingVec<AccountMeta>

StubOracleClose#

Discriminator 5c892d032d3c75e0 · data StubOracleClose · accounts StubOracleCloseInstructionAccounts.

No data fields.

Required accounts: 4; extras go to remaining.

Fields of StubOracleCloseInstructionAccounts, in account order:

#FieldType
0ownerPubkey
1oraclePubkey
2sol_destinationPubkey
3token_programPubkey
4…remainingVec<AccountMeta>

StubOracleCreate#

Discriminator ac3f65538d4cc7d8 · data StubOracleCreate · accounts StubOracleCreateInstructionAccounts.

FieldType
pricef64

Required accounts: 5; extras go to remaining.

Fields of StubOracleCreateInstructionAccounts, in account order:

#FieldType
0payerPubkey
1ownerPubkey
2oraclePubkey
3mintPubkey
4system_programPubkey
5…remainingVec<AccountMeta>

StubOracleSet#

Discriminator 6dc64f7941caa18e · data StubOracleSet · accounts StubOracleSetInstructionAccounts.

FieldType
pricef64

Required accounts: 2; extras go to remaining.

Fields of StubOracleSetInstructionAccounts, in account order:

#FieldType
0ownerPubkey
1oraclePubkey
2…remainingVec<AccountMeta>

SweepFees#

From the program's IDL:

Sweep fees, as a 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:

#FieldType
0collect_fee_adminPubkey
1marketPubkey
2market_authorityPubkey
3market_quote_vaultPubkey
4token_receiver_accountPubkey
5token_programPubkey
6…remainingVec<AccountMeta>

CpiEvent#

Anchor self-CPI that carries one of the program's 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:

#FieldType
0programPubkey
1event_authorityPubkey
2…remainingVec<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.

FieldType
roots[OrderTreeRoot; 2]
reserved_roots[OrderTreeRoot; 4]
reserved[u8; 256]
nodesOrderTreeNodes

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.

FieldType
headerEventHeapHeader
nodes[EventNode; 600]
reserved[u8; 64]

Market#

Discriminator dbbed53700e3c69a · accounts::market::Market.

FieldTypeDescription
bumpu8PDA bump
base_decimalsu8Number of decimals used for the base token. Used to convert the oracle's price into a native/native price.
quote_decimalsu8
padding1[u8; 5]
market_authorityPubkey
time_expiryi64No expiry = 0. Market will expire and no trading allowed after time_expiry
collect_fee_adminPubkeyAdmin who can collect fees from the market
open_orders_adminNonZeroPubkeyOptionAdmin who must sign off on all order creations
consume_events_adminNonZeroPubkeyOptionAdmin who must sign off on all event consumptions
close_market_adminNonZeroPubkeyOptionAdmin who can set market expired, prune orders and close the market
name[u8; 16]Name. Trailing zero bytes are ignored.
bidsPubkeyAddress of the BookSide account for bids
asksPubkeyAddress of the BookSide account for asks
event_heapPubkeyAddress of the EventHeap account
oracle_aNonZeroPubkeyOptionOracles account address
oracle_bNonZeroPubkeyOption
oracle_configOracleConfigOracle configuration
quote_lot_sizei64Number 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_sizei64Number 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_numu64Total number of orders seen
registration_timei64Timestamp in seconds that the market was registered at.
maker_feei64Fees 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_feei64Fee (in 10^-6) for taker orders, always >= 0.
fees_accruedu128Total fees accrued in native quote
fees_to_referrersu128Total fees settled in native quote
referrer_rebates_accruedu64Referrer rebates to be distributed
fees_availableu64Fees generated and available to withdraw via sweep_fees
maker_volumeu128Cumulative maker volume (same as taker volume) in quote native units
taker_volume_wo_oou128Cumulative taker volume in quote native units due to place take orders
base_mintPubkey
quote_mintPubkey
market_base_vaultPubkey
base_deposit_totalu64
market_quote_vaultPubkey
quote_deposit_totalu64
reserved[u8; 128]

OpenOrdersAccount#

Discriminator ffc24e7b1069d0a5 · accounts::open_orders_account::OpenOrdersAccount.

FieldType
ownerPubkey
marketPubkey
name[u8; 32]
delegateNonZeroPubkeyOption
account_numu32
bumpu8
versionu8
padding[u8; 2]
positionPosition
open_orders[OpenOrder; 24]

OpenOrdersIndexer#

Discriminator c35380d5cc5b1396 · accounts::open_orders_indexer::OpenOrdersIndexer.

FieldType
bumpu8
created_counteru32
addressesVec<Pubkey>

StubOracle#

Discriminator e0fbfe63b1ae8904 · accounts::stub_oracle::StubOracle.

FieldType
ownerPubkey
mintPubkey
pricef64
last_update_tsi64
last_update_slotu64
deviationf64
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.

FieldType
open_orders_accountPubkey
signerPubkey
base_amountu64
quote_amountu64

FillLog#

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

FieldType
marketPubkey
taker_sideu8
maker_slotu8
maker_outbool
timestampu64
seq_numu64
makerPubkey
maker_client_order_idu64
maker_feeu64
maker_timestampu64
takerPubkey
taker_client_order_idu64
taker_fee_ceilu64
pricei64
quantityi64

MarketMetaDataLog#

Discriminator d157d4eca43a3c75 · events::market_meta_data_log::MarketMetaDataLogEvent.

FieldType
marketPubkey
nameString
base_mintPubkey
quote_mintPubkey
base_decimalsu8
quote_decimalsu8
base_lot_sizei64
quote_lot_sizei64

TotalOrderFillEvent#

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

FieldType
sideu8
takerPubkey
total_quantity_paidu64
total_quantity_receivedu64
feesu64

SetDelegateLog#

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

FieldType
open_orders_accountPubkey
delegateOption<Pubkey>

SettleFundsLog#

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

FieldType
open_orders_accountPubkey
base_nativeu64
quote_nativeu64
referrer_rebateu64
referrerOption<Pubkey>

SweepFeesLog#

Discriminator d2f21a4d5e30ff3d · events::sweep_fees_log::SweepFeesLogEvent.

FieldType
marketPubkey
amountu64
receiverPubkey

OpenOrdersPositionLog#

Discriminator c4f99421a8e44906 · events::open_orders_position_log::OpenOrdersPositionLogEvent.

FieldType
ownerPubkey
open_orders_account_numu32
marketPubkey
bids_base_lotsi64
bids_quote_lotsi64
asks_base_lotsi64
base_free_nativeu64
quote_free_nativeu64
locked_maker_feesu64
referrer_rebates_availableu64
maker_volumeu128
taker_volumeu128

Types#

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

AnyEvent#

Struct types::AnyEvent.

FieldType
event_typeu8
padding[u8; 143]

AnyNode#

Struct types::AnyNode.

FieldType
tagu8
data[u8; 87]

BookSideOrderTree#

Enum types::BookSideOrderTree.

Variant
Fixed
OraclePegged

DepositLog#

Struct types::DepositLog. Same fields as the DepositLog event.

EventHeapHeader#

Struct types::EventHeapHeader.

FieldType
free_headu16
used_headu16
countu16
paddu16
seq_numu64

EventNode#

Struct types::EventNode.

FieldType
nextu16
prevu16
pad[u8; 4]
eventAnyEvent

EventType#

Enum types::EventType.

Variant
Fill
Out

FillEvent#

Struct types::FillEvent.

FieldType
event_typeu8
taker_sideu8
maker_outu8
maker_slotu8
padding[u8; 4]
timestampu64
seq_numu64
makerPubkey
maker_timestampu64
takerPubkey
taker_client_order_idu64
pricei64
peg_limiti64
quantityi64
maker_client_order_idu64
reserved[u8; 8]

FillLog#

Struct types::FillLog. Same fields as the 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.

FieldType
vali128

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.

FieldTypeDescription
tagu8
padding[u8; 3]
prefix_lenu32number 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
keyu128only 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.

FieldTypeDescription
tagu8NodeTag
owner_slotu8Index into the owning OpenOrdersAccount's OpenOrders
time_in_forceu16Time in seconds after timestamp at which the order expires. A value of 0 means no expiry.
padding[u8; 4]
keyu128The binary tree key, see new_node_key()
ownerPubkeyAddress of the owning OpenOrdersAccount
quantityi64Number of base lots to buy or sell, always >=1
timestampu64The time the order was placed
peg_limiti64If 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_idu64User defined id for this order, used in FillEvents

MarketMetaDataLog#

Struct types::MarketMetaDataLog. Same fields as the 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.

FieldType
keyPubkey

OpenOrder#

Struct types::OpenOrder.

FieldTypeDescription
idu128
client_idu64
locked_pricei64Price at which user's assets were locked
is_freeu8
side_and_treeu8
padding[u8; 6]

OpenOrdersPositionLog#

Struct types::OpenOrdersPositionLog. Same fields as the OpenOrdersPositionLog event.

OracleConfig#

Struct types::OracleConfig.

FieldType
conf_filterf64
max_staleness_slotsi64
reserved[u8; 72]

OracleConfigParams#

Struct types::OracleConfigParams.

FieldType
conf_filterf32
max_staleness_slotsOption<u32>

OracleType#

Enum types::OracleType.

Variant
Pyth
Stub
SwitchboardV1
SwitchboardV2
RaydiumCLMM

OrderParams#

Enum types::OrderParams.

VariantFields
Market
ImmediateOrCancelprice_lots: i64
Fixedprice_lots: i64, order_type: PostOrderType
OraclePeggedprice_offset_lots: i64, order_type: 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.

FieldType
order_tree_typeu8
padding[u8; 3]
bump_indexu32
free_list_lenu32
free_list_headu32
reserved[u8; 512]
nodes[AnyNode; 1024]

OrderTreeRoot#

Struct types::OrderTreeRoot.

FieldType
maybe_nodeu32
leaf_countu32

OrderTreeType#

Enum types::OrderTreeType.

Variant
Bids
Asks

OutEvent#

Struct types::OutEvent.

FieldType
event_typeu8
sideu8
owner_slotu8
padding0[u8; 5]
timestampu64
seq_numu64
ownerPubkey
quantityi64
padding1[u8; 80]

PlaceMultipleOrdersArgs#

Struct types::PlaceMultipleOrdersArgs.

FieldType
price_lotsi64
max_quote_lots_including_feesi64
expiry_timestampu64

PlaceOrderArgs#

Struct types::PlaceOrderArgs.

FieldType
sideSide
price_lotsi64
max_base_lotsi64
max_quote_lots_including_feesi64
client_order_idu64
order_typePlaceOrderType
expiry_timestampu64
self_trade_behaviorSelfTradeBehavior
limitu8

PlaceOrderPeggedArgs#

Struct types::PlaceOrderPeggedArgs.

FieldType
sideSide
price_offset_lotsi64
peg_limiti64
max_base_lotsi64
max_quote_lots_including_feesi64
client_order_idu64
order_typePlaceOrderType
expiry_timestampu64
self_trade_behaviorSelfTradeBehavior
limitu8

PlaceOrderType#

Enum types::PlaceOrderType.

Variant
Limit
ImmediateOrCancel
PostOnly
Market
PostOnlySlide

PlaceTakeOrderArgs#

Struct types::PlaceTakeOrderArgs.

FieldType
sideSide
price_lotsi64
max_base_lotsi64
max_quote_lots_including_feesi64
order_typePlaceOrderType
limitu8

Position#

Struct types::Position.

FieldTypeDescription
bids_base_lotsi64Base lots in open bids
asks_base_lotsi64Base lots in open asks
base_free_nativeu64
quote_free_nativeu64
locked_maker_feesu64
referrer_rebates_availableu64
penalty_heap_countu64Count of ixs when events are added to the heap To avoid this, send remaining accounts in order to process the events
maker_volumeu128Cumulative maker volume in quote native units (display only)
taker_volumeu128Cumulative taker volume in quote native units (display only)
bids_quote_lotsi64Quote 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 event.

SettleFundsLog#

Struct types::SettleFundsLog. Same fields as the 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 event.

TotalOrderFillEvent#

Struct types::TotalOrderFillEvent. Same fields as the TotalOrderFillEvent event.

Generated from the crate’s source at Carbon v2.0.0, so it always matches the published code. Spotted a problem? Report it; edits to this page itself are overwritten on the next release.

Your endpoints

Code samples use these instead of the placeholders, so you can copy and run them as they are. They’re stored only in this browser and never sent anywhere.