From 0df8a5a210e5653aca8854e33d1f840791c4851e Mon Sep 17 00:00:00 2001 From: gcranju Date: Thu, 25 Jul 2024 13:48:26 +0545 Subject: [PATCH] fix: calculate limit issue --- contracts/cw-common/src/rate_limit.rs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/contracts/cw-common/src/rate_limit.rs b/contracts/cw-common/src/rate_limit.rs index b71c4b8..542fc32 100644 --- a/contracts/cw-common/src/rate_limit.rs +++ b/contracts/cw-common/src/rate_limit.rs @@ -71,18 +71,18 @@ impl RateLimited for RateLimit { .checked_div(self.period.into()) .unwrap(); - let mut calculated_limit = self.current_limit; + let mut limit = max_limit; - if self.current_limit > added_allowed_withdrawal { - calculated_limit = self + if self.current_limit >= added_allowed_withdrawal { + let calculated_limit = self .current_limit .checked_sub(added_allowed_withdrawal) .unwrap(); - } - // If the balance is below the limit then set limt to current balance (no withdraws are possible) - // If limit goes below what the protected percentage is set it to the maxLimit - let limit = calculated_limit.max(max_limit); + // If the balance is below the limit then set limt to current balance (no withdraws are possible) + // If limit goes below what the protected percentage is set it to the maxLimit + limit = calculated_limit.max(max_limit); + } if balance.checked_sub(amount).unwrap() < limit { return Err(ContractError::Std(StdError::GenericErr { msg: "Exceeds Withdrawal limits".to_string(),