carbon-gavel-decoder 1.0.0

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

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

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

pub mod lp_position_account;
pub mod pool_account;

#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(feature = "serde", serde(tag = "type", content = "data"))]
pub enum GavelAccount {
    LpPositionAccount(Box<lp_position_account::LpPositionAccount>),
    PoolAccount(Box<pool_account::PoolAccount>),
}

impl<'a> carbon_core::account::AccountDecoder<'a> for GavelDecoder {
    type AccountType = GavelAccount;

    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) = pool_account::PoolAccount::decode(data) {
                return Some(carbon_core::account::DecodedAccount {
                    lamports: account.lamports,
                    data: GavelAccount::PoolAccount(Box::new(decoded)),
                    owner: account.owner,
                    executable: account.executable,
                    rent_epoch: account.rent_epoch,
                });
            }
        }
        {
            if let Some(decoded) = lp_position_account::LpPositionAccount::decode(data) {
                return Some(carbon_core::account::DecodedAccount {
                    lamports: account.lamports,
                    data: GavelAccount::LpPositionAccount(Box::new(decoded)),
                    owner: account.owner,
                    executable: account.executable,
                    rent_epoch: account.rent_epoch,
                });
            }
        }

        None
    }
}