mirror of
https://github.com/Instadapp/aave-protocol-v2.git
synced 2024-07-29 21:47:30 +00:00
refactor: updated cache field names
This commit is contained in:
parent
86686ef3be
commit
b8fb9e592f
|
@ -289,27 +289,27 @@ contract LendingPool is VersionedInitializable, ILendingPool, LendingPoolStorage
|
||||||
if (interestRateMode == DataTypes.InterestRateMode.STABLE) {
|
if (interestRateMode == DataTypes.InterestRateMode.STABLE) {
|
||||||
IStableDebtToken(reserveCache.stableDebtTokenAddress).burn(msg.sender, stableDebt);
|
IStableDebtToken(reserveCache.stableDebtTokenAddress).burn(msg.sender, stableDebt);
|
||||||
|
|
||||||
reserveCache.newPrincipalStableDebt = reserveCache.newTotalStableDebt = reserveCache
|
reserveCache.nextPrincipalStableDebt = reserveCache.nextTotalStableDebt = reserveCache
|
||||||
.oldTotalStableDebt
|
.currTotalStableDebt
|
||||||
.sub(stableDebt);
|
.sub(stableDebt);
|
||||||
|
|
||||||
IVariableDebtToken(reserveCache.variableDebtTokenAddress).mint(
|
IVariableDebtToken(reserveCache.variableDebtTokenAddress).mint(
|
||||||
msg.sender,
|
msg.sender,
|
||||||
msg.sender,
|
msg.sender,
|
||||||
stableDebt,
|
stableDebt,
|
||||||
reserveCache.newVariableBorrowIndex
|
reserveCache.nextVariableBorrowIndex
|
||||||
);
|
);
|
||||||
reserveCache.newScaledVariableDebt = reserveCache.oldScaledVariableDebt.add(
|
reserveCache.nextScaledVariableDebt = reserveCache.currScaledVariableDebt.add(
|
||||||
stableDebt.rayDiv(reserveCache.newVariableBorrowIndex)
|
stableDebt.rayDiv(reserveCache.nextVariableBorrowIndex)
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
IVariableDebtToken(reserveCache.variableDebtTokenAddress).burn(
|
IVariableDebtToken(reserveCache.variableDebtTokenAddress).burn(
|
||||||
msg.sender,
|
msg.sender,
|
||||||
variableDebt,
|
variableDebt,
|
||||||
reserveCache.newVariableBorrowIndex
|
reserveCache.nextVariableBorrowIndex
|
||||||
);
|
);
|
||||||
reserveCache.newScaledVariableDebt = reserveCache.oldScaledVariableDebt.sub(
|
reserveCache.nextScaledVariableDebt = reserveCache.currScaledVariableDebt.sub(
|
||||||
variableDebt.rayDiv(reserveCache.newVariableBorrowIndex)
|
variableDebt.rayDiv(reserveCache.nextVariableBorrowIndex)
|
||||||
);
|
);
|
||||||
|
|
||||||
IStableDebtToken(reserveCache.stableDebtTokenAddress).mint(
|
IStableDebtToken(reserveCache.stableDebtTokenAddress).mint(
|
||||||
|
@ -319,8 +319,8 @@ contract LendingPool is VersionedInitializable, ILendingPool, LendingPoolStorage
|
||||||
reserve.currentStableBorrowRate
|
reserve.currentStableBorrowRate
|
||||||
);
|
);
|
||||||
|
|
||||||
reserveCache.newPrincipalStableDebt = reserveCache.newTotalStableDebt = reserveCache
|
reserveCache.nextPrincipalStableDebt = reserveCache.nextTotalStableDebt = reserveCache
|
||||||
.oldTotalStableDebt
|
.currTotalStableDebt
|
||||||
.add(stableDebt);
|
.add(stableDebt);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -927,8 +927,8 @@ contract LendingPool is VersionedInitializable, ILendingPool, LendingPoolStorage
|
||||||
currentStableRate
|
currentStableRate
|
||||||
);
|
);
|
||||||
|
|
||||||
reserveCache.newPrincipalStableDebt = reserveCache.newTotalStableDebt = reserveCache
|
reserveCache.nextPrincipalStableDebt = reserveCache.nextTotalStableDebt = reserveCache
|
||||||
.oldTotalStableDebt
|
.currTotalStableDebt
|
||||||
.add(vars.amount);
|
.add(vars.amount);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
@ -936,11 +936,11 @@ contract LendingPool is VersionedInitializable, ILendingPool, LendingPoolStorage
|
||||||
vars.user,
|
vars.user,
|
||||||
vars.onBehalfOf,
|
vars.onBehalfOf,
|
||||||
vars.amount,
|
vars.amount,
|
||||||
reserveCache.newVariableBorrowIndex
|
reserveCache.nextVariableBorrowIndex
|
||||||
);
|
);
|
||||||
|
|
||||||
reserveCache.newScaledVariableDebt = reserveCache.newScaledVariableDebt.add(
|
reserveCache.nextScaledVariableDebt = reserveCache.nextScaledVariableDebt.add(
|
||||||
vars.amount.rayDiv(reserveCache.newVariableBorrowIndex)
|
vars.amount.rayDiv(reserveCache.nextVariableBorrowIndex)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -990,7 +990,7 @@ contract LendingPool is VersionedInitializable, ILendingPool, LendingPoolStorage
|
||||||
IERC20(asset).safeTransferFrom(msg.sender, reserveCache.aTokenAddress, amount);
|
IERC20(asset).safeTransferFrom(msg.sender, reserveCache.aTokenAddress, amount);
|
||||||
|
|
||||||
bool isFirstDeposit =
|
bool isFirstDeposit =
|
||||||
IAToken(reserveCache.aTokenAddress).mint(onBehalfOf, amount, reserveCache.newLiquidityIndex);
|
IAToken(reserveCache.aTokenAddress).mint(onBehalfOf, amount, reserveCache.nextLiquidityIndex);
|
||||||
|
|
||||||
if (isFirstDeposit) {
|
if (isFirstDeposit) {
|
||||||
_usersConfig[onBehalfOf].setUsingAsCollateral(reserve.id, true);
|
_usersConfig[onBehalfOf].setUsingAsCollateral(reserve.id, true);
|
||||||
|
@ -1013,7 +1013,7 @@ contract LendingPool is VersionedInitializable, ILendingPool, LendingPoolStorage
|
||||||
|
|
||||||
uint256 userBalance =
|
uint256 userBalance =
|
||||||
IAToken(reserveCache.aTokenAddress).scaledBalanceOf(msg.sender).rayMul(
|
IAToken(reserveCache.aTokenAddress).scaledBalanceOf(msg.sender).rayMul(
|
||||||
reserveCache.newLiquidityIndex
|
reserveCache.nextLiquidityIndex
|
||||||
);
|
);
|
||||||
|
|
||||||
uint256 amountToWithdraw = amount;
|
uint256 amountToWithdraw = amount;
|
||||||
|
@ -1030,7 +1030,7 @@ contract LendingPool is VersionedInitializable, ILendingPool, LendingPoolStorage
|
||||||
msg.sender,
|
msg.sender,
|
||||||
to,
|
to,
|
||||||
amountToWithdraw,
|
amountToWithdraw,
|
||||||
reserveCache.newLiquidityIndex
|
reserveCache.nextLiquidityIndex
|
||||||
);
|
);
|
||||||
|
|
||||||
if (userConfig.isUsingAsCollateral(reserve.id)) {
|
if (userConfig.isUsingAsCollateral(reserve.id)) {
|
||||||
|
@ -1090,17 +1090,17 @@ contract LendingPool is VersionedInitializable, ILendingPool, LendingPoolStorage
|
||||||
|
|
||||||
if (interestRateMode == DataTypes.InterestRateMode.STABLE) {
|
if (interestRateMode == DataTypes.InterestRateMode.STABLE) {
|
||||||
IStableDebtToken(reserveCache.stableDebtTokenAddress).burn(onBehalfOf, paybackAmount);
|
IStableDebtToken(reserveCache.stableDebtTokenAddress).burn(onBehalfOf, paybackAmount);
|
||||||
reserveCache.newPrincipalStableDebt = reserveCache.newTotalStableDebt = reserveCache
|
reserveCache.nextPrincipalStableDebt = reserveCache.nextTotalStableDebt = reserveCache
|
||||||
.oldTotalStableDebt
|
.currTotalStableDebt
|
||||||
.sub(paybackAmount);
|
.sub(paybackAmount);
|
||||||
} else {
|
} else {
|
||||||
IVariableDebtToken(reserveCache.variableDebtTokenAddress).burn(
|
IVariableDebtToken(reserveCache.variableDebtTokenAddress).burn(
|
||||||
onBehalfOf,
|
onBehalfOf,
|
||||||
paybackAmount,
|
paybackAmount,
|
||||||
reserveCache.newVariableBorrowIndex
|
reserveCache.nextVariableBorrowIndex
|
||||||
);
|
);
|
||||||
reserveCache.newScaledVariableDebt = reserveCache.oldScaledVariableDebt.sub(
|
reserveCache.nextScaledVariableDebt = reserveCache.currScaledVariableDebt.sub(
|
||||||
paybackAmount.rayDiv(reserveCache.newVariableBorrowIndex)
|
paybackAmount.rayDiv(reserveCache.nextVariableBorrowIndex)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -171,10 +171,10 @@ contract LendingPoolCollateralManager is
|
||||||
IVariableDebtToken(debtReserveCache.variableDebtTokenAddress).burn(
|
IVariableDebtToken(debtReserveCache.variableDebtTokenAddress).burn(
|
||||||
user,
|
user,
|
||||||
vars.actualDebtToLiquidate,
|
vars.actualDebtToLiquidate,
|
||||||
debtReserveCache.newVariableBorrowIndex
|
debtReserveCache.nextVariableBorrowIndex
|
||||||
);
|
);
|
||||||
debtReserveCache.newScaledVariableDebt = debtReserveCache.oldScaledVariableDebt.sub(
|
debtReserveCache.nextScaledVariableDebt = debtReserveCache.currScaledVariableDebt.sub(
|
||||||
vars.actualDebtToLiquidate.rayDiv(debtReserveCache.newVariableBorrowIndex)
|
vars.actualDebtToLiquidate.rayDiv(debtReserveCache.nextVariableBorrowIndex)
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
// If the user doesn't have variable debt, no need to try to burn variable debt tokens
|
// If the user doesn't have variable debt, no need to try to burn variable debt tokens
|
||||||
|
@ -182,19 +182,19 @@ contract LendingPoolCollateralManager is
|
||||||
IVariableDebtToken(debtReserveCache.variableDebtTokenAddress).burn(
|
IVariableDebtToken(debtReserveCache.variableDebtTokenAddress).burn(
|
||||||
user,
|
user,
|
||||||
vars.userVariableDebt,
|
vars.userVariableDebt,
|
||||||
debtReserveCache.newVariableBorrowIndex
|
debtReserveCache.nextVariableBorrowIndex
|
||||||
);
|
);
|
||||||
debtReserveCache.newScaledVariableDebt = debtReserveCache
|
debtReserveCache.nextScaledVariableDebt = debtReserveCache
|
||||||
.oldScaledVariableDebt
|
.currScaledVariableDebt
|
||||||
.sub(vars.userVariableDebt.rayDiv(debtReserveCache.newVariableBorrowIndex));
|
.sub(vars.userVariableDebt.rayDiv(debtReserveCache.nextVariableBorrowIndex));
|
||||||
}
|
}
|
||||||
IStableDebtToken(debtReserveCache.stableDebtTokenAddress).burn(
|
IStableDebtToken(debtReserveCache.stableDebtTokenAddress).burn(
|
||||||
user,
|
user,
|
||||||
vars.actualDebtToLiquidate.sub(vars.userVariableDebt)
|
vars.actualDebtToLiquidate.sub(vars.userVariableDebt)
|
||||||
);
|
);
|
||||||
|
|
||||||
debtReserveCache.newPrincipalStableDebt = debtReserveCache
|
debtReserveCache.nextPrincipalStableDebt = debtReserveCache
|
||||||
.newTotalStableDebt = debtReserveCache.oldTotalStableDebt.sub(
|
.nextTotalStableDebt = debtReserveCache.currTotalStableDebt.sub(
|
||||||
vars.actualDebtToLiquidate.sub(vars.userVariableDebt)
|
vars.actualDebtToLiquidate.sub(vars.userVariableDebt)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -186,13 +186,13 @@ library ReserveLogic {
|
||||||
) internal {
|
) internal {
|
||||||
UpdateInterestRatesLocalVars memory vars;
|
UpdateInterestRatesLocalVars memory vars;
|
||||||
|
|
||||||
if (reserveCache.oldTotalStableDebt != reserveCache.newTotalStableDebt) {
|
if (reserveCache.currTotalStableDebt != reserveCache.nextTotalStableDebt) {
|
||||||
reserveCache.newAvgStableBorrowRate = IStableDebtToken(reserveCache.stableDebtTokenAddress)
|
reserveCache.nextAvgStableBorrowRate = IStableDebtToken(reserveCache.stableDebtTokenAddress)
|
||||||
.getAverageStableRate();
|
.getAverageStableRate();
|
||||||
}
|
}
|
||||||
|
|
||||||
reserveCache.newTotalVariableDebt = reserveCache.newScaledVariableDebt.rayMul(
|
reserveCache.nextTotalVariableDebt = reserveCache.nextScaledVariableDebt.rayMul(
|
||||||
reserveCache.newVariableBorrowIndex
|
reserveCache.nextVariableBorrowIndex
|
||||||
);
|
);
|
||||||
|
|
||||||
(
|
(
|
||||||
|
@ -204,9 +204,9 @@ library ReserveLogic {
|
||||||
reserveCache.aTokenAddress,
|
reserveCache.aTokenAddress,
|
||||||
liquidityAdded,
|
liquidityAdded,
|
||||||
liquidityTaken,
|
liquidityTaken,
|
||||||
reserveCache.newTotalStableDebt,
|
reserveCache.nextTotalStableDebt,
|
||||||
reserveCache.newTotalVariableDebt,
|
reserveCache.nextTotalVariableDebt,
|
||||||
reserveCache.newAvgStableBorrowRate,
|
reserveCache.nextAvgStableBorrowRate,
|
||||||
reserveCache.reserveConfiguration.getReserveFactorMemory()
|
reserveCache.reserveConfiguration.getReserveFactorMemory()
|
||||||
);
|
);
|
||||||
require(vars.newLiquidityRate <= type(uint128).max, Errors.RL_LIQUIDITY_RATE_OVERFLOW);
|
require(vars.newLiquidityRate <= type(uint128).max, Errors.RL_LIQUIDITY_RATE_OVERFLOW);
|
||||||
|
@ -222,8 +222,8 @@ library ReserveLogic {
|
||||||
vars.newLiquidityRate,
|
vars.newLiquidityRate,
|
||||||
vars.newStableRate,
|
vars.newStableRate,
|
||||||
vars.newVariableRate,
|
vars.newVariableRate,
|
||||||
reserveCache.newLiquidityIndex,
|
reserveCache.nextLiquidityIndex,
|
||||||
reserveCache.newVariableBorrowIndex
|
reserveCache.nextVariableBorrowIndex
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -260,30 +260,30 @@ library ReserveLogic {
|
||||||
}
|
}
|
||||||
|
|
||||||
//calculate the last principal variable debt
|
//calculate the last principal variable debt
|
||||||
vars.previousVariableDebt = reserveCache.oldScaledVariableDebt.rayMul(
|
vars.previousVariableDebt = reserveCache.currScaledVariableDebt.rayMul(
|
||||||
reserveCache.oldVariableBorrowIndex
|
reserveCache.currVariableBorrowIndex
|
||||||
);
|
);
|
||||||
|
|
||||||
//calculate the new total supply after accumulation of the index
|
//calculate the new total supply after accumulation of the index
|
||||||
vars.currentVariableDebt = reserveCache.oldScaledVariableDebt.rayMul(
|
vars.currentVariableDebt = reserveCache.currScaledVariableDebt.rayMul(
|
||||||
reserveCache.newVariableBorrowIndex
|
reserveCache.nextVariableBorrowIndex
|
||||||
);
|
);
|
||||||
|
|
||||||
//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(
|
||||||
reserveCache.oldAvgStableBorrowRate,
|
reserveCache.currAvgStableBorrowRate,
|
||||||
reserveCache.stableDebtLastUpdateTimestamp,
|
reserveCache.stableDebtLastUpdateTimestamp,
|
||||||
reserveCache.reserveLastUpdateTimestamp
|
reserveCache.reserveLastUpdateTimestamp
|
||||||
);
|
);
|
||||||
|
|
||||||
vars.previousStableDebt = reserveCache.oldPrincipalStableDebt.rayMul(
|
vars.previousStableDebt = reserveCache.currPrincipalStableDebt.rayMul(
|
||||||
vars.cumulatedStableInterest
|
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(reserveCache.oldTotalStableDebt)
|
.add(reserveCache.currTotalStableDebt)
|
||||||
.sub(vars.previousVariableDebt)
|
.sub(vars.previousVariableDebt)
|
||||||
.sub(vars.previousStableDebt);
|
.sub(vars.previousStableDebt);
|
||||||
|
|
||||||
|
@ -291,7 +291,7 @@ library ReserveLogic {
|
||||||
|
|
||||||
if (vars.amountToMint != 0) {
|
if (vars.amountToMint != 0) {
|
||||||
reserve.accruedToTreasury = reserve.accruedToTreasury.add(
|
reserve.accruedToTreasury = reserve.accruedToTreasury.add(
|
||||||
vars.amountToMint.rayDiv(reserveCache.newLiquidityIndex)
|
vars.amountToMint.rayDiv(reserveCache.nextLiquidityIndex)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -305,41 +305,41 @@ library ReserveLogic {
|
||||||
DataTypes.ReserveData storage reserve,
|
DataTypes.ReserveData storage reserve,
|
||||||
DataTypes.ReserveCache memory reserveCache
|
DataTypes.ReserveCache memory reserveCache
|
||||||
) internal {
|
) internal {
|
||||||
reserveCache.newLiquidityIndex = reserveCache.oldLiquidityIndex;
|
reserveCache.nextLiquidityIndex = reserveCache.currLiquidityIndex;
|
||||||
reserveCache.newVariableBorrowIndex = reserveCache.oldVariableBorrowIndex;
|
reserveCache.nextVariableBorrowIndex = reserveCache.currVariableBorrowIndex;
|
||||||
|
|
||||||
//only cumulating if there is any income being produced
|
//only cumulating if there is any income being produced
|
||||||
if (reserveCache.oldLiquidityRate > 0) {
|
if (reserveCache.currLiquidityRate > 0) {
|
||||||
uint256 cumulatedLiquidityInterest =
|
uint256 cumulatedLiquidityInterest =
|
||||||
MathUtils.calculateLinearInterest(
|
MathUtils.calculateLinearInterest(
|
||||||
reserveCache.oldLiquidityRate,
|
reserveCache.currLiquidityRate,
|
||||||
reserveCache.reserveLastUpdateTimestamp
|
reserveCache.reserveLastUpdateTimestamp
|
||||||
);
|
);
|
||||||
reserveCache.newLiquidityIndex = cumulatedLiquidityInterest.rayMul(
|
reserveCache.nextLiquidityIndex = cumulatedLiquidityInterest.rayMul(
|
||||||
reserveCache.oldLiquidityIndex
|
reserveCache.currLiquidityIndex
|
||||||
);
|
);
|
||||||
require(
|
require(
|
||||||
reserveCache.newLiquidityIndex <= type(uint128).max,
|
reserveCache.nextLiquidityIndex <= type(uint128).max,
|
||||||
Errors.RL_LIQUIDITY_INDEX_OVERFLOW
|
Errors.RL_LIQUIDITY_INDEX_OVERFLOW
|
||||||
);
|
);
|
||||||
reserve.liquidityIndex = uint128(reserveCache.newLiquidityIndex);
|
reserve.liquidityIndex = uint128(reserveCache.nextLiquidityIndex);
|
||||||
|
|
||||||
//as the liquidity rate might come only from stable rate loans, we need to ensure
|
//as the liquidity rate might come only from stable rate loans, we need to ensure
|
||||||
//that there is actual variable debt before accumulating
|
//that there is actual variable debt before accumulating
|
||||||
if (reserveCache.oldScaledVariableDebt != 0) {
|
if (reserveCache.currScaledVariableDebt != 0) {
|
||||||
uint256 cumulatedVariableBorrowInterest =
|
uint256 cumulatedVariableBorrowInterest =
|
||||||
MathUtils.calculateCompoundedInterest(
|
MathUtils.calculateCompoundedInterest(
|
||||||
reserveCache.oldVariableBorrowRate,
|
reserveCache.currVariableBorrowRate,
|
||||||
reserveCache.reserveLastUpdateTimestamp
|
reserveCache.reserveLastUpdateTimestamp
|
||||||
);
|
);
|
||||||
reserveCache.newVariableBorrowIndex = cumulatedVariableBorrowInterest.rayMul(
|
reserveCache.nextVariableBorrowIndex = cumulatedVariableBorrowInterest.rayMul(
|
||||||
reserveCache.oldVariableBorrowIndex
|
reserveCache.currVariableBorrowIndex
|
||||||
);
|
);
|
||||||
require(
|
require(
|
||||||
reserveCache.newVariableBorrowIndex <= type(uint128).max,
|
reserveCache.nextVariableBorrowIndex <= type(uint128).max,
|
||||||
Errors.RL_VARIABLE_BORROW_INDEX_OVERFLOW
|
Errors.RL_VARIABLE_BORROW_INDEX_OVERFLOW
|
||||||
);
|
);
|
||||||
reserve.variableBorrowIndex = uint128(reserveCache.newVariableBorrowIndex);
|
reserve.variableBorrowIndex = uint128(reserveCache.nextVariableBorrowIndex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -355,10 +355,10 @@ library ReserveLogic {
|
||||||
DataTypes.ReserveCache memory reserveCache;
|
DataTypes.ReserveCache memory reserveCache;
|
||||||
|
|
||||||
reserveCache.reserveConfiguration = reserve.configuration;
|
reserveCache.reserveConfiguration = reserve.configuration;
|
||||||
reserveCache.oldLiquidityIndex = reserve.liquidityIndex;
|
reserveCache.currLiquidityIndex = reserve.liquidityIndex;
|
||||||
reserveCache.oldVariableBorrowIndex = reserve.variableBorrowIndex;
|
reserveCache.currVariableBorrowIndex = reserve.variableBorrowIndex;
|
||||||
reserveCache.oldLiquidityRate = reserve.currentLiquidityRate;
|
reserveCache.currLiquidityRate = reserve.currentLiquidityRate;
|
||||||
reserveCache.oldVariableBorrowRate = reserve.currentVariableBorrowRate;
|
reserveCache.currVariableBorrowRate = reserve.currentVariableBorrowRate;
|
||||||
|
|
||||||
reserveCache.aTokenAddress = reserve.aTokenAddress;
|
reserveCache.aTokenAddress = reserve.aTokenAddress;
|
||||||
reserveCache.stableDebtTokenAddress = reserve.stableDebtTokenAddress;
|
reserveCache.stableDebtTokenAddress = reserve.stableDebtTokenAddress;
|
||||||
|
@ -366,22 +366,22 @@ library ReserveLogic {
|
||||||
|
|
||||||
reserveCache.reserveLastUpdateTimestamp = reserve.lastUpdateTimestamp;
|
reserveCache.reserveLastUpdateTimestamp = reserve.lastUpdateTimestamp;
|
||||||
|
|
||||||
reserveCache.oldScaledVariableDebt = reserveCache.newScaledVariableDebt = IVariableDebtToken(
|
reserveCache.currScaledVariableDebt = reserveCache.nextScaledVariableDebt = IVariableDebtToken(
|
||||||
reserveCache
|
reserveCache
|
||||||
.variableDebtTokenAddress
|
.variableDebtTokenAddress
|
||||||
)
|
)
|
||||||
.scaledTotalSupply();
|
.scaledTotalSupply();
|
||||||
|
|
||||||
(
|
(
|
||||||
reserveCache.oldPrincipalStableDebt,
|
reserveCache.currPrincipalStableDebt,
|
||||||
reserveCache.oldTotalStableDebt,
|
reserveCache.currTotalStableDebt,
|
||||||
reserveCache.oldAvgStableBorrowRate,
|
reserveCache.currAvgStableBorrowRate,
|
||||||
reserveCache.stableDebtLastUpdateTimestamp
|
reserveCache.stableDebtLastUpdateTimestamp
|
||||||
) = IStableDebtToken(reserveCache.stableDebtTokenAddress).getSupplyData();
|
) = IStableDebtToken(reserveCache.stableDebtTokenAddress).getSupplyData();
|
||||||
|
|
||||||
reserveCache.newPrincipalStableDebt = reserveCache.oldPrincipalStableDebt;
|
reserveCache.nextPrincipalStableDebt = reserveCache.currPrincipalStableDebt;
|
||||||
reserveCache.newTotalStableDebt = reserveCache.oldTotalStableDebt;
|
reserveCache.nextTotalStableDebt = reserveCache.currTotalStableDebt;
|
||||||
reserveCache.newAvgStableBorrowRate = reserveCache.oldAvgStableBorrowRate;
|
reserveCache.nextAvgStableBorrowRate = reserveCache.currAvgStableBorrowRate;
|
||||||
|
|
||||||
return reserveCache;
|
return reserveCache;
|
||||||
}
|
}
|
||||||
|
|
|
@ -60,7 +60,7 @@ library ValidationLogic {
|
||||||
supplyCap == 0 ||
|
supplyCap == 0 ||
|
||||||
IAToken(reserveCache.aTokenAddress)
|
IAToken(reserveCache.aTokenAddress)
|
||||||
.scaledTotalSupply()
|
.scaledTotalSupply()
|
||||||
.rayMul(reserveCache.newLiquidityIndex)
|
.rayMul(reserveCache.nextLiquidityIndex)
|
||||||
.add(amount)
|
.add(amount)
|
||||||
.div(10**reserveDecimals) <
|
.div(10**reserveDecimals) <
|
||||||
supplyCap,
|
supplyCap,
|
||||||
|
@ -79,7 +79,7 @@ library ValidationLogic {
|
||||||
DataTypes.ReserveCache memory reserveCache,
|
DataTypes.ReserveCache memory reserveCache,
|
||||||
uint256 amount,
|
uint256 amount,
|
||||||
uint256 userBalance
|
uint256 userBalance
|
||||||
) external view {
|
) internal view {
|
||||||
require(amount != 0, Errors.VL_INVALID_AMOUNT);
|
require(amount != 0, Errors.VL_INVALID_AMOUNT);
|
||||||
require(amount <= userBalance, Errors.VL_NOT_ENOUGH_AVAILABLE_USER_BALANCE);
|
require(amount <= userBalance, Errors.VL_NOT_ENOUGH_AVAILABLE_USER_BALANCE);
|
||||||
|
|
||||||
|
@ -162,13 +162,13 @@ library ValidationLogic {
|
||||||
|
|
||||||
vars.borrowCap = reserveCache.reserveConfiguration.getBorrowCapMemory();
|
vars.borrowCap = reserveCache.reserveConfiguration.getBorrowCapMemory();
|
||||||
|
|
||||||
if (vars.borrowCap > 0) {
|
if (vars.borrowCap != 0) {
|
||||||
{
|
{
|
||||||
vars.totalSupplyVariableDebt = reserveCache.oldScaledVariableDebt.rayMul(
|
vars.totalSupplyVariableDebt = reserveCache.currScaledVariableDebt.rayMul(
|
||||||
reserveCache.newVariableBorrowIndex
|
reserveCache.nextVariableBorrowIndex
|
||||||
);
|
);
|
||||||
|
|
||||||
vars.totalDebt = reserveCache.oldTotalStableDebt.add(vars.totalSupplyVariableDebt).add(
|
vars.totalDebt = reserveCache.currTotalStableDebt.add(vars.totalSupplyVariableDebt).add(
|
||||||
amount
|
amount
|
||||||
);
|
);
|
||||||
require(
|
require(
|
||||||
|
@ -357,7 +357,7 @@ library ValidationLogic {
|
||||||
//if the liquidity rate is below REBALANCE_UP_THRESHOLD of the max variable APR at 95% usage,
|
//if the liquidity rate is below REBALANCE_UP_THRESHOLD of the max variable APR at 95% usage,
|
||||||
//then we allow rebalancing of the stable rate positions.
|
//then we allow rebalancing of the stable rate positions.
|
||||||
|
|
||||||
uint256 currentLiquidityRate = reserveCache.oldLiquidityRate;
|
uint256 currentLiquidityRate = reserveCache.currLiquidityRate;
|
||||||
uint256 maxVariableBorrowRate =
|
uint256 maxVariableBorrowRate =
|
||||||
IReserveInterestRateStrategy(reserve.interestRateStrategyAddress).getMaxVariableBorrowRate();
|
IReserveInterestRateStrategy(reserve.interestRateStrategyAddress).getMaxVariableBorrowRate();
|
||||||
|
|
||||||
|
|
|
@ -53,22 +53,21 @@ library DataTypes {
|
||||||
enum InterestRateMode {NONE, STABLE, VARIABLE}
|
enum InterestRateMode {NONE, STABLE, VARIABLE}
|
||||||
|
|
||||||
struct ReserveCache {
|
struct ReserveCache {
|
||||||
uint256 oldScaledVariableDebt;
|
uint256 currScaledVariableDebt;
|
||||||
uint256 oldTotalVariableDebt;
|
uint256 nextScaledVariableDebt;
|
||||||
uint256 newScaledVariableDebt;
|
uint256 nextTotalVariableDebt;
|
||||||
uint256 newTotalVariableDebt;
|
uint256 currPrincipalStableDebt;
|
||||||
uint256 oldPrincipalStableDebt;
|
uint256 currAvgStableBorrowRate;
|
||||||
uint256 oldAvgStableBorrowRate;
|
uint256 currTotalStableDebt;
|
||||||
uint256 oldTotalStableDebt;
|
uint256 nextPrincipalStableDebt;
|
||||||
uint256 newPrincipalStableDebt;
|
uint256 nextAvgStableBorrowRate;
|
||||||
uint256 newAvgStableBorrowRate;
|
uint256 nextTotalStableDebt;
|
||||||
uint256 newTotalStableDebt;
|
uint256 currLiquidityIndex;
|
||||||
uint256 oldLiquidityIndex;
|
uint256 nextLiquidityIndex;
|
||||||
uint256 newLiquidityIndex;
|
uint256 currVariableBorrowIndex;
|
||||||
uint256 oldVariableBorrowIndex;
|
uint256 nextVariableBorrowIndex;
|
||||||
uint256 newVariableBorrowIndex;
|
uint256 currLiquidityRate;
|
||||||
uint256 oldLiquidityRate;
|
uint256 currVariableBorrowRate;
|
||||||
uint256 oldVariableBorrowRate;
|
|
||||||
DataTypes.ReserveConfigurationMap reserveConfiguration;
|
DataTypes.ReserveConfigurationMap reserveConfiguration;
|
||||||
address aTokenAddress;
|
address aTokenAddress;
|
||||||
address stableDebtTokenAddress;
|
address stableDebtTokenAddress;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user