carbon-drift-v2-decoder 2.0.0

Drift v2 Decoder
Documentation
//! This code was AUTOGENERATED using the Codama library.
use crate::{DriftV2Decoder, PROGRAM_ID};

#[cfg(feature = "postgres")]
pub mod postgres;

#[cfg(feature = "graphql")]
pub mod graphql;

pub mod amm_cache;
pub mod amm_constituent_mapping;
pub mod constituent;
pub mod constituent_correlations;
pub mod constituent_target_base;
pub mod fuel_overflow;
pub mod high_leverage_mode_config;
pub mod if_rebalance_config;
pub mod insurance_fund_stake;
pub mod l_p_pool;
pub mod openbook_v2_fulfillment_config;
pub mod perp_market;
pub mod phoenix_v1_fulfillment_config;
pub mod prelaunch_oracle;
pub mod protected_maker_mode_config;
pub mod protocol_if_shares_transfer_config;
pub mod pyth_lazer_oracle;
pub mod referrer_name;
pub mod revenue_share;
pub mod revenue_share_escrow;
pub mod serum_v3_fulfillment_config;
pub mod signed_msg_user_orders;
pub mod signed_msg_ws_delegates;
pub mod spot_market;
pub mod state;
pub mod user;
pub mod user_stats;

#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(feature = "serde", serde(tag = "type", content = "data"))]
pub enum DriftV2Account {
    AmmCache(Box<amm_cache::AmmCache>),
    AmmConstituentMapping(Box<amm_constituent_mapping::AmmConstituentMapping>),
    Constituent(Box<constituent::Constituent>),
    ConstituentCorrelations(Box<constituent_correlations::ConstituentCorrelations>),
    ConstituentTargetBase(Box<constituent_target_base::ConstituentTargetBase>),
    FuelOverflow(Box<fuel_overflow::FuelOverflow>),
    HighLeverageModeConfig(Box<high_leverage_mode_config::HighLeverageModeConfig>),
    IfRebalanceConfig(Box<if_rebalance_config::IfRebalanceConfig>),
    InsuranceFundStake(Box<insurance_fund_stake::InsuranceFundStake>),
    LPPool(Box<l_p_pool::LPPool>),
    OpenbookV2FulfillmentConfig(Box<openbook_v2_fulfillment_config::OpenbookV2FulfillmentConfig>),
    PerpMarket(Box<perp_market::PerpMarket>),
    PhoenixV1FulfillmentConfig(Box<phoenix_v1_fulfillment_config::PhoenixV1FulfillmentConfig>),
    PrelaunchOracle(Box<prelaunch_oracle::PrelaunchOracle>),
    ProtectedMakerModeConfig(Box<protected_maker_mode_config::ProtectedMakerModeConfig>),
    ProtocolIfSharesTransferConfig(
        Box<protocol_if_shares_transfer_config::ProtocolIfSharesTransferConfig>,
    ),
    PythLazerOracle(Box<pyth_lazer_oracle::PythLazerOracle>),
    ReferrerName(Box<referrer_name::ReferrerName>),
    RevenueShare(Box<revenue_share::RevenueShare>),
    RevenueShareEscrow(Box<revenue_share_escrow::RevenueShareEscrow>),
    SerumV3FulfillmentConfig(Box<serum_v3_fulfillment_config::SerumV3FulfillmentConfig>),
    SignedMsgUserOrders(Box<signed_msg_user_orders::SignedMsgUserOrders>),
    SignedMsgWsDelegates(Box<signed_msg_ws_delegates::SignedMsgWsDelegates>),
    SpotMarket(Box<spot_market::SpotMarket>),
    State(Box<state::State>),
    User(Box<user::User>),
    UserStats(Box<user_stats::UserStats>),
}

impl<'a> carbon_core::account::AccountDecoder<'a> for DriftV2Decoder {
    type AccountType = DriftV2Account;

    fn decode_account(
        &self,
        account: &'a solana_account::Account,
    ) -> Option<carbon_core::account::DecodedAccount<Self::AccountType>> {
        if account.owner != PROGRAM_ID {
            return None;
        }

        let data = account.data.as_slice();

        {
            if let Some(decoded) = amm_cache::AmmCache::decode(data) {
                return Some(carbon_core::account::DecodedAccount {
                    lamports: account.lamports,
                    data: DriftV2Account::AmmCache(Box::new(decoded)),
                    owner: account.owner,
                    executable: account.executable,
                    rent_epoch: account.rent_epoch,
                });
            }
        }
        {
            if let Some(decoded) =
                openbook_v2_fulfillment_config::OpenbookV2FulfillmentConfig::decode(data)
            {
                return Some(carbon_core::account::DecodedAccount {
                    lamports: account.lamports,
                    data: DriftV2Account::OpenbookV2FulfillmentConfig(Box::new(decoded)),
                    owner: account.owner,
                    executable: account.executable,
                    rent_epoch: account.rent_epoch,
                });
            }
        }
        {
            if let Some(decoded) =
                phoenix_v1_fulfillment_config::PhoenixV1FulfillmentConfig::decode(data)
            {
                return Some(carbon_core::account::DecodedAccount {
                    lamports: account.lamports,
                    data: DriftV2Account::PhoenixV1FulfillmentConfig(Box::new(decoded)),
                    owner: account.owner,
                    executable: account.executable,
                    rent_epoch: account.rent_epoch,
                });
            }
        }
        {
            if let Some(decoded) =
                serum_v3_fulfillment_config::SerumV3FulfillmentConfig::decode(data)
            {
                return Some(carbon_core::account::DecodedAccount {
                    lamports: account.lamports,
                    data: DriftV2Account::SerumV3FulfillmentConfig(Box::new(decoded)),
                    owner: account.owner,
                    executable: account.executable,
                    rent_epoch: account.rent_epoch,
                });
            }
        }
        {
            if let Some(decoded) = high_leverage_mode_config::HighLeverageModeConfig::decode(data) {
                return Some(carbon_core::account::DecodedAccount {
                    lamports: account.lamports,
                    data: DriftV2Account::HighLeverageModeConfig(Box::new(decoded)),
                    owner: account.owner,
                    executable: account.executable,
                    rent_epoch: account.rent_epoch,
                });
            }
        }
        {
            if let Some(decoded) = if_rebalance_config::IfRebalanceConfig::decode(data) {
                return Some(carbon_core::account::DecodedAccount {
                    lamports: account.lamports,
                    data: DriftV2Account::IfRebalanceConfig(Box::new(decoded)),
                    owner: account.owner,
                    executable: account.executable,
                    rent_epoch: account.rent_epoch,
                });
            }
        }
        {
            if let Some(decoded) = insurance_fund_stake::InsuranceFundStake::decode(data) {
                return Some(carbon_core::account::DecodedAccount {
                    lamports: account.lamports,
                    data: DriftV2Account::InsuranceFundStake(Box::new(decoded)),
                    owner: account.owner,
                    executable: account.executable,
                    rent_epoch: account.rent_epoch,
                });
            }
        }
        {
            if let Some(decoded) =
                protocol_if_shares_transfer_config::ProtocolIfSharesTransferConfig::decode(data)
            {
                return Some(carbon_core::account::DecodedAccount {
                    lamports: account.lamports,
                    data: DriftV2Account::ProtocolIfSharesTransferConfig(Box::new(decoded)),
                    owner: account.owner,
                    executable: account.executable,
                    rent_epoch: account.rent_epoch,
                });
            }
        }
        {
            if let Some(decoded) = l_p_pool::LPPool::decode(data) {
                return Some(carbon_core::account::DecodedAccount {
                    lamports: account.lamports,
                    data: DriftV2Account::LPPool(Box::new(decoded)),
                    owner: account.owner,
                    executable: account.executable,
                    rent_epoch: account.rent_epoch,
                });
            }
        }
        {
            if let Some(decoded) = constituent::Constituent::decode(data) {
                return Some(carbon_core::account::DecodedAccount {
                    lamports: account.lamports,
                    data: DriftV2Account::Constituent(Box::new(decoded)),
                    owner: account.owner,
                    executable: account.executable,
                    rent_epoch: account.rent_epoch,
                });
            }
        }
        {
            if let Some(decoded) = amm_constituent_mapping::AmmConstituentMapping::decode(data) {
                return Some(carbon_core::account::DecodedAccount {
                    lamports: account.lamports,
                    data: DriftV2Account::AmmConstituentMapping(Box::new(decoded)),
                    owner: account.owner,
                    executable: account.executable,
                    rent_epoch: account.rent_epoch,
                });
            }
        }
        {
            if let Some(decoded) = constituent_target_base::ConstituentTargetBase::decode(data) {
                return Some(carbon_core::account::DecodedAccount {
                    lamports: account.lamports,
                    data: DriftV2Account::ConstituentTargetBase(Box::new(decoded)),
                    owner: account.owner,
                    executable: account.executable,
                    rent_epoch: account.rent_epoch,
                });
            }
        }
        {
            if let Some(decoded) = constituent_correlations::ConstituentCorrelations::decode(data) {
                return Some(carbon_core::account::DecodedAccount {
                    lamports: account.lamports,
                    data: DriftV2Account::ConstituentCorrelations(Box::new(decoded)),
                    owner: account.owner,
                    executable: account.executable,
                    rent_epoch: account.rent_epoch,
                });
            }
        }
        {
            if let Some(decoded) = prelaunch_oracle::PrelaunchOracle::decode(data) {
                return Some(carbon_core::account::DecodedAccount {
                    lamports: account.lamports,
                    data: DriftV2Account::PrelaunchOracle(Box::new(decoded)),
                    owner: account.owner,
                    executable: account.executable,
                    rent_epoch: account.rent_epoch,
                });
            }
        }
        {
            if let Some(decoded) = perp_market::PerpMarket::decode(data) {
                return Some(carbon_core::account::DecodedAccount {
                    lamports: account.lamports,
                    data: DriftV2Account::PerpMarket(Box::new(decoded)),
                    owner: account.owner,
                    executable: account.executable,
                    rent_epoch: account.rent_epoch,
                });
            }
        }
        {
            if let Some(decoded) =
                protected_maker_mode_config::ProtectedMakerModeConfig::decode(data)
            {
                return Some(carbon_core::account::DecodedAccount {
                    lamports: account.lamports,
                    data: DriftV2Account::ProtectedMakerModeConfig(Box::new(decoded)),
                    owner: account.owner,
                    executable: account.executable,
                    rent_epoch: account.rent_epoch,
                });
            }
        }
        {
            if let Some(decoded) = pyth_lazer_oracle::PythLazerOracle::decode(data) {
                return Some(carbon_core::account::DecodedAccount {
                    lamports: account.lamports,
                    data: DriftV2Account::PythLazerOracle(Box::new(decoded)),
                    owner: account.owner,
                    executable: account.executable,
                    rent_epoch: account.rent_epoch,
                });
            }
        }
        {
            if let Some(decoded) = revenue_share::RevenueShare::decode(data) {
                return Some(carbon_core::account::DecodedAccount {
                    lamports: account.lamports,
                    data: DriftV2Account::RevenueShare(Box::new(decoded)),
                    owner: account.owner,
                    executable: account.executable,
                    rent_epoch: account.rent_epoch,
                });
            }
        }
        {
            if let Some(decoded) = revenue_share_escrow::RevenueShareEscrow::decode(data) {
                return Some(carbon_core::account::DecodedAccount {
                    lamports: account.lamports,
                    data: DriftV2Account::RevenueShareEscrow(Box::new(decoded)),
                    owner: account.owner,
                    executable: account.executable,
                    rent_epoch: account.rent_epoch,
                });
            }
        }
        {
            if let Some(decoded) = signed_msg_user_orders::SignedMsgUserOrders::decode(data) {
                return Some(carbon_core::account::DecodedAccount {
                    lamports: account.lamports,
                    data: DriftV2Account::SignedMsgUserOrders(Box::new(decoded)),
                    owner: account.owner,
                    executable: account.executable,
                    rent_epoch: account.rent_epoch,
                });
            }
        }
        {
            if let Some(decoded) = signed_msg_ws_delegates::SignedMsgWsDelegates::decode(data) {
                return Some(carbon_core::account::DecodedAccount {
                    lamports: account.lamports,
                    data: DriftV2Account::SignedMsgWsDelegates(Box::new(decoded)),
                    owner: account.owner,
                    executable: account.executable,
                    rent_epoch: account.rent_epoch,
                });
            }
        }
        {
            if let Some(decoded) = spot_market::SpotMarket::decode(data) {
                return Some(carbon_core::account::DecodedAccount {
                    lamports: account.lamports,
                    data: DriftV2Account::SpotMarket(Box::new(decoded)),
                    owner: account.owner,
                    executable: account.executable,
                    rent_epoch: account.rent_epoch,
                });
            }
        }
        {
            if let Some(decoded) = state::State::decode(data) {
                return Some(carbon_core::account::DecodedAccount {
                    lamports: account.lamports,
                    data: DriftV2Account::State(Box::new(decoded)),
                    owner: account.owner,
                    executable: account.executable,
                    rent_epoch: account.rent_epoch,
                });
            }
        }
        {
            if let Some(decoded) = user::User::decode(data) {
                return Some(carbon_core::account::DecodedAccount {
                    lamports: account.lamports,
                    data: DriftV2Account::User(Box::new(decoded)),
                    owner: account.owner,
                    executable: account.executable,
                    rent_epoch: account.rent_epoch,
                });
            }
        }
        {
            if let Some(decoded) = user_stats::UserStats::decode(data) {
                return Some(carbon_core::account::DecodedAccount {
                    lamports: account.lamports,
                    data: DriftV2Account::UserStats(Box::new(decoded)),
                    owner: account.owner,
                    executable: account.executable,
                    rent_epoch: account.rent_epoch,
                });
            }
        }
        {
            if let Some(decoded) = referrer_name::ReferrerName::decode(data) {
                return Some(carbon_core::account::DecodedAccount {
                    lamports: account.lamports,
                    data: DriftV2Account::ReferrerName(Box::new(decoded)),
                    owner: account.owner,
                    executable: account.executable,
                    rent_epoch: account.rent_epoch,
                });
            }
        }
        {
            if let Some(decoded) = fuel_overflow::FuelOverflow::decode(data) {
                return Some(carbon_core::account::DecodedAccount {
                    lamports: account.lamports,
                    data: DriftV2Account::FuelOverflow(Box::new(decoded)),
                    owner: account.owner,
                    executable: account.executable,
                    rent_epoch: account.rent_epoch,
                });
            }
        }

        None
    }
}