Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed: Add boundary checks for ratio and threshold parameters #92

Merged
merged 1 commit into from
Jun 25, 2024
Merged
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
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
Loading