carbon_zeta_decoder/accounts/
mod.rs1use alloc::boxed::Box;
2use carbon_core::account::AccountDecoder;
3use carbon_core::deserialize::CarbonDeserialize;
4
5use crate::PROGRAM_ID;
6
7use super::ZetaDecoder;
8pub mod cross_margin_account;
9pub mod cross_margin_account_manager;
10pub mod cross_open_orders_map;
11pub mod greeks;
12pub mod insurance_deposit_account;
13pub mod margin_account;
14pub mod market_indexes;
15pub mod market_node;
16pub mod open_orders_map;
17pub mod perp_sync_queue;
18pub mod pricing;
19pub mod referrer_id_account;
20pub mod referrer_pubkey_account;
21pub mod settlement_account;
22pub mod socialized_loss_account;
23pub mod spread_account;
24pub mod state;
25pub mod trigger_order;
26pub mod underlying;
27pub mod whitelist_deposit_account;
28pub mod whitelist_insurance_account;
29pub mod whitelist_trading_fees_account;
30pub mod zeta_group;
31
32pub enum ZetaAccount {
33 Pricing(Box<pricing::Pricing>),
34 Greeks(Box<greeks::Greeks>),
35 MarketIndexes(market_indexes::MarketIndexes),
36 OpenOrdersMap(open_orders_map::OpenOrdersMap),
37 CrossOpenOrdersMap(cross_open_orders_map::CrossOpenOrdersMap),
38 State(state::State),
39 Underlying(underlying::Underlying),
40 SettlementAccount(settlement_account::SettlementAccount),
41 PerpSyncQueue(perp_sync_queue::PerpSyncQueue),
42 ZetaGroup(zeta_group::ZetaGroup),
43 MarketNode(market_node::MarketNode),
44 SpreadAccount(spread_account::SpreadAccount),
45 CrossMarginAccountManager(cross_margin_account_manager::CrossMarginAccountManager),
46 CrossMarginAccount(cross_margin_account::CrossMarginAccount),
47 MarginAccount(margin_account::MarginAccount),
48 TriggerOrder(trigger_order::TriggerOrder),
49 SocializedLossAccount(socialized_loss_account::SocializedLossAccount),
50 WhitelistDepositAccount(whitelist_deposit_account::WhitelistDepositAccount),
51 WhitelistInsuranceAccount(whitelist_insurance_account::WhitelistInsuranceAccount),
52 InsuranceDepositAccount(insurance_deposit_account::InsuranceDepositAccount),
53 WhitelistTradingFeesAccount(whitelist_trading_fees_account::WhitelistTradingFeesAccount),
54 ReferrerIdAccount(referrer_id_account::ReferrerIdAccount),
55 ReferrerPubkeyAccount(referrer_pubkey_account::ReferrerPubkeyAccount),
56}
57
58impl AccountDecoder<'_> for ZetaDecoder {
59 type AccountType = ZetaAccount;
60 fn decode_account(
61 &self,
62 account: &solana_account::Account,
63 ) -> Option<carbon_core::account::DecodedAccount<Self::AccountType>> {
64 if !account.owner.eq(&PROGRAM_ID) {
65 return None;
66 }
67
68 if let Some(decoded_account) = pricing::Pricing::deserialize(account.data.as_slice()) {
69 return Some(carbon_core::account::DecodedAccount {
70 lamports: account.lamports,
71 data: ZetaAccount::Pricing(Box::new(decoded_account)),
72 owner: account.owner,
73 executable: account.executable,
74 rent_epoch: account.rent_epoch,
75 });
76 }
77
78 if let Some(decoded_account) = greeks::Greeks::deserialize(account.data.as_slice()) {
79 return Some(carbon_core::account::DecodedAccount {
80 lamports: account.lamports,
81 data: ZetaAccount::Greeks(Box::new(decoded_account)),
82 owner: account.owner,
83 executable: account.executable,
84 rent_epoch: account.rent_epoch,
85 });
86 }
87
88 if let Some(decoded_account) =
89 market_indexes::MarketIndexes::deserialize(account.data.as_slice())
90 {
91 return Some(carbon_core::account::DecodedAccount {
92 lamports: account.lamports,
93 data: ZetaAccount::MarketIndexes(decoded_account),
94 owner: account.owner,
95 executable: account.executable,
96 rent_epoch: account.rent_epoch,
97 });
98 }
99
100 if let Some(decoded_account) =
101 open_orders_map::OpenOrdersMap::deserialize(account.data.as_slice())
102 {
103 return Some(carbon_core::account::DecodedAccount {
104 lamports: account.lamports,
105 data: ZetaAccount::OpenOrdersMap(decoded_account),
106 owner: account.owner,
107 executable: account.executable,
108 rent_epoch: account.rent_epoch,
109 });
110 }
111
112 if let Some(decoded_account) =
113 cross_open_orders_map::CrossOpenOrdersMap::deserialize(account.data.as_slice())
114 {
115 return Some(carbon_core::account::DecodedAccount {
116 lamports: account.lamports,
117 data: ZetaAccount::CrossOpenOrdersMap(decoded_account),
118 owner: account.owner,
119 executable: account.executable,
120 rent_epoch: account.rent_epoch,
121 });
122 }
123
124 if let Some(decoded_account) = state::State::deserialize(account.data.as_slice()) {
125 return Some(carbon_core::account::DecodedAccount {
126 lamports: account.lamports,
127 data: ZetaAccount::State(decoded_account),
128 owner: account.owner,
129 executable: account.executable,
130 rent_epoch: account.rent_epoch,
131 });
132 }
133
134 if let Some(decoded_account) = underlying::Underlying::deserialize(account.data.as_slice())
135 {
136 return Some(carbon_core::account::DecodedAccount {
137 lamports: account.lamports,
138 data: ZetaAccount::Underlying(decoded_account),
139 owner: account.owner,
140 executable: account.executable,
141 rent_epoch: account.rent_epoch,
142 });
143 }
144
145 if let Some(decoded_account) =
146 settlement_account::SettlementAccount::deserialize(account.data.as_slice())
147 {
148 return Some(carbon_core::account::DecodedAccount {
149 lamports: account.lamports,
150 data: ZetaAccount::SettlementAccount(decoded_account),
151 owner: account.owner,
152 executable: account.executable,
153 rent_epoch: account.rent_epoch,
154 });
155 }
156
157 if let Some(decoded_account) =
158 perp_sync_queue::PerpSyncQueue::deserialize(account.data.as_slice())
159 {
160 return Some(carbon_core::account::DecodedAccount {
161 lamports: account.lamports,
162 data: ZetaAccount::PerpSyncQueue(decoded_account),
163 owner: account.owner,
164 executable: account.executable,
165 rent_epoch: account.rent_epoch,
166 });
167 }
168
169 if let Some(decoded_account) = zeta_group::ZetaGroup::deserialize(account.data.as_slice()) {
170 return Some(carbon_core::account::DecodedAccount {
171 lamports: account.lamports,
172 data: ZetaAccount::ZetaGroup(decoded_account),
173 owner: account.owner,
174 executable: account.executable,
175 rent_epoch: account.rent_epoch,
176 });
177 }
178
179 if let Some(decoded_account) = market_node::MarketNode::deserialize(account.data.as_slice())
180 {
181 return Some(carbon_core::account::DecodedAccount {
182 lamports: account.lamports,
183 data: ZetaAccount::MarketNode(decoded_account),
184 owner: account.owner,
185 executable: account.executable,
186 rent_epoch: account.rent_epoch,
187 });
188 }
189
190 if let Some(decoded_account) =
191 spread_account::SpreadAccount::deserialize(account.data.as_slice())
192 {
193 return Some(carbon_core::account::DecodedAccount {
194 lamports: account.lamports,
195 data: ZetaAccount::SpreadAccount(decoded_account),
196 owner: account.owner,
197 executable: account.executable,
198 rent_epoch: account.rent_epoch,
199 });
200 }
201
202 if let Some(decoded_account) =
203 cross_margin_account_manager::CrossMarginAccountManager::deserialize(
204 account.data.as_slice(),
205 )
206 {
207 return Some(carbon_core::account::DecodedAccount {
208 lamports: account.lamports,
209 data: ZetaAccount::CrossMarginAccountManager(decoded_account),
210 owner: account.owner,
211 executable: account.executable,
212 rent_epoch: account.rent_epoch,
213 });
214 }
215
216 if let Some(decoded_account) =
217 cross_margin_account::CrossMarginAccount::deserialize(account.data.as_slice())
218 {
219 return Some(carbon_core::account::DecodedAccount {
220 lamports: account.lamports,
221 data: ZetaAccount::CrossMarginAccount(decoded_account),
222 owner: account.owner,
223 executable: account.executable,
224 rent_epoch: account.rent_epoch,
225 });
226 }
227
228 if let Some(decoded_account) =
229 margin_account::MarginAccount::deserialize(account.data.as_slice())
230 {
231 return Some(carbon_core::account::DecodedAccount {
232 lamports: account.lamports,
233 data: ZetaAccount::MarginAccount(decoded_account),
234 owner: account.owner,
235 executable: account.executable,
236 rent_epoch: account.rent_epoch,
237 });
238 }
239
240 if let Some(decoded_account) =
241 trigger_order::TriggerOrder::deserialize(account.data.as_slice())
242 {
243 return Some(carbon_core::account::DecodedAccount {
244 lamports: account.lamports,
245 data: ZetaAccount::TriggerOrder(decoded_account),
246 owner: account.owner,
247 executable: account.executable,
248 rent_epoch: account.rent_epoch,
249 });
250 }
251
252 if let Some(decoded_account) =
253 socialized_loss_account::SocializedLossAccount::deserialize(account.data.as_slice())
254 {
255 return Some(carbon_core::account::DecodedAccount {
256 lamports: account.lamports,
257 data: ZetaAccount::SocializedLossAccount(decoded_account),
258 owner: account.owner,
259 executable: account.executable,
260 rent_epoch: account.rent_epoch,
261 });
262 }
263
264 if let Some(decoded_account) =
265 whitelist_deposit_account::WhitelistDepositAccount::deserialize(account.data.as_slice())
266 {
267 return Some(carbon_core::account::DecodedAccount {
268 lamports: account.lamports,
269 data: ZetaAccount::WhitelistDepositAccount(decoded_account),
270 owner: account.owner,
271 executable: account.executable,
272 rent_epoch: account.rent_epoch,
273 });
274 }
275
276 if let Some(decoded_account) =
277 whitelist_insurance_account::WhitelistInsuranceAccount::deserialize(
278 account.data.as_slice(),
279 )
280 {
281 return Some(carbon_core::account::DecodedAccount {
282 lamports: account.lamports,
283 data: ZetaAccount::WhitelistInsuranceAccount(decoded_account),
284 owner: account.owner,
285 executable: account.executable,
286 rent_epoch: account.rent_epoch,
287 });
288 }
289
290 if let Some(decoded_account) =
291 insurance_deposit_account::InsuranceDepositAccount::deserialize(account.data.as_slice())
292 {
293 return Some(carbon_core::account::DecodedAccount {
294 lamports: account.lamports,
295 data: ZetaAccount::InsuranceDepositAccount(decoded_account),
296 owner: account.owner,
297 executable: account.executable,
298 rent_epoch: account.rent_epoch,
299 });
300 }
301
302 if let Some(decoded_account) =
303 whitelist_trading_fees_account::WhitelistTradingFeesAccount::deserialize(
304 account.data.as_slice(),
305 )
306 {
307 return Some(carbon_core::account::DecodedAccount {
308 lamports: account.lamports,
309 data: ZetaAccount::WhitelistTradingFeesAccount(decoded_account),
310 owner: account.owner,
311 executable: account.executable,
312 rent_epoch: account.rent_epoch,
313 });
314 }
315
316 if let Some(decoded_account) =
317 referrer_id_account::ReferrerIdAccount::deserialize(account.data.as_slice())
318 {
319 return Some(carbon_core::account::DecodedAccount {
320 lamports: account.lamports,
321 data: ZetaAccount::ReferrerIdAccount(decoded_account),
322 owner: account.owner,
323 executable: account.executable,
324 rent_epoch: account.rent_epoch,
325 });
326 }
327
328 if let Some(decoded_account) =
329 referrer_pubkey_account::ReferrerPubkeyAccount::deserialize(account.data.as_slice())
330 {
331 return Some(carbon_core::account::DecodedAccount {
332 lamports: account.lamports,
333 data: ZetaAccount::ReferrerPubkeyAccount(decoded_account),
334 owner: account.owner,
335 executable: account.executable,
336 rent_epoch: account.rent_epoch,
337 });
338 }
339
340 None
341 }
342}