carbon-drift-v2-decoder 1.0.0

Drift v2 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 LPPool {
    /// address of the vault.
    pub pubkey: Pubkey,
    pub mint: Pubkey,
    pub whitelist_mint: Pubkey,
    pub constituent_target_base: Pubkey,
    pub constituent_correlations: Pubkey,
    /// The current number of VaultConstituents in the vault, each constituent
    /// is pda(LPPool.address, constituent_index) which constituent is the
    /// quote, receives revenue pool distributions. (maybe this should just be
    /// implied idx 0) pub quote_constituent_index: u16,
    /// QUOTE_PRECISION: Max AUM, Prohibit minting new DLP beyond this
    pub max_aum: u128,
    /// QUOTE_PRECISION: AUM of the vault in USD, updated lazily
    pub last_aum: u128,
    /// QUOTE PRECISION: Cumulative quotes from settles
    pub cumulative_quote_sent_to_perp_markets: u128,
    pub cumulative_quote_received_from_perp_markets: u128,
    /// QUOTE_PRECISION: Total fees paid for minting and redeeming LP tokens
    pub total_mint_redeem_fees_paid: i128,
    /// timestamp of last AUM slot
    pub last_aum_slot: u64,
    pub max_settle_quote_amount: u64,
    /// timestamp of last vAMM revenue rebalance
    pub _padding: u64,
    /// Every mint/redeem has a monotonically increasing id. This is the next id
    /// to use
    pub mint_redeem_id: u64,
    pub settle_id: u64,
    /// PERCENTAGE_PRECISION
    pub min_mint_fee: i64,
    pub token_supply: u64,
    pub volatility: u64,
    pub constituents: u16,
    pub quote_consituent_index: u16,
    pub bump: u8,
    pub gamma_execution: u8,
    pub xi: u8,
    pub target_oracle_delay_fee_bps_per10_slots: u8,
    pub target_position_delay_fee_bps_per10_slots: u8,
    pub lp_pool_id: u8,
    #[cfg_attr(feature = "serde", serde(with = "serde_big_array::BigArray"))]
    pub padding: [u8; 174],
}

impl LPPool {
    pub fn decode(data: &[u8]) -> Option<Self> {
        if data.len() < 8 {
            return None;
        }
        let discriminator = &data[0..8];
        if discriminator != [228, 152, 141, 224, 161, 170, 11, 89] {
            return None;
        }

        let mut data_slice = data;

        data_slice = &data_slice[8..];

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