Skip to content

Commit

Permalink
Use bmul_bdiv_* in pallets
Browse files Browse the repository at this point in the history
  • Loading branch information
maltekliemann committed Dec 24, 2023
1 parent 43e8fe6 commit 0c8e9bd
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 26 deletions.
7 changes: 2 additions & 5 deletions zrml/orderbook/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ use sp_runtime::traits::{Get, Zero};
use zeitgeist_primitives::{
math::{
checked_ops_res::{CheckedAddRes, CheckedSubRes},
fixed::{FixedDiv, FixedMul},
fixed::FixedMulDiv,
},
traits::{DistributeFees, MarketCommonsPalletApi},
types::{Asset, Market, MarketStatus, MarketType, ScalarPosition, ScoringRule},
Expand Down Expand Up @@ -295,10 +295,7 @@ mod pallet {
// This ensures that the reserve of the maker
// is always enough to repatriate successfully!
// `maker_full_fill` is ensured to be never zero in `ensure_ratio_quotient_valid`
let ratio = maker_fill.bdiv_floor(maker_full_fill)?;
// returns the (partial) amount of what the taker gets from the maker's amount
// respected the partial fill from the taker of what the maker wants to get filled
ratio.bmul_floor(taker_full_fill)
maker_fill.bmul_bdiv_floor(taker_full_fill, maker_full_fill)
}

fn ensure_ratio_quotient_valid(order_data: &OrderOf<T>) -> DispatchResult {
Expand Down
26 changes: 5 additions & 21 deletions zrml/parimutuel/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,10 @@ mod pallet {
use orml_traits::MultiCurrency;
use sp_runtime::{
traits::{AccountIdConversion, CheckedSub, Zero},
DispatchResult, SaturatedConversion,
DispatchResult,
};
use zeitgeist_primitives::{
constants::BASE,
math::fixed::{FixedDiv, FixedMul},
math::fixed::FixedMulDiv,
traits::DistributeFees,
types::{Asset, Market, MarketStatus, MarketType, OutcomeReport, ScoringRule},
};
Expand Down Expand Up @@ -260,7 +259,6 @@ mod pallet {
winning_balance: BalanceOf<T>,
pot_total: BalanceOf<T>,
outcome_total: BalanceOf<T>,
payoff_ratio_mul_base: BalanceOf<T>,
payoff: BalanceOf<T>,
) -> DispatchResult {
ensure!(
Expand All @@ -275,13 +273,6 @@ mod pallet {
InconsistentStateError::OutcomeIssuanceGreaterCollateral
)
);
if payoff_ratio_mul_base < BASE.saturated_into() {
log::debug!(
target: LOG_TARGET,
"The payoff ratio should be greater than or equal to BASE!"
);
debug_assert!(false);
}
if payoff < winning_balance {
log::debug!(
target: LOG_TARGET,
Expand Down Expand Up @@ -406,16 +397,9 @@ mod pallet {

let pot_account = Self::pot_account(market_id);
let pot_total = T::AssetManager::free_balance(market.base_asset, &pot_account);
let payoff_ratio_mul_base = pot_total.bdiv_floor(outcome_total)?;
let payoff = payoff_ratio_mul_base.bmul_floor(winning_balance)?;

Self::check_values(
winning_balance,
pot_total,
outcome_total,
payoff_ratio_mul_base,
payoff,
)?;
let payoff = pot_total.bmul_bdiv(winning_balance, outcome_total)?;

Self::check_values(winning_balance, pot_total, outcome_total, payoff)?;

let withdrawn_asset_balance = winning_balance;

Expand Down

0 comments on commit 0c8e9bd

Please sign in to comment.