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 BankMetadata {
    /// Bank this metadata corresponds to
    pub bank: Pubkey,
    pub placeholder: u64,
    /// The token's ticker name, e.g. USDC
    /// * utf-8
    #[cfg_attr(feature = "serde", serde(with = "serde_big_array::BigArray"))]
    pub ticker: [u8; 64],
    /// The token's plain english description, e.g US Dollar Coin
    /// * utf-8
    #[cfg_attr(feature = "serde", serde(with = "serde_big_array::BigArray"))]
    pub description: [u8; 128],
    /// Reserved for future use. Room for a very small icon or something else
    /// cool
    #[cfg_attr(feature = "serde", serde(with = "serde_big_array::BigArray"))]
    pub data_blob: [u8; 256],
    /// The last data byte in description (padding follows)
    pub end_description_byte: u16,
    /// The last data byte in data_blob (padding follows)
    pub end_data_blob: u16,
    /// The last data byte in ticker (padding follows)
    pub end_ticker_byte: u8,
    pub bump: u8,
    pub pad0: [u8; 2],
}

impl BankMetadata {
    pub fn decode(data: &[u8]) -> Option<Self> {
        if data.len() < 8 {
            return None;
        }
        let discriminator = &data[0..8];
        if discriminator != [49, 207, 31, 34, 67, 225, 169, 186] {
            return None;
        }

        let mut data_slice = data;

        data_slice = &data_slice[8..];

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