carbon-marginfi-v2-decoder 1.0.0

MarginfiV2 Decoder
Documentation
//! This code was AUTOGENERATED using the Codama library.
use {
    crate::types::WrappedI80F48,
    carbon_core::{account_utils::next_account, deserialize::ArrangeAccounts},
    solana_pubkey::Pubkey,
};
/// (Runs once per program) Configures the fee state account, where the global
/// admin sets fees that are assessed to the protocol
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Debug, Clone, borsh::BorshSerialize, borsh::BorshDeserialize, PartialEq)]
pub struct InitGlobalFeeState {
    pub admin: Pubkey,
    pub fee_wallet: Pubkey,
    pub bank_init_flat_sol_fee: u32,
    pub liquidation_flat_sol_fee: u32,
    pub order_init_flat_sol_fee: u32,
    pub program_fee_fixed: WrappedI80F48,
    pub program_fee_rate: WrappedI80F48,
    pub liquidation_max_fee: WrappedI80F48,
    pub order_execution_max_fee: WrappedI80F48,
}

#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct InitGlobalFeeStateInstructionAccounts {
    pub payer: solana_pubkey::Pubkey,
    pub fee_state: solana_pubkey::Pubkey,
    pub system_program: solana_pubkey::Pubkey,
    pub remaining: Vec<solana_instruction::AccountMeta>,
}

impl InitGlobalFeeState {
    pub fn decode(data: &[u8]) -> Option<Self> {
        if data.len() < 8 {
            return None;
        }
        let discriminator = &data[0..8];
        if discriminator != [82, 48, 247, 59, 220, 109, 231, 44] {
            return None;
        }

        let mut data_slice = data;

        data_slice = &data_slice[8..];

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

impl ArrangeAccounts for InitGlobalFeeState {
    type ArrangedAccounts = InitGlobalFeeStateInstructionAccounts;

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

        let payer = next_account(&mut iter)?;
        let fee_state = next_account(&mut iter)?;
        let system_program = next_account(&mut iter)?;

        let remaining = iter.as_slice();

        Some(InitGlobalFeeStateInstructionAccounts {
            payer,
            fee_state,
            system_program,
            remaining: remaining.to_vec(),
        })
    }
}