Skip to content

Commit

Permalink
Merge pull request #92 from toints/Magnet-Stack
Browse files Browse the repository at this point in the history
Fixed: Add boundary checks for ratio and threshold parameters
  • Loading branch information
toints authored Jun 25, 2024
2 parents 1b2ccdf + 582bc67 commit e439d7d
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions pallets/liquidation/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,14 @@ pub mod pallet {

/// Require admin authority
RequireAdmin,

/// Invalid ratio sum (must be <= 100%)
InvalidRatio,
/// MinLiquidationThreshold must be greater than ExistentialDeposit
InvalidMinLiquidationThreshold,
/// ProfitDistributionCycle must be greater than 1
InvalidProfitDistributionCycle,

///xcm error
XcmError,
}
Expand Down Expand Up @@ -567,6 +575,13 @@ pub mod pallet {
) -> DispatchResultWithPostInfo {
ensure_root_or_admin::<T>(origin)?;

let treasury_ratio = TreasuryRatio::<T>::get();
let operation_ratio = OperationRatio::<T>::get();
ensure!(
ratio + treasury_ratio + operation_ratio <= Perbill::one(),
Error::<T>::InvalidRatio
);

SystemRatio::<T>::put(ratio);
Self::deposit_event(Event::SystemRatioSet(ratio));
Ok(Pays::No.into())
Expand All @@ -580,6 +595,13 @@ pub mod pallet {
) -> DispatchResultWithPostInfo {
ensure_root_or_admin::<T>(origin)?;

let system_ratio = SystemRatio::<T>::get();
let operation_ratio = OperationRatio::<T>::get();
ensure!(
system_ratio + ratio + operation_ratio <= Perbill::one(),
Error::<T>::InvalidRatio
);

TreasuryRatio::<T>::put(ratio);
Self::deposit_event(Event::TreasuryRatioSet(ratio));
Ok(Pays::No.into())
Expand All @@ -593,6 +615,13 @@ pub mod pallet {
) -> DispatchResultWithPostInfo {
ensure_root_or_admin::<T>(origin)?;

let system_ratio = SystemRatio::<T>::get();
let treasury_ratio = TreasuryRatio::<T>::get();
ensure!(
system_ratio + treasury_ratio + ratio <= Perbill::one(),
Error::<T>::InvalidRatio
);

OperationRatio::<T>::put(ratio);
Self::deposit_event(Event::OperationRatioSet(ratio));
Ok(Pays::No.into())
Expand All @@ -606,6 +635,9 @@ pub mod pallet {
) -> DispatchResultWithPostInfo {
ensure_root_or_admin::<T>(origin)?;

let existential_deposit = <T as pallet::Config>::ExistentialDeposit::get();
ensure!(threshold > existential_deposit, Error::<T>::InvalidMinLiquidationThreshold);

MinLiquidationThreshold::<T>::put(threshold);
Self::deposit_event(Event::MinLiquidationThresholdSet(threshold));
Ok(Pays::No.into())
Expand All @@ -619,6 +651,8 @@ pub mod pallet {
) -> DispatchResultWithPostInfo {
ensure_root_or_admin::<T>(origin)?;

ensure!(cycle > 1u32.into(), Error::<T>::InvalidProfitDistributionCycle);

ProfitDistributionCycle::<T>::put(cycle);
Self::deposit_event(Event::ProfitDistributionCycleSet(cycle));
Ok(Pays::No.into())
Expand Down

0 comments on commit e439d7d

Please sign in to comment.