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