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

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

Closed
miguelmtzinf opened this issue Dec 15, 2022 · 2 comments
Assignees

Comments

@miguelmtzinf
Copy link
Contributor

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);
}

@miguelmtzinf miguelmtzinf self-assigned this Dec 15, 2022
@eboadom
Copy link
Collaborator

eboadom commented Dec 15, 2022

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)

@miguelmtzinf
Copy link
Contributor Author

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

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

2 participants