Skip to main content

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