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 pub padding0: [u64; 4],
54 #[cfg_attr(
55 feature = "serde",
56 serde(with = "serde_with::As::<serde_with::DisplayFromStr>")
57 )]
58 pub base_vault: Address,
59 #[cfg_attr(
60 feature = "serde",
61 serde(with = "serde_with::As::<serde_with::DisplayFromStr>")
62 )]
63 pub quote_vault: Address,
64 #[cfg_attr(
65 feature = "serde",
66 serde(with = "serde_with::As::<serde_with::DisplayFromStr>")
67 )]
68 pub lp_mint: Address,
69 #[cfg_attr(
70 feature = "serde",
71 serde(with = "serde_with::As::<serde_with::DisplayFromStr>")
72 )]
73 pub lp_supply: u64,
74 #[cfg_attr(
75 feature = "serde",
76 serde(with = "serde_with::As::<serde_with::DisplayFromStr>")
77 )]
78 pub base_reserves: u64,
79 #[cfg_attr(
80 feature = "serde",
81 serde(with = "serde_with::As::<serde_with::DisplayFromStr>")
82 )]
83 pub quote_reserves: u64,
84 #[cfg_attr(
85 feature = "serde",
86 serde(with = "serde_with::As::<serde_with::DisplayFromStr>")
87 )]
88 pub quote_ledger: u64,
89 #[cfg_attr(
90 feature = "serde",
91 serde(with = "serde_with::As::<serde_with::DisplayFromStr>")
92 )]
93 pub created_at: i64,
94 #[cfg_attr(
95 feature = "serde",
96 serde(with = "serde_with::As::<serde_with::DisplayFromStr>")
97 )]
98 pub protocol_owed: u64,
99 #[cfg_attr(
100 feature = "serde",
101 serde(with = "serde_with::As::<serde_with::DisplayFromStr>")
102 )]
103 pub creator_owed: u64,
104 #[cfg_attr(
105 feature = "serde",
106 serde(with = "serde_with::As::<serde_with::DisplayFromStr>")
107 )]
108 pub platform_config: Address,
109 pub creator_fee_mode: u8,
110 pub creator_fee_bps: u16,
111 #[cfg_attr(
112 feature = "serde",
113 serde(with = "serde_with::As::<serde_with::Bytes>")
114 )]
115 pub reserved: [u8; 256],
116}
117
118pub const POOL_DISCRIMINATOR: [u8; 8] = [241, 154, 109, 4, 17, 177, 109, 188];
119
120impl Pool {
121 pub const LEN: usize = 584;
122
123 #[inline(always)]
124 pub fn from_bytes(data: &[u8]) -> Result<Self, std::io::Error> {
125 if data.get(..POOL_DISCRIMINATOR.len()) != Some(&POOL_DISCRIMINATOR[..])
126 {
127 return Err(std::io::Error::new(
128 std::io::ErrorKind::InvalidData,
129 "invalid account discriminator",
130 ));
131 }
132 let mut data = data;
133 Self::deserialize(&mut data)
134 }
135
136 pub fn from_account(
138 owner: &solana_address::Address,
139 data: &[u8],
140 ) -> Result<Self, std::io::Error> {
141 if *owner != crate::dex::generated::SEND_DEX_ID {
142 return Err(std::io::Error::new(
143 std::io::ErrorKind::InvalidData,
144 format!(
145 "invalid account owner: {owner}, expected {}",
146 crate::dex::generated::SEND_DEX_ID
147 ),
148 ));
149 }
150 Self::from_bytes(data)
151 }
152
153 pub fn from_account_maybe(
155 owner: &solana_address::Address,
156 data: &[u8],
157 ) -> Result<Option<Self>, std::io::Error> {
158 if data.is_empty() && *owner == super::SYSTEM_PROGRAM_ID {
159 return Ok(None);
160 }
161 Self::from_account(owner, data).map(Some)
162 }
163}
164
165impl<'a> TryFrom<&solana_program::account_info::AccountInfo<'a>> for Pool {
166 type Error = std::io::Error;
167
168 fn try_from(
169 account_info: &solana_program::account_info::AccountInfo<'a>,
170 ) -> Result<Self, Self::Error> {
171 if account_info.owner != &crate::dex::generated::SEND_DEX_ID {
172 return Err(std::io::Error::new(
173 std::io::ErrorKind::InvalidData,
174 "invalid account owner",
175 ));
176 }
177 let data: &[u8] = &(*account_info.data).borrow();
178 Self::from_bytes(data)
179 }
180}
181
182#[cfg(feature = "anchor")]
183impl anchor_lang::AccountDeserialize for Pool {
184 fn try_deserialize(buf: &mut &[u8]) -> anchor_lang::Result<Self> {
185 if buf.len() < POOL_DISCRIMINATOR.len()
186 || buf[..POOL_DISCRIMINATOR.len()] != POOL_DISCRIMINATOR[..]
187 {
188 return Err(
189 anchor_lang::error::ErrorCode::AccountDiscriminatorMismatch
190 .into(),
191 );
192 }
193 Self::try_deserialize_unchecked(buf)
194 }
195
196 fn try_deserialize_unchecked(buf: &mut &[u8]) -> anchor_lang::Result<Self> {
197 Ok(Self::deserialize(buf)?)
198 }
199}
200
201#[cfg(feature = "anchor")]
202impl anchor_lang::AccountSerialize for Pool {}
203
204#[cfg(feature = "anchor")]
205impl anchor_lang::Owner for Pool {
206 fn owner() -> anchor_lang::solana_program::pubkey::Pubkey {
207 anchor_lang::solana_program::pubkey::Pubkey::from(
208 crate::dex::generated::SEND_DEX_ID.to_bytes(),
209 )
210 }
211}
212
213#[cfg(feature = "anchor-idl-build")]
214impl anchor_lang::IdlBuild for Pool {}
215
216#[cfg(feature = "anchor-idl-build")]
217impl anchor_lang::Discriminator for Pool {
218 const DISCRIMINATOR: &[u8] = &POOL_DISCRIMINATOR;
219}