carbon-marginfi-v2-decoder 1.0.0

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

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

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

pub mod bank;
pub mod bank_metadata;
pub mod execute_order_record;
pub mod fee_state;
pub mod lending;
pub mod liquidation_record;
pub mod marginfi_account;
pub mod marginfi_group;
pub mod minimal_obligation;
pub mod minimal_reserve;
pub mod minimal_spot_market;
pub mod minimal_user;
pub mod order;
pub mod solend_minimal_reserve;
pub mod staked_settings;

#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(feature = "serde", serde(tag = "type", content = "data"))]
pub enum MarginfiV2Account {
    Bank(Box<bank::Bank>),
    BankMetadata(Box<bank_metadata::BankMetadata>),
    ExecuteOrderRecord(Box<execute_order_record::ExecuteOrderRecord>),
    FeeState(Box<fee_state::FeeState>),
    Lending(Box<lending::Lending>),
    LiquidationRecord(Box<liquidation_record::LiquidationRecord>),
    MarginfiAccount(Box<marginfi_account::MarginfiAccount>),
    MarginfiGroup(Box<marginfi_group::MarginfiGroup>),
    MinimalObligation(Box<minimal_obligation::MinimalObligation>),
    MinimalReserve(Box<minimal_reserve::MinimalReserve>),
    MinimalSpotMarket(Box<minimal_spot_market::MinimalSpotMarket>),
    MinimalUser(Box<minimal_user::MinimalUser>),
    Order(Box<order::Order>),
    SolendMinimalReserve(Box<solend_minimal_reserve::SolendMinimalReserve>),
    StakedSettings(Box<staked_settings::StakedSettings>),
}

impl<'a> carbon_core::account::AccountDecoder<'a> for MarginfiV2Decoder {
    type AccountType = MarginfiV2Account;

    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) = bank::Bank::decode(data) {
                return Some(carbon_core::account::DecodedAccount {
                    lamports: account.lamports,
                    data: MarginfiV2Account::Bank(Box::new(decoded)),
                    owner: account.owner,
                    executable: account.executable,
                    rent_epoch: account.rent_epoch,
                });
            }
        }
        {
            if let Some(decoded) = bank_metadata::BankMetadata::decode(data) {
                return Some(carbon_core::account::DecodedAccount {
                    lamports: account.lamports,
                    data: MarginfiV2Account::BankMetadata(Box::new(decoded)),
                    owner: account.owner,
                    executable: account.executable,
                    rent_epoch: account.rent_epoch,
                });
            }
        }
        {
            if let Some(decoded) = execute_order_record::ExecuteOrderRecord::decode(data) {
                return Some(carbon_core::account::DecodedAccount {
                    lamports: account.lamports,
                    data: MarginfiV2Account::ExecuteOrderRecord(Box::new(decoded)),
                    owner: account.owner,
                    executable: account.executable,
                    rent_epoch: account.rent_epoch,
                });
            }
        }
        {
            if let Some(decoded) = fee_state::FeeState::decode(data) {
                return Some(carbon_core::account::DecodedAccount {
                    lamports: account.lamports,
                    data: MarginfiV2Account::FeeState(Box::new(decoded)),
                    owner: account.owner,
                    executable: account.executable,
                    rent_epoch: account.rent_epoch,
                });
            }
        }
        {
            if let Some(decoded) = lending::Lending::decode(data) {
                return Some(carbon_core::account::DecodedAccount {
                    lamports: account.lamports,
                    data: MarginfiV2Account::Lending(Box::new(decoded)),
                    owner: account.owner,
                    executable: account.executable,
                    rent_epoch: account.rent_epoch,
                });
            }
        }
        {
            if let Some(decoded) = liquidation_record::LiquidationRecord::decode(data) {
                return Some(carbon_core::account::DecodedAccount {
                    lamports: account.lamports,
                    data: MarginfiV2Account::LiquidationRecord(Box::new(decoded)),
                    owner: account.owner,
                    executable: account.executable,
                    rent_epoch: account.rent_epoch,
                });
            }
        }
        {
            if let Some(decoded) = marginfi_account::MarginfiAccount::decode(data) {
                return Some(carbon_core::account::DecodedAccount {
                    lamports: account.lamports,
                    data: MarginfiV2Account::MarginfiAccount(Box::new(decoded)),
                    owner: account.owner,
                    executable: account.executable,
                    rent_epoch: account.rent_epoch,
                });
            }
        }
        {
            if let Some(decoded) = marginfi_group::MarginfiGroup::decode(data) {
                return Some(carbon_core::account::DecodedAccount {
                    lamports: account.lamports,
                    data: MarginfiV2Account::MarginfiGroup(Box::new(decoded)),
                    owner: account.owner,
                    executable: account.executable,
                    rent_epoch: account.rent_epoch,
                });
            }
        }
        {
            if let Some(decoded) = minimal_obligation::MinimalObligation::decode(data) {
                return Some(carbon_core::account::DecodedAccount {
                    lamports: account.lamports,
                    data: MarginfiV2Account::MinimalObligation(Box::new(decoded)),
                    owner: account.owner,
                    executable: account.executable,
                    rent_epoch: account.rent_epoch,
                });
            }
        }
        {
            if let Some(decoded) = minimal_reserve::MinimalReserve::decode(data) {
                return Some(carbon_core::account::DecodedAccount {
                    lamports: account.lamports,
                    data: MarginfiV2Account::MinimalReserve(Box::new(decoded)),
                    owner: account.owner,
                    executable: account.executable,
                    rent_epoch: account.rent_epoch,
                });
            }
        }
        {
            if let Some(decoded) = minimal_spot_market::MinimalSpotMarket::decode(data) {
                return Some(carbon_core::account::DecodedAccount {
                    lamports: account.lamports,
                    data: MarginfiV2Account::MinimalSpotMarket(Box::new(decoded)),
                    owner: account.owner,
                    executable: account.executable,
                    rent_epoch: account.rent_epoch,
                });
            }
        }
        {
            if let Some(decoded) = minimal_user::MinimalUser::decode(data) {
                return Some(carbon_core::account::DecodedAccount {
                    lamports: account.lamports,
                    data: MarginfiV2Account::MinimalUser(Box::new(decoded)),
                    owner: account.owner,
                    executable: account.executable,
                    rent_epoch: account.rent_epoch,
                });
            }
        }
        {
            if let Some(decoded) = order::Order::decode(data) {
                return Some(carbon_core::account::DecodedAccount {
                    lamports: account.lamports,
                    data: MarginfiV2Account::Order(Box::new(decoded)),
                    owner: account.owner,
                    executable: account.executable,
                    rent_epoch: account.rent_epoch,
                });
            }
        }
        {
            if let Some(decoded) = solend_minimal_reserve::SolendMinimalReserve::decode(data) {
                return Some(carbon_core::account::DecodedAccount {
                    lamports: account.lamports,
                    data: MarginfiV2Account::SolendMinimalReserve(Box::new(decoded)),
                    owner: account.owner,
                    executable: account.executable,
                    rent_epoch: account.rent_epoch,
                });
            }
        }
        {
            if let Some(decoded) = staked_settings::StakedSettings::decode(data) {
                return Some(carbon_core::account::DecodedAccount {
                    lamports: account.lamports,
                    data: MarginfiV2Account::StakedSettings(Box::new(decoded)),
                    owner: account.owner,
                    executable: account.executable,
                    rent_epoch: account.rent_epoch,
                });
            }
        }

        None
    }
}