morpho-org / morpho-blue-irm

Morpho Blue Interest Rate Models
https://morpho.org
MIT License
26 stars 17 forks source link

Fix bounds #73

Closed MerlinEgalite closed 11 months ago

MerlinEgalite commented 11 months ago

Based on the following comment: https://github.com/morpho-labs/morpho-blue-irm/pull/54#discussion_r1390240289

endBorrowRate = startBorrowRate * exp(linearAdaptation) is true mathematically but it's not in the code because of how we bound values in the computation. Here is an example of a failing test showcasing the issue: #77

MerlinEgalite commented 11 months ago

testNotUnbounded fails be cause of the issue mentioned above.

testBounded passes because it uses the fix.

MerlinEgalite commented 11 months ago

still to check @morpho-labs/onchain @morpho-labs/protocol

MerlinEgalite commented 11 months ago

With a MAX_CURVE_STEEPNESS = 10_000 ether we must cap WEXP_UPPER_VALUE to 36516193261880035393743548115955503434 to avoid overflows in _curve which is way stricter that the current max value: 115432178323118442717551238386899909037872776636038612254720

MerlinEgalite commented 11 months ago

Closing it but we should adapt the doc perhaps

MathisGD commented 11 months ago

We could have made a special case for when the endRate touches the bounds:

if end = min: avg = min else if end = max: avg = max

MerlinEgalite commented 11 months ago

could be a solution as well indeed!