sigil_client/generated/instructions/
create_mint.rs

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