aave / aave-v3-core

This repository contains the core smart contracts of the Aave V3 protocol.

Home Page:https://aave.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

The update of interest rates does not account for the real unbacked amount (can be bypassed if cap is 0)

miguelmtzinf opened this issue · comments

If there is unbacked liquidity in the system and governance decides to "switch off" portals (setting a zero unbackedMintCap), the calculation of the interest rates would be wrong since this function would pass 0 as unbacked because of 0 unbackedMintCap (when we could have non-zero unbacked).

function updateInterestRates(
DataTypes.ReserveData storage reserve,
DataTypes.ReserveCache memory reserveCache,
address reserveAddress,
uint256 liquidityAdded,
uint256 liquidityTaken
) internal {
UpdateInterestRatesLocalVars memory vars;
vars.totalVariableDebt = reserveCache.nextScaledVariableDebt.rayMul(
reserveCache.nextVariableBorrowIndex
);
(
vars.nextLiquidityRate,
vars.nextStableRate,
vars.nextVariableRate
) = IReserveInterestRateStrategy(reserve.interestRateStrategyAddress).calculateInterestRates(
DataTypes.CalculateInterestRatesParams({
unbacked: reserveCache.reserveConfiguration.getUnbackedMintCap() != 0
? reserve.unbacked
: 0,
liquidityAdded: liquidityAdded,
liquidityTaken: liquidityTaken,
totalStableDebt: reserveCache.nextTotalStableDebt,
totalVariableDebt: vars.totalVariableDebt,
averageStableBorrowRate: reserveCache.nextAvgStableBorrowRate,
reserveFactor: reserveCache.reserveFactor,
reserve: reserveAddress,
aToken: reserveCache.aTokenAddress
})
);

Additionally, there is no check of the current unbacked amount in IPoolConfigurator.setUnbackedMintCap.

function setUnbackedMintCap(address asset, uint256 newUnbackedMintCap)
external
override
onlyRiskOrPoolAdmins
{
DataTypes.ReserveConfigurationMap memory currentConfig = _pool.getConfiguration(asset);
uint256 oldUnbackedMintCap = currentConfig.getUnbackedMintCap();
currentConfig.setUnbackedMintCap(newUnbackedMintCap);
_pool.setConfiguration(asset, currentConfig);
emit UnbackedMintCapChanged(asset, oldUnbackedMintCap, newUnbackedMintCap);
}

Agree with fixing the first, but for now would leave the validation of the setter for a following iteration, because I think we should do a broader review of this type of cases (fairly sure there is more)

I didn't mean we should fix the setter, because it is working as intended. I will create a PR for the other.