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.
| Crate | carbon-openbook-v2-decoder 2.0.0 |
| Install | cargo add carbon-openbook-v2-decoder@2. |
| Program ID | opnb2LAfJYbRMAHHvqjCwQxanZn7ReEHp1k81EohpZb (carbon_) |
| Category | DEX & AMM |
| Decoder | carbon_ |
| Instruction enum | instructions:: |
| Account enum | accounts:: |
| Event enum | instructions:: |
| Features | serde, postgres, graphql (none enabled by default) |
| API docs | docs.rs/carbon-openbook-v2-decoder/2.0.0 |
| Source | decoders/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:
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/fulluse {
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(())
}
}RUST_LOG=info cargo runEach 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:: (import instructions::); see Events. If CpiEvent never arrives, the program logs its events with emit! instead: decode them with decode_.
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:
cargo add carbon-rpc-program-subscribe-datasource@2.0.0 solana-client@4.2.2use {
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(())
}
}RUST_LOG=info cargo runEach 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::, where data and accounts are the types listed under the variant, exported from carbon_. 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:
- The instruction's program ID is
opnb2LAfJYbRMAHHvqjCwQxanZn7ReEHp1k81EohpZb. - The data starts with the variant's discriminator, and the rest deserializes into its data type.
- 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_ too. Accounts after the listed ones are in accounts. as AccountMetas. The decoder doesn't record whether an account signed or was writable: read that from input. and ., 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 |
bids | Vec< |
asks | Vec< |
limit | u8 |
Required accounts: 14; extras go to remaining.
Fields of CancelAllAndPlaceOrdersInstructionAccounts, in account order:
| # | Field | Type |
|---|---|---|
| 0 | signer | Pubkey |
| 1 | open_ | Pubkey |
| 2 | open_ | Option< |
| 3 | user_ | Pubkey |
| 4 | user_ | Pubkey |
| 5 | market | Pubkey |
| 6 | bids | Pubkey |
| 7 | asks | Pubkey |
| 8 | event_heap | Pubkey |
| 9 | market_ | Pubkey |
| 10 | market_ | Pubkey |
| 11 | oracle_a | Option< |
| 12 | oracle_b | Option< |
| 13 | token_ | Pubkey |
| 14… | remaining | Vec< |
CancelAllOrders#
From the program's IDL:
Cancel up to
limitorders, optionally filtering by side
Discriminator c453f3ab1164a08f · data CancelAllOrders · accounts CancelAllOrdersInstructionAccounts.
| Field | Type |
|---|---|
side_option | Option< |
limit | u8 |
Required accounts: 5; extras go to remaining.
Fields of CancelAllOrdersInstructionAccounts, in account order:
| # | Field | Type |
|---|---|---|
| 0 | signer | Pubkey |
| 1 | open_ | Pubkey |
| 2 | market | Pubkey |
| 3 | bids | Pubkey |
| 4 | asks | Pubkey |
| 5… | remaining | Vec< |
CancelOrder#
From the program's IDL:
Cancel an order by its
order_id.
Note that this doesn't emit anOutEventbecause a maker knows that they will be passing in their own
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_ | Pubkey |
| 2 | market | Pubkey |
| 3 | bids | Pubkey |
| 4 | asks | Pubkey |
| 5… | remaining | Vec< |
CancelOrderByClientOrderId#
From the program's IDL:
Cancel an order by its
client_.order_ id
Note that this doesn't emit anOutEventbecause a maker knows that they will be passing in their own
OpenOrdersAccount.
Discriminator 73b2c908afb77b77 · data CancelOrderByClientOrderId · accounts CancelOrderByClientOrderIdInstructionAccounts.
| Field | Type |
|---|---|
client_ | u64 |
Required accounts: 5; extras go to remaining.
Fields of CancelOrderByClientOrderIdInstructionAccounts, in account order:
| # | Field | Type |
|---|---|---|
| 0 | signer | Pubkey |
| 1 | open_ | Pubkey |
| 2 | market | Pubkey |
| 3 | bids | Pubkey |
| 4 | asks | Pubkey |
| 5… | remaining | Vec< |
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:
| # | Field | Type |
|---|---|---|
| 0 | close_ | Pubkey |
| 1 | market | Pubkey |
| 2 | bids | Pubkey |
| 3 | asks | Pubkey |
| 4 | event_heap | Pubkey |
| 5 | sol_ | Pubkey |
| 6 | token_ | Pubkey |
| 7… | remaining | Vec< |
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:
| # | Field | Type |
|---|---|---|
| 0 | owner | Pubkey |
| 1 | open_ | Pubkey |
| 2 | open_ | Pubkey |
| 3 | sol_ | Pubkey |
| 4 | system_ | Pubkey |
| 5… | remaining | Vec< |
CloseOpenOrdersIndexer#
From the program's IDL:
Close an
OpenOrdersIndexeraccount.
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_ | Pubkey |
| 2 | sol_ | Pubkey |
| 3 | token_ | Pubkey |
| 4… | remaining | Vec< |
ConsumeEvents#
From the program's IDL:
Process up to
limitevents.
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, whereplace_orderonly emits events, andconsume_handles token settlement.events
Currently, there are two types of events:
FillEvents andOutEvents.
AFillEventis 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. AnOutEventis emitted when a limit order needs to be removed from the book during aplace_orderinvocation, 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_ | Option< |
| 1 | market | Pubkey |
| 2 | event_heap | Pubkey |
| 3… | remaining | Vec< |
ConsumeGivenEvents#
From the program's IDL:
Process the events 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_ | Option< |
| 1 | market | Pubkey |
| 2 | event_heap | Pubkey |
| 3… | remaining | Vec< |
CreateMarket#
From the program's IDL:
Create a
Marketfor a given token pair.
Discriminator 67e261ebc8bcfbfe · data CreateMarket · accounts CreateMarketInstructionAccounts.
| Field | Type |
|---|---|
name | String |
oracle_ | OracleConfigParams |
quote_ | i64 |
base_ | 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_ | Pubkey |
| 2 | bids | Pubkey |
| 3 | asks | Pubkey |
| 4 | event_heap | Pubkey |
| 5 | payer | Pubkey |
| 6 | market_ | Pubkey |
| 7 | market_ | Pubkey |
| 8 | base_mint | Pubkey |
| 9 | quote_mint | Pubkey |
| 10 | system_ | Pubkey |
| 11 | token_ | Pubkey |
| 12 | associated_ | Pubkey |
| 13 | oracle_a | Option< |
| 14 | oracle_b | Option< |
| 15 | collect_ | Pubkey |
| 16 | open_ | Option< |
| 17 | consume_ | Option< |
| 18 | close_ | Option< |
| 19 | event_ | Pubkey |
| 20 | program | Pubkey |
| 21… | remaining | Vec< |
CreateOpenOrdersAccount#
From the program's IDL:
Create an
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_ | Option< |
| 3 | open_ | Pubkey |
| 4 | open_ | Pubkey |
| 5 | market | Pubkey |
| 6 | system_ | Pubkey |
| 7… | remaining | Vec< |
CreateOpenOrdersIndexer#
From the program's IDL:
Create an
OpenOrdersIndexeraccount.
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_ | Pubkey |
| 3 | system_ | Pubkey |
| 4… | remaining | Vec< |
Deposit#
From the program's IDL:
Deposit a certain amount of
baseandquotelamports into one's
Position.
Makers might wish todeposit, 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_ | u64 |
Required accounts: 8; extras go to remaining.
Fields of DepositInstructionAccounts, in account order:
| # | Field | Type |
|---|---|---|
| 0 | owner | Pubkey |
| 1 | user_ | Pubkey |
| 2 | user_ | Pubkey |
| 3 | open_ | Pubkey |
| 4 | market | Pubkey |
| 5 | market_ | Pubkey |
| 6 | market_ | Pubkey |
| 7 | token_ | Pubkey |
| 8… | remaining | Vec< |
EditOrder#
From the program's IDL:
Edit an order.
Discriminator fed0761dadf8c846 · data EditOrder · accounts EditOrderInstructionAccounts.
| Field | Type |
|---|---|
client_ | u64 |
expected_ | i64 |
place_order | PlaceOrderArgs |
Required accounts: 12; extras go to remaining.
Fields of EditOrderInstructionAccounts, in account order:
| # | Field | Type |
|---|---|---|
| 0 | signer | Pubkey |
| 1 | open_ | Pubkey |
| 2 | open_ | Option< |
| 3 | user_ | Pubkey |
| 4 | market | Pubkey |
| 5 | bids | Pubkey |
| 6 | asks | Pubkey |
| 7 | event_heap | Pubkey |
| 8 | market_ | Pubkey |
| 9 | oracle_a | Option< |
| 10 | oracle_b | Option< |
| 11 | token_ | Pubkey |
| 12… | remaining | Vec< |
EditOrderPegged#
From the program's IDL:
Edit an order pegged.
Discriminator 3ebb7d451add9d85 · data EditOrderPegged · accounts EditOrderPeggedInstructionAccounts.
| Field | Type |
|---|---|
client_ | u64 |
expected_ | i64 |
place_order | PlaceOrderPeggedArgs |
Required accounts: 12; extras go to remaining.
Fields of EditOrderPeggedInstructionAccounts, in account order:
| # | Field | Type |
|---|---|---|
| 0 | signer | Pubkey |
| 1 | open_ | Pubkey |
| 2 | open_ | Option< |
| 3 | user_ | Pubkey |
| 4 | market | Pubkey |
| 5 | bids | Pubkey |
| 6 | asks | Pubkey |
| 7 | event_heap | Pubkey |
| 8 | market_ | Pubkey |
| 9 | oracle_a | Option< |
| 10 | oracle_b | Option< |
| 11 | token_ | Pubkey |
| 12… | remaining | Vec< |
PlaceOrder#
From the program's IDL:
Place an order.
Different types of orders have different effects on the order book, as described inPlaceOrderType.
price_lotsrefers to the price in lots: the number of quote lots per base lot. It is ignored forPlaceOrderType::orders.Market
expiry_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.timestamp
limitdetermines 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 |
Required accounts: 12; extras go to remaining.
Fields of PlaceOrderInstructionAccounts, in account order:
| # | Field | Type |
|---|---|---|
| 0 | signer | Pubkey |
| 1 | open_ | Pubkey |
| 2 | open_ | Option< |
| 3 | user_ | Pubkey |
| 4 | market | Pubkey |
| 5 | bids | Pubkey |
| 6 | asks | Pubkey |
| 7 | event_heap | Pubkey |
| 8 | market_ | Pubkey |
| 9 | oracle_a | Option< |
| 10 | oracle_b | Option< |
| 11 | token_ | Pubkey |
| 12… | remaining | Vec< |
PlaceOrderPegged#
From the program's IDL:
Place an oracle-peg order.
Discriminator 8db9fb3f4a55d291 · data PlaceOrderPegged · accounts PlaceOrderPeggedInstructionAccounts.
| Field | Type |
|---|---|
args | PlaceOrderPeggedArgs |
Required accounts: 12; extras go to remaining.
Fields of PlaceOrderPeggedInstructionAccounts, in account order:
| # | Field | Type |
|---|---|---|
| 0 | signer | Pubkey |
| 1 | open_ | Pubkey |
| 2 | open_ | Option< |
| 3 | user_ | Pubkey |
| 4 | market | Pubkey |
| 5 | bids | Pubkey |
| 6 | asks | Pubkey |
| 7 | event_heap | Pubkey |
| 8 | market_ | Pubkey |
| 9 | oracle_a | Option< |
| 10 | oracle_b | Option< |
| 11 | token_ | Pubkey |
| 12… | remaining | Vec< |
PlaceOrders#
From the program's IDL:
Place multiple orders
Discriminator 3c3f327b0cc53cbe · data PlaceOrders · accounts PlaceOrdersInstructionAccounts.
| Field | Type |
|---|---|
orders_type | PlaceOrderType |
bids | Vec< |
asks | Vec< |
limit | u8 |
Required accounts: 14; extras go to remaining.
Fields of PlaceOrdersInstructionAccounts, in account order:
| # | Field | Type |
|---|---|---|
| 0 | signer | Pubkey |
| 1 | open_ | Pubkey |
| 2 | open_ | Option< |
| 3 | user_ | Pubkey |
| 4 | user_ | Pubkey |
| 5 | market | Pubkey |
| 6 | bids | Pubkey |
| 7 | asks | Pubkey |
| 8 | event_heap | Pubkey |
| 9 | market_ | Pubkey |
| 10 | market_ | Pubkey |
| 11 | oracle_a | Option< |
| 12 | oracle_b | Option< |
| 13 | token_ | Pubkey |
| 14… | remaining | Vec< |
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 |
Required accounts: 15 (16 listed); extras go to remaining.
Fields of PlaceTakeOrderInstructionAccounts, in account order:
| # | Field | Type |
|---|---|---|
| 0 | signer | Pubkey |
| 1 | penalty_ | Pubkey |
| 2 | market | Pubkey |
| 3 | market_ | Pubkey |
| 4 | bids | Pubkey |
| 5 | asks | Pubkey |
| 6 | market_ | Pubkey |
| 7 | market_ | Pubkey |
| 8 | event_heap | Pubkey |
| 9 | user_ | Pubkey |
| 10 | user_ | Pubkey |
| 11 | oracle_a | Option< |
| 12 | oracle_b | Option< |
| 13 | token_ | Pubkey |
| 14 | system_ | Pubkey |
| 15 | open_ | Option< |
| 16… | remaining | Vec< |
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.
| Field | Type |
|---|---|
limit | u8 |
Required accounts: 5; extras go to remaining.
Fields of PruneOrdersInstructionAccounts, in account order:
| # | Field | Type |
|---|---|---|
| 0 | close_ | Pubkey |
| 1 | open_ | Pubkey |
| 2 | market | Pubkey |
| 3 | bids | Pubkey |
| 4 | asks | Pubkey |
| 5… | remaining | Vec< |
Refill#
From the program's IDL:
Refill a certain amount of
baseandquotelamports. The amount being passed is the total lamports that thePositionwill have. Makers might wish torefill, 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_ | u64 |
Required accounts: 8; extras go to remaining.
Fields of RefillInstructionAccounts, in account order:
| # | Field | Type |
|---|---|---|
| 0 | owner | Pubkey |
| 1 | user_ | Pubkey |
| 2 | user_ | Pubkey |
| 3 | open_ | Pubkey |
| 4 | market | Pubkey |
| 5 | market_ | Pubkey |
| 6 | market_ | Pubkey |
| 7 | token_ | Pubkey |
| 8… | remaining | Vec< |
SetDelegate#
From the program's IDL:
Update the
delegateof 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_ | Pubkey |
| 2 | delegate_ | Option< |
| 3… | remaining | Vec< |
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:
| # | Field | Type |
|---|---|---|
| 0 | close_ | Pubkey |
| 1 | market | Pubkey |
| 2… | remaining | Vec< |
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_ | Pubkey |
| 2 | open_ | Pubkey |
| 3 | market | Pubkey |
| 4 | market_ | Pubkey |
| 5 | market_ | Pubkey |
| 6 | market_ | Pubkey |
| 7 | user_ | Pubkey |
| 8 | user_ | Pubkey |
| 9 | referrer_ | Option< |
| 10 | token_ | Pubkey |
| 11 | system_ | Pubkey |
| 12… | remaining | Vec< |
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:
| # | Field | Type |
|---|---|---|
| 0 | close_ | Pubkey |
| 1 | owner | Pubkey |
| 2 | penalty_ | Pubkey |
| 3 | open_ | Pubkey |
| 4 | market | Pubkey |
| 5 | market_ | Pubkey |
| 6 | market_ | Pubkey |
| 7 | market_ | Pubkey |
| 8 | user_ | Pubkey |
| 9 | user_ | Pubkey |
| 10 | referrer_ | Option< |
| 11 | token_ | Pubkey |
| 12 | system_ | Pubkey |
| 13… | remaining | Vec< |
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_ | Pubkey |
| 3 | token_ | Pubkey |
| 4… | remaining | Vec< |
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_ | Pubkey |
| 5… | remaining | Vec< |
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< |
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:
| # | Field | Type |
|---|---|---|
| 0 | collect_ | Pubkey |
| 1 | market | Pubkey |
| 2 | market_ | Pubkey |
| 3 | market_ | Pubkey |
| 4 | token_ | Pubkey |
| 5 | token_ | Pubkey |
| 6… | remaining | Vec< |
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:
| # | Field | Type |
|---|---|---|
| 0 | program | Pubkey |
| 1 | event_ | Pubkey |
| 2… | remaining | Vec< |
Accounts#
Variants of OpenbookV2Account. Each wraps a boxed struct from carbon_. decode_ only considers accounts owned by PROGRAM_ID and returns the first variant that matches.
BookSide#
Discriminator 482ce18db2826139 · accounts::.
| Field | Type |
|---|---|
roots | [OrderTreeRoot; 2] |
reserved_ | [OrderTreeRoot; 4] |
reserved | [u8; 256] |
nodes | 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::.
| Field | Type |
|---|---|
header | EventHeapHeader |
nodes | [EventNode; 600] |
reserved | [u8; 64] |
Market#
Discriminator dbbed53700e3c69a · accounts::.
| Field | Type | Description |
|---|---|---|
bump | u8 | PDA bump |
base_ | u8 | Number of decimals used for the base token. Used to convert the oracle's price into a native/native price. |
quote_ | u8 | |
padding1 | [u8; 5] | |
market_ | Pubkey | |
time_expiry | i64 | No expiry = 0. Market will expire and no trading allowed after time_expiry |
collect_ | Pubkey | Admin who can collect fees from the market |
open_ | NonZeroPubkeyOption | Admin who must sign off on all order creations |
consume_ | NonZeroPubkeyOption | Admin who must sign off on all event consumptions |
close_ | 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 | Oracles account address |
oracle_b | NonZeroPubkeyOption | |
oracle_ | OracleConfig | Oracle configuration |
quote_ | 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_ | 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_ | 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_ | u128 | Total fees accrued in native quote |
fees_ | u128 | Total fees settled in native quote |
referrer_ | u64 | Referrer rebates to be distributed |
fees_ | u64 | Fees generated and available to withdraw via sweep_fees |
maker_ | u128 | Cumulative maker volume (same as taker volume) in quote native units |
taker_ | u128 | Cumulative taker volume in quote native units due to place take orders |
base_mint | Pubkey | |
quote_mint | Pubkey | |
market_ | Pubkey | |
base_ | u64 | |
market_ | Pubkey | |
quote_ | u64 | |
reserved | [u8; 128] |
OpenOrdersAccount#
Discriminator ffc24e7b1069d0a5 · accounts::.
| Field | Type |
|---|---|
owner | Pubkey |
market | Pubkey |
name | [u8; 32] |
delegate | NonZeroPubkeyOption |
account_num | u32 |
bump | u8 |
version | u8 |
padding | [u8; 2] |
position | Position |
open_orders | [OpenOrder; 24] |
OpenOrdersIndexer#
Discriminator c35380d5cc5b1396 · accounts::.
| Field | Type |
|---|---|
bump | u8 |
created_ | u32 |
addresses | Vec<Pubkey> |
StubOracle#
Discriminator e0fbfe63b1ae8904 · accounts::.
| Field | Type |
|---|---|
owner | Pubkey |
mint | Pubkey |
price | f64 |
last_ | i64 |
last_ | u64 |
deviation | f64 |
reserved | [u8; 104] |
Events#
Variants of instructions::, decoded from the CpiEvent instruction. Each wraps a struct from carbon_. The discriminator is the 8-byte event discriminator that follows the e445a52e51cb9a1d CPI-event tag.
DepositLog#
Discriminator 8dbaa8fc6c8d485e · events::.
| Field | Type |
|---|---|
open_ | Pubkey |
signer | Pubkey |
base_amount | u64 |
quote_ | u64 |
FillLog#
Discriminator 9617299498a2d740 · events::.
| Field | Type |
|---|---|
market | Pubkey |
taker_side | u8 |
maker_slot | u8 |
maker_out | bool |
timestamp | u64 |
seq_num | u64 |
maker | Pubkey |
maker_ | u64 |
maker_fee | u64 |
maker_ | u64 |
taker | Pubkey |
taker_ | u64 |
taker_ | u64 |
price | i64 |
quantity | i64 |
MarketMetaDataLog#
Discriminator d157d4eca43a3c75 · events::.
| Field | Type |
|---|---|
market | Pubkey |
name | String |
base_mint | Pubkey |
quote_mint | Pubkey |
base_ | u8 |
quote_ | u8 |
base_ | i64 |
quote_ | i64 |
TotalOrderFillEvent#
Discriminator 08eb303aae4c9c69 · events::.
| Field | Type |
|---|---|
side | u8 |
taker | Pubkey |
total_ | u64 |
total_ | u64 |
fees | u64 |
SetDelegateLog#
Discriminator 3582975c6d399170 · events::.
| Field | Type |
|---|---|
open_ | Pubkey |
delegate | Option< |
SettleFundsLog#
Discriminator 0a32f075ed43e6e9 · events::.
| Field | Type |
|---|---|
open_ | Pubkey |
base_native | u64 |
quote_ | u64 |
referrer_ | u64 |
referrer | Option< |
SweepFeesLog#
Discriminator d2f21a4d5e30ff3d · events::.
| Field | Type |
|---|---|
market | Pubkey |
amount | u64 |
receiver | Pubkey |
OpenOrdersPositionLog#
Discriminator c4f99421a8e44906 · events::.
| Field | Type |
|---|---|
owner | Pubkey |
open_ | u32 |
market | Pubkey |
bids_ | i64 |
bids_ | i64 |
asks_ | i64 |
base_ | u64 |
quote_ | u64 |
locked_ | u64 |
referrer_ | u64 |
maker_ | u128 |
taker_ | u128 |
Types#
Types used by the instructions, accounts and events above, exported from carbon_.
AnyEvent#
Struct types::.
| Field | Type |
|---|---|
event_type | u8 |
padding | [u8; 143] |
AnyNode#
Struct types::.
| Field | Type |
|---|---|
tag | u8 |
data | [u8; 87] |
BookSideOrderTree#
Enum types::.
| Variant |
|---|
Fixed |
OraclePegged |
DepositLog#
Struct types::. Same fields as the DepositLog event.
EventHeapHeader#
Struct types::.
| Field | Type |
|---|---|
free_head | u16 |
used_head | u16 |
count | u16 |
padd | u16 |
seq_num | u64 |
EventNode#
Struct types::.
| Field | Type |
|---|---|
next | u16 |
prev | u16 |
pad | [u8; 4] |
event | AnyEvent |
EventType#
Enum types::.
| Variant |
|---|
Fill |
Out |
FillEvent#
Struct types::.
| 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_ | u64 |
taker | Pubkey |
taker_ | u64 |
price | i64 |
peg_limit | i64 |
quantity | i64 |
maker_ | u64 |
reserved | [u8; 8] |
FillLog#
Struct types::. 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::.
| 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 topprefix_lenbits ofkey. The left child has a 0 in the next bit, and the right a 1.
Struct types::.
| 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:: |
child_ | [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::.
| Field | Type | Description |
|---|---|---|
tag | u8 | NodeTag |
owner_slot | u8 | Index into the owning OpenOrdersAccount's OpenOrders |
time_ | 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_ | u64 | User defined id for this order, used in FillEvents |
MarketMetaDataLog#
Struct types::. Same fields as the MarketMetaDataLog event.
NodeTag#
Enum types::.
| Variant |
|---|
Uninitialized |
InnerNode |
LeafNode |
FreeNode |
LastFreeNode |
NonZeroPubkeyOption#
From the program's IDL:
Like
Option, but implemented forPubkeyto be used withzero_copy
Struct types::.
| Field | Type |
|---|---|
key | Pubkey |
OpenOrder#
Struct types::.
| Field | Type | Description |
|---|---|---|
id | u128 | |
client_id | u64 | |
locked_ | i64 | Price at which user's assets were locked |
is_free | u8 | |
side_ | u8 | |
padding | [u8; 6] |
OpenOrdersPositionLog#
Struct types::. Same fields as the OpenOrdersPositionLog event.
OracleConfig#
Struct types::.
| Field | Type |
|---|---|
conf_filter | f64 |
max_ | i64 |
reserved | [u8; 72] |
OracleConfigParams#
Struct types::.
| Field | Type |
|---|---|
conf_filter | f32 |
max_ | Option<u32> |
OracleType#
Enum types::.
| Variant |
|---|
Pyth |
Stub |
SwitchboardV1 |
SwitchboardV2 |
RaydiumCLMM |
OrderParams#
Enum types::.
| Variant | Fields |
|---|---|
Market | |
ImmediateOrCancel | price_lots: i64 |
Fixed | price_lots: i64, order_type: PostOrderType |
OraclePegged | price_: i64, order_type: PostOrderType, peg_limit: i64 |
OrderState#
Enum types::.
| 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::.
| Field | Type |
|---|---|
order_ | u8 |
padding | [u8; 3] |
bump_index | u32 |
free_ | u32 |
free_ | u32 |
reserved | [u8; 512] |
nodes | [AnyNode; 1024] |
OrderTreeRoot#
Struct types::.
| Field | Type |
|---|---|
maybe_node | u32 |
leaf_count | u32 |
OrderTreeType#
Enum types::.
| Variant |
|---|
Bids |
Asks |
OutEvent#
Struct types::.
| 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::.
| Field | Type |
|---|---|
price_lots | i64 |
max_ | i64 |
expiry_ | u64 |
PlaceOrderArgs#
Struct types::.
| Field | Type |
|---|---|
side | Side |
price_lots | i64 |
max_ | i64 |
max_ | i64 |
client_ | u64 |
order_type | PlaceOrderType |
expiry_ | u64 |
self_ | SelfTradeBehavior |
limit | u8 |
PlaceOrderPeggedArgs#
Struct types::.
| Field | Type |
|---|---|
side | Side |
price_ | i64 |
peg_limit | i64 |
max_ | i64 |
max_ | i64 |
client_ | u64 |
order_type | PlaceOrderType |
expiry_ | u64 |
self_ | SelfTradeBehavior |
limit | u8 |
PlaceOrderType#
Enum types::.
| Variant |
|---|
Limit |
ImmediateOrCancel |
PostOnly |
Market |
PostOnlySlide |
PlaceTakeOrderArgs#
Struct types::.
| Field | Type |
|---|---|
side | Side |
price_lots | i64 |
max_ | i64 |
max_ | i64 |
order_type | PlaceOrderType |
limit | u8 |
Position#
Struct types::.
| Field | Type | Description |
|---|---|---|
bids_ | i64 | Base lots in open bids |
asks_ | i64 | Base lots in open asks |
base_ | u64 | |
quote_ | u64 | |
locked_ | u64 | |
referrer_ | u64 | |
penalty_ | u64 | Count of ixs when events are added to the heap To avoid this, send remaining accounts in order to process the events |
maker_ | u128 | Cumulative maker volume in quote native units (display only) |
taker_ | u128 | Cumulative taker volume in quote native units (display only) |
bids_ | i64 | Quote lots in open bids |
reserved | [u8; 64] |
PostOrderType#
Enum types::.
| 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::.
| Variant |
|---|
DecrementTake |
CancelProvide |
AbortTransaction |
SetDelegateLog#
Struct types::. Same fields as the SetDelegateLog event.
SettleFundsLog#
Struct types::. 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::.
| Variant |
|---|
BidFixed |
AskFixed |
BidOraclePegged |
AskOraclePegged |
SweepFeesLog#
Struct types::. Same fields as the SweepFeesLog event.
TotalOrderFillEvent#
Struct types::. Same fields as the TotalOrderFillEvent event.