use crate::{OpenbookV2Decoder, PROGRAM_ID};
#[cfg(feature = "postgres")]
pub mod postgres;
#[cfg(feature = "graphql")]
pub mod graphql;
pub mod book_side;
pub mod event_heap;
pub mod market;
pub mod open_orders_account;
pub mod open_orders_indexer;
pub mod stub_oracle;
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(feature = "serde", serde(tag = "type", content = "data"))]
pub enum OpenbookV2Account {
BookSide(Box<book_side::BookSide>),
EventHeap(Box<event_heap::EventHeap>),
Market(Box<market::Market>),
OpenOrdersAccount(Box<open_orders_account::OpenOrdersAccount>),
OpenOrdersIndexer(Box<open_orders_indexer::OpenOrdersIndexer>),
StubOracle(Box<stub_oracle::StubOracle>),
}
impl<'a> carbon_core::account::AccountDecoder<'a> for OpenbookV2Decoder {
type AccountType = OpenbookV2Account;
fn decode_account(
&self,
account: &'a solana_account::Account,
) -> Option<carbon_core::account::DecodedAccount<Self::AccountType>> {
if account.owner != PROGRAM_ID {
return None;
}
let data = account.data.as_slice();
{
if let Some(decoded) = market::Market::decode(data) {
return Some(carbon_core::account::DecodedAccount {
lamports: account.lamports,
data: OpenbookV2Account::Market(Box::new(decoded)),
owner: account.owner,
executable: account.executable,
rent_epoch: account.rent_epoch,
});
}
}
{
if let Some(decoded) = open_orders_account::OpenOrdersAccount::decode(data) {
return Some(carbon_core::account::DecodedAccount {
lamports: account.lamports,
data: OpenbookV2Account::OpenOrdersAccount(Box::new(decoded)),
owner: account.owner,
executable: account.executable,
rent_epoch: account.rent_epoch,
});
}
}
{
if let Some(decoded) = open_orders_indexer::OpenOrdersIndexer::decode(data) {
return Some(carbon_core::account::DecodedAccount {
lamports: account.lamports,
data: OpenbookV2Account::OpenOrdersIndexer(Box::new(decoded)),
owner: account.owner,
executable: account.executable,
rent_epoch: account.rent_epoch,
});
}
}
{
if let Some(decoded) = stub_oracle::StubOracle::decode(data) {
return Some(carbon_core::account::DecodedAccount {
lamports: account.lamports,
data: OpenbookV2Account::StubOracle(Box::new(decoded)),
owner: account.owner,
executable: account.executable,
rent_epoch: account.rent_epoch,
});
}
}
{
if let Some(decoded) = book_side::BookSide::decode(data) {
return Some(carbon_core::account::DecodedAccount {
lamports: account.lamports,
data: OpenbookV2Account::BookSide(Box::new(decoded)),
owner: account.owner,
executable: account.executable,
rent_epoch: account.rent_epoch,
});
}
}
{
if let Some(decoded) = event_heap::EventHeap::decode(data) {
return Some(carbon_core::account::DecodedAccount {
lamports: account.lamports,
data: OpenbookV2Account::EventHeap(Box::new(decoded)),
owner: account.owner,
executable: account.executable,
rent_epoch: account.rent_epoch,
});
}
}
None
}
}