Skip to main content

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