diff --git a/contracts/name-minter/src/contract.rs b/contracts/name-minter/src/contract.rs index 5f6c20e..4e6503e 100644 --- a/contracts/name-minter/src/contract.rs +++ b/contracts/name-minter/src/contract.rs @@ -196,7 +196,18 @@ pub fn execute_mint_and_list( .transpose()? .unwrap_or(None); - let price = validate_payment(name.len(), &info, params.base_price.u128(), discount)?; + let whitelist_type = list.map(|whitelist| match whitelist { + WhitelistContract::Updatable(_) => Some(WhitelistType::Updatable), + WhitelistContract::Flatrate(_) => Some(WhitelistType::Flatrate), + }); + + let price = validate_payment( + name.len(), + &info, + params.base_price.u128(), + discount, + whitelist_type.unwrap(), + )?; charge_fees(&mut res, params.fair_burn_percent, price.amount); let collection = NAME_COLLECTION.load(deps.storage)?; @@ -369,9 +380,10 @@ fn validate_payment( info: &MessageInfo, base_price: u128, discount: Option, + whitelist_type: Option, ) -> Result { // Because we know we are left with ASCII chars, a simple byte count is enough - let amount: Uint128 = (match name_len { + let mut amount: Uint128 = (match name_len { 0..=2 => { return Err(ContractError::NameTooShort {}); } @@ -381,9 +393,23 @@ fn validate_payment( }) .into(); - let amount = discount - .map(|d| amount * (Decimal::one() - d)) - .unwrap_or(amount); + amount = match whitelist_type { + Some(WhitelistType::Updatable) => discount + .map(|d| amount * (Decimal::one() - d)) + .unwrap_or(amount), + Some(WhitelistType::Flatrate) => { + // we assume that discount is a flat amount and + // not a percentage and is a whole number + discount + .map(|d| amount - (d * Uint128::from(1u128))) + .unwrap_or(amount) + } + None => return Err(ContractError::InvalidWhitelistType {}), + }; + + // let amount = discount + // .map(|d| amount * (Decimal::one() - d)) + // .unwrap_or(amount); let payment = must_pay(info, NATIVE_DENOM)?; if payment != amount { @@ -463,7 +489,7 @@ pub fn migrate(deps: DepsMut, _env: Env, _msg: Empty) -> Result