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 group rate limiter with aggregated
/// inflow/outflow. The delegate flow admin aggregates
/// `RateLimitFlowEvent` events off-chain, converts to USD, and calls this
/// instruction at intervals to update group rate limiter state.
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Debug, Clone, borsh::BorshSerialize, borsh::BorshDeserialize, PartialEq)]
pub struct UpdateGroupRateLimiter {
    pub outflow_usd: Option<u64>,
    pub inflow_usd: Option<u64>,
    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 UpdateGroupRateLimiterInstructionAccounts {
    pub marginfi_group: solana_pubkey::Pubkey,
    pub delegate_flow_admin: solana_pubkey::Pubkey,
    pub remaining: Vec<solana_instruction::AccountMeta>,
}

impl UpdateGroupRateLimiter {
    pub fn decode(data: &[u8]) -> Option<Self> {
        if data.len() < 8 {
            return None;
        }
        let discriminator = &data[0..8];
        if discriminator != [23, 78, 60, 139, 187, 44, 129, 37] {
            return None;
        }

        let mut data_slice = data;

        data_slice = &data_slice[8..];

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

impl ArrangeAccounts for UpdateGroupRateLimiter {
    type ArrangedAccounts = UpdateGroupRateLimiterInstructionAccounts;

    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(UpdateGroupRateLimiterInstructionAccounts {
            marginfi_group,
            delegate_flow_admin,
            remaining: remaining.to_vec(),
        })
    }
}