carbon-drift-v2-decoder 1.0.0

Drift v2 Decoder
Documentation
//! This code was AUTOGENERATED using the Codama library.
use {crate::types::ConstituentSpotBalance, solana_pubkey::Pubkey};

#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Debug, Clone, borsh::BorshSerialize, borsh::BorshDeserialize, PartialEq)]
pub struct Constituent {
    /// address of the constituent
    pub pubkey: Pubkey,
    pub mint: Pubkey,
    pub lp_pool: Pubkey,
    pub vault: Pubkey,
    /// total fees received by the constituent. Positive = fees received,
    /// Negative = fees paid
    pub total_swap_fees: i128,
    /// spot borrow-lend balance for constituent
    pub spot_balance: ConstituentSpotBalance,
    pub last_spot_balance_token_amount: i64,
    pub cumulative_spot_interest_accrued_token_amount: i64,
    /// max deviation from target_weight allowed for the constituent
    /// precision: PERCENTAGE_PRECISION
    pub max_weight_deviation: i64,
    /// min fee charged on swaps to/from this constituent
    /// precision: PERCENTAGE_PRECISION
    pub swap_fee_min: i64,
    /// max fee charged on swaps to/from this constituent
    /// precision: PERCENTAGE_PRECISION
    pub swap_fee_max: i64,
    /// Max Borrow amount:
    /// precision: token precision
    pub max_borrow_token_amount: u64,
    /// ata token balance in token precision
    pub vault_token_balance: u64,
    pub last_oracle_price: i64,
    pub last_oracle_slot: u64,
    /// Delay allowed for valid AUM calculation
    pub oracle_staleness_threshold: u64,
    pub flash_loan_initial_token_amount: u64,
    /// Every swap to/from this constituent has a monotonically increasing id.
    /// This is the next id to use
    pub next_swap_id: u64,
    /// percentable of derivatve weight to go to this specific derivative
    /// PERCENTAGE_PRECISION. Zero if no derivative weight
    pub derivative_weight: u64,
    pub volatility: u64,
    pub constituent_derivative_depeg_threshold: u64,
    /// The `constituent_index` of the parent constituent. -1 if it is a parent
    /// index Example: if in a pool with SOL (parent) and dSOL (derivative),
    /// SOL.constituent_index = 1, SOL.constituent_derivative_index = -1,
    /// dSOL.constituent_index = 2, dSOL.constituent_derivative_index = 1
    pub constituent_derivative_index: i16,
    pub spot_market_index: u16,
    pub constituent_index: u16,
    pub decimals: u8,
    pub bump: u8,
    pub vault_bump: u8,
    pub gamma_inventory: u8,
    pub gamma_execution: u8,
    pub xi: u8,
    pub status: u8,
    pub paused_operations: u8,
    #[cfg_attr(feature = "serde", serde(with = "serde_big_array::BigArray"))]
    pub padding: [u8; 162],
}

impl Constituent {
    pub fn decode(data: &[u8]) -> Option<Self> {
        if data.len() < 8 {
            return None;
        }
        let discriminator = &data[0..8];
        if discriminator != [0, 61, 36, 35, 177, 76, 216, 205] {
            return None;
        }

        let mut data_slice = data;

        data_slice = &data_slice[8..];

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