carbon_pump_swap_decoder/accounts/
mod.rs1use carbon_core::account::AccountDecoder;
2use carbon_core::deserialize::CarbonDeserialize;
3
4use crate::PROGRAM_ID;
5
6use super::PumpSwapDecoder;
7pub mod bonding_curve;
8pub mod fee_config;
9pub mod global_config;
10pub mod global_volume_accumulator;
11pub mod pool;
12pub mod user_volume_accumulator;
13
14pub enum PumpSwapAccount {
15 BondingCurve(bonding_curve::BondingCurve),
16 FeeConfig(fee_config::FeeConfig),
17 GlobalConfig(global_config::GlobalConfig),
18 GlobalVolumeAccumulator(global_volume_accumulator::GlobalVolumeAccumulator),
19 Pool(pool::Pool),
20 UserVolumeAccumulator(user_volume_accumulator::UserVolumeAccumulator),
21}
22
23impl AccountDecoder<'_> for PumpSwapDecoder {
24 type AccountType = PumpSwapAccount;
25 fn decode_account(
26 &self,
27 account: &solana_account::Account,
28 ) -> Option<carbon_core::account::DecodedAccount<Self::AccountType>> {
29 if !account.owner.eq(&PROGRAM_ID) {
30 return None;
31 }
32
33 if let Some(decoded_account) =
34 bonding_curve::BondingCurve::deserialize(account.data.as_slice())
35 {
36 return Some(carbon_core::account::DecodedAccount {
37 lamports: account.lamports,
38 data: PumpSwapAccount::BondingCurve(decoded_account),
39 owner: account.owner,
40 executable: account.executable,
41 rent_epoch: account.rent_epoch,
42 });
43 }
44
45 if let Some(decoded_account) = fee_config::FeeConfig::deserialize(account.data.as_slice()) {
46 return Some(carbon_core::account::DecodedAccount {
47 lamports: account.lamports,
48 data: PumpSwapAccount::FeeConfig(decoded_account),
49 owner: account.owner,
50 executable: account.executable,
51 rent_epoch: account.rent_epoch,
52 });
53 }
54
55 if let Some(decoded_account) =
56 global_config::GlobalConfig::deserialize(account.data.as_slice())
57 {
58 return Some(carbon_core::account::DecodedAccount {
59 lamports: account.lamports,
60 data: PumpSwapAccount::GlobalConfig(decoded_account),
61 owner: account.owner,
62 executable: account.executable,
63 rent_epoch: account.rent_epoch,
64 });
65 }
66
67 if let Some(decoded_account) =
68 global_volume_accumulator::GlobalVolumeAccumulator::deserialize(account.data.as_slice())
69 {
70 return Some(carbon_core::account::DecodedAccount {
71 lamports: account.lamports,
72 data: PumpSwapAccount::GlobalVolumeAccumulator(decoded_account),
73 owner: account.owner,
74 executable: account.executable,
75 rent_epoch: account.rent_epoch,
76 });
77 }
78
79 if let Some(decoded_account) = pool::Pool::deserialize(account.data.as_slice()) {
80 return Some(carbon_core::account::DecodedAccount {
81 lamports: account.lamports,
82 data: PumpSwapAccount::Pool(decoded_account),
83 owner: account.owner,
84 executable: account.executable,
85 rent_epoch: account.rent_epoch,
86 });
87 }
88
89 if let Some(decoded_account) =
90 user_volume_accumulator::UserVolumeAccumulator::deserialize(account.data.as_slice())
91 {
92 return Some(carbon_core::account::DecodedAccount {
93 lamports: account.lamports,
94 data: PumpSwapAccount::UserVolumeAccumulator(decoded_account),
95 owner: account.owner,
96 executable: account.executable,
97 rent_epoch: account.rent_epoch,
98 });
99 }
100
101 None
102 }
103}