carbon-openbook-v2-decoder 2.0.0

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

#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Debug, Clone, borsh::BorshSerialize, borsh::BorshDeserialize, PartialEq)]
pub struct OpenOrdersAccount {
    pub owner: Pubkey,
    pub market: Pubkey,
    pub name: [u8; 32],
    pub delegate: NonZeroPubkeyOption,
    pub account_num: u32,
    pub bump: u8,
    pub version: u8,
    pub padding: [u8; 2],
    pub position: Position,
    pub open_orders: [OpenOrder; 24],
}

impl OpenOrdersAccount {
    pub fn decode(data: &[u8]) -> Option<Self> {
        if data.len() < 8 {
            return None;
        }
        let discriminator = &data[0..8];
        if discriminator != [255, 194, 78, 123, 16, 105, 208, 165] {
            return None;
        }

        let mut data_slice = data;

        data_slice = &data_slice[8..];

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