1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
#![allow(clippy::result_large_err)]

use anchor_lang::prelude::*;

pub use errors::CandyError;
use instructions::*;
pub use state::*;
pub use utils::*;

pub mod constants;
pub mod errors;
mod instructions;
mod state;
mod utils;

declare_id!("CndyV3LdqHUfDLmE5naZjVN8rBZz4tqhdefbAnjHG3JR");

#[program]
pub mod candy_machine_core {
    use super::*;

    /// Add the configuration (name + uri) of each NFT to the account data.
    ///
    /// # Accounts
    ///
    ///   0. `[writable]` Candy Machine account
    ///   1. `[signer]` Candy Machine authority
    pub fn add_config_lines(
        ctx: Context<AddConfigLines>,
        index: u32,
        config_lines: Vec<ConfigLine>,
    ) -> Result<()> {
        instructions::add_config_lines(ctx, index, config_lines)
    }

    /// Initialize the candy machine account with the specified data.
    ///
    /// # Accounts
    ///
    ///   0. `[writable]` Candy Machine account (must be pre-allocated but zero content)
    ///   1. `[writable]` Authority PDA (seeds `["candy_machine", candy machine id]`)
    ///   2. `[]` Candy Machine authority
    ///   3. `[signer]` Payer
    ///   4. `[]` Collection metadata
    ///   5. `[]` Collection mint
    ///   6. `[]` Collection master edition
    ///   7. `[signer]` Collection update authority
    ///   8. `[writable]` Collection authority record
    ///   9. `[]` Token Metadata program
    ///   10. `[]` System program
    pub fn initialize(ctx: Context<Initialize>, data: CandyMachineData) -> Result<()> {
        instructions::initialize(ctx, data)
    }

    /// Initialize the candy machine account with the specified data and token standard.
    ///
    /// # Accounts
    ///
    ///   0. `[writable]` Candy Machine account (must be pre-allocated but zero content)
    ///   1. `[writable]` Authority PDA (seeds `["candy_machine", candy machine id]`)
    ///   2. `[]` Candy Machine authority
    ///   3. `[signer]` Payer
    ///   4. `[]` Collection metadata
    ///   5. `[]` Collection mint
    ///   6. `[]` Collection master edition
    ///   7. `[signer]` Collection update authority
    ///   8. `[writable]` Collection metadata delegate record
    ///   9. `[]` Token Metadata program
    ///   10. `[]` System program
    ///   11. `[]` Instructions sysvar account
    ///   12. `[optional]` Token Authorization Rules program
    ///   13. `[optional]` Token authorization rules account
    pub fn initialize_v2(
        ctx: Context<InitializeV2>,
        data: CandyMachineData,
        token_standard: u8,
    ) -> Result<()> {
        instructions::initialize_v2(ctx, data, token_standard)
    }

    /// Mint an NFT.
    ///
    /// Only the candy machine mint authority is allowed to mint.
    ///
    /// # Accounts
    ///
    ///   0. `[writable]` Candy Machine account (must be pre-allocated but zero content)
    ///   1. `[writable]` Authority PDA (seeds `["candy_machine", candy machine id]`)
    ///   2. `[signer]` Candy Machine mint authority
    ///   3. `[signer]` Payer
    ///   4. `[writable]` Mint account of the NFT
    ///   5. `[signer]` Mint authority of the NFT
    ///   6. `[writable]` Metadata account of the NFT
    ///   7. `[writable]` Master edition account of the NFT
    ///   8. `[optional]` Collection authority record
    ///   9. `[]` Collection mint
    ///   10. `[writable]` Collection metadata
    ///   11. `[]` Collection master edition
    ///   12. `[]` Collection update authority
    ///   13. `[]` Token Metadata program
    ///   14. `[]` SPL Token program
    ///   15. `[]` System program
    ///   16. `[]` SlotHashes sysvar cluster data.
    pub fn mint<'info>(ctx: Context<'_, '_, '_, 'info, Mint<'info>>) -> Result<()> {
        instructions::mint(ctx)
    }

    /// Mint an NFT.
    ///
    /// Only the candy machine mint authority is allowed to mint. This handler mints both
    /// NFTs and Programmable NFTs.
    ///
    /// # Accounts
    ///
    ///   0. `[writable]` Candy Machine account (must be pre-allocated but zero content)
    ///   1. `[writable]` Authority PDA (seeds `["candy_machine", candy machine id]`)
    ///   2. `[signer]` Candy Machine mint authority
    ///   3. `[signer]` Payer
    ///   4. `[writable]` Mint account of the NFT
    ///   5. `[]` Mint authority of the NFT
    ///   6. `[writable]` Metadata account of the NFT
    ///   7. `[writable]` Master edition account of the NFT
    ///   8. `[optional, writable]` Destination token account
    ///   9. `[optional, writable]` Token record
    ///   10. `[]` Collection delegate or authority record
    ///   11. `[]` Collection mint
    ///   12. `[writable]` Collection metadata
    ///   13. `[]` Collection master edition
    ///   14. `[]` Collection update authority
    ///   15. `[]` Token Metadata program
    ///   16. `[]` SPL Token program
    ///   17. `[optional]` SPL Associated Token program
    ///   18. `[]` System program
    ///   19. `[optional]` Instructions sysvar account
    ///   20. `[]` SlotHashes sysvar cluster data.
    pub fn mint_v2<'info>(ctx: Context<'_, '_, '_, 'info, MintV2<'info>>) -> Result<()> {
        instructions::mint_v2(ctx)
    }

    /// Set a new authority of the candy machine.
    ///
    /// # Accounts
    ///
    ///   0. `[writable]` Candy Machine account
    ///   1. `[signer]` Candy Machine authority
    pub fn set_authority(ctx: Context<SetAuthority>, new_authority: Pubkey) -> Result<()> {
        instructions::set_authority(ctx, new_authority)
    }

    /// Set the collection mint for the candy machine.
    ///
    /// # Accounts
    ///
    ///   0. `[writable]` Candy Machine account (must be pre-allocated but zero content)
    ///   1. `[signer]` Candy Machine authority
    ///   2. `[]` Authority PDA (seeds `["candy_machine", candy machine id]`)
    ///   3. `[signer]` Payer
    ///   4. `[]` Collection mint
    ///   5. `[]` Collection metadata
    ///   6. `[writable]` Collection authority record
    ///   7. `[signer]` New collection update authority
    ///   8. `[]` Collection metadata
    ///   9. `[]` Collection mint
    ///   10. `[]` New collection master edition
    ///   11. `[]` New collection authority record
    ///   12. `[]` Token Metadata program
    ///   13. `[]` System program
    pub fn set_collection(ctx: Context<SetCollection>) -> Result<()> {
        instructions::set_collection(ctx)
    }

    /// Set the collection mint for the candy machine.
    ///
    /// # Accounts
    ///
    ///   0. `[writable]` Candy Machine account (must be pre-allocated but zero content)
    ///   1. `[signer]` Candy Machine authority
    ///   2. `[]` Authority PDA (seeds `["candy_machine", candy machine id]`)
    ///   3. `[signer]` Payer
    ///   4. `[]` Collection update authority
    ///   5. `[]` Collection mint
    ///   6. `[]` Collection metadata
    ///   7. `[optional, writable]` Metadata delegate record
    ///   8. `[optional, writable]` Collection authority record
    ///   9. `[signer]` New collection update authority
    ///   10. `[]` New collection mint
    ///   11. `[]` New collection metadata
    ///   12. `[]` New collection master edition
    ///   13. `[writable]` New collection metadata delegate record
    ///   14. `[]` Token Metadata program
    ///   15. `[]` System program
    ///   16. `[]` Instructions sysvar account
    ///   17. `[optional]` Token Authorization Rules program
    ///   18. `[optional]` Token authorization rules account
    pub fn set_collection_v2(ctx: Context<SetCollectionV2>) -> Result<()> {
        instructions::set_collection_v2(ctx)
    }

    /// Set a new mint authority of the candy machine.
    ///
    /// # Accounts
    ///
    ///   0. `[writable]` Candy Machine account
    ///   1. `[signer]` Candy Machine authority
    ///   1. `[signer]` New candy machine authority
    pub fn set_mint_authority(ctx: Context<SetMintAuthority>) -> Result<()> {
        instructions::set_mint_authority(ctx)
    }

    /// Set the token standard of the minted NFTs.
    ///
    /// # Accounts
    ///
    ///   0. `[writable]` Candy Machine account (must be pre-allocated but zero content)
    ///   1. `[signer]` Candy Machine authority
    ///   2. `[]` Authority PDA (seeds `["candy_machine", candy machine id]`)
    ///   3. `[signer]` Payer
    ///   4. `[optional, writable]` Metadata delegate record
    ///   5. `[]` Collection mint
    ///   6. `[]` Collection metadata
    ///   7. `[optional, writable]` Collection authority record
    ///   8. `[]` Collection update authority
    ///   9. `[]` Token Metadata program
    ///   10. `[]` System program
    ///   11. `[]` Instructions sysvar account
    ///   12. `[optional]` Token Authorization Rules program
    ///   13. `[optional]` Token authorization rules account
    pub fn set_token_standard(ctx: Context<SetTokenStandard>, token_standard: u8) -> Result<()> {
        instructions::set_token_standard(ctx, token_standard)
    }

    /// Update the candy machine configuration.
    ///
    /// # Accounts
    ///
    ///   0. `[writable]` Candy Machine account
    ///   1. `[signer]` Candy Machine authority
    pub fn update(ctx: Context<Update>, data: CandyMachineData) -> Result<()> {
        instructions::update(ctx, data)
    }

    /// Withdraw the rent lamports and send them to the authority address.
    ///
    /// # Accounts
    ///
    ///   0. `[writable]` Candy Machine account
    ///   1. `[signer]` Candy Machine authority
    pub fn withdraw(ctx: Context<Withdraw>) -> Result<()> {
        instructions::withdraw(ctx)
    }
}