Skip to content

Commit

Permalink
ensure upper limit <= 100%
Browse files Browse the repository at this point in the history
  • Loading branch information
iboss-ptk committed Sep 19, 2023
1 parent 1d73813 commit 051b1b4
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
3 changes: 3 additions & 0 deletions contracts/transmuter/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ pub enum ContractError {
#[error("Upper limit must be greater than zero")]
ZeroUpperLimit {},

#[error("Upper limit must not exceed 100%")]
ExceedHundredPercentUpperLimit {},

#[error("Window must be evenly divisible by division size")]
UnevenWindowDivision {},

Expand Down
20 changes: 20 additions & 0 deletions contracts/transmuter/src/limiter/limiters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,11 @@ impl StaticLimiter {
ContractError::ZeroUpperLimit {}
);

ensure!(
self.upper_limit <= Decimal::percent(100),
ContractError::ExceedHundredPercentUpperLimit {}
);

Ok(self)
}

Expand Down Expand Up @@ -1058,6 +1063,21 @@ mod tests {
.unwrap_err(),
ContractError::ZeroUpperLimit {}
);

// upper limit is 100% + Decimal::raw(1)
assert_eq!(
StaticLimiter::new(Decimal::percent(100) + Decimal::raw(1u128)).unwrap_err(),
ContractError::ExceedHundredPercentUpperLimit {}
);

// set upper limit to 100% + Decimal::raw(1)
assert_eq!(
StaticLimiter::new(Decimal::percent(10))
.unwrap()
.set_upper_limit(Decimal::percent(100) + Decimal::raw(1u128))
.unwrap_err(),
ContractError::ExceedHundredPercentUpperLimit {}
);
}
}
mod remove_outdated_division {
Expand Down

0 comments on commit 051b1b4

Please sign in to comment.