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};
/// (account authority) Transfer all positions to a new account under a new
/// authority. The old account is disabled. Pays a flat SOL fee to the protocol.
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Debug, Clone, borsh::BorshSerialize, borsh::BorshDeserialize, PartialEq)]
pub struct TransferToNewAccount {}

#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct TransferToNewAccountInstructionAccounts {
    pub group: solana_pubkey::Pubkey,
    pub old_marginfi_account: solana_pubkey::Pubkey,
    pub new_marginfi_account: solana_pubkey::Pubkey,
    pub authority: solana_pubkey::Pubkey,
    pub fee_payer: solana_pubkey::Pubkey,
    pub new_authority: solana_pubkey::Pubkey,
    pub global_fee_wallet: solana_pubkey::Pubkey,
    pub system_program: solana_pubkey::Pubkey,
    pub remaining: Vec<solana_instruction::AccountMeta>,
}

impl TransferToNewAccount {
    pub fn decode(data: &[u8]) -> Option<Self> {
        if data.len() < 8 {
            return None;
        }
        let discriminator = &data[0..8];
        if discriminator != [28, 79, 129, 231, 169, 69, 69, 65] {
            return None;
        }

        let mut data_slice = data;

        data_slice = &data_slice[8..];

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

impl ArrangeAccounts for TransferToNewAccount {
    type ArrangedAccounts = TransferToNewAccountInstructionAccounts;

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

        let group = next_account(&mut iter)?;
        let old_marginfi_account = next_account(&mut iter)?;
        let new_marginfi_account = next_account(&mut iter)?;
        let authority = next_account(&mut iter)?;
        let fee_payer = next_account(&mut iter)?;
        let new_authority = next_account(&mut iter)?;
        let global_fee_wallet = next_account(&mut iter)?;
        let system_program = next_account(&mut iter)?;

        let remaining = iter.as_slice();

        Some(TransferToNewAccountInstructionAccounts {
            group,
            old_marginfi_account,
            new_marginfi_account,
            authority,
            fee_payer,
            new_authority,
            global_fee_wallet,
            system_program,
            remaining: remaining.to_vec(),
        })
    }
}