carbon_gavel_decoder/accounts/
mod.rs1use crate::{GavelDecoder, PROGRAM_ID};
3
4#[cfg(feature = "postgres")]
5pub mod postgres;
6
7#[cfg(feature = "graphql")]
8pub mod graphql;
9
10pub mod lp_position_account;
11pub mod pool_account;
12
13#[derive(Debug, Clone, PartialEq)]
14#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
15#[cfg_attr(feature = "serde", serde(tag = "type", content = "data"))]
16pub enum GavelAccount {
17 LpPositionAccount(Box<lp_position_account::LpPositionAccount>),
18 PoolAccount(Box<pool_account::PoolAccount>),
19}
20
21impl<'a> carbon_core::account::AccountDecoder<'a> for GavelDecoder {
22 type AccountType = GavelAccount;
23
24 fn decode_account(
25 &self,
26 account: &'a solana_account::Account,
27 ) -> Option<carbon_core::account::DecodedAccount<Self::AccountType>> {
28 if account.owner != PROGRAM_ID {
29 return None;
30 }
31
32 let data = account.data.as_slice();
33
34 {
35 if let Some(decoded) = pool_account::PoolAccount::decode(data) {
36 return Some(carbon_core::account::DecodedAccount {
37 lamports: account.lamports,
38 data: GavelAccount::PoolAccount(Box::new(decoded)),
39 owner: account.owner,
40 executable: account.executable,
41 rent_epoch: account.rent_epoch,
42 });
43 }
44 }
45 {
46 if let Some(decoded) = lp_position_account::LpPositionAccount::decode(data) {
47 return Some(carbon_core::account::DecodedAccount {
48 lamports: account.lamports,
49 data: GavelAccount::LpPositionAccount(Box::new(decoded)),
50 owner: account.owner,
51 executable: account.executable,
52 rent_epoch: account.rent_epoch,
53 });
54 }
55 }
56
57 None
58 }
59}