Skip to main content

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