Skip to main content

sendfun_sdk/nexus/generated/accounts/
user_stake_position.rs

1#![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
16//! This code was AUTOGENERATED using the codama library.
17//! Please DO NOT EDIT THIS FILE, instead use visitors
18//! to add features, then rerun codama to update it.
19//!
20//! <https://github.com/codama-idl/codama>
21//!
22
23use 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	#[cfg_attr(
52		feature = "serde",
53		serde(with = "serde_with::As::<serde_with::Bytes>")
54	)]
55	pub reserved: [u8; 128],
56}
57
58pub const USER_STAKE_POSITION_DISCRIMINATOR: [u8; 8] =
59	[123, 46, 248, 17, 240, 135, 201, 17];
60
61impl UserStakePosition {
62	pub const LEN: usize = 216;
63
64	#[inline(always)]
65	pub fn from_bytes(data: &[u8]) -> Result<Self, std::io::Error> {
66		if data.get(..USER_STAKE_POSITION_DISCRIMINATOR.len())
67			!= Some(&USER_STAKE_POSITION_DISCRIMINATOR[..])
68		{
69			return Err(std::io::Error::new(
70				std::io::ErrorKind::InvalidData,
71				"invalid account discriminator",
72			));
73		}
74		let mut data = data;
75		Self::deserialize(&mut data)
76	}
77
78	/// Decodes an account read off-chain after checking its owner and discriminator.
79	pub fn from_account(
80		owner: &solana_address::Address,
81		data: &[u8],
82	) -> Result<Self, std::io::Error> {
83		if *owner != crate::nexus::generated::SEND_NEXUS_ID {
84			return Err(std::io::Error::new(
85				std::io::ErrorKind::InvalidData,
86				format!(
87					"invalid account owner: {owner}, expected {}",
88					crate::nexus::generated::SEND_NEXUS_ID
89				),
90			));
91		}
92		Self::from_bytes(data)
93	}
94
95	/// `Ok(None)` for an account that is not created yet: the system program owns it with no data (an address someone sent lamports to).
96	pub fn from_account_maybe(
97		owner: &solana_address::Address,
98		data: &[u8],
99	) -> Result<Option<Self>, std::io::Error> {
100		if data.is_empty() && *owner == super::SYSTEM_PROGRAM_ID {
101			return Ok(None);
102		}
103		Self::from_account(owner, data).map(Some)
104	}
105}
106
107impl<'a> TryFrom<&solana_program::account_info::AccountInfo<'a>>
108	for UserStakePosition
109{
110	type Error = std::io::Error;
111
112	fn try_from(
113		account_info: &solana_program::account_info::AccountInfo<'a>,
114	) -> Result<Self, Self::Error> {
115		if account_info.owner != &crate::nexus::generated::SEND_NEXUS_ID {
116			return Err(std::io::Error::new(
117				std::io::ErrorKind::InvalidData,
118				"invalid account owner",
119			));
120		}
121		let data: &[u8] = &(*account_info.data).borrow();
122		Self::from_bytes(data)
123	}
124}
125
126#[cfg(feature = "anchor")]
127impl anchor_lang::AccountDeserialize for UserStakePosition {
128	fn try_deserialize(buf: &mut &[u8]) -> anchor_lang::Result<Self> {
129		if buf.len() < USER_STAKE_POSITION_DISCRIMINATOR.len()
130			|| buf[..USER_STAKE_POSITION_DISCRIMINATOR.len()]
131				!= USER_STAKE_POSITION_DISCRIMINATOR[..]
132		{
133			return Err(
134				anchor_lang::error::ErrorCode::AccountDiscriminatorMismatch
135					.into(),
136			);
137		}
138		Self::try_deserialize_unchecked(buf)
139	}
140
141	fn try_deserialize_unchecked(buf: &mut &[u8]) -> anchor_lang::Result<Self> {
142		Ok(Self::deserialize(buf)?)
143	}
144}
145
146#[cfg(feature = "anchor")]
147impl anchor_lang::AccountSerialize for UserStakePosition {}
148
149#[cfg(feature = "anchor")]
150impl anchor_lang::Owner for UserStakePosition {
151	fn owner() -> anchor_lang::solana_program::pubkey::Pubkey {
152		anchor_lang::solana_program::pubkey::Pubkey::from(
153			crate::nexus::generated::SEND_NEXUS_ID.to_bytes(),
154		)
155	}
156}
157
158#[cfg(feature = "anchor-idl-build")]
159impl anchor_lang::IdlBuild for UserStakePosition {}
160
161#[cfg(feature = "anchor-idl-build")]
162impl anchor_lang::Discriminator for UserStakePosition {
163	const DISCRIMINATOR: &[u8] = &USER_STAKE_POSITION_DISCRIMINATOR;
164}