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

refactor: use early return in _accrueInterests #233

Closed
wants to merge 4 commits into from
Closed
Changes from 1 commit
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
31 changes: 15 additions & 16 deletions src/Blue.sol
Original file line number Diff line number Diff line change
Expand Up @@ -371,26 +371,25 @@ contract Blue is IBlue {
if (elapsed == 0) return;

uint256 marketTotalBorrow = totalBorrow[id];
MathisGD marked this conversation as resolved.
Show resolved Hide resolved
lastUpdate[id] = block.timestamp;

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

uint256 feeShares;
if (fee[id] != 0) {
uint256 feeAmount = accruedInterests.mulWadDown(fee[id]);
// The fee amount is subtracted from the total supply in this calculation to compensate for the fact that total supply is already updated.
feeShares = feeAmount.mulDivDown(totalSupplyShares[id], totalSupply[id] - feeAmount);
supplyShares[id][feeRecipient] += feeShares;
totalSupplyShares[id] += feeShares;
}
if (marketTotalBorrow == 0) return;

emit AccrueInterests(id, borrowRate, accruedInterests, feeShares);
uint256 borrowRate = IIrm(market.irm).borrowRate(market);
uint256 accruedInterests = marketTotalBorrow.mulWadDown(borrowRate * elapsed);
totalBorrow[id] = marketTotalBorrow + accruedInterests;
totalSupply[id] += accruedInterests;

uint256 feeShares;
if (fee[id] != 0) {
uint256 feeAmount = accruedInterests.mulWadDown(fee[id]);
// The fee amount is subtracted from the total supply in this calculation to compensate for the fact that total supply is already updated.
feeShares = feeAmount.mulDivDown(totalSupplyShares[id], totalSupply[id] - feeAmount);
supplyShares[id][feeRecipient] += feeShares;
totalSupplyShares[id] += feeShares;
}

lastUpdate[id] = block.timestamp;
emit AccrueInterests(id, borrowRate, accruedInterests, feeShares);
}

// Health check.
Expand Down