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