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