morpho-org / morpho-blue-irm

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

compare stepped and leap accrual #71

Closed adhusson closed 11 months ago

adhusson commented 11 months ago

(uses the cantina-review branch of morpho-blue) Calling accrueInterests frequently seems to accumulate errors. I haven't looked into why yet but it seemed worth flagging.

The tests start from a market with 1e18 supplied and 0.9e18 borrowed.

// _accrueInterests in Morpho.sol 
market[id].totalBorrowAssets += interest.toUint128();
market[id].totalSupplyAssets += interest.toUint128();

This happens on main as well, with the same starting params & update period the overflow occurs faster (under 9 weeks).

adhusson commented 11 months ago

I took another look (and finally got to try making plots with ChatGPT): (edit: reposting image due to previous image link being dead)

image

Every dot on the yellow line corresponds to running a single accrueInterest, either after 1 week, or after 2 weeks, etc. Other lines accrue interests at regular intervals over a 10 weeks duration. It may not look like it but the yellow line is an exponential.

The difference comes from the fact that utilization goes up through compounding and that the speed and rate corrections are exponential in the utilization (utilization feeds into the error err, which is itself used by speed, startBorrowRate and endBorrowRate).

adhusson commented 11 months ago

Closing (initial rate 200% + 9 weeks untouched market not realistic)