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