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};
/// (delegate_flow_admin only) Update the deleverage daily withdraw outflow with
/// aggregated data. The delegate flow admin aggregates
/// `DeleverageWithdrawFlowEvent` events off-chain and calls this instruction at
/// intervals.
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Debug, Clone, borsh::BorshSerialize, borsh::BorshDeserialize, PartialEq)]
pub struct UpdateDeleverageWithdrawals {
    pub outflow_usd: u32,
    pub update_seq: u64,
    pub event_start_slot: u64,
    pub event_end_slot: u64,
}

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

impl UpdateDeleverageWithdrawals {
    pub fn decode(data: &[u8]) -> Option<Self> {
        if data.len() < 8 {
            return None;
        }
        let discriminator = &data[0..8];
        if discriminator != [56, 3, 181, 118, 27, 247, 207, 227] {
            return None;
        }

        let mut data_slice = data;

        data_slice = &data_slice[8..];

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

impl ArrangeAccounts for UpdateDeleverageWithdrawals {
    type ArrangedAccounts = UpdateDeleverageWithdrawalsInstructionAccounts;

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

        let marginfi_group = next_account(&mut iter)?;
        let delegate_flow_admin = next_account(&mut iter)?;

        let remaining = iter.as_slice();

        Some(UpdateDeleverageWithdrawalsInstructionAccounts {
            marginfi_group,
            delegate_flow_admin,
            remaining: remaining.to_vec(),
        })
    }
}