carbon_drift_v2_decoder/accounts/
mod.rs

1use carbon_core::account::AccountDecoder;
2use carbon_core::deserialize::CarbonDeserialize;
3
4use crate::PROGRAM_ID;
5
6use super::DriftDecoder;
7pub mod fuel_overflow;
8pub mod high_leverage_mode_config;
9pub mod insurance_fund_stake;
10pub mod openbook_v2_fulfillment_config;
11pub mod perp_market;
12pub mod phoenix_v1_fulfillment_config;
13pub mod prelaunch_oracle;
14pub mod protected_maker_mode_config;
15pub mod protocol_if_shares_transfer_config;
16pub mod pyth_lazer_oracle;
17pub mod referrer_name;
18pub mod serum_v3_fulfillment_config;
19pub mod signed_msg_user_orders;
20pub mod spot_market;
21pub mod state;
22pub mod user;
23pub mod user_stats;
24
25pub enum DriftAccount {
26    OpenbookV2FulfillmentConfig(openbook_v2_fulfillment_config::OpenbookV2FulfillmentConfig),
27    PhoenixV1FulfillmentConfig(phoenix_v1_fulfillment_config::PhoenixV1FulfillmentConfig),
28    SerumV3FulfillmentConfig(serum_v3_fulfillment_config::SerumV3FulfillmentConfig),
29    HighLeverageModeConfig(high_leverage_mode_config::HighLeverageModeConfig),
30    InsuranceFundStake(insurance_fund_stake::InsuranceFundStake),
31    ProtocolIfSharesTransferConfig(
32        protocol_if_shares_transfer_config::ProtocolIfSharesTransferConfig,
33    ),
34    PrelaunchOracle(prelaunch_oracle::PrelaunchOracle),
35    PerpMarket(Box<perp_market::PerpMarket>),
36    ProtectedMakerModeConfig(protected_maker_mode_config::ProtectedMakerModeConfig),
37    PythLazerOracle(pyth_lazer_oracle::PythLazerOracle),
38    SignedMsgUserOrders(signed_msg_user_orders::SignedMsgUserOrders),
39    SpotMarket(Box<spot_market::SpotMarket>),
40    State(Box<state::State>),
41    User(Box<user::User>),
42    UserStats(user_stats::UserStats),
43    ReferrerName(referrer_name::ReferrerName),
44    FuelOverflow(fuel_overflow::FuelOverflow),
45}
46
47impl AccountDecoder<'_> for DriftDecoder {
48    type AccountType = DriftAccount;
49    fn decode_account(
50        &self,
51        account: &solana_account::Account,
52    ) -> Option<carbon_core::account::DecodedAccount<Self::AccountType>> {
53        if !account.owner.eq(&PROGRAM_ID) {
54            return None;
55        }
56
57        if let Some(decoded_account) =
58            openbook_v2_fulfillment_config::OpenbookV2FulfillmentConfig::deserialize(
59                account.data.as_slice(),
60            )
61        {
62            return Some(carbon_core::account::DecodedAccount {
63                lamports: account.lamports,
64                data: DriftAccount::OpenbookV2FulfillmentConfig(decoded_account),
65                owner: account.owner,
66                executable: account.executable,
67                rent_epoch: account.rent_epoch,
68            });
69        }
70
71        if let Some(decoded_account) =
72            phoenix_v1_fulfillment_config::PhoenixV1FulfillmentConfig::deserialize(
73                account.data.as_slice(),
74            )
75        {
76            return Some(carbon_core::account::DecodedAccount {
77                lamports: account.lamports,
78                data: DriftAccount::PhoenixV1FulfillmentConfig(decoded_account),
79                owner: account.owner,
80                executable: account.executable,
81                rent_epoch: account.rent_epoch,
82            });
83        }
84
85        if let Some(decoded_account) =
86            serum_v3_fulfillment_config::SerumV3FulfillmentConfig::deserialize(
87                account.data.as_slice(),
88            )
89        {
90            return Some(carbon_core::account::DecodedAccount {
91                lamports: account.lamports,
92                data: DriftAccount::SerumV3FulfillmentConfig(decoded_account),
93                owner: account.owner,
94                executable: account.executable,
95                rent_epoch: account.rent_epoch,
96            });
97        }
98
99        if let Some(decoded_account) =
100            high_leverage_mode_config::HighLeverageModeConfig::deserialize(account.data.as_slice())
101        {
102            return Some(carbon_core::account::DecodedAccount {
103                lamports: account.lamports,
104                data: DriftAccount::HighLeverageModeConfig(decoded_account),
105                owner: account.owner,
106                executable: account.executable,
107                rent_epoch: account.rent_epoch,
108            });
109        }
110
111        if let Some(decoded_account) =
112            insurance_fund_stake::InsuranceFundStake::deserialize(account.data.as_slice())
113        {
114            return Some(carbon_core::account::DecodedAccount {
115                lamports: account.lamports,
116                data: DriftAccount::InsuranceFundStake(decoded_account),
117                owner: account.owner,
118                executable: account.executable,
119                rent_epoch: account.rent_epoch,
120            });
121        }
122
123        if let Some(decoded_account) =
124            protocol_if_shares_transfer_config::ProtocolIfSharesTransferConfig::deserialize(
125                account.data.as_slice(),
126            )
127        {
128            return Some(carbon_core::account::DecodedAccount {
129                lamports: account.lamports,
130                data: DriftAccount::ProtocolIfSharesTransferConfig(decoded_account),
131                owner: account.owner,
132                executable: account.executable,
133                rent_epoch: account.rent_epoch,
134            });
135        }
136
137        if let Some(decoded_account) =
138            prelaunch_oracle::PrelaunchOracle::deserialize(account.data.as_slice())
139        {
140            return Some(carbon_core::account::DecodedAccount {
141                lamports: account.lamports,
142                data: DriftAccount::PrelaunchOracle(decoded_account),
143                owner: account.owner,
144                executable: account.executable,
145                rent_epoch: account.rent_epoch,
146            });
147        }
148
149        if let Some(decoded_account) = perp_market::PerpMarket::deserialize(account.data.as_slice())
150        {
151            return Some(carbon_core::account::DecodedAccount {
152                lamports: account.lamports,
153                data: DriftAccount::PerpMarket(Box::new(decoded_account)),
154                owner: account.owner,
155                executable: account.executable,
156                rent_epoch: account.rent_epoch,
157            });
158        }
159
160        if let Some(decoded_account) =
161            protected_maker_mode_config::ProtectedMakerModeConfig::deserialize(
162                account.data.as_slice(),
163            )
164        {
165            return Some(carbon_core::account::DecodedAccount {
166                lamports: account.lamports,
167                data: DriftAccount::ProtectedMakerModeConfig(decoded_account),
168                owner: account.owner,
169                executable: account.executable,
170                rent_epoch: account.rent_epoch,
171            });
172        }
173
174        if let Some(decoded_account) =
175            pyth_lazer_oracle::PythLazerOracle::deserialize(account.data.as_slice())
176        {
177            return Some(carbon_core::account::DecodedAccount {
178                lamports: account.lamports,
179                data: DriftAccount::PythLazerOracle(decoded_account),
180                owner: account.owner,
181                executable: account.executable,
182                rent_epoch: account.rent_epoch,
183            });
184        }
185
186        if let Some(decoded_account) =
187            signed_msg_user_orders::SignedMsgUserOrders::deserialize(account.data.as_slice())
188        {
189            return Some(carbon_core::account::DecodedAccount {
190                lamports: account.lamports,
191                data: DriftAccount::SignedMsgUserOrders(decoded_account),
192                owner: account.owner,
193                executable: account.executable,
194                rent_epoch: account.rent_epoch,
195            });
196        }
197
198        if let Some(decoded_account) = spot_market::SpotMarket::deserialize(account.data.as_slice())
199        {
200            return Some(carbon_core::account::DecodedAccount {
201                lamports: account.lamports,
202                data: DriftAccount::SpotMarket(Box::new(decoded_account)),
203                owner: account.owner,
204                executable: account.executable,
205                rent_epoch: account.rent_epoch,
206            });
207        }
208
209        if let Some(decoded_account) = state::State::deserialize(account.data.as_slice()) {
210            return Some(carbon_core::account::DecodedAccount {
211                lamports: account.lamports,
212                data: DriftAccount::State(Box::new(decoded_account)),
213                owner: account.owner,
214                executable: account.executable,
215                rent_epoch: account.rent_epoch,
216            });
217        }
218
219        if let Some(decoded_account) = user::User::deserialize(account.data.as_slice()) {
220            return Some(carbon_core::account::DecodedAccount {
221                lamports: account.lamports,
222                data: DriftAccount::User(Box::new(decoded_account)),
223                owner: account.owner,
224                executable: account.executable,
225                rent_epoch: account.rent_epoch,
226            });
227        }
228
229        if let Some(decoded_account) = user_stats::UserStats::deserialize(account.data.as_slice()) {
230            return Some(carbon_core::account::DecodedAccount {
231                lamports: account.lamports,
232                data: DriftAccount::UserStats(decoded_account),
233                owner: account.owner,
234                executable: account.executable,
235                rent_epoch: account.rent_epoch,
236            });
237        }
238
239        if let Some(decoded_account) =
240            referrer_name::ReferrerName::deserialize(account.data.as_slice())
241        {
242            return Some(carbon_core::account::DecodedAccount {
243                lamports: account.lamports,
244                data: DriftAccount::ReferrerName(decoded_account),
245                owner: account.owner,
246                executable: account.executable,
247                rent_epoch: account.rent_epoch,
248            });
249        }
250
251        if let Some(decoded_account) =
252            fuel_overflow::FuelOverflow::deserialize(account.data.as_slice())
253        {
254            return Some(carbon_core::account::DecodedAccount {
255                lamports: account.lamports,
256                data: DriftAccount::FuelOverflow(decoded_account),
257                owner: account.owner,
258                executable: account.executable,
259                rent_epoch: account.rent_epoch,
260            });
261        }
262
263        None
264    }
265}