carbon-openbook-v2-decoder 2.0.0

Openbook V2 Decoder
Documentation
//! This code was AUTOGENERATED using the Codama library.
use {
    crate::types::Side,
    carbon_core::{account_utils::next_account, deserialize::ArrangeAccounts},
};
/// Cancel up to `limit` orders, optionally filtering by side
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Debug, Clone, borsh::BorshSerialize, borsh::BorshDeserialize, PartialEq)]
pub struct CancelAllOrders {
    pub side_option: Option<Side>,
    pub limit: u8,
}

#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct CancelAllOrdersInstructionAccounts {
    pub signer: solana_pubkey::Pubkey,
    pub open_orders_account: solana_pubkey::Pubkey,
    pub market: solana_pubkey::Pubkey,
    pub bids: solana_pubkey::Pubkey,
    pub asks: solana_pubkey::Pubkey,
    pub remaining: Vec<solana_instruction::AccountMeta>,
}

impl CancelAllOrders {
    pub fn decode(data: &[u8]) -> Option<Self> {
        if data.len() < 8 {
            return None;
        }
        let discriminator = &data[0..8];
        if discriminator != [196, 83, 243, 171, 17, 100, 160, 143] {
            return None;
        }

        let mut data_slice = data;

        data_slice = &data_slice[8..];

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

impl ArrangeAccounts for CancelAllOrders {
    type ArrangedAccounts = CancelAllOrdersInstructionAccounts;

    fn arrange_accounts(
        accounts: &[solana_instruction::AccountMeta],
    ) -> Option<Self::ArrangedAccounts> {
        let mut iter = accounts.iter();

        let signer = next_account(&mut iter)?;
        let open_orders_account = next_account(&mut iter)?;
        let market = next_account(&mut iter)?;
        let bids = next_account(&mut iter)?;
        let asks = next_account(&mut iter)?;

        let remaining = iter.as_slice();

        Some(CancelAllOrdersInstructionAccounts {
            signer,
            open_orders_account,
            market,
            bids,
            asks,
            remaining: remaining.to_vec(),
        })
    }
}