refactor: further refactored the CachingHelper

This commit is contained in:
The3D 2021-06-04 14:47:02 +02:00
parent 360e83fd05
commit 044b492f7f
4 changed files with 8 additions and 13 deletions

View File

@ -198,7 +198,6 @@ contract LendingPool is VersionedInitializable, ILendingPool, LendingPoolStorage
onBehalfOf, onBehalfOf,
amount, amount,
interestRateMode, interestRateMode,
reserve.aTokenAddress,
referralCode, referralCode,
true true
) )
@ -542,7 +541,6 @@ contract LendingPool is VersionedInitializable, ILendingPool, LendingPoolStorage
onBehalfOf, onBehalfOf,
vars.currentAmount, vars.currentAmount,
modes[vars.i], modes[vars.i],
vars.currentATokenAddress,
referralCode, referralCode,
false false
) )
@ -877,7 +875,6 @@ contract LendingPool is VersionedInitializable, ILendingPool, LendingPoolStorage
address onBehalfOf; address onBehalfOf;
uint256 amount; uint256 amount;
uint256 interestRateMode; uint256 interestRateMode;
address aTokenAddress;
uint16 referralCode; uint16 referralCode;
bool releaseUnderlying; bool releaseUnderlying;
} }

View File

@ -166,7 +166,7 @@ contract LendingPoolCollateralManager is
debtReserve.updateState(debtReserveCachedData); debtReserve.updateState(debtReserveCachedData);
if (vars.userVariableDebt >= vars.actualDebtToLiquidate) { if (vars.userVariableDebt >= vars.actualDebtToLiquidate) {
IVariableDebtToken(debtReserve.variableDebtTokenAddress).burn( IVariableDebtToken(debtReserveCachedData.variableDebtTokenAddress).burn(
user, user,
vars.actualDebtToLiquidate, vars.actualDebtToLiquidate,
debtReserveCachedData.newVariableBorrowIndex debtReserveCachedData.newVariableBorrowIndex

View File

@ -39,18 +39,16 @@ library CachingHelper {
{ {
CachedData memory cachedData; CachedData memory cachedData;
cachedData.reserveConfiguration = reserveData.configuration;
cachedData.oldLiquidityIndex = reserveData.liquidityIndex; cachedData.oldLiquidityIndex = reserveData.liquidityIndex;
cachedData.oldVariableBorrowIndex = reserveData.variableBorrowIndex; cachedData.oldVariableBorrowIndex = reserveData.variableBorrowIndex;
cachedData.oldLiquidityRate = reserveData.currentLiquidityRate;
cachedData.oldVariableBorrowRate = reserveData.currentVariableBorrowRate;
cachedData.aTokenAddress = reserveData.aTokenAddress; cachedData.aTokenAddress = reserveData.aTokenAddress;
cachedData.stableDebtTokenAddress = reserveData.stableDebtTokenAddress; cachedData.stableDebtTokenAddress = reserveData.stableDebtTokenAddress;
cachedData.variableDebtTokenAddress = reserveData.variableDebtTokenAddress; cachedData.variableDebtTokenAddress = reserveData.variableDebtTokenAddress;
cachedData.reserveConfiguration = reserveData.configuration;
cachedData.oldLiquidityRate = reserveData.currentLiquidityRate;
cachedData.oldVariableBorrowRate = reserveData.currentVariableBorrowRate;
cachedData.reserveLastUpdateTimestamp = reserveData.lastUpdateTimestamp; cachedData.reserveLastUpdateTimestamp = reserveData.lastUpdateTimestamp;
cachedData.oldScaledVariableDebt = cachedData.newScaledVariableDebt = IVariableDebtToken( cachedData.oldScaledVariableDebt = cachedData.newScaledVariableDebt = IVariableDebtToken(

View File

@ -273,17 +273,17 @@ library ReserveLogic {
//calculate the stable debt until the last timestamp update //calculate the stable debt until the last timestamp update
vars.cumulatedStableInterest = MathUtils.calculateCompoundedInterest( vars.cumulatedStableInterest = MathUtils.calculateCompoundedInterest(
vars.avgStableRate, cachedData.oldAvgStableBorrowRate,
vars.stableSupplyUpdatedTimestamp, cachedData.stableDebtLastUpdateTimestamp,
cachedData.reserveLastUpdateTimestamp 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 //debt accrued is the sum of the current debt minus the sum of the debt at the last update
vars.totalDebtAccrued = vars vars.totalDebtAccrued = vars
.currentVariableDebt .currentVariableDebt
.add(vars.currentStableDebt) .add(cachedData.oldTotalStableDebt)
.sub(vars.previousVariableDebt) .sub(vars.previousVariableDebt)
.sub(vars.previousStableDebt); .sub(vars.previousStableDebt);