Skip to main content

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