Skip to main content

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