use carbon_core::account::AccountDecoder;
use carbon_core::deserialize::CarbonDeserialize;
use crate::PROGRAM_ID;
use super::BoopDecoder;
pub mod amm_config;
pub mod bonding_curve;
pub mod config;
pub mod locked_cp_liquidity_state;
pub enum BoopAccount {
AmmConfig(amm_config::AmmConfig),
BondingCurve(bonding_curve::BondingCurve),
Config(config::Config),
LockedCpLiquidityState(locked_cp_liquidity_state::LockedCpLiquidityState),
}
impl AccountDecoder<'_> for BoopDecoder {
type AccountType = BoopAccount;
fn decode_account(
&self,
account: &solana_account::Account,
) -> Option<carbon_core::account::DecodedAccount<Self::AccountType>> {
if !account.owner.eq(&PROGRAM_ID) {
return None;
}
if let Some(decoded_account) = amm_config::AmmConfig::deserialize(account.data.as_slice()) {
return Some(carbon_core::account::DecodedAccount {
lamports: account.lamports,
data: BoopAccount::AmmConfig(decoded_account),
owner: account.owner,
executable: account.executable,
rent_epoch: account.rent_epoch,
});
}
if let Some(decoded_account) =
bonding_curve::BondingCurve::deserialize(account.data.as_slice())
{
return Some(carbon_core::account::DecodedAccount {
lamports: account.lamports,
data: BoopAccount::BondingCurve(decoded_account),
owner: account.owner,
executable: account.executable,
rent_epoch: account.rent_epoch,
});
}
if let Some(decoded_account) = config::Config::deserialize(account.data.as_slice()) {
return Some(carbon_core::account::DecodedAccount {
lamports: account.lamports,
data: BoopAccount::Config(decoded_account),
owner: account.owner,
executable: account.executable,
rent_epoch: account.rent_epoch,
});
}
if let Some(decoded_account) =
locked_cp_liquidity_state::LockedCpLiquidityState::deserialize(account.data.as_slice())
{
return Some(carbon_core::account::DecodedAccount {
lamports: account.lamports,
data: BoopAccount::LockedCpLiquidityState(decoded_account),
owner: account.owner,
executable: account.executable,
rent_epoch: account.rent_epoch,
});
}
None
}
}