Skip to main content

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