defituna_client/generated/accounts/
vault.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 solana_program::pubkey::Pubkey;
9use borsh::BorshSerialize;
10use borsh::BorshDeserialize;
11
12
13#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)]
14#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
15pub struct Vault {
16pub discriminator: [u8; 8],
17/// Struct version
18pub version: u16,
19/// Bump seed for the vault account
20pub bump: [u8; 1],
21/// The mint of the token that this vault holds
22#[cfg_attr(feature = "serde", serde(with = "serde_with::As::<serde_with::DisplayFromStr>"))]
23pub mint: Pubkey,
24/// The amount of funds deposited in the vault - takes into account accrued interest
25pub deposited_funds: u64,
26/// The amount of shares deposited in the vault
27pub deposited_shares: u64,
28/// The amount of funds borrowed from the vault - takes into account accrued interest
29pub borrowed_funds: u64,
30/// The amount of shares borrowed from the vault
31pub borrowed_shares: u64,
32/// Bad dept may appear on a position liquidation if not enough funds to repay the debt to a lending pool.
33pub unpaid_debt_shares: u64,
34/// The interest rate of the vault per seconds. (1<<60) / 31536000 = 1152921504606846976 / 31536000 = 100% annually.
35pub interest_rate: u64,
36/// The last time the vault was updated.
37pub last_update_timestamp: u64,
38/// The maximum allowed supply for this pool. The default value 0 is unlimited supply.
39pub supply_limit: u64,
40/// Pyth oracle price update account.
41#[cfg_attr(feature = "serde", serde(with = "serde_with::As::<serde_with::DisplayFromStr>"))]
42pub pyth_oracle_price_update: Pubkey,
43/// Pyth oracle price feed id.
44#[cfg_attr(feature = "serde", serde(with = "serde_with::As::<serde_with::DisplayFromStr>"))]
45pub pyth_oracle_feed_id: Pubkey,
46/// Reserved
47#[cfg_attr(feature = "serde", serde(with = "serde_with::As::<serde_with::Bytes>"))]
48pub reserved: [u8; 184],
49}
50
51
52impl Vault {
53      pub const LEN: usize = 355;
54  
55  
56  
57  #[inline(always)]
58  pub fn from_bytes(data: &[u8]) -> Result<Self, std::io::Error> {
59    let mut data = data;
60    Self::deserialize(&mut data)
61  }
62}
63
64impl<'a> TryFrom<&solana_program::account_info::AccountInfo<'a>> for Vault {
65  type Error = std::io::Error;
66
67  fn try_from(account_info: &solana_program::account_info::AccountInfo<'a>) -> Result<Self, Self::Error> {
68      let mut data: &[u8] = &(*account_info.data).borrow();
69      Self::deserialize(&mut data)
70  }
71}
72
73#[cfg(feature = "fetch")]
74pub fn fetch_vault(
75  rpc: &solana_client::rpc_client::RpcClient,
76  address: &solana_program::pubkey::Pubkey,
77) -> Result<crate::shared::DecodedAccount<Vault>, std::io::Error> {
78  let accounts = fetch_all_vault(rpc, &[*address])?;
79  Ok(accounts[0].clone())
80}
81
82#[cfg(feature = "fetch")]
83pub fn fetch_all_vault(
84  rpc: &solana_client::rpc_client::RpcClient,
85  addresses: &[solana_program::pubkey::Pubkey],
86) -> Result<Vec<crate::shared::DecodedAccount<Vault>>, std::io::Error> {
87    let accounts = rpc.get_multiple_accounts(addresses)
88      .map_err(|e| std::io::Error::new(std::io::ErrorKind::Other, e.to_string()))?;
89    let mut decoded_accounts: Vec<crate::shared::DecodedAccount<Vault>> = Vec::new();
90    for i in 0..addresses.len() {
91      let address = addresses[i];
92      let account = accounts[i].as_ref()
93        .ok_or(std::io::Error::new(std::io::ErrorKind::Other, format!("Account not found: {}", address)))?;
94      let data = Vault::from_bytes(&account.data)?;
95      decoded_accounts.push(crate::shared::DecodedAccount { address, account: account.clone(), data });
96    }
97    Ok(decoded_accounts)
98}
99
100#[cfg(feature = "fetch")]
101pub fn fetch_maybe_vault(
102  rpc: &solana_client::rpc_client::RpcClient,
103  address: &solana_program::pubkey::Pubkey,
104) -> Result<crate::shared::MaybeAccount<Vault>, std::io::Error> {
105    let accounts = fetch_all_maybe_vault(rpc, &[*address])?;
106    Ok(accounts[0].clone())
107}
108
109#[cfg(feature = "fetch")]
110pub fn fetch_all_maybe_vault(
111  rpc: &solana_client::rpc_client::RpcClient,
112  addresses: &[solana_program::pubkey::Pubkey],
113) -> Result<Vec<crate::shared::MaybeAccount<Vault>>, std::io::Error> {
114    let accounts = rpc.get_multiple_accounts(addresses)
115      .map_err(|e| std::io::Error::new(std::io::ErrorKind::Other, e.to_string()))?;
116    let mut decoded_accounts: Vec<crate::shared::MaybeAccount<Vault>> = Vec::new();
117    for i in 0..addresses.len() {
118      let address = addresses[i];
119      if let Some(account) = accounts[i].as_ref() {
120        let data = Vault::from_bytes(&account.data)?;
121        decoded_accounts.push(crate::shared::MaybeAccount::Exists(crate::shared::DecodedAccount { address, account: account.clone(), data }));
122      } else {
123        decoded_accounts.push(crate::shared::MaybeAccount::NotFound(address));
124      }
125    }
126  Ok(decoded_accounts)
127}
128
129  #[cfg(feature = "anchor")]
130  impl anchor_lang::AccountDeserialize for Vault {
131      fn try_deserialize_unchecked(buf: &mut &[u8]) -> anchor_lang::Result<Self> {
132        Ok(Self::deserialize(buf)?)
133      }
134  }
135
136  #[cfg(feature = "anchor")]
137  impl anchor_lang::AccountSerialize for Vault {}
138
139  #[cfg(feature = "anchor")]
140  impl anchor_lang::Owner for Vault {
141      fn owner() -> Pubkey {
142        crate::TUNA_ID
143      }
144  }
145
146  #[cfg(feature = "anchor-idl-build")]
147  impl anchor_lang::IdlBuild for Vault {}
148
149  
150  #[cfg(feature = "anchor-idl-build")]
151  impl anchor_lang::Discriminator for Vault {
152    const DISCRIMINATOR: [u8; 8] = [0; 8];
153  }
154