defituna_staking/generated/accounts/
vesting_strategy.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 VestingStrategy {
15pub discriminator: [u8; 8],
16/// Struct version
17pub version: u16,
18/// Vesting strategy (not used, should be zero)
19pub strategy: u8,
20/// The amount of locked shares
21pub locked_shares: u64,
22/// The amount of shares to unlock per lock period
23pub unlock_rate: u64,
24/// The token unlock period in hours, after which N tokens will be unlocked.
25pub unlock_period: u16,
26/// The timestamp when the position has been locked
27pub lock_timestamp: u64,
28/// The period in hours after which the unlock starts. The first unlock occurs after 'cliff + unlock_period'.
29pub cliff: u16,
30/// Reserved
31#[cfg_attr(feature = "serde", serde(with = "serde_with::As::<serde_with::Bytes>"))]
32pub reserved: [u8; 62],
33}
34
35
36impl VestingStrategy {
37      pub const LEN: usize = 101;
38  
39  
40  
41  #[inline(always)]
42  pub fn from_bytes(data: &[u8]) -> Result<Self, std::io::Error> {
43    let mut data = data;
44    Self::deserialize(&mut data)
45  }
46}
47
48impl<'a> TryFrom<&solana_account_info::AccountInfo<'a>> for VestingStrategy {
49  type Error = std::io::Error;
50
51  fn try_from(account_info: &solana_account_info::AccountInfo<'a>) -> Result<Self, Self::Error> {
52      let mut data: &[u8] = &(*account_info.data).borrow();
53      Self::deserialize(&mut data)
54  }
55}
56
57#[cfg(feature = "fetch")]
58pub fn fetch_vesting_strategy(
59  rpc: &solana_client::rpc_client::RpcClient,
60  address: &solana_pubkey::Pubkey,
61) -> Result<crate::shared::DecodedAccount<VestingStrategy>, std::io::Error> {
62  let accounts = fetch_all_vesting_strategy(rpc, &[*address])?;
63  Ok(accounts[0].clone())
64}
65
66#[cfg(feature = "fetch")]
67pub fn fetch_all_vesting_strategy(
68  rpc: &solana_client::rpc_client::RpcClient,
69  addresses: &[solana_pubkey::Pubkey],
70) -> Result<Vec<crate::shared::DecodedAccount<VestingStrategy>>, std::io::Error> {
71    let accounts = rpc.get_multiple_accounts(addresses)
72      .map_err(|e| std::io::Error::new(std::io::ErrorKind::Other, e.to_string()))?;
73    let mut decoded_accounts: Vec<crate::shared::DecodedAccount<VestingStrategy>> = Vec::new();
74    for i in 0..addresses.len() {
75      let address = addresses[i];
76      let account = accounts[i].as_ref()
77        .ok_or(std::io::Error::new(std::io::ErrorKind::Other, format!("Account not found: {}", address)))?;
78      let data = VestingStrategy::from_bytes(&account.data)?;
79      decoded_accounts.push(crate::shared::DecodedAccount { address, account: account.clone(), data });
80    }
81    Ok(decoded_accounts)
82}
83
84#[cfg(feature = "fetch")]
85pub fn fetch_maybe_vesting_strategy(
86  rpc: &solana_client::rpc_client::RpcClient,
87  address: &solana_pubkey::Pubkey,
88) -> Result<crate::shared::MaybeAccount<VestingStrategy>, std::io::Error> {
89    let accounts = fetch_all_maybe_vesting_strategy(rpc, &[*address])?;
90    Ok(accounts[0].clone())
91}
92
93#[cfg(feature = "fetch")]
94pub fn fetch_all_maybe_vesting_strategy(
95  rpc: &solana_client::rpc_client::RpcClient,
96  addresses: &[solana_pubkey::Pubkey],
97) -> Result<Vec<crate::shared::MaybeAccount<VestingStrategy>>, std::io::Error> {
98    let accounts = rpc.get_multiple_accounts(addresses)
99      .map_err(|e| std::io::Error::new(std::io::ErrorKind::Other, e.to_string()))?;
100    let mut decoded_accounts: Vec<crate::shared::MaybeAccount<VestingStrategy>> = Vec::new();
101    for i in 0..addresses.len() {
102      let address = addresses[i];
103      if let Some(account) = accounts[i].as_ref() {
104        let data = VestingStrategy::from_bytes(&account.data)?;
105        decoded_accounts.push(crate::shared::MaybeAccount::Exists(crate::shared::DecodedAccount { address, account: account.clone(), data }));
106      } else {
107        decoded_accounts.push(crate::shared::MaybeAccount::NotFound(address));
108      }
109    }
110  Ok(decoded_accounts)
111}
112
113  #[cfg(feature = "anchor")]
114  impl anchor_lang::AccountDeserialize for VestingStrategy {
115      fn try_deserialize_unchecked(buf: &mut &[u8]) -> anchor_lang::Result<Self> {
116        Ok(Self::deserialize(buf)?)
117      }
118  }
119
120  #[cfg(feature = "anchor")]
121  impl anchor_lang::AccountSerialize for VestingStrategy {}
122
123  #[cfg(feature = "anchor")]
124  impl anchor_lang::Owner for VestingStrategy {
125      fn owner() -> Pubkey {
126        crate::TUNA_STAKING_ID
127      }
128  }
129
130  #[cfg(feature = "anchor-idl-build")]
131  impl anchor_lang::IdlBuild for VestingStrategy {}
132
133  
134  #[cfg(feature = "anchor-idl-build")]
135  impl anchor_lang::Discriminator for VestingStrategy {
136    const DISCRIMINATOR: [u8; 8] = [0; 8];
137  }
138