defituna_client/generated/instructions/
create_vault_v2.rs

1//! This code was AUTOGENERATED using the codama library.
2//! Please DO NOT EDIT THIS FILE, instead use visitors
3//! to add features, then rerun codama to update it.
4//!
5//! <https://github.com/codama-idl/codama>
6//!
7
8use solana_pubkey::Pubkey;
9use borsh::BorshSerialize;
10use borsh::BorshDeserialize;
11
12pub const CREATE_VAULT_V2_DISCRIMINATOR: [u8; 8] = [149, 224, 90, 50, 87, 159, 31, 221];
13
14/// Accounts.
15#[derive(Debug)]
16pub struct CreateVaultV2 {
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 CreateVaultV2 {
41  pub fn instruction(&self, args: CreateVaultV2InstructionArgs) -> 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: CreateVaultV2InstructionArgs, 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(&CreateVaultV2InstructionData::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 CreateVaultV2InstructionData {
92            discriminator: [u8; 8],
93                                          }
94
95impl CreateVaultV2InstructionData {
96  pub fn new() -> Self {
97    Self {
98                        discriminator: [149, 224, 90, 50, 87, 159, 31, 221],
99                                                                                                      }
100  }
101}
102
103impl Default for CreateVaultV2InstructionData {
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 CreateVaultV2InstructionArgs {
112                  pub id: u32,
113                pub interest_rate: u64,
114                pub supply_limit: u64,
115                pub pyth_oracle_price_update: Pubkey,
116                pub pyth_oracle_feed_id: Pubkey,
117                pub allow_unsafe_token_extensions: bool,
118      }
119
120
121/// Instruction builder for `CreateVaultV2`.
122///
123/// ### Accounts:
124///
125                      ///   0. `[writable, signer]` authority
126          ///   1. `[]` mint
127          ///   2. `[]` tuna_config
128                ///   3. `[writable]` vault
129                ///   4. `[writable]` vault_ata
130                ///   5. `[optional]` token_program (default to `TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA`)
131                ///   6. `[optional]` system_program (default to `11111111111111111111111111111111`)
132#[derive(Clone, Debug, Default)]
133pub struct CreateVaultV2Builder {
134            authority: Option<solana_pubkey::Pubkey>,
135                mint: Option<solana_pubkey::Pubkey>,
136                tuna_config: Option<solana_pubkey::Pubkey>,
137                vault: Option<solana_pubkey::Pubkey>,
138                vault_ata: Option<solana_pubkey::Pubkey>,
139                token_program: Option<solana_pubkey::Pubkey>,
140                system_program: Option<solana_pubkey::Pubkey>,
141                        id: Option<u32>,
142                interest_rate: Option<u64>,
143                supply_limit: Option<u64>,
144                pyth_oracle_price_update: Option<Pubkey>,
145                pyth_oracle_feed_id: Option<Pubkey>,
146                allow_unsafe_token_extensions: Option<bool>,
147        __remaining_accounts: Vec<solana_instruction::AccountMeta>,
148}
149
150impl CreateVaultV2Builder {
151  pub fn new() -> Self {
152    Self::default()
153  }
154            #[inline(always)]
155    pub fn authority(&mut self, authority: solana_pubkey::Pubkey) -> &mut Self {
156                        self.authority = Some(authority);
157                    self
158    }
159            #[inline(always)]
160    pub fn mint(&mut self, mint: solana_pubkey::Pubkey) -> &mut Self {
161                        self.mint = Some(mint);
162                    self
163    }
164            #[inline(always)]
165    pub fn tuna_config(&mut self, tuna_config: solana_pubkey::Pubkey) -> &mut Self {
166                        self.tuna_config = Some(tuna_config);
167                    self
168    }
169            #[inline(always)]
170    pub fn vault(&mut self, vault: solana_pubkey::Pubkey) -> &mut Self {
171                        self.vault = Some(vault);
172                    self
173    }
174            #[inline(always)]
175    pub fn vault_ata(&mut self, vault_ata: solana_pubkey::Pubkey) -> &mut Self {
176                        self.vault_ata = Some(vault_ata);
177                    self
178    }
179            /// `[optional account, default to 'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA']`
180#[inline(always)]
181    pub fn token_program(&mut self, token_program: solana_pubkey::Pubkey) -> &mut Self {
182                        self.token_program = Some(token_program);
183                    self
184    }
185            /// `[optional account, default to '11111111111111111111111111111111']`
186#[inline(always)]
187    pub fn system_program(&mut self, system_program: solana_pubkey::Pubkey) -> &mut Self {
188                        self.system_program = Some(system_program);
189                    self
190    }
191                    #[inline(always)]
192      pub fn id(&mut self, id: u32) -> &mut Self {
193        self.id = Some(id);
194        self
195      }
196                #[inline(always)]
197      pub fn interest_rate(&mut self, interest_rate: u64) -> &mut Self {
198        self.interest_rate = Some(interest_rate);
199        self
200      }
201                #[inline(always)]
202      pub fn supply_limit(&mut self, supply_limit: u64) -> &mut Self {
203        self.supply_limit = Some(supply_limit);
204        self
205      }
206                #[inline(always)]
207      pub fn pyth_oracle_price_update(&mut self, pyth_oracle_price_update: Pubkey) -> &mut Self {
208        self.pyth_oracle_price_update = Some(pyth_oracle_price_update);
209        self
210      }
211                #[inline(always)]
212      pub fn pyth_oracle_feed_id(&mut self, pyth_oracle_feed_id: Pubkey) -> &mut Self {
213        self.pyth_oracle_feed_id = Some(pyth_oracle_feed_id);
214        self
215      }
216                #[inline(always)]
217      pub fn allow_unsafe_token_extensions(&mut self, allow_unsafe_token_extensions: bool) -> &mut Self {
218        self.allow_unsafe_token_extensions = Some(allow_unsafe_token_extensions);
219        self
220      }
221        /// Add an additional account to the instruction.
222  #[inline(always)]
223  pub fn add_remaining_account(&mut self, account: solana_instruction::AccountMeta) -> &mut Self {
224    self.__remaining_accounts.push(account);
225    self
226  }
227  /// Add additional accounts to the instruction.
228  #[inline(always)]
229  pub fn add_remaining_accounts(&mut self, accounts: &[solana_instruction::AccountMeta]) -> &mut Self {
230    self.__remaining_accounts.extend_from_slice(accounts);
231    self
232  }
233  #[allow(clippy::clone_on_copy)]
234  pub fn instruction(&self) -> solana_instruction::Instruction {
235    let accounts = CreateVaultV2 {
236                              authority: self.authority.expect("authority is not set"),
237                                        mint: self.mint.expect("mint is not set"),
238                                        tuna_config: self.tuna_config.expect("tuna_config is not set"),
239                                        vault: self.vault.expect("vault is not set"),
240                                        vault_ata: self.vault_ata.expect("vault_ata is not set"),
241                                        token_program: self.token_program.unwrap_or(solana_pubkey::pubkey!("TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA")),
242                                        system_program: self.system_program.unwrap_or(solana_pubkey::pubkey!("11111111111111111111111111111111")),
243                      };
244          let args = CreateVaultV2InstructionArgs {
245                                                              id: self.id.clone().expect("id is not set"),
246                                                                  interest_rate: self.interest_rate.clone().expect("interest_rate is not set"),
247                                                                  supply_limit: self.supply_limit.clone().expect("supply_limit is not set"),
248                                                                  pyth_oracle_price_update: self.pyth_oracle_price_update.clone().expect("pyth_oracle_price_update is not set"),
249                                                                  pyth_oracle_feed_id: self.pyth_oracle_feed_id.clone().expect("pyth_oracle_feed_id is not set"),
250                                                                  allow_unsafe_token_extensions: self.allow_unsafe_token_extensions.clone().expect("allow_unsafe_token_extensions is not set"),
251                                    };
252    
253    accounts.instruction_with_remaining_accounts(args, &self.__remaining_accounts)
254  }
255}
256
257  /// `create_vault_v2` CPI accounts.
258  pub struct CreateVaultV2CpiAccounts<'a, 'b> {
259          
260                    
261              pub authority: &'b solana_account_info::AccountInfo<'a>,
262                
263                    
264              pub mint: &'b solana_account_info::AccountInfo<'a>,
265                
266                    
267              pub tuna_config: &'b solana_account_info::AccountInfo<'a>,
268                
269                    
270              pub vault: &'b solana_account_info::AccountInfo<'a>,
271                
272                    
273              pub vault_ata: &'b solana_account_info::AccountInfo<'a>,
274                
275                    
276              pub token_program: &'b solana_account_info::AccountInfo<'a>,
277                
278                    
279              pub system_program: &'b solana_account_info::AccountInfo<'a>,
280            }
281
282/// `create_vault_v2` CPI instruction.
283pub struct CreateVaultV2Cpi<'a, 'b> {
284  /// The program to invoke.
285  pub __program: &'b solana_account_info::AccountInfo<'a>,
286      
287              
288          pub authority: &'b solana_account_info::AccountInfo<'a>,
289          
290              
291          pub mint: &'b solana_account_info::AccountInfo<'a>,
292          
293              
294          pub tuna_config: &'b solana_account_info::AccountInfo<'a>,
295          
296              
297          pub vault: &'b solana_account_info::AccountInfo<'a>,
298          
299              
300          pub vault_ata: &'b solana_account_info::AccountInfo<'a>,
301          
302              
303          pub token_program: &'b solana_account_info::AccountInfo<'a>,
304          
305              
306          pub system_program: &'b solana_account_info::AccountInfo<'a>,
307            /// The arguments for the instruction.
308    pub __args: CreateVaultV2InstructionArgs,
309  }
310
311impl<'a, 'b> CreateVaultV2Cpi<'a, 'b> {
312  pub fn new(
313    program: &'b solana_account_info::AccountInfo<'a>,
314          accounts: CreateVaultV2CpiAccounts<'a, 'b>,
315              args: CreateVaultV2InstructionArgs,
316      ) -> Self {
317    Self {
318      __program: program,
319              authority: accounts.authority,
320              mint: accounts.mint,
321              tuna_config: accounts.tuna_config,
322              vault: accounts.vault,
323              vault_ata: accounts.vault_ata,
324              token_program: accounts.token_program,
325              system_program: accounts.system_program,
326                    __args: args,
327          }
328  }
329  #[inline(always)]
330  pub fn invoke(&self) -> solana_program_error::ProgramResult {
331    self.invoke_signed_with_remaining_accounts(&[], &[])
332  }
333  #[inline(always)]
334  pub fn invoke_with_remaining_accounts(&self, remaining_accounts: &[(&'b solana_account_info::AccountInfo<'a>, bool, bool)]) -> solana_program_error::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_error::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_account_info::AccountInfo<'a>, bool, bool)]
348  ) -> solana_program_error::ProgramResult {
349    let mut accounts = Vec::with_capacity(7+ remaining_accounts.len());
350                            accounts.push(solana_instruction::AccountMeta::new(
351            *self.authority.key,
352            true
353          ));
354                                          accounts.push(solana_instruction::AccountMeta::new_readonly(
355            *self.mint.key,
356            false
357          ));
358                                          accounts.push(solana_instruction::AccountMeta::new_readonly(
359            *self.tuna_config.key,
360            false
361          ));
362                                          accounts.push(solana_instruction::AccountMeta::new(
363            *self.vault.key,
364            false
365          ));
366                                          accounts.push(solana_instruction::AccountMeta::new(
367            *self.vault_ata.key,
368            false
369          ));
370                                          accounts.push(solana_instruction::AccountMeta::new_readonly(
371            *self.token_program.key,
372            false
373          ));
374                                          accounts.push(solana_instruction::AccountMeta::new_readonly(
375            *self.system_program.key,
376            false
377          ));
378                      remaining_accounts.iter().for_each(|remaining_account| {
379      accounts.push(solana_instruction::AccountMeta {
380          pubkey: *remaining_account.0.key,
381          is_signer: remaining_account.1,
382          is_writable: remaining_account.2,
383      })
384    });
385    let mut data = borsh::to_vec(&CreateVaultV2InstructionData::new()).unwrap();
386          let mut args = borsh::to_vec(&self.__args).unwrap();
387      data.append(&mut args);
388    
389    let instruction = solana_instruction::Instruction {
390      program_id: crate::TUNA_ID,
391      accounts,
392      data,
393    };
394    let mut account_infos = Vec::with_capacity(8 + remaining_accounts.len());
395    account_infos.push(self.__program.clone());
396                  account_infos.push(self.authority.clone());
397                        account_infos.push(self.mint.clone());
398                        account_infos.push(self.tuna_config.clone());
399                        account_infos.push(self.vault.clone());
400                        account_infos.push(self.vault_ata.clone());
401                        account_infos.push(self.token_program.clone());
402                        account_infos.push(self.system_program.clone());
403              remaining_accounts.iter().for_each(|remaining_account| account_infos.push(remaining_account.0.clone()));
404
405    if signers_seeds.is_empty() {
406      solana_cpi::invoke(&instruction, &account_infos)
407    } else {
408      solana_cpi::invoke_signed(&instruction, &account_infos, signers_seeds)
409    }
410  }
411}
412
413/// Instruction builder for `CreateVaultV2` via CPI.
414///
415/// ### Accounts:
416///
417                      ///   0. `[writable, signer]` authority
418          ///   1. `[]` mint
419          ///   2. `[]` tuna_config
420                ///   3. `[writable]` vault
421                ///   4. `[writable]` vault_ata
422          ///   5. `[]` token_program
423          ///   6. `[]` system_program
424#[derive(Clone, Debug)]
425pub struct CreateVaultV2CpiBuilder<'a, 'b> {
426  instruction: Box<CreateVaultV2CpiBuilderInstruction<'a, 'b>>,
427}
428
429impl<'a, 'b> CreateVaultV2CpiBuilder<'a, 'b> {
430  pub fn new(program: &'b solana_account_info::AccountInfo<'a>) -> Self {
431    let instruction = Box::new(CreateVaultV2CpiBuilderInstruction {
432      __program: program,
433              authority: None,
434              mint: None,
435              tuna_config: None,
436              vault: None,
437              vault_ata: None,
438              token_program: None,
439              system_program: None,
440                                            id: None,
441                                interest_rate: None,
442                                supply_limit: None,
443                                pyth_oracle_price_update: None,
444                                pyth_oracle_feed_id: None,
445                                allow_unsafe_token_extensions: None,
446                    __remaining_accounts: Vec::new(),
447    });
448    Self { instruction }
449  }
450      #[inline(always)]
451    pub fn authority(&mut self, authority: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
452                        self.instruction.authority = Some(authority);
453                    self
454    }
455      #[inline(always)]
456    pub fn mint(&mut self, mint: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
457                        self.instruction.mint = Some(mint);
458                    self
459    }
460      #[inline(always)]
461    pub fn tuna_config(&mut self, tuna_config: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
462                        self.instruction.tuna_config = Some(tuna_config);
463                    self
464    }
465      #[inline(always)]
466    pub fn vault(&mut self, vault: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
467                        self.instruction.vault = Some(vault);
468                    self
469    }
470      #[inline(always)]
471    pub fn vault_ata(&mut self, vault_ata: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
472                        self.instruction.vault_ata = Some(vault_ata);
473                    self
474    }
475      #[inline(always)]
476    pub fn token_program(&mut self, token_program: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
477                        self.instruction.token_program = Some(token_program);
478                    self
479    }
480      #[inline(always)]
481    pub fn system_program(&mut self, system_program: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
482                        self.instruction.system_program = Some(system_program);
483                    self
484    }
485                    #[inline(always)]
486      pub fn id(&mut self, id: u32) -> &mut Self {
487        self.instruction.id = Some(id);
488        self
489      }
490                #[inline(always)]
491      pub fn interest_rate(&mut self, interest_rate: u64) -> &mut Self {
492        self.instruction.interest_rate = Some(interest_rate);
493        self
494      }
495                #[inline(always)]
496      pub fn supply_limit(&mut self, supply_limit: u64) -> &mut Self {
497        self.instruction.supply_limit = Some(supply_limit);
498        self
499      }
500                #[inline(always)]
501      pub fn pyth_oracle_price_update(&mut self, pyth_oracle_price_update: Pubkey) -> &mut Self {
502        self.instruction.pyth_oracle_price_update = Some(pyth_oracle_price_update);
503        self
504      }
505                #[inline(always)]
506      pub fn pyth_oracle_feed_id(&mut self, pyth_oracle_feed_id: Pubkey) -> &mut Self {
507        self.instruction.pyth_oracle_feed_id = Some(pyth_oracle_feed_id);
508        self
509      }
510                #[inline(always)]
511      pub fn allow_unsafe_token_extensions(&mut self, allow_unsafe_token_extensions: bool) -> &mut Self {
512        self.instruction.allow_unsafe_token_extensions = Some(allow_unsafe_token_extensions);
513        self
514      }
515        /// Add an additional account to the instruction.
516  #[inline(always)]
517  pub fn add_remaining_account(&mut self, account: &'b solana_account_info::AccountInfo<'a>, is_writable: bool, is_signer: bool) -> &mut Self {
518    self.instruction.__remaining_accounts.push((account, is_writable, is_signer));
519    self
520  }
521  /// Add additional accounts to the instruction.
522  ///
523  /// Each account is represented by a tuple of the `AccountInfo`, a `bool` indicating whether the account is writable or not,
524  /// and a `bool` indicating whether the account is a signer or not.
525  #[inline(always)]
526  pub fn add_remaining_accounts(&mut self, accounts: &[(&'b solana_account_info::AccountInfo<'a>, bool, bool)]) -> &mut Self {
527    self.instruction.__remaining_accounts.extend_from_slice(accounts);
528    self
529  }
530  #[inline(always)]
531  pub fn invoke(&self) -> solana_program_error::ProgramResult {
532    self.invoke_signed(&[])
533  }
534  #[allow(clippy::clone_on_copy)]
535  #[allow(clippy::vec_init_then_push)]
536  pub fn invoke_signed(&self, signers_seeds: &[&[&[u8]]]) -> solana_program_error::ProgramResult {
537          let args = CreateVaultV2InstructionArgs {
538                                                              id: self.instruction.id.clone().expect("id is not set"),
539                                                                  interest_rate: self.instruction.interest_rate.clone().expect("interest_rate is not set"),
540                                                                  supply_limit: self.instruction.supply_limit.clone().expect("supply_limit is not set"),
541                                                                  pyth_oracle_price_update: self.instruction.pyth_oracle_price_update.clone().expect("pyth_oracle_price_update is not set"),
542                                                                  pyth_oracle_feed_id: self.instruction.pyth_oracle_feed_id.clone().expect("pyth_oracle_feed_id is not set"),
543                                                                  allow_unsafe_token_extensions: self.instruction.allow_unsafe_token_extensions.clone().expect("allow_unsafe_token_extensions is not set"),
544                                    };
545        let instruction = CreateVaultV2Cpi {
546        __program: self.instruction.__program,
547                  
548          authority: self.instruction.authority.expect("authority is not set"),
549                  
550          mint: self.instruction.mint.expect("mint is not set"),
551                  
552          tuna_config: self.instruction.tuna_config.expect("tuna_config is not set"),
553                  
554          vault: self.instruction.vault.expect("vault is not set"),
555                  
556          vault_ata: self.instruction.vault_ata.expect("vault_ata is not set"),
557                  
558          token_program: self.instruction.token_program.expect("token_program is not set"),
559                  
560          system_program: self.instruction.system_program.expect("system_program is not set"),
561                          __args: args,
562            };
563    instruction.invoke_signed_with_remaining_accounts(signers_seeds, &self.instruction.__remaining_accounts)
564  }
565}
566
567#[derive(Clone, Debug)]
568struct CreateVaultV2CpiBuilderInstruction<'a, 'b> {
569  __program: &'b solana_account_info::AccountInfo<'a>,
570            authority: Option<&'b solana_account_info::AccountInfo<'a>>,
571                mint: Option<&'b solana_account_info::AccountInfo<'a>>,
572                tuna_config: Option<&'b solana_account_info::AccountInfo<'a>>,
573                vault: Option<&'b solana_account_info::AccountInfo<'a>>,
574                vault_ata: Option<&'b solana_account_info::AccountInfo<'a>>,
575                token_program: Option<&'b solana_account_info::AccountInfo<'a>>,
576                system_program: Option<&'b solana_account_info::AccountInfo<'a>>,
577                        id: Option<u32>,
578                interest_rate: Option<u64>,
579                supply_limit: Option<u64>,
580                pyth_oracle_price_update: Option<Pubkey>,
581                pyth_oracle_feed_id: Option<Pubkey>,
582                allow_unsafe_token_extensions: Option<bool>,
583        /// Additional instruction accounts `(AccountInfo, is_writable, is_signer)`.
584  __remaining_accounts: Vec<(&'b solana_account_info::AccountInfo<'a>, bool, bool)>,
585}
586