Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extract coeff computation in curve function #59

Closed
wants to merge 4 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions src/SpeedJumpIrm.sol
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ contract AdaptativeCurveIrm is IIrm {
// <=> endBorrowRate <= startBorrowRate.
avgBorrowRate = uint256((int256(endBorrowRate) - int256(startBorrowRate)).wDivDown(linearVariation));
}

return (avgBorrowRate, endRateAtTarget);
}
}
Expand All @@ -163,11 +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 coeff = err < 0 ? WAD - WAD.wDivDown(CURVE_STEEPNESS) : CURVE_STEEPNESS - WAD;

// 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);
}
return uint256(coeff.wMulDown(err) + WAD_INT).wMulDown(_rateAtTarget);
}
}