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