From 153bc002912fe146cf6c5864793121837466f6b4 Mon Sep 17 00:00:00 2001 From: 0xripleys <105607696+0xripleys@users.noreply.github.com> Date: Mon, 10 Apr 2023 12:10:31 -0700 Subject: [PATCH] div by zero fix (#138) * div by zero fix * fmt * use cur slot instead of 0 --- token-lending/sdk/src/state/rate_limiter.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/token-lending/sdk/src/state/rate_limiter.rs b/token-lending/sdk/src/state/rate_limiter.rs index fc345daf515..d075e514b79 100644 --- a/token-lending/sdk/src/state/rate_limiter.rs +++ b/token-lending/sdk/src/state/rate_limiter.rs @@ -49,7 +49,12 @@ impl Default for RateLimiterConfig { impl RateLimiter { /// initialize rate limiter pub fn new(config: RateLimiterConfig, cur_slot: u64) -> Self { - let slot_start = cur_slot / config.window_duration * config.window_duration; + let slot_start = if config.window_duration != 0 { + cur_slot / config.window_duration * config.window_duration + } else { + cur_slot + }; + Self { config, prev_qty: Decimal::zero(),