From 222b04e20f3f52478ceed3e81d213aad8ef8e81f Mon Sep 17 00:00:00 2001 From: MathisGD Date: Fri, 10 Nov 2023 10:36:43 +0100 Subject: [PATCH] docs: minor improvements --- src/SpeedJumpIrm.sol | 28 ++++++++++++++-------------- test/SpeedJumpIrmTest.sol | 18 +++++++++--------- 2 files changed, 23 insertions(+), 23 deletions(-) diff --git a/src/SpeedJumpIrm.sol b/src/SpeedJumpIrm.sol index 750b12ff..ae166808 100644 --- a/src/SpeedJumpIrm.sol +++ b/src/SpeedJumpIrm.sol @@ -45,7 +45,7 @@ contract AdaptativeCurveIrm is IIrm { /// @notice Target utilization (scaled by WAD). /// @dev Verified to be strictly between 0 and 1 at construction. int256 public immutable TARGET_UTILIZATION; - /// @notice Initial rate at target (scaled by WAD). + /// @notice Initial rate at target per second (scaled by WAD). uint256 public immutable INITIAL_RATE_AT_TARGET; /* STORAGE */ @@ -102,16 +102,16 @@ contract AdaptativeCurveIrm is IIrm { Id id = marketParams.id(); - (uint256 avgBorrowRate, uint256 newRateAtTarget) = _borrowRate(id, market); + (uint256 avgBorrowRate, uint256 endRateAtTarget) = _borrowRate(id, market); - rateAtTarget[id] = newRateAtTarget; + rateAtTarget[id] = endRateAtTarget; - emit BorrowRateUpdate(id, avgBorrowRate, newRateAtTarget); + emit BorrowRateUpdate(id, avgBorrowRate, endRateAtTarget); return avgBorrowRate; } - /// @dev Returns avgBorrowRate and newRateAtTarget. + /// @dev Returns avgBorrowRate and endRateAtTarget. /// @dev Assumes that the inputs `marketParams` and `id` match. function _borrowRate(Id id, Market memory market) private view returns (uint256, uint256) { // Safe "unchecked" cast because the utilization is smaller than 1 (scaled by WAD). @@ -134,28 +134,28 @@ contract AdaptativeCurveIrm is IIrm { // market.lastUpdate != 0 because it is not the first interaction with this market. uint256 elapsed = block.timestamp - market.lastUpdate; // Safe "unchecked" cast because elapsed <= block.timestamp. - int256 linearVariation = speed * int256(elapsed); - uint256 variationMultiplier = MathLib.wExp(linearVariation); + int256 linearAdaptation = speed * int256(elapsed); + uint256 adaptationMultiplier = MathLib.wExp(linearAdaptation); // endRateAtTarget is bounded between MIN_RATE_AT_TARGET and MAX_RATE_AT_TARGET. uint256 endRateAtTarget = - startRateAtTarget.wMulDown(variationMultiplier).bound(MIN_RATE_AT_TARGET, MAX_RATE_AT_TARGET); + startRateAtTarget.wMulDown(adaptationMultiplier).bound(MIN_RATE_AT_TARGET, MAX_RATE_AT_TARGET); uint256 endBorrowRate = _curve(endRateAtTarget, err); // Then we compute the average rate over the period. // Note that startBorrowRate is defined in the computations below. // avgBorrowRate = 1 / elapsed * ∫ startBorrowRate * exp(speed * t) dt between 0 and elapsed - // = startBorrowRate * (exp(linearVariation) - 1) / linearVariation - // = (endBorrowRate - startBorrowRate) / linearVariation - // And avgBorrowRate ~ startBorrowRate = endBorrowRate for linearVariation around zero. + // = startBorrowRate * (exp(linearAdaptation) - 1) / linearAdaptation + // = (endBorrowRate - startBorrowRate) / linearAdaptation + // And for linearAdaptation around zero: avgBorrowRate ~ startBorrowRate = endBorrowRate. // Also, when it is the first interaction (rateAtTarget = 0). uint256 avgBorrowRate; - if (linearVariation == 0) { + if (linearAdaptation == 0) { avgBorrowRate = endBorrowRate; } else { uint256 startBorrowRate = _curve(startRateAtTarget, err); - // Safe "unchecked" cast to uint256 because linearVariation < 0 <=> variationMultiplier <= 1. + // Safe "unchecked" cast to uint256 because linearAdaptation < 0 <=> adaptationMultiplier <= 1. // <=> endBorrowRate <= startBorrowRate. - avgBorrowRate = uint256((int256(endBorrowRate) - int256(startBorrowRate)).wDivDown(linearVariation)); + avgBorrowRate = uint256((int256(endBorrowRate) - int256(startBorrowRate)).wDivDown(linearAdaptation)); } return (avgBorrowRate, endRateAtTarget); diff --git a/test/SpeedJumpIrmTest.sol b/test/SpeedJumpIrmTest.sol index 2b948ac6..ccd1c965 100644 --- a/test/SpeedJumpIrmTest.sol +++ b/test/SpeedJumpIrmTest.sol @@ -194,10 +194,10 @@ contract AdaptativeCurveIrmTest is Test { uint256 rateAtTarget = irm.rateAtTarget(id); int256 speed = ADJUSTMENT_SPEED.wMulDown(_err(market)); uint256 elapsed = (rateAtTarget > 0) ? block.timestamp - market.lastUpdate : 0; - int256 linearVariation = speed * int256(elapsed); - uint256 variationMultiplier = MathLib.wExp(linearVariation); + int256 linearAdaptation = speed * int256(elapsed); + uint256 adaptationMultiplier = MathLib.wExp(linearAdaptation); return (rateAtTarget > 0) - ? rateAtTarget.wMulDown(variationMultiplier).bound(irm.MIN_RATE_AT_TARGET(), irm.MAX_RATE_AT_TARGET()) + ? rateAtTarget.wMulDown(adaptationMultiplier).bound(irm.MIN_RATE_AT_TARGET(), irm.MAX_RATE_AT_TARGET()) : INITIAL_RATE_AT_TARGET; } @@ -206,17 +206,17 @@ contract AdaptativeCurveIrmTest is Test { int256 err = _err(market); int256 speed = ADJUSTMENT_SPEED.wMulDown(err); uint256 elapsed = (rateAtTarget > 0) ? block.timestamp - market.lastUpdate : 0; - int256 linearVariation = speed * int256(elapsed); - uint256 newRateAtTarget = _expectedRateAtTarget(id, market); - uint256 newBorrowRate = _curve(newRateAtTarget, err); + int256 linearAdaptation = speed * int256(elapsed); + uint256 endRateAtTarget = _expectedRateAtTarget(id, market); + uint256 newBorrowRate = _curve(endRateAtTarget, err); uint256 avgBorrowRate; - if (linearVariation == 0 || rateAtTarget == 0) { + if (linearAdaptation == 0 || rateAtTarget == 0) { avgBorrowRate = newBorrowRate; } else { - // Safe "unchecked" cast to uint256 because linearVariation < 0 <=> newBorrowRate <= borrowRateAfterJump. + // Safe "unchecked" cast to uint256 because linearAdaptation < 0 <=> newBorrowRate <= borrowRateAfterJump. avgBorrowRate = - uint256((int256(newBorrowRate) - int256(_curve(rateAtTarget, err))).wDivDown(linearVariation)); + uint256((int256(newBorrowRate) - int256(_curve(rateAtTarget, err))).wDivDown(linearAdaptation)); } return avgBorrowRate; }