From 044b492f7fbb853d5ad7c93dabe883a27c9226e9 Mon Sep 17 00:00:00 2001 From: The3D Date: Fri, 4 Jun 2021 14:47:02 +0200 Subject: [PATCH] refactor: further refactored the CachingHelper --- contracts/protocol/lendingpool/LendingPool.sol | 3 --- .../protocol/lendingpool/LendingPoolCollateralManager.sol | 2 +- contracts/protocol/libraries/helpers/CachingHelper.sol | 8 +++----- contracts/protocol/libraries/logic/ReserveLogic.sol | 8 ++++---- 4 files changed, 8 insertions(+), 13 deletions(-) diff --git a/contracts/protocol/lendingpool/LendingPool.sol b/contracts/protocol/lendingpool/LendingPool.sol index 06bfeb8e..3165a0e2 100644 --- a/contracts/protocol/lendingpool/LendingPool.sol +++ b/contracts/protocol/lendingpool/LendingPool.sol @@ -198,7 +198,6 @@ contract LendingPool is VersionedInitializable, ILendingPool, LendingPoolStorage onBehalfOf, amount, interestRateMode, - reserve.aTokenAddress, referralCode, true ) @@ -542,7 +541,6 @@ contract LendingPool is VersionedInitializable, ILendingPool, LendingPoolStorage onBehalfOf, vars.currentAmount, modes[vars.i], - vars.currentATokenAddress, referralCode, false ) @@ -877,7 +875,6 @@ contract LendingPool is VersionedInitializable, ILendingPool, LendingPoolStorage address onBehalfOf; uint256 amount; uint256 interestRateMode; - address aTokenAddress; uint16 referralCode; bool releaseUnderlying; } diff --git a/contracts/protocol/lendingpool/LendingPoolCollateralManager.sol b/contracts/protocol/lendingpool/LendingPoolCollateralManager.sol index 2f823d50..a92045c3 100644 --- a/contracts/protocol/lendingpool/LendingPoolCollateralManager.sol +++ b/contracts/protocol/lendingpool/LendingPoolCollateralManager.sol @@ -166,7 +166,7 @@ contract LendingPoolCollateralManager is debtReserve.updateState(debtReserveCachedData); if (vars.userVariableDebt >= vars.actualDebtToLiquidate) { - IVariableDebtToken(debtReserve.variableDebtTokenAddress).burn( + IVariableDebtToken(debtReserveCachedData.variableDebtTokenAddress).burn( user, vars.actualDebtToLiquidate, debtReserveCachedData.newVariableBorrowIndex diff --git a/contracts/protocol/libraries/helpers/CachingHelper.sol b/contracts/protocol/libraries/helpers/CachingHelper.sol index 8bb739ef..06908ee9 100644 --- a/contracts/protocol/libraries/helpers/CachingHelper.sol +++ b/contracts/protocol/libraries/helpers/CachingHelper.sol @@ -39,18 +39,16 @@ library CachingHelper { { CachedData memory cachedData; + cachedData.reserveConfiguration = reserveData.configuration; cachedData.oldLiquidityIndex = reserveData.liquidityIndex; cachedData.oldVariableBorrowIndex = reserveData.variableBorrowIndex; + cachedData.oldLiquidityRate = reserveData.currentLiquidityRate; + cachedData.oldVariableBorrowRate = reserveData.currentVariableBorrowRate; cachedData.aTokenAddress = reserveData.aTokenAddress; cachedData.stableDebtTokenAddress = reserveData.stableDebtTokenAddress; cachedData.variableDebtTokenAddress = reserveData.variableDebtTokenAddress; - cachedData.reserveConfiguration = reserveData.configuration; - - cachedData.oldLiquidityRate = reserveData.currentLiquidityRate; - cachedData.oldVariableBorrowRate = reserveData.currentVariableBorrowRate; - cachedData.reserveLastUpdateTimestamp = reserveData.lastUpdateTimestamp; cachedData.oldScaledVariableDebt = cachedData.newScaledVariableDebt = IVariableDebtToken( diff --git a/contracts/protocol/libraries/logic/ReserveLogic.sol b/contracts/protocol/libraries/logic/ReserveLogic.sol index 53c56454..ac5ff510 100644 --- a/contracts/protocol/libraries/logic/ReserveLogic.sol +++ b/contracts/protocol/libraries/logic/ReserveLogic.sol @@ -273,17 +273,17 @@ library ReserveLogic { //calculate the stable debt until the last timestamp update vars.cumulatedStableInterest = MathUtils.calculateCompoundedInterest( - vars.avgStableRate, - vars.stableSupplyUpdatedTimestamp, + cachedData.oldAvgStableBorrowRate, + cachedData.stableDebtLastUpdateTimestamp, cachedData.reserveLastUpdateTimestamp ); - vars.previousStableDebt = vars.principalStableDebt.rayMul(vars.cumulatedStableInterest); + vars.previousStableDebt = cachedData.oldPrincipalStableDebt.rayMul(vars.cumulatedStableInterest); //debt accrued is the sum of the current debt minus the sum of the debt at the last update vars.totalDebtAccrued = vars .currentVariableDebt - .add(vars.currentStableDebt) + .add(cachedData.oldTotalStableDebt) .sub(vars.previousVariableDebt) .sub(vars.previousStableDebt);