defituna_staking/generated/instructions/
initialize_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 InitializeVestingStrategy {
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 InitializeVestingStrategy {
32  pub fn instruction(&self) -> solana_instruction::Instruction {
33    self.instruction_with_remaining_accounts(&[])
34  }
35  #[allow(clippy::arithmetic_side_effects)]
36  #[allow(clippy::vec_init_then_push)]
37  pub fn instruction_with_remaining_accounts(&self, 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 data = borsh::to_vec(&InitializeVestingStrategyInstructionData::new()).unwrap();
61    
62    solana_instruction::Instruction {
63      program_id: crate::TUNA_STAKING_ID,
64      accounts,
65      data,
66    }
67  }
68}
69
70#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)]
71#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
72 pub struct InitializeVestingStrategyInstructionData {
73            discriminator: [u8; 8],
74      }
75
76impl InitializeVestingStrategyInstructionData {
77  pub fn new() -> Self {
78    Self {
79                        discriminator: [126, 24, 249, 253, 186, 110, 193, 161],
80                  }
81  }
82}
83
84impl Default for InitializeVestingStrategyInstructionData {
85  fn default() -> Self {
86    Self::new()
87  }
88}
89
90
91
92/// Instruction builder for `InitializeVestingStrategy`.
93///
94/// ### Accounts:
95///
96                      ///   0. `[writable, signer]` authority
97          ///   1. `[]` owner
98                ///   2. `[writable]` treasury
99                ///   3. `[writable]` vesting_strategy
100                ///   4. `[optional]` system_program (default to `11111111111111111111111111111111`)
101#[derive(Clone, Debug, Default)]
102pub struct InitializeVestingStrategyBuilder {
103            authority: Option<solana_pubkey::Pubkey>,
104                owner: Option<solana_pubkey::Pubkey>,
105                treasury: Option<solana_pubkey::Pubkey>,
106                vesting_strategy: Option<solana_pubkey::Pubkey>,
107                system_program: Option<solana_pubkey::Pubkey>,
108                __remaining_accounts: Vec<solana_instruction::AccountMeta>,
109}
110
111impl InitializeVestingStrategyBuilder {
112  pub fn new() -> Self {
113    Self::default()
114  }
115            #[inline(always)]
116    pub fn authority(&mut self, authority: solana_pubkey::Pubkey) -> &mut Self {
117                        self.authority = Some(authority);
118                    self
119    }
120            #[inline(always)]
121    pub fn owner(&mut self, owner: solana_pubkey::Pubkey) -> &mut Self {
122                        self.owner = Some(owner);
123                    self
124    }
125            #[inline(always)]
126    pub fn treasury(&mut self, treasury: solana_pubkey::Pubkey) -> &mut Self {
127                        self.treasury = Some(treasury);
128                    self
129    }
130            #[inline(always)]
131    pub fn vesting_strategy(&mut self, vesting_strategy: solana_pubkey::Pubkey) -> &mut Self {
132                        self.vesting_strategy = Some(vesting_strategy);
133                    self
134    }
135            /// `[optional account, default to '11111111111111111111111111111111']`
136#[inline(always)]
137    pub fn system_program(&mut self, system_program: solana_pubkey::Pubkey) -> &mut Self {
138                        self.system_program = Some(system_program);
139                    self
140    }
141            /// Add an additional account to the instruction.
142  #[inline(always)]
143  pub fn add_remaining_account(&mut self, account: solana_instruction::AccountMeta) -> &mut Self {
144    self.__remaining_accounts.push(account);
145    self
146  }
147  /// Add additional accounts to the instruction.
148  #[inline(always)]
149  pub fn add_remaining_accounts(&mut self, accounts: &[solana_instruction::AccountMeta]) -> &mut Self {
150    self.__remaining_accounts.extend_from_slice(accounts);
151    self
152  }
153  #[allow(clippy::clone_on_copy)]
154  pub fn instruction(&self) -> solana_instruction::Instruction {
155    let accounts = InitializeVestingStrategy {
156                              authority: self.authority.expect("authority is not set"),
157                                        owner: self.owner.expect("owner is not set"),
158                                        treasury: self.treasury.expect("treasury is not set"),
159                                        vesting_strategy: self.vesting_strategy.expect("vesting_strategy is not set"),
160                                        system_program: self.system_program.unwrap_or(solana_pubkey::pubkey!("11111111111111111111111111111111")),
161                      };
162    
163    accounts.instruction_with_remaining_accounts(&self.__remaining_accounts)
164  }
165}
166
167  /// `initialize_vesting_strategy` CPI accounts.
168  pub struct InitializeVestingStrategyCpiAccounts<'a, 'b> {
169          
170                    
171              pub authority: &'b solana_account_info::AccountInfo<'a>,
172                
173                    
174              pub owner: &'b solana_account_info::AccountInfo<'a>,
175                
176                    
177              pub treasury: &'b solana_account_info::AccountInfo<'a>,
178                
179                    
180              pub vesting_strategy: &'b solana_account_info::AccountInfo<'a>,
181                
182                    
183              pub system_program: &'b solana_account_info::AccountInfo<'a>,
184            }
185
186/// `initialize_vesting_strategy` CPI instruction.
187pub struct InitializeVestingStrategyCpi<'a, 'b> {
188  /// The program to invoke.
189  pub __program: &'b solana_account_info::AccountInfo<'a>,
190      
191              
192          pub authority: &'b solana_account_info::AccountInfo<'a>,
193          
194              
195          pub owner: &'b solana_account_info::AccountInfo<'a>,
196          
197              
198          pub treasury: &'b solana_account_info::AccountInfo<'a>,
199          
200              
201          pub vesting_strategy: &'b solana_account_info::AccountInfo<'a>,
202          
203              
204          pub system_program: &'b solana_account_info::AccountInfo<'a>,
205        }
206
207impl<'a, 'b> InitializeVestingStrategyCpi<'a, 'b> {
208  pub fn new(
209    program: &'b solana_account_info::AccountInfo<'a>,
210          accounts: InitializeVestingStrategyCpiAccounts<'a, 'b>,
211          ) -> Self {
212    Self {
213      __program: program,
214              authority: accounts.authority,
215              owner: accounts.owner,
216              treasury: accounts.treasury,
217              vesting_strategy: accounts.vesting_strategy,
218              system_program: accounts.system_program,
219                }
220  }
221  #[inline(always)]
222  pub fn invoke(&self) -> solana_program_entrypoint::ProgramResult {
223    self.invoke_signed_with_remaining_accounts(&[], &[])
224  }
225  #[inline(always)]
226  pub fn invoke_with_remaining_accounts(&self, remaining_accounts: &[(&'b solana_account_info::AccountInfo<'a>, bool, bool)]) -> solana_program_entrypoint::ProgramResult {
227    self.invoke_signed_with_remaining_accounts(&[], remaining_accounts)
228  }
229  #[inline(always)]
230  pub fn invoke_signed(&self, signers_seeds: &[&[&[u8]]]) -> solana_program_entrypoint::ProgramResult {
231    self.invoke_signed_with_remaining_accounts(signers_seeds, &[])
232  }
233  #[allow(clippy::arithmetic_side_effects)]
234  #[allow(clippy::clone_on_copy)]
235  #[allow(clippy::vec_init_then_push)]
236  pub fn invoke_signed_with_remaining_accounts(
237    &self,
238    signers_seeds: &[&[&[u8]]],
239    remaining_accounts: &[(&'b solana_account_info::AccountInfo<'a>, bool, bool)]
240  ) -> solana_program_entrypoint::ProgramResult {
241    let mut accounts = Vec::with_capacity(5+ remaining_accounts.len());
242                            accounts.push(solana_instruction::AccountMeta::new(
243            *self.authority.key,
244            true
245          ));
246                                          accounts.push(solana_instruction::AccountMeta::new_readonly(
247            *self.owner.key,
248            false
249          ));
250                                          accounts.push(solana_instruction::AccountMeta::new(
251            *self.treasury.key,
252            false
253          ));
254                                          accounts.push(solana_instruction::AccountMeta::new(
255            *self.vesting_strategy.key,
256            false
257          ));
258                                          accounts.push(solana_instruction::AccountMeta::new_readonly(
259            *self.system_program.key,
260            false
261          ));
262                      remaining_accounts.iter().for_each(|remaining_account| {
263      accounts.push(solana_instruction::AccountMeta {
264          pubkey: *remaining_account.0.key,
265          is_signer: remaining_account.1,
266          is_writable: remaining_account.2,
267      })
268    });
269    let data = borsh::to_vec(&InitializeVestingStrategyInstructionData::new()).unwrap();
270    
271    let instruction = solana_instruction::Instruction {
272      program_id: crate::TUNA_STAKING_ID,
273      accounts,
274      data,
275    };
276    let mut account_infos = Vec::with_capacity(6 + remaining_accounts.len());
277    account_infos.push(self.__program.clone());
278                  account_infos.push(self.authority.clone());
279                        account_infos.push(self.owner.clone());
280                        account_infos.push(self.treasury.clone());
281                        account_infos.push(self.vesting_strategy.clone());
282                        account_infos.push(self.system_program.clone());
283              remaining_accounts.iter().for_each(|remaining_account| account_infos.push(remaining_account.0.clone()));
284
285    if signers_seeds.is_empty() {
286      solana_cpi::invoke(&instruction, &account_infos)
287    } else {
288      solana_cpi::invoke_signed(&instruction, &account_infos, signers_seeds)
289    }
290  }
291}
292
293/// Instruction builder for `InitializeVestingStrategy` via CPI.
294///
295/// ### Accounts:
296///
297                      ///   0. `[writable, signer]` authority
298          ///   1. `[]` owner
299                ///   2. `[writable]` treasury
300                ///   3. `[writable]` vesting_strategy
301          ///   4. `[]` system_program
302#[derive(Clone, Debug)]
303pub struct InitializeVestingStrategyCpiBuilder<'a, 'b> {
304  instruction: Box<InitializeVestingStrategyCpiBuilderInstruction<'a, 'b>>,
305}
306
307impl<'a, 'b> InitializeVestingStrategyCpiBuilder<'a, 'b> {
308  pub fn new(program: &'b solana_account_info::AccountInfo<'a>) -> Self {
309    let instruction = Box::new(InitializeVestingStrategyCpiBuilderInstruction {
310      __program: program,
311              authority: None,
312              owner: None,
313              treasury: None,
314              vesting_strategy: None,
315              system_program: None,
316                                __remaining_accounts: Vec::new(),
317    });
318    Self { instruction }
319  }
320      #[inline(always)]
321    pub fn authority(&mut self, authority: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
322                        self.instruction.authority = Some(authority);
323                    self
324    }
325      #[inline(always)]
326    pub fn owner(&mut self, owner: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
327                        self.instruction.owner = Some(owner);
328                    self
329    }
330      #[inline(always)]
331    pub fn treasury(&mut self, treasury: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
332                        self.instruction.treasury = Some(treasury);
333                    self
334    }
335      #[inline(always)]
336    pub fn vesting_strategy(&mut self, vesting_strategy: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
337                        self.instruction.vesting_strategy = Some(vesting_strategy);
338                    self
339    }
340      #[inline(always)]
341    pub fn system_program(&mut self, system_program: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
342                        self.instruction.system_program = Some(system_program);
343                    self
344    }
345            /// Add an additional account to the instruction.
346  #[inline(always)]
347  pub fn add_remaining_account(&mut self, account: &'b solana_account_info::AccountInfo<'a>, is_writable: bool, is_signer: bool) -> &mut Self {
348    self.instruction.__remaining_accounts.push((account, is_writable, is_signer));
349    self
350  }
351  /// Add additional accounts to the instruction.
352  ///
353  /// Each account is represented by a tuple of the `AccountInfo`, a `bool` indicating whether the account is writable or not,
354  /// and a `bool` indicating whether the account is a signer or not.
355  #[inline(always)]
356  pub fn add_remaining_accounts(&mut self, accounts: &[(&'b solana_account_info::AccountInfo<'a>, bool, bool)]) -> &mut Self {
357    self.instruction.__remaining_accounts.extend_from_slice(accounts);
358    self
359  }
360  #[inline(always)]
361  pub fn invoke(&self) -> solana_program_entrypoint::ProgramResult {
362    self.invoke_signed(&[])
363  }
364  #[allow(clippy::clone_on_copy)]
365  #[allow(clippy::vec_init_then_push)]
366  pub fn invoke_signed(&self, signers_seeds: &[&[&[u8]]]) -> solana_program_entrypoint::ProgramResult {
367        let instruction = InitializeVestingStrategyCpi {
368        __program: self.instruction.__program,
369                  
370          authority: self.instruction.authority.expect("authority is not set"),
371                  
372          owner: self.instruction.owner.expect("owner is not set"),
373                  
374          treasury: self.instruction.treasury.expect("treasury is not set"),
375                  
376          vesting_strategy: self.instruction.vesting_strategy.expect("vesting_strategy is not set"),
377                  
378          system_program: self.instruction.system_program.expect("system_program is not set"),
379                    };
380    instruction.invoke_signed_with_remaining_accounts(signers_seeds, &self.instruction.__remaining_accounts)
381  }
382}
383
384#[derive(Clone, Debug)]
385struct InitializeVestingStrategyCpiBuilderInstruction<'a, 'b> {
386  __program: &'b solana_account_info::AccountInfo<'a>,
387            authority: Option<&'b solana_account_info::AccountInfo<'a>>,
388                owner: Option<&'b solana_account_info::AccountInfo<'a>>,
389                treasury: Option<&'b solana_account_info::AccountInfo<'a>>,
390                vesting_strategy: Option<&'b solana_account_info::AccountInfo<'a>>,
391                system_program: Option<&'b solana_account_info::AccountInfo<'a>>,
392                /// Additional instruction accounts `(AccountInfo, is_writable, is_signer)`.
393  __remaining_accounts: Vec<(&'b solana_account_info::AccountInfo<'a>, bool, bool)>,
394}
395