carbon-marginfi-v2-decoder 1.0.0

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

#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Debug, Clone, borsh::BorshSerialize, borsh::BorshDeserialize, PartialEq)]
pub struct MinimalUser {
    /// The owner/authority of the account
    pub authority: Pubkey,
    /// An addresses that can control the account on the authority's behalf
    pub delegate: Pubkey,
    /// Encoded display name for the account
    pub name: [u8; 32],
    /// The user's spot positions (8 positions)
    pub spot_positions: [SpotPosition; 8],
    /// Skip to the fields we need at the end
    #[cfg_attr(feature = "serde", serde(with = "serde_big_array::BigArray"))]
    pub padding1: [u64; 256],
    #[cfg_attr(feature = "serde", serde(with = "serde_big_array::BigArray"))]
    pub padding2: [u64; 128],
    #[cfg_attr(feature = "serde", serde(with = "serde_big_array::BigArray"))]
    pub padding3: [u64; 64],
    pub padding4: [u64; 32],
    pub padding5: [u64; 8],
    pub padding6: [u64; 2],
    pub padding7: [u16; 1],
    /// Sub account id for this user account
    pub sub_account_id: u16,
    pub status: UserStatus,
    pub padding8: [u8; 27],
}

impl MinimalUser {
    pub fn decode(data: &[u8]) -> Option<Self> {
        if data.len() < 8 {
            return None;
        }
        let discriminator = &data[0..8];
        if discriminator != [159, 117, 95, 227, 239, 151, 58, 236] {
            return None;
        }

        let mut data_slice = data;

        data_slice = &data_slice[8..];

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