defituna_client/generated/instructions/
open_lending_position.rs

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