Skip to content

Commit

Permalink
working version for open edition minter with allowed burn addresses
Browse files Browse the repository at this point in the history
  • Loading branch information
humanalgorithm committed Aug 26, 2023
1 parent b2c4e90 commit 3a967e4
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 29 deletions.
37 changes: 19 additions & 18 deletions contracts/minters/open-edition-minter/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ pub fn instantiate(
.start_trading_time
.or(Some(default_start_time_with_offset));
collection_info.start_trading_time = start_trading_time;

println!("received instantiate msg {:?}", msg);
let config = Config {
factory: factory.clone(),
collection_code_id: msg.collection_params.code_id,
Expand All @@ -132,7 +132,7 @@ pub fn instantiate(
nft_data: msg.init_msg.nft_data,
},
mint_price: sg2::Fungible(msg.init_msg.mint_price),
allowed_burn_collections: None,
allowed_burn_collections: msg.allowed_burn_collections,
};

CONFIG.save(deps.storage, &config)?;
Expand Down Expand Up @@ -267,14 +267,17 @@ pub fn execute_mint_to(
_execute_mint(deps, env, info, action, true, Some(recipient))
}

fn _pay_mint_if_not_contract(
this_contract: Addr,
fn pay_mint_if_not_burn_collection(
info: MessageInfo,
mint_price_with_discounts: Coin,
config_denom: String,
allowed_burn_collections: Option<Vec<Addr>>,
) -> Result<Uint128, ContractError> {
let this_contract = this_contract.to_string();
match info.sender == this_contract {
println!(
"info.sender is {}, allowed burn collections {:?}",
info.sender, allowed_burn_collections
);
match burn_to_mint::sender_is_allowed_burn_collection(info.clone(), allowed_burn_collections) {
true => Ok(Uint128::new(0)),
false => {
let payment = may_pay(&info, &config_denom)?;
Expand All @@ -289,16 +292,16 @@ fn _pay_mint_if_not_contract(
}
}

fn _fairburn_if_not_contract_sender(
fn _fairburn_if_not_burn_collection(
deps: &DepsMut,
this_contract: Addr,
info: MessageInfo,
mint_price_with_discounts: Coin,
mint_fee: Decimal,
factory_params: MinterParams<open_edition_factory::state::ParamsExtension>,
allowed_burn_collections: Option<Vec<Addr>>,
) -> Result<(Response, Uint128), ContractError> {
let mut res = Response::new();
match info.clone().sender == this_contract {
match burn_to_mint::sender_is_allowed_burn_collection(info.clone(), allowed_burn_collections) {
true => Ok((res, Uint128::new(0))),
false => {
let network_fee = mint_price_with_discounts.amount * mint_fee;
Expand All @@ -319,14 +322,14 @@ fn _fairburn_if_not_contract_sender(

fn _compute_seller_amount_if_not_contract_sender(
info: MessageInfo,
this_contract: Addr,
res: Response,
mint_price_with_discounts: Coin,
network_fee: Uint128,
config_extension: crate::state::ConfigExtension,
allowed_burn_collections: Option<Vec<Addr>>,
) -> Result<(Response, Uint128), ContractError> {
let mut res = res;
match info.sender == this_contract {
match burn_to_mint::sender_is_allowed_burn_collection(info.clone(), allowed_burn_collections) {
true => Ok((res, Uint128::new(0))),
false => {
let seller_amount = {
Expand Down Expand Up @@ -376,15 +379,13 @@ fn _execute_mint(
.map_err(|_| ContractError::IncorrectFungibility {})?;
// Exact payment only accepted

_pay_mint_if_not_contract(
env.contract.address.clone(),
pay_mint_if_not_burn_collection(
info.clone(),
mint_price_with_discounts.clone(),
config_denom,
config.allowed_burn_collections.clone(),
)?;

// let mut res = Response::new();

let factory: ParamsResponse = deps
.querier
.query_wasm_smart(config.factory, &Sg2QueryMsg::Params {})?;
Expand All @@ -401,13 +402,13 @@ fn _execute_mint(
} else {
factory_params.mint_fee_bps.bps_to_decimal()
};
let (mut res, network_fee) = _fairburn_if_not_contract_sender(
let (mut res, network_fee) = _fairburn_if_not_burn_collection(
&deps,
env.contract.address.clone(),
info.clone(),
mint_price_with_discounts.clone(),
mint_fee,
factory_params,
config.allowed_burn_collections.clone(),
)?;
// Token ID to mint + update the config counter
let token_id = increment_token_index(deps.storage)?.to_string();
Expand Down Expand Up @@ -442,11 +443,11 @@ fn _execute_mint(

let (res, seller_amount) = _compute_seller_amount_if_not_contract_sender(
info.clone(),
env.contract.address,
res,
mint_price_with_discounts.clone(),
network_fee,
config.extension,
config.allowed_burn_collections,
)?;

Ok(res
Expand Down
2 changes: 2 additions & 0 deletions test-suite/src/common_setup/msg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ pub struct OpenEditionMinterSetupParams<'a> {
pub factory_code_id: u64,
pub sg721_code_id: u64,
pub init_msg: Option<OpenEditionMinterInitMsgExtension>,
pub allowed_burn_collections: Option<Vec<Addr>>,
}

pub struct OpenEditionMinterInstantiateParams {
Expand All @@ -84,4 +85,5 @@ pub struct OpenEditionMinterInstantiateParams {
pub nft_data: Option<NftData>,
pub init_msg: Option<OpenEditionMinterInitMsgExtension>,
pub params_extension: Option<ParamsExtension>,
pub allowed_burn_collections: Option<Vec<Addr>>,
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use cosmwasm_std::{Coin, Timestamp, Uint128};
use cosmwasm_std::{Addr, Coin, Timestamp, Uint128};
use open_edition_factory::{
msg::OpenEditionMinterInitMsgExtension,
state::ParamsExtension,
Expand All @@ -18,6 +18,7 @@ pub fn minter_params_open_edition(
start_time: Option<Timestamp>,
end_time: Option<Timestamp>,
nft_data: Option<NftData>,
allowed_burn_collections: Option<Vec<Addr>>,
) -> OpenEditionMinterInstantiateParams {
let start_time = start_time.unwrap_or(Timestamp::from_nanos(GENESIS_MINT_START_TIME + 100));
let end_time = end_time.unwrap_or(Timestamp::from_nanos(GENESIS_MINT_START_TIME + 10_000));
Expand All @@ -38,6 +39,7 @@ pub fn minter_params_open_edition(
),
init_msg: Some(init_msg),
params_extension: Some(params_extension),
allowed_burn_collections,
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use cosmwasm_std::{coin, Coin, Timestamp, Uint128};
use cosmwasm_std::{coin, Addr, Coin, Timestamp, Uint128};
use open_edition_factory::types::NftData;
use open_edition_factory::{
msg::{OpenEditionMinterCreateMsg, OpenEditionMinterInitMsgExtension},
Expand Down Expand Up @@ -37,6 +37,7 @@ pub fn mock_create_minter(
default_nft_data: NftData,
collection_params: CollectionParams,
payment_address: Option<String>,
allowed_burn_collections: Option<Vec<Addr>>,
) -> OpenEditionMinterCreateMsg {
OpenEditionMinterCreateMsg {
init_msg: mock_init_minter_extension(
Expand All @@ -48,7 +49,7 @@ pub fn mock_create_minter(
payment_address,
),
collection_params,
allowed_burn_collections: None,
allowed_burn_collections,
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,11 @@ pub fn setup_open_edition_minter_contract(
let end_time = setup_params.end_time;
let init_msg = setup_params.init_msg.clone();
let nft_data = setup_params.init_msg.unwrap().nft_data;

let allowed_burn_collections = setup_params.allowed_burn_collections;
println!(
"allowed burn collections test {:?}",
allowed_burn_collections
);
let mut params = mock_params_proper();
params.code_id = minter_code_id;

Expand All @@ -85,6 +89,7 @@ pub fn setup_open_edition_minter_contract(
nft_data.clone(),
collection_params,
None,
allowed_burn_collections,
);
msg.init_msg = build_init_msg(
init_msg,
Expand All @@ -97,6 +102,7 @@ pub fn setup_open_edition_minter_contract(
);
msg.collection_params.code_id = sg721_code_id;
msg.collection_params.info.creator = minter_admin.to_string();

let creation_fee = coins(CREATION_FEE, NATIVE_DENOM);
let msg = Sg2ExecuteMsg::CreateMinter(msg);

Expand Down Expand Up @@ -188,6 +194,9 @@ pub fn configure_open_edition_minter(
.unwrap(),
init_msg: minter_instantiate_params_vec[index].init_msg.clone(),
end_time: minter_instantiate_params_vec[index].end_time.to_owned(),
allowed_burn_collections: minter_instantiate_params_vec[index]
.allowed_burn_collections
.clone(),
};
let minter_collection_res = setup_open_edition_minter_contract(setup_params);
minter_collection_info.push(minter_collection_res);
Expand Down
29 changes: 22 additions & 7 deletions test-suite/src/common_setup/templates.rs
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,8 @@ pub fn open_edition_minter_custom_template(
let (creator, buyer) = setup_accounts(&mut app);
let code_ids = open_edition_minter_code_ids(&mut app);
let collection_params = mock_collection_params_1(None);
let minter_params = minter_params_open_edition(params_extension, init_msg, None, None, None);
let minter_params =
minter_params_open_edition(params_extension, init_msg, None, None, None, None);

let minter_collection_response = configure_open_edition_minter(
&mut app,
Expand All @@ -428,7 +429,7 @@ pub fn open_edition_minter_nft_data(
let code_ids = open_edition_minter_code_ids(&mut app);
let collection_params = mock_collection_params_1(None);
let minter_params =
minter_params_open_edition(params_extension, init_msg, None, None, Some(nft_data));
minter_params_open_edition(params_extension, init_msg, None, None, Some(nft_data), None);

let minter_collection_response = configure_open_edition_minter(
&mut app,
Expand All @@ -455,7 +456,7 @@ pub fn open_edition_minter_start_and_end_time(
let code_ids = open_edition_minter_code_ids(&mut app);
let collection_params = mock_collection_params_1(None);
let minter_params =
minter_params_open_edition(params_extension, init_msg, start_time, end_time, None);
minter_params_open_edition(params_extension, init_msg, start_time, end_time, None, None);

let minter_collection_response = configure_open_edition_minter(
&mut app,
Expand All @@ -480,7 +481,8 @@ pub fn open_edition_minter_custom_code_ids(
let mut app = app;
let (creator, buyer) = setup_accounts(&mut app);
let collection_params = mock_collection_params_1(None);
let minter_params = minter_params_open_edition(params_extension, init_msg, None, None, None);
let minter_params =
minter_params_open_edition(params_extension, init_msg, None, None, None, None);

let minter_collection_response = configure_open_edition_minter(
&mut app,
Expand Down Expand Up @@ -562,9 +564,22 @@ pub fn open_edition_minter_with_two_sg721_collections(
let start_time = Timestamp::from_nanos(GENESIS_MINT_START_TIME);
let collection_params = mock_collection_params_1(Some(start_time));
let collection_params_2 = mock_collection_two(Some(start_time));
let minter_params =
minter_params_open_edition(params_extension.clone(), init_msg.clone(), None, None, None);
let minter_params_2 = minter_params_open_edition(params_extension, init_msg, None, None, None);
let minter_params = minter_params_open_edition(
params_extension.clone(),
init_msg.clone(),
None,
None,
None,
None,
);
let minter_params_2 = minter_params_open_edition(
params_extension,
init_msg,
None,
None,
None,
Some(vec![Addr::unchecked("contract2")]),
);
let code_ids = open_edition_minter_code_ids(&mut router);
let minter_collection_response = configure_open_edition_minter(
&mut router,
Expand Down
1 change: 1 addition & 0 deletions test-suite/src/open_edition_minter/tests/burn_to_mint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ fn check_burns_tokens_when_received() {
};

let res = router.execute_contract(creator, collection_addr_1.clone(), &send_nft, &[]);
println!("res is {:?}", res);
assert!(res.is_ok());

let num_tokens_res: cw721::NumTokensResponse = router
Expand Down
1 change: 1 addition & 0 deletions test-suite/src/open_edition_minter/tests/frozen_factory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ fn frozen_factory_cannot_create_new_minters() {
default_nft_data,
collection_params,
None,
None,
);
msg.collection_params.code_id = 3;
msg.collection_params.info.creator = creator.to_string();
Expand Down

0 comments on commit 3a967e4

Please sign in to comment.