defituna_staking/generated/accounts/
position.rs1use borsh::BorshSerialize;
9use borsh::BorshDeserialize;
10
11
12#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)]
13#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
14pub struct Position {
15pub discriminator: [u8; 8],
16pub version: u8,
18pub shares: u64,
20pub unstake_timestamp: u64,
22pub pending_withdrawal_amount: u64,
24pub reward_debt: u64,
26pub unclaimed_reward: u64,
28pub reserved: [u8; 32],
30}
31
32
33impl Position {
34 pub const LEN: usize = 81;
35
36
37
38 #[inline(always)]
39 pub fn from_bytes(data: &[u8]) -> Result<Self, std::io::Error> {
40 let mut data = data;
41 Self::deserialize(&mut data)
42 }
43}
44
45impl<'a> TryFrom<&solana_account_info::AccountInfo<'a>> for Position {
46 type Error = std::io::Error;
47
48 fn try_from(account_info: &solana_account_info::AccountInfo<'a>) -> Result<Self, Self::Error> {
49 let mut data: &[u8] = &(*account_info.data).borrow();
50 Self::deserialize(&mut data)
51 }
52}
53
54#[cfg(feature = "fetch")]
55pub fn fetch_position(
56 rpc: &solana_client::rpc_client::RpcClient,
57 address: &solana_pubkey::Pubkey,
58) -> Result<crate::shared::DecodedAccount<Position>, std::io::Error> {
59 let accounts = fetch_all_position(rpc, &[*address])?;
60 Ok(accounts[0].clone())
61}
62
63#[cfg(feature = "fetch")]
64pub fn fetch_all_position(
65 rpc: &solana_client::rpc_client::RpcClient,
66 addresses: &[solana_pubkey::Pubkey],
67) -> Result<Vec<crate::shared::DecodedAccount<Position>>, std::io::Error> {
68 let accounts = rpc.get_multiple_accounts(addresses)
69 .map_err(|e| std::io::Error::new(std::io::ErrorKind::Other, e.to_string()))?;
70 let mut decoded_accounts: Vec<crate::shared::DecodedAccount<Position>> = Vec::new();
71 for i in 0..addresses.len() {
72 let address = addresses[i];
73 let account = accounts[i].as_ref()
74 .ok_or(std::io::Error::new(std::io::ErrorKind::Other, format!("Account not found: {}", address)))?;
75 let data = Position::from_bytes(&account.data)?;
76 decoded_accounts.push(crate::shared::DecodedAccount { address, account: account.clone(), data });
77 }
78 Ok(decoded_accounts)
79}
80
81#[cfg(feature = "fetch")]
82pub fn fetch_maybe_position(
83 rpc: &solana_client::rpc_client::RpcClient,
84 address: &solana_pubkey::Pubkey,
85) -> Result<crate::shared::MaybeAccount<Position>, std::io::Error> {
86 let accounts = fetch_all_maybe_position(rpc, &[*address])?;
87 Ok(accounts[0].clone())
88}
89
90#[cfg(feature = "fetch")]
91pub fn fetch_all_maybe_position(
92 rpc: &solana_client::rpc_client::RpcClient,
93 addresses: &[solana_pubkey::Pubkey],
94) -> Result<Vec<crate::shared::MaybeAccount<Position>>, std::io::Error> {
95 let accounts = rpc.get_multiple_accounts(addresses)
96 .map_err(|e| std::io::Error::new(std::io::ErrorKind::Other, e.to_string()))?;
97 let mut decoded_accounts: Vec<crate::shared::MaybeAccount<Position>> = Vec::new();
98 for i in 0..addresses.len() {
99 let address = addresses[i];
100 if let Some(account) = accounts[i].as_ref() {
101 let data = Position::from_bytes(&account.data)?;
102 decoded_accounts.push(crate::shared::MaybeAccount::Exists(crate::shared::DecodedAccount { address, account: account.clone(), data }));
103 } else {
104 decoded_accounts.push(crate::shared::MaybeAccount::NotFound(address));
105 }
106 }
107 Ok(decoded_accounts)
108}
109
110 #[cfg(feature = "anchor")]
111 impl anchor_lang::AccountDeserialize for Position {
112 fn try_deserialize_unchecked(buf: &mut &[u8]) -> anchor_lang::Result<Self> {
113 Ok(Self::deserialize(buf)?)
114 }
115 }
116
117 #[cfg(feature = "anchor")]
118 impl anchor_lang::AccountSerialize for Position {}
119
120 #[cfg(feature = "anchor")]
121 impl anchor_lang::Owner for Position {
122 fn owner() -> Pubkey {
123 crate::TUNA_STAKING_ID
124 }
125 }
126
127 #[cfg(feature = "anchor-idl-build")]
128 impl anchor_lang::IdlBuild for Position {}
129
130
131 #[cfg(feature = "anchor-idl-build")]
132 impl anchor_lang::Discriminator for Position {
133 const DISCRIMINATOR: [u8; 8] = [0; 8];
134 }
135