orca_sol/accounts/
tick_array.rs1use crate::types::Tick;
9use borsh::BorshDeserialize;
10use borsh::BorshSerialize;
11use solana_pubkey::Pubkey;
12
13#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)]
14#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
15pub struct TickArray {
16 pub discriminator: [u8; 8],
17 pub start_tick_index: i32,
18 #[cfg_attr(feature = "serde", serde(with = "serde_big_array::BigArray"))]
19 pub ticks: [Tick; 88],
20 #[cfg_attr(
21 feature = "serde",
22 serde(with = "serde_with::As::<serde_with::DisplayFromStr>")
23 )]
24 pub whirlpool: Pubkey,
25}
26
27impl TickArray {
28 pub const LEN: usize = 9988;
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 TickArray {
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_tick_array(
48 rpc: &solana_client::rpc_client::RpcClient,
49 address: &solana_pubkey::Pubkey,
50) -> Result<crate::shared::DecodedAccount<TickArray>, std::io::Error> {
51 let accounts = fetch_all_tick_array(rpc, &[*address])?;
52 Ok(accounts[0].clone())
53}
54
55#[cfg(feature = "fetch")]
56pub fn fetch_all_tick_array(
57 rpc: &solana_client::rpc_client::RpcClient,
58 addresses: &[solana_pubkey::Pubkey],
59) -> Result<Vec<crate::shared::DecodedAccount<TickArray>>, 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<TickArray>> = Vec::new();
64 for i in 0..addresses.len() {
65 let address = addresses[i];
66 let account = accounts[i].as_ref().ok_or(std::io::Error::new(
67 std::io::ErrorKind::Other,
68 format!("Account not found: {}", address),
69 ))?;
70 let data = TickArray::from_bytes(&account.data)?;
71 decoded_accounts.push(crate::shared::DecodedAccount {
72 address,
73 account: account.clone(),
74 data,
75 });
76 }
77 Ok(decoded_accounts)
78}
79
80#[cfg(feature = "fetch")]
81pub fn fetch_maybe_tick_array(
82 rpc: &solana_client::rpc_client::RpcClient,
83 address: &solana_pubkey::Pubkey,
84) -> Result<crate::shared::MaybeAccount<TickArray>, std::io::Error> {
85 let accounts = fetch_all_maybe_tick_array(rpc, &[*address])?;
86 Ok(accounts[0].clone())
87}
88
89#[cfg(feature = "fetch")]
90pub fn fetch_all_maybe_tick_array(
91 rpc: &solana_client::rpc_client::RpcClient,
92 addresses: &[solana_pubkey::Pubkey],
93) -> Result<Vec<crate::shared::MaybeAccount<TickArray>>, std::io::Error> {
94 let accounts = rpc
95 .get_multiple_accounts(addresses)
96 .map_err(|e| std::io::Error::new(std::io::ErrorKind::Other, e.to_string()))?;
97 let mut decoded_accounts: Vec<crate::shared::MaybeAccount<TickArray>> = Vec::new();
98 for i in 0..addresses.len() {
99 let address = addresses[i];
100 if let Some(account) = accounts[i].as_ref() {
101 let data = TickArray::from_bytes(&account.data)?;
102 decoded_accounts.push(crate::shared::MaybeAccount::Exists(
103 crate::shared::DecodedAccount {
104 address,
105 account: account.clone(),
106 data,
107 },
108 ));
109 } else {
110 decoded_accounts.push(crate::shared::MaybeAccount::NotFound(address));
111 }
112 }
113 Ok(decoded_accounts)
114}
115
116#[cfg(feature = "anchor")]
117impl anchor_lang::AccountDeserialize for TickArray {
118 fn try_deserialize_unchecked(buf: &mut &[u8]) -> anchor_lang::Result<Self> {
119 Ok(Self::deserialize(buf)?)
120 }
121}
122
123#[cfg(feature = "anchor")]
124impl anchor_lang::AccountSerialize for TickArray {}
125
126#[cfg(feature = "anchor")]
127impl anchor_lang::Owner for TickArray {
128 fn owner() -> Pubkey {
129 crate::WHIRLPOOL_ID
130 }
131}
132
133#[cfg(feature = "anchor-idl-build")]
134impl anchor_lang::IdlBuild for TickArray {}
135
136#[cfg(feature = "anchor-idl-build")]
137impl anchor_lang::Discriminator for TickArray {
138 const DISCRIMINATOR: [u8; 8] = [0; 8];
139}