defituna_client/generated/accounts/
lending_position.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 LendingPosition {
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 authority: Pubkey,
24#[cfg_attr(feature = "serde", serde(with = "serde_with::As::<serde_with::DisplayFromStr>"))]
26pub mint: Pubkey,
27pub deposited_funds: u64,
29pub deposited_shares: u64,
31#[cfg_attr(feature = "serde", serde(with = "serde_with::As::<serde_with::DisplayFromStr>"))]
33pub vault: Pubkey,
34pub reserved: [u8; 32],
36}
37
38
39pub const LENDING_POSITION_DISCRIMINATOR: [u8; 8] = [47, 255, 252, 35, 20, 245, 157, 243];
40
41impl LendingPosition {
42 pub const LEN: usize = 155;
43
44
45
46 #[inline(always)]
47 pub fn from_bytes(data: &[u8]) -> Result<Self, std::io::Error> {
48 let mut data = data;
49 Self::deserialize(&mut data)
50 }
51}
52
53impl<'a> TryFrom<&solana_account_info::AccountInfo<'a>> for LendingPosition {
54 type Error = std::io::Error;
55
56 fn try_from(account_info: &solana_account_info::AccountInfo<'a>) -> Result<Self, Self::Error> {
57 let mut data: &[u8] = &(*account_info.data).borrow();
58 Self::deserialize(&mut data)
59 }
60}
61
62#[cfg(feature = "fetch")]
63pub fn fetch_lending_position(
64 rpc: &solana_client::rpc_client::RpcClient,
65 address: &solana_pubkey::Pubkey,
66) -> Result<crate::shared::DecodedAccount<LendingPosition>, std::io::Error> {
67 let accounts = fetch_all_lending_position(rpc, &[*address])?;
68 Ok(accounts[0].clone())
69}
70
71#[cfg(feature = "fetch")]
72pub fn fetch_all_lending_position(
73 rpc: &solana_client::rpc_client::RpcClient,
74 addresses: &[solana_pubkey::Pubkey],
75) -> Result<Vec<crate::shared::DecodedAccount<LendingPosition>>, std::io::Error> {
76 let accounts = rpc.get_multiple_accounts(addresses)
77 .map_err(|e| std::io::Error::new(std::io::ErrorKind::Other, e.to_string()))?;
78 let mut decoded_accounts: Vec<crate::shared::DecodedAccount<LendingPosition>> = Vec::new();
79 for i in 0..addresses.len() {
80 let address = addresses[i];
81 let account = accounts[i].as_ref()
82 .ok_or(std::io::Error::new(std::io::ErrorKind::Other, format!("Account not found: {}", address)))?;
83 let data = LendingPosition::from_bytes(&account.data)?;
84 decoded_accounts.push(crate::shared::DecodedAccount { address, account: account.clone(), data });
85 }
86 Ok(decoded_accounts)
87}
88
89#[cfg(feature = "fetch")]
90pub fn fetch_maybe_lending_position(
91 rpc: &solana_client::rpc_client::RpcClient,
92 address: &solana_pubkey::Pubkey,
93) -> Result<crate::shared::MaybeAccount<LendingPosition>, std::io::Error> {
94 let accounts = fetch_all_maybe_lending_position(rpc, &[*address])?;
95 Ok(accounts[0].clone())
96}
97
98#[cfg(feature = "fetch")]
99pub fn fetch_all_maybe_lending_position(
100 rpc: &solana_client::rpc_client::RpcClient,
101 addresses: &[solana_pubkey::Pubkey],
102) -> Result<Vec<crate::shared::MaybeAccount<LendingPosition>>, std::io::Error> {
103 let accounts = rpc.get_multiple_accounts(addresses)
104 .map_err(|e| std::io::Error::new(std::io::ErrorKind::Other, e.to_string()))?;
105 let mut decoded_accounts: Vec<crate::shared::MaybeAccount<LendingPosition>> = Vec::new();
106 for i in 0..addresses.len() {
107 let address = addresses[i];
108 if let Some(account) = accounts[i].as_ref() {
109 let data = LendingPosition::from_bytes(&account.data)?;
110 decoded_accounts.push(crate::shared::MaybeAccount::Exists(crate::shared::DecodedAccount { address, account: account.clone(), data }));
111 } else {
112 decoded_accounts.push(crate::shared::MaybeAccount::NotFound(address));
113 }
114 }
115 Ok(decoded_accounts)
116}
117
118 #[cfg(feature = "anchor")]
119 impl anchor_lang::AccountDeserialize for LendingPosition {
120 fn try_deserialize_unchecked(buf: &mut &[u8]) -> anchor_lang::Result<Self> {
121 Ok(Self::deserialize(buf)?)
122 }
123 }
124
125 #[cfg(feature = "anchor")]
126 impl anchor_lang::AccountSerialize for LendingPosition {}
127
128 #[cfg(feature = "anchor")]
129 impl anchor_lang::Owner for LendingPosition {
130 fn owner() -> Pubkey {
131 crate::TUNA_ID
132 }
133 }
134
135 #[cfg(feature = "anchor-idl-build")]
136 impl anchor_lang::IdlBuild for LendingPosition {}
137
138
139 #[cfg(feature = "anchor-idl-build")]
140 impl anchor_lang::Discriminator for LendingPosition {
141 const DISCRIMINATOR: &[u8] = &[0; 8];
142 }
143