Skip to main content

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