From ccd8b9912eb6a1f64be1d23e7c93bde09991df3b Mon Sep 17 00:00:00 2001 From: Felipe Buiras Date: Thu, 30 Mar 2023 11:03:03 -0300 Subject: [PATCH] fix: mul before div to avoid precision loss --- contracts/DAIInterestRateModelV4.sol | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/contracts/DAIInterestRateModelV4.sol b/contracts/DAIInterestRateModelV4.sol index 6e1ff9457..643118db9 100644 --- a/contracts/DAIInterestRateModelV4.sol +++ b/contracts/DAIInterestRateModelV4.sol @@ -82,8 +82,8 @@ contract DAIInterestRateModelV4 is JumpRateModelV2 { */ function dsrPerBlock() public view returns (uint) { return (pot.dsr() - RAY_BASE) // scaled RAY_BASE aka RAY, and includes an extra "ONE" before subtraction - / RAY_TO_BASE_SCALE // descale to BASE * SECONDS_PER_BLOCK; // seconds per block + / RAY_TO_BASE_SCALE // descale to BASE } /** @@ -91,7 +91,7 @@ contract DAIInterestRateModelV4 is JumpRateModelV2 { */ function poke() public { (uint duty, ) = jug.ilks("ETH-B"); - uint stabilityFeePerBlock = (duty + jug.base() - RAY_BASE) / RAY_TO_BASE_SCALE * SECONDS_PER_BLOCK; + uint stabilityFeePerBlock = (duty + jug.base() - RAY_BASE) * SECONDS_PER_BLOCK / RAY_TO_BASE_SCALE; // We ensure the minimum borrow rate >= DSR / (1 - reserve factor) baseRatePerBlock = dsrPerBlock() * BASE / assumedOneMinusReserveFactorMantissa;