defituna_client/generated/instructions/
deposit.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 DEPOSIT_DISCRIMINATOR: [u8; 8] = [242, 35, 198, 137, 82, 225, 242, 182];
12
13/// Accounts.
14#[derive(Debug)]
15pub struct Deposit {
16      
17              
18          pub authority: solana_pubkey::Pubkey,
19          
20              
21          pub mint: solana_pubkey::Pubkey,
22          
23              
24          pub tuna_config: solana_pubkey::Pubkey,
25          
26              
27          pub lending_position: solana_pubkey::Pubkey,
28          
29              
30          pub vault: solana_pubkey::Pubkey,
31          
32              
33          pub vault_ata: solana_pubkey::Pubkey,
34          
35              
36          pub authority_ata: solana_pubkey::Pubkey,
37          
38              
39          pub token_program: solana_pubkey::Pubkey,
40          
41              
42          pub memo_program: solana_pubkey::Pubkey,
43      }
44
45impl Deposit {
46  pub fn instruction(&self, args: DepositInstructionArgs) -> solana_instruction::Instruction {
47    self.instruction_with_remaining_accounts(args, &[])
48  }
49  #[allow(clippy::arithmetic_side_effects)]
50  #[allow(clippy::vec_init_then_push)]
51  pub fn instruction_with_remaining_accounts(&self, args: DepositInstructionArgs, remaining_accounts: &[solana_instruction::AccountMeta]) -> solana_instruction::Instruction {
52    let mut accounts = Vec::with_capacity(9+ remaining_accounts.len());
53                            accounts.push(solana_instruction::AccountMeta::new(
54            self.authority,
55            true
56          ));
57                                          accounts.push(solana_instruction::AccountMeta::new_readonly(
58            self.mint,
59            false
60          ));
61                                          accounts.push(solana_instruction::AccountMeta::new_readonly(
62            self.tuna_config,
63            false
64          ));
65                                          accounts.push(solana_instruction::AccountMeta::new(
66            self.lending_position,
67            false
68          ));
69                                          accounts.push(solana_instruction::AccountMeta::new(
70            self.vault,
71            false
72          ));
73                                          accounts.push(solana_instruction::AccountMeta::new(
74            self.vault_ata,
75            false
76          ));
77                                          accounts.push(solana_instruction::AccountMeta::new(
78            self.authority_ata,
79            false
80          ));
81                                          accounts.push(solana_instruction::AccountMeta::new_readonly(
82            self.token_program,
83            false
84          ));
85                                          accounts.push(solana_instruction::AccountMeta::new_readonly(
86            self.memo_program,
87            false
88          ));
89                      accounts.extend_from_slice(remaining_accounts);
90    let mut data = borsh::to_vec(&DepositInstructionData::new()).unwrap();
91          let mut args = borsh::to_vec(&args).unwrap();
92      data.append(&mut args);
93    
94    solana_instruction::Instruction {
95      program_id: crate::TUNA_ID,
96      accounts,
97      data,
98    }
99  }
100}
101
102#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)]
103#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
104 pub struct DepositInstructionData {
105            discriminator: [u8; 8],
106            }
107
108impl DepositInstructionData {
109  pub fn new() -> Self {
110    Self {
111                        discriminator: [242, 35, 198, 137, 82, 225, 242, 182],
112                                }
113  }
114}
115
116impl Default for DepositInstructionData {
117  fn default() -> Self {
118    Self::new()
119  }
120}
121
122#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)]
123#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
124 pub struct DepositInstructionArgs {
125                  pub amount: u64,
126      }
127
128
129/// Instruction builder for `Deposit`.
130///
131/// ### Accounts:
132///
133                      ///   0. `[writable, signer]` authority
134          ///   1. `[]` mint
135          ///   2. `[]` tuna_config
136                ///   3. `[writable]` lending_position
137                ///   4. `[writable]` vault
138                ///   5. `[writable]` vault_ata
139                ///   6. `[writable]` authority_ata
140                ///   7. `[optional]` token_program (default to `TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA`)
141          ///   8. `[]` memo_program
142#[derive(Clone, Debug, Default)]
143pub struct DepositBuilder {
144            authority: Option<solana_pubkey::Pubkey>,
145                mint: Option<solana_pubkey::Pubkey>,
146                tuna_config: Option<solana_pubkey::Pubkey>,
147                lending_position: Option<solana_pubkey::Pubkey>,
148                vault: Option<solana_pubkey::Pubkey>,
149                vault_ata: Option<solana_pubkey::Pubkey>,
150                authority_ata: Option<solana_pubkey::Pubkey>,
151                token_program: Option<solana_pubkey::Pubkey>,
152                memo_program: Option<solana_pubkey::Pubkey>,
153                        amount: Option<u64>,
154        __remaining_accounts: Vec<solana_instruction::AccountMeta>,
155}
156
157impl DepositBuilder {
158  pub fn new() -> Self {
159    Self::default()
160  }
161            #[inline(always)]
162    pub fn authority(&mut self, authority: solana_pubkey::Pubkey) -> &mut Self {
163                        self.authority = Some(authority);
164                    self
165    }
166            #[inline(always)]
167    pub fn mint(&mut self, mint: solana_pubkey::Pubkey) -> &mut Self {
168                        self.mint = Some(mint);
169                    self
170    }
171            #[inline(always)]
172    pub fn tuna_config(&mut self, tuna_config: solana_pubkey::Pubkey) -> &mut Self {
173                        self.tuna_config = Some(tuna_config);
174                    self
175    }
176            #[inline(always)]
177    pub fn lending_position(&mut self, lending_position: solana_pubkey::Pubkey) -> &mut Self {
178                        self.lending_position = Some(lending_position);
179                    self
180    }
181            #[inline(always)]
182    pub fn vault(&mut self, vault: solana_pubkey::Pubkey) -> &mut Self {
183                        self.vault = Some(vault);
184                    self
185    }
186            #[inline(always)]
187    pub fn vault_ata(&mut self, vault_ata: solana_pubkey::Pubkey) -> &mut Self {
188                        self.vault_ata = Some(vault_ata);
189                    self
190    }
191            #[inline(always)]
192    pub fn authority_ata(&mut self, authority_ata: solana_pubkey::Pubkey) -> &mut Self {
193                        self.authority_ata = Some(authority_ata);
194                    self
195    }
196            /// `[optional account, default to 'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA']`
197#[inline(always)]
198    pub fn token_program(&mut self, token_program: solana_pubkey::Pubkey) -> &mut Self {
199                        self.token_program = Some(token_program);
200                    self
201    }
202            #[inline(always)]
203    pub fn memo_program(&mut self, memo_program: solana_pubkey::Pubkey) -> &mut Self {
204                        self.memo_program = Some(memo_program);
205                    self
206    }
207                    #[inline(always)]
208      pub fn amount(&mut self, amount: u64) -> &mut Self {
209        self.amount = Some(amount);
210        self
211      }
212        /// Add an additional account to the instruction.
213  #[inline(always)]
214  pub fn add_remaining_account(&mut self, account: solana_instruction::AccountMeta) -> &mut Self {
215    self.__remaining_accounts.push(account);
216    self
217  }
218  /// Add additional accounts to the instruction.
219  #[inline(always)]
220  pub fn add_remaining_accounts(&mut self, accounts: &[solana_instruction::AccountMeta]) -> &mut Self {
221    self.__remaining_accounts.extend_from_slice(accounts);
222    self
223  }
224  #[allow(clippy::clone_on_copy)]
225  pub fn instruction(&self) -> solana_instruction::Instruction {
226    let accounts = Deposit {
227                              authority: self.authority.expect("authority is not set"),
228                                        mint: self.mint.expect("mint is not set"),
229                                        tuna_config: self.tuna_config.expect("tuna_config is not set"),
230                                        lending_position: self.lending_position.expect("lending_position is not set"),
231                                        vault: self.vault.expect("vault is not set"),
232                                        vault_ata: self.vault_ata.expect("vault_ata is not set"),
233                                        authority_ata: self.authority_ata.expect("authority_ata is not set"),
234                                        token_program: self.token_program.unwrap_or(solana_pubkey::pubkey!("TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA")),
235                                        memo_program: self.memo_program.expect("memo_program is not set"),
236                      };
237          let args = DepositInstructionArgs {
238                                                              amount: self.amount.clone().expect("amount is not set"),
239                                    };
240    
241    accounts.instruction_with_remaining_accounts(args, &self.__remaining_accounts)
242  }
243}
244
245  /// `deposit` CPI accounts.
246  pub struct DepositCpiAccounts<'a, 'b> {
247          
248                    
249              pub authority: &'b solana_account_info::AccountInfo<'a>,
250                
251                    
252              pub mint: &'b solana_account_info::AccountInfo<'a>,
253                
254                    
255              pub tuna_config: &'b solana_account_info::AccountInfo<'a>,
256                
257                    
258              pub lending_position: &'b solana_account_info::AccountInfo<'a>,
259                
260                    
261              pub vault: &'b solana_account_info::AccountInfo<'a>,
262                
263                    
264              pub vault_ata: &'b solana_account_info::AccountInfo<'a>,
265                
266                    
267              pub authority_ata: &'b solana_account_info::AccountInfo<'a>,
268                
269                    
270              pub token_program: &'b solana_account_info::AccountInfo<'a>,
271                
272                    
273              pub memo_program: &'b solana_account_info::AccountInfo<'a>,
274            }
275
276/// `deposit` CPI instruction.
277pub struct DepositCpi<'a, 'b> {
278  /// The program to invoke.
279  pub __program: &'b solana_account_info::AccountInfo<'a>,
280      
281              
282          pub authority: &'b solana_account_info::AccountInfo<'a>,
283          
284              
285          pub mint: &'b solana_account_info::AccountInfo<'a>,
286          
287              
288          pub tuna_config: &'b solana_account_info::AccountInfo<'a>,
289          
290              
291          pub lending_position: &'b solana_account_info::AccountInfo<'a>,
292          
293              
294          pub vault: &'b solana_account_info::AccountInfo<'a>,
295          
296              
297          pub vault_ata: &'b solana_account_info::AccountInfo<'a>,
298          
299              
300          pub authority_ata: &'b solana_account_info::AccountInfo<'a>,
301          
302              
303          pub token_program: &'b solana_account_info::AccountInfo<'a>,
304          
305              
306          pub memo_program: &'b solana_account_info::AccountInfo<'a>,
307            /// The arguments for the instruction.
308    pub __args: DepositInstructionArgs,
309  }
310
311impl<'a, 'b> DepositCpi<'a, 'b> {
312  pub fn new(
313    program: &'b solana_account_info::AccountInfo<'a>,
314          accounts: DepositCpiAccounts<'a, 'b>,
315              args: DepositInstructionArgs,
316      ) -> Self {
317    Self {
318      __program: program,
319              authority: accounts.authority,
320              mint: accounts.mint,
321              tuna_config: accounts.tuna_config,
322              lending_position: accounts.lending_position,
323              vault: accounts.vault,
324              vault_ata: accounts.vault_ata,
325              authority_ata: accounts.authority_ata,
326              token_program: accounts.token_program,
327              memo_program: accounts.memo_program,
328                    __args: args,
329          }
330  }
331  #[inline(always)]
332  pub fn invoke(&self) -> solana_program_error::ProgramResult {
333    self.invoke_signed_with_remaining_accounts(&[], &[])
334  }
335  #[inline(always)]
336  pub fn invoke_with_remaining_accounts(&self, remaining_accounts: &[(&'b solana_account_info::AccountInfo<'a>, bool, bool)]) -> solana_program_error::ProgramResult {
337    self.invoke_signed_with_remaining_accounts(&[], remaining_accounts)
338  }
339  #[inline(always)]
340  pub fn invoke_signed(&self, signers_seeds: &[&[&[u8]]]) -> solana_program_error::ProgramResult {
341    self.invoke_signed_with_remaining_accounts(signers_seeds, &[])
342  }
343  #[allow(clippy::arithmetic_side_effects)]
344  #[allow(clippy::clone_on_copy)]
345  #[allow(clippy::vec_init_then_push)]
346  pub fn invoke_signed_with_remaining_accounts(
347    &self,
348    signers_seeds: &[&[&[u8]]],
349    remaining_accounts: &[(&'b solana_account_info::AccountInfo<'a>, bool, bool)]
350  ) -> solana_program_error::ProgramResult {
351    let mut accounts = Vec::with_capacity(9+ remaining_accounts.len());
352                            accounts.push(solana_instruction::AccountMeta::new(
353            *self.authority.key,
354            true
355          ));
356                                          accounts.push(solana_instruction::AccountMeta::new_readonly(
357            *self.mint.key,
358            false
359          ));
360                                          accounts.push(solana_instruction::AccountMeta::new_readonly(
361            *self.tuna_config.key,
362            false
363          ));
364                                          accounts.push(solana_instruction::AccountMeta::new(
365            *self.lending_position.key,
366            false
367          ));
368                                          accounts.push(solana_instruction::AccountMeta::new(
369            *self.vault.key,
370            false
371          ));
372                                          accounts.push(solana_instruction::AccountMeta::new(
373            *self.vault_ata.key,
374            false
375          ));
376                                          accounts.push(solana_instruction::AccountMeta::new(
377            *self.authority_ata.key,
378            false
379          ));
380                                          accounts.push(solana_instruction::AccountMeta::new_readonly(
381            *self.token_program.key,
382            false
383          ));
384                                          accounts.push(solana_instruction::AccountMeta::new_readonly(
385            *self.memo_program.key,
386            false
387          ));
388                      remaining_accounts.iter().for_each(|remaining_account| {
389      accounts.push(solana_instruction::AccountMeta {
390          pubkey: *remaining_account.0.key,
391          is_signer: remaining_account.1,
392          is_writable: remaining_account.2,
393      })
394    });
395    let mut data = borsh::to_vec(&DepositInstructionData::new()).unwrap();
396          let mut args = borsh::to_vec(&self.__args).unwrap();
397      data.append(&mut args);
398    
399    let instruction = solana_instruction::Instruction {
400      program_id: crate::TUNA_ID,
401      accounts,
402      data,
403    };
404    let mut account_infos = Vec::with_capacity(10 + remaining_accounts.len());
405    account_infos.push(self.__program.clone());
406                  account_infos.push(self.authority.clone());
407                        account_infos.push(self.mint.clone());
408                        account_infos.push(self.tuna_config.clone());
409                        account_infos.push(self.lending_position.clone());
410                        account_infos.push(self.vault.clone());
411                        account_infos.push(self.vault_ata.clone());
412                        account_infos.push(self.authority_ata.clone());
413                        account_infos.push(self.token_program.clone());
414                        account_infos.push(self.memo_program.clone());
415              remaining_accounts.iter().for_each(|remaining_account| account_infos.push(remaining_account.0.clone()));
416
417    if signers_seeds.is_empty() {
418      solana_cpi::invoke(&instruction, &account_infos)
419    } else {
420      solana_cpi::invoke_signed(&instruction, &account_infos, signers_seeds)
421    }
422  }
423}
424
425/// Instruction builder for `Deposit` via CPI.
426///
427/// ### Accounts:
428///
429                      ///   0. `[writable, signer]` authority
430          ///   1. `[]` mint
431          ///   2. `[]` tuna_config
432                ///   3. `[writable]` lending_position
433                ///   4. `[writable]` vault
434                ///   5. `[writable]` vault_ata
435                ///   6. `[writable]` authority_ata
436          ///   7. `[]` token_program
437          ///   8. `[]` memo_program
438#[derive(Clone, Debug)]
439pub struct DepositCpiBuilder<'a, 'b> {
440  instruction: Box<DepositCpiBuilderInstruction<'a, 'b>>,
441}
442
443impl<'a, 'b> DepositCpiBuilder<'a, 'b> {
444  pub fn new(program: &'b solana_account_info::AccountInfo<'a>) -> Self {
445    let instruction = Box::new(DepositCpiBuilderInstruction {
446      __program: program,
447              authority: None,
448              mint: None,
449              tuna_config: None,
450              lending_position: None,
451              vault: None,
452              vault_ata: None,
453              authority_ata: None,
454              token_program: None,
455              memo_program: None,
456                                            amount: None,
457                    __remaining_accounts: Vec::new(),
458    });
459    Self { instruction }
460  }
461      #[inline(always)]
462    pub fn authority(&mut self, authority: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
463                        self.instruction.authority = Some(authority);
464                    self
465    }
466      #[inline(always)]
467    pub fn mint(&mut self, mint: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
468                        self.instruction.mint = Some(mint);
469                    self
470    }
471      #[inline(always)]
472    pub fn tuna_config(&mut self, tuna_config: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
473                        self.instruction.tuna_config = Some(tuna_config);
474                    self
475    }
476      #[inline(always)]
477    pub fn lending_position(&mut self, lending_position: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
478                        self.instruction.lending_position = Some(lending_position);
479                    self
480    }
481      #[inline(always)]
482    pub fn vault(&mut self, vault: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
483                        self.instruction.vault = Some(vault);
484                    self
485    }
486      #[inline(always)]
487    pub fn vault_ata(&mut self, vault_ata: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
488                        self.instruction.vault_ata = Some(vault_ata);
489                    self
490    }
491      #[inline(always)]
492    pub fn authority_ata(&mut self, authority_ata: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
493                        self.instruction.authority_ata = Some(authority_ata);
494                    self
495    }
496      #[inline(always)]
497    pub fn token_program(&mut self, token_program: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
498                        self.instruction.token_program = Some(token_program);
499                    self
500    }
501      #[inline(always)]
502    pub fn memo_program(&mut self, memo_program: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
503                        self.instruction.memo_program = Some(memo_program);
504                    self
505    }
506                    #[inline(always)]
507      pub fn amount(&mut self, amount: u64) -> &mut Self {
508        self.instruction.amount = Some(amount);
509        self
510      }
511        /// Add an additional account to the instruction.
512  #[inline(always)]
513  pub fn add_remaining_account(&mut self, account: &'b solana_account_info::AccountInfo<'a>, is_writable: bool, is_signer: bool) -> &mut Self {
514    self.instruction.__remaining_accounts.push((account, is_writable, is_signer));
515    self
516  }
517  /// Add additional accounts to the instruction.
518  ///
519  /// Each account is represented by a tuple of the `AccountInfo`, a `bool` indicating whether the account is writable or not,
520  /// and a `bool` indicating whether the account is a signer or not.
521  #[inline(always)]
522  pub fn add_remaining_accounts(&mut self, accounts: &[(&'b solana_account_info::AccountInfo<'a>, bool, bool)]) -> &mut Self {
523    self.instruction.__remaining_accounts.extend_from_slice(accounts);
524    self
525  }
526  #[inline(always)]
527  pub fn invoke(&self) -> solana_program_error::ProgramResult {
528    self.invoke_signed(&[])
529  }
530  #[allow(clippy::clone_on_copy)]
531  #[allow(clippy::vec_init_then_push)]
532  pub fn invoke_signed(&self, signers_seeds: &[&[&[u8]]]) -> solana_program_error::ProgramResult {
533          let args = DepositInstructionArgs {
534                                                              amount: self.instruction.amount.clone().expect("amount is not set"),
535                                    };
536        let instruction = DepositCpi {
537        __program: self.instruction.__program,
538                  
539          authority: self.instruction.authority.expect("authority is not set"),
540                  
541          mint: self.instruction.mint.expect("mint is not set"),
542                  
543          tuna_config: self.instruction.tuna_config.expect("tuna_config is not set"),
544                  
545          lending_position: self.instruction.lending_position.expect("lending_position is not set"),
546                  
547          vault: self.instruction.vault.expect("vault is not set"),
548                  
549          vault_ata: self.instruction.vault_ata.expect("vault_ata is not set"),
550                  
551          authority_ata: self.instruction.authority_ata.expect("authority_ata is not set"),
552                  
553          token_program: self.instruction.token_program.expect("token_program is not set"),
554                  
555          memo_program: self.instruction.memo_program.expect("memo_program is not set"),
556                          __args: args,
557            };
558    instruction.invoke_signed_with_remaining_accounts(signers_seeds, &self.instruction.__remaining_accounts)
559  }
560}
561
562#[derive(Clone, Debug)]
563struct DepositCpiBuilderInstruction<'a, 'b> {
564  __program: &'b solana_account_info::AccountInfo<'a>,
565            authority: Option<&'b solana_account_info::AccountInfo<'a>>,
566                mint: Option<&'b solana_account_info::AccountInfo<'a>>,
567                tuna_config: Option<&'b solana_account_info::AccountInfo<'a>>,
568                lending_position: Option<&'b solana_account_info::AccountInfo<'a>>,
569                vault: Option<&'b solana_account_info::AccountInfo<'a>>,
570                vault_ata: Option<&'b solana_account_info::AccountInfo<'a>>,
571                authority_ata: Option<&'b solana_account_info::AccountInfo<'a>>,
572                token_program: Option<&'b solana_account_info::AccountInfo<'a>>,
573                memo_program: Option<&'b solana_account_info::AccountInfo<'a>>,
574                        amount: Option<u64>,
575        /// Additional instruction accounts `(AccountInfo, is_writable, is_signer)`.
576  __remaining_accounts: Vec<(&'b solana_account_info::AccountInfo<'a>, bool, bool)>,
577}
578