Skip to main content

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