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