Skip to main content

sendfun_sdk/dex/generated/accounts/
pool.rs

1#![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
16//! This code was AUTOGENERATED using the codama library.
17//! Please DO NOT EDIT THIS FILE, instead use visitors
18//! to add features, then rerun codama to update it.
19//!
20//! <https://github.com/codama-idl/codama>
21//!
22
23use 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	/// Decodes an account read off-chain after checking its owner and discriminator.
139	pub fn from_account(
140		owner: &solana_address::Address,
141		data: &[u8],
142	) -> Result<Self, std::io::Error> {
143		if *owner != crate::dex::generated::SEND_DEX_ID {
144			return Err(std::io::Error::new(
145				std::io::ErrorKind::InvalidData,
146				format!(
147					"invalid account owner: {owner}, expected {}",
148					crate::dex::generated::SEND_DEX_ID
149				),
150			));
151		}
152		Self::from_bytes(data)
153	}
154
155	/// `Ok(None)` for an account that is not created yet: the system program owns it with no data (an address someone sent lamports to).
156	pub fn from_account_maybe(
157		owner: &solana_address::Address,
158		data: &[u8],
159	) -> Result<Option<Self>, std::io::Error> {
160		if data.is_empty() && *owner == super::SYSTEM_PROGRAM_ID {
161			return Ok(None);
162		}
163		Self::from_account(owner, data).map(Some)
164	}
165}
166
167impl<'a> TryFrom<&solana_program::account_info::AccountInfo<'a>> for Pool {
168	type Error = std::io::Error;
169
170	fn try_from(
171		account_info: &solana_program::account_info::AccountInfo<'a>,
172	) -> Result<Self, Self::Error> {
173		if account_info.owner != &crate::dex::generated::SEND_DEX_ID {
174			return Err(std::io::Error::new(
175				std::io::ErrorKind::InvalidData,
176				"invalid account owner",
177			));
178		}
179		let data: &[u8] = &(*account_info.data).borrow();
180		Self::from_bytes(data)
181	}
182}
183
184#[cfg(feature = "anchor")]
185impl anchor_lang::AccountDeserialize for Pool {
186	fn try_deserialize(buf: &mut &[u8]) -> anchor_lang::Result<Self> {
187		if buf.len() < POOL_DISCRIMINATOR.len()
188			|| buf[..POOL_DISCRIMINATOR.len()] != POOL_DISCRIMINATOR[..]
189		{
190			return Err(
191				anchor_lang::error::ErrorCode::AccountDiscriminatorMismatch
192					.into(),
193			);
194		}
195		Self::try_deserialize_unchecked(buf)
196	}
197
198	fn try_deserialize_unchecked(buf: &mut &[u8]) -> anchor_lang::Result<Self> {
199		Ok(Self::deserialize(buf)?)
200	}
201}
202
203#[cfg(feature = "anchor")]
204impl anchor_lang::AccountSerialize for Pool {}
205
206#[cfg(feature = "anchor")]
207impl anchor_lang::Owner for Pool {
208	fn owner() -> anchor_lang::solana_program::pubkey::Pubkey {
209		anchor_lang::solana_program::pubkey::Pubkey::from(
210			crate::dex::generated::SEND_DEX_ID.to_bytes(),
211		)
212	}
213}
214
215#[cfg(feature = "anchor-idl-build")]
216impl anchor_lang::IdlBuild for Pool {}
217
218#[cfg(feature = "anchor-idl-build")]
219impl anchor_lang::Discriminator for Pool {
220	const DISCRIMINATOR: &[u8] = &POOL_DISCRIMINATOR;
221}