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

Improving skip of updateState() by time, and caching dynamics for indexes #725

Merged
merged 3 commits into from
Nov 14, 2022
Merged
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
26 changes: 16 additions & 10 deletions contracts/protocol/libraries/logic/ReserveLogic.sol
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,17 @@ library ReserveLogic {
DataTypes.ReserveData storage reserve,
DataTypes.ReserveCache memory reserveCache
) internal {
// If time didn't pass since last stored timestamp, skip state update
//solium-disable-next-line
if (reserve.lastUpdateTimestamp == uint40(block.timestamp)) {
return;
}

_updateIndexes(reserve, reserveCache);
_accrueToTreasury(reserve, reserveCache);

//solium-disable-next-line
reserve.lastUpdateTimestamp = uint40(block.timestamp);
}

/**
Expand Down Expand Up @@ -283,9 +292,6 @@ library ReserveLogic {
DataTypes.ReserveData storage reserve,
DataTypes.ReserveCache memory reserveCache
) internal {
reserveCache.nextLiquidityIndex = reserveCache.currLiquidityIndex;
reserveCache.nextVariableBorrowIndex = reserveCache.currVariableBorrowIndex;

//only cumulating if there is any income being produced
if (reserveCache.currLiquidityRate != 0) {
uint256 cumulatedLiquidityInterest = MathUtils.calculateLinearInterest(
Expand All @@ -310,9 +316,6 @@ library ReserveLogic {
reserve.variableBorrowIndex = reserveCache.nextVariableBorrowIndex.toUint128();
}
}

//solium-disable-next-line
reserve.lastUpdateTimestamp = uint40(block.timestamp);
}

/**
Expand All @@ -330,8 +333,9 @@ library ReserveLogic {

reserveCache.reserveConfiguration = reserve.configuration;
reserveCache.reserveFactor = reserveCache.reserveConfiguration.getReserveFactor();
reserveCache.currLiquidityIndex = reserve.liquidityIndex;
reserveCache.currVariableBorrowIndex = reserve.variableBorrowIndex;
reserveCache.currLiquidityIndex = reserveCache.nextLiquidityIndex = reserve.liquidityIndex;
reserveCache.currVariableBorrowIndex = reserveCache.nextVariableBorrowIndex = reserve
.variableBorrowIndex;
reserveCache.currLiquidityRate = reserve.currentLiquidityRate;
reserveCache.currVariableBorrowRate = reserve.currentVariableBorrowRate;

Expand All @@ -342,8 +346,10 @@ library ReserveLogic {
reserveCache.reserveLastUpdateTimestamp = reserve.lastUpdateTimestamp;

reserveCache.currScaledVariableDebt = reserveCache.nextScaledVariableDebt = IVariableDebtToken(
reserveCache.variableDebtTokenAddress
).scaledTotalSupply();
reserveCache
.variableDebtTokenAddress
)
.scaledTotalSupply();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the way your prettier tooling formatted this two lines are a bit messy for readability.
The .scaledTotalSupply() contains an extra new line and also an extra tab, so is like floating over there.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the issue is on the pre-commit hook because it auto-formats this way even when forcing a different format. Any idea?


(
reserveCache.currPrincipalStableDebt,
Expand Down