sendfun_sdk/dex/generated/accounts/
pool.rs1#![allow(
2 clippy::all,
3 clippy::pedantic,
4 clippy::nursery,
5 clippy::expect_used,
6 clippy::unwrap_used,
7 clippy::indexing_slicing,
8 clippy::allow_attributes,
9 clippy::allow_attributes_without_reason,
10 clippy::mem_forget,
11 unfulfilled_lint_expectations,
12 unexpected_cfgs,
13 unused_imports
14)]
15
16use crate::dex::generated::types::PoolStatus;
24use borsh::BorshDeserialize;
25use borsh::BorshSerialize;
26use solana_address::Address;
27
28#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)]
29#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
30#[cfg_attr(feature = "serde", serde(rename_all = "camelCase"))]
31pub struct Pool {
32 pub discriminator: [u8; 8],
33 pub version: u8,
34 pub bump: u8,
35 pub status: PoolStatus,
36 #[cfg_attr(
37 feature = "serde",
38 serde(with = "serde_with::As::<serde_with::DisplayFromStr>")
39 )]
40 pub base_mint: Address,
41 pub base_decimals: u8,
42 #[cfg_attr(
43 feature = "serde",
44 serde(with = "serde_with::As::<serde_with::DisplayFromStr>")
45 )]
46 pub quote_mint: Address,
47 pub quote_decimals: u8,
48 #[cfg_attr(
49 feature = "serde",
50 serde(with = "serde_with::As::<serde_with::DisplayFromStr>")
51 )]
52 pub coin_creator: Address,
53 #[cfg_attr(
54 feature = "serde",
55 serde(with = "serde_with::As::<serde_with::DisplayFromStr>")
56 )]
57 pub creator_fee_config: Address,
58 #[cfg_attr(
59 feature = "serde",
60 serde(with = "serde_with::As::<serde_with::DisplayFromStr>")
61 )]
62 pub base_vault: Address,
63 #[cfg_attr(
64 feature = "serde",
65 serde(with = "serde_with::As::<serde_with::DisplayFromStr>")
66 )]
67 pub quote_vault: Address,
68 #[cfg_attr(
69 feature = "serde",
70 serde(with = "serde_with::As::<serde_with::DisplayFromStr>")
71 )]
72 pub lp_mint: Address,
73 #[cfg_attr(
74 feature = "serde",
75 serde(with = "serde_with::As::<serde_with::DisplayFromStr>")
76 )]
77 pub lp_supply: u64,
78 #[cfg_attr(
79 feature = "serde",
80 serde(with = "serde_with::As::<serde_with::DisplayFromStr>")
81 )]
82 pub base_reserves: u64,
83 #[cfg_attr(
84 feature = "serde",
85 serde(with = "serde_with::As::<serde_with::DisplayFromStr>")
86 )]
87 pub quote_reserves: u64,
88 #[cfg_attr(
89 feature = "serde",
90 serde(with = "serde_with::As::<serde_with::DisplayFromStr>")
91 )]
92 pub quote_ledger: u64,
93 #[cfg_attr(
94 feature = "serde",
95 serde(with = "serde_with::As::<serde_with::DisplayFromStr>")
96 )]
97 pub created_at: i64,
98 #[cfg_attr(
99 feature = "serde",
100 serde(with = "serde_with::As::<serde_with::DisplayFromStr>")
101 )]
102 pub protocol_owed: u64,
103 #[cfg_attr(
104 feature = "serde",
105 serde(with = "serde_with::As::<serde_with::DisplayFromStr>")
106 )]
107 pub creator_owed: u64,
108 #[cfg_attr(
109 feature = "serde",
110 serde(with = "serde_with::As::<serde_with::DisplayFromStr>")
111 )]
112 pub platform_config: Address,
113 #[cfg_attr(
114 feature = "serde",
115 serde(with = "serde_with::As::<serde_with::Bytes>")
116 )]
117 pub reserved: [u8; 64],
118}
119
120pub const POOL_DISCRIMINATOR: [u8; 8] = [241, 154, 109, 4, 17, 177, 109, 188];
121
122impl Pool {
123 pub const LEN: usize = 389;
124
125 #[inline(always)]
126 pub fn from_bytes(data: &[u8]) -> Result<Self, std::io::Error> {
127 if data.get(..POOL_DISCRIMINATOR.len()) != Some(&POOL_DISCRIMINATOR[..])
128 {
129 return Err(std::io::Error::new(
130 std::io::ErrorKind::InvalidData,
131 "invalid account discriminator",
132 ));
133 }
134 let mut data = data;
135 Self::deserialize(&mut data)
136 }
137}
138
139impl<'a> TryFrom<&solana_program::account_info::AccountInfo<'a>> for Pool {
140 type Error = std::io::Error;
141
142 fn try_from(
143 account_info: &solana_program::account_info::AccountInfo<'a>,
144 ) -> Result<Self, Self::Error> {
145 if account_info.owner != &crate::dex::generated::SEND_DEX_ID {
146 return Err(std::io::Error::new(
147 std::io::ErrorKind::InvalidData,
148 "invalid account owner",
149 ));
150 }
151 let data: &[u8] = &(*account_info.data).borrow();
152 Self::from_bytes(data)
153 }
154}
155
156#[cfg(feature = "fetch")]
157pub fn fetch_pool(
158 rpc: &solana_rpc_client::rpc_client::RpcClient,
159 address: &solana_address::Address,
160) -> Result<crate::dex::generated::shared::DecodedAccount<Pool>, std::io::Error>
161{
162 let accounts = fetch_all_pool(rpc, &[*address])?;
163 Ok(accounts[0].clone())
164}
165
166#[cfg(feature = "fetch")]
167pub fn fetch_all_pool(
168 rpc: &solana_rpc_client::rpc_client::RpcClient,
169 addresses: &[solana_address::Address],
170) -> Result<
171 Vec<crate::dex::generated::shared::DecodedAccount<Pool>>,
172 std::io::Error,
173> {
174 let accounts = rpc
175 .get_multiple_accounts(addresses)
176 .map_err(|e| std::io::Error::other(e.to_string()))?;
177 let mut decoded_accounts: Vec<
178 crate::dex::generated::shared::DecodedAccount<Pool>,
179 > = Vec::new();
180 for i in 0..addresses.len() {
181 let address = addresses[i];
182 let account = accounts[i].as_ref().ok_or(std::io::Error::other(
183 format!("Account not found: {address}"),
184 ))?;
185 if account.owner != crate::dex::generated::SEND_DEX_ID {
186 return Err(std::io::Error::other(format!(
187 "Invalid owner for account: {address}"
188 )));
189 }
190 let data = Pool::from_bytes(&account.data)?;
191 decoded_accounts.push(crate::dex::generated::shared::DecodedAccount {
192 address,
193 account: account.clone(),
194 data,
195 });
196 }
197 Ok(decoded_accounts)
198}
199
200#[cfg(feature = "fetch")]
201pub fn fetch_maybe_pool(
202 rpc: &solana_rpc_client::rpc_client::RpcClient,
203 address: &solana_address::Address,
204) -> Result<crate::dex::generated::shared::MaybeAccount<Pool>, std::io::Error> {
205 let accounts = fetch_all_maybe_pool(rpc, &[*address])?;
206 Ok(accounts[0].clone())
207}
208
209#[cfg(feature = "fetch")]
210pub fn fetch_all_maybe_pool(
211 rpc: &solana_rpc_client::rpc_client::RpcClient,
212 addresses: &[solana_address::Address],
213) -> Result<
214 Vec<crate::dex::generated::shared::MaybeAccount<Pool>>,
215 std::io::Error,
216> {
217 let accounts = rpc
218 .get_multiple_accounts(addresses)
219 .map_err(|e| std::io::Error::other(e.to_string()))?;
220 let mut decoded_accounts: Vec<
221 crate::dex::generated::shared::MaybeAccount<Pool>,
222 > = Vec::new();
223 for i in 0..addresses.len() {
224 let address = addresses[i];
225 if let Some(account) = accounts[i].as_ref() {
226 if account.owner != crate::dex::generated::SEND_DEX_ID {
227 return Err(std::io::Error::other(format!(
228 "Invalid owner for account: {address}"
229 )));
230 }
231 let data = Pool::from_bytes(&account.data)?;
232 decoded_accounts.push(
233 crate::dex::generated::shared::MaybeAccount::Exists(
234 crate::dex::generated::shared::DecodedAccount {
235 address,
236 account: account.clone(),
237 data,
238 },
239 ),
240 );
241 } else {
242 decoded_accounts.push(
243 crate::dex::generated::shared::MaybeAccount::NotFound(address),
244 );
245 }
246 }
247 Ok(decoded_accounts)
248}
249
250#[cfg(feature = "anchor")]
251impl anchor_lang::AccountDeserialize for Pool {
252 fn try_deserialize(buf: &mut &[u8]) -> anchor_lang::Result<Self> {
253 if buf.len() < POOL_DISCRIMINATOR.len()
254 || buf[..POOL_DISCRIMINATOR.len()] != POOL_DISCRIMINATOR[..]
255 {
256 return Err(
257 anchor_lang::error::ErrorCode::AccountDiscriminatorMismatch
258 .into(),
259 );
260 }
261 Self::try_deserialize_unchecked(buf)
262 }
263
264 fn try_deserialize_unchecked(buf: &mut &[u8]) -> anchor_lang::Result<Self> {
265 Ok(Self::deserialize(buf)?)
266 }
267}
268
269#[cfg(feature = "anchor")]
270impl anchor_lang::AccountSerialize for Pool {}
271
272#[cfg(feature = "anchor")]
273impl anchor_lang::Owner for Pool {
274 fn owner() -> anchor_lang::solana_program::pubkey::Pubkey {
275 anchor_lang::solana_program::pubkey::Pubkey::from(
276 crate::dex::generated::SEND_DEX_ID.to_bytes(),
277 )
278 }
279}
280
281#[cfg(feature = "anchor-idl-build")]
282impl anchor_lang::IdlBuild for Pool {}
283
284#[cfg(feature = "anchor-idl-build")]
285impl anchor_lang::Discriminator for Pool {
286 const DISCRIMINATOR: &[u8] = &POOL_DISCRIMINATOR;
287}