Skip to content

Commit

Permalink
Replace with saturating sub (#930)
Browse files Browse the repository at this point in the history
## Describe your changes

1. The auction logic is now using saturating subtraction.
2. Fixed a typo
  • Loading branch information
Gauthamastro authored Mar 20, 2024
2 parents db7ae33 + c68818e commit 6ded428
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions pallets/ocex/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1530,7 +1530,8 @@ pub mod pallet {
);
let fee_to_be_burnt =
Percent::from_percent(distribution.burn_ration) * fees;
let fee_to_be_distributed = fees - fee_to_be_burnt;
let fee_to_be_distributed =
fees.saturating_sub(fee_to_be_burnt);
// Burn the fee
let imbalance = T::NativeCurrency::burn(
fee_to_be_burnt.saturated_into(),
Expand Down Expand Up @@ -2118,11 +2119,12 @@ pub mod pallet {
let _ = T::NativeCurrency::unreserve(&bidder, total_bidder_reserve_balance);
let amount_to_be_burnt =
Percent::from_percent(fee_config.burn_ration) * total_bidder_reserve_balance;
let trasnferable_amount = total_bidder_reserve_balance - amount_to_be_burnt;
let transferable_amount =
total_bidder_reserve_balance.saturating_sub(amount_to_be_burnt);
T::NativeCurrency::transfer(
&bidder,
&fee_config.recipient_address,
trasnferable_amount,
transferable_amount,
ExistenceRequirement::KeepAlive,
)?;

Expand All @@ -2139,7 +2141,7 @@ pub mod pallet {
Self::deposit_event(Event::<T>::AuctionClosed {
bidder,
burned: Compact::from(amount_to_be_burnt),
paid_to_operator: Compact::from(trasnferable_amount),
paid_to_operator: Compact::from(transferable_amount),
})
}
Ok(())
Expand Down

0 comments on commit 6ded428

Please sign in to comment.