Merge branch 'protocol-2.5' into feat/gas-optimization-3

This commit is contained in:
The3D 2021-05-15 00:28:21 +02:00
commit 7395363e59
8 changed files with 130 additions and 357 deletions

View File

@ -1,163 +1,49 @@
// SPDX-License-Identifier: agpl-3.0 // SPDX-License-Identifier: agpl-3.0
pragma solidity 0.6.12; pragma solidity 0.6.12;
/** /// @title Optimized overflow and underflow safe math operations
* @dev Wrappers over Solidity's arithmetic operations with added overflow /// @notice Contains methods for doing math operations that revert on overflow or underflow for minimal gas cost
* checks.
*
* Arithmetic operations in Solidity wrap on overflow. This can easily result
* in bugs, because programmers usually assume that an overflow raises an
* error, which is the standard behavior in high level programming languages.
* `SafeMath` restores this intuition by reverting the transaction when an
* operation overflows.
*
* Using this library instead of the unchecked operations eliminates an entire
* class of bugs, so it's recommended to use it always.
*/
library SafeMath { library SafeMath {
/** /// @notice Returns x + y, reverts if sum overflows uint256
* @dev Returns the addition of two unsigned integers, reverting on /// @param x The augend
* overflow. /// @param y The addend
* /// @return z The sum of x and y
* Counterpart to Solidity's `+` operator. function add(uint256 x, uint256 y) internal pure returns (uint256 z) {
* require((z = x + y) >= x);
* Requirements:
* - Addition cannot overflow.
*/
function add(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 c = a + b;
require(c >= a, 'SafeMath: addition overflow');
return c;
} }
/** /// @notice Returns x - y, reverts if underflows
* @dev Returns the subtraction of two unsigned integers, reverting on /// @param x The minuend
* overflow (when the result is negative). /// @param y The subtrahend
* /// @return z The difference of x and y
* Counterpart to Solidity's `-` operator. function sub(uint256 x, uint256 y) internal pure returns (uint256 z) {
* require((z = x - y) <= x);
* Requirements:
* - Subtraction cannot overflow.
*/
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
return sub(a, b, 'SafeMath: subtraction overflow');
} }
/** /// @notice Returns x - y, reverts if underflows
* @dev Returns the subtraction of two unsigned integers, reverting with custom message on /// @param x The minuend
* overflow (when the result is negative). /// @param y The subtrahend
* /// @param message The error msg
* Counterpart to Solidity's `-` operator. /// @return z The difference of x and y
* function sub(uint256 x, uint256 y, string memory message) internal pure returns (uint256 z) {
* Requirements: require((z = x - y) <= x, message);
* - Subtraction cannot overflow.
*/
function sub(
uint256 a,
uint256 b,
string memory errorMessage
) internal pure returns (uint256) {
require(b <= a, errorMessage);
uint256 c = a - b;
return c;
} }
/**
* @dev Returns the multiplication of two unsigned integers, reverting on /// @notice Returns x * y, reverts if overflows
* overflow. /// @param x The multiplicand
* /// @param y The multiplier
* Counterpart to Solidity's `*` operator. /// @return z The product of x and y
* function mul(uint256 x, uint256 y) internal pure returns (uint256 z) {
* Requirements: require(x == 0 || (z = x * y) / x == y);
* - Multiplication cannot overflow.
*/
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
// Gas optimization: this is cheaper than requiring 'a' not being zero, but the
// benefit is lost if 'b' is also tested.
// See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522
if (a == 0) {
return 0;
} }
uint256 c = a * b; /// @notice Returns x / y, reverts if overflows - no specific check, solidity reverts on division by 0
require(c / a == b, 'SafeMath: multiplication overflow'); /// @param x The numerator
/// @param y The denominator
return c; /// @return z The product of x and y
function div(uint256 x, uint256 y) internal pure returns (uint256 z) {
return x / y;
} }
/**
* @dev Returns the integer division of two unsigned integers. Reverts on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator. Note: this function uses a
* `revert` opcode (which leaves remaining gas untouched) while Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
* - The divisor cannot be zero.
*/
function div(uint256 a, uint256 b) internal pure returns (uint256) {
return div(a, b, 'SafeMath: division by zero');
}
/**
* @dev Returns the integer division of two unsigned integers. Reverts with custom message on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator. Note: this function uses a
* `revert` opcode (which leaves remaining gas untouched) while Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
* - The divisor cannot be zero.
*/
function div(
uint256 a,
uint256 b,
string memory errorMessage
) internal pure returns (uint256) {
// Solidity only automatically asserts when dividing by 0
require(b > 0, errorMessage);
uint256 c = a / b;
// assert(a == b * c + a % b); // There is no case in which this doesn't hold
return c;
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* Reverts when dividing by zero.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
* - The divisor cannot be zero.
*/
function mod(uint256 a, uint256 b) internal pure returns (uint256) {
return mod(a, b, 'SafeMath: modulo by zero');
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* Reverts with custom message when dividing by zero.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
* - The divisor cannot be zero.
*/
function mod(
uint256 a,
uint256 b,
string memory errorMessage
) internal pure returns (uint256) {
require(b != 0, errorMessage);
return a % b;
}
} }

View File

@ -136,7 +136,15 @@ contract LendingPool is VersionedInitializable, ILendingPool, LendingPoolStorage
bytes32 permitR, bytes32 permitR,
bytes32 permitS bytes32 permitS
) external override { ) external override {
IERC20WithPermit(asset).permit(msg.sender, address(this), amount, deadline, permitV, permitR, permitS); IERC20WithPermit(asset).permit(
msg.sender,
address(this),
amount,
deadline,
permitV,
permitR,
permitS
);
_executeDeposit(asset, amount, onBehalfOf, referralCode); _executeDeposit(asset, amount, onBehalfOf, referralCode);
} }
@ -243,7 +251,15 @@ contract LendingPool is VersionedInitializable, ILendingPool, LendingPoolStorage
bytes32 permitR, bytes32 permitR,
bytes32 permitS bytes32 permitS
) external override returns (uint256) { ) external override returns (uint256) {
IERC20WithPermit(asset).permit(msg.sender, address(this), amount, deadline, permitV, permitR, permitS); IERC20WithPermit(asset).permit(
msg.sender,
address(this),
amount,
deadline,
permitV,
permitR,
permitS
);
return _executeRepay(asset, amount, rateMode, onBehalfOf); return _executeRepay(asset, amount, rateMode, onBehalfOf);
} }
@ -349,10 +365,15 @@ contract LendingPool is VersionedInitializable, ILendingPool, LendingPoolStorage
{ {
DataTypes.ReserveData storage reserve = _reserves[asset]; DataTypes.ReserveData storage reserve = _reserves[asset];
ValidationLogic.validateSetUseReserveAsCollateral( ValidationLogic.validateSetUseReserveAsCollateral(reserve);
reserve,
asset, _usersConfig[msg.sender].setUsingAsCollateral(reserve.id, useAsCollateral);
useAsCollateral,
if (useAsCollateral) {
emit ReserveUsedAsCollateralEnabled(asset, msg.sender);
} else {
ValidationLogic.validateHealthFactor(
msg.sender,
_reserves, _reserves,
_usersConfig[msg.sender], _usersConfig[msg.sender],
_reservesList, _reservesList,
@ -360,11 +381,6 @@ contract LendingPool is VersionedInitializable, ILendingPool, LendingPoolStorage
_addressesProvider.getPriceOracle() _addressesProvider.getPriceOracle()
); );
_usersConfig[msg.sender].setUsingAsCollateral(reserve.id, useAsCollateral);
if (useAsCollateral) {
emit ReserveUsedAsCollateralEnabled(asset, msg.sender);
} else {
emit ReserveUsedAsCollateralDisabled(asset, msg.sender); emit ReserveUsedAsCollateralDisabled(asset, msg.sender);
} }
} }
@ -724,7 +740,14 @@ contract LendingPool is VersionedInitializable, ILendingPool, LendingPoolStorage
) external override whenNotPaused { ) external override whenNotPaused {
require(msg.sender == _reserves[asset].aTokenAddress, Errors.LP_CALLER_MUST_BE_AN_ATOKEN); require(msg.sender == _reserves[asset].aTokenAddress, Errors.LP_CALLER_MUST_BE_AN_ATOKEN);
ValidationLogic.validateTransfer( uint256 reserveId = _reserves[asset].id;
if (from != to) {
DataTypes.UserConfigurationMap storage fromConfig = _usersConfig[from];
if (fromConfig.isUsingAsCollateral(reserveId)) {
if (fromConfig.isBorrowingAny()) {
ValidationLogic.validateHealthFactor(
from, from,
_reserves, _reserves,
_usersConfig[from], _usersConfig[from],
@ -732,15 +755,12 @@ contract LendingPool is VersionedInitializable, ILendingPool, LendingPoolStorage
_reservesCount, _reservesCount,
_addressesProvider.getPriceOracle() _addressesProvider.getPriceOracle()
); );
}
uint256 reserveId = _reserves[asset].id;
if (from != to) {
if (balanceFromBefore.sub(amount) == 0) { if (balanceFromBefore.sub(amount) == 0) {
DataTypes.UserConfigurationMap storage fromConfig = _usersConfig[from];
fromConfig.setUsingAsCollateral(reserveId, false); fromConfig.setUsingAsCollateral(reserveId, false);
emit ReserveUsedAsCollateralDisabled(asset, from); emit ReserveUsedAsCollateralDisabled(asset, from);
} }
}
if (balanceToBefore == 0 && amount != 0) { if (balanceToBefore == 0 && amount != 0) {
DataTypes.UserConfigurationMap storage toConfig = _usersConfig[to]; DataTypes.UserConfigurationMap storage toConfig = _usersConfig[to];
@ -940,10 +960,15 @@ contract LendingPool is VersionedInitializable, ILendingPool, LendingPoolStorage
address to address to
) internal returns (uint256) { ) internal returns (uint256) {
DataTypes.ReserveData storage reserve = _reserves[asset]; DataTypes.ReserveData storage reserve = _reserves[asset];
DataTypes.UserConfigurationMap storage userConfig = _usersConfig[msg.sender];
address aToken = reserve.aTokenAddress; address aToken = reserve.aTokenAddress;
uint256 userBalance = IAToken(aToken).balanceOf(msg.sender); reserve.updateState();
uint256 liquidityIndex = reserve.liquidityIndex;
uint256 userBalance = IAToken(aToken).scaledBalanceOf(msg.sender).rayMul(liquidityIndex);
uint256 amountToWithdraw = amount; uint256 amountToWithdraw = amount;
@ -951,27 +976,29 @@ contract LendingPool is VersionedInitializable, ILendingPool, LendingPoolStorage
amountToWithdraw = userBalance; amountToWithdraw = userBalance;
} }
ValidationLogic.validateWithdraw( ValidationLogic.validateWithdraw(reserve, amountToWithdraw, userBalance);
asset,
amountToWithdraw, reserve.updateInterestRates(asset, aToken, 0, amountToWithdraw);
userBalance,
IAToken(aToken).burn(msg.sender, to, amountToWithdraw, liquidityIndex);
if (userConfig.isUsingAsCollateral(reserve.id)) {
if (userConfig.isBorrowingAny()) {
ValidationLogic.validateHealthFactor(
msg.sender,
_reserves, _reserves,
_usersConfig[msg.sender], userConfig,
_reservesList, _reservesList,
_reservesCount, _reservesCount,
_addressesProvider.getPriceOracle() _addressesProvider.getPriceOracle()
); );
reserve.updateState();
reserve.updateInterestRates(asset, aToken, 0, amountToWithdraw);
if (amountToWithdraw == userBalance) {
_usersConfig[msg.sender].setUsingAsCollateral(reserve.id, false);
emit ReserveUsedAsCollateralDisabled(asset, msg.sender);
} }
IAToken(aToken).burn(msg.sender, to, amountToWithdraw, reserve.liquidityIndex); if (amountToWithdraw == userBalance) {
userConfig.setUsingAsCollateral(reserve.id, false);
emit ReserveUsedAsCollateralDisabled(asset, msg.sender);
}
}
emit Withdraw(asset, msg.sender, to, amountToWithdraw); emit Withdraw(asset, msg.sender, to, amountToWithdraw);

View File

@ -30,7 +30,6 @@ library Errors {
string public constant VL_RESERVE_FROZEN = '3'; // 'Action cannot be performed because the reserve is frozen' string public constant VL_RESERVE_FROZEN = '3'; // 'Action cannot be performed because the reserve is frozen'
string public constant VL_CURRENT_AVAILABLE_LIQUIDITY_NOT_ENOUGH = '4'; // 'The current liquidity is not enough' string public constant VL_CURRENT_AVAILABLE_LIQUIDITY_NOT_ENOUGH = '4'; // 'The current liquidity is not enough'
string public constant VL_NOT_ENOUGH_AVAILABLE_USER_BALANCE = '5'; // 'User cannot withdraw more than the available balance' string public constant VL_NOT_ENOUGH_AVAILABLE_USER_BALANCE = '5'; // 'User cannot withdraw more than the available balance'
string public constant VL_TRANSFER_NOT_ALLOWED = '6'; // 'Transfer cannot be allowed.'
string public constant VL_BORROWING_NOT_ENABLED = '7'; // 'Borrowing is not enabled' string public constant VL_BORROWING_NOT_ENABLED = '7'; // 'Borrowing is not enabled'
string public constant VL_INVALID_INTEREST_RATE_MODE_SELECTED = '8'; // 'Invalid interest rate mode selected' string public constant VL_INVALID_INTEREST_RATE_MODE_SELECTED = '8'; // 'Invalid interest rate mode selected'
string public constant VL_COLLATERAL_BALANCE_IS_0 = '9'; // 'The collateral balance is 0' string public constant VL_COLLATERAL_BALANCE_IS_0 = '9'; // 'The collateral balance is 0'

View File

@ -28,94 +28,6 @@ library GenericLogic {
uint256 public constant HEALTH_FACTOR_LIQUIDATION_THRESHOLD = 1 ether; uint256 public constant HEALTH_FACTOR_LIQUIDATION_THRESHOLD = 1 ether;
struct balanceDecreaseAllowedLocalVars {
uint256 decimals;
uint256 liquidationThreshold;
uint256 totalCollateralInETH;
uint256 totalDebtInETH;
uint256 avgLiquidationThreshold;
uint256 amountToDecreaseInETH;
uint256 collateralBalanceAfterDecrease;
uint256 liquidationThresholdAfterDecrease;
uint256 healthFactorAfterDecrease;
bool reserveUsageAsCollateralEnabled;
}
/**
* @dev Checks if a specific balance decrease is allowed
* (i.e. doesn't bring the user borrow position health factor under HEALTH_FACTOR_LIQUIDATION_THRESHOLD)
* @param asset The address of the underlying asset of the reserve
* @param user The address of the user
* @param amount The amount to decrease
* @param reservesData The data of all the reserves
* @param userConfig The user configuration
* @param reserves The list of all the active reserves
* @param oracle The address of the oracle contract
* @return true if the decrease of the balance is allowed
**/
function balanceDecreaseAllowed(
address asset,
address user,
uint256 amount,
mapping(address => DataTypes.ReserveData) storage reservesData,
DataTypes.UserConfigurationMap calldata userConfig,
mapping(uint256 => address) storage reserves,
uint256 reservesCount,
address oracle
) external view returns (bool) {
if (!userConfig.isBorrowingAny() || !userConfig.isUsingAsCollateral(reservesData[asset].id)) {
return true;
}
balanceDecreaseAllowedLocalVars memory vars;
(, vars.liquidationThreshold, , vars.decimals, ) = reservesData[asset]
.configuration
.getParams();
if (vars.liquidationThreshold == 0) {
return true;
}
(
vars.totalCollateralInETH,
vars.totalDebtInETH,
,
vars.avgLiquidationThreshold,
) = calculateUserAccountData(user, reservesData, userConfig, reserves, reservesCount, oracle);
if (vars.totalDebtInETH == 0) {
return true;
}
vars.amountToDecreaseInETH = IPriceOracleGetter(oracle).getAssetPrice(asset).mul(amount).div(
10**vars.decimals
);
vars.collateralBalanceAfterDecrease = vars.totalCollateralInETH.sub(vars.amountToDecreaseInETH);
//if there is a borrow, there can't be 0 collateral
if (vars.collateralBalanceAfterDecrease == 0) {
return false;
}
vars.liquidationThresholdAfterDecrease = vars
.totalCollateralInETH
.mul(vars.avgLiquidationThreshold)
.sub(vars.amountToDecreaseInETH.mul(vars.liquidationThreshold))
.div(vars.collateralBalanceAfterDecrease);
uint256 healthFactorAfterDecrease =
calculateHealthFactorFromBalances(
vars.collateralBalanceAfterDecrease,
vars.totalDebtInETH,
vars.liquidationThresholdAfterDecrease
);
return healthFactorAfterDecrease >= GenericLogic.HEALTH_FACTOR_LIQUIDATION_THRESHOLD;
}
struct CalculateUserAccountDataVars { struct CalculateUserAccountDataVars {
uint256 assetPrice; uint256 assetPrice;
uint256 assetUnit; uint256 assetUnit;
@ -221,7 +133,6 @@ library GenericLogic {
); );
vars.userDebtETH = vars.assetPrice.mul(vars.userDebt).div(vars.assetUnit); vars.userDebtETH = vars.assetPrice.mul(vars.userDebt).div(vars.assetUnit);
vars.totalDebtInETH = vars.totalDebtInETH.add(vars.userDebtETH); vars.totalDebtInETH = vars.totalDebtInETH.add(vars.userDebtETH);
} }
} }

View File

@ -38,7 +38,7 @@ library ValidationLogic {
* @param reserve The reserve object on which the user is depositing * @param reserve The reserve object on which the user is depositing
* @param amount The amount to be deposited * @param amount The amount to be deposited
*/ */
function validateDeposit(DataTypes.ReserveData storage reserve, uint256 amount) external view { function validateDeposit(DataTypes.ReserveData storage reserve, uint256 amount) internal view {
(bool isActive, bool isFrozen, , ) = reserve.configuration.getFlags(); (bool isActive, bool isFrozen, , ) = reserve.configuration.getFlags();
require(amount != 0, Errors.VL_INVALID_AMOUNT); require(amount != 0, Errors.VL_INVALID_AMOUNT);
@ -46,46 +46,23 @@ library ValidationLogic {
require(!isFrozen, Errors.VL_RESERVE_FROZEN); require(!isFrozen, Errors.VL_RESERVE_FROZEN);
} }
/** /**
* @dev Validates a withdraw action * @dev Validates a withdraw action
* @param reserveAddress The address of the reserve * @param reserve The reserve object
* @param amount The amount to be withdrawn * @param amount The amount to be withdrawn
* @param userBalance The balance of the user * @param userBalance The balance of the user
* @param reservesData The reserves state
* @param userConfig The user configuration
* @param reserves The addresses of the reserves
* @param reservesCount The number of reserves
* @param oracle The price oracle
*/ */
function validateWithdraw( function validateWithdraw(
address reserveAddress, DataTypes.ReserveData storage reserve,
uint256 amount, uint256 amount,
uint256 userBalance, uint256 userBalance
mapping(address => DataTypes.ReserveData) storage reservesData, ) internal view {
DataTypes.UserConfigurationMap storage userConfig,
mapping(uint256 => address) storage reserves,
uint256 reservesCount,
address oracle
) external 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);
(bool isActive, , , ) = reservesData[reserveAddress].configuration.getFlags(); (bool isActive, , , ) = reserve.configuration.getFlags();
require(isActive, Errors.VL_NO_ACTIVE_RESERVE); require(isActive, Errors.VL_NO_ACTIVE_RESERVE);
require(
GenericLogic.balanceDecreaseAllowed(
reserveAddress,
msg.sender,
amount,
reservesData,
userConfig,
reserves,
reservesCount,
oracle
),
Errors.VL_TRANSFER_NOT_ALLOWED
);
} }
struct ValidateBorrowLocalVars { struct ValidateBorrowLocalVars {
@ -130,7 +107,7 @@ library ValidationLogic {
mapping(uint256 => address) storage reserves, mapping(uint256 => address) storage reserves,
uint256 reservesCount, uint256 reservesCount,
address oracle address oracle
) external view { ) internal view {
ValidateBorrowLocalVars memory vars; ValidateBorrowLocalVars memory vars;
(vars.isActive, vars.isFrozen, vars.borrowingEnabled, vars.stableRateBorrowingEnabled) = reserve (vars.isActive, vars.isFrozen, vars.borrowingEnabled, vars.stableRateBorrowingEnabled) = reserve
@ -227,7 +204,7 @@ library ValidationLogic {
address onBehalfOf, address onBehalfOf,
uint256 stableDebt, uint256 stableDebt,
uint256 variableDebt uint256 variableDebt
) external view { ) internal view {
bool isActive = reserve.configuration.getActive(); bool isActive = reserve.configuration.getActive();
require(isActive, Errors.VL_NO_ACTIVE_RESERVE); require(isActive, Errors.VL_NO_ACTIVE_RESERVE);
@ -335,40 +312,13 @@ library ValidationLogic {
/** /**
* @dev Validates the action of setting an asset as collateral * @dev Validates the action of setting an asset as collateral
* @param reserve The state of the reserve that the user is enabling or disabling as collateral * @param reserve The state of the reserve that the user is enabling or disabling as collateral
* @param reserveAddress The address of the reserve
* @param reservesData The data of all the reserves
* @param userConfig The state of the user for the specific reserve
* @param reserves The addresses of all the active reserves
* @param oracle The price oracle
*/ */
function validateSetUseReserveAsCollateral( function validateSetUseReserveAsCollateral(
DataTypes.ReserveData storage reserve, DataTypes.ReserveData storage reserve
address reserveAddress,
bool useAsCollateral,
mapping(address => DataTypes.ReserveData) storage reservesData,
DataTypes.UserConfigurationMap storage userConfig,
mapping(uint256 => address) storage reserves,
uint256 reservesCount,
address oracle
) external view { ) external view {
uint256 underlyingBalance = IERC20(reserve.aTokenAddress).balanceOf(msg.sender); uint256 underlyingBalance = IERC20(reserve.aTokenAddress).balanceOf(msg.sender);
require(underlyingBalance > 0, Errors.VL_UNDERLYING_BALANCE_NOT_GREATER_THAN_0); require(underlyingBalance > 0, Errors.VL_UNDERLYING_BALANCE_NOT_GREATER_THAN_0);
require(
useAsCollateral ||
GenericLogic.balanceDecreaseAllowed(
reserveAddress,
msg.sender,
underlyingBalance,
reservesData,
userConfig,
reserves,
reservesCount,
oracle
),
Errors.VL_DEPOSIT_ALREADY_IN_USE
);
} }
/** /**
@ -436,14 +386,15 @@ library ValidationLogic {
} }
/** /**
* @dev Validates an aToken transfer * @dev Validates the health factor of a user
* @param from The user from which the aTokens are being transferred * @param from The user from which the aTokens are being transferred
* @param reservesData The state of all the reserves * @param reservesData The state of all the reserves
* @param userConfig The state of the user for the specific reserve * @param userConfig The state of the user for the specific reserve
* @param reserves The addresses of all the active reserves * @param reserves The addresses of all the active reserves
* @param reservesCount The number of available reserves
* @param oracle The price oracle * @param oracle The price oracle
*/ */
function validateTransfer( function validateHealthFactor(
address from, address from,
mapping(address => DataTypes.ReserveData) storage reservesData, mapping(address => DataTypes.ReserveData) storage reservesData,
DataTypes.UserConfigurationMap storage userConfig, DataTypes.UserConfigurationMap storage userConfig,
@ -463,7 +414,7 @@ library ValidationLogic {
require( require(
healthFactor >= GenericLogic.HEALTH_FACTOR_LIQUIDATION_THRESHOLD, healthFactor >= GenericLogic.HEALTH_FACTOR_LIQUIDATION_THRESHOLD,
Errors.VL_TRANSFER_NOT_ALLOWED Errors.VL_HEALTH_FACTOR_LOWER_THAN_LIQUIDATION_THRESHOLD
); );
} }
} }

View File

@ -111,7 +111,6 @@ export enum ProtocolErrors {
VL_RESERVE_FROZEN = '3', // 'Action requires an unfrozen reserve' VL_RESERVE_FROZEN = '3', // 'Action requires an unfrozen reserve'
VL_CURRENT_AVAILABLE_LIQUIDITY_NOT_ENOUGH = '4', // 'The current liquidity is not enough' VL_CURRENT_AVAILABLE_LIQUIDITY_NOT_ENOUGH = '4', // 'The current liquidity is not enough'
VL_NOT_ENOUGH_AVAILABLE_USER_BALANCE = '5', // 'User cannot withdraw more than the available balance' VL_NOT_ENOUGH_AVAILABLE_USER_BALANCE = '5', // 'User cannot withdraw more than the available balance'
VL_TRANSFER_NOT_ALLOWED = '6', // 'Transfer cannot be allowed.'
VL_BORROWING_NOT_ENABLED = '7', // 'Borrowing is not enabled' VL_BORROWING_NOT_ENABLED = '7', // 'Borrowing is not enabled'
VL_INVALID_INTEREST_RATE_MODE_SELECTED = '8', // 'Invalid interest rate mode selected' VL_INVALID_INTEREST_RATE_MODE_SELECTED = '8', // 'Invalid interest rate mode selected'
VL_COLLATERAL_BALANCE_IS_0 = '9', // 'The collateral balance is 0' VL_COLLATERAL_BALANCE_IS_0 = '9', // 'The collateral balance is 0'

View File

@ -12,7 +12,7 @@ makeSuite('AToken: Transfer', (testEnv: TestEnv) => {
const { const {
INVALID_FROM_BALANCE_AFTER_TRANSFER, INVALID_FROM_BALANCE_AFTER_TRANSFER,
INVALID_TO_BALANCE_AFTER_TRANSFER, INVALID_TO_BALANCE_AFTER_TRANSFER,
VL_TRANSFER_NOT_ALLOWED, VL_HEALTH_FACTOR_LOWER_THAN_LIQUIDATION_THRESHOLD,
} = ProtocolErrors; } = ProtocolErrors;
it('User 0 deposits 1000 DAI, transfers to user 1', async () => { it('User 0 deposits 1000 DAI, transfers to user 1', async () => {
@ -81,8 +81,8 @@ makeSuite('AToken: Transfer', (testEnv: TestEnv) => {
await expect( await expect(
aDai.connect(users[1].signer).transfer(users[0].address, aDAItoTransfer), aDai.connect(users[1].signer).transfer(users[0].address, aDAItoTransfer),
VL_TRANSFER_NOT_ALLOWED VL_HEALTH_FACTOR_LOWER_THAN_LIQUIDATION_THRESHOLD
).to.be.revertedWith(VL_TRANSFER_NOT_ALLOWED); ).to.be.revertedWith(VL_HEALTH_FACTOR_LOWER_THAN_LIQUIDATION_THRESHOLD);
}); });
it('User 1 tries to transfer a small amount of DAI used as collateral back to user 0', async () => { it('User 1 tries to transfer a small amount of DAI used as collateral back to user 0', async () => {

View File

@ -12,7 +12,7 @@ makeSuite('AToken: Transfer', (testEnv: TestEnv) => {
const { const {
INVALID_FROM_BALANCE_AFTER_TRANSFER, INVALID_FROM_BALANCE_AFTER_TRANSFER,
INVALID_TO_BALANCE_AFTER_TRANSFER, INVALID_TO_BALANCE_AFTER_TRANSFER,
VL_TRANSFER_NOT_ALLOWED, VL_HEALTH_FACTOR_LOWER_THAN_LIQUIDATION_THRESHOLD,
} = ProtocolErrors; } = ProtocolErrors;
it('User 0 deposits 1000 DAI, transfers to user 1', async () => { it('User 0 deposits 1000 DAI, transfers to user 1', async () => {
@ -81,8 +81,8 @@ makeSuite('AToken: Transfer', (testEnv: TestEnv) => {
await expect( await expect(
aDai.connect(users[1].signer).transfer(users[0].address, aDAItoTransfer), aDai.connect(users[1].signer).transfer(users[0].address, aDAItoTransfer),
VL_TRANSFER_NOT_ALLOWED VL_HEALTH_FACTOR_LOWER_THAN_LIQUIDATION_THRESHOLD
).to.be.revertedWith(VL_TRANSFER_NOT_ALLOWED); ).to.be.revertedWith(VL_HEALTH_FACTOR_LOWER_THAN_LIQUIDATION_THRESHOLD);
}); });
it('User 1 tries to transfer a small amount of DAI used as collateral back to user 0', async () => { it('User 1 tries to transfer a small amount of DAI used as collateral back to user 0', async () => {