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