Skip to content

Commit

Permalink
use mint discount percent (#178)
Browse files Browse the repository at this point in the history
* use mint discount percent

* Refactor discount

Co-authored-by: Shane Vitarana <shanev@gmail.com>
  • Loading branch information
yubrew and shanev authored Nov 7, 2022
1 parent 87b21bb commit 0b5dcce
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 13 deletions.
18 changes: 10 additions & 8 deletions contracts/name-minter/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,12 +167,14 @@ pub fn execute_mint_and_list(
return Err(ContractError::MintingNotStarted {});
}

let discount = if let Some(list) = list {
res = res.add_message(list.process_address(sender)?);
list.config(&deps.querier).map(|c| c.mint_discount())?
} else {
None
};
let discount = list
.map(|list| {
res.messages
.push(SubMsg::new(list.process_address(sender)?));
list.mint_discount_percent(&deps.querier)
})
.transpose()?
.unwrap_or(None);

let price = validate_payment(name.len(), &info, params.base_price.u128(), discount)?;
charge_fees(&mut res, params.fair_burn_percent, price.amount);
Expand Down Expand Up @@ -333,8 +335,8 @@ fn validate_payment(
let payment = must_pay(info, NATIVE_DENOM)?;
if payment != amount {
return Err(ContractError::IncorrectPayment {
got: amount.u128(),
expected: payment.u128(),
got: payment.u128(),
expected: amount.u128(),
});
}

Expand Down
8 changes: 4 additions & 4 deletions contracts/whitelist-updatable/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use crate::state::{Config, CONFIG, TOTAL_ADDRESS_COUNT, WHITELIST};
use cosmwasm_std::entry_point;
use cosmwasm_std::{
to_binary, Addr, Binary, Decimal, Deps, DepsMut, Env, Event, MessageInfo, Order, StdResult,
Uint128,
};
use cw2::set_contract_version;

Expand Down Expand Up @@ -322,8 +321,9 @@ pub fn query_is_processable(deps: Deps, address: String) -> StdResult<bool> {
Ok(count < config.per_address_limit)
}

pub fn query_mint_discount_percent(deps: Deps) -> StdResult<Decimal> {
pub fn query_mint_discount_percent(deps: Deps) -> StdResult<Option<Decimal>> {
let config = CONFIG.load(deps.storage)?;
let discount_bps = config.mint_discount_bps.map_or(0u64, |v| v);
Ok(Decimal::percent(discount_bps) / Uint128::from(100u128))
Ok(config
.mint_discount_bps
.map(|x| Decimal::from_ratio(x, 10_000u128)))
}
2 changes: 1 addition & 1 deletion contracts/whitelist-updatable/src/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ impl WhitelistUpdatableContract {
Ok(res.config)
}

pub fn mint_discount_percent(&self, querier: &QuerierWrapper) -> StdResult<Decimal> {
pub fn mint_discount_percent(&self, querier: &QuerierWrapper) -> StdResult<Option<Decimal>> {
querier.query(&QueryRequest::Wasm(WasmQuery::Smart {
contract_addr: self.addr().into(),
msg: to_binary(&QueryMsg::MintDiscountPercent {})?,
Expand Down

0 comments on commit 0b5dcce

Please sign in to comment.