Skip to main content

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