From c123cfd00b0613f92371f57c23cf11c0687429df Mon Sep 17 00:00:00 2001 From: MathisGD Date: Sun, 5 Nov 2023 00:51:47 +0100 Subject: [PATCH 1/4] chore: space --- src/SpeedJumpIrm.sol | 1 + 1 file changed, 1 insertion(+) diff --git a/src/SpeedJumpIrm.sol b/src/SpeedJumpIrm.sol index bfde9464..c3911441 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); } } From 94753ff09e8618976c18350655d0256e7f1f69da Mon Sep 17 00:00:00 2001 From: MerlinEgalite Date: Mon, 6 Nov 2023 10:36:07 +0300 Subject: [PATCH 2/4] refactor: extract coeff computation --- src/SpeedJumpIrm.sol | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/SpeedJumpIrm.sol b/src/SpeedJumpIrm.sol index c3911441..de2193b5 100644 --- a/src/SpeedJumpIrm.sol +++ b/src/SpeedJumpIrm.sol @@ -165,10 +165,8 @@ contract AdaptativeCurveIrm is IIrm { /// ((C-1)*err + 1) * rateAtTarget else. function _curve(uint256 _rateAtTarget, int256 err) private view returns (uint256) { // 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); - } + uint256 steeringCoeff = err < 0 ? WAD - WAD.wDivDown(CURVE_STEEPNESS) : CURVE_STEEPNESS - WAD; + + return uint256(steeringCoeff.wMulDown(err) + WAD_INT).wMulDown(_rateAtTarget); } } From 3eb9580757ed3d4cc652af3b44787346f5cd8eac Mon Sep 17 00:00:00 2001 From: MerlinEgalite Date: Mon, 6 Nov 2023 17:53:48 +0300 Subject: [PATCH 3/4] docs: move comment to the right place --- src/SpeedJumpIrm.sol | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/SpeedJumpIrm.sol b/src/SpeedJumpIrm.sol index de2193b5..286f96a2 100644 --- a/src/SpeedJumpIrm.sol +++ b/src/SpeedJumpIrm.sol @@ -164,9 +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) { - // Safe "unchecked" cast because err >= -1 (in WAD). uint256 steeringCoeff = err < 0 ? WAD - WAD.wDivDown(CURVE_STEEPNESS) : CURVE_STEEPNESS - WAD; + // Safe "unchecked" cast because err >= -1 (in WAD). return uint256(steeringCoeff.wMulDown(err) + WAD_INT).wMulDown(_rateAtTarget); } } From f3eaa08641b875bda74bd3c2ce90afcf3e84ad63 Mon Sep 17 00:00:00 2001 From: MerlinEgalite Date: Thu, 9 Nov 2023 12:14:47 +0300 Subject: [PATCH 4/4] refactor: rename variable --- src/SpeedJumpIrm.sol | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/SpeedJumpIrm.sol b/src/SpeedJumpIrm.sol index 286f96a2..372588ad 100644 --- a/src/SpeedJumpIrm.sol +++ b/src/SpeedJumpIrm.sol @@ -164,9 +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 steeringCoeff = err < 0 ? WAD - WAD.wDivDown(CURVE_STEEPNESS) : CURVE_STEEPNESS - WAD; + uint256 coeff = err < 0 ? WAD - WAD.wDivDown(CURVE_STEEPNESS) : CURVE_STEEPNESS - WAD; // Safe "unchecked" cast because err >= -1 (in WAD). - return uint256(steeringCoeff.wMulDown(err) + WAD_INT).wMulDown(_rateAtTarget); + return uint256(coeff.wMulDown(err) + WAD_INT).wMulDown(_rateAtTarget); } }