Merge branch 'fix/79' into 'master'

Resolve "Fix PVE006-2, PVE012, PVE013-1-2-3-4"

Closes #79

See merge request aave-tech/protocol-v2!88
This commit is contained in:
The-3D 2020-10-26 13:14:28 +00:00
commit d694a961b5
4 changed files with 25 additions and 26 deletions

View File

@ -262,15 +262,6 @@ contract LendingPool is VersionedInitializable, ILendingPool, LendingPoolStorage
ReserveLogic.InterestRateMode interestRateMode = ReserveLogic.InterestRateMode(rateMode);
//default to max amount
uint256 paybackAmount = interestRateMode == ReserveLogic.InterestRateMode.STABLE
? stableDebt
: variableDebt;
if (amount < paybackAmount) {
paybackAmount = amount;
}
ValidationLogic.validateRepay(
reserve,
amount,
@ -280,6 +271,15 @@ contract LendingPool is VersionedInitializable, ILendingPool, LendingPoolStorage
variableDebt
);
//default to max amount
uint256 paybackAmount = interestRateMode == ReserveLogic.InterestRateMode.STABLE
? stableDebt
: variableDebt;
if (amount < paybackAmount) {
paybackAmount = amount;
}
reserve.updateState();
//burns an equivalent amount of debt tokens
@ -356,9 +356,10 @@ contract LendingPool is VersionedInitializable, ILendingPool, LendingPoolStorage
}
/**
* @dev rebalances the stable interest rate of a user if current liquidity rate > user stable rate.
* this is regulated by Aave to ensure that the protocol is not abused, and the user is paying a fair
* rate. Anyone can call this function.
* @dev rebalances the stable interest rate of a user. Users can be rebalanced if the following conditions are satisfied:
* 1. Usage ratio is above 95%
* 2. the current deposit APY is below REBALANCE_UP_THRESHOLD * maxVariableBorrowRate, which means that too much has been
* borrowed at a stable rate and depositors are not earning enough.
* @param asset the address of the reserve
* @param user the address of the user to be rebalanced
**/
@ -373,7 +374,7 @@ contract LendingPool is VersionedInitializable, ILendingPool, LendingPoolStorage
uint256 stableBorrowBalance = IERC20(stableDebtToken).balanceOf(user);
//if the utilization rate is below 95%, no rebalances are needed
//if the usage ratio is below 95%, no rebalances are needed
uint256 totalBorrows = stableDebtToken
.totalSupply()
.add(variableDebtToken.totalSupply())
@ -417,7 +418,7 @@ contract LendingPool is VersionedInitializable, ILendingPool, LendingPoolStorage
/**
* @dev allows depositors to enable or disable a specific deposit as collateral.
* @param asset the address of the reserve
* @param useAsCollateral true if the user wants to user the deposit as collateral, false otherwise.
* @param useAsCollateral true if the user wants to use the deposit as collateral, false otherwise.
**/
function setUserUseReserveAsCollateral(address asset, bool useAsCollateral) external override {
_whenNotPaused();

View File

@ -194,13 +194,6 @@ contract LendingPoolCollateralManager is VersionedInitializable, LendingPoolStor
//update the principal reserve
principalReserve.updateState();
principalReserve.updateInterestRates(
principal,
principalReserve.aTokenAddress,
vars.actualAmountToLiquidate,
0
);
if (vars.userVariableDebt >= vars.actualAmountToLiquidate) {
IVariableDebtToken(principalReserve.variableDebtTokenAddress).burn(
user,
@ -223,6 +216,13 @@ contract LendingPoolCollateralManager is VersionedInitializable, LendingPoolStor
);
}
principalReserve.updateInterestRates(
principal,
principalReserve.aTokenAddress,
vars.actualAmountToLiquidate,
0
);
//if liquidator reclaims the aToken, he receives the equivalent atoken amount
if (receiveAToken) {
vars.collateralAtoken.transferOnLiquidation(user, msg.sender, vars.maxCollateralToLiquidate);
@ -306,8 +306,8 @@ contract LendingPoolCollateralManager is VersionedInitializable, LendingPoolStor
.principalCurrencyPrice
.mul(purchaseAmount)
.mul(10**vars.collateralDecimals)
.div(vars.collateralPrice.mul(10**vars.principalDecimals))
.percentMul(vars.liquidationBonus);
.percentMul(vars.liquidationBonus)
.div(vars.collateralPrice.mul(10**vars.principalDecimals));
if (vars.maxAmountCollateralToLiquidate > userCollateralBalance) {
collateralAmount = userCollateralBalance;

View File

@ -25,7 +25,6 @@ library GenericLogic {
using UserConfiguration for UserConfiguration.Map;
uint256 public constant HEALTH_FACTOR_LIQUIDATION_THRESHOLD = 1 ether;
uint256 public constant HEALTH_FACTOR_CRITICAL_THRESHOLD = 0.98 ether;
struct balanceDecreaseAllowedLocalVars {
uint256 decimals;

View File

@ -196,8 +196,7 @@ contract StableDebtToken is IStableDebtToken, DebtTokenBase {
/**
* @dev Calculates the increase in balance since the last user interaction
* @param user The address of the user for which the interest is being accumulated
* @return The previous principal balance, the new principal balance, the balance increase
* and the new user index
* @return The previous principal balance, the new principal balance and the balance increase
**/
function _calculateBalanceIncrease(address user)
internal