carbon_sharky_decoder/accounts/
mod.rs1use {
2 super::SharkyDecoder,
3 crate::PROGRAM_ID,
4 carbon_core::{account::AccountDecoder, deserialize::CarbonDeserialize},
5};
6pub mod escrow_pda;
7pub mod loan;
8pub mod nft_list;
9pub mod order_book;
10pub mod program_version;
11
12pub enum SharkyAccount {
13 OrderBook(order_book::OrderBook),
14 Loan(loan::Loan),
15 NftList(nft_list::NftList),
16 EscrowPda(escrow_pda::EscrowPda),
17 ProgramVersion(program_version::ProgramVersion),
18}
19
20impl AccountDecoder<'_> for SharkyDecoder {
21 type AccountType = SharkyAccount;
22 fn decode_account(
23 &self,
24 account: &solana_account::Account,
25 ) -> Option<carbon_core::account::DecodedAccount<Self::AccountType>> {
26 if !account.owner.eq(&PROGRAM_ID) {
27 return None;
28 }
29
30 if let Some(decoded_account) = order_book::OrderBook::deserialize(account.data.as_slice()) {
31 return Some(carbon_core::account::DecodedAccount {
32 lamports: account.lamports,
33 data: SharkyAccount::OrderBook(decoded_account),
34 owner: account.owner,
35 executable: account.executable,
36 rent_epoch: account.rent_epoch,
37 });
38 }
39
40 if let Some(decoded_account) = loan::Loan::deserialize(account.data.as_slice()) {
41 return Some(carbon_core::account::DecodedAccount {
42 lamports: account.lamports,
43 data: SharkyAccount::Loan(decoded_account),
44 owner: account.owner,
45 executable: account.executable,
46 rent_epoch: account.rent_epoch,
47 });
48 }
49
50 if let Some(decoded_account) = nft_list::NftList::deserialize(account.data.as_slice()) {
51 return Some(carbon_core::account::DecodedAccount {
52 lamports: account.lamports,
53 data: SharkyAccount::NftList(decoded_account),
54 owner: account.owner,
55 executable: account.executable,
56 rent_epoch: account.rent_epoch,
57 });
58 }
59
60 if let Some(decoded_account) = escrow_pda::EscrowPda::deserialize(account.data.as_slice()) {
61 return Some(carbon_core::account::DecodedAccount {
62 lamports: account.lamports,
63 data: SharkyAccount::EscrowPda(decoded_account),
64 owner: account.owner,
65 executable: account.executable,
66 rent_epoch: account.rent_epoch,
67 });
68 }
69
70 if let Some(decoded_account) =
71 program_version::ProgramVersion::deserialize(account.data.as_slice())
72 {
73 return Some(carbon_core::account::DecodedAccount {
74 lamports: account.lamports,
75 data: SharkyAccount::ProgramVersion(decoded_account),
76 owner: account.owner,
77 executable: account.executable,
78 rent_epoch: account.rent_epoch,
79 });
80 }
81
82 None
83 }
84}