carbon-marginfi-v2-decoder 1.0.0

MarginfiV2 Decoder
Documentation
//! This code was AUTOGENERATED using the Codama library.
use {
    crate::types::{PanicState, WrappedI80F48},
    solana_pubkey::Pubkey,
};

#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Debug, Clone, borsh::BorshSerialize, borsh::BorshDeserialize, PartialEq)]
pub struct FeeState {
    /// The fee state's own key. A PDA derived from just `b"feestate"`
    pub key: Pubkey,
    /// Can modify fees
    pub global_fee_admin: Pubkey,
    /// The base wallet for all protocol fees. All SOL fees go to this wallet.
    /// All non-SOL fees go to the cannonical ATA of this wallet for that
    /// asset.
    pub global_fee_wallet: Pubkey,
    pub placeholder0: u64,
    /// Flat fee assessed when a new bank is initialized, in lamports.
    /// * In SOL, in native decimals.
    pub bank_init_flat_sol_fee: u32,
    pub bump_seed: u8,
    pub padding0: [u8; 3],
    /// Liquidators can claim at this premium, when liquidating an asset in
    /// receivership liquidation, e.g. (1 + this) * amount repaid >= asset
    /// seized
    /// * A percentage
    pub liquidation_max_fee: WrappedI80F48,
    /// Fee collected by the program owner from all groups
    /// * A percentage
    pub program_fee_fixed: WrappedI80F48,
    /// Fee collected by the program owner from all groups
    /// * A percentage
    pub program_fee_rate: WrappedI80F48,
    /// When the global admin pauses the protocol in the event of an emergency,
    /// information about the pause duration will be stored here and
    /// propagated to groups.
    pub panic_state: PanicState,
    pub placeholder1: u64,
    /// Flat fee assessed for insurance/program use when a liquidation is
    /// executed
    /// * In SOL, in native decimals.
    pub liquidation_flat_sol_fee: u32,
    /// Flat fee assessed for preventing spam use when creating an order
    /// * In SOL, in native decimals.
    pub order_init_flat_sol_fee: u32,
    /// Take-profit Orders can be executed at this premium, which Keepers are
    /// allowed to keep (no pun intended) e.g. (1 + this) * amount repaid >=
    /// asset seized
    /// * A percentage
    pub order_execution_max_fee: WrappedI80F48,
    pub reserved1: [u8; 32],
}

impl FeeState {
    pub fn decode(data: &[u8]) -> Option<Self> {
        if data.len() < 8 {
            return None;
        }
        let discriminator = &data[0..8];
        if discriminator != [63, 224, 16, 85, 193, 36, 235, 220] {
            return None;
        }

        let mut data_slice = data;

        data_slice = &data_slice[8..];

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