1use crate::{DriftV2Decoder, PROGRAM_ID};
3
4#[cfg(feature = "postgres")]
5pub mod postgres;
6
7#[cfg(feature = "graphql")]
8pub mod graphql;
9
10pub mod amm_cache;
11pub mod amm_constituent_mapping;
12pub mod constituent;
13pub mod constituent_correlations;
14pub mod constituent_target_base;
15pub mod fuel_overflow;
16pub mod high_leverage_mode_config;
17pub mod if_rebalance_config;
18pub mod insurance_fund_stake;
19pub mod l_p_pool;
20pub mod openbook_v2_fulfillment_config;
21pub mod perp_market;
22pub mod phoenix_v1_fulfillment_config;
23pub mod prelaunch_oracle;
24pub mod protected_maker_mode_config;
25pub mod protocol_if_shares_transfer_config;
26pub mod pyth_lazer_oracle;
27pub mod referrer_name;
28pub mod revenue_share;
29pub mod revenue_share_escrow;
30pub mod serum_v3_fulfillment_config;
31pub mod signed_msg_user_orders;
32pub mod signed_msg_ws_delegates;
33pub mod spot_market;
34pub mod state;
35pub mod user;
36pub mod user_stats;
37
38#[derive(Debug, Clone, PartialEq)]
39#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
40#[cfg_attr(feature = "serde", serde(tag = "type", content = "data"))]
41pub enum DriftV2Account {
42 AmmCache(Box<amm_cache::AmmCache>),
43 AmmConstituentMapping(Box<amm_constituent_mapping::AmmConstituentMapping>),
44 Constituent(Box<constituent::Constituent>),
45 ConstituentCorrelations(Box<constituent_correlations::ConstituentCorrelations>),
46 ConstituentTargetBase(Box<constituent_target_base::ConstituentTargetBase>),
47 FuelOverflow(Box<fuel_overflow::FuelOverflow>),
48 HighLeverageModeConfig(Box<high_leverage_mode_config::HighLeverageModeConfig>),
49 IfRebalanceConfig(Box<if_rebalance_config::IfRebalanceConfig>),
50 InsuranceFundStake(Box<insurance_fund_stake::InsuranceFundStake>),
51 LPPool(Box<l_p_pool::LPPool>),
52 OpenbookV2FulfillmentConfig(Box<openbook_v2_fulfillment_config::OpenbookV2FulfillmentConfig>),
53 PerpMarket(Box<perp_market::PerpMarket>),
54 PhoenixV1FulfillmentConfig(Box<phoenix_v1_fulfillment_config::PhoenixV1FulfillmentConfig>),
55 PrelaunchOracle(Box<prelaunch_oracle::PrelaunchOracle>),
56 ProtectedMakerModeConfig(Box<protected_maker_mode_config::ProtectedMakerModeConfig>),
57 ProtocolIfSharesTransferConfig(
58 Box<protocol_if_shares_transfer_config::ProtocolIfSharesTransferConfig>,
59 ),
60 PythLazerOracle(Box<pyth_lazer_oracle::PythLazerOracle>),
61 ReferrerName(Box<referrer_name::ReferrerName>),
62 RevenueShare(Box<revenue_share::RevenueShare>),
63 RevenueShareEscrow(Box<revenue_share_escrow::RevenueShareEscrow>),
64 SerumV3FulfillmentConfig(Box<serum_v3_fulfillment_config::SerumV3FulfillmentConfig>),
65 SignedMsgUserOrders(Box<signed_msg_user_orders::SignedMsgUserOrders>),
66 SignedMsgWsDelegates(Box<signed_msg_ws_delegates::SignedMsgWsDelegates>),
67 SpotMarket(Box<spot_market::SpotMarket>),
68 State(Box<state::State>),
69 User(Box<user::User>),
70 UserStats(Box<user_stats::UserStats>),
71}
72
73impl<'a> carbon_core::account::AccountDecoder<'a> for DriftV2Decoder {
74 type AccountType = DriftV2Account;
75
76 fn decode_account(
77 &self,
78 account: &'a solana_account::Account,
79 ) -> Option<carbon_core::account::DecodedAccount<Self::AccountType>> {
80 if account.owner != PROGRAM_ID {
81 return None;
82 }
83
84 let data = account.data.as_slice();
85
86 {
87 if let Some(decoded) = amm_cache::AmmCache::decode(data) {
88 return Some(carbon_core::account::DecodedAccount {
89 lamports: account.lamports,
90 data: DriftV2Account::AmmCache(Box::new(decoded)),
91 owner: account.owner,
92 executable: account.executable,
93 rent_epoch: account.rent_epoch,
94 });
95 }
96 }
97 {
98 if let Some(decoded) =
99 openbook_v2_fulfillment_config::OpenbookV2FulfillmentConfig::decode(data)
100 {
101 return Some(carbon_core::account::DecodedAccount {
102 lamports: account.lamports,
103 data: DriftV2Account::OpenbookV2FulfillmentConfig(Box::new(decoded)),
104 owner: account.owner,
105 executable: account.executable,
106 rent_epoch: account.rent_epoch,
107 });
108 }
109 }
110 {
111 if let Some(decoded) =
112 phoenix_v1_fulfillment_config::PhoenixV1FulfillmentConfig::decode(data)
113 {
114 return Some(carbon_core::account::DecodedAccount {
115 lamports: account.lamports,
116 data: DriftV2Account::PhoenixV1FulfillmentConfig(Box::new(decoded)),
117 owner: account.owner,
118 executable: account.executable,
119 rent_epoch: account.rent_epoch,
120 });
121 }
122 }
123 {
124 if let Some(decoded) =
125 serum_v3_fulfillment_config::SerumV3FulfillmentConfig::decode(data)
126 {
127 return Some(carbon_core::account::DecodedAccount {
128 lamports: account.lamports,
129 data: DriftV2Account::SerumV3FulfillmentConfig(Box::new(decoded)),
130 owner: account.owner,
131 executable: account.executable,
132 rent_epoch: account.rent_epoch,
133 });
134 }
135 }
136 {
137 if let Some(decoded) = high_leverage_mode_config::HighLeverageModeConfig::decode(data) {
138 return Some(carbon_core::account::DecodedAccount {
139 lamports: account.lamports,
140 data: DriftV2Account::HighLeverageModeConfig(Box::new(decoded)),
141 owner: account.owner,
142 executable: account.executable,
143 rent_epoch: account.rent_epoch,
144 });
145 }
146 }
147 {
148 if let Some(decoded) = if_rebalance_config::IfRebalanceConfig::decode(data) {
149 return Some(carbon_core::account::DecodedAccount {
150 lamports: account.lamports,
151 data: DriftV2Account::IfRebalanceConfig(Box::new(decoded)),
152 owner: account.owner,
153 executable: account.executable,
154 rent_epoch: account.rent_epoch,
155 });
156 }
157 }
158 {
159 if let Some(decoded) = insurance_fund_stake::InsuranceFundStake::decode(data) {
160 return Some(carbon_core::account::DecodedAccount {
161 lamports: account.lamports,
162 data: DriftV2Account::InsuranceFundStake(Box::new(decoded)),
163 owner: account.owner,
164 executable: account.executable,
165 rent_epoch: account.rent_epoch,
166 });
167 }
168 }
169 {
170 if let Some(decoded) =
171 protocol_if_shares_transfer_config::ProtocolIfSharesTransferConfig::decode(data)
172 {
173 return Some(carbon_core::account::DecodedAccount {
174 lamports: account.lamports,
175 data: DriftV2Account::ProtocolIfSharesTransferConfig(Box::new(decoded)),
176 owner: account.owner,
177 executable: account.executable,
178 rent_epoch: account.rent_epoch,
179 });
180 }
181 }
182 {
183 if let Some(decoded) = l_p_pool::LPPool::decode(data) {
184 return Some(carbon_core::account::DecodedAccount {
185 lamports: account.lamports,
186 data: DriftV2Account::LPPool(Box::new(decoded)),
187 owner: account.owner,
188 executable: account.executable,
189 rent_epoch: account.rent_epoch,
190 });
191 }
192 }
193 {
194 if let Some(decoded) = constituent::Constituent::decode(data) {
195 return Some(carbon_core::account::DecodedAccount {
196 lamports: account.lamports,
197 data: DriftV2Account::Constituent(Box::new(decoded)),
198 owner: account.owner,
199 executable: account.executable,
200 rent_epoch: account.rent_epoch,
201 });
202 }
203 }
204 {
205 if let Some(decoded) = amm_constituent_mapping::AmmConstituentMapping::decode(data) {
206 return Some(carbon_core::account::DecodedAccount {
207 lamports: account.lamports,
208 data: DriftV2Account::AmmConstituentMapping(Box::new(decoded)),
209 owner: account.owner,
210 executable: account.executable,
211 rent_epoch: account.rent_epoch,
212 });
213 }
214 }
215 {
216 if let Some(decoded) = constituent_target_base::ConstituentTargetBase::decode(data) {
217 return Some(carbon_core::account::DecodedAccount {
218 lamports: account.lamports,
219 data: DriftV2Account::ConstituentTargetBase(Box::new(decoded)),
220 owner: account.owner,
221 executable: account.executable,
222 rent_epoch: account.rent_epoch,
223 });
224 }
225 }
226 {
227 if let Some(decoded) = constituent_correlations::ConstituentCorrelations::decode(data) {
228 return Some(carbon_core::account::DecodedAccount {
229 lamports: account.lamports,
230 data: DriftV2Account::ConstituentCorrelations(Box::new(decoded)),
231 owner: account.owner,
232 executable: account.executable,
233 rent_epoch: account.rent_epoch,
234 });
235 }
236 }
237 {
238 if let Some(decoded) = prelaunch_oracle::PrelaunchOracle::decode(data) {
239 return Some(carbon_core::account::DecodedAccount {
240 lamports: account.lamports,
241 data: DriftV2Account::PrelaunchOracle(Box::new(decoded)),
242 owner: account.owner,
243 executable: account.executable,
244 rent_epoch: account.rent_epoch,
245 });
246 }
247 }
248 {
249 if let Some(decoded) = perp_market::PerpMarket::decode(data) {
250 return Some(carbon_core::account::DecodedAccount {
251 lamports: account.lamports,
252 data: DriftV2Account::PerpMarket(Box::new(decoded)),
253 owner: account.owner,
254 executable: account.executable,
255 rent_epoch: account.rent_epoch,
256 });
257 }
258 }
259 {
260 if let Some(decoded) =
261 protected_maker_mode_config::ProtectedMakerModeConfig::decode(data)
262 {
263 return Some(carbon_core::account::DecodedAccount {
264 lamports: account.lamports,
265 data: DriftV2Account::ProtectedMakerModeConfig(Box::new(decoded)),
266 owner: account.owner,
267 executable: account.executable,
268 rent_epoch: account.rent_epoch,
269 });
270 }
271 }
272 {
273 if let Some(decoded) = pyth_lazer_oracle::PythLazerOracle::decode(data) {
274 return Some(carbon_core::account::DecodedAccount {
275 lamports: account.lamports,
276 data: DriftV2Account::PythLazerOracle(Box::new(decoded)),
277 owner: account.owner,
278 executable: account.executable,
279 rent_epoch: account.rent_epoch,
280 });
281 }
282 }
283 {
284 if let Some(decoded) = revenue_share::RevenueShare::decode(data) {
285 return Some(carbon_core::account::DecodedAccount {
286 lamports: account.lamports,
287 data: DriftV2Account::RevenueShare(Box::new(decoded)),
288 owner: account.owner,
289 executable: account.executable,
290 rent_epoch: account.rent_epoch,
291 });
292 }
293 }
294 {
295 if let Some(decoded) = revenue_share_escrow::RevenueShareEscrow::decode(data) {
296 return Some(carbon_core::account::DecodedAccount {
297 lamports: account.lamports,
298 data: DriftV2Account::RevenueShareEscrow(Box::new(decoded)),
299 owner: account.owner,
300 executable: account.executable,
301 rent_epoch: account.rent_epoch,
302 });
303 }
304 }
305 {
306 if let Some(decoded) = signed_msg_user_orders::SignedMsgUserOrders::decode(data) {
307 return Some(carbon_core::account::DecodedAccount {
308 lamports: account.lamports,
309 data: DriftV2Account::SignedMsgUserOrders(Box::new(decoded)),
310 owner: account.owner,
311 executable: account.executable,
312 rent_epoch: account.rent_epoch,
313 });
314 }
315 }
316 {
317 if let Some(decoded) = signed_msg_ws_delegates::SignedMsgWsDelegates::decode(data) {
318 return Some(carbon_core::account::DecodedAccount {
319 lamports: account.lamports,
320 data: DriftV2Account::SignedMsgWsDelegates(Box::new(decoded)),
321 owner: account.owner,
322 executable: account.executable,
323 rent_epoch: account.rent_epoch,
324 });
325 }
326 }
327 {
328 if let Some(decoded) = spot_market::SpotMarket::decode(data) {
329 return Some(carbon_core::account::DecodedAccount {
330 lamports: account.lamports,
331 data: DriftV2Account::SpotMarket(Box::new(decoded)),
332 owner: account.owner,
333 executable: account.executable,
334 rent_epoch: account.rent_epoch,
335 });
336 }
337 }
338 {
339 if let Some(decoded) = state::State::decode(data) {
340 return Some(carbon_core::account::DecodedAccount {
341 lamports: account.lamports,
342 data: DriftV2Account::State(Box::new(decoded)),
343 owner: account.owner,
344 executable: account.executable,
345 rent_epoch: account.rent_epoch,
346 });
347 }
348 }
349 {
350 if let Some(decoded) = user::User::decode(data) {
351 return Some(carbon_core::account::DecodedAccount {
352 lamports: account.lamports,
353 data: DriftV2Account::User(Box::new(decoded)),
354 owner: account.owner,
355 executable: account.executable,
356 rent_epoch: account.rent_epoch,
357 });
358 }
359 }
360 {
361 if let Some(decoded) = user_stats::UserStats::decode(data) {
362 return Some(carbon_core::account::DecodedAccount {
363 lamports: account.lamports,
364 data: DriftV2Account::UserStats(Box::new(decoded)),
365 owner: account.owner,
366 executable: account.executable,
367 rent_epoch: account.rent_epoch,
368 });
369 }
370 }
371 {
372 if let Some(decoded) = referrer_name::ReferrerName::decode(data) {
373 return Some(carbon_core::account::DecodedAccount {
374 lamports: account.lamports,
375 data: DriftV2Account::ReferrerName(Box::new(decoded)),
376 owner: account.owner,
377 executable: account.executable,
378 rent_epoch: account.rent_epoch,
379 });
380 }
381 }
382 {
383 if let Some(decoded) = fuel_overflow::FuelOverflow::decode(data) {
384 return Some(carbon_core::account::DecodedAccount {
385 lamports: account.lamports,
386 data: DriftV2Account::FuelOverflow(Box::new(decoded)),
387 owner: account.owner,
388 executable: account.executable,
389 rent_epoch: account.rent_epoch,
390 });
391 }
392 }
393
394 None
395 }
396}