mpl_candy_machine_core/lib.rs
1#![allow(clippy::result_large_err)]
2
3use anchor_lang::prelude::*;
4
5pub use errors::CandyError;
6use instructions::*;
7pub use state::*;
8pub use utils::*;
9
10pub mod constants;
11pub mod errors;
12mod instructions;
13mod state;
14mod utils;
15
16declare_id!("CMv3YQQ7nbhFUjArAcGuRcDa6avoYN1a72HRZMvJ6WnU");
17
18#[program]
19pub mod candy_machine_core {
20 use super::*;
21
22 /// Add the configuration (name + uri) of each NFT to the account data.
23 ///
24 /// # Accounts
25 ///
26 /// 0. `[writable]` Candy Machine account
27 /// 1. `[signer]` Candy Machine authority
28 pub fn add_config_lines(
29 ctx: Context<AddConfigLines>,
30 index: u32,
31 config_lines: Vec<ConfigLine>,
32 ) -> Result<()> {
33 instructions::add_config_lines(ctx, index, config_lines)
34 }
35
36 /// Initialize the candy machine account with the specified data.
37 ///
38 /// # Accounts
39 ///
40 /// 0. `[writable]` Candy Machine account (must be pre-allocated but zero content)
41 /// 1. `[writable]` Authority PDA (seeds `["candy_machine", candy machine id]`)
42 /// 2. `[]` Candy Machine authority
43 /// 3. `[signer]` Payer
44 /// 4. `[]` Collection metadata
45 /// 5. `[]` Collection mint
46 /// 6. `[]` Collection master edition
47 /// 7. `[signer]` Collection update authority
48 /// 8. `[writable]` Collection authority record
49 /// 9. `[]` Token Metadata program
50 /// 10. `[]` System program
51 pub fn initialize(ctx: Context<Initialize>, data: CandyMachineData) -> Result<()> {
52 instructions::initialize(ctx, data)
53 }
54
55 /// Initialize the candy machine account with the specified data and token standard.
56 ///
57 /// # Accounts
58 ///
59 /// 0. `[writable]` Candy Machine account (must be pre-allocated but zero content)
60 /// 1. `[writable]` Authority PDA (seeds `["candy_machine", candy machine id]`)
61 /// 2. `[]` Candy Machine authority
62 /// 3. `[signer]` Payer
63 /// 4. `[]` Collection metadata
64 /// 5. `[]` Collection mint
65 /// 6. `[]` Collection master edition
66 /// 7. `[signer]` Collection update authority
67 /// 8. `[writable]` Collection metadata delegate record
68 /// 9. `[]` Token Metadata program
69 /// 10. `[]` System program
70 /// 11. `[]` Instructions sysvar account
71 /// 12. `[optional]` Token Authorization Rules program
72 /// 13. `[optional]` Token authorization rules account
73 pub fn initialize_v2(
74 ctx: Context<InitializeV2>,
75 data: CandyMachineData,
76 token_standard: u8,
77 ) -> Result<()> {
78 instructions::initialize_v2(ctx, data, token_standard)
79 }
80
81 /// Mint an NFT.
82 ///
83 /// Only the candy machine mint authority is allowed to mint.
84 ///
85 /// # Accounts
86 ///
87 /// 0. `[writable]` Candy Machine account (must be pre-allocated but zero content)
88 /// 1. `[writable]` Authority PDA (seeds `["candy_machine", candy machine id]`)
89 /// 2. `[signer]` Candy Machine mint authority
90 /// 3. `[signer]` Payer
91 /// 4. `[writable]` Mint account of the NFT
92 /// 5. `[signer]` Mint authority of the NFT
93 /// 6. `[writable]` Metadata account of the NFT
94 /// 7. `[writable]` Master edition account of the NFT
95 /// 8. `[optional]` Collection authority record
96 /// 9. `[]` Collection mint
97 /// 10. `[writable]` Collection metadata
98 /// 11. `[]` Collection master edition
99 /// 12. `[]` Collection update authority
100 /// 13. `[]` Token Metadata program
101 /// 14. `[]` SPL Token program
102 /// 15. `[]` System program
103 /// 16. `[]` SlotHashes sysvar cluster data.
104 pub fn mint<'info>(ctx: Context<'_, '_, '_, 'info, Mint<'info>>) -> Result<()> {
105 instructions::mint(ctx)
106 }
107
108 /// Mint an NFT.
109 ///
110 /// Only the candy machine mint authority is allowed to mint. This handler mints both
111 /// NFTs and Programmable NFTs.
112 ///
113 /// # Accounts
114 ///
115 /// 0. `[writable]` Candy Machine account (must be pre-allocated but zero content)
116 /// 1. `[writable]` Authority PDA (seeds `["candy_machine", candy machine id]`)
117 /// 2. `[signer]` Candy Machine mint authority
118 /// 3. `[signer]` Payer
119 /// 4. `[writable]` Mint account of the NFT
120 /// 5. `[]` Mint authority of the NFT
121 /// 6. `[writable]` Metadata account of the NFT
122 /// 7. `[writable]` Master edition account of the NFT
123 /// 8. `[optional, writable]` Destination token account
124 /// 9. `[optional, writable]` Token record
125 /// 10. `[]` Collection delegate or authority record
126 /// 11. `[]` Collection mint
127 /// 12. `[writable]` Collection metadata
128 /// 13. `[]` Collection master edition
129 /// 14. `[]` Collection update authority
130 /// 15. `[]` Token Metadata program
131 /// 16. `[]` SPL Token program
132 /// 17. `[optional]` SPL Associated Token program
133 /// 18. `[]` System program
134 /// 19. `[optional]` Instructions sysvar account
135 /// 20. `[]` SlotHashes sysvar cluster data.
136 pub fn mint_v2<'info>(ctx: Context<'_, '_, '_, 'info, MintV2<'info>>) -> Result<()> {
137 instructions::mint_v2(ctx)
138 }
139
140 /// Set a new authority of the candy machine.
141 ///
142 /// # Accounts
143 ///
144 /// 0. `[writable]` Candy Machine account
145 /// 1. `[signer]` Candy Machine authority
146 pub fn set_authority(ctx: Context<SetAuthority>, new_authority: Pubkey) -> Result<()> {
147 instructions::set_authority(ctx, new_authority)
148 }
149
150 /// Set the collection mint for the candy machine.
151 ///
152 /// # Accounts
153 ///
154 /// 0. `[writable]` Candy Machine account (must be pre-allocated but zero content)
155 /// 1. `[signer]` Candy Machine authority
156 /// 2. `[]` Authority PDA (seeds `["candy_machine", candy machine id]`)
157 /// 3. `[signer]` Payer
158 /// 4. `[]` Collection mint
159 /// 5. `[]` Collection metadata
160 /// 6. `[writable]` Collection authority record
161 /// 7. `[signer]` New collection update authority
162 /// 8. `[]` Collection metadata
163 /// 9. `[]` Collection mint
164 /// 10. `[]` New collection master edition
165 /// 11. `[]` New collection authority record
166 /// 12. `[]` Token Metadata program
167 /// 13. `[]` System program
168 pub fn set_collection(ctx: Context<SetCollection>) -> Result<()> {
169 instructions::set_collection(ctx)
170 }
171
172 /// Set the collection mint for the candy machine.
173 ///
174 /// # Accounts
175 ///
176 /// 0. `[writable]` Candy Machine account (must be pre-allocated but zero content)
177 /// 1. `[signer]` Candy Machine authority
178 /// 2. `[]` Authority PDA (seeds `["candy_machine", candy machine id]`)
179 /// 3. `[signer]` Payer
180 /// 4. `[]` Collection update authority
181 /// 5. `[]` Collection mint
182 /// 6. `[]` Collection metadata
183 /// 7. `[optional, writable]` Metadata delegate record
184 /// 8. `[optional, writable]` Collection authority record
185 /// 9. `[signer]` New collection update authority
186 /// 10. `[]` New collection mint
187 /// 11. `[]` New collection metadata
188 /// 12. `[]` New collection master edition
189 /// 13. `[writable]` New collection metadata delegate record
190 /// 14. `[]` Token Metadata program
191 /// 15. `[]` System program
192 /// 16. `[]` Instructions sysvar account
193 /// 17. `[optional]` Token Authorization Rules program
194 /// 18. `[optional]` Token authorization rules account
195 pub fn set_collection_v2(ctx: Context<SetCollectionV2>) -> Result<()> {
196 instructions::set_collection_v2(ctx)
197 }
198
199 /// Set a new mint authority of the candy machine.
200 ///
201 /// # Accounts
202 ///
203 /// 0. `[writable]` Candy Machine account
204 /// 1. `[signer]` Candy Machine authority
205 /// 1. `[signer]` New candy machine authority
206 pub fn set_mint_authority(ctx: Context<SetMintAuthority>) -> Result<()> {
207 instructions::set_mint_authority(ctx)
208 }
209
210 /// Set the token standard of the minted NFTs.
211 ///
212 /// # Accounts
213 ///
214 /// 0. `[writable]` Candy Machine account (must be pre-allocated but zero content)
215 /// 1. `[signer]` Candy Machine authority
216 /// 2. `[]` Authority PDA (seeds `["candy_machine", candy machine id]`)
217 /// 3. `[signer]` Payer
218 /// 4. `[optional, writable]` Metadata delegate record
219 /// 5. `[]` Collection mint
220 /// 6. `[]` Collection metadata
221 /// 7. `[optional, writable]` Collection authority record
222 /// 8. `[]` Collection update authority
223 /// 9. `[]` Token Metadata program
224 /// 10. `[]` System program
225 /// 11. `[]` Instructions sysvar account
226 /// 12. `[optional]` Token Authorization Rules program
227 /// 13. `[optional]` Token authorization rules account
228 pub fn set_token_standard(ctx: Context<SetTokenStandard>, token_standard: u8) -> Result<()> {
229 instructions::set_token_standard(ctx, token_standard)
230 }
231
232 /// Update the candy machine configuration.
233 ///
234 /// # Accounts
235 ///
236 /// 0. `[writable]` Candy Machine account
237 /// 1. `[signer]` Candy Machine authority
238 pub fn update(ctx: Context<Update>, data: CandyMachineData) -> Result<()> {
239 instructions::update(ctx, data)
240 }
241
242 /// Withdraw the rent lamports and send them to the authority address.
243 ///
244 /// # Accounts
245 ///
246 /// 0. `[writable]` Candy Machine account
247 /// 1. `[signer]` Candy Machine authority
248 pub fn withdraw(ctx: Context<Withdraw>) -> Result<()> {
249 instructions::withdraw(ctx)
250 }
251}