Skip to content

Commit

Permalink
perf: remove the need of via ir
Browse files Browse the repository at this point in the history
  • Loading branch information
MerlinEgalite committed Oct 31, 2023
1 parent e061946 commit df39e3e
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
2 changes: 1 addition & 1 deletion foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ src = "src"
out = "out"
test = "test"
libs = ["lib"]
via-ir = true
via-ir = false

[profile.default.fuzz]
runs = 4096
Expand Down
18 changes: 11 additions & 7 deletions src/SpeedJumpIrm.sol
Original file line number Diff line number Diff line change
Expand Up @@ -112,13 +112,17 @@ contract AdaptativeCurveIRM is IIrm {
// Safe "unchecked" int256 casts because utilization <= WAD, TARGET_UTILIZATION < WAD and errNormFactor <= WAD.
int256 err = (int256(utilization) - int256(TARGET_UTILIZATION)).wDivDown(int256(errNormFactor));

// 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;
// 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;
int256 linearVariation;
{
// 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;
// Safe "unchecked" cast because elapsed <= block.timestamp.
linearVariation = speed * int256(elapsed);
}

uint256 newBaseRate =
(baseRate[id] > 0) ? baseRate[id].wMulDown(MathLib.wExp(linearVariation)) : 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 Down
2 changes: 1 addition & 1 deletion test/SpeedJumpIrmTest.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit df39e3e

Please sign in to comment.