Skip to content

Commit

Permalink
working allowed collections for base,vending and open edition minter
Browse files Browse the repository at this point in the history
  • Loading branch information
humanalgorithm committed Aug 27, 2023
1 parent 3a967e4 commit 79c425b
Show file tree
Hide file tree
Showing 14 changed files with 95 additions and 78 deletions.
18 changes: 6 additions & 12 deletions contracts/minters/open-edition-minter/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,6 @@ 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 Down Expand Up @@ -240,7 +239,7 @@ pub fn execute_mint_sender(
{
return Err(ContractError::MaxPerAddressLimitExceeded {});
}
_execute_mint(deps, env, info, action, false, None)
_execute_mint(deps, info, action, false, None)
}

pub fn execute_mint_to(
Expand All @@ -264,7 +263,7 @@ pub fn execute_mint_to(
return Err(ContractError::AfterMintEndTime {});
}

_execute_mint(deps, env, info, action, true, Some(recipient))
_execute_mint(deps, info, action, true, Some(recipient))
}

fn pay_mint_if_not_burn_collection(
Expand All @@ -273,10 +272,6 @@ fn pay_mint_if_not_burn_collection(
config_denom: String,
allowed_burn_collections: Option<Vec<Addr>>,
) -> Result<Uint128, ContractError> {
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 => {
Expand All @@ -292,7 +287,7 @@ fn pay_mint_if_not_burn_collection(
}
}

fn _fairburn_if_not_burn_collection(
fn fairburn_if_not_burn_collection(
deps: &DepsMut,
info: MessageInfo,
mint_price_with_discounts: Coin,
Expand Down Expand Up @@ -329,7 +324,7 @@ fn _compute_seller_amount_if_not_contract_sender(
allowed_burn_collections: Option<Vec<Addr>>,
) -> Result<(Response, Uint128), ContractError> {
let mut res = res;
match burn_to_mint::sender_is_allowed_burn_collection(info.clone(), allowed_burn_collections) {
match burn_to_mint::sender_is_allowed_burn_collection(info, allowed_burn_collections) {
true => Ok((res, Uint128::new(0))),
false => {
let seller_amount = {
Expand All @@ -356,7 +351,6 @@ fn _compute_seller_amount_if_not_contract_sender(
// mint_to(recipient: "friend") -> _execute_mint(Some(recipient), token_id: None)
fn _execute_mint(
deps: DepsMut,
env: Env,
info: MessageInfo,
action: &str,
is_admin: bool,
Expand Down Expand Up @@ -402,7 +396,7 @@ fn _execute_mint(
} else {
factory_params.mint_fee_bps.bps_to_decimal()
};
let (mut res, network_fee) = _fairburn_if_not_burn_collection(
let (mut res, network_fee) = fairburn_if_not_burn_collection(
&deps,
info.clone(),
mint_price_with_discounts.clone(),
Expand Down Expand Up @@ -688,7 +682,7 @@ pub fn burn_and_mint(
info: MessageInfo,
msg: Cw721ReceiveMsg,
) -> Result<Response, ContractError> {
let res = burn_to_mint::generate_burn_msg(info.clone(), msg.clone())?;
let res = burn_to_mint::generate_burn_msg(info.clone(), msg)?;
let mint_res = execute_mint_sender(deps, env, info)?;
Ok(mint_res.add_submessages(res.messages))
}
Expand Down
44 changes: 22 additions & 22 deletions contracts/minters/vending-minter/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ pub fn instantiate(
discount_price: None,
},
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 @@ -246,19 +246,19 @@ pub fn execute(
execute_update_discount_price(deps, env, info, price)
}
ExecuteMsg::RemoveDiscountPrice {} => execute_remove_discount_price(deps, info),
ExecuteMsg::ReceiveNft(msg) => call_burn_to_mint(deps, env, info, msg),
ExecuteMsg::ReceiveNft(msg) => burn_and_mint(deps, env, info, msg),
}
}

pub fn call_burn_to_mint(
_deps: DepsMut,
pub fn burn_and_mint(
deps: DepsMut,
env: Env,
info: MessageInfo,
msg: Cw721ReceiveMsg,
) -> Result<Response, ContractError> {
let execute_mint_msg = ExecuteMsg::Mint {};
burn_to_mint::generate_burn_mint_response(info, env, msg, execute_mint_msg)
.map_err(|_| ContractError::BurnToMintError {})
let res = burn_to_mint::generate_burn_msg(info.clone(), msg)?;
let mint_res = execute_mint_sender(deps, env, info)?;
Ok(mint_res.add_submessages(res.messages))
}

pub fn execute_update_discount_price(
Expand Down Expand Up @@ -596,14 +596,13 @@ pub fn execute_mint_for(
)
}

fn _pay_mint_if_not_contract(
this_contract: Addr,
fn pay_mint_if_not_contract(
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 {
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 @@ -618,15 +617,15 @@ fn _pay_mint_if_not_contract(
}
}

fn _compute_seller_amount_if_not_contract_sender(
fn compute_seller_amount_if_not_contract_sender(
info: MessageInfo,
this_contract: Addr,
mut 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> {
match info.sender == this_contract {
match burn_to_mint::sender_is_allowed_burn_collection(info, allowed_burn_collections) {
true => Ok((res, Uint128::new(0))),
false => {
let seller_amount = {
Expand Down Expand Up @@ -692,13 +691,12 @@ fn _execute_mint(
.denom()
.map_err(|_| ContractError::IncorrectFungibility {})?;

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

let mut res = Response::new();

let factory: ParamsResponse = deps
Expand All @@ -715,9 +713,11 @@ fn _execute_mint(
} else {
factory_params.mint_fee_bps.bps_to_decimal()
};

let network_fee = mint_price_with_discounts.amount * mint_fee;
if env.contract.address != info.sender {
if !burn_to_mint::sender_is_allowed_burn_collection(
info.clone(),
config.allowed_burn_collections.clone(),
) {
if mint_price_with_discounts.denom != NATIVE_DENOM {
// only send non-zero amounts
if !network_fee.is_zero() {
Expand Down Expand Up @@ -750,7 +750,7 @@ fn _execute_mint(
}
TokenPositionMapping { position, token_id }
}
None => random_mintable_token_mapping(deps.as_ref(), env.clone(), info.sender.clone())?,
None => random_mintable_token_mapping(deps.as_ref(), env, info.sender.clone())?,
};

// Create mint msgs
Expand Down Expand Up @@ -779,13 +779,13 @@ fn _execute_mint(
let new_mint_count = mint_count(deps.as_ref(), &info)? + 1;
MINTER_ADDRS.save(deps.storage, &info.sender, &new_mint_count)?;

let (res, seller_amount) = _compute_seller_amount_if_not_contract_sender(
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
10 changes: 5 additions & 5 deletions packages/burn-to-mint/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ pub fn check_sender_creator_or_allowed_burn_collection(
allowed_burn_collections: Option<Vec<Addr>>,
) -> Result<bool, StdError> {
let mut allowed_senders = vec![creator_addr];
if allowed_burn_collections.is_some() {
allowed_senders.append(&mut allowed_burn_collections.unwrap());
if let Some(mut allowed_burn_collections) = allowed_burn_collections {
allowed_senders.append(&mut allowed_burn_collections);
};
if !allowed_senders.contains(&info.sender) {
return Err(StdError::GenericErr {
Expand All @@ -68,8 +68,8 @@ pub fn sender_is_allowed_burn_collection(
info: MessageInfo,
allowed_burn_collections: Option<Vec<Addr>>,
) -> bool {
if allowed_burn_collections.is_some() {
return allowed_burn_collections.unwrap().contains(&info.sender);
if let Some(allowed_burn_collections) = allowed_burn_collections {
return allowed_burn_collections.contains(&info.sender);
};
return false;
false
}
18 changes: 5 additions & 13 deletions test-suite/src/base_minter/tests/integration_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::common_setup::setup_minter::base_minter::mock_params::mock_params;
use crate::common_setup::setup_minter::common::constants::MIN_MINT_PRICE;
use crate::common_setup::templates::{
base_minter_with_sg721, base_minter_with_sg721nt, base_minter_with_specified_sg721,
base_minter_with_two_sg721_collections,
base_minter_with_two_sg721_collections_burn_mint,
};
use base_factory::msg::{BaseMinterCreateMsg, BaseUpdateParamsMsg, SudoMsg};

Expand Down Expand Up @@ -228,7 +228,8 @@ fn update_start_trading_time() {

#[test]
fn check_burns_tokens_when_received() {
let bmt = base_minter_with_two_sg721_collections(2);
let allowed_collections_vec = vec![Addr::unchecked("contract2".to_string())];
let bmt = base_minter_with_two_sg721_collections_burn_mint(2, allowed_collections_vec);
let (mut router, creator) = (bmt.router, bmt.accts.creator);
let minter_addr_1 = bmt.collection_response_vec[0].minter.clone().unwrap();
let collection_addr_1 = bmt.collection_response_vec[0].collection.clone().unwrap();
Expand Down Expand Up @@ -263,7 +264,6 @@ fn check_burns_tokens_when_received() {
msg: to_binary(&token_uri_msg).unwrap(),
};
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 All @@ -277,19 +277,12 @@ fn check_burns_tokens_when_received() {

#[test]
fn check_mints_new_tokens_when_received() {
let bmt = base_minter_with_two_sg721_collections(2);
let allowed_collections_vec = vec![Addr::unchecked("contract2".to_string())];
let bmt = base_minter_with_two_sg721_collections_burn_mint(2, allowed_collections_vec);
let (mut router, creator) = (bmt.router, bmt.accts.creator);
let minter_addr_1 = bmt.collection_response_vec[0].minter.clone().unwrap();
let collection_addr_1 = bmt.collection_response_vec[0].collection.clone().unwrap();
let collection_addr_2 = bmt.collection_response_vec[1].collection.clone().unwrap();

println!(
"collection 1: {}, collection 2: {}, minter1: {}, minter2: {}",
collection_addr_1.to_string(),
collection_addr_2.to_string(),
minter_addr_1.to_string(),
bmt.collection_response_vec[1].minter.clone().unwrap()
);
let minter_addr_2 = bmt.collection_response_vec[1].minter.clone().unwrap();

let token_uri = "ipfs://example".to_string();
Expand Down Expand Up @@ -339,7 +332,6 @@ fn check_mints_new_tokens_when_received() {
&send_nft,
&[coin(5_000_000_000, NATIVE_DENOM)],
);
println!("res is {:?}", res);
assert!(res.is_ok());
let num_tokens_res: cw721::NumTokensResponse = router
.wrap()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ pub fn mock_init_minter_extension(
}
}

#[allow(clippy::too_many_arguments)]
pub fn mock_create_minter(
start_time: Option<Timestamp>,
end_time: Option<Timestamp>,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use cosmwasm_std::{coin, Timestamp};
use cosmwasm_std::{coin, Addr, Timestamp};
use sg2::msg::CollectionParams;
use sg_std::{GENESIS_MINT_START_TIME, NATIVE_DENOM};
use vending_factory::{
Expand Down Expand Up @@ -30,11 +30,12 @@ pub fn mock_create_minter(
splits_addr: Option<String>,
collection_params: CollectionParams,
start_time: Option<Timestamp>,
allowed_burn_collections: Option<Vec<Addr>>,
) -> VendingMinterCreateMsg {
VendingMinterCreateMsg {
init_msg: mock_init_extension(splits_addr, start_time),
collection_params,
allowed_burn_collections: None,
allowed_burn_collections,
}
}

Expand Down
12 changes: 10 additions & 2 deletions test-suite/src/common_setup/setup_minter/vending_minter/setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ pub fn setup_minter_contract(setup_params: MinterSetupParams) -> MinterCollectio
let collection_params = setup_params.collection_params;
let start_time = setup_params.start_time;
let init_msg = setup_params.init_msg;
let allowed_burn_collections = setup_params.allowed_burn_collections;

let mint_denom: Option<String> = init_msg
.as_ref()
Expand All @@ -65,7 +66,12 @@ pub fn setup_minter_contract(setup_params: MinterSetupParams) -> MinterCollectio
None,
)
.unwrap();
let mut msg = mock_create_minter(splits_addr, collection_params, start_time);
let mut msg = mock_create_minter(
splits_addr,
collection_params,
start_time,
allowed_burn_collections,
);
msg.init_msg = build_init_msg(init_msg, msg.clone(), num_tokens);
msg.collection_params.code_id = sg721_code_id;
msg.collection_params.info.creator = minter_admin.to_string();
Expand Down Expand Up @@ -128,7 +134,9 @@ pub fn configure_minter(
sg721_code_id: code_ids.sg721_code_id,
start_time: minter_instantiate_params_vec[index].start_time,
init_msg: minter_instantiate_params_vec[index].init_msg.clone(),
allowed_burn_collections: None,
allowed_burn_collections: minter_instantiate_params_vec[index]
.allowed_burn_collections
.clone(),
};
let minter_collection_res = setup_minter_contract(setup_params);
minter_collection_info.push(minter_collection_res);
Expand Down
Loading

0 comments on commit 79c425b

Please sign in to comment.