From d083e58646d5ed31a6dd1ad7171edd3a5350d9fa Mon Sep 17 00:00:00 2001 From: Rubilmax Date: Tue, 31 Oct 2023 09:50:12 +0100 Subject: [PATCH] refactor(irm): compile without IR --- foundry.toml | 12 +++++++++++- src/SpeedJumpIrm.sol | 10 ++++++---- test/SpeedJumpIrmTest.sol | 2 +- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/foundry.toml b/foundry.toml index b4d0a92c..0147431f 100644 --- a/foundry.toml +++ b/foundry.toml @@ -3,7 +3,6 @@ src = "src" out = "out" test = "test" libs = ["lib"] -via-ir = true [profile.default.fuzz] runs = 4096 @@ -11,4 +10,15 @@ runs = 4096 [profile.default.fmt] wrap_comments = true + +[profile.build] +via-ir = true +test = "/dev/null" +script = "/dev/null" + + +[profile.test] +via-ir = false + + # See more config options https://github.com/foundry-rs/foundry/blob/master/crates/config/README.md#all-options diff --git a/src/SpeedJumpIrm.sol b/src/SpeedJumpIrm.sol index 6597f5b5..8e03a4ad 100644 --- a/src/SpeedJumpIrm.sol +++ b/src/SpeedJumpIrm.sol @@ -114,11 +114,13 @@ contract AdaptativeCurveIRM is IIrm { // Safe "unchecked" cast because ADJUSTMENT_SPEED <= type(int256).max. int256 speed = int256(ADJUSTMENT_SPEED).wMulDown(err); - uint256 elapsed = (baseRate[id] > 0) ? block.timestamp - market.lastUpdate : 0; + + uint256 prevBaseRate = baseRate[id]; + uint256 elapsed = (prevBaseRate > 0) ? block.timestamp - market.lastUpdate : 0; // Safe "unchecked" cast because elapsed <= block.timestamp. int256 linearVariation = speed * int256(elapsed); uint256 variationMultiplier = MathLib.wExp(linearVariation); - uint256 newBaseRate = (baseRate[id] > 0) ? baseRate[id].wMulDown(variationMultiplier) : INITIAL_BASE_RATE; + uint256 newBaseRate = (prevBaseRate > 0) ? prevBaseRate.wMulDown(variationMultiplier) : 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). @@ -128,13 +130,13 @@ contract AdaptativeCurveIRM is IIrm { // And avgBorrowRate ~ borrowRateStartOfThePeriod ~ newBorrowRate for linearVariation around zero. // Also, when it is the first interaction (baseRate == 0). uint256 avgBorrowRate; - if (linearVariation == 0 || baseRate[id] == 0) { + if (linearVariation == 0 || prevBaseRate == 0) { avgBorrowRate = newBorrowRate; } else { // Safe "unchecked" cast to uint256 because linearVariation < 0 <=> newBorrowRate <= // borrowRateStartOfThePeriod. avgBorrowRate = - uint256((int256(newBorrowRate) - int256(_curve(baseRate[id], err))).wDivDown(linearVariation)); + uint256((int256(newBorrowRate) - int256(_curve(prevBaseRate, err))).wDivDown(linearVariation)); } // We bound both newBorrowRate and avgBorrowRate between MIN_RATE and MAX_RATE. diff --git a/test/SpeedJumpIrmTest.sol b/test/SpeedJumpIrmTest.sol index d2aa65d3..3aed5a1c 100644 --- a/test/SpeedJumpIrmTest.sol +++ b/test/SpeedJumpIrmTest.sol @@ -164,7 +164,7 @@ contract AdaptativeCurveIRMTest is Test { return avgBorrowRate; } - function _curve(uint256 baseRate, int256 err) internal view returns (uint256) { + function _curve(uint256 baseRate, int256 err) internal pure returns (uint256) { // Safe "unchecked" cast because err >= -1 (in WAD). if (err < 0) { return uint256((WAD_INT - WAD_INT.wDivDown(int256(CURVE_STEEPNESS))).wMulDown(err) + WAD_INT).wMulDown(