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

duplicated arithmetic multiplication during calculating variable and stable debt? #337

Open
bnb-scs opened this issue Oct 4, 2024 · 0 comments

Comments

@bnb-scs
Copy link

bnb-scs commented Oct 4, 2024

Have a question about the stable and variable debt calculating logic in the _mintToTreasury() function.

https://github.com/aave/protocol-v2/blob/release/aave-v2-ethereum/contracts/protocol/libraries/logic/ReserveLogic.sol#L274-L311

it seems the passed in scaledVariableDebt has already multiplied by the reserve.variableBorrowIndex factor in ReserveLogic.sol, why do multiply it by previousVariableBorrowIndex (and newVariableBorrowIndex) again in _mintToTreasury()? the resulting variable debt would be the principal debt supply multiply twice the variableBorrowIndex

    //calculate the last principal variable debt
    vars.previousVariableDebt = scaledVariableDebt.rayMul(previousVariableBorrowIndex);

    //calculate the new total supply after accumulation of the index
    vars.currentVariableDebt = scaledVariableDebt.rayMul(newVariableBorrowIndex);

For stable debt, vars.currentStableDebt and vars.previousStableDebt seem to be the same, where IStableDebtToken(reserve.stableDebtTokenAddress).getSupplyData() calculates the current stable debt by multiply the principleSupply and the compoundedInterest, whereas previousStableDebt is calculated using exactly the same formula with the same avgrate and same stableSupplyUpdatedTimestamp, so these two variables should be always the same?

@bnb-scs bnb-scs closed this as completed Oct 4, 2024
@bnb-scs bnb-scs reopened this Oct 4, 2024
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

No branches or pull requests

1 participant