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