Skip to main content

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