carbon-openbook-v2-decoder 2.0.0

Openbook V2 Decoder
Documentation
//! This code was AUTOGENERATED using the Codama library.
use {
    crate::types::{NonZeroPubkeyOption, OracleConfig},
    solana_pubkey::Pubkey,
};

#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Debug, Clone, borsh::BorshSerialize, borsh::BorshDeserialize, PartialEq)]
pub struct Market {
    /// PDA bump
    pub bump: u8,
    /// Number of decimals used for the base token.
    /// Used to convert the oracle's price into a native/native price.
    pub base_decimals: u8,
    pub quote_decimals: u8,
    pub padding1: [u8; 5],
    pub market_authority: Pubkey,
    /// No expiry = 0. Market will expire and no trading allowed after
    /// time_expiry
    pub time_expiry: i64,
    /// Admin who can collect fees from the market
    pub collect_fee_admin: Pubkey,
    /// Admin who must sign off on all order creations
    pub open_orders_admin: NonZeroPubkeyOption,
    /// Admin who must sign off on all event consumptions
    pub consume_events_admin: NonZeroPubkeyOption,
    /// Admin who can set market expired, prune orders and close the market
    pub close_market_admin: NonZeroPubkeyOption,
    /// Name. Trailing zero bytes are ignored.
    pub name: [u8; 16],
    /// Address of the BookSide account for bids
    pub bids: Pubkey,
    /// Address of the BookSide account for asks
    pub asks: Pubkey,
    /// Address of the EventHeap account
    pub event_heap: Pubkey,
    /// Oracles account address
    pub oracle_a: NonZeroPubkeyOption,
    pub oracle_b: NonZeroPubkeyOption,
    /// Oracle configuration
    pub oracle_config: OracleConfig,
    /// 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.
    pub quote_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.
    pub base_lot_size: i64,
    /// Total number of orders seen
    pub seq_num: u64,
    /// Timestamp in seconds that the market was registered at.
    pub registration_time: 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
    pub maker_fee: i64,
    /// Fee (in 10^-6) for taker orders, always >= 0.
    pub taker_fee: i64,
    /// Total fees accrued in native quote
    pub fees_accrued: u128,
    /// Total fees settled in native quote
    pub fees_to_referrers: u128,
    /// Referrer rebates to be distributed
    pub referrer_rebates_accrued: u64,
    /// Fees generated and available to withdraw via sweep_fees
    pub fees_available: u64,
    /// Cumulative maker volume (same as taker volume) in quote native units
    pub maker_volume: u128,
    /// Cumulative taker volume in quote native units due to place take orders
    pub taker_volume_wo_oo: u128,
    pub base_mint: Pubkey,
    pub quote_mint: Pubkey,
    pub market_base_vault: Pubkey,
    pub base_deposit_total: u64,
    pub market_quote_vault: Pubkey,
    pub quote_deposit_total: u64,
    #[cfg_attr(feature = "serde", serde(with = "serde_big_array::BigArray"))]
    pub reserved: [u8; 128],
}

impl Market {
    pub fn decode(data: &[u8]) -> Option<Self> {
        if data.len() < 8 {
            return None;
        }
        let discriminator = &data[0..8];
        if discriminator != [219, 190, 213, 55, 0, 227, 198, 154] {
            return None;
        }

        let mut data_slice = data;

        data_slice = &data_slice[8..];

        borsh::BorshDeserialize::deserialize(&mut data_slice).ok()
    }
}