-
Notifications
You must be signed in to change notification settings - Fork 20
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
Fix bounds #73
Closed
+26
−8
Closed
Fix bounds #73
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
abf841b
fix: try fixing bounds
MerlinEgalite 08a6921
refactor: remove bounded average
MerlinEgalite 1eec0de
test: remove failing test
MerlinEgalite 88b72e2
Merge branch 'refactor/curve' of github.com:morpho-labs/morpho-blue-i…
MerlinEgalite 1316754
test: remove correct test
MerlinEgalite File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -137,9 +137,9 @@ contract AdaptativeCurveIrm is IIrm { | |
int256 linearAdaptation = speed * int256(elapsed); | ||
uint256 adaptationMultiplier = MathLib.wExp(linearAdaptation); | ||
// endRateAtTarget is bounded between MIN_RATE_AT_TARGET and MAX_RATE_AT_TARGET. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This comment should be moved downward |
||
uint256 endRateAtTarget = | ||
startRateAtTarget.wMulDown(adaptationMultiplier).bound(MIN_RATE_AT_TARGET, MAX_RATE_AT_TARGET); | ||
uint256 endBorrowRate = _curve(endRateAtTarget, err); | ||
uint256 unboundedEndRateAtTarget = startRateAtTarget.wMulDown(adaptationMultiplier); | ||
uint256 endRateAtTarget = unboundedEndRateAtTarget.bound(MIN_RATE_AT_TARGET, MAX_RATE_AT_TARGET); | ||
uint256 endBorrowRate = _curve(unboundedEndRateAtTarget, err); | ||
|
||
// Then we compute the average rate over the period. | ||
// Note that startBorrowRate is defined in the computations below. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice find but the changes come with the following risks:
At the same time, the current situation is not risky: it is bounded and it just corresponds to another value of the average rate.
For these reasons I'm against doing the changes in this PR.
Still, it's true that the formula does not work when the bound is reached. So we should at least adapt the comment above to mention when the formula is valid.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's still capped to
MAX_RATE_AT_TARGET * WEXP_UPPER_VALUE / WAD
though. But I agree. But if we do nothing the code is incorrect so we must find a solution I think. @Rubilmax is working on an alternative solution at the moment.I think we could reduce the max upper value returned by
wExp
to avoid overflow in the_curve
function.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is multiplying the max rate at target by
115432178323118442717551238386899909037872
, not really a small upper bound 😆I don't like it, because the
_curve
function is supposed to return a rate based on the rate at target (that should be in the bounds). We are now considering edge cases where those rates are not really bounded anymore.In the end, what is the issue with the current code ? What are we trying to fix exactly ? Just change the comment and we are fine, we don't have to stick to the formula for extreme edge cases, especially if the current code gives reasonable results where the rate is bounded.
The only issue I can see is that the rate can actually go down if we wait for super long. But this is not an issue in practice because the max rate at target is absurdly high
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok so let's update the comment then