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