From 978f6c93854c35a30d78bbdff458d915c18e7d07 Mon Sep 17 00:00:00 2001 From: emilio Date: Mon, 14 Jun 2021 15:47:13 +0200 Subject: [PATCH] refactor:removed unused/unneeded fields in the cache object --- .../protocol/libraries/logic/ReserveLogic.sol | 23 +++++++------------ .../protocol/libraries/types/DataTypes.sol | 2 -- 2 files changed, 8 insertions(+), 17 deletions(-) diff --git a/contracts/protocol/libraries/logic/ReserveLogic.sol b/contracts/protocol/libraries/logic/ReserveLogic.sol index 91104182..bbcc6fb8 100644 --- a/contracts/protocol/libraries/logic/ReserveLogic.sol +++ b/contracts/protocol/libraries/logic/ReserveLogic.sol @@ -161,9 +161,6 @@ library ReserveLogic { } struct UpdateInterestRatesLocalVars { - address stableDebtTokenAddress; - uint256 availableLiquidity; - uint256 totalStableDebt; uint256 newLiquidityRate; uint256 newStableRate; uint256 newVariableRate; @@ -186,10 +183,9 @@ library ReserveLogic { ) internal { UpdateInterestRatesLocalVars memory vars; - reserveCache.nextTotalVariableDebt = reserveCache.nextScaledVariableDebt.rayMul( + vars.totalVariableDebt = reserveCache.nextScaledVariableDebt.rayMul( reserveCache.nextVariableBorrowIndex ); - ( vars.newLiquidityRate, vars.newStableRate, @@ -200,7 +196,7 @@ library ReserveLogic { liquidityAdded, liquidityTaken, reserveCache.nextTotalStableDebt, - reserveCache.nextTotalVariableDebt, + vars.totalVariableDebt, reserveCache.nextAvgStableBorrowRate, reserveCache.reserveConfiguration.getReserveFactorMemory() ); @@ -252,12 +248,12 @@ library ReserveLogic { return; } - //calculate the last principal variable debt + //calculate the total variable debt at moment of the last interaction vars.prevTotalVariableDebt = reserveCache.currScaledVariableDebt.rayMul( reserveCache.currVariableBorrowIndex ); - //calculate the new total supply after accumulation of the index + //calculate the new total variable debt after accumulation of the interest on the index vars.currTotalVariableDebt = reserveCache.currScaledVariableDebt.rayMul( reserveCache.nextVariableBorrowIndex ); @@ -379,7 +375,6 @@ library ReserveLogic { // by default the actions are considered as not affecting the debt balances. // if the action involves mint/burn of debt, the cache needs to be updated through refreshDebt() - reserveCache.nextPrincipalStableDebt = reserveCache.currPrincipalStableDebt; reserveCache.nextTotalStableDebt = reserveCache.currTotalStableDebt; reserveCache.nextAvgStableBorrowRate = reserveCache.currAvgStableBorrowRate; @@ -404,15 +399,13 @@ library ReserveLogic { ) internal view { if (stableDebtMinted != 0 || stableDebtBurned != 0) { if (cache.currTotalStableDebt.add(stableDebtMinted) > stableDebtBurned) { - cache.nextPrincipalStableDebt = cache.nextTotalStableDebt = cache - .currTotalStableDebt - .add(stableDebtMinted) - .sub(stableDebtBurned); + cache.nextTotalStableDebt = cache.currTotalStableDebt.add(stableDebtMinted).sub( + stableDebtBurned + ); cache.nextAvgStableBorrowRate = IStableDebtToken(cache.stableDebtTokenAddress) .getAverageStableRate(); } else { - cache.nextPrincipalStableDebt = cache.nextTotalStableDebt = cache - .nextAvgStableBorrowRate = 0; + cache.nextTotalStableDebt = cache.nextAvgStableBorrowRate = 0; } } diff --git a/contracts/protocol/libraries/types/DataTypes.sol b/contracts/protocol/libraries/types/DataTypes.sol index 4a2ce981..62cd4de5 100644 --- a/contracts/protocol/libraries/types/DataTypes.sol +++ b/contracts/protocol/libraries/types/DataTypes.sol @@ -55,11 +55,9 @@ library DataTypes { struct ReserveCache { uint256 currScaledVariableDebt; uint256 nextScaledVariableDebt; - uint256 nextTotalVariableDebt; uint256 currPrincipalStableDebt; uint256 currAvgStableBorrowRate; uint256 currTotalStableDebt; - uint256 nextPrincipalStableDebt; uint256 nextAvgStableBorrowRate; uint256 nextTotalStableDebt; uint256 currLiquidityIndex;