Merge branch 'feat/reorg-errors' into 'master'

Resolve "Reorg `Errors.sol`"

Closes #54

See merge request aave-tech/protocol-v2!74
This commit is contained in:
Ernesto Boado 2020-10-30 16:03:04 +00:00
commit f188fd5c8f
28 changed files with 460 additions and 418 deletions

View File

@ -14,17 +14,13 @@ usePlugin('@nomiclabs/buidler-etherscan');
usePlugin('buidler-gas-reporter');
const SKIP_LOAD = process.env.SKIP_LOAD === 'true';
const DEFAULT_BLOCK_GAS_LIMIT = 12000000;
const DEFAULT_BLOCK_GAS_LIMIT = 12450000;
const DEFAULT_GAS_PRICE = 10;
const HARDFORK = 'istanbul';
const INFURA_KEY = process.env.INFURA_KEY || '';
const ETHERSCAN_KEY = process.env.ETHERSCAN_KEY || '';
const MNEMONIC_PATH = "m/44'/60'/0'/0";
const MNEMONICS: {[network: string]: string} = {
[eEthereumNetwork.kovan]: process.env.MNEMONIC || '',
[eEthereumNetwork.ropsten]: process.env.MNEMONIC || '',
[eEthereumNetwork.main]: process.env.MNEMONIC || '',
};
const MNEMONIC = process.env.MNEMONIC || '';
// Prevent to load scripts before compilation and typechain
if (!SKIP_LOAD) {
@ -44,7 +40,7 @@ const getCommonNetworkConfig = (networkName: eEthereumNetwork, networkId: number
gasMultiplier: DEFAULT_GAS_PRICE,
chainId: networkId,
accounts: {
mnemonic: MNEMONICS[networkName],
mnemonic: MNEMONIC,
path: MNEMONIC_PATH,
initialIndex: 0,
count: 20,

View File

@ -56,7 +56,7 @@ contract LendingPoolAddressesProviderRegistry is Ownable, ILendingPoolAddressesP
* @param provider the pool address to be registered
**/
function registerAddressesProvider(address provider, uint256 id) external override onlyOwner {
require(id != 0, Errors.INVALID_ADDRESSES_PROVIDER_ID);
require(id != 0, Errors.LPAPR_INVALID_ADDRESSES_PROVIDER_ID);
_addressesProviders[provider] = id;
_addToAddressesProvidersList(provider);
@ -68,7 +68,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, Errors.PROVIDER_NOT_REGISTERED);
require(_addressesProviders[provider] > 0, Errors.LPAPR_PROVIDER_NOT_REGISTERED);
_addressesProviders[provider] = 0;
emit AddressesProviderUnregistered(provider);
}

View File

@ -52,7 +52,7 @@ contract LendingPool is VersionedInitializable, ILendingPool, LendingPoolStorage
function _onlyLendingPoolConfigurator() internal view {
require(
_addressesProvider.getLendingPoolConfigurator() == msg.sender,
Errors.CALLER_NOT_LENDING_POOL_CONFIGURATOR
Errors.LP_CALLER_NOT_LENDING_POOL_CONFIGURATOR
);
}
@ -64,7 +64,7 @@ contract LendingPool is VersionedInitializable, ILendingPool, LendingPoolStorage
* - The contract must not be paused.
*/
function _whenNotPaused() internal view {
require(!_paused, Errors.IS_PAUSED);
require(!_paused, Errors.P_IS_PAUSED);
}
function getRevision() internal override pure returns (uint256) {
@ -200,7 +200,7 @@ contract LendingPool is VersionedInitializable, ILendingPool, LendingPoolStorage
uint256 countAssets = assets.length;
require(
countAssets == interestRateModes.length && countAssets == amounts.length,
Errors.INCONSISTENT_PARAMS_LENGTH
Errors.LP_INCONSISTENT_PARAMS_LENGTH
);
for (uint256 i = 0; i < countAssets; i++) {
@ -236,7 +236,7 @@ contract LendingPool is VersionedInitializable, ILendingPool, LendingPoolStorage
_borrowAllowance[debtToken][onBehalfOf][msg
.sender] = _borrowAllowance[debtToken][onBehalfOf][msg.sender].sub(
amount,
Errors.BORROW_ALLOWANCE_ARE_NOT_ENOUGH
Errors.LP_BORROW_ALLOWANCE_ARE_NOT_ENOUGH
);
}
_executeBorrow(
@ -411,7 +411,7 @@ contract LendingPool is VersionedInitializable, ILendingPool, LendingPoolStorage
usageRatio >= REBALANCE_UP_USAGE_RATIO_THRESHOLD &&
currentLiquidityRate <=
maxVariableBorrowRate.percentMul(REBALANCE_UP_LIQUIDITY_RATE_THRESHOLD),
Errors.INTEREST_RATE_REBALANCE_CONDITIONS_NOT_MET
Errors.LP_INTEREST_RATE_REBALANCE_CONDITIONS_NOT_MET
);
reserve.updateState();
@ -486,7 +486,7 @@ contract LendingPool is VersionedInitializable, ILendingPool, LendingPoolStorage
receiveAToken
)
);
require(success, Errors.LIQUIDATION_CALL_FAILED);
require(success, Errors.LP_LIQUIDATION_CALL_FAILED);
(uint256 returnCode, string memory returnMessage) = abi.decode(result, (uint256, string));
@ -552,7 +552,7 @@ contract LendingPool is VersionedInitializable, ILendingPool, LendingPoolStorage
//execute action of the receiver
require(
vars.receiver.executeOperation(assets, amounts, premiums, msg.sender, params),
Errors.INVALID_FLASH_LOAN_EXECUTOR_RETURN
Errors.LP_INVALID_FLASH_LOAN_EXECUTOR_RETURN
);
for (vars.i = 0; vars.i < assets.length; vars.i++) {
@ -586,7 +586,7 @@ contract LendingPool is VersionedInitializable, ILendingPool, LendingPoolStorage
_borrowAllowance[vars.debtToken][onBehalfOf][msg.sender] = _borrowAllowance[vars
.debtToken][onBehalfOf][msg.sender]
.sub(vars.currentAmount, Errors.BORROW_ALLOWANCE_ARE_NOT_ENOUGH);
.sub(vars.currentAmount, Errors.LP_BORROW_ALLOWANCE_ARE_NOT_ENOUGH);
}
//if the user didn't choose to return the funds, the system checks if there
@ -776,7 +776,7 @@ contract LendingPool is VersionedInitializable, ILendingPool, LendingPoolStorage
) external override {
_whenNotPaused();
require(msg.sender == _reserves[asset].aTokenAddress, Errors.CALLER_MUST_BE_AN_ATOKEN);
require(msg.sender == _reserves[asset].aTokenAddress, Errors.LP_CALLER_MUST_BE_AN_ATOKEN);
ValidationLogic.validateTransfer(
from,
@ -969,7 +969,7 @@ contract LendingPool is VersionedInitializable, ILendingPool, LendingPoolStorage
function _addReserveToList(address asset) internal {
uint256 reservesCount = _reservesCount;
require(reservesCount < MAX_NUMBER_RESERVES, Errors.NO_MORE_RESERVES_ALLOWED);
require(reservesCount < MAX_NUMBER_RESERVES, Errors.LP_NO_MORE_RESERVES_ALLOWED);
bool reserveAlreadyAdded = _reserves[asset].id != 0 || _reservesList[0] == asset;

View File

@ -185,7 +185,7 @@ contract LendingPoolCollateralManager is VersionedInitializable, LendingPoolStor
if (currentAvailableCollateral < vars.maxCollateralToLiquidate) {
return (
uint256(Errors.CollateralManagerErrors.NOT_ENOUGH_LIQUIDITY),
Errors.NOT_ENOUGH_LIQUIDITY_TO_LIQUIDATE
Errors.LPCM_NOT_ENOUGH_LIQUIDITY_TO_LIQUIDATE
);
}
}
@ -263,7 +263,7 @@ contract LendingPoolCollateralManager is VersionedInitializable, LendingPoolStor
receiveAToken
);
return (uint256(Errors.CollateralManagerErrors.NO_ERROR), Errors.NO_ERRORS);
return (uint256(Errors.CollateralManagerErrors.NO_ERROR), Errors.LPCM_NO_ERRORS);
}
/**

View File

@ -196,7 +196,7 @@ contract LendingPoolConfigurator is VersionedInitializable {
* @dev only the lending pool manager can call functions affected by this modifier
**/
modifier onlyAaveAdmin {
require(addressesProvider.getAaveAdmin() == msg.sender, Errors.CALLER_NOT_AAVE_ADMIN);
require(addressesProvider.getAaveAdmin() == msg.sender, Errors.LPC_CALLER_NOT_AAVE_ADMIN);
_;
}
@ -230,23 +230,23 @@ contract LendingPoolConfigurator is VersionedInitializable {
require(
address(pool) == ITokenConfiguration(aTokenImpl).POOL(),
Errors.INVALID_ATOKEN_POOL_ADDRESS
Errors.LPC_INVALID_ATOKEN_POOL_ADDRESS
);
require(
address(pool) == ITokenConfiguration(stableDebtTokenImpl).POOL(),
Errors.INVALID_STABLE_DEBT_TOKEN_POOL_ADDRESS
Errors.LPC_INVALID_STABLE_DEBT_TOKEN_POOL_ADDRESS
);
require(
address(pool) == ITokenConfiguration(variableDebtTokenImpl).POOL(),
Errors.INVALID_VARIABLE_DEBT_TOKEN_POOL_ADDRESS
Errors.LPC_INVALID_VARIABLE_DEBT_TOKEN_POOL_ADDRESS
);
require(
asset == ITokenConfiguration(stableDebtTokenImpl).UNDERLYING_ASSET_ADDRESS(),
Errors.INVALID_STABLE_DEBT_TOKEN_UNDERLYING_ADDRESS
Errors.LPC_INVALID_STABLE_DEBT_TOKEN_UNDERLYING_ADDRESS
);
require(
asset == ITokenConfiguration(variableDebtTokenImpl).UNDERLYING_ASSET_ADDRESS(),
Errors.INVALID_VARIABLE_DEBT_TOKEN_UNDERLYING_ADDRESS
Errors.LPC_INVALID_VARIABLE_DEBT_TOKEN_UNDERLYING_ADDRESS
);
address aTokenProxyAddress = _initTokenWithProxy(aTokenImpl, underlyingAssetDecimals);
@ -449,7 +449,7 @@ contract LendingPoolConfigurator is VersionedInitializable {
require(
availableLiquidity == 0 && reserveData.currentLiquidityRate == 0,
Errors.RESERVE_LIQUIDITY_NOT_0
Errors.LPC_RESERVE_LIQUIDITY_NOT_0
);
ReserveConfiguration.Map memory currentConfig = pool.getConfiguration(asset);

View File

@ -55,7 +55,7 @@ library ReserveConfiguration {
* @param ltv the new ltv
**/
function setLtv(ReserveConfiguration.Map memory self, uint256 ltv) internal pure {
require(ltv <= MAX_VALID_LTV, Errors.INVALID_LTV);
require(ltv <= MAX_VALID_LTV, Errors.RC_INVALID_LTV);
self.data = (self.data & LTV_MASK) | ltv;
}
@ -78,7 +78,7 @@ library ReserveConfiguration {
internal
pure
{
require(threshold <= MAX_VALID_LIQUIDATION_THRESHOLD, Errors.INVALID_LIQ_THRESHOLD);
require(threshold <= MAX_VALID_LIQUIDATION_THRESHOLD, Errors.RC_INVALID_LIQ_THRESHOLD);
self.data =
(self.data & LIQUIDATION_THRESHOLD_MASK) |
@ -104,7 +104,7 @@ library ReserveConfiguration {
* @param bonus the new liquidation bonus
**/
function setLiquidationBonus(ReserveConfiguration.Map memory self, uint256 bonus) internal pure {
require(bonus <= MAX_VALID_LIQUIDATION_BONUS, Errors.INVALID_LIQ_BONUS);
require(bonus <= MAX_VALID_LIQUIDATION_BONUS, Errors.RC_INVALID_LIQ_BONUS);
self.data =
(self.data & LIQUIDATION_BONUS_MASK) |
@ -130,7 +130,7 @@ library ReserveConfiguration {
* @param decimals the decimals
**/
function setDecimals(ReserveConfiguration.Map memory self, uint256 decimals) internal pure {
require(decimals <= MAX_VALID_DECIMALS, Errors.INVALID_DECIMALS);
require(decimals <= MAX_VALID_DECIMALS, Errors.RC_INVALID_DECIMALS);
self.data = (self.data & DECIMALS_MASK) | (decimals << RESERVE_DECIMALS_START_BIT_POSITION);
}
@ -240,7 +240,7 @@ library ReserveConfiguration {
internal
pure
{
require(reserveFactor <= MAX_VALID_RESERVE_FACTOR, Errors.INVALID_RESERVE_FACTOR);
require(reserveFactor <= MAX_VALID_RESERVE_FACTOR, Errors.RC_INVALID_RESERVE_FACTOR);
self.data =
(self.data & RESERVE_FACTOR_MASK) |

View File

@ -5,101 +5,92 @@ pragma solidity ^0.6.8;
* @title Errors library
* @author Aave
* @notice Implements error messages.
* @dev Error messages prefix glossary:
* - VL = ValidationLogic
* - MATH = Math libraries
* - AT = aToken or DebtTokens
* - LP = LendingPool
* - LPAPR = LendingPoolAddressesProviderRegistry
* - LPC = LendingPoolConfiguration
* - RL = ReserveLogic
* - LPCM = LendingPoolCollateralManager
* - P = Pausable
*/
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'
string public constant INVALID_FLASHLOAN_MODE = '43'; //Invalid flashloan mode selected
string public constant BORROW_ALLOWANCE_ARE_NOT_ENOUGH = '54'; // User borrows on behalf, but allowance are too small
string public constant REENTRANCY_NOT_ALLOWED = '57';
string public constant FAILED_REPAY_WITH_COLLATERAL = '53';
string public constant FAILED_COLLATERAL_SWAP = '55';
string public constant INVALID_EQUAL_ASSETS_TO_SWAP = '56';
string public constant NO_MORE_RESERVES_ALLOWED = '59';
string public constant INVALID_FLASH_LOAN_EXECUTOR_RETURN = '60';
string public constant INCONSISTENT_FLASHLOAN_PARAMS = '69';
string public constant CALLER_MUST_BE_AN_ATOKEN = '76';
// require error messages - aToken - DebtTokens
string public constant CALLER_MUST_BE_LENDING_POOL = '28'; // 'The caller of this function must be a lending pool'
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 INVALID_MINT_AMOUNT = '61'; //invalid amount to mint
string public constant INVALID_BURN_AMOUNT = '62'; //invalid amount to burn
// require error messages - ReserveLogic
string public constant RESERVE_ALREADY_INITIALIZED = '34'; // 'Reserve has already been initialized'
string public constant LIQUIDITY_INDEX_OVERFLOW = '47'; // Liquidity index overflows uint128
string public constant VARIABLE_BORROW_INDEX_OVERFLOW = '48'; // Variable borrow index overflows uint128
string public constant LIQUIDITY_RATE_OVERFLOW = '49'; // Liquidity rate overflows uint128
string public constant VARIABLE_BORROW_RATE_OVERFLOW = '50'; // Variable borrow rate overflows uint128
string public constant STABLE_BORROW_RATE_OVERFLOW = '51'; // Stable borrow rate overflows uint128
//require error messages - LendingPoolConfiguration
string public constant CALLER_NOT_AAVE_ADMIN = '35'; // 'The caller must be the aave admin'
string public constant RESERVE_LIQUIDITY_NOT_0 = '36'; // 'The liquidity of the reserve needs to be 0'
string public constant INVALID_ATOKEN_POOL_ADDRESS = '63'; // the lending pool in the aToken implementation is not configured correctly
string public constant INVALID_STABLE_DEBT_TOKEN_POOL_ADDRESS = '64'; // the lending pool in the stable debt token implementation is not configured correctly
string public constant INVALID_VARIABLE_DEBT_TOKEN_POOL_ADDRESS = '65'; // the lending pool in the variable debt token implementation is not configured correctly
string public constant INVALID_STABLE_DEBT_TOKEN_UNDERLYING_ADDRESS = '66'; // the underlying asset in the stable debt token implementation is not configured correctly
string public constant INVALID_VARIABLE_DEBT_TOKEN_UNDERLYING_ADDRESS = '67'; // the underlying asset in the variable debt token implementation is not configured correctly
//require error messages - LendingPoolAddressesProviderRegistry
string public constant PROVIDER_NOT_REGISTERED = '37'; // 'Provider is not registered'
string public constant INVALID_ADDRESSES_PROVIDER_ID = '68'; // the addresses provider id needs to be greater than 0
//return error messages - LendingPoolCollateralManager
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'
//require error messages - Math libraries
string public constant MULTIPLICATION_OVERFLOW = '44';
string public constant ADDITION_OVERFLOW = '45';
string public constant DIVISION_BY_ZERO = '46';
// pausable error message
string public constant IS_PAUSED = '58'; // 'Pool is paused'
// Reserve configuration
string public constant INVALID_LTV = '70';
string public constant INVALID_LIQ_THRESHOLD = '71';
string public constant INVALID_LIQ_BONUS = '72';
string public constant INVALID_DECIMALS = '73';
string public constant INVALID_RESERVE_FACTOR = '74';
// Credit delegation
string public constant INCONSISTENT_PARAMS_LENGTH = '75';
string public constant VL_AMOUNT_NOT_GREATER_THAN_0 = '1'; // 'Amount must be greater than 0'
string public constant VL_NO_ACTIVE_RESERVE = '2'; // 'Action requires an active reserve'
string public constant VL_NO_UNFREEZED_RESERVE = '3'; // 'Action requires an unfreezed reserve'
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_TRANSFER_NOT_ALLOWED = '6'; // 'Transfer cannot be allowed.'
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_COLLATERAL_BALANCE_IS_0 = '9'; // 'The collateral balance is 0'
string public constant VL_HEALTH_FACTOR_LOWER_THAN_LIQUIDATION_THRESHOLD = '10'; // 'Health factor is lesser than the liquidation threshold'
string public constant VL_COLLATERAL_CANNOT_COVER_NEW_BORROW = '11'; // 'There is not enough collateral to cover a new borrow'
string public constant VL_STABLE_BORROWING_NOT_ENABLED = '12'; // stable borrowing not enabled
string public constant VL_CALLATERAL_SAME_AS_BORROWING_CURRENCY = '13'; // collateral is (mostly) the same currency that is being borrowed
string public constant VL_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 VL_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 VL_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 VL_NO_STABLE_RATE_LOAN_IN_RESERVE = '17'; // 'User does not have a stable rate loan in progress on this reserve'
string public constant VL_NO_VARIABLE_RATE_LOAN_IN_RESERVE = '18'; // 'User does not have a variable rate loan in progress on this reserve'
string public constant VL_UNDERLYING_BALANCE_NOT_GREATER_THAN_0 = '19'; // 'The underlying balance needs to be greater than 0'
string public constant VL_DEPOSIT_ALREADY_IN_USE = '20'; // 'User deposit is already being used as collateral'
string public constant LP_NOT_ENOUGH_STABLE_BORROW_BALANCE = '21'; // 'User does not have any stable rate loan for this reserve'
string public constant LP_INTEREST_RATE_REBALANCE_CONDITIONS_NOT_MET = '22'; // 'Interest rate rebalance conditions were not met'
string public constant LP_LIQUIDATION_CALL_FAILED = '23'; // 'Liquidation call failed'
string public constant LP_NOT_ENOUGH_LIQUIDITY_TO_BORROW = '24'; // 'There is not enough liquidity available to borrow'
string public constant LP_REQUESTED_AMOUNT_TOO_SMALL = '25'; // 'The requested amount is too small for a FlashLoan.'
string public constant LP_INCONSISTENT_PROTOCOL_ACTUAL_BALANCE = '26'; // 'The actual balance of the protocol is inconsistent'
string public constant LP_CALLER_NOT_LENDING_POOL_CONFIGURATOR = '27'; // 'The actual balance of the protocol is inconsistent'
string public constant LP_INCONSISTENT_FLASHLOAN_PARAMS = '28';
string public constant AT_CALLER_MUST_BE_LENDING_POOL = '29'; // 'The caller of this function must be a lending pool'
string public constant AT_CANNOT_GIVE_ALLVWANCE_TO_HIMSELF = '30'; // 'User cannot give allowance to himself'
string public constant AT_TRANSFER_AMOUNT_NOT_GT_0 = '31'; // 'Transferred amount needs to be greater than zero'
string public constant RL_RESERVE_ALREADY_INITIALIZED = '32'; // 'Reserve has already been initialized'
string public constant LPC_CALLER_NOT_AAVE_ADMIN = '33'; // 'The caller must be the aave admin'
string public constant LPC_RESERVE_LIQUIDITY_NOT_0 = '34'; // 'The liquidity of the reserve needs to be 0'
string public constant LPC_INVALID_ATOKEN_POOL_ADDRESS = '35'; // 'The liquidity of the reserve needs to be 0'
string public constant LPC_INVALID_STABLE_DEBT_TOKEN_POOL_ADDRESS = '36'; // 'The liquidity of the reserve needs to be 0'
string public constant LPC_INVALID_VARIABLE_DEBT_TOKEN_POOL_ADDRESS = '37'; // 'The liquidity of the reserve needs to be 0'
string public constant LPC_INVALID_STABLE_DEBT_TOKEN_UNDERLYING_ADDRESS = '38'; // 'The liquidity of the reserve needs to be 0'
string public constant LPC_INVALID_VARIABLE_DEBT_TOKEN_UNDERLYING_ADDRESS = '39'; // 'The liquidity of the reserve needs to be 0'
string public constant LPC_INVALID_ADDRESSES_PROVIDER_ID = '40'; // 'The liquidity of the reserve needs to be 0'
string public constant LPAPR_PROVIDER_NOT_REGISTERED = '41'; // 'Provider is not registered'
string public constant LPCM_HEALTH_FACTOR_NOT_BELOW_THRESHOLD = '42'; // 'Health factor is not below the threshold'
string public constant LPCM_COLLATERAL_CANNOT_BE_LIQUIDATED = '43'; // 'The collateral chosen cannot be liquidated'
string public constant LPCM_SPECIFIED_CURRENCY_NOT_BORROWED_BY_USER = '44'; // 'User did not borrow the specified currency'
string public constant LPCM_NOT_ENOUGH_LIQUIDITY_TO_LIQUIDATE = '45'; // "There isn't enough liquidity available to liquidate"
string public constant LPCM_NO_ERRORS = '46'; // 'No errors'
string public constant LP_INVALID_FLASHLOAN_MODE = '47'; //Invalid flashloan mode selected
string public constant MATH_MULTIPLICATION_OVERFLOW = '48';
string public constant MATH_ADDITION_OVERFLOW = '49';
string public constant MATH_DIVISION_BY_ZERO = '50';
string public constant RL_LIQUIDITY_INDEX_OVERFLOW = '51'; // Liquidity index overflows uint128
string public constant RL_VARIABLE_BORROW_INDEX_OVERFLOW = '52'; // Variable borrow index overflows uint128
string public constant RL_LIQUIDITY_RATE_OVERFLOW = '53'; // Liquidity rate overflows uint128
string public constant RL_VARIABLE_BORROW_RATE_OVERFLOW = '54'; // Variable borrow rate overflows uint128
string public constant RL_STABLE_BORROW_RATE_OVERFLOW = '55'; // Stable borrow rate overflows uint128
string public constant AT_INVALID_MINT_AMOUNT = '56'; //invalid amount to mint
string public constant LP_FAILED_REPAY_WITH_COLLATERAL = '57';
string public constant AT_INVALID_BURN_AMOUNT = '58'; //invalid amount to burn
string public constant LP_BORROW_ALLOWANCE_ARE_NOT_ENOUGH = '59'; // User borrows on behalf, but allowance are too small
string public constant LP_FAILED_COLLATERAL_SWAP = '60';
string public constant LP_INVALID_EQUAL_ASSETS_TO_SWAP = '61';
string public constant LP_REENTRANCY_NOT_ALLOWED = '62';
string public constant LP_CALLER_MUST_BE_AN_ATOKEN = '63';
string public constant P_IS_PAUSED = '64'; // 'Pool is paused'
string public constant LP_NO_MORE_RESERVES_ALLOWED = '65';
string public constant LP_INVALID_FLASH_LOAN_EXECUTOR_RETURN = '66';
string public constant RC_INVALID_LTV = '67';
string public constant RC_INVALID_LIQ_THRESHOLD = '68';
string public constant RC_INVALID_LIQ_BONUS = '69';
string public constant RC_INVALID_DECIMALS = '70';
string public constant RC_INVALID_RESERVE_FACTOR = '71';
string public constant LPAPR_INVALID_ADDRESSES_PROVIDER_ID = '72';
string public constant VL_INCONSISTENT_FLASHLOAN_PARAMS = '73';
string public constant LP_INCONSISTENT_PARAMS_LENGTH = '74';
enum CollateralManagerErrors {
NO_ERROR,

View File

@ -133,7 +133,7 @@ library ReserveLogic {
require(
ReserveLogic.InterestRateMode.STABLE == ReserveLogic.InterestRateMode(interestRateMode) ||
ReserveLogic.InterestRateMode.VARIABLE == ReserveLogic.InterestRateMode(interestRateMode),
Errors.INVALID_INTEREST_RATE_MODE_SELECTED
Errors.VL_INVALID_INTEREST_RATE_MODE_SELECTED
);
return
ReserveLogic.InterestRateMode.STABLE == ReserveLogic.InterestRateMode(interestRateMode)
@ -188,7 +188,7 @@ library ReserveLogic {
uint256 result = amountToLiquidityRatio.add(WadRayMath.ray());
result = result.rayMul(reserve.liquidityIndex);
require(result < (1 << 128), Errors.LIQUIDITY_INDEX_OVERFLOW);
require(result < (1 << 128), Errors.RL_LIQUIDITY_INDEX_OVERFLOW);
reserve.liquidityIndex = uint128(result);
}
@ -206,7 +206,7 @@ library ReserveLogic {
address variableDebtTokenAddress,
address interestRateStrategyAddress
) external {
require(reserve.aTokenAddress == address(0), Errors.RESERVE_ALREADY_INITIALIZED);
require(reserve.aTokenAddress == address(0), Errors.RL_RESERVE_ALREADY_INITIALIZED);
if (reserve.liquidityIndex == 0) {
//if the reserve has not been initialized yet
reserve.liquidityIndex = uint128(WadRayMath.ray());
@ -395,7 +395,7 @@ library ReserveLogic {
timestamp
);
newLiquidityIndex = cumulatedLiquidityInterest.rayMul(liquidityIndex);
require(newLiquidityIndex < (1 << 128), Errors.LIQUIDITY_INDEX_OVERFLOW);
require(newLiquidityIndex < (1 << 128), Errors.RL_LIQUIDITY_INDEX_OVERFLOW);
reserve.liquidityIndex = uint128(newLiquidityIndex);
@ -407,7 +407,7 @@ library ReserveLogic {
timestamp
);
newVariableBorrowIndex = cumulatedVariableBorrowInterest.rayMul(variableBorrowIndex);
require(newVariableBorrowIndex < (1 << 128), Errors.VARIABLE_BORROW_INDEX_OVERFLOW);
require(newVariableBorrowIndex < (1 << 128), Errors.RL_VARIABLE_BORROW_INDEX_OVERFLOW);
reserve.variableBorrowIndex = uint128(newVariableBorrowIndex);
}
}

View File

@ -36,9 +36,9 @@ library ValidationLogic {
function validateDeposit(ReserveLogic.ReserveData storage reserve, uint256 amount) external view {
(bool isActive, bool isFreezed, , ) = reserve.configuration.getFlags();
require(amount > 0, Errors.AMOUNT_NOT_GREATER_THAN_0);
require(isActive, Errors.NO_ACTIVE_RESERVE);
require(!isFreezed, Errors.NO_UNFREEZED_RESERVE);
require(amount > 0, Errors.VL_AMOUNT_NOT_GREATER_THAN_0);
require(isActive, Errors.VL_NO_ACTIVE_RESERVE);
require(!isFreezed, Errors.VL_NO_UNFREEZED_RESERVE);
}
/**
@ -62,9 +62,9 @@ library ValidationLogic {
uint256 reservesCount,
address oracle
) external view {
require(amount > 0, Errors.AMOUNT_NOT_GREATER_THAN_0);
require(amount > 0, Errors.VL_AMOUNT_NOT_GREATER_THAN_0);
require(amount <= userBalance, Errors.NOT_ENOUGH_AVAILABLE_USER_BALANCE);
require(amount <= userBalance, Errors.VL_NOT_ENOUGH_AVAILABLE_USER_BALANCE);
require(
GenericLogic.balanceDecreaseAllowed(
@ -77,7 +77,7 @@ library ValidationLogic {
reservesCount,
oracle
),
Errors.TRANSFER_NOT_ALLOWED
Errors.VL_TRANSFER_NOT_ALLOWED
);
}
@ -140,16 +140,16 @@ library ValidationLogic {
vars.stableRateBorrowingEnabled
) = reserve.configuration.getFlags();
require(vars.isActive, Errors.NO_ACTIVE_RESERVE);
require(!vars.isFreezed, Errors.NO_UNFREEZED_RESERVE);
require(vars.isActive, Errors.VL_NO_ACTIVE_RESERVE);
require(!vars.isFreezed, Errors.VL_NO_UNFREEZED_RESERVE);
require(vars.borrowingEnabled, Errors.BORROWING_NOT_ENABLED);
require(vars.borrowingEnabled, Errors.VL_BORROWING_NOT_ENABLED);
//validate interest rate mode
require(
uint256(ReserveLogic.InterestRateMode.VARIABLE) == interestRateMode ||
uint256(ReserveLogic.InterestRateMode.STABLE) == interestRateMode,
Errors.INVALID_INTEREST_RATE_MODE_SELECTED
Errors.VL_INVALID_INTEREST_RATE_MODE_SELECTED
);
(
@ -167,11 +167,11 @@ library ValidationLogic {
oracle
);
require(vars.userCollateralBalanceETH > 0, Errors.COLLATERAL_BALANCE_IS_0);
require(vars.userCollateralBalanceETH > 0, Errors.VL_COLLATERAL_BALANCE_IS_0);
require(
vars.healthFactor > GenericLogic.HEALTH_FACTOR_LIQUIDATION_THRESHOLD,
Errors.HEALTH_FACTOR_LOWER_THAN_LIQUIDATION_THRESHOLD
Errors.VL_HEALTH_FACTOR_LOWER_THAN_LIQUIDATION_THRESHOLD
);
//add the current already borrowed amount to the amount requested to calculate the total collateral needed.
@ -181,7 +181,7 @@ library ValidationLogic {
require(
vars.amountOfCollateralNeededETH <= vars.userCollateralBalanceETH,
Errors.COLLATERAL_CANNOT_COVER_NEW_BORROW
Errors.VL_COLLATERAL_CANNOT_COVER_NEW_BORROW
);
/**
@ -196,13 +196,13 @@ 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, Errors.STABLE_BORROWING_NOT_ENABLED);
require(vars.stableRateBorrowingEnabled, Errors.VL_STABLE_BORROWING_NOT_ENABLED);
require(
!userConfig.isUsingAsCollateral(reserve.id) ||
reserve.configuration.getLtv() == 0 ||
amount > IERC20(reserve.aTokenAddress).balanceOf(userAddress),
Errors.CALLATERAL_SAME_AS_BORROWING_CURRENCY
Errors.VL_CALLATERAL_SAME_AS_BORROWING_CURRENCY
);
vars.availableLiquidity = IERC20(asset).balanceOf(reserve.aTokenAddress);
@ -211,7 +211,7 @@ library ValidationLogic {
//available liquidity
uint256 maxLoanSizeStable = vars.availableLiquidity.percentMul(maxStableLoanPercent);
require(amount <= maxLoanSizeStable, Errors.AMOUNT_BIGGER_THAN_MAX_LOAN_SIZE_STABLE);
require(amount <= maxLoanSizeStable, Errors.VL_AMOUNT_BIGGER_THAN_MAX_LOAN_SIZE_STABLE);
}
}
@ -233,21 +233,21 @@ library ValidationLogic {
) external view {
bool isActive = reserve.configuration.getActive();
require(isActive, Errors.NO_ACTIVE_RESERVE);
require(isActive, Errors.VL_NO_ACTIVE_RESERVE);
require(amountSent > 0, Errors.AMOUNT_NOT_GREATER_THAN_0);
require(amountSent > 0, Errors.VL_AMOUNT_NOT_GREATER_THAN_0);
require(
(stableDebt > 0 &&
ReserveLogic.InterestRateMode(rateMode) == ReserveLogic.InterestRateMode.STABLE) ||
(variableDebt > 0 &&
ReserveLogic.InterestRateMode(rateMode) == ReserveLogic.InterestRateMode.VARIABLE),
Errors.NO_DEBT_OF_SELECTED_TYPE
Errors.VL_NO_DEBT_OF_SELECTED_TYPE
);
require(
amountSent != uint256(-1) || msg.sender == onBehalfOf,
Errors.NO_EXPLICIT_AMOUNT_TO_REPAY_ON_BEHALF
Errors.VL_NO_EXPLICIT_AMOUNT_TO_REPAY_ON_BEHALF
);
}
@ -268,13 +268,13 @@ library ValidationLogic {
) external view {
(bool isActive, bool isFreezed, , bool stableRateEnabled) = reserve.configuration.getFlags();
require(isActive, Errors.NO_ACTIVE_RESERVE);
require(!isFreezed, Errors.NO_UNFREEZED_RESERVE);
require(isActive, Errors.VL_NO_ACTIVE_RESERVE);
require(!isFreezed, Errors.VL_NO_UNFREEZED_RESERVE);
if (currentRateMode == ReserveLogic.InterestRateMode.STABLE) {
require(stableDebt > 0, Errors.NO_STABLE_RATE_LOAN_IN_RESERVE);
require(stableDebt > 0, Errors.VL_NO_STABLE_RATE_LOAN_IN_RESERVE);
} else if (currentRateMode == ReserveLogic.InterestRateMode.VARIABLE) {
require(variableDebt > 0, Errors.NO_VARIABLE_RATE_LOAN_IN_RESERVE);
require(variableDebt > 0, Errors.VL_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
@ -282,16 +282,16 @@ library ValidationLogic {
* more collateral than he is borrowing, artificially lowering
* the interest rate, borrowing at variable, and switching to stable
**/
require(stableRateEnabled, Errors.STABLE_BORROWING_NOT_ENABLED);
require(stableRateEnabled, Errors.VL_STABLE_BORROWING_NOT_ENABLED);
require(
!userConfig.isUsingAsCollateral(reserve.id) ||
reserve.configuration.getLtv() == 0 ||
stableDebt.add(variableDebt) > IERC20(reserve.aTokenAddress).balanceOf(msg.sender),
Errors.CALLATERAL_SAME_AS_BORROWING_CURRENCY
Errors.VL_CALLATERAL_SAME_AS_BORROWING_CURRENCY
);
} else {
revert(Errors.INVALID_INTEREST_RATE_MODE_SELECTED);
revert(Errors.VL_INVALID_INTEREST_RATE_MODE_SELECTED);
}
}
@ -315,7 +315,7 @@ library ValidationLogic {
) external view {
uint256 underlyingBalance = IERC20(reserve.aTokenAddress).balanceOf(msg.sender);
require(underlyingBalance > 0, Errors.UNDERLYING_BALANCE_NOT_GREATER_THAN_0);
require(underlyingBalance > 0, Errors.VL_UNDERLYING_BALANCE_NOT_GREATER_THAN_0);
require(
GenericLogic.balanceDecreaseAllowed(
@ -328,7 +328,7 @@ library ValidationLogic {
reservesCount,
oracle
),
Errors.DEPOSIT_ALREADY_IN_USE
Errors.VL_DEPOSIT_ALREADY_IN_USE
);
}
@ -338,7 +338,7 @@ library ValidationLogic {
* @param amounts the amounts for each asset being borrowed
**/
function validateFlashloan(address[] memory assets, uint256[] memory amounts) internal pure {
require(assets.length == amounts.length, Errors.INCONSISTENT_FLASHLOAN_PARAMS);
require(assets.length == amounts.length, Errors.VL_INCONSISTENT_FLASHLOAN_PARAMS);
}
/**
@ -361,13 +361,16 @@ library ValidationLogic {
if (
!collateralReserve.configuration.getActive() || !principalReserve.configuration.getActive()
) {
return (uint256(Errors.CollateralManagerErrors.NO_ACTIVE_RESERVE), Errors.NO_ACTIVE_RESERVE);
return (
uint256(Errors.CollateralManagerErrors.NO_ACTIVE_RESERVE),
Errors.VL_NO_ACTIVE_RESERVE
);
}
if (userHealthFactor >= GenericLogic.HEALTH_FACTOR_LIQUIDATION_THRESHOLD) {
return (
uint256(Errors.CollateralManagerErrors.HEALTH_FACTOR_ABOVE_THRESHOLD),
Errors.HEALTH_FACTOR_NOT_BELOW_THRESHOLD
Errors.LPCM_HEALTH_FACTOR_NOT_BELOW_THRESHOLD
);
}
@ -378,18 +381,18 @@ library ValidationLogic {
if (!isCollateralEnabled) {
return (
uint256(Errors.CollateralManagerErrors.COLLATERAL_CANNOT_BE_LIQUIDATED),
Errors.COLLATERAL_CANNOT_BE_LIQUIDATED
Errors.LPCM_COLLATERAL_CANNOT_BE_LIQUIDATED
);
}
if (userStableDebt == 0 && userVariableDebt == 0) {
return (
uint256(Errors.CollateralManagerErrors.CURRRENCY_NOT_BORROWED),
Errors.SPECIFIED_CURRENCY_NOT_BORROWED_BY_USER
Errors.LPCM_SPECIFIED_CURRENCY_NOT_BORROWED_BY_USER
);
}
return (uint256(Errors.CollateralManagerErrors.NO_ERROR), Errors.NO_ERRORS);
return (uint256(Errors.CollateralManagerErrors.NO_ERROR), Errors.LPCM_NO_ERRORS);
}
/**
@ -419,7 +422,7 @@ library ValidationLogic {
require(
healthFactor >= GenericLogic.HEALTH_FACTOR_LIQUIDATION_THRESHOLD,
Errors.TRANSFER_NOT_ALLOWED
Errors.VL_TRANSFER_NOT_ALLOWED
);
}
}

View File

@ -28,7 +28,7 @@ library PercentageMath {
require(
value <= (type(uint256).max - HALF_PERCENT) / percentage,
Errors.MULTIPLICATION_OVERFLOW
Errors.MATH_MULTIPLICATION_OVERFLOW
);
return (value * percentage + HALF_PERCENT) / PERCENTAGE_FACTOR;
@ -41,12 +41,12 @@ library PercentageMath {
* @return the value divided the percentage
**/
function percentDiv(uint256 value, uint256 percentage) internal pure returns (uint256) {
require(percentage != 0, Errors.DIVISION_BY_ZERO);
require(percentage != 0, Errors.MATH_DIVISION_BY_ZERO);
uint256 halfPercentage = percentage / 2;
require(
value <= (type(uint256).max - halfPercentage) / PERCENTAGE_FACTOR,
Errors.MULTIPLICATION_OVERFLOW
Errors.MATH_MULTIPLICATION_OVERFLOW
);
return (value * PERCENTAGE_FACTOR + halfPercentage) / percentage;

View File

@ -58,7 +58,7 @@ library WadRayMath {
return 0;
}
require(a <= (type(uint256).max - halfWAD) / b, Errors.MULTIPLICATION_OVERFLOW);
require(a <= (type(uint256).max - halfWAD) / b, Errors.MATH_MULTIPLICATION_OVERFLOW);
return (a * b + halfWAD) / WAD;
}
@ -70,10 +70,10 @@ library WadRayMath {
* @return the result of a/b, in wad
**/
function wadDiv(uint256 a, uint256 b) internal pure returns (uint256) {
require(b != 0, Errors.DIVISION_BY_ZERO);
require(b != 0, Errors.MATH_DIVISION_BY_ZERO);
uint256 halfB = b / 2;
require(a <= (type(uint256).max - halfB) / WAD, Errors.MULTIPLICATION_OVERFLOW);
require(a <= (type(uint256).max - halfB) / WAD, Errors.MATH_MULTIPLICATION_OVERFLOW);
return (a * WAD + halfB) / b;
}
@ -89,7 +89,7 @@ library WadRayMath {
return 0;
}
require(a <= (type(uint256).max - halfRAY) / b, Errors.MULTIPLICATION_OVERFLOW);
require(a <= (type(uint256).max - halfRAY) / b, Errors.MATH_MULTIPLICATION_OVERFLOW);
return (a * b + halfRAY) / RAY;
}
@ -101,10 +101,10 @@ library WadRayMath {
* @return the result of a/b, in ray
**/
function rayDiv(uint256 a, uint256 b) internal pure returns (uint256) {
require(b != 0, Errors.DIVISION_BY_ZERO);
require(b != 0, Errors.MATH_DIVISION_BY_ZERO);
uint256 halfB = b / 2;
require(a <= (type(uint256).max - halfB) / RAY, Errors.MULTIPLICATION_OVERFLOW);
require(a <= (type(uint256).max - halfB) / RAY, Errors.MATH_MULTIPLICATION_OVERFLOW);
return (a * RAY + halfB) / b;
}
@ -117,7 +117,7 @@ library WadRayMath {
function rayToWad(uint256 a) internal pure returns (uint256) {
uint256 halfRatio = WAD_RAY_RATIO / 2;
uint256 result = halfRatio + a;
require(result >= halfRatio, Errors.ADDITION_OVERFLOW);
require(result >= halfRatio, Errors.MATH_ADDITION_OVERFLOW);
return result / WAD_RAY_RATIO;
}
@ -129,7 +129,7 @@ library WadRayMath {
**/
function wadToRay(uint256 a) internal pure returns (uint256) {
uint256 result = a * WAD_RAY_RATIO;
require(result / WAD_RAY_RATIO == a, Errors.MULTIPLICATION_OVERFLOW);
require(result / WAD_RAY_RATIO == a, Errors.MATH_MULTIPLICATION_OVERFLOW);
return result;
}
}

View File

@ -40,7 +40,7 @@ contract AToken is VersionedInitializable, IncentivizedERC20, IAToken {
bytes32 public DOMAIN_SEPARATOR;
modifier onlyLendingPool {
require(_msgSender() == address(POOL), Errors.CALLER_MUST_BE_LENDING_POOL);
require(_msgSender() == address(POOL), Errors.AT_CALLER_MUST_BE_LENDING_POOL);
_;
}
@ -100,7 +100,7 @@ contract AToken is VersionedInitializable, IncentivizedERC20, IAToken {
uint256 index
) external override onlyLendingPool {
uint256 amountScaled = amount.rayDiv(index);
require(amountScaled != 0, Errors.INVALID_BURN_AMOUNT);
require(amountScaled != 0, Errors.AT_INVALID_BURN_AMOUNT);
_burn(user, amountScaled);
//transfers the underlying to the target
@ -127,7 +127,7 @@ contract AToken is VersionedInitializable, IncentivizedERC20, IAToken {
uint256 previousBalance = super.balanceOf(user);
uint256 amountScaled = amount.rayDiv(index);
require(amountScaled != 0, Errors.INVALID_MINT_AMOUNT);
require(amountScaled != 0, Errors.AT_INVALID_MINT_AMOUNT);
_mint(user, amountScaled);
//transfer event to track balances

View File

@ -60,7 +60,7 @@ contract VariableDebtToken is DebtTokenBase, IVariableDebtToken {
) external override onlyLendingPool returns (bool) {
uint256 previousBalance = super.balanceOf(user);
uint256 amountScaled = amount.rayDiv(index);
require(amountScaled != 0, Errors.INVALID_MINT_AMOUNT);
require(amountScaled != 0, Errors.AT_INVALID_MINT_AMOUNT);
_mint(user, amountScaled);
@ -81,7 +81,7 @@ contract VariableDebtToken is DebtTokenBase, IVariableDebtToken {
uint256 index
) external override onlyLendingPool {
uint256 amountScaled = amount.rayDiv(index);
require(amountScaled != 0, Errors.INVALID_BURN_AMOUNT);
require(amountScaled != 0, Errors.AT_INVALID_BURN_AMOUNT);
_burn(user, amountScaled);

View File

@ -23,7 +23,7 @@ abstract contract DebtTokenBase is IncentivizedERC20, VersionedInitializable {
* @dev Only lending pool can call functions marked by this modifier
**/
modifier onlyLendingPool {
require(_msgSender() == address(POOL), Errors.CALLER_MUST_BE_LENDING_POOL);
require(_msgSender() == address(POOL), Errors.AT_CALLER_MUST_BE_LENDING_POOL);
_;
}

View File

@ -198,7 +198,7 @@
},
"ATokensAndRatesHelper": {
"buidlerevm": {
"address": "0x06bA8d8af0dF898D0712DffFb0f862cC51AF45c2",
"address": "0x920d847fE49E54C19047ba8bc236C45A8068Bca7",
"deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6"
}
},
@ -266,4 +266,4 @@
"deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6"
}
}
}
}

View File

@ -33,7 +33,10 @@ import {
LendingRateOracleFactory,
MintableErc20Factory,
MockAggregatorFactory,
MockATokenFactory,
MockFlashLoanReceiverFactory,
MockStableDebtTokenFactory,
MockVariableDebtTokenFactory,
PriceOracleFactory,
ReserveLogicFactory,
StableDebtTokenFactory,
@ -42,6 +45,8 @@ import {
} from '../types';
import {withSaveAndVerify, registerContractInJsonDb, linkBytecode} from './contracts-helpers';
import {StableAndVariableTokensHelperFactory} from '../types/StableAndVariableTokensHelperFactory';
import {MockStableDebtToken} from '../types/MockStableDebtToken';
import {MockVariableDebtToken} from '../types/MockVariableDebtToken';
export const deployLendingPoolAddressesProvider = async (verify?: boolean) =>
withSaveAndVerify(
@ -373,3 +378,36 @@ export const deployATokensAndRatesHelper = async (
args,
verify
);
export const deployMockStableDebtToken = async (
args: [tEthereumAddress, tEthereumAddress, string, string, tEthereumAddress],
verify?: boolean
) =>
withSaveAndVerify(
await new MockStableDebtTokenFactory(await getFirstSigner()).deploy(...args),
eContractid.ATokensAndRatesHelper,
args,
verify
);
export const deployMockVariableDebtToken = async (
args: [tEthereumAddress, tEthereumAddress, string, string, tEthereumAddress],
verify?: boolean
) =>
withSaveAndVerify(
await new MockVariableDebtTokenFactory(await getFirstSigner()).deploy(...args),
eContractid.ATokensAndRatesHelper,
args,
verify
);
export const deployMockAToken = async (
args: [tEthereumAddress, tEthereumAddress, tEthereumAddress, string, string, tEthereumAddress],
verify?: boolean
) =>
withSaveAndVerify(
await new MockATokenFactory(await getFirstSigner()).deploy(...args),
eContractid.ATokensAndRatesHelper,
args,
verify
);

View File

@ -10,7 +10,10 @@ import {
LendingPoolFactory,
LendingRateOracleFactory,
MintableErc20Factory,
MockATokenFactory,
MockFlashLoanReceiverFactory,
MockStableDebtTokenFactory,
MockVariableDebtTokenFactory,
PriceOracleFactory,
ReserveLogicFactory,
StableAndVariableTokensHelperFactory,
@ -222,3 +225,23 @@ export const getATokensAndRatesHelper = async (address?: tEthereumAddress) =>
.address,
await getFirstSigner()
);
export const getMockAToken = async (address?: tEthereumAddress) =>
await MockATokenFactory.connect(
address || (await getDb().get(`${eContractid.MockAToken}.${BRE.network.name}`).value()).address,
await getFirstSigner()
);
export const getMockVariableDebtToken = async (address?: tEthereumAddress) =>
await MockVariableDebtTokenFactory.connect(
address ||
(await getDb().get(`${eContractid.MockVariableDebtToken}.${BRE.network.name}`).value())
.address,
await getFirstSigner()
);
export const getMockStableDebtToken = async (address?: tEthereumAddress) =>
await MockStableDebtTokenFactory.connect(
address ||
(await getDb().get(`${eContractid.MockStableDebtToken}.${BRE.network.name}`).value()).address,
await getFirstSigner()
);

View File

@ -59,72 +59,91 @@ export enum eContractid {
ATokensAndRatesHelper = 'ATokensAndRatesHelper',
}
/*
* Error messages prefix glossary:
* - VL = ValidationLogic
* - MATH = Math libraries
* - AT = aToken or DebtTokens
* - LP = LendingPool
* - LPAPR = LendingPoolAddressesProviderRegistry
* - LPC = LendingPoolConfiguration
* - RL = ReserveLogic
* - LPCM = LendingPoolCollateralManager
* - P = Pausable
*/
export enum ProtocolErrors {
// 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'
INVALID_EQUAL_ASSETS_TO_SWAP = '56', // User can't use same reserve as destination of liquidity swap
// 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'
BORROW_ALLOWANCE_ARE_NOT_ENOUGH = '54', // User borrows on behalf, but allowance are too small
INVALID_FLASH_LOAN_EXECUTOR_RETURN = '60', // The flash loan received returned 0 (EOA)
// require error messages - aToken
CALLER_MUST_BE_LENDING_POOL = '28', // 'The caller of this function must be a lending pool'
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'
// require error messages - ReserveLogic
RESERVE_ALREADY_INITIALIZED = '34', // 'Reserve has already been initialized'
//require error messages - LendingPoolConfiguration
CALLER_NOT_AAVE_ADMIN = '35', // 'The caller must be the aave admin'
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'
INVALID_ADDRESSES_PROVIDER_ID = '68',
//return error messages - LendingPoolCollateralManager
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'
INVALID_FLASHLOAN_MODE = '43', //Invalid flashloan mode
IS_PAUSED = '58', // Pool is paused
INVALID_LTV = '70',
INVALID_LIQ_THRESHOLD = '71',
INVALID_LIQ_BONUS = '72',
INVALID_DECIMALS = '73',
INVALID_RESERVE_FACTOR = '74',
VL_AMOUNT_NOT_GREATER_THAN_0 = '1', // 'Amount must be greater than 0'
VL_NO_ACTIVE_RESERVE = '2', // 'Action requires an active reserve'
VL_NO_UNFREEZED_RESERVE = '3', // 'Action requires an unfreezed reserve'
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_TRANSFER_NOT_ALLOWED = '6', // 'Transfer cannot be allowed.'
VL_BORROWING_NOT_ENABLED = '7', // 'Borrowing is not enabled'
VL_INVALID_INTEREST_RATE_MODE_SELECTED = '8', // 'Invalid interest rate mode selected'
VL_COLLATERAL_BALANCE_IS_0 = '9', // 'The collateral balance is 0'
VL_HEALTH_FACTOR_LOWER_THAN_LIQUIDATION_THRESHOLD = '10', // 'Health factor is lesser than the liquidation threshold'
VL_COLLATERAL_CANNOT_COVER_NEW_BORROW = '11', // 'There is not enough collateral to cover a new borrow'
VL_STABLE_BORROWING_NOT_ENABLED = '12', // stable borrowing not enabled
VL_CALLATERAL_SAME_AS_BORROWING_CURRENCY = '13', // collateral is (mostly) the same currency that is being borrowed
VL_AMOUNT_BIGGER_THAN_MAX_LOAN_SIZE_STABLE = '14', // 'The requested amount is greater than the max loan size in stable rate mode
VL_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'
VL_NO_EXPLICIT_AMOUNT_TO_REPAY_ON_BEHALF = '16', // 'To repay on behalf of an user an explicit amount to repay is needed'
VL_NO_STABLE_RATE_LOAN_IN_RESERVE = '17', // 'User does not have a stable rate loan in progress on this reserve'
VL_NO_VARIABLE_RATE_LOAN_IN_RESERVE = '18', // 'User does not have a variable rate loan in progress on this reserve'
VL_UNDERLYING_BALANCE_NOT_GREATER_THAN_0 = '19', // 'The underlying balance needs to be greater than 0'
VL_DEPOSIT_ALREADY_IN_USE = '20', // 'User deposit is already being used as collateral'
LP_NOT_ENOUGH_STABLE_BORROW_BALANCE = '21', // 'User does not have any stable rate loan for this reserve'
LP_INTEREST_RATE_REBALANCE_CONDITIONS_NOT_MET = '22', // 'Interest rate rebalance conditions were not met'
LP_LIQUIDATION_CALL_FAILED = '23', // 'Liquidation call failed'
LP_NOT_ENOUGH_LIQUIDITY_TO_BORROW = '24', // 'There is not enough liquidity available to borrow'
LP_REQUESTED_AMOUNT_TOO_SMALL = '25', // 'The requested amount is too small for a FlashLoan.'
LP_INCONSISTENT_PROTOCOL_ACTUAL_BALANCE = '26', // 'The actual balance of the protocol is inconsistent'
LP_CALLER_NOT_LENDING_POOL_CONFIGURATOR = '27', // 'The actual balance of the protocol is inconsistent'
LP_INCONSISTENT_FLASHLOAN_PARAMS = '28',
AT_CALLER_MUST_BE_LENDING_POOL = '29', // 'The caller of this function must be a lending pool'
AT_CANNOT_GIVE_ALLVWANCE_TO_HIMSELF = '30', // 'User cannot give allowance to himself'
AT_TRANSFER_AMOUNT_NOT_GT_0 = '31', // 'Transferred amount needs to be greater than zero'
RL_RESERVE_ALREADY_INITIALIZED = '32', // 'Reserve has already been initialized'
LPC_CALLER_NOT_AAVE_ADMIN = '33', // 'The caller must be the aave admin'
LPC_RESERVE_LIQUIDITY_NOT_0 = '34', // 'The liquidity of the reserve needs to be 0'
LPC_INVALID_ATOKEN_POOL_ADDRESS = '35', // 'The liquidity of the reserve needs to be 0'
LPC_INVALID_STABLE_DEBT_TOKEN_POOL_ADDRESS = '36', // 'The liquidity of the reserve needs to be 0'
LPC_INVALID_VARIABLE_DEBT_TOKEN_POOL_ADDRESS = '37', // 'The liquidity of the reserve needs to be 0'
LPC_INVALID_STABLE_DEBT_TOKEN_UNDERLYING_ADDRESS = '38', // 'The liquidity of the reserve needs to be 0'
LPC_INVALID_VARIABLE_DEBT_TOKEN_UNDERLYING_ADDRESS = '39', // 'The liquidity of the reserve needs to be 0'
LPC_INVALID_ADDRESSES_PROVIDER_ID = '40', // 'The liquidity of the reserve needs to be 0'
LPAPR_PROVIDER_NOT_REGISTERED = '41', // 'Provider is not registered'
LPCM_HEALTH_FACTOR_NOT_BELOW_THRESHOLD = '42', // 'Health factor is not below the threshold'
LPCM_COLLATERAL_CANNOT_BE_LIQUIDATED = '43', // 'The collateral chosen cannot be liquidated'
LPCM_SPECIFIED_CURRENCY_NOT_BORROWED_BY_USER = '44', // 'User did not borrow the specified currency'
LPCM_NOT_ENOUGH_LIQUIDITY_TO_LIQUIDATE = '45', // "There isn't enough liquidity available to liquidate"
LPCM_NO_ERRORS = '46', // 'No errors'
LP_INVALID_FLASHLOAN_MODE = '47', //Invalid flashloan mode selected
MATH_MULTIPLICATION_OVERFLOW = '48',
MATH_ADDITION_OVERFLOW = '49',
MATH_DIVISION_BY_ZERO = '50',
RL_LIQUIDITY_INDEX_OVERFLOW = '51', // Liquidity index overflows uint128
RL_VARIABLE_BORROW_INDEX_OVERFLOW = '52', // Variable borrow index overflows uint128
RL_LIQUIDITY_RATE_OVERFLOW = '53', // Liquidity rate overflows uint128
RL_VARIABLE_BORROW_RATE_OVERFLOW = '54', // Variable borrow rate overflows uint128
RL_STABLE_BORROW_RATE_OVERFLOW = '55', // Stable borrow rate overflows uint128
AT_INVALID_MINT_AMOUNT = '56', //invalid amount to mint
LP_FAILED_REPAY_WITH_COLLATERAL = '57',
AT_INVALID_BURN_AMOUNT = '58', //invalid amount to burn
LP_BORROW_ALLOWANCE_ARE_NOT_ENOUGH = '59', // User borrows on behalf, but allowance are too small
LP_FAILED_COLLATERAL_SWAP = '60',
LP_INVALID_EQUAL_ASSETS_TO_SWAP = '61',
LP_REENTRANCY_NOT_ALLOWED = '62',
LP_CALLER_MUST_BE_AN_ATOKEN = '63',
P_IS_PAUSED = '64', // 'Pool is paused'
LP_NO_MORE_RESERVES_ALLOWED = '65',
LP_INVALID_FLASH_LOAN_EXECUTOR_RETURN = '66',
RC_INVALID_LTV = '67',
RC_INVALID_LIQ_THRESHOLD = '68',
RC_INVALID_LIQ_BONUS = '69',
RC_INVALID_DECIMALS = '70',
RC_INVALID_RESERVE_FACTOR = '71',
LPAPR_INVALID_ADDRESSES_PROVIDER_ID = '72',
// old

View File

@ -19,10 +19,10 @@ makeSuite('AddressesProviderRegistry', (testEnv: TestEnv) => {
it('tries to register an addresses provider with id 0', async () => {
const {users, registry} = testEnv;
const {INVALID_ADDRESSES_PROVIDER_ID} = ProtocolErrors;
const {LPAPR_INVALID_ADDRESSES_PROVIDER_ID} = ProtocolErrors;
await expect(registry.registerAddressesProvider(users[2].address, '0')).to.be.revertedWith(
INVALID_ADDRESSES_PROVIDER_ID
LPAPR_INVALID_ADDRESSES_PROVIDER_ID
);
});
@ -62,22 +62,22 @@ makeSuite('AddressesProviderRegistry', (testEnv: TestEnv) => {
});
it('Tries to remove a unregistered addressesProvider', async () => {
const {PROVIDER_NOT_REGISTERED} = ProtocolErrors;
const {LPAPR_PROVIDER_NOT_REGISTERED} = ProtocolErrors;
const {users, registry} = testEnv;
await expect(registry.unregisterAddressesProvider(users[2].address)).to.be.revertedWith(
PROVIDER_NOT_REGISTERED
LPAPR_PROVIDER_NOT_REGISTERED
);
});
it('Tries to remove a unregistered addressesProvider', async () => {
const {PROVIDER_NOT_REGISTERED} = ProtocolErrors;
const {LPAPR_PROVIDER_NOT_REGISTERED} = ProtocolErrors;
const {users, registry} = testEnv;
await expect(registry.unregisterAddressesProvider(users[2].address)).to.be.revertedWith(
PROVIDER_NOT_REGISTERED
LPAPR_PROVIDER_NOT_REGISTERED
);
});

View File

@ -3,19 +3,19 @@ import {makeSuite, TestEnv} from './helpers/make-suite';
import {ProtocolErrors} from '../helpers/types';
makeSuite('AToken: Modifiers', (testEnv: TestEnv) => {
const {CALLER_MUST_BE_LENDING_POOL} = ProtocolErrors;
const {AT_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', '1')).to.be.revertedWith(
CALLER_MUST_BE_LENDING_POOL
AT_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', '1')).to.be.revertedWith(
CALLER_MUST_BE_LENDING_POOL
AT_CALLER_MUST_BE_LENDING_POOL
);
});
@ -23,13 +23,13 @@ makeSuite('AToken: Modifiers', (testEnv: TestEnv) => {
const {deployer, users, aDai} = testEnv;
await expect(
aDai.transferOnLiquidation(deployer.address, users[0].address, '1')
).to.be.revertedWith(CALLER_MUST_BE_LENDING_POOL);
).to.be.revertedWith(AT_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(
CALLER_MUST_BE_LENDING_POOL
AT_CALLER_MUST_BE_LENDING_POOL
);
});
});

View File

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

View File

@ -11,13 +11,13 @@ const {expect} = require('chai');
makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
const {
CALLER_NOT_AAVE_ADMIN,
RESERVE_LIQUIDITY_NOT_0,
INVALID_LTV,
INVALID_LIQ_THRESHOLD,
INVALID_LIQ_BONUS,
INVALID_DECIMALS,
INVALID_RESERVE_FACTOR,
LPC_CALLER_NOT_AAVE_ADMIN,
LPC_RESERVE_LIQUIDITY_NOT_0,
RC_INVALID_LTV,
RC_INVALID_LIQ_THRESHOLD,
RC_INVALID_LIQ_BONUS,
RC_INVALID_DECIMALS,
RC_INVALID_RESERVE_FACTOR,
} = ProtocolErrors;
it('Reverts trying to set an invalid LTV', async () => {
@ -25,7 +25,7 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
const invalidLtv = 65536;
await expect(configurator.setLtv(weth.address, invalidLtv)).to.be.revertedWith(INVALID_LTV);
await expect(configurator.setLtv(weth.address, invalidLtv)).to.be.revertedWith(RC_INVALID_LTV);
});
it('Reverts trying to set an invalid liquidation threshold', async () => {
@ -35,7 +35,7 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
await expect(
configurator.setLiquidationThreshold(weth.address, invalidLiqThreshold)
).to.be.revertedWith(INVALID_LIQ_THRESHOLD);
).to.be.revertedWith(RC_INVALID_LIQ_THRESHOLD);
});
it('Reverts trying to set an invalid liquidation bonus', async () => {
@ -45,7 +45,7 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
await expect(
configurator.setLiquidationBonus(weth.address, invalidLiqBonus)
).to.be.revertedWith(INVALID_LIQ_BONUS);
).to.be.revertedWith(RC_INVALID_LIQ_BONUS);
});
it('Reverts trying to set an invalid reserve decimals', async () => {
@ -54,7 +54,7 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
const invalidDecimals = 256;
await expect(configurator.setReserveDecimals(weth.address, invalidDecimals)).to.be.revertedWith(
INVALID_DECIMALS
RC_INVALID_DECIMALS
);
});
@ -65,7 +65,7 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
await expect(
configurator.setReserveFactor(weth.address, invalidReserveFactor)
).to.be.revertedWith(INVALID_RESERVE_FACTOR);
).to.be.revertedWith(RC_INVALID_RESERVE_FACTOR);
});
it('Deactivates the ETH reserve', async () => {
@ -87,16 +87,16 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
const {configurator, users, weth} = testEnv;
await expect(
configurator.connect(users[2].signer).deactivateReserve(weth.address),
CALLER_NOT_AAVE_ADMIN
).to.be.revertedWith(CALLER_NOT_AAVE_ADMIN);
LPC_CALLER_NOT_AAVE_ADMIN
).to.be.revertedWith(LPC_CALLER_NOT_AAVE_ADMIN);
});
it('Check the onlyAaveAdmin on activateReserve ', async () => {
const {configurator, users, weth} = testEnv;
await expect(
configurator.connect(users[2].signer).activateReserve(weth.address),
CALLER_NOT_AAVE_ADMIN
).to.be.revertedWith(CALLER_NOT_AAVE_ADMIN);
LPC_CALLER_NOT_AAVE_ADMIN
).to.be.revertedWith(LPC_CALLER_NOT_AAVE_ADMIN);
});
it('Freezes the ETH reserve', async () => {
@ -156,16 +156,16 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
const {configurator, users, weth} = testEnv;
await expect(
configurator.connect(users[2].signer).freezeReserve(weth.address),
CALLER_NOT_AAVE_ADMIN
).to.be.revertedWith(CALLER_NOT_AAVE_ADMIN);
LPC_CALLER_NOT_AAVE_ADMIN
).to.be.revertedWith(LPC_CALLER_NOT_AAVE_ADMIN);
});
it('Check the onlyAaveAdmin on unfreezeReserve ', async () => {
const {configurator, users, weth} = testEnv;
await expect(
configurator.connect(users[2].signer).unfreezeReserve(weth.address),
CALLER_NOT_AAVE_ADMIN
).to.be.revertedWith(CALLER_NOT_AAVE_ADMIN);
LPC_CALLER_NOT_AAVE_ADMIN
).to.be.revertedWith(LPC_CALLER_NOT_AAVE_ADMIN);
});
it('Deactivates the ETH reserve for borrowing', async () => {
@ -228,16 +228,16 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
const {configurator, users, weth} = testEnv;
await expect(
configurator.connect(users[2].signer).disableBorrowingOnReserve(weth.address),
CALLER_NOT_AAVE_ADMIN
).to.be.revertedWith(CALLER_NOT_AAVE_ADMIN);
LPC_CALLER_NOT_AAVE_ADMIN
).to.be.revertedWith(LPC_CALLER_NOT_AAVE_ADMIN);
});
it('Check the onlyAaveAdmin on enableBorrowingOnReserve ', async () => {
const {configurator, users, weth} = testEnv;
await expect(
configurator.connect(users[2].signer).enableBorrowingOnReserve(weth.address, true),
CALLER_NOT_AAVE_ADMIN
).to.be.revertedWith(CALLER_NOT_AAVE_ADMIN);
LPC_CALLER_NOT_AAVE_ADMIN
).to.be.revertedWith(LPC_CALLER_NOT_AAVE_ADMIN);
});
it('Deactivates the ETH reserve as collateral', async () => {
@ -297,8 +297,8 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
const {configurator, users, weth} = testEnv;
await expect(
configurator.connect(users[2].signer).disableReserveAsCollateral(weth.address),
CALLER_NOT_AAVE_ADMIN
).to.be.revertedWith(CALLER_NOT_AAVE_ADMIN);
LPC_CALLER_NOT_AAVE_ADMIN
).to.be.revertedWith(LPC_CALLER_NOT_AAVE_ADMIN);
});
it('Check the onlyAaveAdmin on enableReserveAsCollateral ', async () => {
@ -307,8 +307,8 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
configurator
.connect(users[2].signer)
.enableReserveAsCollateral(weth.address, '75', '80', '105'),
CALLER_NOT_AAVE_ADMIN
).to.be.revertedWith(CALLER_NOT_AAVE_ADMIN);
LPC_CALLER_NOT_AAVE_ADMIN
).to.be.revertedWith(LPC_CALLER_NOT_AAVE_ADMIN);
});
it('Disable stable borrow rate on the ETH reserve', async () => {
@ -367,16 +367,16 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
const {configurator, users, weth} = testEnv;
await expect(
configurator.connect(users[2].signer).disableReserveStableRate(weth.address),
CALLER_NOT_AAVE_ADMIN
).to.be.revertedWith(CALLER_NOT_AAVE_ADMIN);
LPC_CALLER_NOT_AAVE_ADMIN
).to.be.revertedWith(LPC_CALLER_NOT_AAVE_ADMIN);
});
it('Check the onlyAaveAdmin on enableReserveStableRate', async () => {
const {configurator, users, weth} = testEnv;
await expect(
configurator.connect(users[2].signer).enableReserveStableRate(weth.address),
CALLER_NOT_AAVE_ADMIN
).to.be.revertedWith(CALLER_NOT_AAVE_ADMIN);
LPC_CALLER_NOT_AAVE_ADMIN
).to.be.revertedWith(LPC_CALLER_NOT_AAVE_ADMIN);
});
it('Changes LTV of the reserve', async () => {
@ -409,8 +409,8 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
const {configurator, users, weth} = testEnv;
await expect(
configurator.connect(users[2].signer).setLtv(weth.address, '75'),
CALLER_NOT_AAVE_ADMIN
).to.be.revertedWith(CALLER_NOT_AAVE_ADMIN);
LPC_CALLER_NOT_AAVE_ADMIN
).to.be.revertedWith(LPC_CALLER_NOT_AAVE_ADMIN);
});
it('Changes the reserve factor of the reserve', async () => {
@ -443,8 +443,8 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
const {configurator, users, weth} = testEnv;
await expect(
configurator.connect(users[2].signer).setReserveFactor(weth.address, '2000'),
CALLER_NOT_AAVE_ADMIN
).to.be.revertedWith(CALLER_NOT_AAVE_ADMIN);
LPC_CALLER_NOT_AAVE_ADMIN
).to.be.revertedWith(LPC_CALLER_NOT_AAVE_ADMIN);
});
it('Changes liquidation threshold of the reserve', async () => {
@ -477,8 +477,8 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
const {configurator, users, weth} = testEnv;
await expect(
configurator.connect(users[2].signer).setLiquidationThreshold(weth.address, '80'),
CALLER_NOT_AAVE_ADMIN
).to.be.revertedWith(CALLER_NOT_AAVE_ADMIN);
LPC_CALLER_NOT_AAVE_ADMIN
).to.be.revertedWith(LPC_CALLER_NOT_AAVE_ADMIN);
});
it('Changes liquidation bonus of the reserve', async () => {
@ -511,24 +511,24 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
const {configurator, users, weth} = testEnv;
await expect(
configurator.connect(users[2].signer).setLiquidationBonus(weth.address, '80'),
CALLER_NOT_AAVE_ADMIN
).to.be.revertedWith(CALLER_NOT_AAVE_ADMIN);
LPC_CALLER_NOT_AAVE_ADMIN
).to.be.revertedWith(LPC_CALLER_NOT_AAVE_ADMIN);
});
it('Check the onlyAaveAdmin on setReserveDecimals', async () => {
const {configurator, users, weth} = testEnv;
await expect(
configurator.connect(users[2].signer).setReserveDecimals(weth.address, '80'),
CALLER_NOT_AAVE_ADMIN
).to.be.revertedWith(CALLER_NOT_AAVE_ADMIN);
LPC_CALLER_NOT_AAVE_ADMIN
).to.be.revertedWith(LPC_CALLER_NOT_AAVE_ADMIN);
});
it('Check the onlyAaveAdmin on setLiquidationBonus', async () => {
const {configurator, users, weth} = testEnv;
await expect(
configurator.connect(users[2].signer).setLiquidationBonus(weth.address, '80'),
CALLER_NOT_AAVE_ADMIN
).to.be.revertedWith(CALLER_NOT_AAVE_ADMIN);
LPC_CALLER_NOT_AAVE_ADMIN
).to.be.revertedWith(LPC_CALLER_NOT_AAVE_ADMIN);
});
it('Reverts when trying to disable the DAI reserve with liquidity on it', async () => {
@ -545,7 +545,7 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
await expect(
configurator.deactivateReserve(dai.address),
RESERVE_LIQUIDITY_NOT_0
).to.be.revertedWith(RESERVE_LIQUIDITY_NOT_0);
LPC_RESERVE_LIQUIDITY_NOT_0
).to.be.revertedWith(LPC_RESERVE_LIQUIDITY_NOT_0);
});
});

View File

@ -8,21 +8,23 @@ import {MockFlashLoanReceiver} from '../types/MockFlashLoanReceiver';
import {ProtocolErrors, eContractid} from '../helpers/types';
import {VariableDebtToken} from '../types/VariableDebtToken';
import {StableDebtToken} from '../types/StableDebtToken';
import {getMockFlashLoanReceiver} from '../helpers/contracts-getters';
import {
getMockFlashLoanReceiver,
getStableDebtToken,
getVariableDebtToken,
} from '../helpers/contracts-getters';
const {expect} = require('chai');
makeSuite('LendingPool FlashLoan function', (testEnv: TestEnv) => {
let _mockFlashLoanReceiver = {} as MockFlashLoanReceiver;
const {
COLLATERAL_BALANCE_IS_0,
REQUESTED_AMOUNT_TOO_SMALL,
VL_COLLATERAL_BALANCE_IS_0,
TRANSFER_AMOUNT_EXCEEDS_BALANCE,
INVALID_FLASHLOAN_MODE,
LP_INVALID_FLASHLOAN_MODE,
SAFEERC20_LOWLEVEL_CALL,
IS_PAUSED,
INVALID_FLASH_LOAN_EXECUTOR_RETURN,
BORROW_ALLOWANCE_ARE_NOT_ENOUGH,
LP_INVALID_FLASH_LOAN_EXECUTOR_RETURN,
LP_BORROW_ALLOWANCE_ARE_NOT_ENOUGH,
} = ProtocolErrors;
before(async () => {
@ -136,7 +138,7 @@ makeSuite('LendingPool FlashLoan function', (testEnv: TestEnv) => {
'0x10',
'0'
)
).to.be.revertedWith(INVALID_FLASH_LOAN_EXECUTOR_RETURN);
).to.be.revertedWith(LP_INVALID_FLASH_LOAN_EXECUTOR_RETURN);
});
it('Takes a WETH flashloan with an invalid mode. (revert expected)', async () => {
@ -190,10 +192,7 @@ makeSuite('LendingPool FlashLoan function', (testEnv: TestEnv) => {
weth.address
);
const wethDebtToken = await getContract<VariableDebtToken>(
eContractid.VariableDebtToken,
variableDebtTokenAddress
);
const wethDebtToken = await getVariableDebtToken(variableDebtTokenAddress);
const callerDebt = await wethDebtToken.balanceOf(caller.address);
@ -307,7 +306,7 @@ makeSuite('LendingPool FlashLoan function', (testEnv: TestEnv) => {
'0x10',
'0'
)
).to.be.revertedWith(COLLATERAL_BALANCE_IS_0);
).to.be.revertedWith(VL_COLLATERAL_BALANCE_IS_0);
});
it('Caller deposits 5 WETH as collateral, Takes a USDC flashloan with mode = 2, does not return the funds. A loan for caller is created', async () => {
@ -342,10 +341,7 @@ makeSuite('LendingPool FlashLoan function', (testEnv: TestEnv) => {
usdc.address
);
const usdcDebtToken = await getContract<VariableDebtToken>(
eContractid.VariableDebtToken,
variableDebtTokenAddress
);
const usdcDebtToken = await getVariableDebtToken(variableDebtTokenAddress);
const callerDebt = await usdcDebtToken.balanceOf(caller.address);
@ -407,10 +403,7 @@ makeSuite('LendingPool FlashLoan function', (testEnv: TestEnv) => {
const {stableDebtTokenAddress} = await helpersContract.getReserveTokensAddresses(weth.address);
const wethDebtToken = await getContract<StableDebtToken>(
eContractid.VariableDebtToken,
stableDebtTokenAddress
);
const wethDebtToken = await getStableDebtToken(stableDebtTokenAddress);
const callerDebt = await wethDebtToken.balanceOf(caller.address);
@ -450,7 +443,7 @@ makeSuite('LendingPool FlashLoan function', (testEnv: TestEnv) => {
'0x10',
'0'
)
).to.be.revertedWith(BORROW_ALLOWANCE_ARE_NOT_ENOUGH);
).to.be.revertedWith(LP_BORROW_ALLOWANCE_ARE_NOT_ENOUGH);
});
it('Caller takes a WETH flashloan with mode = 1 onBehalfOf user with allowance. A loan for onBehalfOf is creatd.', async () => {
@ -482,10 +475,7 @@ makeSuite('LendingPool FlashLoan function', (testEnv: TestEnv) => {
const {stableDebtTokenAddress} = await helpersContract.getReserveTokensAddresses(weth.address);
const wethDebtToken = await getContract<StableDebtToken>(
eContractid.VariableDebtToken,
stableDebtTokenAddress
);
const wethDebtToken = await getStableDebtToken(stableDebtTokenAddress);
const onBehalfOfDebt = await wethDebtToken.balanceOf(onBehalfOf.address);

View File

@ -17,11 +17,11 @@ const {expect} = chai;
makeSuite('LendingPool liquidation - liquidator receiving aToken', (testEnv) => {
const {
HEALTH_FACTOR_NOT_BELOW_THRESHOLD,
LPCM_HEALTH_FACTOR_NOT_BELOW_THRESHOLD,
INVALID_HF,
SPECIFIED_CURRENCY_NOT_BORROWED_BY_USER,
COLLATERAL_CANNOT_BE_LIQUIDATED,
IS_PAUSED,
LPCM_SPECIFIED_CURRENCY_NOT_BORROWED_BY_USER,
LPCM_COLLATERAL_CANNOT_BE_LIQUIDATED,
P_IS_PAUSED,
} = ProtocolErrors;
it('LIQUIDATION - Deposits WETH, borrows DAI/Check liquidation fails because health factor is above 1', async () => {
@ -80,7 +80,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(HEALTH_FACTOR_NOT_BELOW_THRESHOLD);
).to.be.revertedWith(LPCM_HEALTH_FACTOR_NOT_BELOW_THRESHOLD);
});
it('LIQUIDATION - Drop the health factor below 1', async () => {
@ -105,7 +105,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(SPECIFIED_CURRENCY_NOT_BORROWED_BY_USER);
).revertedWith(LPCM_SPECIFIED_CURRENCY_NOT_BORROWED_BY_USER);
});
it('LIQUIDATION - Tries to liquidate a different collateral than the borrower collateral', async () => {
@ -114,7 +114,7 @@ makeSuite('LendingPool liquidation - liquidator receiving aToken', (testEnv) =>
await expect(
pool.liquidationCall(dai.address, dai.address, borrower.address, oneEther.toString(), true)
).revertedWith(COLLATERAL_CANNOT_BE_LIQUIDATED);
).revertedWith(LPCM_COLLATERAL_CANNOT_BE_LIQUIDATED);
});
it('LIQUIDATION - Liquidates the borrow', async () => {

View File

@ -13,8 +13,7 @@ makeSuite('Pausable Pool', (testEnv: TestEnv) => {
let _mockFlashLoanReceiver = {} as MockFlashLoanReceiver;
const {
IS_PAUSED,
TRANSFER_NOT_ALLOWED,
P_IS_PAUSED,
INVALID_FROM_BALANCE_AFTER_TRANSFER,
INVALID_TO_BALANCE_AFTER_TRANSFER,
} = ProtocolErrors;
@ -45,7 +44,7 @@ makeSuite('Pausable Pool', (testEnv: TestEnv) => {
// User 0 tries the transfer to User 1
await expect(
aDai.connect(users[0].signer).transfer(users[1].address, amountDAItoDeposit)
).to.revertedWith(IS_PAUSED);
).to.revertedWith(P_IS_PAUSED);
const pausedFromBalance = await aDai.balanceOf(users[0].address);
const pausedToBalance = await aDai.balanceOf(users[1].address);
@ -92,7 +91,7 @@ makeSuite('Pausable Pool', (testEnv: TestEnv) => {
await configurator.setPoolPause(true);
await expect(
pool.connect(users[0].signer).deposit(dai.address, amountDAItoDeposit, users[0].address, '0')
).to.revertedWith(IS_PAUSED);
).to.revertedWith(P_IS_PAUSED);
// Configurator unpauses the pool
await configurator.setPoolPause(false);
@ -117,7 +116,7 @@ makeSuite('Pausable Pool', (testEnv: TestEnv) => {
// user tries to burn
await expect(
pool.connect(users[0].signer).withdraw(dai.address, amountDAItoDeposit, users[0].address)
).to.revertedWith(IS_PAUSED);
).to.revertedWith(P_IS_PAUSED);
// Configurator unpauses the pool
await configurator.setPoolPause(false);
@ -134,7 +133,7 @@ makeSuite('Pausable Pool', (testEnv: TestEnv) => {
// Try to execute liquidation
await expect(
pool.connect(user.signer).delegateBorrowAllowance([dai.address], toUser.address, ['1'], ['1'])
).revertedWith(IS_PAUSED);
).revertedWith(P_IS_PAUSED);
// Unpause the pool
await configurator.setPoolPause(false);
@ -150,7 +149,7 @@ makeSuite('Pausable Pool', (testEnv: TestEnv) => {
// Try to execute liquidation
await expect(
pool.connect(user.signer).borrow(dai.address, '1', '1', '0', user.address)
).revertedWith(IS_PAUSED);
).revertedWith(P_IS_PAUSED);
// Unpause the pool
await configurator.setPoolPause(false);
@ -165,7 +164,7 @@ makeSuite('Pausable Pool', (testEnv: TestEnv) => {
// Try to execute liquidation
await expect(pool.connect(user.signer).repay(dai.address, '1', '1', user.address)).revertedWith(
IS_PAUSED
P_IS_PAUSED
);
// Unpause the pool
@ -196,7 +195,7 @@ makeSuite('Pausable Pool', (testEnv: TestEnv) => {
'0x10',
'0'
)
).revertedWith(IS_PAUSED);
).revertedWith(P_IS_PAUSED);
// Unpause pool
await configurator.setPoolPause(false);
@ -277,7 +276,7 @@ makeSuite('Pausable Pool', (testEnv: TestEnv) => {
// Do liquidation
expect(
pool.liquidationCall(weth.address, usdc.address, borrower.address, amountToLiquidate, true)
).revertedWith(IS_PAUSED);
).revertedWith(P_IS_PAUSED);
// Unpause pool
await configurator.setPoolPause(false);
@ -306,7 +305,7 @@ makeSuite('Pausable Pool', (testEnv: TestEnv) => {
// Try to repay
await expect(
pool.connect(user.signer).swapBorrowRateMode(usdc.address, RateMode.Stable)
).revertedWith(IS_PAUSED);
).revertedWith(P_IS_PAUSED);
// Unpause pool
await configurator.setPoolPause(false);
@ -320,7 +319,7 @@ makeSuite('Pausable Pool', (testEnv: TestEnv) => {
await expect(
pool.connect(user.signer).rebalanceStableBorrowRate(dai.address, user.address)
).revertedWith(IS_PAUSED);
).revertedWith(P_IS_PAUSED);
// Unpause pool
await configurator.setPoolPause(false);
@ -340,7 +339,7 @@ makeSuite('Pausable Pool', (testEnv: TestEnv) => {
await expect(
pool.connect(user.signer).setUserUseReserveAsCollateral(weth.address, false)
).revertedWith(IS_PAUSED);
).revertedWith(P_IS_PAUSED);
// Unpause pool
await configurator.setPoolPause(false);

View File

@ -3,9 +3,10 @@ import {makeSuite, TestEnv} from './helpers/make-suite';
import {ProtocolErrors, eContractid} from '../helpers/types';
import {getContract} from '../helpers/contracts-helpers';
import {StableDebtToken} from '../types/StableDebtToken';
import {getStableDebtToken} from '../helpers/contracts-getters';
makeSuite('Stable debt token tests', (testEnv: TestEnv) => {
const {CALLER_MUST_BE_LENDING_POOL} = ProtocolErrors;
const {AT_CALLER_MUST_BE_LENDING_POOL} = ProtocolErrors;
it('Tries to invoke mint not being the LendingPool', async () => {
const {deployer, pool, dai, helpersContract} = testEnv;
@ -13,13 +14,10 @@ makeSuite('Stable debt token tests', (testEnv: TestEnv) => {
const daiStableDebtTokenAddress = (await helpersContract.getReserveTokensAddresses(dai.address))
.stableDebtTokenAddress;
const stableDebtContract = await getContract<StableDebtToken>(
eContractid.StableDebtToken,
daiStableDebtTokenAddress
);
const stableDebtContract = await getStableDebtToken(daiStableDebtTokenAddress);
await expect(stableDebtContract.mint(deployer.address, '1', '1')).to.be.revertedWith(
CALLER_MUST_BE_LENDING_POOL
AT_CALLER_MUST_BE_LENDING_POOL
);
});
@ -29,16 +27,13 @@ makeSuite('Stable debt token tests', (testEnv: TestEnv) => {
const daiStableDebtTokenAddress = (await helpersContract.getReserveTokensAddresses(dai.address))
.stableDebtTokenAddress;
const stableDebtContract = await getContract<StableDebtToken>(
eContractid.StableDebtToken,
daiStableDebtTokenAddress
);
const stableDebtContract = await getStableDebtToken(daiStableDebtTokenAddress);
const name = await stableDebtContract.name();
expect(name).to.be.equal('Aave stable debt bearing DAI');
await expect(stableDebtContract.burn(deployer.address, '1')).to.be.revertedWith(
CALLER_MUST_BE_LENDING_POOL
AT_CALLER_MUST_BE_LENDING_POOL
);
});
});

View File

@ -6,17 +6,27 @@ import {MockAToken} from '../types/MockAToken';
import {MockStableDebtToken} from '../types/MockStableDebtToken';
import {MockVariableDebtToken} from '../types/MockVariableDebtToken';
import {ZERO_ADDRESS} from '../helpers/constants';
import {getAToken} from '../helpers/contracts-getters';
import {
getAToken,
getMockStableDebtToken,
getMockVariableDebtToken,
getVariableDebtToken,
} from '../helpers/contracts-getters';
import {
deployMockAToken,
deployMockStableDebtToken,
deployMockVariableDebtToken,
} from '../helpers/contracts-deployments';
makeSuite('Upgradeability', (testEnv: TestEnv) => {
const {CALLER_NOT_AAVE_ADMIN} = ProtocolErrors;
const {LPC_CALLER_NOT_AAVE_ADMIN} = 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, [
const aTokenInstance = await deployMockAToken([
pool.address,
dai.address,
ZERO_ADDRESS,
@ -25,27 +35,21 @@ makeSuite('Upgradeability', (testEnv: TestEnv) => {
ZERO_ADDRESS,
]);
const stableDebtTokenInstance = await deployContract<MockStableDebtToken>(
eContractid.MockStableDebtToken,
[
pool.address,
dai.address,
'Aave stable debt bearing DAI updated',
'stableDebtDAI',
ZERO_ADDRESS,
]
);
const stableDebtTokenInstance = await deployMockStableDebtToken([
pool.address,
dai.address,
'Aave stable debt bearing DAI updated',
'stableDebtDAI',
ZERO_ADDRESS,
]);
const variableDebtTokenInstance = await deployContract<MockVariableDebtToken>(
eContractid.MockVariableDebtToken,
[
pool.address,
dai.address,
'Aave variable debt bearing DAI updated',
'variableDebtDAI',
ZERO_ADDRESS,
]
);
const variableDebtTokenInstance = await deployMockVariableDebtToken([
pool.address,
dai.address,
'Aave variable debt bearing DAI updated',
'variableDebtDAI',
ZERO_ADDRESS,
]);
newATokenAddress = aTokenInstance.address;
newVariableTokenAddress = variableDebtTokenInstance.address;
@ -57,7 +61,7 @@ makeSuite('Upgradeability', (testEnv: TestEnv) => {
await expect(
configurator.connect(users[1].signer).updateAToken(dai.address, newATokenAddress)
).to.be.revertedWith(CALLER_NOT_AAVE_ADMIN);
).to.be.revertedWith(LPC_CALLER_NOT_AAVE_ADMIN);
});
it('Upgrades the DAI Atoken implementation ', async () => {
@ -79,7 +83,7 @@ makeSuite('Upgradeability', (testEnv: TestEnv) => {
configurator
.connect(users[1].signer)
.updateStableDebtToken(dai.address, newStableTokenAddress)
).to.be.revertedWith(CALLER_NOT_AAVE_ADMIN);
).to.be.revertedWith(LPC_CALLER_NOT_AAVE_ADMIN);
});
it('Upgrades the DAI stable debt token implementation ', async () => {
@ -91,10 +95,7 @@ makeSuite('Upgradeability', (testEnv: TestEnv) => {
const {stableDebtTokenAddress} = await helpersContract.getReserveTokensAddresses(dai.address);
const debtToken = await getContract<MockStableDebtToken>(
eContractid.MockStableDebtToken,
stableDebtTokenAddress
);
const debtToken = await getMockStableDebtToken(stableDebtTokenAddress);
const tokenName = await debtToken.name();
@ -108,7 +109,7 @@ makeSuite('Upgradeability', (testEnv: TestEnv) => {
configurator
.connect(users[1].signer)
.updateVariableDebtToken(dai.address, newVariableTokenAddress)
).to.be.revertedWith(CALLER_NOT_AAVE_ADMIN);
).to.be.revertedWith(LPC_CALLER_NOT_AAVE_ADMIN);
});
it('Upgrades the DAI variable debt token implementation ', async () => {
@ -120,10 +121,7 @@ makeSuite('Upgradeability', (testEnv: TestEnv) => {
const {variableDebtTokenAddress} = await helpersContract.getReserveTokensAddresses(dai.address);
const debtToken = await getContract<MockStableDebtToken>(
eContractid.MockStableDebtToken,
variableDebtTokenAddress
);
const debtToken = await getMockVariableDebtToken(variableDebtTokenAddress);
const tokenName = await debtToken.name();

View File

@ -1,11 +1,10 @@
import {expect} from 'chai';
import {makeSuite, TestEnv} from './helpers/make-suite';
import {ProtocolErrors, TokenContractId, eContractid} from '../helpers/types';
import {getContract} from '../helpers/contracts-helpers';
import {VariableDebtToken} from '../types/VariableDebtToken';
import {getVariableDebtToken} from '../helpers/contracts-getters';
makeSuite('Variable debt token tests', (testEnv: TestEnv) => {
const {CALLER_MUST_BE_LENDING_POOL} = ProtocolErrors;
const {AT_CALLER_MUST_BE_LENDING_POOL} = ProtocolErrors;
it('Tries to invoke mint not being the LendingPool', async () => {
const {deployer, pool, dai, helpersContract} = testEnv;
@ -14,13 +13,10 @@ makeSuite('Variable debt token tests', (testEnv: TestEnv) => {
await helpersContract.getReserveTokensAddresses(dai.address)
).variableDebtTokenAddress;
const variableDebtContract = await getContract<VariableDebtToken>(
eContractid.VariableDebtToken,
daiVariableDebtTokenAddress
);
const variableDebtContract = await getVariableDebtToken(daiVariableDebtTokenAddress);
await expect(variableDebtContract.mint(deployer.address, '1', '1')).to.be.revertedWith(
CALLER_MUST_BE_LENDING_POOL
AT_CALLER_MUST_BE_LENDING_POOL
);
});
@ -31,13 +27,10 @@ makeSuite('Variable debt token tests', (testEnv: TestEnv) => {
await helpersContract.getReserveTokensAddresses(dai.address)
).variableDebtTokenAddress;
const variableDebtContract = await getContract<VariableDebtToken>(
eContractid.VariableDebtToken,
daiVariableDebtTokenAddress
);
const variableDebtContract = await getVariableDebtToken(daiVariableDebtTokenAddress);
await expect(variableDebtContract.burn(deployer.address, '1', '1')).to.be.revertedWith(
CALLER_MUST_BE_LENDING_POOL
AT_CALLER_MUST_BE_LENDING_POOL
);
});
});