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 Lending {
    pub mint: Pubkey,
    pub f_token_mint: Pubkey,
    pub lending_id: u16,
    /// number of decimals for the fToken, same as underlying mint
    pub decimals: u8,
    /// PDA of rewards rate model (LRRM)
    pub rewards_rate_model: Pubkey,
    /// exchange price in the liquidity layer (no rewards)
    pub liquidity_exchange_price: u64,
    /// exchange price between fToken and underlying (with rewards)
    pub token_exchange_price: u64,
    /// unix timestamp when exchange prices were updated last
    pub last_update_timestamp: u64,
    pub token_reserves_liquidity: Pubkey,
    pub supply_position_on_liquidity: Pubkey,
    pub bump: u8,
}

impl Lending {
    pub fn decode(data: &[u8]) -> Option<Self> {
        if data.len() < 8 {
            return None;
        }
        let discriminator = &data[0..8];
        if discriminator != [135, 199, 82, 16, 249, 131, 182, 241] {
            return None;
        }

        let mut data_slice = data;

        data_slice = &data_slice[8..];

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