defituna_client/generated/accounts/
vault.rs1use 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],
17pub version: u16,
19pub bump: [u8; 1],
21#[cfg_attr(feature = "serde", serde(with = "serde_with::As::<serde_with::DisplayFromStr>"))]
23pub mint: Pubkey,
24pub deposited_funds: u64,
26pub deposited_shares: u64,
28pub borrowed_funds: u64,
30pub borrowed_shares: u64,
32pub unpaid_debt_shares: u64,
34pub interest_rate: u64,
36pub last_update_timestamp: u64,
38pub supply_limit: u64,
40#[cfg_attr(feature = "serde", serde(with = "serde_with::As::<serde_with::DisplayFromStr>"))]
42pub pyth_oracle_price_update: Pubkey,
43#[cfg_attr(feature = "serde", serde(with = "serde_with::As::<serde_with::DisplayFromStr>"))]
45pub pyth_oracle_feed_id: Pubkey,
46#[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