mirror of
https://github.com/Instadapp/aave-protocol-v2.git
synced 2024-07-29 21:47:30 +00:00
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:
commit
d694a961b5
|
@ -262,15 +262,6 @@ contract LendingPool is VersionedInitializable, ILendingPool, LendingPoolStorage
|
||||||
|
|
||||||
ReserveLogic.InterestRateMode interestRateMode = ReserveLogic.InterestRateMode(rateMode);
|
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(
|
ValidationLogic.validateRepay(
|
||||||
reserve,
|
reserve,
|
||||||
amount,
|
amount,
|
||||||
|
@ -280,6 +271,15 @@ contract LendingPool is VersionedInitializable, ILendingPool, LendingPoolStorage
|
||||||
variableDebt
|
variableDebt
|
||||||
);
|
);
|
||||||
|
|
||||||
|
//default to max amount
|
||||||
|
uint256 paybackAmount = interestRateMode == ReserveLogic.InterestRateMode.STABLE
|
||||||
|
? stableDebt
|
||||||
|
: variableDebt;
|
||||||
|
|
||||||
|
if (amount < paybackAmount) {
|
||||||
|
paybackAmount = amount;
|
||||||
|
}
|
||||||
|
|
||||||
reserve.updateState();
|
reserve.updateState();
|
||||||
|
|
||||||
//burns an equivalent amount of debt tokens
|
//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.
|
* @dev rebalances the stable interest rate of a user. Users can be rebalanced if the following conditions are satisfied:
|
||||||
* this is regulated by Aave to ensure that the protocol is not abused, and the user is paying a fair
|
* 1. Usage ratio is above 95%
|
||||||
* rate. Anyone can call this function.
|
* 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 asset the address of the reserve
|
||||||
* @param user the address of the user to be rebalanced
|
* @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);
|
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
|
uint256 totalBorrows = stableDebtToken
|
||||||
.totalSupply()
|
.totalSupply()
|
||||||
.add(variableDebtToken.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.
|
* @dev allows depositors to enable or disable a specific deposit as collateral.
|
||||||
* @param asset the address of the reserve
|
* @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 {
|
function setUserUseReserveAsCollateral(address asset, bool useAsCollateral) external override {
|
||||||
_whenNotPaused();
|
_whenNotPaused();
|
||||||
|
|
|
@ -194,13 +194,6 @@ contract LendingPoolCollateralManager is VersionedInitializable, LendingPoolStor
|
||||||
//update the principal reserve
|
//update the principal reserve
|
||||||
principalReserve.updateState();
|
principalReserve.updateState();
|
||||||
|
|
||||||
principalReserve.updateInterestRates(
|
|
||||||
principal,
|
|
||||||
principalReserve.aTokenAddress,
|
|
||||||
vars.actualAmountToLiquidate,
|
|
||||||
0
|
|
||||||
);
|
|
||||||
|
|
||||||
if (vars.userVariableDebt >= vars.actualAmountToLiquidate) {
|
if (vars.userVariableDebt >= vars.actualAmountToLiquidate) {
|
||||||
IVariableDebtToken(principalReserve.variableDebtTokenAddress).burn(
|
IVariableDebtToken(principalReserve.variableDebtTokenAddress).burn(
|
||||||
user,
|
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 liquidator reclaims the aToken, he receives the equivalent atoken amount
|
||||||
if (receiveAToken) {
|
if (receiveAToken) {
|
||||||
vars.collateralAtoken.transferOnLiquidation(user, msg.sender, vars.maxCollateralToLiquidate);
|
vars.collateralAtoken.transferOnLiquidation(user, msg.sender, vars.maxCollateralToLiquidate);
|
||||||
|
@ -306,8 +306,8 @@ contract LendingPoolCollateralManager is VersionedInitializable, LendingPoolStor
|
||||||
.principalCurrencyPrice
|
.principalCurrencyPrice
|
||||||
.mul(purchaseAmount)
|
.mul(purchaseAmount)
|
||||||
.mul(10**vars.collateralDecimals)
|
.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) {
|
if (vars.maxAmountCollateralToLiquidate > userCollateralBalance) {
|
||||||
collateralAmount = userCollateralBalance;
|
collateralAmount = userCollateralBalance;
|
||||||
|
|
|
@ -25,7 +25,6 @@ library GenericLogic {
|
||||||
using UserConfiguration for UserConfiguration.Map;
|
using UserConfiguration for UserConfiguration.Map;
|
||||||
|
|
||||||
uint256 public constant HEALTH_FACTOR_LIQUIDATION_THRESHOLD = 1 ether;
|
uint256 public constant HEALTH_FACTOR_LIQUIDATION_THRESHOLD = 1 ether;
|
||||||
uint256 public constant HEALTH_FACTOR_CRITICAL_THRESHOLD = 0.98 ether;
|
|
||||||
|
|
||||||
struct balanceDecreaseAllowedLocalVars {
|
struct balanceDecreaseAllowedLocalVars {
|
||||||
uint256 decimals;
|
uint256 decimals;
|
||||||
|
|
|
@ -196,8 +196,7 @@ contract StableDebtToken is IStableDebtToken, DebtTokenBase {
|
||||||
/**
|
/**
|
||||||
* @dev Calculates the increase in balance since the last user interaction
|
* @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
|
* @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
|
* @return The previous principal balance, the new principal balance and the balance increase
|
||||||
* and the new user index
|
|
||||||
**/
|
**/
|
||||||
function _calculateBalanceIncrease(address user)
|
function _calculateBalanceIncrease(address user)
|
||||||
internal
|
internal
|
||||||
|
|
Loading…
Reference in New Issue
Block a user