carbon-marginfi-v2-decoder 1.0.0

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

#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Debug, Clone, borsh::BorshSerialize, borsh::BorshDeserialize, PartialEq)]
pub struct LiquidationRecord {
    /// This account's own key. A PDA derived from `marginfi_account`
    pub key: Pubkey,
    /// Account this record tracks
    pub marginfi_account: Pubkey,
    /// The key that paid to create this account. At some point, we may allow
    /// this wallet to reclaim the rent paid to open a record.
    pub record_payer: Pubkey,
    /// The liquidator taking receivership of the `marginfi_account` to complete
    /// a liquidation. Pays the liquidation fee.
    /// * Always pubkey default unless actively within a liquidation event.
    pub liquidation_receiver: Pubkey,
    /// Basic historical data for the last few liquidation events on this
    /// account
    pub entries: [LiquidationEntry; 4],
    pub cache: LiquidationCache,
    #[cfg_attr(feature = "serde", serde(with = "serde_big_array::BigArray"))]
    pub reserved0: [u8; 64],
    pub reserved2: [u8; 16],
    pub reserved3: [u8; 8],
}

impl LiquidationRecord {
    pub fn decode(data: &[u8]) -> Option<Self> {
        if data.len() < 8 {
            return None;
        }
        let discriminator = &data[0..8];
        if discriminator != [95, 116, 23, 132, 89, 210, 245, 162] {
            return None;
        }

        let mut data_slice = data;

        data_slice = &data_slice[8..];

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