carbon_pumpfun_decoder/accounts/
mod.rs

1use {
2    super::PumpfunDecoder,
3    crate::PROGRAM_ID,
4    carbon_core::{account::AccountDecoder, deserialize::CarbonDeserialize},
5};
6pub mod bonding_curve;
7pub mod global;
8pub mod last_withdraw;
9
10pub enum PumpfunAccount {
11    Global(global::Global),
12    LastWithdraw(last_withdraw::LastWithdraw),
13    BondingCurve(bonding_curve::BondingCurve),
14}
15
16impl AccountDecoder<'_> for PumpfunDecoder {
17    type AccountType = PumpfunAccount;
18    fn decode_account(
19        &self,
20        account: &solana_sdk::account::Account,
21    ) -> Option<carbon_core::account::DecodedAccount<Self::AccountType>> {
22        if !account.owner.eq(&PROGRAM_ID) {
23            return None;
24        }
25
26        if let Some(decoded_account) = global::Global::deserialize(account.data.as_slice()) {
27            return Some(carbon_core::account::DecodedAccount {
28                lamports: account.lamports,
29                data: PumpfunAccount::Global(decoded_account),
30                owner: account.owner,
31                executable: account.executable,
32                rent_epoch: account.rent_epoch,
33            });
34        }
35
36        if let Some(decoded_account) =
37            last_withdraw::LastWithdraw::deserialize(account.data.as_slice())
38        {
39            return Some(carbon_core::account::DecodedAccount {
40                lamports: account.lamports,
41                data: PumpfunAccount::LastWithdraw(decoded_account),
42                owner: account.owner,
43                executable: account.executable,
44                rent_epoch: account.rent_epoch,
45            });
46        }
47
48        if let Some(decoded_account) =
49            bonding_curve::BondingCurve::deserialize(account.data.as_slice())
50        {
51            return Some(carbon_core::account::DecodedAccount {
52                lamports: account.lamports,
53                data: PumpfunAccount::BondingCurve(decoded_account),
54                owner: account.owner,
55                executable: account.executable,
56                rent_epoch: account.rent_epoch,
57            });
58        }
59
60        None
61    }
62}