mpl_candy_machine_core/instructions/
mint.rs

1use anchor_lang::prelude::*;
2use solana_program::sysvar;
3
4use super::mint_v2::{process_mint, MintAccounts};
5use crate::{constants::AUTHORITY_SEED, utils::*, AccountVersion, CandyError, CandyMachine};
6
7pub fn mint<'info>(ctx: Context<'_, '_, '_, 'info, Mint<'info>>) -> Result<()> {
8    msg!("(Deprecated as of 1.0.0) Use MintV2 instead");
9
10    if !matches!(ctx.accounts.candy_machine.version, AccountVersion::V1) {
11        return err!(CandyError::InvalidAccountVersion);
12    }
13
14    let accounts = MintAccounts {
15        spl_ata_program: None,
16        authority_pda: ctx.accounts.authority_pda.to_account_info(),
17        collection_delegate_record: ctx.accounts.collection_authority_record.to_account_info(),
18        collection_master_edition: ctx.accounts.collection_master_edition.to_account_info(),
19        collection_metadata: ctx.accounts.collection_metadata.to_account_info(),
20        collection_mint: ctx.accounts.collection_mint.to_account_info(),
21        collection_update_authority: ctx.accounts.collection_update_authority.to_account_info(),
22        nft_owner: ctx.accounts.nft_mint_authority.to_account_info(),
23        nft_master_edition: ctx.accounts.nft_master_edition.to_account_info(),
24        nft_metadata: ctx.accounts.nft_metadata.to_account_info(),
25        nft_mint: ctx.accounts.nft_mint.to_account_info(),
26        nft_mint_authority: ctx.accounts.nft_mint_authority.to_account_info(),
27        payer: ctx.accounts.payer.to_account_info(),
28        recent_slothashes: ctx.accounts.recent_slothashes.to_account_info(),
29        system_program: ctx.accounts.system_program.to_account_info(),
30        sysvar_instructions: None,
31        token: None,
32        token_metadata_program: ctx.accounts.token_metadata_program.to_account_info(),
33        spl_token_program: ctx.accounts.token_program.to_account_info(),
34        token_record: None,
35    };
36
37    process_mint(
38        &mut ctx.accounts.candy_machine,
39        accounts,
40        ctx.bumps["authority_pda"],
41    )
42}
43
44/// Mint a new NFT.
45#[derive(Accounts)]
46pub struct Mint<'info> {
47    /// Candy machine account.
48    #[account(mut, has_one = mint_authority)]
49    candy_machine: Box<Account<'info, CandyMachine>>,
50
51    /// Candy machine authority account. This is the account that holds a delegate
52    /// to verify an item into the collection.
53    ///
54    /// CHECK: account constraints checked in account trait
55    #[account(mut, seeds = [AUTHORITY_SEED.as_bytes(), candy_machine.key().as_ref()], bump)]
56    authority_pda: UncheckedAccount<'info>,
57
58    /// Candy machine mint authority (mint only allowed for the mint_authority).
59    mint_authority: Signer<'info>,
60
61    /// Payer for the transaction and account allocation (rent).
62    #[account(mut)]
63    payer: Signer<'info>,
64
65    /// Mint account of the NFT. The account will be initialized if necessary.
66    ///
67    /// CHECK: account checked in CPI
68    #[account(mut)]
69    nft_mint: UncheckedAccount<'info>,
70
71    /// Mint authority of the NFT. In most cases this will be the owner of the NFT.
72    nft_mint_authority: Signer<'info>,
73
74    /// Metadata account of the NFT. This account must be uninitialized.
75    ///
76    /// CHECK: account checked in CPI
77    #[account(mut)]
78    nft_metadata: UncheckedAccount<'info>,
79
80    /// Master edition account of the NFT. The account will be initialized if necessary.
81    ///
82    /// CHECK: account checked in CPI
83    #[account(mut)]
84    nft_master_edition: UncheckedAccount<'info>,
85
86    /// Collection authority record account is either the delegated authority record (legacy)
87    /// or a metadata delegate record for the `authority_pda`. The delegate is set when a new collection
88    /// is set to the candy machine.
89    ///
90    /// CHECK: account checked in CPI
91    collection_authority_record: UncheckedAccount<'info>,
92
93    /// Mint account of the collection NFT.
94    ///
95    /// CHECK: account checked in CPI
96    collection_mint: UncheckedAccount<'info>,
97
98    /// Metadata account of the collection NFT.
99    ///
100    /// CHECK: account checked in CPI
101    #[account(mut)]
102    collection_metadata: UncheckedAccount<'info>,
103
104    /// Master edition account of the collection NFT.
105    ///
106    /// CHECK: account checked in CPI
107    collection_master_edition: UncheckedAccount<'info>,
108
109    /// Update authority of the collection NFT.
110    ///
111    /// CHECK: account checked in CPI
112    collection_update_authority: UncheckedAccount<'info>,
113
114    /// Token Metadata program.
115    ///
116    /// CHECK: account checked in CPI
117    #[account(address = mpl_token_metadata::id())]
118    token_metadata_program: UncheckedAccount<'info>,
119
120    /// SPL Token program.
121    token_program: Program<'info, Token>,
122
123    /// System program.
124    system_program: Program<'info, System>,
125
126    /// SlotHashes sysvar cluster data.
127    ///
128    /// CHECK: account constraints checked in account trait
129    #[account(address = sysvar::slot_hashes::id())]
130    recent_slothashes: UncheckedAccount<'info>,
131}