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