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