sendfun_sdk/dex/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::Bytes>")
48 )]
49 pub reserved: [u8; 64],
50}
51
52pub const GLOBAL_CONFIG_DISCRIMINATOR: [u8; 8] =
53 [149, 8, 156, 202, 160, 252, 176, 217];
54
55impl GlobalConfig {
56 pub const LEN: usize = 139;
57
58 #[inline(always)]
59 pub fn from_bytes(data: &[u8]) -> Result<Self, std::io::Error> {
60 if data.get(..GLOBAL_CONFIG_DISCRIMINATOR.len())
61 != Some(&GLOBAL_CONFIG_DISCRIMINATOR[..])
62 {
63 return Err(std::io::Error::new(
64 std::io::ErrorKind::InvalidData,
65 "invalid account discriminator",
66 ));
67 }
68 let mut data = data;
69 Self::deserialize(&mut data)
70 }
71
72 pub fn from_account(
74 owner: &solana_address::Address,
75 data: &[u8],
76 ) -> Result<Self, std::io::Error> {
77 if *owner != crate::dex::generated::SEND_DEX_ID {
78 return Err(std::io::Error::new(
79 std::io::ErrorKind::InvalidData,
80 format!(
81 "invalid account owner: {owner}, expected {}",
82 crate::dex::generated::SEND_DEX_ID
83 ),
84 ));
85 }
86 Self::from_bytes(data)
87 }
88
89 pub fn from_account_maybe(
91 owner: &solana_address::Address,
92 data: &[u8],
93 ) -> Result<Option<Self>, std::io::Error> {
94 if data.is_empty() && *owner == super::SYSTEM_PROGRAM_ID {
95 return Ok(None);
96 }
97 Self::from_account(owner, data).map(Some)
98 }
99}
100
101impl<'a> TryFrom<&solana_program::account_info::AccountInfo<'a>>
102 for GlobalConfig
103{
104 type Error = std::io::Error;
105
106 fn try_from(
107 account_info: &solana_program::account_info::AccountInfo<'a>,
108 ) -> Result<Self, Self::Error> {
109 if account_info.owner != &crate::dex::generated::SEND_DEX_ID {
110 return Err(std::io::Error::new(
111 std::io::ErrorKind::InvalidData,
112 "invalid account owner",
113 ));
114 }
115 let data: &[u8] = &(*account_info.data).borrow();
116 Self::from_bytes(data)
117 }
118}
119
120#[cfg(feature = "anchor")]
121impl anchor_lang::AccountDeserialize for GlobalConfig {
122 fn try_deserialize(buf: &mut &[u8]) -> anchor_lang::Result<Self> {
123 if buf.len() < GLOBAL_CONFIG_DISCRIMINATOR.len()
124 || buf[..GLOBAL_CONFIG_DISCRIMINATOR.len()]
125 != GLOBAL_CONFIG_DISCRIMINATOR[..]
126 {
127 return Err(
128 anchor_lang::error::ErrorCode::AccountDiscriminatorMismatch
129 .into(),
130 );
131 }
132 Self::try_deserialize_unchecked(buf)
133 }
134
135 fn try_deserialize_unchecked(buf: &mut &[u8]) -> anchor_lang::Result<Self> {
136 Ok(Self::deserialize(buf)?)
137 }
138}
139
140#[cfg(feature = "anchor")]
141impl anchor_lang::AccountSerialize for GlobalConfig {}
142
143#[cfg(feature = "anchor")]
144impl anchor_lang::Owner for GlobalConfig {
145 fn owner() -> anchor_lang::solana_program::pubkey::Pubkey {
146 anchor_lang::solana_program::pubkey::Pubkey::from(
147 crate::dex::generated::SEND_DEX_ID.to_bytes(),
148 )
149 }
150}
151
152#[cfg(feature = "anchor-idl-build")]
153impl anchor_lang::IdlBuild for GlobalConfig {}
154
155#[cfg(feature = "anchor-idl-build")]
156impl anchor_lang::Discriminator for GlobalConfig {
157 const DISCRIMINATOR: &[u8] = &GLOBAL_CONFIG_DISCRIMINATOR;
158}