Skip to main content

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