carbon-marginfi-v2-decoder 1.0.0

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

#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Debug, Clone, borsh::BorshSerialize, borsh::BorshDeserialize, PartialEq)]
pub struct MinimalObligation {
    pub tag: u64,
    /// Kamino obligations are only good for one slot, e.g. `refresh_obligation`
    /// must have run within the same slot as any ix that needs a non-stale
    /// obligation e.g. withdraw.
    pub last_update_slot: u64,
    /// True if the obligation is stale, which will cause various ixes like
    /// withdraw to fail. Typically set to true in any tx that modifies
    /// obligation balance, and set to false at the end of a successful
    /// `refresh_obligation`
    /// * 0 = false, 1 = true
    pub last_update_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 last_update_price_status: u8,
    pub last_update_placeholder: [u8; 6],
    pub lending_market: Pubkey,
    /// For mrgn banks, the bank's Liquidity Vault Authority (a pda which can be
    /// derived if the bank key is known)
    pub owner: Pubkey,
    pub deposits: [MinimalObligationCollateral; 8],
    pub lowest_reserve_deposit_liquidation_ltv: u64,
    pub deposited_value_sf: [u8; 16],
    #[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; 512],
    #[cfg_attr(feature = "serde", serde(with = "serde_big_array::BigArray"))]
    pub padding_part4: [u8; 512],
    #[cfg_attr(feature = "serde", serde(with = "serde_big_array::BigArray"))]
    pub padding_part5a: [u8; 64],
    pub padding_part5c: [u8; 24],
}

impl MinimalObligation {
    pub fn decode(data: &[u8]) -> Option<Self> {
        if data.len() < 8 {
            return None;
        }
        let discriminator = &data[0..8];
        if discriminator != [168, 206, 141, 106, 88, 76, 172, 167] {
            return None;
        }

        let mut data_slice = data;

        data_slice = &data_slice[8..];

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