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