meteora_sol/accounts/
bin_array_bitmap_extension.rs1use borsh::BorshDeserialize;
9use borsh::BorshSerialize;
10use solana_pubkey::Pubkey;
11
12#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)]
13#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
14pub struct BinArrayBitmapExtension {
15 pub discriminator: [u8; 8],
16 #[cfg_attr(
17 feature = "serde",
18 serde(with = "serde_with::As::<serde_with::DisplayFromStr>")
19 )]
20 pub lb_pair: Pubkey,
21 pub positive_bin_array_bitmap: [[u64; 8]; 12],
23 pub negative_bin_array_bitmap: [[u64; 8]; 12],
25}
26
27impl BinArrayBitmapExtension {
28 pub const LEN: usize = 1576;
29
30 #[inline(always)]
31 pub fn from_bytes(data: &[u8]) -> Result<Self, std::io::Error> {
32 let mut data = data;
33 Self::deserialize(&mut data)
34 }
35}
36
37impl<'a> TryFrom<&solana_account_info::AccountInfo<'a>> for BinArrayBitmapExtension {
38 type Error = std::io::Error;
39
40 fn try_from(account_info: &solana_account_info::AccountInfo<'a>) -> Result<Self, Self::Error> {
41 let mut data: &[u8] = &(*account_info.data).borrow();
42 Self::deserialize(&mut data)
43 }
44}
45
46#[cfg(feature = "fetch")]
47pub fn fetch_bin_array_bitmap_extension(
48 rpc: &solana_client::rpc_client::RpcClient,
49 address: &solana_pubkey::Pubkey,
50) -> Result<crate::shared::DecodedAccount<BinArrayBitmapExtension>, std::io::Error> {
51 let accounts = fetch_all_bin_array_bitmap_extension(rpc, &[*address])?;
52 Ok(accounts[0].clone())
53}
54
55#[cfg(feature = "fetch")]
56pub fn fetch_all_bin_array_bitmap_extension(
57 rpc: &solana_client::rpc_client::RpcClient,
58 addresses: &[solana_pubkey::Pubkey],
59) -> Result<Vec<crate::shared::DecodedAccount<BinArrayBitmapExtension>>, std::io::Error> {
60 let accounts = rpc
61 .get_multiple_accounts(addresses)
62 .map_err(|e| std::io::Error::new(std::io::ErrorKind::Other, e.to_string()))?;
63 let mut decoded_accounts: Vec<crate::shared::DecodedAccount<BinArrayBitmapExtension>> =
64 Vec::new();
65 for i in 0..addresses.len() {
66 let address = addresses[i];
67 let account = accounts[i].as_ref().ok_or(std::io::Error::new(
68 std::io::ErrorKind::Other,
69 format!("Account not found: {}", address),
70 ))?;
71 let data = BinArrayBitmapExtension::from_bytes(&account.data)?;
72 decoded_accounts.push(crate::shared::DecodedAccount {
73 address,
74 account: account.clone(),
75 data,
76 });
77 }
78 Ok(decoded_accounts)
79}
80
81#[cfg(feature = "fetch")]
82pub fn fetch_maybe_bin_array_bitmap_extension(
83 rpc: &solana_client::rpc_client::RpcClient,
84 address: &solana_pubkey::Pubkey,
85) -> Result<crate::shared::MaybeAccount<BinArrayBitmapExtension>, std::io::Error> {
86 let accounts = fetch_all_maybe_bin_array_bitmap_extension(rpc, &[*address])?;
87 Ok(accounts[0].clone())
88}
89
90#[cfg(feature = "fetch")]
91pub fn fetch_all_maybe_bin_array_bitmap_extension(
92 rpc: &solana_client::rpc_client::RpcClient,
93 addresses: &[solana_pubkey::Pubkey],
94) -> Result<Vec<crate::shared::MaybeAccount<BinArrayBitmapExtension>>, std::io::Error> {
95 let accounts = rpc
96 .get_multiple_accounts(addresses)
97 .map_err(|e| std::io::Error::new(std::io::ErrorKind::Other, e.to_string()))?;
98 let mut decoded_accounts: Vec<crate::shared::MaybeAccount<BinArrayBitmapExtension>> =
99 Vec::new();
100 for i in 0..addresses.len() {
101 let address = addresses[i];
102 if let Some(account) = accounts[i].as_ref() {
103 let data = BinArrayBitmapExtension::from_bytes(&account.data)?;
104 decoded_accounts.push(crate::shared::MaybeAccount::Exists(
105 crate::shared::DecodedAccount {
106 address,
107 account: account.clone(),
108 data,
109 },
110 ));
111 } else {
112 decoded_accounts.push(crate::shared::MaybeAccount::NotFound(address));
113 }
114 }
115 Ok(decoded_accounts)
116}
117
118#[cfg(feature = "anchor")]
119impl anchor_lang::AccountDeserialize for BinArrayBitmapExtension {
120 fn try_deserialize_unchecked(buf: &mut &[u8]) -> anchor_lang::Result<Self> {
121 Ok(Self::deserialize(buf)?)
122 }
123}
124
125#[cfg(feature = "anchor")]
126impl anchor_lang::AccountSerialize for BinArrayBitmapExtension {}
127
128#[cfg(feature = "anchor")]
129impl anchor_lang::Owner for BinArrayBitmapExtension {
130 fn owner() -> Pubkey {
131 crate::LB_CLMM_ID
132 }
133}
134
135#[cfg(feature = "anchor-idl-build")]
136impl anchor_lang::IdlBuild for BinArrayBitmapExtension {}
137
138#[cfg(feature = "anchor-idl-build")]
139impl anchor_lang::Discriminator for BinArrayBitmapExtension {
140 const DISCRIMINATOR: [u8; 8] = [0; 8];
141}