sendfun_sdk/launchpad/generated/accounts/
global_config.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 borsh::BorshDeserialize;
24use borsh::BorshSerialize;
25use solana_address::Address;
26
27#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)]
28#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
29#[cfg_attr(feature = "serde", serde(rename_all = "camelCase"))]
30pub struct GlobalConfig {
31 pub discriminator: [u8; 8],
32 pub version: u8,
33 pub bump: u8,
34 #[cfg_attr(
35 feature = "serde",
36 serde(with = "serde_with::As::<serde_with::DisplayFromStr>")
37 )]
38 pub authority: Address,
39 #[cfg_attr(
40 feature = "serde",
41 serde(with = "serde_with::As::<serde_with::DisplayFromStr>")
42 )]
43 pub operator: Address,
44 pub create_token_disabled: bool,
45 #[cfg_attr(
46 feature = "serde",
47 serde(with = "serde_with::As::<serde_with::DisplayFromStr>")
48 )]
49 pub normalized_sol_price_cents: u64,
50 #[cfg_attr(
51 feature = "serde",
52 serde(with = "serde_with::As::<serde_with::DisplayFromStr>")
53 )]
54 pub initial_base_supply: u64,
55 #[cfg_attr(
56 feature = "serde",
57 serde(with = "serde_with::As::<serde_with::DisplayFromStr>")
58 )]
59 pub initial_virtual_base_reserves: u64,
60 #[cfg_attr(
61 feature = "serde",
62 serde(with = "serde_with::As::<serde_with::DisplayFromStr>")
63 )]
64 pub initial_real_base_reserves: u64,
65 #[cfg_attr(
66 feature = "serde",
67 serde(with = "serde_with::As::<serde_with::DisplayFromStr>")
68 )]
69 pub initial_virtual_quote_reserves: u64,
70 #[cfg_attr(
71 feature = "serde",
72 serde(with = "serde_with::As::<serde_with::Bytes>")
73 )]
74 pub reserved: [u8; 64],
75}
76
77pub const GLOBAL_CONFIG_DISCRIMINATOR: [u8; 8] =
78 [149, 8, 156, 202, 160, 252, 176, 217];
79
80impl GlobalConfig {
81 pub const LEN: usize = 179;
82
83 #[inline(always)]
84 pub fn from_bytes(data: &[u8]) -> Result<Self, std::io::Error> {
85 if data.get(..GLOBAL_CONFIG_DISCRIMINATOR.len())
86 != Some(&GLOBAL_CONFIG_DISCRIMINATOR[..])
87 {
88 return Err(std::io::Error::new(
89 std::io::ErrorKind::InvalidData,
90 "invalid account discriminator",
91 ));
92 }
93 let mut data = data;
94 Self::deserialize(&mut data)
95 }
96
97 pub fn from_account(
99 owner: &solana_address::Address,
100 data: &[u8],
101 ) -> Result<Self, std::io::Error> {
102 if *owner != crate::launchpad::generated::SEND_LAUNCHPAD_ID {
103 return Err(std::io::Error::new(
104 std::io::ErrorKind::InvalidData,
105 format!(
106 "invalid account owner: {owner}, expected {}",
107 crate::launchpad::generated::SEND_LAUNCHPAD_ID
108 ),
109 ));
110 }
111 Self::from_bytes(data)
112 }
113
114 pub fn from_account_maybe(
116 owner: &solana_address::Address,
117 data: &[u8],
118 ) -> Result<Option<Self>, std::io::Error> {
119 if data.is_empty() && *owner == super::SYSTEM_PROGRAM_ID {
120 return Ok(None);
121 }
122 Self::from_account(owner, data).map(Some)
123 }
124}
125
126impl<'a> TryFrom<&solana_program::account_info::AccountInfo<'a>>
127 for GlobalConfig
128{
129 type Error = std::io::Error;
130
131 fn try_from(
132 account_info: &solana_program::account_info::AccountInfo<'a>,
133 ) -> Result<Self, Self::Error> {
134 if account_info.owner != &crate::launchpad::generated::SEND_LAUNCHPAD_ID
135 {
136 return Err(std::io::Error::new(
137 std::io::ErrorKind::InvalidData,
138 "invalid account owner",
139 ));
140 }
141 let data: &[u8] = &(*account_info.data).borrow();
142 Self::from_bytes(data)
143 }
144}
145
146#[cfg(feature = "anchor")]
147impl anchor_lang::AccountDeserialize for GlobalConfig {
148 fn try_deserialize(buf: &mut &[u8]) -> anchor_lang::Result<Self> {
149 if buf.len() < GLOBAL_CONFIG_DISCRIMINATOR.len()
150 || buf[..GLOBAL_CONFIG_DISCRIMINATOR.len()]
151 != GLOBAL_CONFIG_DISCRIMINATOR[..]
152 {
153 return Err(
154 anchor_lang::error::ErrorCode::AccountDiscriminatorMismatch
155 .into(),
156 );
157 }
158 Self::try_deserialize_unchecked(buf)
159 }
160
161 fn try_deserialize_unchecked(buf: &mut &[u8]) -> anchor_lang::Result<Self> {
162 Ok(Self::deserialize(buf)?)
163 }
164}
165
166#[cfg(feature = "anchor")]
167impl anchor_lang::AccountSerialize for GlobalConfig {}
168
169#[cfg(feature = "anchor")]
170impl anchor_lang::Owner for GlobalConfig {
171 fn owner() -> anchor_lang::solana_program::pubkey::Pubkey {
172 anchor_lang::solana_program::pubkey::Pubkey::from(
173 crate::launchpad::generated::SEND_LAUNCHPAD_ID.to_bytes(),
174 )
175 }
176}
177
178#[cfg(feature = "anchor-idl-build")]
179impl anchor_lang::IdlBuild for GlobalConfig {}
180
181#[cfg(feature = "anchor-idl-build")]
182impl anchor_lang::Discriminator for GlobalConfig {
183 const DISCRIMINATOR: &[u8] = &GLOBAL_CONFIG_DISCRIMINATOR;
184}