diff --git a/src/SpeedJumpIrm.sol b/src/SpeedJumpIrm.sol index bfde9464..372588ad 100644 --- a/src/SpeedJumpIrm.sol +++ b/src/SpeedJumpIrm.sol @@ -154,6 +154,7 @@ contract AdaptativeCurveIrm is IIrm { // <=> endBorrowRate <= startBorrowRate. avgBorrowRate = uint256((int256(endBorrowRate) - int256(startBorrowRate)).wDivDown(linearVariation)); } + return (avgBorrowRate, endRateAtTarget); } } @@ -163,11 +164,9 @@ contract AdaptativeCurveIrm is IIrm { /// r = ((1-1/C)*err + 1) * rateAtTarget if err < 0 /// ((C-1)*err + 1) * rateAtTarget else. function _curve(uint256 _rateAtTarget, int256 err) private view returns (uint256) { + uint256 coeff = err < 0 ? WAD - WAD.wDivDown(CURVE_STEEPNESS) : CURVE_STEEPNESS - WAD; + // Safe "unchecked" cast because err >= -1 (in WAD). - if (err < 0) { - return uint256((WAD - WAD.wDivDown(CURVE_STEEPNESS)).wMulDown(err) + WAD_INT).wMulDown(_rateAtTarget); - } else { - return uint256((CURVE_STEEPNESS - WAD).wMulDown(err) + WAD_INT).wMulDown(_rateAtTarget); - } + return uint256(coeff.wMulDown(err) + WAD_INT).wMulDown(_rateAtTarget); } }