defituna_client/generated/instructions/
open_lending_position.rs1use borsh::BorshSerialize;
9use borsh::BorshDeserialize;
10
11#[derive(Debug)]
13pub struct OpenLendingPosition {
14
15
16 pub authority: solana_program::pubkey::Pubkey,
17
18
19 pub tuna_config: solana_program::pubkey::Pubkey,
20
21
22 pub vault: solana_program::pubkey::Pubkey,
23
24
25 pub lending_position: solana_program::pubkey::Pubkey,
26
27
28 pub pool_mint: solana_program::pubkey::Pubkey,
29
30
31 pub system_program: solana_program::pubkey::Pubkey,
32 }
33
34impl OpenLendingPosition {
35 pub fn instruction(&self) -> solana_program::instruction::Instruction {
36 self.instruction_with_remaining_accounts(&[])
37 }
38 #[allow(clippy::arithmetic_side_effects)]
39 #[allow(clippy::vec_init_then_push)]
40 pub fn instruction_with_remaining_accounts(&self, remaining_accounts: &[solana_program::instruction::AccountMeta]) -> solana_program::instruction::Instruction {
41 let mut accounts = Vec::with_capacity(6+ remaining_accounts.len());
42 accounts.push(solana_program::instruction::AccountMeta::new(
43 self.authority,
44 true
45 ));
46 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
47 self.tuna_config,
48 false
49 ));
50 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
51 self.vault,
52 false
53 ));
54 accounts.push(solana_program::instruction::AccountMeta::new(
55 self.lending_position,
56 false
57 ));
58 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
59 self.pool_mint,
60 false
61 ));
62 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
63 self.system_program,
64 false
65 ));
66 accounts.extend_from_slice(remaining_accounts);
67 let data = borsh::to_vec(&OpenLendingPositionInstructionData::new()).unwrap();
68
69 solana_program::instruction::Instruction {
70 program_id: crate::TUNA_ID,
71 accounts,
72 data,
73 }
74 }
75}
76
77#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)]
78#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
79 pub struct OpenLendingPositionInstructionData {
80 discriminator: [u8; 8],
81 }
82
83impl OpenLendingPositionInstructionData {
84 pub fn new() -> Self {
85 Self {
86 discriminator: [174, 227, 181, 127, 78, 227, 244, 19],
87 }
88 }
89}
90
91impl Default for OpenLendingPositionInstructionData {
92 fn default() -> Self {
93 Self::new()
94 }
95}
96
97
98
99#[derive(Clone, Debug, Default)]
110pub struct OpenLendingPositionBuilder {
111 authority: Option<solana_program::pubkey::Pubkey>,
112 tuna_config: Option<solana_program::pubkey::Pubkey>,
113 vault: Option<solana_program::pubkey::Pubkey>,
114 lending_position: Option<solana_program::pubkey::Pubkey>,
115 pool_mint: Option<solana_program::pubkey::Pubkey>,
116 system_program: Option<solana_program::pubkey::Pubkey>,
117 __remaining_accounts: Vec<solana_program::instruction::AccountMeta>,
118}
119
120impl OpenLendingPositionBuilder {
121 pub fn new() -> Self {
122 Self::default()
123 }
124 #[inline(always)]
125 pub fn authority(&mut self, authority: solana_program::pubkey::Pubkey) -> &mut Self {
126 self.authority = Some(authority);
127 self
128 }
129 #[inline(always)]
130 pub fn tuna_config(&mut self, tuna_config: solana_program::pubkey::Pubkey) -> &mut Self {
131 self.tuna_config = Some(tuna_config);
132 self
133 }
134 #[inline(always)]
135 pub fn vault(&mut self, vault: solana_program::pubkey::Pubkey) -> &mut Self {
136 self.vault = Some(vault);
137 self
138 }
139 #[inline(always)]
140 pub fn lending_position(&mut self, lending_position: solana_program::pubkey::Pubkey) -> &mut Self {
141 self.lending_position = Some(lending_position);
142 self
143 }
144 #[inline(always)]
145 pub fn pool_mint(&mut self, pool_mint: solana_program::pubkey::Pubkey) -> &mut Self {
146 self.pool_mint = Some(pool_mint);
147 self
148 }
149 #[inline(always)]
151 pub fn system_program(&mut self, system_program: solana_program::pubkey::Pubkey) -> &mut Self {
152 self.system_program = Some(system_program);
153 self
154 }
155 #[inline(always)]
157 pub fn add_remaining_account(&mut self, account: solana_program::instruction::AccountMeta) -> &mut Self {
158 self.__remaining_accounts.push(account);
159 self
160 }
161 #[inline(always)]
163 pub fn add_remaining_accounts(&mut self, accounts: &[solana_program::instruction::AccountMeta]) -> &mut Self {
164 self.__remaining_accounts.extend_from_slice(accounts);
165 self
166 }
167 #[allow(clippy::clone_on_copy)]
168 pub fn instruction(&self) -> solana_program::instruction::Instruction {
169 let accounts = OpenLendingPosition {
170 authority: self.authority.expect("authority is not set"),
171 tuna_config: self.tuna_config.expect("tuna_config is not set"),
172 vault: self.vault.expect("vault is not set"),
173 lending_position: self.lending_position.expect("lending_position is not set"),
174 pool_mint: self.pool_mint.expect("pool_mint is not set"),
175 system_program: self.system_program.unwrap_or(solana_program::pubkey!("11111111111111111111111111111111")),
176 };
177
178 accounts.instruction_with_remaining_accounts(&self.__remaining_accounts)
179 }
180}
181
182 pub struct OpenLendingPositionCpiAccounts<'a, 'b> {
184
185
186 pub authority: &'b solana_program::account_info::AccountInfo<'a>,
187
188
189 pub tuna_config: &'b solana_program::account_info::AccountInfo<'a>,
190
191
192 pub vault: &'b solana_program::account_info::AccountInfo<'a>,
193
194
195 pub lending_position: &'b solana_program::account_info::AccountInfo<'a>,
196
197
198 pub pool_mint: &'b solana_program::account_info::AccountInfo<'a>,
199
200
201 pub system_program: &'b solana_program::account_info::AccountInfo<'a>,
202 }
203
204pub struct OpenLendingPositionCpi<'a, 'b> {
206 pub __program: &'b solana_program::account_info::AccountInfo<'a>,
208
209
210 pub authority: &'b solana_program::account_info::AccountInfo<'a>,
211
212
213 pub tuna_config: &'b solana_program::account_info::AccountInfo<'a>,
214
215
216 pub vault: &'b solana_program::account_info::AccountInfo<'a>,
217
218
219 pub lending_position: &'b solana_program::account_info::AccountInfo<'a>,
220
221
222 pub pool_mint: &'b solana_program::account_info::AccountInfo<'a>,
223
224
225 pub system_program: &'b solana_program::account_info::AccountInfo<'a>,
226 }
227
228impl<'a, 'b> OpenLendingPositionCpi<'a, 'b> {
229 pub fn new(
230 program: &'b solana_program::account_info::AccountInfo<'a>,
231 accounts: OpenLendingPositionCpiAccounts<'a, 'b>,
232 ) -> Self {
233 Self {
234 __program: program,
235 authority: accounts.authority,
236 tuna_config: accounts.tuna_config,
237 vault: accounts.vault,
238 lending_position: accounts.lending_position,
239 pool_mint: accounts.pool_mint,
240 system_program: accounts.system_program,
241 }
242 }
243 #[inline(always)]
244 pub fn invoke(&self) -> solana_program::entrypoint::ProgramResult {
245 self.invoke_signed_with_remaining_accounts(&[], &[])
246 }
247 #[inline(always)]
248 pub fn invoke_with_remaining_accounts(&self, remaining_accounts: &[(&'b solana_program::account_info::AccountInfo<'a>, bool, bool)]) -> solana_program::entrypoint::ProgramResult {
249 self.invoke_signed_with_remaining_accounts(&[], remaining_accounts)
250 }
251 #[inline(always)]
252 pub fn invoke_signed(&self, signers_seeds: &[&[&[u8]]]) -> solana_program::entrypoint::ProgramResult {
253 self.invoke_signed_with_remaining_accounts(signers_seeds, &[])
254 }
255 #[allow(clippy::arithmetic_side_effects)]
256 #[allow(clippy::clone_on_copy)]
257 #[allow(clippy::vec_init_then_push)]
258 pub fn invoke_signed_with_remaining_accounts(
259 &self,
260 signers_seeds: &[&[&[u8]]],
261 remaining_accounts: &[(&'b solana_program::account_info::AccountInfo<'a>, bool, bool)]
262 ) -> solana_program::entrypoint::ProgramResult {
263 let mut accounts = Vec::with_capacity(6+ remaining_accounts.len());
264 accounts.push(solana_program::instruction::AccountMeta::new(
265 *self.authority.key,
266 true
267 ));
268 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
269 *self.tuna_config.key,
270 false
271 ));
272 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
273 *self.vault.key,
274 false
275 ));
276 accounts.push(solana_program::instruction::AccountMeta::new(
277 *self.lending_position.key,
278 false
279 ));
280 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
281 *self.pool_mint.key,
282 false
283 ));
284 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
285 *self.system_program.key,
286 false
287 ));
288 remaining_accounts.iter().for_each(|remaining_account| {
289 accounts.push(solana_program::instruction::AccountMeta {
290 pubkey: *remaining_account.0.key,
291 is_signer: remaining_account.1,
292 is_writable: remaining_account.2,
293 })
294 });
295 let data = borsh::to_vec(&OpenLendingPositionInstructionData::new()).unwrap();
296
297 let instruction = solana_program::instruction::Instruction {
298 program_id: crate::TUNA_ID,
299 accounts,
300 data,
301 };
302 let mut account_infos = Vec::with_capacity(7 + remaining_accounts.len());
303 account_infos.push(self.__program.clone());
304 account_infos.push(self.authority.clone());
305 account_infos.push(self.tuna_config.clone());
306 account_infos.push(self.vault.clone());
307 account_infos.push(self.lending_position.clone());
308 account_infos.push(self.pool_mint.clone());
309 account_infos.push(self.system_program.clone());
310 remaining_accounts.iter().for_each(|remaining_account| account_infos.push(remaining_account.0.clone()));
311
312 if signers_seeds.is_empty() {
313 solana_program::program::invoke(&instruction, &account_infos)
314 } else {
315 solana_program::program::invoke_signed(&instruction, &account_infos, signers_seeds)
316 }
317 }
318}
319
320#[derive(Clone, Debug)]
331pub struct OpenLendingPositionCpiBuilder<'a, 'b> {
332 instruction: Box<OpenLendingPositionCpiBuilderInstruction<'a, 'b>>,
333}
334
335impl<'a, 'b> OpenLendingPositionCpiBuilder<'a, 'b> {
336 pub fn new(program: &'b solana_program::account_info::AccountInfo<'a>) -> Self {
337 let instruction = Box::new(OpenLendingPositionCpiBuilderInstruction {
338 __program: program,
339 authority: None,
340 tuna_config: None,
341 vault: None,
342 lending_position: None,
343 pool_mint: None,
344 system_program: None,
345 __remaining_accounts: Vec::new(),
346 });
347 Self { instruction }
348 }
349 #[inline(always)]
350 pub fn authority(&mut self, authority: &'b solana_program::account_info::AccountInfo<'a>) -> &mut Self {
351 self.instruction.authority = Some(authority);
352 self
353 }
354 #[inline(always)]
355 pub fn tuna_config(&mut self, tuna_config: &'b solana_program::account_info::AccountInfo<'a>) -> &mut Self {
356 self.instruction.tuna_config = Some(tuna_config);
357 self
358 }
359 #[inline(always)]
360 pub fn vault(&mut self, vault: &'b solana_program::account_info::AccountInfo<'a>) -> &mut Self {
361 self.instruction.vault = Some(vault);
362 self
363 }
364 #[inline(always)]
365 pub fn lending_position(&mut self, lending_position: &'b solana_program::account_info::AccountInfo<'a>) -> &mut Self {
366 self.instruction.lending_position = Some(lending_position);
367 self
368 }
369 #[inline(always)]
370 pub fn pool_mint(&mut self, pool_mint: &'b solana_program::account_info::AccountInfo<'a>) -> &mut Self {
371 self.instruction.pool_mint = Some(pool_mint);
372 self
373 }
374 #[inline(always)]
375 pub fn system_program(&mut self, system_program: &'b solana_program::account_info::AccountInfo<'a>) -> &mut Self {
376 self.instruction.system_program = Some(system_program);
377 self
378 }
379 #[inline(always)]
381 pub fn add_remaining_account(&mut self, account: &'b solana_program::account_info::AccountInfo<'a>, is_writable: bool, is_signer: bool) -> &mut Self {
382 self.instruction.__remaining_accounts.push((account, is_writable, is_signer));
383 self
384 }
385 #[inline(always)]
390 pub fn add_remaining_accounts(&mut self, accounts: &[(&'b solana_program::account_info::AccountInfo<'a>, bool, bool)]) -> &mut Self {
391 self.instruction.__remaining_accounts.extend_from_slice(accounts);
392 self
393 }
394 #[inline(always)]
395 pub fn invoke(&self) -> solana_program::entrypoint::ProgramResult {
396 self.invoke_signed(&[])
397 }
398 #[allow(clippy::clone_on_copy)]
399 #[allow(clippy::vec_init_then_push)]
400 pub fn invoke_signed(&self, signers_seeds: &[&[&[u8]]]) -> solana_program::entrypoint::ProgramResult {
401 let instruction = OpenLendingPositionCpi {
402 __program: self.instruction.__program,
403
404 authority: self.instruction.authority.expect("authority is not set"),
405
406 tuna_config: self.instruction.tuna_config.expect("tuna_config is not set"),
407
408 vault: self.instruction.vault.expect("vault is not set"),
409
410 lending_position: self.instruction.lending_position.expect("lending_position is not set"),
411
412 pool_mint: self.instruction.pool_mint.expect("pool_mint is not set"),
413
414 system_program: self.instruction.system_program.expect("system_program is not set"),
415 };
416 instruction.invoke_signed_with_remaining_accounts(signers_seeds, &self.instruction.__remaining_accounts)
417 }
418}
419
420#[derive(Clone, Debug)]
421struct OpenLendingPositionCpiBuilderInstruction<'a, 'b> {
422 __program: &'b solana_program::account_info::AccountInfo<'a>,
423 authority: Option<&'b solana_program::account_info::AccountInfo<'a>>,
424 tuna_config: Option<&'b solana_program::account_info::AccountInfo<'a>>,
425 vault: Option<&'b solana_program::account_info::AccountInfo<'a>>,
426 lending_position: Option<&'b solana_program::account_info::AccountInfo<'a>>,
427 pool_mint: Option<&'b solana_program::account_info::AccountInfo<'a>>,
428 system_program: Option<&'b solana_program::account_info::AccountInfo<'a>>,
429 __remaining_accounts: Vec<(&'b solana_program::account_info::AccountInfo<'a>, bool, bool)>,
431}
432