@@ -10,20 +10,14 @@ use anchor_spl::metadata::{
10
10
MetadataAccount ,
11
11
Metadata ,
12
12
CreateMetadataAccountsV3 ,
13
- SetAndVerifySizedCollectionItem ,
13
+ CreateMasterEditionV3 ,
14
+ SignMetadata ,
15
+ create_master_edition_v3,
14
16
create_metadata_accounts_v3,
15
- set_and_verify_sized_collection_item ,
17
+ sign_metadata ,
16
18
mpl_token_metadata:: {
17
- instructions:: {
18
- CreateMasterEditionV3Cpi ,
19
- CreateMasterEditionV3CpiAccounts ,
20
- CreateMasterEditionV3InstructionArgs ,
21
- CreateMetadataAccountV3Cpi ,
22
- CreateMetadataAccountV3CpiAccounts ,
23
- CreateMetadataAccountV3InstructionArgs ,
24
- } ,
25
19
types:: {
26
- Collection ,
20
+ CollectionDetails ,
27
21
Creator ,
28
22
DataV2 ,
29
23
} ,
@@ -46,17 +40,98 @@ pub mod token_lottery {
46
40
47
41
pub fn initialize ( ctx : Context < Initialize > , start : u64 , end : u64 , price : u64 ) -> Result < ( ) > {
48
42
ctx. accounts . token_lottery . bump = ctx. bumps . token_lottery ;
49
- ctx. accounts . token_lottery . mint = ctx. accounts . mint . key ( ) ;
50
43
ctx. accounts . token_lottery . lottery_start = start;
51
44
ctx. accounts . token_lottery . lottery_end = end;
52
45
ctx. accounts . token_lottery . price = price;
53
- ctx. accounts . token_lottery . authority = ctx. accounts . signer . key ( ) ;
46
+ ctx. accounts . token_lottery . authority = ctx. accounts . payer . key ( ) ;
54
47
ctx. accounts . token_lottery . randomness_account = Pubkey :: default ( ) ;
55
48
56
- // Is this needed Jacob?
49
+ let lottery_account_key = & ctx. accounts . token_lottery . key ( ) ;
50
+
57
51
ctx. accounts . token_lottery . ticket_num = 0 ;
58
52
59
53
// Create Collection Mint
54
+ let signer_seeds: & [ & [ & [ u8 ] ] ] = & [ & [
55
+ lottery_account_key. as_ref ( ) ,
56
+ & [ ctx. bumps . collection_mint ] ,
57
+ ] ] ;
58
+
59
+ msg ! ( "Creating mint accounts" ) ;
60
+ mint_to (
61
+ CpiContext :: new_with_signer (
62
+ ctx. accounts . token_program . to_account_info ( ) ,
63
+ MintTo {
64
+ mint : ctx. accounts . collection_mint . to_account_info ( ) ,
65
+ to : ctx. accounts . collection_token_account . to_account_info ( ) ,
66
+ authority : ctx. accounts . collection_mint . to_account_info ( ) ,
67
+ } ,
68
+ signer_seeds,
69
+ ) ,
70
+ 1 ,
71
+ ) ?;
72
+
73
+ msg ! ( "Creating metadata accounts" ) ;
74
+ create_metadata_accounts_v3 (
75
+ CpiContext :: new_with_signer (
76
+ ctx. accounts . token_metadata_program . to_account_info ( ) ,
77
+ CreateMetadataAccountsV3 {
78
+ metadata : ctx. accounts . metadata . to_account_info ( ) ,
79
+ mint : ctx. accounts . collection_mint . to_account_info ( ) ,
80
+ mint_authority : ctx. accounts . collection_mint . to_account_info ( ) , // use pda mint address as mint authority
81
+ update_authority : ctx. accounts . collection_mint . to_account_info ( ) , // use pda mint as update authority
82
+ payer : ctx. accounts . payer . to_account_info ( ) ,
83
+ system_program : ctx. accounts . system_program . to_account_info ( ) ,
84
+ rent : ctx. accounts . rent . to_account_info ( ) ,
85
+ } ,
86
+ & signer_seeds,
87
+ ) ,
88
+ DataV2 {
89
+ name : NAME . to_string ( ) ,
90
+ symbol : SYMBOL . to_string ( ) ,
91
+ uri : URI . to_string ( ) ,
92
+ seller_fee_basis_points : 0 ,
93
+ creators : Some ( vec ! [ Creator {
94
+ address: ctx. accounts. payer. key( ) ,
95
+ verified: false ,
96
+ share: 100 ,
97
+ } ] ) ,
98
+ collection : None ,
99
+ uses : None ,
100
+ } ,
101
+ true ,
102
+ true ,
103
+ Some ( CollectionDetails :: V1 { size : 0 } ) , // set as collection nft
104
+ ) ?;
105
+
106
+ msg ! ( "Creating Master edition accounts" ) ;
107
+ create_master_edition_v3 (
108
+ CpiContext :: new_with_signer (
109
+ ctx. accounts . token_metadata_program . to_account_info ( ) ,
110
+ CreateMasterEditionV3 {
111
+ payer : ctx. accounts . payer . to_account_info ( ) ,
112
+ mint : ctx. accounts . collection_mint . to_account_info ( ) ,
113
+ edition : ctx. accounts . master_edition . to_account_info ( ) ,
114
+ mint_authority : ctx. accounts . collection_mint . to_account_info ( ) ,
115
+ update_authority : ctx. accounts . collection_mint . to_account_info ( ) ,
116
+ metadata : ctx. accounts . metadata . to_account_info ( ) ,
117
+ token_program : ctx. accounts . token_program . to_account_info ( ) ,
118
+ system_program : ctx. accounts . system_program . to_account_info ( ) ,
119
+ rent : ctx. accounts . rent . to_account_info ( ) ,
120
+ } ,
121
+ & signer_seeds,
122
+ ) ,
123
+ Some ( 0 ) ,
124
+ ) ?;
125
+
126
+ msg ! ( "verifying collection" ) ;
127
+ sign_metadata ( CpiContext :: new (
128
+ ctx. accounts . token_metadata_program . to_account_info ( ) ,
129
+ SignMetadata {
130
+ creator : ctx. accounts . collection_mint . to_account_info ( ) ,
131
+ metadata : ctx. accounts . metadata . to_account_info ( ) ,
132
+ } ,
133
+ ) ) ?;
134
+
60
135
61
136
Ok ( ( ) )
62
137
}
@@ -69,13 +144,6 @@ pub mod token_lottery {
69
144
return Err ( ErrorCode :: LotteryNotOpen . into ( ) ) ;
70
145
}
71
146
72
- let metadata = & ctx. accounts . metadata . to_account_info ( ) ;
73
- let master_edition = & ctx. accounts . master_edition . to_account_info ( ) ;
74
- let system_program = & ctx. accounts . system_program . to_account_info ( ) ;
75
- let spl_token_program = & ctx. accounts . token_program . to_account_info ( ) ;
76
- let spl_metadata_program = & ctx. accounts . token_metadata_program . to_account_info ( ) ;
77
-
78
- // Take Money
79
147
system_program:: transfer (
80
148
CpiContext :: new (
81
149
ctx. accounts . system_program . to_account_info ( ) ,
@@ -133,30 +201,10 @@ pub mod token_lottery {
133
201
None ,
134
202
) ?;
135
203
136
- set_and_verify_sized_collection_item (
137
- CpiContext :: new_with_signer (
138
- ctx. accounts . token_metadata_program . to_account_info ( ) ,
139
- SetAndVerifySizedCollectionItem {
140
- metadata : ctx. accounts . metadata . to_account_info ( ) ,
141
- collection_authority : ctx. accounts . collection_mint . to_account_info ( ) ,
142
- payer : ctx. accounts . payer . to_account_info ( ) ,
143
- update_authority : ctx. accounts . collection_mint . to_account_info ( ) ,
144
- collection_mint : ctx. accounts . collection_mint . to_account_info ( ) ,
145
- collection_metadata : ctx. accounts . collection_metadata . to_account_info ( ) ,
146
- collection_master_edition : ctx
147
- . accounts
148
- . collection_master_edition
149
- . to_account_info ( ) ,
150
- } ,
151
- & signer_seeds,
152
- ) ,
153
- None ,
154
- ) ?;
155
-
156
204
Ok ( ( ) )
157
205
}
158
206
159
- pub fn commit_a_winner ( ctx : Context < CommitWinner > , randomness_account : Pubkey ) -> Result < ( ) > {
207
+ pub fn commit_a_winner ( ctx : Context < CommitWinner > ) -> Result < ( ) > {
160
208
let clock = Clock :: get ( ) ?;
161
209
let token_lottery = & mut ctx. accounts . token_lottery ;
162
210
@@ -287,47 +335,51 @@ pub struct BuyTicket<'info> {
287
335
#[ derive( Accounts ) ]
288
336
pub struct Initialize < ' info > {
289
337
#[ account( mut ) ]
290
- pub signer : Signer < ' info > ,
338
+ pub payer : Signer < ' info > ,
291
339
292
340
#[ account(
293
341
init,
294
- payer = signer ,
342
+ payer = payer ,
295
343
space = 8 + TokenLottery :: INIT_SPACE ,
296
344
// Challenge: Make this be able to run more than 1 lottery at a time
297
345
seeds = [ b"token_lottery" . as_ref( ) ] ,
298
346
bump
299
347
) ]
300
- pub token_lottery : Account < ' info , TokenLottery > ,
301
-
302
- pub mint : InterfaceAccount < ' info , Mint > ,
348
+ pub token_lottery : Box < Account < ' info , TokenLottery > > ,
303
349
304
350
#[ account(
305
351
init,
306
- payer = signer ,
352
+ payer = payer ,
307
353
mint:: decimals = 0 ,
308
354
mint:: authority = collection_mint,
309
355
seeds = [ token_lottery. key( ) . as_ref( ) ] ,
310
356
bump,
311
357
) ]
312
- pub collection_mint : InterfaceAccount < ' info , Mint > ,
358
+ pub collection_mint : Box < InterfaceAccount < ' info , Mint > > ,
313
359
360
+ /// CHECK: This account will be initialized by the metaplex program
314
361
#[ account( mut ) ]
315
- pub metadata : Account < ' info , MetadataAccount > ,
362
+ pub metadata : UncheckedAccount < ' info > ,
316
363
364
+ /// CHECK: This account will be initialized by the metaplex program
317
365
#[ account( mut ) ]
318
- pub master_edition : Account < ' info , MasterEditionAccount > ,
366
+ pub master_edition : UncheckedAccount < ' info > ,
319
367
320
368
#[ account(
321
369
init_if_needed,
322
- payer = signer,
323
- associated_token:: mint = collection_mint,
324
- associated_token:: authority = collection_token_account
370
+ payer = payer,
371
+ seeds = [ b"collection_token_account" . as_ref( ) ] ,
372
+ bump,
373
+ token:: mint = collection_mint,
374
+ token:: authority = collection_token_account
325
375
) ]
326
- pub collection_token_account : InterfaceAccount < ' info , TokenAccount > ,
376
+ pub collection_token_account : Box < InterfaceAccount < ' info , TokenAccount > > ,
327
377
328
378
pub token_program : Interface < ' info , TokenInterface > ,
329
379
pub associated_token_program : Program < ' info , AssociatedToken > ,
330
380
pub system_program : Program < ' info , System > ,
381
+ pub token_metadata_program : Program < ' info , Metadata > ,
382
+ pub rent : Sysvar < ' info , Rent > ,
331
383
}
332
384
333
385
#[ account]
@@ -339,7 +391,6 @@ pub struct TokenLottery {
339
391
pub lottery_end : u64 ,
340
392
// Is it good practice to store SOL on an account used for something else?
341
393
pub lottery_pot_amount : u64 ,
342
- pub mint : Pubkey ,
343
394
pub ticket_num : u32 ,
344
395
pub price : u64 ,
345
396
pub randomness_account : Pubkey ,
0 commit comments