Skip to main content

meteora_sol/accounts/
bin_array.rs

1//! This code was AUTOGENERATED using the codama library.
2//! Please DO NOT EDIT THIS FILE, instead use visitors
3//! to add features, then rerun codama to update it.
4//!
5//! <https://github.com/codama-idl/codama>
6//!
7
8use crate::types::Bin;
9use borsh::BorshDeserialize;
10use borsh::BorshSerialize;
11use solana_pubkey::Pubkey;
12
13/// An account to contain a range of bin. For example: Bin 100 <-> 200.
14/// For example:
15/// BinArray index: 0 contains bin 0 <-> 599
16/// index: 2 contains bin 600 <-> 1199, ...
17
18#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)]
19#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
20pub struct BinArray {
21    pub discriminator: [u8; 8],
22    pub index: i64,
23    /// Version of binArray
24    pub version: u8,
25    pub padding: [u8; 7],
26    #[cfg_attr(
27        feature = "serde",
28        serde(with = "serde_with::As::<serde_with::DisplayFromStr>")
29    )]
30    pub lb_pair: Pubkey,
31    #[cfg_attr(feature = "serde", serde(with = "serde_big_array::BigArray"))]
32    pub bins: [Bin; 70],
33}
34
35impl BinArray {
36    pub const LEN: usize = 10136;
37
38    #[inline(always)]
39    pub fn from_bytes(data: &[u8]) -> Result<Self, std::io::Error> {
40        let mut data = data;
41        Self::deserialize(&mut data)
42    }
43}
44
45impl<'a> TryFrom<&solana_account_info::AccountInfo<'a>> for BinArray {
46    type Error = std::io::Error;
47
48    fn try_from(account_info: &solana_account_info::AccountInfo<'a>) -> Result<Self, Self::Error> {
49        let mut data: &[u8] = &(*account_info.data).borrow();
50        Self::deserialize(&mut data)
51    }
52}
53
54#[cfg(feature = "fetch")]
55pub fn fetch_bin_array(
56    rpc: &solana_client::rpc_client::RpcClient,
57    address: &solana_pubkey::Pubkey,
58) -> Result<crate::shared::DecodedAccount<BinArray>, std::io::Error> {
59    let accounts = fetch_all_bin_array(rpc, &[*address])?;
60    Ok(accounts[0].clone())
61}
62
63#[cfg(feature = "fetch")]
64pub fn fetch_all_bin_array(
65    rpc: &solana_client::rpc_client::RpcClient,
66    addresses: &[solana_pubkey::Pubkey],
67) -> Result<Vec<crate::shared::DecodedAccount<BinArray>>, std::io::Error> {
68    let accounts = rpc
69        .get_multiple_accounts(addresses)
70        .map_err(|e| std::io::Error::new(std::io::ErrorKind::Other, e.to_string()))?;
71    let mut decoded_accounts: Vec<crate::shared::DecodedAccount<BinArray>> = Vec::new();
72    for i in 0..addresses.len() {
73        let address = addresses[i];
74        let account = accounts[i].as_ref().ok_or(std::io::Error::new(
75            std::io::ErrorKind::Other,
76            format!("Account not found: {}", address),
77        ))?;
78        let data = BinArray::from_bytes(&account.data)?;
79        decoded_accounts.push(crate::shared::DecodedAccount {
80            address,
81            account: account.clone(),
82            data,
83        });
84    }
85    Ok(decoded_accounts)
86}
87
88#[cfg(feature = "fetch")]
89pub fn fetch_maybe_bin_array(
90    rpc: &solana_client::rpc_client::RpcClient,
91    address: &solana_pubkey::Pubkey,
92) -> Result<crate::shared::MaybeAccount<BinArray>, std::io::Error> {
93    let accounts = fetch_all_maybe_bin_array(rpc, &[*address])?;
94    Ok(accounts[0].clone())
95}
96
97#[cfg(feature = "fetch")]
98pub fn fetch_all_maybe_bin_array(
99    rpc: &solana_client::rpc_client::RpcClient,
100    addresses: &[solana_pubkey::Pubkey],
101) -> Result<Vec<crate::shared::MaybeAccount<BinArray>>, std::io::Error> {
102    let accounts = rpc
103        .get_multiple_accounts(addresses)
104        .map_err(|e| std::io::Error::new(std::io::ErrorKind::Other, e.to_string()))?;
105    let mut decoded_accounts: Vec<crate::shared::MaybeAccount<BinArray>> = Vec::new();
106    for i in 0..addresses.len() {
107        let address = addresses[i];
108        if let Some(account) = accounts[i].as_ref() {
109            let data = BinArray::from_bytes(&account.data)?;
110            decoded_accounts.push(crate::shared::MaybeAccount::Exists(
111                crate::shared::DecodedAccount {
112                    address,
113                    account: account.clone(),
114                    data,
115                },
116            ));
117        } else {
118            decoded_accounts.push(crate::shared::MaybeAccount::NotFound(address));
119        }
120    }
121    Ok(decoded_accounts)
122}
123
124#[cfg(feature = "anchor")]
125impl anchor_lang::AccountDeserialize for BinArray {
126    fn try_deserialize_unchecked(buf: &mut &[u8]) -> anchor_lang::Result<Self> {
127        Ok(Self::deserialize(buf)?)
128    }
129}
130
131#[cfg(feature = "anchor")]
132impl anchor_lang::AccountSerialize for BinArray {}
133
134#[cfg(feature = "anchor")]
135impl anchor_lang::Owner for BinArray {
136    fn owner() -> Pubkey {
137        crate::LB_CLMM_ID
138    }
139}
140
141#[cfg(feature = "anchor-idl-build")]
142impl anchor_lang::IdlBuild for BinArray {}
143
144#[cfg(feature = "anchor-idl-build")]
145impl anchor_lang::Discriminator for BinArray {
146    const DISCRIMINATOR: [u8; 8] = [0; 8];
147}