Skip to content

Commit ab9093b

Browse files
authored
Fix: prevent WL token burn before punish bot calls (metaplex-foundation#425)
* wl token burn fix * bump version
1 parent 3a269a5 commit ab9093b

File tree

2 files changed

+52
-53
lines changed

2 files changed

+52
-53
lines changed

candy-machine/program/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[workspace]
22
[package]
33
name = "mpl-candy-machine"
4-
version = "3.2.1"
4+
version = "3.2.2"
55
description = "NFT Candy Machine v2: programmatic and trustless NFT drops."
66
authors = ["Jordan Prince", "Metaplex Developers <dev@metaplex.com>"]
77
repository = "https://github.com/metaplex-foundation/metaplex-program-library"

candy-machine/program/src/lib.rs

Lines changed: 51 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,36 @@
11
pub mod utils;
22

3-
use solana_program::sysvar::{instructions::get_instruction_relative, SysvarId};
4-
use {
5-
crate::utils::{
6-
assert_initialized, assert_is_ata, assert_keys_equal, assert_owned_by,
7-
assert_valid_go_live, punish_bots, spl_token_burn, spl_token_transfer, TokenBurnParams,
8-
TokenTransferParams,
3+
use crate::utils::{
4+
assert_initialized, assert_is_ata, assert_keys_equal, assert_owned_by, assert_valid_go_live,
5+
punish_bots, spl_token_burn, spl_token_transfer, TokenBurnParams, TokenTransferParams,
6+
};
7+
use anchor_lang::{
8+
prelude::*,
9+
solana_program::{
10+
program::{invoke, invoke_signed},
11+
serialize_utils::{read_pubkey, read_u16},
12+
system_instruction, sysvar,
913
},
10-
anchor_lang::{
11-
prelude::*,
12-
solana_program::{
13-
program::{invoke, invoke_signed},
14-
serialize_utils::{read_pubkey, read_u16},
15-
system_instruction, sysvar,
16-
},
17-
AnchorDeserialize, AnchorSerialize, Discriminator, Key,
14+
AnchorDeserialize, AnchorSerialize, Discriminator, Key,
15+
};
16+
use anchor_spl::token::Token;
17+
use arrayref::array_ref;
18+
use mpl_token_metadata::{
19+
assertions::collection::assert_master_edition,
20+
error::MetadataError,
21+
instruction::{
22+
approve_collection_authority, create_master_edition_v3, create_metadata_accounts_v2,
23+
revoke_collection_authority, set_and_verify_collection, update_metadata_accounts_v2,
1824
},
19-
anchor_spl::token::Token,
20-
arrayref::array_ref,
21-
mpl_token_metadata::{
22-
assertions::collection::assert_master_edition,
23-
error::MetadataError,
24-
instruction::{
25-
approve_collection_authority, create_master_edition_v3, create_metadata_accounts_v2,
26-
revoke_collection_authority, set_and_verify_collection, update_metadata_accounts_v2,
27-
},
28-
state::{
29-
Metadata, MAX_CREATOR_LEN, MAX_CREATOR_LIMIT, MAX_NAME_LENGTH, MAX_SYMBOL_LENGTH,
30-
MAX_URI_LENGTH,
31-
},
32-
utils::{assert_derivation, create_or_allocate_account_raw},
25+
state::{
26+
Metadata, MAX_CREATOR_LEN, MAX_CREATOR_LIMIT, MAX_NAME_LENGTH, MAX_SYMBOL_LENGTH,
27+
MAX_URI_LENGTH,
3328
},
34-
spl_token::state::Mint,
35-
std::{cell::RefMut, ops::Deref, str::FromStr},
29+
utils::{assert_derivation, create_or_allocate_account_raw},
3630
};
31+
use solana_program::sysvar::{instructions::get_instruction_relative, SysvarId};
32+
use spl_token::state::Mint;
33+
use std::{cell::RefMut, ops::Deref, str::FromStr};
3734
anchor_lang::declare_id!("cndy3Z4yapfJBmL3ShUp5exZKqR3z33thTzeNMm2gRZ");
3835
const EXPIRE_OFFSET: i64 = 10 * 60;
3936
const PREFIX: &str = "candy_machine";
@@ -224,27 +221,6 @@ pub mod candy_machine {
224221
match assert_is_ata(whitelist_token_account, &payer.key(), &ws.mint) {
225222
Ok(wta) => {
226223
if wta.amount > 0 {
227-
if ws.mode == WhitelistMintMode::BurnEveryTime {
228-
let whitelist_token_mint =
229-
&ctx.remaining_accounts[remaining_accounts_counter];
230-
remaining_accounts_counter += 1;
231-
232-
let whitelist_burn_authority =
233-
&ctx.remaining_accounts[remaining_accounts_counter];
234-
remaining_accounts_counter += 1;
235-
236-
assert_keys_equal(whitelist_token_mint.key(), ws.mint)?;
237-
238-
spl_token_burn(TokenBurnParams {
239-
mint: whitelist_token_mint.clone(),
240-
source: whitelist_token_account.clone(),
241-
amount: 1,
242-
authority: whitelist_burn_authority.clone(),
243-
authority_signer_seeds: None,
244-
token_program: token_program.to_account_info(),
245-
})?;
246-
}
247-
248224
match candy_machine.data.go_live_date {
249225
None => {
250226
if ctx.accounts.payer.key() != candy_machine.authority
@@ -277,6 +253,27 @@ pub mod candy_machine {
277253
}
278254
}
279255

256+
if ws.mode == WhitelistMintMode::BurnEveryTime {
257+
let whitelist_token_mint =
258+
&ctx.remaining_accounts[remaining_accounts_counter];
259+
remaining_accounts_counter += 1;
260+
261+
let whitelist_burn_authority =
262+
&ctx.remaining_accounts[remaining_accounts_counter];
263+
remaining_accounts_counter += 1;
264+
265+
assert_keys_equal(whitelist_token_mint.key(), ws.mint)?;
266+
267+
spl_token_burn(TokenBurnParams {
268+
mint: whitelist_token_mint.clone(),
269+
source: whitelist_token_account.clone(),
270+
amount: 1,
271+
authority: whitelist_burn_authority.clone(),
272+
authority_signer_seeds: None,
273+
token_program: token_program.to_account_info(),
274+
})?;
275+
}
276+
280277
if let Some(dp) = ws.discount_price {
281278
price = dp;
282279
}
@@ -566,7 +563,9 @@ pub mod candy_machine {
566563
return Ok(());
567564
}
568565
/// Check if the metadata acount has data if not bot fee
569-
if ctx.accounts.metadata.owner != &mpl_token_metadata::id() || ctx.accounts.token_metadata_program.data_len() == 0 {
566+
if ctx.accounts.metadata.owner != &mpl_token_metadata::id()
567+
|| ctx.accounts.token_metadata_program.data_len() == 0
568+
{
570569
return Ok(());
571570
}
572571

0 commit comments

Comments
 (0)