defituna_staking/generated/accounts/
position.rs

1//! This code was AUTOGENERATED using the codama library.
2//! Please DO NOT EDIT THIS FILE, instead use visitors
3//! to add features, then rerun codama to update it.
4//!
5//! <https://github.com/codama-idl/codama>
6//!
7
8use 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],
16/// Struct version
17pub version: u8,
18/// The amount of staked tokens (shares) provided by the user
19pub shares: u64,
20/// Last unstake timestamp
21pub unstake_timestamp: u64,
22/// The amount of tokens that the user can withdraw
23pub pending_withdrawal_amount: u64,
24/// Reward debt
25pub reward_debt: u64,
26/// Unclaimed reward
27pub unclaimed_reward: u64,
28/// Reserved
29pub 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