Skip to main content

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