Skip to main content

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