carbon_openbook_v2_decoder/accounts/
mod.rs1use crate::{OpenbookV2Decoder, PROGRAM_ID};
3
4#[cfg(feature = "postgres")]
5pub mod postgres;
6
7#[cfg(feature = "graphql")]
8pub mod graphql;
9
10pub mod book_side;
11pub mod event_heap;
12pub mod market;
13pub mod open_orders_account;
14pub mod open_orders_indexer;
15pub mod stub_oracle;
16
17#[derive(Debug, Clone, PartialEq)]
18#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
19#[cfg_attr(feature = "serde", serde(tag = "type", content = "data"))]
20pub enum OpenbookV2Account {
21 BookSide(Box<book_side::BookSide>),
22 EventHeap(Box<event_heap::EventHeap>),
23 Market(Box<market::Market>),
24 OpenOrdersAccount(Box<open_orders_account::OpenOrdersAccount>),
25 OpenOrdersIndexer(Box<open_orders_indexer::OpenOrdersIndexer>),
26 StubOracle(Box<stub_oracle::StubOracle>),
27}
28
29impl<'a> carbon_core::account::AccountDecoder<'a> for OpenbookV2Decoder {
30 type AccountType = OpenbookV2Account;
31
32 fn decode_account(
33 &self,
34 account: &'a solana_account::Account,
35 ) -> Option<carbon_core::account::DecodedAccount<Self::AccountType>> {
36 if account.owner != PROGRAM_ID {
37 return None;
38 }
39
40 let data = account.data.as_slice();
41
42 {
43 if let Some(decoded) = market::Market::decode(data) {
44 return Some(carbon_core::account::DecodedAccount {
45 lamports: account.lamports,
46 data: OpenbookV2Account::Market(Box::new(decoded)),
47 owner: account.owner,
48 executable: account.executable,
49 rent_epoch: account.rent_epoch,
50 });
51 }
52 }
53 {
54 if let Some(decoded) = open_orders_account::OpenOrdersAccount::decode(data) {
55 return Some(carbon_core::account::DecodedAccount {
56 lamports: account.lamports,
57 data: OpenbookV2Account::OpenOrdersAccount(Box::new(decoded)),
58 owner: account.owner,
59 executable: account.executable,
60 rent_epoch: account.rent_epoch,
61 });
62 }
63 }
64 {
65 if let Some(decoded) = open_orders_indexer::OpenOrdersIndexer::decode(data) {
66 return Some(carbon_core::account::DecodedAccount {
67 lamports: account.lamports,
68 data: OpenbookV2Account::OpenOrdersIndexer(Box::new(decoded)),
69 owner: account.owner,
70 executable: account.executable,
71 rent_epoch: account.rent_epoch,
72 });
73 }
74 }
75 {
76 if let Some(decoded) = stub_oracle::StubOracle::decode(data) {
77 return Some(carbon_core::account::DecodedAccount {
78 lamports: account.lamports,
79 data: OpenbookV2Account::StubOracle(Box::new(decoded)),
80 owner: account.owner,
81 executable: account.executable,
82 rent_epoch: account.rent_epoch,
83 });
84 }
85 }
86 {
87 if let Some(decoded) = book_side::BookSide::decode(data) {
88 return Some(carbon_core::account::DecodedAccount {
89 lamports: account.lamports,
90 data: OpenbookV2Account::BookSide(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) = event_heap::EventHeap::decode(data) {
99 return Some(carbon_core::account::DecodedAccount {
100 lamports: account.lamports,
101 data: OpenbookV2Account::EventHeap(Box::new(decoded)),
102 owner: account.owner,
103 executable: account.executable,
104 rent_epoch: account.rent_epoch,
105 });
106 }
107 }
108
109 None
110 }
111}