carbon-phoenix-v1-decoder 2.0.0

Phoenix V1 Decoder
Documentation
//! This code was AUTOGENERATED using the Codama library.
use {
    crate::types::ReduceOrderParams,
    carbon_core::{account_utils::next_account, deserialize::ArrangeAccounts},
};
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Debug, Clone, borsh::BorshSerialize, borsh::BorshDeserialize, PartialEq)]
pub struct ReduceOrderWithFreeFunds {
    pub params: ReduceOrderParams,
}

#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct ReduceOrderWithFreeFundsInstructionAccounts {
    pub phoenix_program: solana_pubkey::Pubkey,
    pub log_authority: solana_pubkey::Pubkey,
    pub market: solana_pubkey::Pubkey,
    pub trader: solana_pubkey::Pubkey,
    pub remaining: Vec<solana_instruction::AccountMeta>,
}

impl ReduceOrderWithFreeFunds {
    pub fn decode(data: &[u8]) -> Option<Self> {
        if data.is_empty() {
            return None;
        }
        let discriminator = &data[0..1];
        if discriminator != [5] {
            return None;
        }

        let mut data_slice = data;

        data_slice = &data_slice[1..];

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

impl ArrangeAccounts for ReduceOrderWithFreeFunds {
    type ArrangedAccounts = ReduceOrderWithFreeFundsInstructionAccounts;

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

        let phoenix_program = next_account(&mut iter)?;
        let log_authority = next_account(&mut iter)?;
        let market = next_account(&mut iter)?;
        let trader = next_account(&mut iter)?;

        let remaining = iter.as_slice();

        Some(ReduceOrderWithFreeFundsInstructionAccounts {
            phoenix_program,
            log_authority,
            market,
            trader,
            remaining: remaining.to_vec(),
        })
    }
}