Skip to content

Commit

Permalink
Merge pull request #182 from morpho-labs/refactor/skip-interest-accrual
Browse files Browse the repository at this point in the history
Skip interest accrual if already accrued in the same block
  • Loading branch information
MathisGD authored Jul 31, 2023
2 parents 1f2ba2a + f5f40d2 commit 4e10a7b
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/Blue.sol
Original file line number Diff line number Diff line change
Expand Up @@ -288,11 +288,15 @@ contract Blue is IFlashLender {
// Interests management.

function _accrueInterests(Market memory market, Id id) internal {
uint256 elapsed = block.timestamp - lastUpdate[id];

if (elapsed == 0) return;

uint256 marketTotalBorrow = totalBorrow[id];

if (marketTotalBorrow != 0) {
uint256 borrowRate = market.irm.borrowRate(market);
uint256 accruedInterests = marketTotalBorrow.mulWadDown(borrowRate * (block.timestamp - lastUpdate[id]));
uint256 accruedInterests = marketTotalBorrow.mulWadDown(borrowRate * elapsed);
totalBorrow[id] = marketTotalBorrow + accruedInterests;
totalSupply[id] += accruedInterests;

Expand Down

0 comments on commit 4e10a7b

Please sign in to comment.