Merge branch 'master' into fix/23

This commit is contained in:
emilio 2020-09-03 15:41:36 +02:00
commit db99b6eca6
20 changed files with 301 additions and 183 deletions

View File

@ -3,6 +3,7 @@
"trailingComma": "es5",
"semi": true,
"singleQuote": true,
"tabWidth": 2,
"overrides": [
{
"files": "*.sol",

View File

@ -5,6 +5,7 @@ import {Ownable} from '@openzeppelin/contracts/access/Ownable.sol';
import {
ILendingPoolAddressesProviderRegistry
} from '../interfaces/ILendingPoolAddressesProviderRegistry.sol';
import {Errors} from '../libraries/helpers/Errors.sol';
/**
* @title LendingPoolAddressesProviderRegistry contract
@ -63,7 +64,7 @@ contract LendingPoolAddressesProviderRegistry is Ownable, ILendingPoolAddressesP
* @param provider the pool address to be unregistered
**/
function unregisterAddressesProvider(address provider) external override onlyOwner {
require(addressesProviders[provider] > 0, 'Provider is not registered');
require(addressesProviders[provider] > 0, Errors.PROVIDER_NOT_REGISTERED);
addressesProviders[provider] = 0;
emit AddressesProviderUnregistered(provider);
}

View File

@ -10,6 +10,7 @@ import {
import {ILendingPoolAddressesProvider} from '../interfaces/ILendingPoolAddressesProvider.sol';
import {IAToken} from '../tokenization/interfaces/IAToken.sol';
import {Helpers} from '../libraries/helpers/Helpers.sol';
import {Errors} from '../libraries/helpers/Errors.sol';
import {WadRayMath} from '../libraries/math/WadRayMath.sol';
import {ReserveLogic} from '../libraries/logic/ReserveLogic.sol';
import {GenericLogic} from '../libraries/logic/GenericLogic.sol';
@ -54,7 +55,10 @@ contract LendingPool is VersionedInitializable, ILendingPool {
* @dev only lending pools configurator can use functions affected by this modifier
**/
modifier onlyLendingPoolConfigurator {
require(_addressesProvider.getLendingPoolConfigurator() == msg.sender, '30');
require(
_addressesProvider.getLendingPoolConfigurator() == msg.sender,
Errors.CALLER_NOT_LENDING_POOL_CONFIGURATOR
);
_;
}
@ -295,7 +299,7 @@ contract LendingPool is VersionedInitializable, ILendingPool {
uint256 stableBorrowBalance = IERC20(address(stableDebtToken)).balanceOf(user);
// user must be borrowing on asset at a stable rate
require(stableBorrowBalance > 0, 'User does not have any stable rate loan for this reserve');
require(stableBorrowBalance > 0, Errors.NOT_ENOUGH_STABLE_BORROW_BALANCE);
uint256 rebalanceDownRateThreshold = reserve.currentStableBorrowRate.rayMul(
WadRayMath.ray().add(REBALANCE_DOWN_RATE_DELTA)
@ -310,7 +314,7 @@ contract LendingPool is VersionedInitializable, ILendingPool {
require(
userStableRate < reserve.currentLiquidityRate || userStableRate > rebalanceDownRateThreshold,
'Interest rate rebalance conditions were not met'
Errors.INTEREST_RATE_REBALANCE_CONDITIONS_NOT_MET
);
//burn old debt tokens, mint new ones
@ -382,7 +386,7 @@ contract LendingPool is VersionedInitializable, ILendingPool {
receiveAToken
)
);
require(success, 'Liquidation call failed');
require(success, Errors.LIQUIDATION_CALL_FAILED);
(uint256 returnCode, string memory returnMessage) = abi.decode(result, (uint256, string));

View File

@ -13,6 +13,7 @@ import {ReserveConfiguration} from '../libraries/configuration/ReserveConfigurat
import {ILendingPoolAddressesProvider} from '../interfaces/ILendingPoolAddressesProvider.sol';
import {ILendingPool} from '../interfaces/ILendingPool.sol';
import {IERC20Detailed} from '../interfaces/IERC20Detailed.sol';
import {Errors} from '../libraries/helpers/Errors.sol';
/**
* @title LendingPoolConfigurator contract
@ -178,7 +179,7 @@ contract LendingPoolConfigurator is VersionedInitializable {
modifier onlyLendingPoolManager {
require(
addressesProvider.getLendingPoolManager() == msg.sender,
'The caller must be a lending pool manager'
Errors.CALLER_NOT_LENDING_POOL_MANAGER
);
_;
}
@ -425,7 +426,7 @@ contract LendingPoolConfigurator is VersionedInitializable {
) = pool.getReserveData(asset);
require(
availableLiquidity == 0 && totalBorrowsStable == 0 && totalBorrowsVariable == 0,
'The liquidity of the reserve needs to be 0'
Errors.RESERVE_LIQUIDITY_NOT_0
);
ReserveConfiguration.Map memory currentConfig = pool.getConfiguration(asset);

View File

@ -19,6 +19,7 @@ import {Helpers} from '../libraries/helpers/Helpers.sol';
import {WadRayMath} from '../libraries/math/WadRayMath.sol';
import {PercentageMath} from '../libraries/math/PercentageMath.sol';
import {SafeERC20} from '@openzeppelin/contracts/token/ERC20/SafeERC20.sol';
import {Errors} from '../libraries/helpers/Errors.sol';
/**
* @title LendingPoolLiquidationManager contract
@ -130,7 +131,7 @@ contract LendingPoolLiquidationManager is VersionedInitializable {
if (vars.healthFactor >= GenericLogic.HEALTH_FACTOR_LIQUIDATION_THRESHOLD) {
return (
uint256(LiquidationErrors.HEALTH_FACTOR_ABOVE_THRESHOLD),
'Health factor is not below the threshold'
Errors.HEALTH_FACTOR_NOT_BELOW_THRESHOLD
);
}
@ -146,7 +147,7 @@ contract LendingPoolLiquidationManager is VersionedInitializable {
if (!vars.isCollateralEnabled) {
return (
uint256(LiquidationErrors.COLLATERAL_CANNOT_BE_LIQUIDATED),
'The collateral chosen cannot be liquidated'
Errors.COLLATERAL_CANNOT_BE_LIQUIDATED
);
}
@ -159,7 +160,7 @@ contract LendingPoolLiquidationManager is VersionedInitializable {
if (vars.userStableDebt == 0 && vars.userVariableDebt == 0) {
return (
uint256(LiquidationErrors.CURRRENCY_NOT_BORROWED),
'User did not borrow the specified currency'
Errors.SPECIFIED_CURRENCY_NOT_BORROWED_BY_USER
);
}
@ -200,7 +201,7 @@ contract LendingPoolLiquidationManager is VersionedInitializable {
if (currentAvailableCollateral < vars.maxCollateralToLiquidate) {
return (
uint256(LiquidationErrors.NOT_ENOUGH_LIQUIDITY),
"There isn't enough liquidity available to liquidate"
Errors.NOT_ENOUGH_LIQUIDITY_TO_LIQUIDATE
);
}
}
@ -266,7 +267,7 @@ contract LendingPoolLiquidationManager is VersionedInitializable {
receiveAToken
);
return (uint256(LiquidationErrors.NO_ERROR), 'No errors');
return (uint256(LiquidationErrors.NO_ERROR), Errors.NO_ERRORS);
}
struct AvailableCollateralToLiquidateLocalVars {

View File

@ -0,0 +1,66 @@
// SPDX-License-Identifier: agpl-3.0
pragma solidity ^0.6.8;
/**
* @title Errors library
* @author Aave
* @notice Implements error messages.
*/
library Errors {
// require error messages - ValidationLogic
string public constant AMOUNT_NOT_GREATER_THAN_0 = '1'; // 'Amount must be greater than 0'
string public constant NO_ACTIVE_RESERVE = '2'; // 'Action requires an active reserve'
string public constant NO_UNFREEZED_RESERVE = '3'; // 'Action requires an unfreezed reserve'
string public constant CURRENT_AVAILABLE_LIQUIDITY_NOT_ENOUGH = '4'; // 'The current liquidity is not enough'
string public constant NOT_ENOUGH_AVAILABLE_USER_BALANCE = '5'; // 'User cannot withdraw more than the available balance'
string public constant TRANSFER_NOT_ALLOWED = '6'; // 'Transfer cannot be allowed.'
string public constant BORROWING_NOT_ENABLED = '7'; // 'Borrowing is not enabled'
string public constant INVALID_INTEREST_RATE_MODE_SELECTED = '8'; // 'Invalid interest rate mode selected'
string public constant COLLATERAL_BALANCE_IS_0 = '9'; // 'The collateral balance is 0'
string public constant HEALTH_FACTOR_LOWER_THAN_LIQUIDATION_THRESHOLD = '10'; // 'Health factor is lesser than the liquidation threshold'
string public constant COLLATERAL_CANNOT_COVER_NEW_BORROW = '11'; // 'There is not enough collateral to cover a new borrow'
string public constant STABLE_BORROWING_NOT_ENABLED = '12'; // stable borrowing not enabled
string public constant CALLATERAL_SAME_AS_BORROWING_CURRENCY = '13'; // collateral is (mostly) the same currency that is being borrowed
string public constant AMOUNT_BIGGER_THAN_MAX_LOAN_SIZE_STABLE = '14'; // 'The requested amount is greater than the max loan size in stable rate mode
string public constant NO_DEBT_OF_SELECTED_TYPE = '15'; // 'for repayment of stable debt, the user needs to have stable debt, otherwise, he needs to have variable debt'
string public constant NO_EXPLICIT_AMOUNT_TO_REPAY_ON_BEHALF = '16'; // 'To repay on behalf of an user an explicit amount to repay is needed'
string public constant NO_STABLE_RATE_LOAN_IN_RESERVE = '17'; // 'User does not have a stable rate loan in progress on this reserve'
string public constant NO_VARIABLE_RATE_LOAN_IN_RESERVE = '18'; // 'User does not have a variable rate loan in progress on this reserve'
string public constant UNDERLYING_BALANCE_NOT_GREATER_THAN_0 = '19'; // 'The underlying balance needs to be greater than 0'
string public constant DEPOSIT_ALREADY_IN_USE = '20'; // 'User deposit is already being used as collateral'
// require error messages - LendingPool
string public constant NOT_ENOUGH_STABLE_BORROW_BALANCE = '21'; // 'User does not have any stable rate loan for this reserve'
string public constant INTEREST_RATE_REBALANCE_CONDITIONS_NOT_MET = '22'; // 'Interest rate rebalance conditions were not met'
string public constant LIQUIDATION_CALL_FAILED = '23'; // 'Liquidation call failed'
string public constant NOT_ENOUGH_LIQUIDITY_TO_BORROW = '24'; // 'There is not enough liquidity available to borrow'
string public constant REQUESTED_AMOUNT_TOO_SMALL = '25'; // 'The requested amount is too small for a FlashLoan.'
string public constant INCONSISTENT_PROTOCOL_ACTUAL_BALANCE = '26'; // 'The actual balance of the protocol is inconsistent'
string public constant CALLER_NOT_LENDING_POOL_CONFIGURATOR = '27'; // 'The actual balance of the protocol is inconsistent'
// require error messages - aToken
string public constant CALLER_MUST_BE_LENDING_POOL = '28'; // 'The caller of this function must be a lending pool'
string public constant INTEREST_REDIRECTION_NOT_ALLOWED = '29'; // 'Caller is not allowed to redirect the interest of the user'
string public constant CANNOT_GIVE_ALLOWANCE_TO_HIMSELF = '30'; // 'User cannot give allowance to himself'
string public constant TRANSFER_AMOUNT_NOT_GT_0 = '31'; // 'Transferred amount needs to be greater than zero'
string public constant INTEREST_ALREADY_REDIRECTED = '32'; // 'Interest is already redirected to the user'
string public constant NO_VALID_BALANCE_FOR_REDIRECTION = '33'; // 'Interest stream can only be redirected if there is a valid balance'
// require error messages - ReserveLogic
string public constant RESERVE_ALREADY_INITIALIZED = '34'; // 'Reserve has already been initialized'
//require error messages - LendingPoolConfiguration
string public constant CALLER_NOT_LENDING_POOL_MANAGER = '35'; // 'The caller must be a lending pool manager'
string public constant RESERVE_LIQUIDITY_NOT_0 = '36'; // 'The liquidity of the reserve needs to be 0'
//require error messages - LendingPoolAddressesProviderRegistry
string public constant PROVIDER_NOT_REGISTERED = '37'; // 'Provider is not registered'
//return error messages - LendingPoolLiquidationManager
string public constant HEALTH_FACTOR_NOT_BELOW_THRESHOLD = '38'; // 'Health factor is not below the threshold'
string public constant COLLATERAL_CANNOT_BE_LIQUIDATED = '39'; // 'The collateral chosen cannot be liquidated'
string public constant SPECIFIED_CURRENCY_NOT_BORROWED_BY_USER = '40'; // 'User did not borrow the specified currency'
string public constant NOT_ENOUGH_LIQUIDITY_TO_LIQUIDATE = '41'; // "There isn't enough liquidity available to liquidate"
string public constant NO_ERRORS = '42'; // 'No errors'
string public constant INVALID_FLASHLOAN_MODE = '43'; //Invalid flashloan mode selected
}

View File

@ -10,6 +10,7 @@ import {IStableDebtToken} from '../../tokenization/interfaces/IStableDebtToken.s
import {ReserveConfiguration} from '../configuration/ReserveConfiguration.sol';
import {IReserveInterestRateStrategy} from '../../interfaces/IReserveInterestRateStrategy.sol';
import {WadRayMath} from '../math/WadRayMath.sol';
import {Errors} from '../helpers/Errors.sol';
/**
* @title ReserveLogic library
@ -180,7 +181,7 @@ library ReserveLogic {
address variableDebtTokenAddress,
address interestRateStrategyAddress
) external {
require(reserve.aTokenAddress == address(0), 'Reserve has already been initialized');
require(reserve.aTokenAddress == address(0), Errors.RESERVE_ALREADY_INITIALIZED);
if (reserve.lastLiquidityIndex == 0) {
//if the reserve has not been initialized yet
reserve.lastLiquidityIndex = WadRayMath.ray();

View File

@ -12,6 +12,7 @@ import {SafeERC20} from '@openzeppelin/contracts/token/ERC20/SafeERC20.sol';
import {ReserveConfiguration} from '../configuration/ReserveConfiguration.sol';
import {UserConfiguration} from '../configuration/UserConfiguration.sol';
import {IPriceOracleGetter} from '../../interfaces/IPriceOracleGetter.sol';
import {Errors} from '../helpers/Errors.sol';
/**
* @title ReserveLogic library
@ -32,15 +33,12 @@ library ValidationLogic {
* @param reserve the reserve state on which the user is depositing
* @param amount the amount to be deposited
*/
function validateDeposit(ReserveLogic.ReserveData storage reserve, uint256 amount)
internal
view
{
function validateDeposit(ReserveLogic.ReserveData storage reserve, uint256 amount) internal view {
(bool isActive, bool isFreezed, , ) = reserve.configuration.getFlags();
require(amount > 0, 'Amount must be greater than 0');
require(isActive, 'Action requires an active reserve');
require(!isFreezed, 'Action requires an unfreezed reserve');
require(amount > 0, Errors.AMOUNT_NOT_GREATER_THAN_0);
require(isActive, Errors.NO_ACTIVE_RESERVE);
require(!isFreezed, Errors.NO_UNFREEZED_RESERVE);
}
/**
@ -60,9 +58,9 @@ library ValidationLogic {
address[] calldata reserves,
address oracle
) external view {
require(amount > 0, 'Amount must be greater than 0');
require(amount > 0, Errors.AMOUNT_NOT_GREATER_THAN_0);
require(amount <= userBalance, 'User cannot withdraw more than the available balance');
require(amount <= userBalance, Errors.NOT_ENOUGH_AVAILABLE_USER_BALANCE);
require(
GenericLogic.balanceDecreaseAllowed(
@ -74,7 +72,7 @@ library ValidationLogic {
reserves,
oracle
),
'Transfer cannot be allowed.'
Errors.TRANSFER_NOT_ALLOWED
);
}
@ -134,16 +132,16 @@ library ValidationLogic {
vars.stableRateBorrowingEnabled
) = reserve.configuration.getFlags();
require(vars.isActive, 'Action requires an active reserve');
require(!vars.isFreezed, 'Action requires an unfreezed reserve');
require(vars.isActive, Errors.NO_ACTIVE_RESERVE);
require(!vars.isFreezed, Errors.NO_UNFREEZED_RESERVE);
require(vars.borrowingEnabled, '5');
require(vars.borrowingEnabled, Errors.BORROWING_NOT_ENABLED);
//validate interest rate mode
require(
uint256(ReserveLogic.InterestRateMode.VARIABLE) == interestRateMode ||
uint256(ReserveLogic.InterestRateMode.STABLE) == interestRateMode,
'Invalid interest rate mode selected'
Errors.INVALID_INTEREST_RATE_MODE_SELECTED
);
(
@ -160,9 +158,12 @@ library ValidationLogic {
oracle
);
require(vars.userCollateralBalanceETH > 0, 'The collateral balance is 0');
require(vars.userCollateralBalanceETH > 0, Errors.COLLATERAL_BALANCE_IS_0);
require(vars.healthFactor > GenericLogic.HEALTH_FACTOR_LIQUIDATION_THRESHOLD, '8');
require(
vars.healthFactor > GenericLogic.HEALTH_FACTOR_LIQUIDATION_THRESHOLD,
Errors.HEALTH_FACTOR_LOWER_THAN_LIQUIDATION_THRESHOLD
);
//add the current already borrowed amount to the amount requested to calculate the total collateral needed.
vars.amountOfCollateralNeededETH = vars.userBorrowBalanceETH.add(amountInETH).percentDiv(
@ -171,7 +172,7 @@ library ValidationLogic {
require(
vars.amountOfCollateralNeededETH <= vars.userCollateralBalanceETH,
'There is not enough collateral to cover a new borrow'
Errors.COLLATERAL_CANNOT_COVER_NEW_BORROW
);
/**
@ -186,20 +187,20 @@ library ValidationLogic {
if (vars.rateMode == ReserveLogic.InterestRateMode.STABLE) {
//check if the borrow mode is stable and if stable rate borrowing is enabled on this reserve
require(vars.stableRateBorrowingEnabled, '11');
require(vars.stableRateBorrowingEnabled, Errors.STABLE_BORROWING_NOT_ENABLED);
require(
!userConfig.isUsingAsCollateral(reserve.index) ||
reserve.configuration.getLtv() == 0 ||
amount > IERC20(reserve.aTokenAddress).balanceOf(msg.sender),
'12'
Errors.CALLATERAL_SAME_AS_BORROWING_CURRENCY
);
//calculate the max available loan size in stable rate mode as a percentage of the
//available liquidity
uint256 maxLoanSizeStable = vars.availableLiquidity.percentMul(maxStableLoanPercent);
require(amount <= maxLoanSizeStable, '13');
require(amount <= maxLoanSizeStable, Errors.AMOUNT_BIGGER_THAN_MAX_LOAN_SIZE_STABLE);
}
}
@ -221,21 +222,21 @@ library ValidationLogic {
) external view {
bool isActive = reserve.configuration.getActive();
require(isActive, 'Action requires an active reserve');
require(isActive, Errors.NO_ACTIVE_RESERVE);
require(amountSent > 0, 'Amount must be greater than 0');
require(amountSent > 0, Errors.AMOUNT_NOT_GREATER_THAN_0);
require(
(stableDebt > 0 &&
ReserveLogic.InterestRateMode(rateMode) == ReserveLogic.InterestRateMode.STABLE) ||
(variableDebt > 0 &&
ReserveLogic.InterestRateMode(rateMode) == ReserveLogic.InterestRateMode.VARIABLE),
'16'
Errors.NO_DEBT_OF_SELECTED_TYPE
);
require(
amountSent != uint256(-1) || msg.sender == onBehalfOf,
'To repay on behalf of an user an explicit amount to repay is needed'
Errors.NO_EXPLICIT_AMOUNT_TO_REPAY_ON_BEHALF
);
}
@ -256,19 +257,13 @@ library ValidationLogic {
) external view {
(bool isActive, bool isFreezed, , bool stableRateEnabled) = reserve.configuration.getFlags();
require(isActive, 'Action requires an active reserve');
require(!isFreezed, 'Action requires an unfreezed reserve');
require(isActive, Errors.NO_ACTIVE_RESERVE);
require(!isFreezed, Errors.NO_UNFREEZED_RESERVE);
if (currentRateMode == ReserveLogic.InterestRateMode.STABLE) {
require(
stableBorrowBalance > 0,
'User does not have a stable rate loan in progress on this reserve'
);
require(stableBorrowBalance > 0, Errors.NO_STABLE_RATE_LOAN_IN_RESERVE);
} else if (currentRateMode == ReserveLogic.InterestRateMode.VARIABLE) {
require(
variableBorrowBalance > 0,
'User does not have a variable rate loan in progress on this reserve'
);
require(variableBorrowBalance > 0, Errors.NO_VARIABLE_RATE_LOAN_IN_RESERVE);
/**
* user wants to swap to stable, before swapping we need to ensure that
* 1. stable borrow rate is enabled on the reserve
@ -276,17 +271,17 @@ library ValidationLogic {
* more collateral than he is borrowing, artificially lowering
* the interest rate, borrowing at variable, and switching to stable
**/
require(stableRateEnabled, '11');
require(stableRateEnabled, Errors.STABLE_BORROWING_NOT_ENABLED);
require(
!userConfig.isUsingAsCollateral(reserve.index) ||
reserve.configuration.getLtv() == 0 ||
stableBorrowBalance.add(variableBorrowBalance) >
IERC20(reserve.aTokenAddress).balanceOf(msg.sender),
'12'
Errors.CALLATERAL_SAME_AS_BORROWING_CURRENCY
);
} else {
revert('Invalid interest rate mode selected');
revert(Errors.INVALID_INTEREST_RATE_MODE_SELECTED);
}
}
@ -309,7 +304,7 @@ library ValidationLogic {
) external view {
uint256 underlyingBalance = IERC20(reserve.aTokenAddress).balanceOf(msg.sender);
require(underlyingBalance > 0, '22');
require(underlyingBalance > 0, Errors.UNDERLYING_BALANCE_NOT_GREATER_THAN_0);
require(
GenericLogic.balanceDecreaseAllowed(
@ -321,7 +316,7 @@ library ValidationLogic {
reserves,
oracle
),
'User deposit is already being used as collateral'
Errors.DEPOSIT_ALREADY_IN_USE
);
}
@ -331,7 +326,7 @@ library ValidationLogic {
* @param premium the premium paid on the flashloan
**/
function validateFlashloan(ReserveLogic.InterestRateMode mode, uint256 premium) internal pure {
require(premium > 0, 'The requested amount is too small for a FlashLoan.');
require(mode <= ReserveLogic.InterestRateMode.VARIABLE, 'Invalid flashloan mode selected');
require(premium > 0, Errors.REQUESTED_AMOUNT_TOO_SMALL);
require(mode <= ReserveLogic.InterestRateMode.VARIABLE, Errors.INVALID_FLASHLOAN_MODE);
}
}

View File

@ -4,6 +4,7 @@ pragma solidity ^0.6.8;
import {ERC20} from './ERC20.sol';
import {LendingPool} from '../lendingpool/LendingPool.sol';
import {WadRayMath} from '../libraries/math/WadRayMath.sol';
import {Errors} from '../libraries/helpers/Errors.sol';
import {SafeERC20} from '@openzeppelin/contracts/token/ERC20/SafeERC20.sol';
import {
VersionedInitializable
@ -34,12 +35,12 @@ contract AToken is VersionedInitializable, ERC20, IAToken {
uint256 public constant ATOKEN_REVISION = 0x1;
modifier onlyLendingPool {
require(msg.sender == address(_pool), 'The caller of this function must be a lending pool');
require(msg.sender == address(_pool), Errors.CALLER_MUST_BE_LENDING_POOL);
_;
}
modifier whenTransferAllowed(address from, uint256 amount) {
require(isTransferAllowed(from, amount), 'Transfer cannot be allowed.');
require(isTransferAllowed(from, amount), Errors.TRANSFER_NOT_ALLOWED);
_;
}
@ -100,7 +101,7 @@ contract AToken is VersionedInitializable, ERC20, IAToken {
function redirectInterestStreamOf(address from, address to) external override {
require(
msg.sender == _interestRedirectionAllowances[from],
'Caller is not allowed to redirect the interest of the user'
Errors.INTEREST_REDIRECTION_NOT_ALLOWED
);
_redirectInterestStream(from, to);
}
@ -112,7 +113,7 @@ contract AToken is VersionedInitializable, ERC20, IAToken {
* the allowance.
**/
function allowInterestRedirectionTo(address to) external override {
require(to != msg.sender, 'User cannot give allowance to himself');
require(to != msg.sender, Errors.CANNOT_GIVE_ALLOWANCE_TO_HIMSELF);
_interestRedirectionAllowances[msg.sender] = to;
emit InterestRedirectionAllowanceChanged(msg.sender, to);
}
@ -434,15 +435,12 @@ contract AToken is VersionedInitializable, ERC20, IAToken {
address to,
uint256 value
) internal {
require(value > 0, 'Transferred amount needs to be greater than zero');
require(value > 0, Errors.TRANSFER_AMOUNT_NOT_GT_0);
//cumulate the balance of the sender
(
,
uint256 fromBalance,
uint256 fromBalanceIncrease,
uint256 fromIndex
) = _cumulateBalance(from);
(, uint256 fromBalance, uint256 fromBalanceIncrease, uint256 fromIndex) = _cumulateBalance(
from
);
//cumulate the balance of the receiver
(, , uint256 toBalanceIncrease, uint256 toIndex) = _cumulateBalance(to);
@ -486,7 +484,7 @@ contract AToken is VersionedInitializable, ERC20, IAToken {
function _redirectInterestStream(address from, address to) internal {
address currentRedirectionAddress = _interestRedirectionAddresses[from];
require(to != currentRedirectionAddress, 'Interest is already redirected to the user');
require(to != currentRedirectionAddress, Errors.INTEREST_ALREADY_REDIRECTED);
//accumulates the accrued interest to the principal
(
@ -496,7 +494,7 @@ contract AToken is VersionedInitializable, ERC20, IAToken {
uint256 fromIndex
) = _cumulateBalance(from);
require(fromBalance > 0, 'Interest stream can only be redirected if there is a valid balance');
require(fromBalance > 0, Errors.NO_VALID_BALANCE_FOR_REDIRECTION);
//if the user is already redirecting the interest to someone, before changing
//the redirection address we substract the redirected balance of the previous

View File

@ -9,6 +9,7 @@ import {
VersionedInitializable
} from '../../libraries/openzeppelin-upgradeability/VersionedInitializable.sol';
import {IERC20Detailed} from '../../interfaces/IERC20Detailed.sol';
import {Errors} from '../../libraries/helpers/Errors.sol';
/**
* @title contract DebtTokenBase
@ -33,7 +34,7 @@ abstract contract DebtTokenBase is IERC20Detailed, VersionedInitializable {
* @dev only lending pool can call functions marked by this modifier
**/
modifier onlyLendingPool {
require(msg.sender == address(_pool), 'The caller of this function must be a lending pool');
require(msg.sender == address(_pool), Errors.CALLER_MUST_BE_LENDING_POOL);
_;
}

View File

@ -44,26 +44,72 @@ export enum eContractid {
}
export enum ProtocolErrors {
INVALID_CONFIGURATOR_CALLER_MSG = 'The caller must be a lending pool configurator contract',
INVALID_POOL_CALLER_MSG = 'The caller must be a lending pool contract',
INVALID_POOL_CALLER_MSG_1 = 'The caller of this function must be a lending pool',
INVALID_POOL_MANAGER_CALLER_MSG = 'The caller must be a lending pool manager',
// require error messages - ValidationLogic
AMOUNT_NOT_GREATER_THAN_0 = '1', // 'Amount must be greater than 0'
NO_ACTIVE_RESERVE = '2', // 'Action requires an active reserve'
NO_UNFREEZED_RESERVE = '3', // 'Action requires an unfreezed reserve'
CURRENT_AVAILABLE_LIQUIDITY_NOT_ENOUGH = '4', // 'The current liquidity is not enough'
NOT_ENOUGH_AVAILABLE_USER_BALANCE = '5', // 'User cannot withdraw more than the available balance'
TRANSFER_NOT_ALLOWED = '6', // 'Transfer cannot be allowed.'
BORROWING_NOT_ENABLED = '7', // 'Borrowing is not enabled'
INVALID_INTEREST_RATE_MODE_SELECTED = '8', // 'Invalid interest rate mode selected'
COLLATERAL_BALANCE_IS_0 = '9', // 'The collateral balance is 0'
HEALTH_FACTOR_LOWER_THAN_LIQUIDATION_THRESHOLD = '10', // 'Health factor is lesser than the liquidation threshold'
COLLATERAL_CANNOT_COVER_NEW_BORROW = '11', // 'There is not enough collateral to cover a new borrow'
STABLE_BORROWING_NOT_ENABLED = '12', // stable borrowing not enabled
CALLATERAL_SAME_AS_BORROWING_CURRENCY = '13', // collateral is (mostly) the same currency that is being borrowed
AMOUNT_BIGGER_THAN_MAX_LOAN_SIZE_STABLE = '14', // 'The requested amount is greater than the max loan size in stable rate mode
NO_DEBT_OF_SELECTED_TYPE = '15', // 'for repayment of stable debt, the user needs to have stable debt, otherwise, he needs to have variable debt'
NO_EXPLICIT_AMOUNT_TO_REPAY_ON_BEHALF = '16', // 'To repay on behalf of an user an explicit amount to repay is needed'
NO_STABLE_RATE_LOAN_IN_RESERVE = '17', // 'User does not have a stable rate loan in progress on this reserve'
NO_VARIABLE_RATE_LOAN_IN_RESERVE = '18', // 'User does not have a variable rate loan in progress on this reserve'
UNDERLYING_BALANCE_NOT_GREATER_THAN_0 = '19', // 'The underlying balance needs to be greater than 0'
DEPOSIT_ALREADY_IN_USE = '20', // 'User deposit is already being used as collateral'
// require error messages - LendingPool
NOT_ENOUGH_STABLE_BORROW_BALANCE = '21', // 'User does not have any stable rate loan for this reserve'
INTEREST_RATE_REBALANCE_CONDITIONS_NOT_MET = '22', // 'Interest rate rebalance conditions were not met'
LIQUIDATION_CALL_FAILED = '23', // 'Liquidation call failed'
NOT_ENOUGH_LIQUIDITY_TO_BORROW = '24', // 'There is not enough liquidity available to borrow'
REQUESTED_AMOUNT_TOO_SMALL = '25', // 'The requested amount is too small for a FlashLoan.'
INCONSISTENT_PROTOCOL_ACTUAL_BALANCE = '26', // 'The actual balance of the protocol is inconsistent'
CALLER_NOT_LENDING_POOL_CONFIGURATOR = '27', // 'The actual balance of the protocol is inconsistent'
// require error messages - aToken
CALLER_MUST_BE_LENDING_POOL = '28', // 'The caller of this function must be a lending pool'
INTEREST_REDIRECTION_NOT_ALLOWED = '29', // 'Caller is not allowed to redirect the interest of the user'
CANNOT_GIVE_ALLOWANCE_TO_HIMSELF = '30', // 'User cannot give allowance to himself'
TRANSFER_AMOUNT_NOT_GT_0 = '31', // 'Transferred amount needs to be greater than zero'
INTEREST_ALREADY_REDIRECTED = '32', // 'Interest is already redirected to the user'
NO_VALID_BALANCE_FOR_REDIRECTION = '33', // 'Interest stream can only be redirected if there is a valid balance'
// require error messages - ReserveLogic
RESERVE_ALREADY_INITIALIZED = '34', // 'Reserve has already been initialized'
//require error messages - LendingPoolConfiguration
CALLER_NOT_LENDING_POOL_MANAGER = '35', // 'The caller must be a lending pool manager'
RESERVE_LIQUIDITY_NOT_0 = '36', // 'The liquidity of the reserve needs to be 0'
//require error messages - LendingPoolAddressesProviderRegistry
PROVIDER_NOT_REGISTERED = '37', // 'Provider is not registered'
//return error messages - LendingPoolLiquidationManager
HEALTH_FACTOR_NOT_BELOW_THRESHOLD = '38', // 'Health factor is not below the threshold'
COLLATERAL_CANNOT_BE_LIQUIDATED = '39', // 'The collateral chosen cannot be liquidated'
SPECIFIED_CURRENCY_NOT_BORROWED_BY_USER = '40', // 'User did not borrow the specified currency'
NOT_ENOUGH_LIQUIDITY_TO_LIQUIDATE = '41', // "There isn't enough liquidity available to liquidate"
NO_ERRORS = '42', // 'No errors'
// old
INVALID_FROM_BALANCE_AFTER_TRANSFER = 'Invalid from balance after transfer',
INVALID_TO_BALANCE_AFTER_TRANSFER = 'Invalid from balance after transfer',
INVALID_OWNER_REVERT_MSG = 'Ownable: caller is not the owner',
INVALID_REDIRECTED_BALANCE_BEFORE_TRANSFER = 'Invalid redirected balance before transfer',
INVALID_REDIRECTED_BALANCE_AFTER_TRANSFER = 'Invalid redirected balance after transfer',
INVALID_REDIRECTION_ADDRESS = 'Invalid redirection address',
TRANSFERRED_AMOUNT_GT_ZERO = 'Transferred amount needs to be greater than zero',
ZERO_COLLATERAL = 'The collateral balance is 0',
TRANSFER_AMOUNT_EXCEEDS_BALANCE = 'ERC20: transfer amount exceeds balance',
TOO_SMALL_FLASH_LOAN = 'The requested amount is too small for a FlashLoan.',
NOT_ENOUGH_LIQUIDITY_TO_BORROW = 'There is not enough liquidity available to borrow',
HF_IS_NOT_BELLOW_THRESHOLD = 'Health factor is not below the threshold',
INVALID_HF = 'Invalid health factor',
USER_DID_NOT_BORROW_SPECIFIED = 'User did not borrow the specified currency',
THE_COLLATERAL_CHOSEN_CANNOT_BE_LIQUIDATED = 'The collateral chosen cannot be liquidated',
COLLATERAL_BALANCE_IS_0 = 'The collateral balance is 0'
TRANSFER_AMOUNT_EXCEEDS_BALANCE = 'ERC20: transfer amount exceeds balance'
}
export type tEthereumAddress = string;

View File

@ -3,17 +3,17 @@ import {makeSuite, TestEnv} from './helpers/make-suite';
import {ProtocolErrors} from '../helpers/types';
makeSuite('AToken: Modifiers', (testEnv: TestEnv) => {
const {INVALID_POOL_CALLER_MSG_1} = ProtocolErrors;
const {CALLER_MUST_BE_LENDING_POOL} = ProtocolErrors;
it('Tries to invoke mint not being the LendingPool', async () => {
const {deployer, aDai} = testEnv;
await expect(aDai.mint(deployer.address, '1')).to.be.revertedWith(INVALID_POOL_CALLER_MSG_1);
await expect(aDai.mint(deployer.address, '1')).to.be.revertedWith(CALLER_MUST_BE_LENDING_POOL);
});
it('Tries to invoke burn not being the LendingPool', async () => {
const {deployer, aDai} = testEnv;
await expect(aDai.burn(deployer.address, deployer.address, '1')).to.be.revertedWith(
INVALID_POOL_CALLER_MSG_1
CALLER_MUST_BE_LENDING_POOL
);
});
@ -21,13 +21,13 @@ makeSuite('AToken: Modifiers', (testEnv: TestEnv) => {
const {deployer, users, aDai} = testEnv;
await expect(
aDai.transferOnLiquidation(deployer.address, users[0].address, '1')
).to.be.revertedWith(INVALID_POOL_CALLER_MSG_1);
).to.be.revertedWith(CALLER_MUST_BE_LENDING_POOL);
});
it('Tries to invoke transferUnderlyingTo not being the LendingPool', async () => {
const {deployer, users, aDai} = testEnv;
await expect(aDai.transferUnderlyingTo(deployer.address, '1')).to.be.revertedWith(
INVALID_POOL_CALLER_MSG_1
CALLER_MUST_BE_LENDING_POOL
);
});
});

View File

@ -17,8 +17,10 @@ makeSuite('AToken: Transfer', (testEnv: TestEnv) => {
INVALID_REDIRECTED_BALANCE_BEFORE_TRANSFER,
INVALID_REDIRECTED_BALANCE_AFTER_TRANSFER,
INVALID_REDIRECTION_ADDRESS,
ZERO_COLLATERAL,
TRANSFERRED_AMOUNT_GT_ZERO,
// ZERO_COLLATERAL,
TRANSFER_AMOUNT_NOT_GT_0,
COLLATERAL_BALANCE_IS_0,
TRANSFER_NOT_ALLOWED,
} = ProtocolErrors;
it('User 0 deposits 1000 DAI, transfers to user 1', async () => {
@ -96,16 +98,14 @@ makeSuite('AToken: Transfer', (testEnv: TestEnv) => {
await weth.connect(users[0].signer).mint(await convertToCurrencyDecimals(weth.address, '1'));
await weth.connect(users[0].signer).approve(pool.address, APPROVAL_AMOUNT_LENDING_POOL);
await pool
.connect(users[0].signer)
.deposit(weth.address, ethers.utils.parseEther('1.0'), '0');
await pool.connect(users[0].signer).deposit(weth.address, ethers.utils.parseEther('1.0'), '0');
await expect(
pool
.connect(users[1].signer)
.borrow(weth.address, ethers.utils.parseEther('0.1'), RateMode.Stable, AAVE_REFERRAL),
ZERO_COLLATERAL
).to.be.revertedWith(ZERO_COLLATERAL);
COLLATERAL_BALANCE_IS_0
).to.be.revertedWith(COLLATERAL_BALANCE_IS_0);
});
it('User 1 sets the DAI as collateral and borrows, tries to transfer everything back to user 0 (revert expected)', async () => {
@ -120,25 +120,25 @@ makeSuite('AToken: Transfer', (testEnv: TestEnv) => {
await expect(
aDai.connect(users[1].signer).transfer(users[0].address, aDAItoTransfer),
'Transfer cannot be allowed.'
).to.be.revertedWith('Transfer cannot be allowed.');
TRANSFER_NOT_ALLOWED
).to.be.revertedWith(TRANSFER_NOT_ALLOWED);
});
it('User 0 tries to transfer 0 balance (revert expected)', async () => {
const {users, pool, aDai, dai, weth} = testEnv;
await expect(
aDai.connect(users[0].signer).transfer(users[1].address, '0'),
TRANSFERRED_AMOUNT_GT_ZERO
).to.be.revertedWith(TRANSFERRED_AMOUNT_GT_ZERO);
TRANSFER_AMOUNT_NOT_GT_0
).to.be.revertedWith(TRANSFER_AMOUNT_NOT_GT_0);
});
it('User 1 repays the borrow, transfers aDAI back to user 0', async () => {
const {users, pool, aDai, dai, weth} = testEnv;
await weth.connect(users[1].signer).mint(await convertToCurrencyDecimals(weth.address, '2'));
await weth.connect(users[1].signer).approve(pool.address, APPROVAL_AMOUNT_LENDING_POOL);
await pool
.connect(users[1].signer)
.repay(weth.address, MAX_UINT_AMOUNT, RateMode.Stable, users[1].address);

View File

@ -6,7 +6,7 @@ import {ProtocolErrors} from '../helpers/types';
const {expect} = require('chai');
makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
const {INVALID_POOL_MANAGER_CALLER_MSG} = ProtocolErrors;
const {CALLER_NOT_LENDING_POOL_MANAGER, RESERVE_LIQUIDITY_NOT_0} = ProtocolErrors;
it('Deactivates the ETH reserve', async () => {
const {configurator, pool, weth} = testEnv;
@ -27,16 +27,16 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
const {configurator, users, weth} = testEnv;
await expect(
configurator.connect(users[2].signer).deactivateReserve(weth.address),
INVALID_POOL_MANAGER_CALLER_MSG
).to.be.revertedWith(INVALID_POOL_MANAGER_CALLER_MSG);
CALLER_NOT_LENDING_POOL_MANAGER
).to.be.revertedWith(CALLER_NOT_LENDING_POOL_MANAGER);
});
it('Check the onlyLendingPoolManager on activateReserve ', async () => {
const {configurator, users, weth} = testEnv;
await expect(
configurator.connect(users[2].signer).activateReserve(weth.address),
INVALID_POOL_MANAGER_CALLER_MSG
).to.be.revertedWith(INVALID_POOL_MANAGER_CALLER_MSG);
CALLER_NOT_LENDING_POOL_MANAGER
).to.be.revertedWith(CALLER_NOT_LENDING_POOL_MANAGER);
});
it('Freezes the ETH reserve', async () => {
@ -58,16 +58,16 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
const {configurator, users, weth} = testEnv;
await expect(
configurator.connect(users[2].signer).freezeReserve(weth.address),
INVALID_POOL_MANAGER_CALLER_MSG
).to.be.revertedWith(INVALID_POOL_MANAGER_CALLER_MSG);
CALLER_NOT_LENDING_POOL_MANAGER
).to.be.revertedWith(CALLER_NOT_LENDING_POOL_MANAGER);
});
it('Check the onlyLendingPoolManager on unfreezeReserve ', async () => {
const {configurator, users, weth} = testEnv;
await expect(
configurator.connect(users[2].signer).unfreezeReserve(weth.address),
INVALID_POOL_MANAGER_CALLER_MSG
).to.be.revertedWith(INVALID_POOL_MANAGER_CALLER_MSG);
CALLER_NOT_LENDING_POOL_MANAGER
).to.be.revertedWith(CALLER_NOT_LENDING_POOL_MANAGER);
});
it('Deactivates the ETH reserve for borrowing', async () => {
@ -90,16 +90,16 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
const {configurator, users, weth} = testEnv;
await expect(
configurator.connect(users[2].signer).disableBorrowingOnReserve(weth.address),
INVALID_POOL_MANAGER_CALLER_MSG
).to.be.revertedWith(INVALID_POOL_MANAGER_CALLER_MSG);
CALLER_NOT_LENDING_POOL_MANAGER
).to.be.revertedWith(CALLER_NOT_LENDING_POOL_MANAGER);
});
it('Check the onlyLendingPoolManager on enableBorrowingOnReserve ', async () => {
const {configurator, users, weth} = testEnv;
await expect(
configurator.connect(users[2].signer).enableBorrowingOnReserve(weth.address, true),
INVALID_POOL_MANAGER_CALLER_MSG
).to.be.revertedWith(INVALID_POOL_MANAGER_CALLER_MSG);
CALLER_NOT_LENDING_POOL_MANAGER
).to.be.revertedWith(CALLER_NOT_LENDING_POOL_MANAGER);
});
it('Deactivates the ETH reserve as collateral', async () => {
@ -121,8 +121,8 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
const {configurator, users, weth} = testEnv;
await expect(
configurator.connect(users[2].signer).disableReserveAsCollateral(weth.address),
INVALID_POOL_MANAGER_CALLER_MSG
).to.be.revertedWith(INVALID_POOL_MANAGER_CALLER_MSG);
CALLER_NOT_LENDING_POOL_MANAGER
).to.be.revertedWith(CALLER_NOT_LENDING_POOL_MANAGER);
});
it('Check the onlyLendingPoolManager on enableReserveAsCollateral ', async () => {
@ -131,8 +131,8 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
configurator
.connect(users[2].signer)
.enableReserveAsCollateral(weth.address, '75', '80', '105'),
INVALID_POOL_MANAGER_CALLER_MSG
).to.be.revertedWith(INVALID_POOL_MANAGER_CALLER_MSG);
CALLER_NOT_LENDING_POOL_MANAGER
).to.be.revertedWith(CALLER_NOT_LENDING_POOL_MANAGER);
});
it('Disable stable borrow rate on the ETH reserve', async () => {
@ -153,16 +153,16 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
const {configurator, users, weth} = testEnv;
await expect(
configurator.connect(users[2].signer).disableReserveStableRate(weth.address),
INVALID_POOL_MANAGER_CALLER_MSG
).to.be.revertedWith(INVALID_POOL_MANAGER_CALLER_MSG);
CALLER_NOT_LENDING_POOL_MANAGER
).to.be.revertedWith(CALLER_NOT_LENDING_POOL_MANAGER);
});
it('Check the onlyLendingPoolManager on enableReserveStableRate', async () => {
const {configurator, users, weth} = testEnv;
await expect(
configurator.connect(users[2].signer).enableReserveStableRate(weth.address),
INVALID_POOL_MANAGER_CALLER_MSG
).to.be.revertedWith(INVALID_POOL_MANAGER_CALLER_MSG);
CALLER_NOT_LENDING_POOL_MANAGER
).to.be.revertedWith(CALLER_NOT_LENDING_POOL_MANAGER);
});
it('Changes LTV of the reserve', async () => {
@ -176,8 +176,8 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
const {configurator, users, weth} = testEnv;
await expect(
configurator.connect(users[2].signer).setLtv(weth.address, '75'),
INVALID_POOL_MANAGER_CALLER_MSG
).to.be.revertedWith(INVALID_POOL_MANAGER_CALLER_MSG);
CALLER_NOT_LENDING_POOL_MANAGER
).to.be.revertedWith(CALLER_NOT_LENDING_POOL_MANAGER);
});
it('Changes liquidation threshold of the reserve', async () => {
@ -194,8 +194,8 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
const {configurator, users, weth} = testEnv;
await expect(
configurator.connect(users[2].signer).setLiquidationThreshold(weth.address, '80'),
INVALID_POOL_MANAGER_CALLER_MSG
).to.be.revertedWith(INVALID_POOL_MANAGER_CALLER_MSG);
CALLER_NOT_LENDING_POOL_MANAGER
).to.be.revertedWith(CALLER_NOT_LENDING_POOL_MANAGER);
});
it('Changes liquidation bonus of the reserve', async () => {
@ -212,24 +212,24 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
const {configurator, users, weth} = testEnv;
await expect(
configurator.connect(users[2].signer).setLiquidationBonus(weth.address, '80'),
INVALID_POOL_MANAGER_CALLER_MSG
).to.be.revertedWith(INVALID_POOL_MANAGER_CALLER_MSG);
CALLER_NOT_LENDING_POOL_MANAGER
).to.be.revertedWith(CALLER_NOT_LENDING_POOL_MANAGER);
});
it('Check the onlyLendingPoolManager on setReserveDecimals', async () => {
const {configurator, users, weth} = testEnv;
await expect(
configurator.connect(users[2].signer).setReserveDecimals(weth.address, '80'),
INVALID_POOL_MANAGER_CALLER_MSG
).to.be.revertedWith(INVALID_POOL_MANAGER_CALLER_MSG);
CALLER_NOT_LENDING_POOL_MANAGER
).to.be.revertedWith(CALLER_NOT_LENDING_POOL_MANAGER);
});
it('Check the onlyLendingPoolManager on setLiquidationBonus', async () => {
const {configurator, users, weth} = testEnv;
await expect(
configurator.connect(users[2].signer).setLiquidationBonus(weth.address, '80'),
INVALID_POOL_MANAGER_CALLER_MSG
).to.be.revertedWith(INVALID_POOL_MANAGER_CALLER_MSG);
CALLER_NOT_LENDING_POOL_MANAGER
).to.be.revertedWith(CALLER_NOT_LENDING_POOL_MANAGER);
});
it('Reverts when trying to disable the DAI reserve with liquidity on it', async () => {
@ -246,7 +246,7 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
await expect(
configurator.deactivateReserve(dai.address),
'The liquidity of the reserve needs to be 0'
).to.be.revertedWith('The liquidity of the reserve needs to be 0');
RESERVE_LIQUIDITY_NOT_0
).to.be.revertedWith(RESERVE_LIQUIDITY_NOT_0);
});
});

View File

@ -16,9 +16,9 @@ const {expect} = require('chai');
makeSuite('LendingPool FlashLoan function', (testEnv: TestEnv) => {
let _mockFlashLoanReceiver = {} as MockFlashLoanReceiver;
const {
TRANSFER_AMOUNT_EXCEEDS_BALANCE,
TOO_SMALL_FLASH_LOAN,
COLLATERAL_BALANCE_IS_0,
REQUESTED_AMOUNT_TOO_SMALL,
TRANSFER_AMOUNT_EXCEEDS_BALANCE
} = ProtocolErrors;
before(async () => {
@ -103,7 +103,7 @@ makeSuite('LendingPool FlashLoan function', (testEnv: TestEnv) => {
_mockFlashLoanReceiver.address,
weth.address,
ethers.utils.parseEther('0.8'),
2,
0,
'0x10',
'0'
)
@ -159,7 +159,7 @@ makeSuite('LendingPool FlashLoan function', (testEnv: TestEnv) => {
'0x10',
'0'
)
).to.be.revertedWith(TOO_SMALL_FLASH_LOAN);
).to.be.revertedWith(REQUESTED_AMOUNT_TOO_SMALL);
});
it('tries to take a flashloan that is bigger than the available liquidity (revert expected)', async () => {

View File

@ -13,10 +13,10 @@ const {expect} = chai;
makeSuite('LendingPool liquidation - liquidator receiving aToken', (testEnv) => {
const {
HF_IS_NOT_BELLOW_THRESHOLD,
HEALTH_FACTOR_NOT_BELOW_THRESHOLD,
INVALID_HF,
USER_DID_NOT_BORROW_SPECIFIED,
THE_COLLATERAL_CHOSEN_CANNOT_BE_LIQUIDATED,
SPECIFIED_CURRENCY_NOT_BORROWED_BY_USER,
COLLATERAL_CANNOT_BE_LIQUIDATED,
} = ProtocolErrors;
it('LIQUIDATION - Deposits WETH, borrows DAI/Check liquidation fails because health factor is above 1', async () => {
@ -71,7 +71,7 @@ makeSuite('LendingPool liquidation - liquidator receiving aToken', (testEnv) =>
//someone tries to liquidate user 2
await expect(
pool.liquidationCall(weth.address, dai.address, borrower.address, 1, true)
).to.be.revertedWith(HF_IS_NOT_BELLOW_THRESHOLD);
).to.be.revertedWith(HEALTH_FACTOR_NOT_BELOW_THRESHOLD);
});
it('LIQUIDATION - Drop the health factor below 1', async () => {
@ -96,7 +96,7 @@ makeSuite('LendingPool liquidation - liquidator receiving aToken', (testEnv) =>
//user 2 tries to borrow
await expect(
pool.liquidationCall(weth.address, weth.address, borrower.address, oneEther.toString(), true)
).revertedWith(USER_DID_NOT_BORROW_SPECIFIED);
).revertedWith(SPECIFIED_CURRENCY_NOT_BORROWED_BY_USER);
});
it('LIQUIDATION - Tries to liquidate a different collateral than the borrower collateral', async () => {
@ -105,7 +105,7 @@ makeSuite('LendingPool liquidation - liquidator receiving aToken', (testEnv) =>
await expect(
pool.liquidationCall(dai.address, dai.address, borrower.address, oneEther.toString(), true)
).revertedWith(THE_COLLATERAL_CHOSEN_CANNOT_BE_LIQUIDATED);
).revertedWith(COLLATERAL_CANNOT_BE_LIQUIDATED);
});
it('LIQUIDATION - Liquidates the borrow', async () => {

View File

@ -13,12 +13,7 @@ const chai = require('chai');
const {expect} = chai;
makeSuite('LendingPool liquidation - liquidator receiving the underlying asset', (testEnv) => {
const {
HF_IS_NOT_BELLOW_THRESHOLD,
INVALID_HF,
USER_DID_NOT_BORROW_SPECIFIED,
THE_COLLATERAL_CHOSEN_CANNOT_BE_LIQUIDATED,
} = ProtocolErrors;
const {INVALID_HF} = ProtocolErrors;
it('LIQUIDATION - Deposits WETH, borrows DAI', async () => {
const {dai, weth, users, pool, oracle} = testEnv;
@ -67,7 +62,7 @@ makeSuite('LendingPool liquidation - liquidator receiving the underlying asset',
expect(userGlobalDataAfter.currentLiquidationThreshold.toString()).to.be.bignumber.equal(
'8000',
'Invalid liquidation threshold'
INVALID_HF
);
});
@ -86,7 +81,7 @@ makeSuite('LendingPool liquidation - liquidator receiving the underlying asset',
expect(userGlobalData.healthFactor.toString()).to.be.bignumber.lt(
oneEther.toFixed(0),
'Invalid health factor'
INVALID_HF
);
});

View File

@ -5,7 +5,7 @@ import {getContract} from '../helpers/contracts-helpers';
import {StableDebtToken} from '../types/StableDebtToken';
makeSuite('Stable debt token tests', (testEnv: TestEnv) => {
const {INVALID_POOL_CALLER_MSG_1} = ProtocolErrors;
const {CALLER_MUST_BE_LENDING_POOL} = ProtocolErrors;
it('Tries to invoke mint not being the LendingPool', async () => {
const {deployer, pool, dai} = testEnv;
@ -19,7 +19,7 @@ makeSuite('Stable debt token tests', (testEnv: TestEnv) => {
);
await expect(stableDebtContract.mint(deployer.address, '1', '1')).to.be.revertedWith(
INVALID_POOL_CALLER_MSG_1
CALLER_MUST_BE_LENDING_POOL
);
});
@ -35,7 +35,7 @@ makeSuite('Stable debt token tests', (testEnv: TestEnv) => {
);
await expect(stableDebtContract.burn(deployer.address, '1')).to.be.revertedWith(
INVALID_POOL_CALLER_MSG_1
CALLER_MUST_BE_LENDING_POOL
);
});
});

View File

@ -1,18 +1,22 @@
import {expect} from 'chai';
import {makeSuite, TestEnv} from './helpers/make-suite';
import {ProtocolErrors, eContractid} from '../helpers/types';
import {deployGenericAToken, getAToken, deployContract, getContract} from '../helpers/contracts-helpers';
import {
deployGenericAToken,
getAToken,
deployContract,
getContract,
} from '../helpers/contracts-helpers';
import {MockAToken} from '../types/MockAToken';
import { MockStableDebtToken } from '../types/MockStableDebtToken';
import { MockVariableDebtToken } from '../types/MockVariableDebtToken';
import {MockStableDebtToken} from '../types/MockStableDebtToken';
import {MockVariableDebtToken} from '../types/MockVariableDebtToken';
makeSuite('Upgradeability', (testEnv: TestEnv) => {
const {INVALID_POOL_MANAGER_CALLER_MSG} = ProtocolErrors;
const {CALLER_NOT_LENDING_POOL_MANAGER} = ProtocolErrors;
let newATokenAddress: string;
let newStableTokenAddress: string;
let newVariableTokenAddress: string;
before('deploying instances', async () => {
const {dai, pool} = testEnv;
const aTokenInstance = await deployContract<MockAToken>(eContractid.MockAToken, [
@ -22,24 +26,19 @@ makeSuite('Upgradeability', (testEnv: TestEnv) => {
'aDAI',
]);
const stableDebtTokenInstance = await deployContract<MockStableDebtToken>(eContractid.MockStableDebtToken, [
pool.address,
dai.address,
'Aave stable debt bearing DAI updated',
'stableDebtDAI',
]);
const stableDebtTokenInstance = await deployContract<MockStableDebtToken>(
eContractid.MockStableDebtToken,
[pool.address, dai.address, 'Aave stable debt bearing DAI updated', 'stableDebtDAI']
);
const variableDebtTokenInstance = await deployContract<MockVariableDebtToken>(eContractid.MockVariableDebtToken, [
pool.address,
dai.address,
'Aave variable debt bearing DAI updated',
'variableDebtDAI',
]);
const variableDebtTokenInstance = await deployContract<MockVariableDebtToken>(
eContractid.MockVariableDebtToken,
[pool.address, dai.address, 'Aave variable debt bearing DAI updated', 'variableDebtDAI']
);
newATokenAddress = aTokenInstance.address;
newVariableTokenAddress = variableDebtTokenInstance.address;
newStableTokenAddress = stableDebtTokenInstance.address;
});
it('Tries to update the DAI Atoken implementation with a different address than the lendingPoolManager', async () => {
@ -47,7 +46,7 @@ makeSuite('Upgradeability', (testEnv: TestEnv) => {
await expect(
configurator.connect(users[1].signer).updateAToken(dai.address, newATokenAddress)
).to.be.revertedWith(INVALID_POOL_MANAGER_CALLER_MSG);
).to.be.revertedWith(CALLER_NOT_LENDING_POOL_MANAGER);
});
it('Upgrades the DAI Atoken implementation ', async () => {
@ -66,8 +65,10 @@ makeSuite('Upgradeability', (testEnv: TestEnv) => {
const {dai, configurator, users} = testEnv;
await expect(
configurator.connect(users[1].signer).updateStableDebtToken(dai.address, newStableTokenAddress)
).to.be.revertedWith(INVALID_POOL_MANAGER_CALLER_MSG);
configurator
.connect(users[1].signer)
.updateStableDebtToken(dai.address, newStableTokenAddress)
).to.be.revertedWith(CALLER_NOT_LENDING_POOL_MANAGER);
});
it('Upgrades the DAI stable debt token implementation ', async () => {
@ -79,7 +80,10 @@ makeSuite('Upgradeability', (testEnv: TestEnv) => {
const {stableDebtTokenAddress} = await pool.getReserveTokensAddresses(dai.address);
const debtToken = await getContract<MockStableDebtToken>(eContractid.MockStableDebtToken, stableDebtTokenAddress);
const debtToken = await getContract<MockStableDebtToken>(
eContractid.MockStableDebtToken,
stableDebtTokenAddress
);
const tokenName = await debtToken.name();
@ -90,8 +94,10 @@ makeSuite('Upgradeability', (testEnv: TestEnv) => {
const {dai, configurator, users} = testEnv;
await expect(
configurator.connect(users[1].signer).updateVariableDebtToken(dai.address, newVariableTokenAddress)
).to.be.revertedWith(INVALID_POOL_MANAGER_CALLER_MSG);
configurator
.connect(users[1].signer)
.updateVariableDebtToken(dai.address, newVariableTokenAddress)
).to.be.revertedWith(CALLER_NOT_LENDING_POOL_MANAGER);
});
it('Upgrades the DAI variable debt token implementation ', async () => {
@ -103,11 +109,13 @@ makeSuite('Upgradeability', (testEnv: TestEnv) => {
const {variableDebtTokenAddress} = await pool.getReserveTokensAddresses(dai.address);
const debtToken = await getContract<MockStableDebtToken>(eContractid.MockStableDebtToken, variableDebtTokenAddress);
const debtToken = await getContract<MockStableDebtToken>(
eContractid.MockStableDebtToken,
variableDebtTokenAddress
);
const tokenName = await debtToken.name();
expect(tokenName).to.be.eq('Aave variable debt bearing DAI updated', 'Invalid token name');
});
});

View File

@ -5,7 +5,7 @@ import {getContract} from '../helpers/contracts-helpers';
import {VariableDebtToken} from '../types/VariableDebtToken';
makeSuite('Variable debt token tests', (testEnv: TestEnv) => {
const {INVALID_POOL_CALLER_MSG_1} = ProtocolErrors;
const {CALLER_MUST_BE_LENDING_POOL} = ProtocolErrors;
it('Tries to invoke mint not being the LendingPool', async () => {
const {deployer, pool, dai} = testEnv;
@ -19,7 +19,7 @@ makeSuite('Variable debt token tests', (testEnv: TestEnv) => {
);
await expect(variableDebtContract.mint(deployer.address, '1')).to.be.revertedWith(
INVALID_POOL_CALLER_MSG_1
CALLER_MUST_BE_LENDING_POOL
);
});
@ -35,7 +35,7 @@ makeSuite('Variable debt token tests', (testEnv: TestEnv) => {
);
await expect(variableDebtContract.burn(deployer.address, '1')).to.be.revertedWith(
INVALID_POOL_CALLER_MSG_1
CALLER_MUST_BE_LENDING_POOL
);
});
});