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