carbon-marginfi-v2-decoder 1.0.0

MarginfiV2 Decoder
Documentation
//! This code was AUTOGENERATED using the Codama library.
use {
    crate::types::InterestRateConfigOpt,
    carbon_core::{account_utils::next_account, deserialize::ArrangeAccounts},
};
/// (delegate_curve_admin only) Update interest rate config. Does nothing if
/// bank has `FREEZE_SETTINGS`.
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Debug, Clone, borsh::BorshSerialize, borsh::BorshDeserialize, PartialEq)]
pub struct LendingPoolConfigureBankInterestOnly {
    pub interest_rate_config: InterestRateConfigOpt,
}

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

impl LendingPoolConfigureBankInterestOnly {
    pub fn decode(data: &[u8]) -> Option<Self> {
        if data.len() < 8 {
            return None;
        }
        let discriminator = &data[0..8];
        if discriminator != [245, 107, 83, 38, 103, 219, 163, 241] {
            return None;
        }

        let mut data_slice = data;

        data_slice = &data_slice[8..];

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

impl ArrangeAccounts for LendingPoolConfigureBankInterestOnly {
    type ArrangedAccounts = LendingPoolConfigureBankInterestOnlyInstructionAccounts;

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

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

        let remaining = iter.as_slice();

        Some(LendingPoolConfigureBankInterestOnlyInstructionAccounts {
            group,
            delegate_curve_admin,
            bank,
            remaining: remaining.to_vec(),
        })
    }
}