carbon-drift-v2-decoder 1.0.0

Drift v2 Decoder
Documentation
//! This code was AUTOGENERATED using the Codama library.
use 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 EndLpSwap {
    pub in_market_index: u16,
    pub out_market_index: u16,
}

#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct EndLpSwapInstructionAccounts {
    pub state: solana_pubkey::Pubkey,
    pub admin: solana_pubkey::Pubkey,
    pub signer_out_token_account: solana_pubkey::Pubkey,
    pub signer_in_token_account: solana_pubkey::Pubkey,
    pub constituent_out_token_account: solana_pubkey::Pubkey,
    pub constituent_in_token_account: solana_pubkey::Pubkey,
    pub out_constituent: solana_pubkey::Pubkey,
    pub in_constituent: solana_pubkey::Pubkey,
    pub lp_pool: solana_pubkey::Pubkey,
    pub instructions: solana_pubkey::Pubkey,
    pub token_program: solana_pubkey::Pubkey,
    pub remaining: Vec<solana_instruction::AccountMeta>,
}

impl EndLpSwap {
    pub fn decode(data: &[u8]) -> Option<Self> {
        if data.len() < 8 {
            return None;
        }
        let discriminator = &data[0..8];
        if discriminator != [99, 125, 214, 165, 129, 175, 253, 135] {
            return None;
        }

        let mut data_slice = data;

        data_slice = &data_slice[8..];

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

impl ArrangeAccounts for EndLpSwap {
    type ArrangedAccounts = EndLpSwapInstructionAccounts;

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

        let state = next_account(&mut iter)?;
        let admin = next_account(&mut iter)?;
        let signer_out_token_account = next_account(&mut iter)?;
        let signer_in_token_account = next_account(&mut iter)?;
        let constituent_out_token_account = next_account(&mut iter)?;
        let constituent_in_token_account = next_account(&mut iter)?;
        let out_constituent = next_account(&mut iter)?;
        let in_constituent = next_account(&mut iter)?;
        let lp_pool = next_account(&mut iter)?;
        let instructions = next_account(&mut iter)?;
        let token_program = next_account(&mut iter)?;

        let remaining = iter.as_slice();

        Some(EndLpSwapInstructionAccounts {
            state,
            admin,
            signer_out_token_account,
            signer_in_token_account,
            constituent_out_token_account,
            constituent_in_token_account,
            out_constituent,
            in_constituent,
            lp_pool,
            instructions,
            token_program,
            remaining: remaining.to_vec(),
        })
    }
}