Skip to content

Commit

Permalink
Set a limit to the max number of mintable tokens for OEs
Browse files Browse the repository at this point in the history
  • Loading branch information
MightOfOaks committed Aug 9, 2024
1 parent c4c36c7 commit 32891b6
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 18 deletions.
17 changes: 10 additions & 7 deletions contracts/minters/open-edition-minter-merkle-wl/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,8 @@ pub fn instantiate(
// Max token count (optional)
if let Some(max_num_tokens) = msg.init_msg.num_tokens {
MINTABLE_NUM_TOKENS.save(deps.storage, &max_num_tokens)?;
} else {
MINTABLE_NUM_TOKENS.save(deps.storage, &factory_params.extension.max_token_limit)?;
}

// Submessage to instantiate sg721 contract
Expand Down Expand Up @@ -223,13 +225,6 @@ pub fn execute_purge(
info: MessageInfo,
) -> Result<Response, ContractError> {
nonpayable(&info)?;
// check if sold out (optional)
let mintable_num_tokens = MINTABLE_NUM_TOKENS.may_load(deps.storage)?;
if let Some(mintable_nb_tokens) = mintable_num_tokens {
if mintable_nb_tokens != 0 {
return Err(ContractError::NotSoldOut {});
}
}

// Check if mint has ended (optional)
let end_time = CONFIG.load(deps.storage)?.extension.end_time;
Expand All @@ -239,6 +234,14 @@ pub fn execute_purge(
}
}

// check if sold out before end time (optional)
let mintable_num_tokens = MINTABLE_NUM_TOKENS.may_load(deps.storage)?;
if let Some(mintable_nb_tokens) = mintable_num_tokens {
if mintable_nb_tokens != 0 && end_time.is_none() {
return Err(ContractError::NotSoldOut {});
}
}

let keys = MINTER_ADDRS
.keys(deps.storage, None, None, Order::Ascending)
.collect::<Vec<_>>();
Expand Down
17 changes: 10 additions & 7 deletions contracts/minters/open-edition-minter/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,8 @@ pub fn instantiate(
// Max token count (optional)
if let Some(max_num_tokens) = msg.init_msg.num_tokens {
MINTABLE_NUM_TOKENS.save(deps.storage, &max_num_tokens)?;
} else {
MINTABLE_NUM_TOKENS.save(deps.storage, &factory_params.extension.max_token_limit)?;
}

// Submessage to instantiate sg721 contract
Expand Down Expand Up @@ -221,13 +223,6 @@ pub fn execute_purge(
info: MessageInfo,
) -> Result<Response, ContractError> {
nonpayable(&info)?;
// check if sold out (optional)
let mintable_num_tokens = MINTABLE_NUM_TOKENS.may_load(deps.storage)?;
if let Some(mintable_nb_tokens) = mintable_num_tokens {
if mintable_nb_tokens != 0 {
return Err(ContractError::NotSoldOut {});
}
}

// Check if mint has ended (optional)
let end_time = CONFIG.load(deps.storage)?.extension.end_time;
Expand All @@ -237,6 +232,14 @@ pub fn execute_purge(
}
}

// check if sold out before end time (optional)
let mintable_num_tokens = MINTABLE_NUM_TOKENS.may_load(deps.storage)?;
if let Some(mintable_nb_tokens) = mintable_num_tokens {
if mintable_nb_tokens != 0 && end_time.is_none() {
return Err(ContractError::NotSoldOut {});
}
}

let keys = MINTER_ADDRS
.keys(deps.storage, None, None, Order::Ascending)
.collect::<Vec<_>>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use open_edition_minter::msg::{
use sg4::StatusResponse;

use crate::common_setup::setup_accounts_and_block::{coins_for_msg, setup_block_time};
use crate::common_setup::setup_minter::common::constants::DEV_ADDRESS;
use crate::common_setup::setup_minter::common::constants::{DEV_ADDRESS, MAX_TOKEN_LIMIT};
use crate::common_setup::setup_minter::open_edition_minter::minter_params::{
default_nft_data, init_msg,
};
Expand Down Expand Up @@ -93,7 +93,7 @@ fn check_mint_revenues_distribution(num_tokens: Option<u32>, end_minter_time: Op
.query_wasm_smart(minter_addr.clone(), &query_config_msg)
.unwrap();
if end_minter_time.is_some() {
assert_eq!(res.count, None);
assert_eq!(res.count, Some(MAX_TOKEN_LIMIT));
} else {
assert_eq!(res.count, Some(5));
}
Expand Down Expand Up @@ -423,14 +423,14 @@ fn check_mint_revenues_distribution(num_tokens: Option<u32>, end_minter_time: Op
}

#[test]
fn check_mint_revenues_distribution_without_end_time() {
fn check_mint_revenues_distribution_with_end_time() {
check_mint_revenues_distribution(
None,
Some(Timestamp::from_nanos(GENESIS_MINT_START_TIME + 10_000)),
)
}

#[test]
fn check_mint_revenues_distribution_with_end_time() {
fn check_mint_revenues_distribution_without_end_time() {
check_mint_revenues_distribution(Some(5u32), None)
}

0 comments on commit 32891b6

Please sign in to comment.