Skip to content

Commit

Permalink
Reorg errors library, sorted by error number, added prefix to each co…
Browse files Browse the repository at this point in the history
…nstant and a prefix glossary.
  • Loading branch information
kartojal committed Oct 14, 2020
1 parent 20da932 commit 57ffc9c
Show file tree
Hide file tree
Showing 26 changed files with 331 additions and 328 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,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, Errors.PROVIDER_NOT_REGISTERED);
require(_addressesProviders[provider] > 0, Errors.LPAPR_PROVIDER_NOT_REGISTERED);
_addressesProviders[provider] = 0;
emit AddressesProviderUnregistered(provider);
}
Expand Down
20 changes: 10 additions & 10 deletions contracts/lendingpool/LendingPool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,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
);
}

Expand All @@ -67,7 +67,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) {
Expand Down Expand Up @@ -226,7 +226,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(
Expand Down Expand Up @@ -400,7 +400,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();
Expand Down Expand Up @@ -475,7 +475,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));

Expand Down Expand Up @@ -506,7 +506,7 @@ contract LendingPool is VersionedInitializable, ILendingPool, LendingPoolStorage
bytes calldata params
) external override {
_whenNotPaused();
require(!_flashLiquidationLocked, Errors.REENTRANCY_NOT_ALLOWED);
require(!_flashLiquidationLocked, Errors.LP_REENTRANCY_NOT_ALLOWED);
_flashLiquidationLocked = true;

address collateralManager = _addressesProvider.getLendingPoolCollateralManager();
Expand All @@ -523,7 +523,7 @@ contract LendingPool is VersionedInitializable, ILendingPool, LendingPoolStorage
params
)
);
require(success, Errors.FAILED_REPAY_WITH_COLLATERAL);
require(success, Errors.LP_FAILED_REPAY_WITH_COLLATERAL);

(uint256 returnCode, string memory returnMessage) = abi.decode(result, (uint256, string));

Expand Down Expand Up @@ -581,7 +581,7 @@ contract LendingPool is VersionedInitializable, ILendingPool, LendingPoolStorage
//execute action of the receiver
require(
vars.receiver.executeOperation(asset, amount, vars.premium, params),
Errors.INVALID_FLASH_LOAN_EXECUTOR_RETURN
Errors.LP_INVALID_FLASH_LOAN_EXECUTOR_RETURN
);

vars.amountPlusPremium = amount.add(vars.premium);
Expand Down Expand Up @@ -641,7 +641,7 @@ contract LendingPool is VersionedInitializable, ILendingPool, LendingPoolStorage
params
)
);
require(success, Errors.FAILED_COLLATERAL_SWAP);
require(success, Errors.LP_FAILED_COLLATERAL_SWAP);

(uint256 returnCode, string memory returnMessage) = abi.decode(result, (uint256, string));

Expand Down Expand Up @@ -958,7 +958,7 @@ contract LendingPool is VersionedInitializable, ILendingPool, LendingPoolStorage
* @dev adds a reserve to the array of the _reserves address
**/
function _addReserveToList(address asset) internal {
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;

Expand Down
10 changes: 5 additions & 5 deletions contracts/lendingpool/LendingPoolCollateralManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,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
);
}
}
Expand Down Expand Up @@ -295,7 +295,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);
}

/**
Expand Down Expand Up @@ -450,7 +450,7 @@ contract LendingPoolCollateralManager is VersionedInitializable, LendingPoolStor
vars.maxCollateralToLiquidate
);

return (uint256(Errors.CollateralManagerErrors.NO_ERROR), Errors.NO_ERRORS);
return (uint256(Errors.CollateralManagerErrors.NO_ERROR), Errors.LPCM_NO_ERRORS);
}

/**
Expand Down Expand Up @@ -544,11 +544,11 @@ contract LendingPoolCollateralManager is VersionedInitializable, LendingPoolStor
if (vars.healthFactor < GenericLogic.HEALTH_FACTOR_LIQUIDATION_THRESHOLD) {
return (
uint256(Errors.CollateralManagerErrors.HEALTH_FACTOR_LOWER_THAN_LIQUIDATION_THRESHOLD),
Errors.HEALTH_FACTOR_LOWER_THAN_LIQUIDATION_THRESHOLD
Errors.VL_HEALTH_FACTOR_LOWER_THAN_LIQUIDATION_THRESHOLD
);
}

return (uint256(Errors.CollateralManagerErrors.NO_ERROR), Errors.NO_ERRORS);
return (uint256(Errors.CollateralManagerErrors.NO_ERROR), Errors.LPCM_NO_ERRORS);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions contracts/lendingpool/LendingPoolConfigurator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,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);
_;
}

Expand Down Expand Up @@ -424,7 +424,7 @@ contract LendingPoolConfigurator is VersionedInitializable {
) = pool.getReserveData(asset);
require(
availableLiquidity == 0 && totalStableDebt == 0 && totalVariableDebt == 0,
Errors.RESERVE_LIQUIDITY_NOT_0
Errors.LPC_RESERVE_LIQUIDITY_NOT_0
);

ReserveConfiguration.Map memory currentConfig = pool.getConfiguration(asset);
Expand Down
143 changes: 68 additions & 75 deletions contracts/libraries/helpers/Errors.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,83 +5,76 @@ 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';

// 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 = '53'; //invalid amount to mint
string public constant INVALID_BURN_AMOUNT = '54'; //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'

//require error messages - LendingPoolAddressesProviderRegistry
string public constant PROVIDER_NOT_REGISTERED = '37'; // 'Provider is not registered'

//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'
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 AT_CALLER_MUST_BE_LENDING_POOL = '28'; // 'The caller of this function must be a lending pool'
string public constant AT_CANNOT_GIVE_ALLOWANCE_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 = '34'; // 'Reserve has already been initialized'
string public constant LPC_CALLER_NOT_AAVE_ADMIN = '35'; // 'The caller must be the aave admin'
string public constant LPC_RESERVE_LIQUIDITY_NOT_0 = '36'; // 'The liquidity of the reserve needs to be 0'
string public constant LPAPR_PROVIDER_NOT_REGISTERED = '37'; // 'Provider is not registered'
string public constant LPCM_HEALTH_FACTOR_NOT_BELOW_THRESHOLD = '38'; // 'Health factor is not below the threshold'
string public constant LPCM_COLLATERAL_CANNOT_BE_LIQUIDATED = '39'; // 'The collateral chosen cannot be liquidated'
string public constant LPCM_SPECIFIED_CURRENCY_NOT_BORROWED_BY_USER = '40'; // 'User did not borrow the specified currency'
string public constant LPCM_NOT_ENOUGH_LIQUIDITY_TO_LIQUIDATE = '41'; // "There isn't enough liquidity available to liquidate"
string public constant LPCM_NO_ERRORS = '42'; // 'No errors'
string public constant LP_INVALID_FLASHLOAN_MODE = '43'; //Invalid flashloan mode selected
string public constant MATH_MULTIPLICATION_OVERFLOW = '44';
string public constant MATH_ADDITION_OVERFLOW = '45';
string public constant MATH_DIVISION_BY_ZERO = '46';
string public constant RL_LIQUIDITY_INDEX_OVERFLOW = '47'; // Liquidity index overflows uint128
string public constant RL_VARIABLE_BORROW_INDEX_OVERFLOW = '48'; // Variable borrow index overflows uint128
string public constant RL_LIQUIDITY_RATE_OVERFLOW = '49'; // Liquidity rate overflows uint128
string public constant RL_VARIABLE_BORROW_RATE_OVERFLOW = '50'; // Variable borrow rate overflows uint128
string public constant RL_STABLE_BORROW_RATE_OVERFLOW = '51'; // Stable borrow rate overflows uint128
string public constant AT_INVALID_MINT_AMOUNT = '53'; //invalid amount to mint
string public constant LP_FAILED_REPAY_WITH_COLLATERAL = '53';
string public constant AT_INVALID_BURN_AMOUNT = '54'; //invalid amount to burn
string public constant LP_BORROW_ALLOWANCE_ARE_NOT_ENOUGH = '54'; // User borrows on behalf, but allowance are too small
string public constant LP_FAILED_COLLATERAL_SWAP = '55';
string public constant LP_INVALID_EQUAL_ASSETS_TO_SWAP = '56';
string public constant LP_REENTRANCY_NOT_ALLOWED = '57';
string public constant P_IS_PAUSED = '58'; // 'Pool is paused'
string public constant LP_NO_MORE_RESERVES_ALLOWED = '59';
string public constant LP_INVALID_FLASH_LOAN_EXECUTOR_RETURN = '60';
enum CollateralManagerErrors {
NO_ERROR,
NO_COLLATERAL_AVAILABLE,
Expand Down

0 comments on commit 57ffc9c

Please sign in to comment.