Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions pallets/vsbond-auction/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ pub mod pallet {
InvalidVsbond,
Unexpected,
InvalidRateInput,
Overflow,
}

#[pallet::event]
Expand Down Expand Up @@ -455,7 +456,7 @@ pub mod pallet {
// Calculate the real quantity to clinch
let quantity_clinchd = min(order_info.remain, quantity);
// Calculate the total price that buyer need to pay
let price_to_pay = Self::price_to_pay(quantity_clinchd, order_info.unit_price());
let price_to_pay = Self::price_to_pay(quantity_clinchd, order_info.unit_price())?;

let (token_to_get, amount_to_get, token_to_pay, amount_to_pay) = match order_info
.order_type
Expand Down Expand Up @@ -647,13 +648,12 @@ pub mod pallet {
pub(crate) fn price_to_pay(
quantity: BalanceOf<T, I>,
unit_price: FixedU128,
) -> BalanceOf<T, I> {
) -> Result<BalanceOf<T, I>, Error<T, I>> {
let quantity: u128 = quantity.saturated_into();
let total_price =
unit_price.checked_mul_int(quantity).ok_or(Error::<T, I>::Overflow)?;

let total_price = (unit_price.saturating_mul(quantity.into())).floor().into_inner() /
FixedU128::accuracy();

BalanceOf::<T, I>::saturated_from(total_price)
Ok(BalanceOf::<T, I>::saturated_from(total_price))
}

pub(crate) fn do_order_revoke(order_id: OrderId) -> DispatchResultWithPostInfo {
Expand Down
2 changes: 1 addition & 1 deletion pallets/vsbond-auction/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -948,6 +948,6 @@ fn check_price_to_pay() {
let price_to_pays: [BalanceOf<Test>; 4] = [0, 10, 109, 1099];

for (quantity, price_to_pay) in quantities.iter().zip(price_to_pays.iter()) {
assert_eq!(Auction::price_to_pay(*quantity, unit_price), *price_to_pay);
assert_eq!(Auction::price_to_pay(*quantity, unit_price).unwrap(), *price_to_pay);
}
}