Skip to content

Commit

Permalink
Merge pull request #66 from balancednetwork/fix/calculate-limit-issue
Browse files Browse the repository at this point in the history
fix: calculate limit issue
  • Loading branch information
AntonAndell authored Jul 25, 2024
2 parents d37faa9 + 0df8a5a commit c5e1b80
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions contracts/cw-common/src/rate_limit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down

0 comments on commit c5e1b80

Please sign in to comment.