Skip to content

Commit

Permalink
fix: mul before div to avoid precision loss
Browse files Browse the repository at this point in the history
  • Loading branch information
fmorisan committed Mar 30, 2023
1 parent de0fb67 commit ccd8b99
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions contracts/DAIInterestRateModelV4.sol
Original file line number Diff line number Diff line change
Expand Up @@ -82,16 +82,16 @@ 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
}

/**
* @notice Resets the baseRate and multiplier per block based on the stability fee and Dai savings rate
*/
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;
Expand Down

0 comments on commit ccd8b99

Please sign in to comment.