Skip to content
This repository was archived by the owner on Dec 9, 2025. It is now read-only.
This repository was archived by the owner on Dec 9, 2025. It is now read-only.

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

@bnb-scs

Description

@bnb-scs

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions