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_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 vault.
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
52pub const VAULT_DISCRIMINATOR: [u8; 8] = [211, 8, 232, 43, 2, 152, 117, 119];
53
54impl Vault {
55      pub const LEN: usize = 355;
56  
57  
58  
59  #[inline(always)]
60  pub fn from_bytes(data: &[u8]) -> Result<Self, std::io::Error> {
61    let mut data = data;
62    Self::deserialize(&mut data)
63  }
64}
65
66impl<'a> TryFrom<&solana_account_info::AccountInfo<'a>> for Vault {
67  type Error = std::io::Error;
68
69  fn try_from(account_info: &solana_account_info::AccountInfo<'a>) -> Result<Self, Self::Error> {
70      let mut data: &[u8] = &(*account_info.data).borrow();
71      Self::deserialize(&mut data)
72  }
73}
74
75#[cfg(feature = "fetch")]
76pub fn fetch_vault(
77  rpc: &solana_client::rpc_client::RpcClient,
78  address: &solana_pubkey::Pubkey,
79) -> Result<crate::shared::DecodedAccount<Vault>, std::io::Error> {
80  let accounts = fetch_all_vault(rpc, &[*address])?;
81  Ok(accounts[0].clone())
82}
83
84#[cfg(feature = "fetch")]
85pub fn fetch_all_vault(
86  rpc: &solana_client::rpc_client::RpcClient,
87  addresses: &[solana_pubkey::Pubkey],
88) -> Result<Vec<crate::shared::DecodedAccount<Vault>>, std::io::Error> {
89    let accounts = rpc.get_multiple_accounts(addresses)
90      .map_err(|e| std::io::Error::new(std::io::ErrorKind::Other, e.to_string()))?;
91    let mut decoded_accounts: Vec<crate::shared::DecodedAccount<Vault>> = Vec::new();
92    for i in 0..addresses.len() {
93      let address = addresses[i];
94      let account = accounts[i].as_ref()
95        .ok_or(std::io::Error::new(std::io::ErrorKind::Other, format!("Account not found: {}", address)))?;
96      let data = Vault::from_bytes(&account.data)?;
97      decoded_accounts.push(crate::shared::DecodedAccount { address, account: account.clone(), data });
98    }
99    Ok(decoded_accounts)
100}
101
102#[cfg(feature = "fetch")]
103pub fn fetch_maybe_vault(
104  rpc: &solana_client::rpc_client::RpcClient,
105  address: &solana_pubkey::Pubkey,
106) -> Result<crate::shared::MaybeAccount<Vault>, std::io::Error> {
107    let accounts = fetch_all_maybe_vault(rpc, &[*address])?;
108    Ok(accounts[0].clone())
109}
110
111#[cfg(feature = "fetch")]
112pub fn fetch_all_maybe_vault(
113  rpc: &solana_client::rpc_client::RpcClient,
114  addresses: &[solana_pubkey::Pubkey],
115) -> Result<Vec<crate::shared::MaybeAccount<Vault>>, std::io::Error> {
116    let accounts = rpc.get_multiple_accounts(addresses)
117      .map_err(|e| std::io::Error::new(std::io::ErrorKind::Other, e.to_string()))?;
118    let mut decoded_accounts: Vec<crate::shared::MaybeAccount<Vault>> = Vec::new();
119    for i in 0..addresses.len() {
120      let address = addresses[i];
121      if let Some(account) = accounts[i].as_ref() {
122        let data = Vault::from_bytes(&account.data)?;
123        decoded_accounts.push(crate::shared::MaybeAccount::Exists(crate::shared::DecodedAccount { address, account: account.clone(), data }));
124      } else {
125        decoded_accounts.push(crate::shared::MaybeAccount::NotFound(address));
126      }
127    }
128  Ok(decoded_accounts)
129}
130
131  #[cfg(feature = "anchor")]
132  impl anchor_lang::AccountDeserialize for Vault {
133      fn try_deserialize_unchecked(buf: &mut &[u8]) -> anchor_lang::Result<Self> {
134        Ok(Self::deserialize(buf)?)
135      }
136  }
137
138  #[cfg(feature = "anchor")]
139  impl anchor_lang::AccountSerialize for Vault {}
140
141  #[cfg(feature = "anchor")]
142  impl anchor_lang::Owner for Vault {
143      fn owner() -> Pubkey {
144        crate::TUNA_ID
145      }
146  }
147
148  #[cfg(feature = "anchor-idl-build")]
149  impl anchor_lang::IdlBuild for Vault {}
150
151  
152  #[cfg(feature = "anchor-idl-build")]
153  impl anchor_lang::Discriminator for Vault {
154    const DISCRIMINATOR: &[u8] = &[0; 8];
155  }
156