carbon-marginfi-v2-decoder 1.0.0

MarginfiV2 Decoder
Documentation
//! This code was AUTOGENERATED using the Codama library.
use {
    crate::types::BankConfigOpt,
    carbon_core::{account_utils::next_account, deserialize::ArrangeAccounts},
};
/// (admin only) Configure bank parameters. If the bank has `FREEZE_SETTINGS`,
/// only deposit/borrow limits are updated and all other config changes are
/// silently ignored.
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Debug, Clone, borsh::BorshSerialize, borsh::BorshDeserialize, PartialEq)]
pub struct LendingPoolConfigureBank {
    pub bank_config_opt: BankConfigOpt,
}

#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct LendingPoolConfigureBankInstructionAccounts {
    pub group: solana_pubkey::Pubkey,
    pub admin: solana_pubkey::Pubkey,
    pub bank: solana_pubkey::Pubkey,
    pub remaining: Vec<solana_instruction::AccountMeta>,
}

impl LendingPoolConfigureBank {
    pub fn decode(data: &[u8]) -> Option<Self> {
        if data.len() < 8 {
            return None;
        }
        let discriminator = &data[0..8];
        if discriminator != [121, 173, 156, 40, 93, 148, 56, 237] {
            return None;
        }

        let mut data_slice = data;

        data_slice = &data_slice[8..];

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

impl ArrangeAccounts for LendingPoolConfigureBank {
    type ArrangedAccounts = LendingPoolConfigureBankInstructionAccounts;

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

        let group = next_account(&mut iter)?;
        let admin = next_account(&mut iter)?;
        let bank = next_account(&mut iter)?;

        let remaining = iter.as_slice();

        Some(LendingPoolConfigureBankInstructionAccounts {
            group,
            admin,
            bank,
            remaining: remaining.to_vec(),
        })
    }
}