Skip to main content

meteora_sol/instructions/
update_position_operator.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;
10use solana_pubkey::Pubkey;
11
12/// Accounts.
13#[derive(Debug)]
14pub struct UpdatePositionOperator {
15    pub position: solana_pubkey::Pubkey,
16
17    pub owner: solana_pubkey::Pubkey,
18
19    pub event_authority: solana_pubkey::Pubkey,
20
21    pub program: solana_pubkey::Pubkey,
22}
23
24impl UpdatePositionOperator {
25    pub fn instruction(
26        &self,
27        args: UpdatePositionOperatorInstructionArgs,
28    ) -> solana_instruction::Instruction {
29        self.instruction_with_remaining_accounts(args, &[])
30    }
31    #[allow(clippy::arithmetic_side_effects)]
32    #[allow(clippy::vec_init_then_push)]
33    pub fn instruction_with_remaining_accounts(
34        &self,
35        args: UpdatePositionOperatorInstructionArgs,
36        remaining_accounts: &[solana_instruction::AccountMeta],
37    ) -> solana_instruction::Instruction {
38        let mut accounts = Vec::with_capacity(4 + remaining_accounts.len());
39        accounts.push(solana_instruction::AccountMeta::new(self.position, false));
40        accounts.push(solana_instruction::AccountMeta::new_readonly(
41            self.owner, true,
42        ));
43        accounts.push(solana_instruction::AccountMeta::new_readonly(
44            self.event_authority,
45            false,
46        ));
47        accounts.push(solana_instruction::AccountMeta::new_readonly(
48            self.program,
49            false,
50        ));
51        accounts.extend_from_slice(remaining_accounts);
52        let mut data = borsh::to_vec(&UpdatePositionOperatorInstructionData::new()).unwrap();
53        let mut args = borsh::to_vec(&args).unwrap();
54        data.append(&mut args);
55
56        solana_instruction::Instruction {
57            program_id: crate::LB_CLMM_ID,
58            accounts,
59            data,
60        }
61    }
62}
63
64#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)]
65#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
66pub struct UpdatePositionOperatorInstructionData {
67    discriminator: [u8; 8],
68}
69
70impl UpdatePositionOperatorInstructionData {
71    pub fn new() -> Self {
72        Self {
73            discriminator: [202, 184, 103, 143, 180, 191, 116, 217],
74        }
75    }
76}
77
78impl Default for UpdatePositionOperatorInstructionData {
79    fn default() -> Self {
80        Self::new()
81    }
82}
83
84#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)]
85#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
86pub struct UpdatePositionOperatorInstructionArgs {
87    pub operator: Pubkey,
88}
89
90/// Instruction builder for `UpdatePositionOperator`.
91///
92/// ### Accounts:
93///
94///   0. `[writable]` position
95///   1. `[signer]` owner
96///   2. `[]` event_authority
97///   3. `[]` program
98#[derive(Clone, Debug, Default)]
99pub struct UpdatePositionOperatorBuilder {
100    position: Option<solana_pubkey::Pubkey>,
101    owner: Option<solana_pubkey::Pubkey>,
102    event_authority: Option<solana_pubkey::Pubkey>,
103    program: Option<solana_pubkey::Pubkey>,
104    operator: Option<Pubkey>,
105    __remaining_accounts: Vec<solana_instruction::AccountMeta>,
106}
107
108impl UpdatePositionOperatorBuilder {
109    pub fn new() -> Self {
110        Self::default()
111    }
112    #[inline(always)]
113    pub fn position(&mut self, position: solana_pubkey::Pubkey) -> &mut Self {
114        self.position = Some(position);
115        self
116    }
117    #[inline(always)]
118    pub fn owner(&mut self, owner: solana_pubkey::Pubkey) -> &mut Self {
119        self.owner = Some(owner);
120        self
121    }
122    #[inline(always)]
123    pub fn event_authority(&mut self, event_authority: solana_pubkey::Pubkey) -> &mut Self {
124        self.event_authority = Some(event_authority);
125        self
126    }
127    #[inline(always)]
128    pub fn program(&mut self, program: solana_pubkey::Pubkey) -> &mut Self {
129        self.program = Some(program);
130        self
131    }
132    #[inline(always)]
133    pub fn operator(&mut self, operator: Pubkey) -> &mut Self {
134        self.operator = Some(operator);
135        self
136    }
137    /// Add an additional account to the instruction.
138    #[inline(always)]
139    pub fn add_remaining_account(&mut self, account: solana_instruction::AccountMeta) -> &mut Self {
140        self.__remaining_accounts.push(account);
141        self
142    }
143    /// Add additional accounts to the instruction.
144    #[inline(always)]
145    pub fn add_remaining_accounts(
146        &mut self,
147        accounts: &[solana_instruction::AccountMeta],
148    ) -> &mut Self {
149        self.__remaining_accounts.extend_from_slice(accounts);
150        self
151    }
152    #[allow(clippy::clone_on_copy)]
153    pub fn instruction(&self) -> solana_instruction::Instruction {
154        let accounts = UpdatePositionOperator {
155            position: self.position.expect("position is not set"),
156            owner: self.owner.expect("owner is not set"),
157            event_authority: self.event_authority.expect("event_authority is not set"),
158            program: self.program.expect("program is not set"),
159        };
160        let args = UpdatePositionOperatorInstructionArgs {
161            operator: self.operator.clone().expect("operator is not set"),
162        };
163
164        accounts.instruction_with_remaining_accounts(args, &self.__remaining_accounts)
165    }
166}
167
168/// `update_position_operator` CPI accounts.
169pub struct UpdatePositionOperatorCpiAccounts<'a, 'b> {
170    pub position: &'b solana_account_info::AccountInfo<'a>,
171
172    pub owner: &'b solana_account_info::AccountInfo<'a>,
173
174    pub event_authority: &'b solana_account_info::AccountInfo<'a>,
175
176    pub program: &'b solana_account_info::AccountInfo<'a>,
177}
178
179/// `update_position_operator` CPI instruction.
180pub struct UpdatePositionOperatorCpi<'a, 'b> {
181    /// The program to invoke.
182    pub __program: &'b solana_account_info::AccountInfo<'a>,
183
184    pub position: &'b solana_account_info::AccountInfo<'a>,
185
186    pub owner: &'b solana_account_info::AccountInfo<'a>,
187
188    pub event_authority: &'b solana_account_info::AccountInfo<'a>,
189
190    pub program: &'b solana_account_info::AccountInfo<'a>,
191    /// The arguments for the instruction.
192    pub __args: UpdatePositionOperatorInstructionArgs,
193}
194
195impl<'a, 'b> UpdatePositionOperatorCpi<'a, 'b> {
196    pub fn new(
197        program: &'b solana_account_info::AccountInfo<'a>,
198        accounts: UpdatePositionOperatorCpiAccounts<'a, 'b>,
199        args: UpdatePositionOperatorInstructionArgs,
200    ) -> Self {
201        Self {
202            __program: program,
203            position: accounts.position,
204            owner: accounts.owner,
205            event_authority: accounts.event_authority,
206            program: accounts.program,
207            __args: args,
208        }
209    }
210    #[inline(always)]
211    pub fn invoke(&self) -> solana_program_entrypoint::ProgramResult {
212        self.invoke_signed_with_remaining_accounts(&[], &[])
213    }
214    #[inline(always)]
215    pub fn invoke_with_remaining_accounts(
216        &self,
217        remaining_accounts: &[(&'b solana_account_info::AccountInfo<'a>, bool, bool)],
218    ) -> solana_program_entrypoint::ProgramResult {
219        self.invoke_signed_with_remaining_accounts(&[], remaining_accounts)
220    }
221    #[inline(always)]
222    pub fn invoke_signed(
223        &self,
224        signers_seeds: &[&[&[u8]]],
225    ) -> solana_program_entrypoint::ProgramResult {
226        self.invoke_signed_with_remaining_accounts(signers_seeds, &[])
227    }
228    #[allow(clippy::arithmetic_side_effects)]
229    #[allow(clippy::clone_on_copy)]
230    #[allow(clippy::vec_init_then_push)]
231    pub fn invoke_signed_with_remaining_accounts(
232        &self,
233        signers_seeds: &[&[&[u8]]],
234        remaining_accounts: &[(&'b solana_account_info::AccountInfo<'a>, bool, bool)],
235    ) -> solana_program_entrypoint::ProgramResult {
236        let mut accounts = Vec::with_capacity(4 + remaining_accounts.len());
237        accounts.push(solana_instruction::AccountMeta::new(
238            *self.position.key,
239            false,
240        ));
241        accounts.push(solana_instruction::AccountMeta::new_readonly(
242            *self.owner.key,
243            true,
244        ));
245        accounts.push(solana_instruction::AccountMeta::new_readonly(
246            *self.event_authority.key,
247            false,
248        ));
249        accounts.push(solana_instruction::AccountMeta::new_readonly(
250            *self.program.key,
251            false,
252        ));
253        remaining_accounts.iter().for_each(|remaining_account| {
254            accounts.push(solana_instruction::AccountMeta {
255                pubkey: *remaining_account.0.key,
256                is_signer: remaining_account.1,
257                is_writable: remaining_account.2,
258            })
259        });
260        let mut data = borsh::to_vec(&UpdatePositionOperatorInstructionData::new()).unwrap();
261        let mut args = borsh::to_vec(&self.__args).unwrap();
262        data.append(&mut args);
263
264        let instruction = solana_instruction::Instruction {
265            program_id: crate::LB_CLMM_ID,
266            accounts,
267            data,
268        };
269        let mut account_infos = Vec::with_capacity(5 + remaining_accounts.len());
270        account_infos.push(self.__program.clone());
271        account_infos.push(self.position.clone());
272        account_infos.push(self.owner.clone());
273        account_infos.push(self.event_authority.clone());
274        account_infos.push(self.program.clone());
275        remaining_accounts
276            .iter()
277            .for_each(|remaining_account| account_infos.push(remaining_account.0.clone()));
278
279        if signers_seeds.is_empty() {
280            solana_cpi::invoke(&instruction, &account_infos)
281        } else {
282            solana_cpi::invoke_signed(&instruction, &account_infos, signers_seeds)
283        }
284    }
285}
286
287/// Instruction builder for `UpdatePositionOperator` via CPI.
288///
289/// ### Accounts:
290///
291///   0. `[writable]` position
292///   1. `[signer]` owner
293///   2. `[]` event_authority
294///   3. `[]` program
295#[derive(Clone, Debug)]
296pub struct UpdatePositionOperatorCpiBuilder<'a, 'b> {
297    instruction: Box<UpdatePositionOperatorCpiBuilderInstruction<'a, 'b>>,
298}
299
300impl<'a, 'b> UpdatePositionOperatorCpiBuilder<'a, 'b> {
301    pub fn new(program: &'b solana_account_info::AccountInfo<'a>) -> Self {
302        let instruction = Box::new(UpdatePositionOperatorCpiBuilderInstruction {
303            __program: program,
304            position: None,
305            owner: None,
306            event_authority: None,
307            program: None,
308            operator: None,
309            __remaining_accounts: Vec::new(),
310        });
311        Self { instruction }
312    }
313    #[inline(always)]
314    pub fn position(&mut self, position: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
315        self.instruction.position = Some(position);
316        self
317    }
318    #[inline(always)]
319    pub fn owner(&mut self, owner: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
320        self.instruction.owner = Some(owner);
321        self
322    }
323    #[inline(always)]
324    pub fn event_authority(
325        &mut self,
326        event_authority: &'b solana_account_info::AccountInfo<'a>,
327    ) -> &mut Self {
328        self.instruction.event_authority = Some(event_authority);
329        self
330    }
331    #[inline(always)]
332    pub fn program(&mut self, program: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
333        self.instruction.program = Some(program);
334        self
335    }
336    #[inline(always)]
337    pub fn operator(&mut self, operator: Pubkey) -> &mut Self {
338        self.instruction.operator = Some(operator);
339        self
340    }
341    /// Add an additional account to the instruction.
342    #[inline(always)]
343    pub fn add_remaining_account(
344        &mut self,
345        account: &'b solana_account_info::AccountInfo<'a>,
346        is_writable: bool,
347        is_signer: bool,
348    ) -> &mut Self {
349        self.instruction
350            .__remaining_accounts
351            .push((account, is_writable, is_signer));
352        self
353    }
354    /// Add additional accounts to the instruction.
355    ///
356    /// Each account is represented by a tuple of the `AccountInfo`, a `bool` indicating whether the account is writable or not,
357    /// and a `bool` indicating whether the account is a signer or not.
358    #[inline(always)]
359    pub fn add_remaining_accounts(
360        &mut self,
361        accounts: &[(&'b solana_account_info::AccountInfo<'a>, bool, bool)],
362    ) -> &mut Self {
363        self.instruction
364            .__remaining_accounts
365            .extend_from_slice(accounts);
366        self
367    }
368    #[inline(always)]
369    pub fn invoke(&self) -> solana_program_entrypoint::ProgramResult {
370        self.invoke_signed(&[])
371    }
372    #[allow(clippy::clone_on_copy)]
373    #[allow(clippy::vec_init_then_push)]
374    pub fn invoke_signed(
375        &self,
376        signers_seeds: &[&[&[u8]]],
377    ) -> solana_program_entrypoint::ProgramResult {
378        let args = UpdatePositionOperatorInstructionArgs {
379            operator: self
380                .instruction
381                .operator
382                .clone()
383                .expect("operator is not set"),
384        };
385        let instruction = UpdatePositionOperatorCpi {
386            __program: self.instruction.__program,
387
388            position: self.instruction.position.expect("position is not set"),
389
390            owner: self.instruction.owner.expect("owner is not set"),
391
392            event_authority: self
393                .instruction
394                .event_authority
395                .expect("event_authority is not set"),
396
397            program: self.instruction.program.expect("program is not set"),
398            __args: args,
399        };
400        instruction.invoke_signed_with_remaining_accounts(
401            signers_seeds,
402            &self.instruction.__remaining_accounts,
403        )
404    }
405}
406
407#[derive(Clone, Debug)]
408struct UpdatePositionOperatorCpiBuilderInstruction<'a, 'b> {
409    __program: &'b solana_account_info::AccountInfo<'a>,
410    position: Option<&'b solana_account_info::AccountInfo<'a>>,
411    owner: Option<&'b solana_account_info::AccountInfo<'a>>,
412    event_authority: Option<&'b solana_account_info::AccountInfo<'a>>,
413    program: Option<&'b solana_account_info::AccountInfo<'a>>,
414    operator: Option<Pubkey>,
415    /// Additional instruction accounts `(AccountInfo, is_writable, is_signer)`.
416    __remaining_accounts: Vec<(&'b solana_account_info::AccountInfo<'a>, bool, bool)>,
417}