Skip to content

Commit

Permalink
Merge branch 'refactor/curve' into refactor/build-profile
Browse files Browse the repository at this point in the history
Signed-off-by: MathisGD <74971347+MathisGD@users.noreply.github.com>
  • Loading branch information
MathisGD authored Oct 31, 2023
2 parents d083e58 + c68cb45 commit 89b0133
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
8 changes: 5 additions & 3 deletions src/SpeedJumpIrm.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand All @@ -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) {
Expand Down
3 changes: 1 addition & 2 deletions test/SpeedJumpIrmTest.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 89b0133

Please sign in to comment.