refactor:removed unused/unneeded fields in the cache object

This commit is contained in:
emilio 2021-06-14 15:47:13 +02:00
parent 9f71c7da8e
commit 978f6c9385
2 changed files with 8 additions and 17 deletions

View File

@ -161,9 +161,6 @@ library ReserveLogic {
} }
struct UpdateInterestRatesLocalVars { struct UpdateInterestRatesLocalVars {
address stableDebtTokenAddress;
uint256 availableLiquidity;
uint256 totalStableDebt;
uint256 newLiquidityRate; uint256 newLiquidityRate;
uint256 newStableRate; uint256 newStableRate;
uint256 newVariableRate; uint256 newVariableRate;
@ -186,10 +183,9 @@ library ReserveLogic {
) internal { ) internal {
UpdateInterestRatesLocalVars memory vars; UpdateInterestRatesLocalVars memory vars;
reserveCache.nextTotalVariableDebt = reserveCache.nextScaledVariableDebt.rayMul( vars.totalVariableDebt = reserveCache.nextScaledVariableDebt.rayMul(
reserveCache.nextVariableBorrowIndex reserveCache.nextVariableBorrowIndex
); );
( (
vars.newLiquidityRate, vars.newLiquidityRate,
vars.newStableRate, vars.newStableRate,
@ -200,7 +196,7 @@ library ReserveLogic {
liquidityAdded, liquidityAdded,
liquidityTaken, liquidityTaken,
reserveCache.nextTotalStableDebt, reserveCache.nextTotalStableDebt,
reserveCache.nextTotalVariableDebt, vars.totalVariableDebt,
reserveCache.nextAvgStableBorrowRate, reserveCache.nextAvgStableBorrowRate,
reserveCache.reserveConfiguration.getReserveFactorMemory() reserveCache.reserveConfiguration.getReserveFactorMemory()
); );
@ -252,12 +248,12 @@ library ReserveLogic {
return; return;
} }
//calculate the last principal variable debt //calculate the total variable debt at moment of the last interaction
vars.prevTotalVariableDebt = reserveCache.currScaledVariableDebt.rayMul( vars.prevTotalVariableDebt = reserveCache.currScaledVariableDebt.rayMul(
reserveCache.currVariableBorrowIndex 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( vars.currTotalVariableDebt = reserveCache.currScaledVariableDebt.rayMul(
reserveCache.nextVariableBorrowIndex reserveCache.nextVariableBorrowIndex
); );
@ -379,7 +375,6 @@ library ReserveLogic {
// by default the actions are considered as not affecting the debt balances. // 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() // 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.nextTotalStableDebt = reserveCache.currTotalStableDebt;
reserveCache.nextAvgStableBorrowRate = reserveCache.currAvgStableBorrowRate; reserveCache.nextAvgStableBorrowRate = reserveCache.currAvgStableBorrowRate;
@ -404,15 +399,13 @@ library ReserveLogic {
) internal view { ) internal view {
if (stableDebtMinted != 0 || stableDebtBurned != 0) { if (stableDebtMinted != 0 || stableDebtBurned != 0) {
if (cache.currTotalStableDebt.add(stableDebtMinted) > stableDebtBurned) { if (cache.currTotalStableDebt.add(stableDebtMinted) > stableDebtBurned) {
cache.nextPrincipalStableDebt = cache.nextTotalStableDebt = cache cache.nextTotalStableDebt = cache.currTotalStableDebt.add(stableDebtMinted).sub(
.currTotalStableDebt stableDebtBurned
.add(stableDebtMinted) );
.sub(stableDebtBurned);
cache.nextAvgStableBorrowRate = IStableDebtToken(cache.stableDebtTokenAddress) cache.nextAvgStableBorrowRate = IStableDebtToken(cache.stableDebtTokenAddress)
.getAverageStableRate(); .getAverageStableRate();
} else { } else {
cache.nextPrincipalStableDebt = cache.nextTotalStableDebt = cache cache.nextTotalStableDebt = cache.nextAvgStableBorrowRate = 0;
.nextAvgStableBorrowRate = 0;
} }
} }

View File

@ -55,11 +55,9 @@ library DataTypes {
struct ReserveCache { struct ReserveCache {
uint256 currScaledVariableDebt; uint256 currScaledVariableDebt;
uint256 nextScaledVariableDebt; uint256 nextScaledVariableDebt;
uint256 nextTotalVariableDebt;
uint256 currPrincipalStableDebt; uint256 currPrincipalStableDebt;
uint256 currAvgStableBorrowRate; uint256 currAvgStableBorrowRate;
uint256 currTotalStableDebt; uint256 currTotalStableDebt;
uint256 nextPrincipalStableDebt;
uint256 nextAvgStableBorrowRate; uint256 nextAvgStableBorrowRate;
uint256 nextTotalStableDebt; uint256 nextTotalStableDebt;
uint256 currLiquidityIndex; uint256 currLiquidityIndex;