carbon-marginfi-v2-decoder 1.0.0

MarginfiV2 Decoder
Documentation
//! This code was AUTOGENERATED using the Codama library.
use solana_pubkey::Pubkey;

#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Debug, Clone, borsh::BorshSerialize, borsh::BorshDeserialize, PartialEq)]
pub struct MinimalReserve {
    pub version: u64,
    /// Kamino reserves are only good for one slot, e.g. `refresh_reserve` must
    /// have run within the same slot as any ix that needs a non-stale
    /// reserve e.g. withdraw.
    pub slot: u64,
    /// True if the reserve is stale, which will cause various ixes like
    /// withdraw to fail. Typically set to true in any tx that modifies
    /// reserve balance, and set to false at the end of a successful
    /// `refresh_reserve`
    /// * 0 = false, 1 = true
    pub stale: u8,
    /// Each bit represents a passed check in price status.
    /// * 63 = all checks passed
    ///
    /// Otherwise:
    /// * PRICE_LOADED =        0b_0000_0001; // 1
    /// * PRICE_AGE_CHECKED =   0b_0000_0010; // 2
    /// * TWAP_CHECKED =        0b_0000_0100; // 4
    /// * TWAP_AGE_CHECKED =    0b_0000_1000; // 8
    /// * HEURISTIC_CHECKED =   0b_0001_0000; // 16
    /// * PRICE_USAGE_ALLOWED = 0b_0010_0000; // 32
    pub price_status: u8,
    pub placeholder: [u8; 6],
    pub lending_market: Pubkey,
    pub farm_collateral: Pubkey,
    pub farm_debt: Pubkey,
    pub mint_pubkey: Pubkey,
    /// * A PDA
    pub supply_vault: Pubkey,
    /// * A PDA
    pub fee_vault: Pubkey,
    /// In simple terms: (amount in supply vault - outstanding borrows)
    /// * In token, with `mint_decimals`
    pub available_amount: u64,
    /// * In token, with `mint_decimals`
    /// * Actually an I68F60, stored as a u128 (i.e. BN) in Kamino.
    pub borrowed_amount_sf: [u8; 16],
    /// * Actually an I68F60, stored as a u128 (i.e. BN) in Kamino.
    pub market_price_sf: [u8; 16],
    pub market_price_last_updated_ts: u64,
    pub mint_decimals: u64,
    pub deposit_limit_crossed_timestamp: u64,
    pub borrow_limit_crossed_timestamp: u64,
    #[cfg_attr(feature = "serde", serde(with = "serde_big_array::BigArray"))]
    pub cumulative_borrow_rate_bsf: [u8; 48],
    /// * In token, with `mint_decimals`
    /// * Actually an I68F60, stored as a u128 (i.e. BN) in Kamino.
    pub accumulated_protocol_fees_sf: [u8; 16],
    /// * In token, with `mint_decimals`
    /// * Actually an I68F60, stored as a u128 (i.e. BN) in Kamino.
    pub accumulated_referrer_fees_sf: [u8; 16],
    /// * In token, with `mint_decimals`
    /// * Actually an I68F60, stored as a u128 (i.e. BN) in Kamino.
    pub pending_referrer_fees_sf: [u8; 16],
    /// * In token, with `mint_decimals`
    /// * Actually an I68F60, stored as a u128 (i.e. BN) in Kamino.
    pub absolute_referral_rate_sf: [u8; 16],
    /// Token or Token22. If token22, note that Kamino does not support all
    /// Token22 extensions.
    pub token_program: Pubkey,
    #[cfg_attr(feature = "serde", serde(with = "serde_big_array::BigArray"))]
    pub padding2_part1: [u8; 256],
    #[cfg_attr(feature = "serde", serde(with = "serde_big_array::BigArray"))]
    pub padding2_part2: [u8; 128],
    pub padding2_part3: [u8; 24],
    #[cfg_attr(feature = "serde", serde(with = "serde_big_array::BigArray"))]
    pub padding3: [u8; 512],
    #[cfg_attr(feature = "serde", serde(with = "serde_big_array::BigArray"))]
    pub padding_part1: [u8; 512],
    #[cfg_attr(feature = "serde", serde(with = "serde_big_array::BigArray"))]
    pub padding_part2: [u8; 512],
    #[cfg_attr(feature = "serde", serde(with = "serde_big_array::BigArray"))]
    pub padding_part3: [u8; 128],
    #[cfg_attr(feature = "serde", serde(with = "serde_big_array::BigArray"))]
    pub padding_part4: [u8; 48],
    /// Mints collateral tokens
    /// * A PDA
    /// * technically 6 decimals, but uses `mint_decimals` regardless for all
    ///   purposes
    /// * authority = lending_market_authority
    pub collateral_mint_pubkey: Pubkey,
    /// Total number of collateral tokens
    /// * uses `mint_decimals`, even though it's technically 6 decimals under
    ///   the hood
    pub mint_total_supply: u64,
    /// * A PDA
    pub collateral_supply_vault: Pubkey,
    #[cfg_attr(feature = "serde", serde(with = "serde_big_array::BigArray"))]
    pub padding1_reserve_collateral: [u8; 512],
    #[cfg_attr(feature = "serde", serde(with = "serde_big_array::BigArray"))]
    pub padding2_reserve_collateral: [u8; 512],
    #[cfg_attr(feature = "serde", serde(with = "serde_big_array::BigArray"))]
    pub padding4_part1: [u8; 4096],
    #[cfg_attr(feature = "serde", serde(with = "serde_big_array::BigArray"))]
    pub padding4_part2: [u8; 512],
    #[cfg_attr(feature = "serde", serde(with = "serde_big_array::BigArray"))]
    pub padding4_part3: [u8; 256],
    #[cfg_attr(feature = "serde", serde(with = "serde_big_array::BigArray"))]
    pub padding4_part4: [u8; 64],
    pub padding4_part5: [u8; 32],
    pub padding4_part6: [u8; 8],
}

impl MinimalReserve {
    pub fn decode(data: &[u8]) -> Option<Self> {
        if data.len() < 8 {
            return None;
        }
        let discriminator = &data[0..8];
        if discriminator != [43, 242, 204, 202, 26, 247, 59, 127] {
            return None;
        }

        let mut data_slice = data;

        data_slice = &data_slice[8..];

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