From fc2852e94e1d1aae18e25852fe366f5725670dd9 Mon Sep 17 00:00:00 2001 From: The3D Date: Mon, 14 Sep 2020 09:53:21 +0200 Subject: [PATCH] Rename updateIndexesAndTimestamp to updateState --- contracts/lendingpool/LendingPool.sol | 37 ++++--------------- .../LendingPoolLiquidationManager.sol | 8 ++-- contracts/libraries/logic/ReserveLogic.sol | 4 +- 3 files changed, 14 insertions(+), 35 deletions(-) diff --git a/contracts/lendingpool/LendingPool.sol b/contracts/lendingpool/LendingPool.sol index 34d8e1aa..88df63af 100644 --- a/contracts/lendingpool/LendingPool.sol +++ b/contracts/lendingpool/LendingPool.sol @@ -103,7 +103,7 @@ contract LendingPool is VersionedInitializable, ILendingPool { address aToken = reserve.aTokenAddress; - reserve.updateCumulativeIndexesAndTimestamp(); + reserve.updateState(); reserve.updateInterestRates(asset, aToken, amount, 0); bool isFirstDeposit = IAToken(aToken).balanceOf(onBehalfOf) == 0; @@ -149,7 +149,7 @@ contract LendingPool is VersionedInitializable, ILendingPool { _addressesProvider.getPriceOracle() ); - reserve.updateCumulativeIndexesAndTimestamp(); + reserve.updateState(); reserve.updateInterestRates(asset, aToken, 0, amountToWithdraw); @@ -237,7 +237,7 @@ contract LendingPool is VersionedInitializable, ILendingPool { variableDebt ); - reserve.updateCumulativeIndexesAndTimestamp(); + reserve.updateState(); address debtTokenAddress = interestRateMode == ReserveLogic.InterestRateMode.STABLE ? reserve.stableDebtTokenAddress @@ -284,7 +284,7 @@ contract LendingPool is VersionedInitializable, ILendingPool { interestRateMode ); - reserve.updateCumulativeIndexesAndTimestamp(); + reserve.updateState(); address debtTokenAddress = interestRateMode == ReserveLogic.InterestRateMode.STABLE ? reserve.stableDebtTokenAddress @@ -346,7 +346,7 @@ contract LendingPool is VersionedInitializable, ILendingPool { //burn old debt tokens, mint new ones - reserve.updateCumulativeIndexesAndTimestamp(); + reserve.updateState(); _mintToReserveTreasury(reserve, user, address(stableDebtToken)); @@ -529,7 +529,7 @@ contract LendingPool is VersionedInitializable, ILendingPool { if (debtMode == ReserveLogic.InterestRateMode.NONE) { IERC20(asset).transferFrom(receiverAddress, vars.aTokenAddress, vars.amountPlusPremium); - reserve.updateCumulativeIndexesAndTimestamp(); + reserve.updateState(); reserve.cumulateToLiquidityIndex(IERC20(vars.aTokenAddress).totalSupply(), vars.premium); reserve.updateInterestRates(asset, vars.aTokenAddress, vars.premium, 0); @@ -818,7 +818,7 @@ contract LendingPool is VersionedInitializable, ILendingPool { _mintToReserveTreasury(reserve, vars.user, debtTokenAddress); - reserve.updateCumulativeIndexesAndTimestamp(); + reserve.updateState(); //caching the current stable borrow rate uint256 currentStableRate = 0; @@ -931,27 +931,4 @@ contract LendingPool is VersionedInitializable, ILendingPool { function getAddressesProvider() external view returns (ILendingPoolAddressesProvider) { return _addressesProvider; } - - function _mintToReserveTreasury( - ReserveLogic.ReserveData storage reserve, - address user, - address debtTokenAddress - ) internal { - uint256 reserveFactor = reserve.configuration.getReserveFactor(); - if (reserveFactor == 0) { - return; - } - - uint256 currentPrincipalBalance = DebtTokenBase(debtTokenAddress).principalBalanceOf(user); - //calculating the interest accrued since the last borrow and minting the equivalent amount to the reserve factor - if (currentPrincipalBalance > 0) { - uint256 balanceIncrease = IERC20(debtTokenAddress).balanceOf(user).sub( - currentPrincipalBalance - ); - - uint256 amountForReserveFactor = balanceIncrease.percentMul(reserveFactor); - - IAToken(reserve.aTokenAddress).mintToReserve(amountForReserveFactor); - } - } } diff --git a/contracts/lendingpool/LendingPoolLiquidationManager.sol b/contracts/lendingpool/LendingPoolLiquidationManager.sol index 83f37172..848aaffb 100644 --- a/contracts/lendingpool/LendingPoolLiquidationManager.sol +++ b/contracts/lendingpool/LendingPoolLiquidationManager.sol @@ -232,7 +232,7 @@ contract LendingPoolLiquidationManager is VersionedInitializable { } //update the principal reserve - principalReserve.updateCumulativeIndexesAndTimestamp(); + principalReserve.updateState(); @@ -279,7 +279,7 @@ contract LendingPoolLiquidationManager is VersionedInitializable { //otherwise receives the underlying asset //updating collateral reserve - collateralReserve.updateCumulativeIndexesAndTimestamp(); + collateralReserve.updateState(); collateralReserve.updateInterestRates( collateral, address(vars.collateralAtoken), @@ -406,7 +406,7 @@ contract LendingPoolLiquidationManager is VersionedInitializable { vars.actualAmountToLiquidate = vars.principalAmountNeeded; } //updating collateral reserve indexes - collateralReserve.updateCumulativeIndexesAndTimestamp(); + collateralReserve.updateState(); vars.collateralAtoken.burn(user, receiver, vars.maxCollateralToLiquidate, collateralReserve.liquidityIndex); @@ -426,7 +426,7 @@ contract LendingPoolLiquidationManager is VersionedInitializable { ); //updating debt reserve - debtReserve.updateCumulativeIndexesAndTimestamp(); + debtReserve.updateState(); debtReserve.updateInterestRates(principal, principalAToken, vars.actualAmountToLiquidate, 0); IERC20(principal).transferFrom(receiver, principalAToken, vars.actualAmountToLiquidate); diff --git a/contracts/libraries/logic/ReserveLogic.sol b/contracts/libraries/logic/ReserveLogic.sol index 3d688b75..e2f3df70 100644 --- a/contracts/libraries/logic/ReserveLogic.sol +++ b/contracts/libraries/logic/ReserveLogic.sol @@ -125,7 +125,9 @@ library ReserveLogic { * a formal specification. * @param reserve the reserve object **/ - function updateCumulativeIndexesAndTimestamp(ReserveData storage reserve) internal { + function updateState(ReserveData storage reserve) internal { + + uint256 currentLiquidityRate = reserve.currentLiquidityRate; //only cumulating if there is any income being produced