diff --git a/common/cosmwasm-smart-contracts/contracts-common/src/types.rs b/common/cosmwasm-smart-contracts/contracts-common/src/types.rs index 46a6b174c6..95ba1fa6f3 100644 --- a/common/cosmwasm-smart-contracts/contracts-common/src/types.rs +++ b/common/cosmwasm-smart-contracts/contracts-common/src/types.rs @@ -75,9 +75,14 @@ impl Percent { pub fn pow(&self, exp: u32) -> Self { match self.0.checked_pow(exp) { Ok(res) => Percent(res), - Err(overflow) => { - // since the percent is meant to always be strictly less than 1, this should NEVER hapen - panic!("the percent invariant has been broken. the exponentiation result has overflown: {overflow}"); + Err(_overflow) => { + // since the percent is meant to always be less than 1, this should NEVER hapen, however, + // when the inevitable happens because of some misuse, just saturate the result + if self.0 < Decimal::one() { + Percent::zero() + } else { + Percent(Decimal::MAX) + } } } }