carbon-zeta-decoder 2.0.0

Zeta Program Decoder
Documentation
//! This code was AUTOGENERATED using the Codama library.
use {
    crate::types::{AnchorDecimal, Asset, MarginAccountType, ProductLedger},
    solana_pubkey::Pubkey,
};

#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Debug, Clone, borsh::BorshSerialize, borsh::BorshDeserialize, PartialEq)]
pub struct MarginAccount {
    pub authority: Pubkey,
    pub nonce: u8,
    pub balance: u64,
    pub force_cancel_flag: bool,
    #[cfg_attr(feature = "serde", serde(with = "serde_big_array::BigArray"))]
    pub open_orders_nonce: [u8; 138],
    pub series_expiry: [u64; 5],
    pub series_expiry_padding: u64,
    #[cfg_attr(feature = "serde", serde(with = "serde_big_array::BigArray"))]
    pub product_ledgers: [ProductLedger; 46],
    #[cfg_attr(feature = "serde", serde(with = "serde_big_array::BigArray"))]
    pub product_ledgers_padding: [ProductLedger; 91],
    pub perp_product_ledger: ProductLedger,
    pub rebalance_amount: i64,
    pub asset: Asset,
    pub account_type: MarginAccountType,
    pub last_funding_delta: AnchorDecimal,
    pub delegated_pubkey: Pubkey,
    #[cfg_attr(feature = "serde", serde(with = "serde_big_array::BigArray"))]
    pub padding: [u8; 338],
}

impl MarginAccount {
    pub fn decode(data: &[u8]) -> Option<Self> {
        if data.len() < 8 {
            return None;
        }
        let discriminator = &data[0..8];
        if discriminator != [133, 220, 173, 213, 179, 211, 43, 238] {
            return None;
        }

        let mut data_slice = data;

        data_slice = &data_slice[8..];

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