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

Optimisation of the balance/debt increase math #707

Open
wants to merge 1 commit into
base: feat/3.0.1
Choose a base branch
from

Conversation

kyzia551
Copy link
Collaborator

This PR removes one operation in the balance/debt increase-related calculations. Also because of this opt it's no need to use AccrueToTreasuryLocalVars on the _accrueToTreasury function

uint256 balanceIncrease = scaledBalance.rayMul(index) -
scaledBalance.rayMul(_userState[onBehalfOf].additionalData);

uint256 balanceIncrease = scaledBalance.rayMul(index - _userState[onBehalfOf].additionalData);
Copy link
Contributor

Choose a reason for hiding this comment

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

This approach is not exactly equivalent to the other because of math rounding and precision. We should stick to the original approach

reserveCache.nextVariableBorrowIndex
// calculate the total variable debt increase after the moment of the last interaction
uint256 variableDebtIncrease = reserveCache.currScaledVariableDebt.rayMul(
reserveCache.nextVariableBorrowIndex - reserveCache.currVariableBorrowIndex
Copy link
Contributor

Choose a reason for hiding this comment

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

Same

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants