diff --git a/src/SpeedJumpIrm.sol b/src/SpeedJumpIrm.sol index 8e03a4ad..d48c94b3 100644 --- a/src/SpeedJumpIrm.sol +++ b/src/SpeedJumpIrm.sol @@ -120,7 +120,10 @@ contract AdaptativeCurveIRM is IIrm { // Safe "unchecked" cast because elapsed <= block.timestamp. int256 linearVariation = speed * int256(elapsed); uint256 variationMultiplier = MathLib.wExp(linearVariation); - uint256 newBaseRate = (prevBaseRate > 0) ? prevBaseRate.wMulDown(variationMultiplier) : INITIAL_BASE_RATE; + // newBaseRate is bounded between MIN_BASE_RATE, MAX_BASE_RATE. + uint256 newBaseRate = (prevBaseRate > 0) + ? prevBaseRate.wMulDown(variationMultiplier).bound(MIN_BASE_RATE, MAX_BASE_RATE) + : INITIAL_BASE_RATE; uint256 newBorrowRate = _curve(newBaseRate, err); // Then we compute the average rate over the period (this is what Morpho needs to accrue the interest). @@ -139,8 +142,7 @@ contract AdaptativeCurveIRM is IIrm { uint256((int256(newBorrowRate) - int256(_curve(prevBaseRate, err))).wDivDown(linearVariation)); } - // We bound both newBorrowRate and avgBorrowRate between MIN_RATE and MAX_RATE. - return (avgBorrowRate, newBaseRate.bound(MIN_BASE_RATE, MAX_BASE_RATE)); + return (avgBorrowRate, newBaseRate); } function _curve(uint256 _baseRate, int256 err) internal view returns (uint256) { diff --git a/test/SpeedJumpIrmTest.sol b/test/SpeedJumpIrmTest.sol index 3aed5a1c..4fa3fc44 100644 --- a/test/SpeedJumpIrmTest.sol +++ b/test/SpeedJumpIrmTest.sol @@ -150,8 +150,7 @@ contract AdaptativeCurveIRMTest is Test { int256 speed = int256(ADJUSTMENT_SPEED).wMulDown(err); uint256 elapsed = (baseRate > 0) ? block.timestamp - market.lastUpdate : 0; int256 linearVariation = speed * int256(elapsed); - uint256 variationMultiplier = MathLib.wExp(linearVariation); - uint256 newBaseRate = (baseRate > 0) ? baseRate.wMulDown(variationMultiplier) : INITIAL_BASE_RATE; + uint256 newBaseRate = _expectedBaseRate(id, market); uint256 newBorrowRate = _curve(newBaseRate, err); uint256 avgBorrowRate;