carbon-marginfi-v2-decoder 1.0.0

MarginfiV2 Decoder
Documentation
//! This code was AUTOGENERATED using the Codama library.
use carbon_core::{account_utils::next_account, deserialize::ArrangeAccounts};
/// The same as `marginfi_account_initialize`, except the created marginfi
/// account uses a PDA (Program Derived Address)
/// seeds:
/// - marginfi_group
/// - authority: The account authority (owner)
/// - account_index: A u16 value to allow multiple accounts per authority
/// - third_party_id: Optional u16 for third-party tagging. Seeds <
///   PDA_FREE_THRESHOLD can be
///
/// used freely. For a dedicated seed used by just your program (via CPI),
/// contact us.
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Debug, Clone, borsh::BorshSerialize, borsh::BorshDeserialize, PartialEq)]
pub struct MarginfiAccountInitializePda {
    pub account_index: u16,
    pub third_party_id: Option<u16>,
}

#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct MarginfiAccountInitializePdaInstructionAccounts {
    pub marginfi_group: solana_pubkey::Pubkey,
    pub marginfi_account: solana_pubkey::Pubkey,
    pub authority: solana_pubkey::Pubkey,
    pub fee_payer: solana_pubkey::Pubkey,
    pub instructions_sysvar: solana_pubkey::Pubkey,
    pub system_program: solana_pubkey::Pubkey,
    pub remaining: Vec<solana_instruction::AccountMeta>,
}

impl MarginfiAccountInitializePda {
    pub fn decode(data: &[u8]) -> Option<Self> {
        if data.len() < 8 {
            return None;
        }
        let discriminator = &data[0..8];
        if discriminator != [87, 177, 91, 80, 218, 119, 245, 31] {
            return None;
        }

        let mut data_slice = data;

        data_slice = &data_slice[8..];

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

impl ArrangeAccounts for MarginfiAccountInitializePda {
    type ArrangedAccounts = MarginfiAccountInitializePdaInstructionAccounts;

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

        let marginfi_group = next_account(&mut iter)?;
        let marginfi_account = next_account(&mut iter)?;
        let authority = next_account(&mut iter)?;
        let fee_payer = next_account(&mut iter)?;
        let instructions_sysvar = next_account(&mut iter)?;
        let system_program = next_account(&mut iter)?;

        let remaining = iter.as_slice();

        Some(MarginfiAccountInitializePdaInstructionAccounts {
            marginfi_group,
            marginfi_account,
            authority,
            fee_payer,
            instructions_sysvar,
            system_program,
            remaining: remaining.to_vec(),
        })
    }
}