mirror of
				https://github.com/Instadapp/aave-protocol-v2.git
				synced 2024-07-29 21:47:30 +00:00 
			
		
		
		
	fixed getting error codes from error lib
This commit is contained in:
		
							parent
							
								
									7b4812c956
								
							
						
					
					
						commit
						6122826ef4
					
				|  | @ -345,7 +345,7 @@ contract LendingPool is ReentrancyGuard, VersionedInitializable, ILendingPool { | |||
|     uint256 stableBorrowBalance = IERC20(address(stableDebtToken)).balanceOf(user); | ||||
| 
 | ||||
|     // user must be borrowing on asset at a stable rate | ||||
|     require(stableBorrowBalance > 0, NOT_ENOUGH_STABLE_BORROW_BALANCE); | ||||
|     require(stableBorrowBalance > 0, Errors.NOT_ENOUGH_STABLE_BORROW_BALANCE); | ||||
| 
 | ||||
|     uint256 rebalanceDownRateThreshold = reserve.currentStableBorrowRate.rayMul( | ||||
|       WadRayMath.ray().add(REBALANCE_DOWN_RATE_DELTA) | ||||
|  | @ -360,7 +360,7 @@ contract LendingPool is ReentrancyGuard, VersionedInitializable, ILendingPool { | |||
| 
 | ||||
|     require( | ||||
|       userStableRate < reserve.currentLiquidityRate || userStableRate > rebalanceDownRateThreshold, | ||||
|       INTERESTRATE_REBALANCE_CONDITIONS_NOT_MET | ||||
|       Errors.INTERESTRATE_REBALANCE_CONDITIONS_NOT_MET | ||||
|     ); | ||||
| 
 | ||||
|     //burn old debt tokens, mint new ones | ||||
|  | @ -436,7 +436,7 @@ contract LendingPool is ReentrancyGuard, VersionedInitializable, ILendingPool { | |||
|         receiveAToken | ||||
|       ) | ||||
|     ); | ||||
|     require(success, LIQUIDATION_CALL_FAILED); | ||||
|     require(success, Errors.LIQUIDATION_CALL_FAILED); | ||||
| 
 | ||||
|     (uint256 returnCode, string memory returnMessage) = abi.decode(result, (uint256, string)); | ||||
| 
 | ||||
|  | @ -470,8 +470,8 @@ contract LendingPool is ReentrancyGuard, VersionedInitializable, ILendingPool { | |||
|     //calculate amount fee | ||||
|     uint256 amountFee = amount.mul(FLASHLOAN_FEE_TOTAL).div(10000); | ||||
| 
 | ||||
|     require(availableLiquidityBefore >= amount, NOT_ENOUGH_LIQUIDITY_TO_BORROW); | ||||
|     require(amountFee > 0, REQUESTED_AMOUNT_TO_SMALL); | ||||
|     require(availableLiquidityBefore >= amount, Errors.NOT_ENOUGH_LIQUIDITY_TO_BORROW); | ||||
|     require(amountFee > 0, Errors.REQUESTED_AMOUNT_TO_SMALL); | ||||
| 
 | ||||
|     //get the FlashLoanReceiver instance | ||||
|     IFlashLoanReceiver receiver = IFlashLoanReceiver(receiverAddress); | ||||
|  | @ -487,7 +487,7 @@ contract LendingPool is ReentrancyGuard, VersionedInitializable, ILendingPool { | |||
| 
 | ||||
|     require( | ||||
|       availableLiquidityAfter == availableLiquidityBefore.add(amountFee), | ||||
|       INCONSISTENT_PROTOCOL_ACTUAL_BALANCE | ||||
|       Errors.INCONSISTENT_PROTOCOL_ACTUAL_BALANCE | ||||
|     ); | ||||
| 
 | ||||
|     //compounding the cumulated interest | ||||
|  |  | |||
|  | @ -8,41 +8,41 @@ pragma solidity ^0.6.8; | |||
|  */ | ||||
| library Errors { | ||||
|   // require error messages - ValidationLogic | ||||
|   string private constant AMOUNT_NOT_GREATER_THAN_0 = '1'; // 'Amount must be greater than 0' | ||||
|   string private constant NO_ACTIVE_RESERVE = '2'; // 'Action requires an active reserve' | ||||
|   string private constant NO_UNFREEZED_RESERVE = '3'; // 'Action requires an unfreezed reserve' | ||||
|   string private constant CURRENT_AVAILABLE_LIQUIDITY_NOT_ENOUGH = '4'; // 'The current liquidity is not enough' | ||||
|   string private constant NOT_ENOUGH_AVAILABLE_USER_BALANCE = '5'; // 'User cannot withdraw more than the available balance' | ||||
|   string private constant TRANSFER_NOT_ALLOWED = '6'; // 'Transfer cannot be allowed.' | ||||
|   string private constant BORROWING_NOT_ENABLED = '7'; // 'Borrowing is not enabled' | ||||
|   string private constant INVALID_INTERESTRATE_MODE_SELECTED = '8'; // 'Invalid interest rate mode selected' | ||||
|   string private constant COLLATERAL_BALANCE_IS_0 = '9'; // 'The collateral balance is 0' | ||||
|   string private constant HEALTH_FACTOR_LOWER_THAN_LIQUIDATION_THRESHOLD = '10'; // 'Health factor is lesser than the liquidation threshold' | ||||
|   string private constant COLLATERAL_CANNOT_COVER_NEW_BORROW = '11'; // 'There is not enough collateral to cover a new borrow' | ||||
|   string private constant STABLE_BORROWING_NOT_ENABLED = '12'; // stable borrowing not enabled | ||||
|   string private constant CALLATERAL_SAME_AS_BORROWING_CURRENCY = '13'; // collateral is (mostly) the same currency that is being borrowed | ||||
|   string private constant AMOUNT_BIGGER_THAN_MAX_LOAN_SIZE_STABLE = '14'; // 'The requested amount is greater than the max loan size in stable rate mode | ||||
|   string private 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 private constant NO_EPLICIT_AMOUNT_TO_REPAY_ON_BEHALF = '16'; // 'To repay on behalf of an user an explicit amount to repay is needed' | ||||
|   string private constant NO_STABLE_RATE_LOAN_IN_RESERVE = '17'; // 'User does not have a stable rate loan in progress on this reserve' | ||||
|   string private constant NO_VARIABLE_RATE_LOAN_IN_RESERVE = '18'; // 'User does not have a variable rate loan in progress on this reserve' | ||||
|   string private constant UNDERLYING_BALANCE_NOT_GREATER_THAN_0 = '19'; // 'The underlying balance needs to be greater than 0' | ||||
|   string private constant DEPOSIT_ALREADY_IN_USE = '20'; // 'User deposit is already being used as collateral' | ||||
|   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_INTERESTRATE_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_EPLICIT_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 private constant NOT_ENOUGH_STABLE_BORROW_BALANCE = '21'; // 'User does not have any stable rate loan for this reserve' | ||||
|   string private constant INTERESTRATE_REBALANCE_CONDITIONS_NOT_MET = '22'; // 'Interest rate rebalance conditions were not met' | ||||
|   string private constant LIQUIDATION_CALL_FAILED = '23'; // 'Liquidation call failed' | ||||
|   string private constant NOT_ENOUGH_LIQUIDITY_TO_BORROW = '24'; // 'There is not enough liquidity available to borrow' | ||||
|   string private constant REQUESTED_AMOUNT_TO_SMALL = '25'; // 'The requested amount is too small for a FlashLoan.' | ||||
|   string private constant INCONSISTENT_PROTOCOL_ACTUAL_BALANCE = '26'; // 'The actual balance of the protocol is inconsistent' | ||||
|   string public constant NOT_ENOUGH_STABLE_BORROW_BALANCE = '21'; // 'User does not have any stable rate loan for this reserve' | ||||
|   string public constant INTERESTRATE_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_TO_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' | ||||
| 
 | ||||
|   // require error messages - aToken | ||||
|   string private constant CALLER_MUST_BE_LENDING_POOL = '27'; // 'The caller of this function must be a lending pool' | ||||
|   string private constant TRANSFER_CANNOT_BE_ALLOWED = '28'; // 'Transfer cannot be allowed.' | ||||
|   string private constant NOT_ALLOWED_TO_REDIRECT_INTEREST = '29'; // 'Caller is not allowed to redirect the interest of the user' | ||||
|   string private constant CANNOT_GIVE_ALLOWANCE_TO_HIMSELF = '30'; // 'User cannot give allowance to himself' | ||||
|   string private constant TRANSFER_AMOUNT_NOT_GT_0 = '31'; // 'Transferred amount needs to be greater than zero' | ||||
|   string private constant INTEREST_ALREADY_REDIRECTED = '32'; // 'Interest is already redirected to the user' | ||||
|   string private constant NO_VALID_BALANCE_FOR_REDIRECT_INT_STREAM = '33'; // 'Interest stream can only be redirected if there is a valid balance' | ||||
|   string public constant CALLER_MUST_BE_LENDING_POOL = '27'; // 'The caller of this function must be a lending pool' | ||||
|   string public constant TRANSFER_CANNOT_BE_ALLOWED = '28'; // 'Transfer cannot be allowed.' | ||||
|   string public constant NOT_ALLOWED_TO_REDIRECT_INTEREST = '29'; // 'Caller is not allowed to redirect the interest of the user' | ||||
|   string public constant CANNOT_GIVE_ALLOWANCE_TO_HIMSELF = '30'; // 'User cannot give allowance to himself' | ||||
|   string public constant TRANSFER_AMOUNT_NOT_GT_0 = '31'; // 'Transferred amount needs to be greater than zero' | ||||
|   string public constant INTEREST_ALREADY_REDIRECTED = '32'; // 'Interest is already redirected to the user' | ||||
|   string public constant NO_VALID_BALANCE_FOR_REDIRECT_INT_STREAM = '33'; // 'Interest stream can only be redirected if there is a valid balance' | ||||
| } | ||||
|  |  | |||
|  | @ -12,7 +12,7 @@ import {SafeERC20} from '@openzeppelin/contracts/token/ERC20/SafeERC20.sol'; | |||
| import {ReserveConfiguration} from '../configuration/ReserveConfiguration.sol'; | ||||
| import {UserConfiguration} from '../configuration/UserConfiguration.sol'; | ||||
| import {IPriceOracleGetter} from '../../interfaces/IPriceOracleGetter.sol'; | ||||
| import {Errors} from '../libraries/helpers/Errors.sol'; | ||||
| import {Errors} from '../helpers/Errors.sol'; | ||||
| 
 | ||||
| /** | ||||
|  * @title ReserveLogic library | ||||
|  | @ -36,9 +36,9 @@ library ValidationLogic { | |||
|   function validateDeposit(ReserveLogic.ReserveData storage reserve, uint256 amount) internal view { | ||||
|     (bool isActive, bool isFreezed, , ) = reserve.configuration.getFlags(); | ||||
| 
 | ||||
|     require(amount > 0, AMOUNT_NOT_GREATER_THAN_0); | ||||
|     require(isActive, NO_ACTIVE_RESERVE); | ||||
|     require(!isFreezed, NO_UNFREEZED_RESERVE); | ||||
|     require(amount > 0, Errors.AMOUNT_NOT_GREATER_THAN_0); | ||||
|     require(isActive, Errors.NO_ACTIVE_RESERVE); | ||||
|     require(!isFreezed, Errors.NO_UNFREEZED_RESERVE); | ||||
|   } | ||||
| 
 | ||||
|   /** | ||||
|  | @ -58,13 +58,13 @@ library ValidationLogic { | |||
|     address[] calldata reserves, | ||||
|     address oracle | ||||
|   ) external view { | ||||
|     require(amount > 0, AMOUNT_NOT_GREATER_THAN_0); | ||||
|     require(amount > 0, Errors.AMOUNT_NOT_GREATER_THAN_0); | ||||
| 
 | ||||
|     uint256 currentAvailableLiquidity = IERC20(reserveAddress).balanceOf(address(aTokenAddress)); | ||||
| 
 | ||||
|     require(currentAvailableLiquidity >= amount, CURRENT_AVAILABLE_LIQUIDITY_NOT_ENOUGH); | ||||
|     require(currentAvailableLiquidity >= amount, Errors.CURRENT_AVAILABLE_LIQUIDITY_NOT_ENOUGH); | ||||
| 
 | ||||
|     require(amount <= userBalance, NOT_ENOUGH_AVAILABLE_USER_BALANCE); | ||||
|     require(amount <= userBalance, Errors.NOT_ENOUGH_AVAILABLE_USER_BALANCE); | ||||
| 
 | ||||
|     require( | ||||
|       GenericLogic.balanceDecreaseAllowed( | ||||
|  | @ -76,7 +76,7 @@ library ValidationLogic { | |||
|         reserves, | ||||
|         oracle | ||||
|       ), | ||||
|       TRANSFER_NOT_ALLOWED | ||||
|       Errors.TRANSFER_NOT_ALLOWED | ||||
|     ); | ||||
|   } | ||||
| 
 | ||||
|  | @ -136,22 +136,22 @@ library ValidationLogic { | |||
|       vars.stableRateBorrowingEnabled | ||||
|     ) = reserve.configuration.getFlags(); | ||||
| 
 | ||||
|     require(vars.isActive, NO_ACTIVE_RESERVE); | ||||
|     require(!vars.isFreezed, NO_UNFREEZED_RESERVE); | ||||
|     require(vars.isActive, Errors.NO_ACTIVE_RESERVE); | ||||
|     require(!vars.isFreezed, Errors.NO_UNFREEZED_RESERVE); | ||||
| 
 | ||||
|     require(vars.borrowingEnabled, BORROWING_NOT_ENABLED); | ||||
|     require(vars.borrowingEnabled, Errors.BORROWING_NOT_ENABLED); | ||||
| 
 | ||||
|     //validate interest rate mode | ||||
|     require( | ||||
|       uint256(ReserveLogic.InterestRateMode.VARIABLE) == interestRateMode || | ||||
|         uint256(ReserveLogic.InterestRateMode.STABLE) == interestRateMode, | ||||
|       INVALID_INTERESTRATE_MODE_SELECTED | ||||
|       Errors.INVALID_INTERESTRATE_MODE_SELECTED | ||||
|     ); | ||||
| 
 | ||||
|     //check that the amount is available in the reserve | ||||
|     vars.availableLiquidity = IERC20(reserveAddress).balanceOf(address(reserve.aTokenAddress)); | ||||
| 
 | ||||
|     require(vars.availableLiquidity >= amount, CURRENT_AVAILABLE_LIQUIDITY_NOT_ENOUGH); | ||||
|     require(vars.availableLiquidity >= amount, Errors.CURRENT_AVAILABLE_LIQUIDITY_NOT_ENOUGH); | ||||
| 
 | ||||
|     ( | ||||
|       vars.userCollateralBalanceETH, | ||||
|  | @ -167,11 +167,11 @@ library ValidationLogic { | |||
|       oracle | ||||
|     ); | ||||
| 
 | ||||
|     require(vars.userCollateralBalanceETH > 0, COLLATERAL_BALANCE_IS_0); | ||||
|     require(vars.userCollateralBalanceETH > 0, Errors.COLLATERAL_BALANCE_IS_0); | ||||
| 
 | ||||
|     require( | ||||
|       vars.healthFactor > GenericLogic.HEALTH_FACTOR_LIQUIDATION_THRESHOLD, | ||||
|       HEALTH_FACTOR_LOWER_THAN_LIQUIDATION_THRESHOLD | ||||
|       Errors.HEALTH_FACTOR_LOWER_THAN_LIQUIDATION_THRESHOLD | ||||
|     ); | ||||
| 
 | ||||
|     //add the current already borrowed amount to the amount requested to calculate the total collateral needed. | ||||
|  | @ -181,7 +181,7 @@ library ValidationLogic { | |||
| 
 | ||||
|     require( | ||||
|       vars.amountOfCollateralNeededETH <= vars.userCollateralBalanceETH, | ||||
|       COLLATERAL_CANNOT_COVER_NEW_BORROW | ||||
|       Errors.COLLATERAL_CANNOT_COVER_NEW_BORROW | ||||
|     ); | ||||
| 
 | ||||
|     /** | ||||
|  | @ -196,20 +196,20 @@ library ValidationLogic { | |||
|     if (vars.rateMode == ReserveLogic.InterestRateMode.STABLE) { | ||||
|       //check if the borrow mode is stable and if stable rate borrowing is enabled on this reserve | ||||
| 
 | ||||
|       require(vars.stableRateBorrowingEnabled, STABLE_BORROWING_NOT_ENABLED); | ||||
|       require(vars.stableRateBorrowingEnabled, Errors.STABLE_BORROWING_NOT_ENABLED); | ||||
| 
 | ||||
|       require( | ||||
|         !userConfig.isUsingAsCollateral(reserve.index) || | ||||
|           reserve.configuration.getLtv() == 0 || | ||||
|           amount > IERC20(reserve.aTokenAddress).balanceOf(msg.sender), | ||||
|         CALLATERAL_SAME_AS_BORROWING_CURRENCY | ||||
|         Errors.CALLATERAL_SAME_AS_BORROWING_CURRENCY | ||||
|       ); | ||||
| 
 | ||||
|       //calculate the max available loan size in stable rate mode as a percentage of the | ||||
|       //available liquidity | ||||
|       uint256 maxLoanSizeStable = vars.availableLiquidity.percentMul(maxStableLoanPercent); | ||||
| 
 | ||||
|       require(amount <= maxLoanSizeStable, AMOUNT_BIGGER_THAN_MAX_LOAN_SIZE_STABLE); | ||||
|       require(amount <= maxLoanSizeStable, Errors.AMOUNT_BIGGER_THAN_MAX_LOAN_SIZE_STABLE); | ||||
|     } | ||||
|   } | ||||
| 
 | ||||
|  | @ -231,21 +231,21 @@ library ValidationLogic { | |||
|   ) external view { | ||||
|     bool isActive = reserve.configuration.getActive(); | ||||
| 
 | ||||
|     require(isActive, NO_ACTIVE_RESERVE); | ||||
|     require(isActive, Errors.NO_ACTIVE_RESERVE); | ||||
| 
 | ||||
|     require(amountSent > 0, AMOUNT_NOT_GREATER_THAN_0); | ||||
|     require(amountSent > 0, Errors.AMOUNT_NOT_GREATER_THAN_0); | ||||
| 
 | ||||
|     require( | ||||
|       (stableDebt > 0 && | ||||
|         ReserveLogic.InterestRateMode(rateMode) == ReserveLogic.InterestRateMode.STABLE) || | ||||
|         (variableDebt > 0 && | ||||
|           ReserveLogic.InterestRateMode(rateMode) == ReserveLogic.InterestRateMode.VARIABLE), | ||||
|       NO_DEBT_OF_SELECTED_TYPE | ||||
|       Errors.NO_DEBT_OF_SELECTED_TYPE | ||||
|     ); | ||||
| 
 | ||||
|     require( | ||||
|       amountSent != uint256(-1) || msg.sender == onBehalfOf, | ||||
|       NO_EPLICIT_AMOUNT_TO_REPAY_ON_BEHALF | ||||
|       Errors.NO_EPLICIT_AMOUNT_TO_REPAY_ON_BEHALF | ||||
|     ); | ||||
|   } | ||||
| 
 | ||||
|  | @ -266,13 +266,13 @@ library ValidationLogic { | |||
|   ) external view { | ||||
|     (bool isActive, bool isFreezed, , bool stableRateEnabled) = reserve.configuration.getFlags(); | ||||
| 
 | ||||
|     require(isActive, NO_ACTIVE_RESERVE); | ||||
|     require(!isFreezed, NO_UNFREEZED_RESERVE); | ||||
|     require(isActive, Errors.NO_ACTIVE_RESERVE); | ||||
|     require(!isFreezed, Errors.NO_UNFREEZED_RESERVE); | ||||
| 
 | ||||
|     if (currentRateMode == ReserveLogic.InterestRateMode.STABLE) { | ||||
|       require(stableBorrowBalance > 0, NO_STABLE_RATE_LOAN_IN_RESERVE); | ||||
|       require(stableBorrowBalance > 0, Errors.NO_STABLE_RATE_LOAN_IN_RESERVE); | ||||
|     } else if (currentRateMode == ReserveLogic.InterestRateMode.VARIABLE) { | ||||
|       require(variableBorrowBalance > 0, NO_VARIABLE_RATE_LOAN_IN_RESERVE); | ||||
|       require(variableBorrowBalance > 0, Errors.NO_VARIABLE_RATE_LOAN_IN_RESERVE); | ||||
|       /** | ||||
|        * user wants to swap to stable, before swapping we need to ensure that | ||||
|        * 1. stable borrow rate is enabled on the reserve | ||||
|  | @ -280,17 +280,17 @@ library ValidationLogic { | |||
|        * more collateral than he is borrowing, artificially lowering | ||||
|        * the interest rate, borrowing at variable, and switching to stable | ||||
|        **/ | ||||
|       require(stableRateEnabled, STABLE_BORROWING_NOT_ENABLED); | ||||
|       require(stableRateEnabled, Errors.STABLE_BORROWING_NOT_ENABLED); | ||||
| 
 | ||||
|       require( | ||||
|         !userConfig.isUsingAsCollateral(reserve.index) || | ||||
|           reserve.configuration.getLtv() == 0 || | ||||
|           stableBorrowBalance.add(variableBorrowBalance) > | ||||
|           IERC20(reserve.aTokenAddress).balanceOf(msg.sender), | ||||
|         CALLATERAL_SAME_AS_BORROWING_CURRENCY | ||||
|         Errors.CALLATERAL_SAME_AS_BORROWING_CURRENCY | ||||
|       ); | ||||
|     } else { | ||||
|       revert(INVALID_INTERESTRATE_MODE_SELECTED); | ||||
|       revert(Errors.INVALID_INTERESTRATE_MODE_SELECTED); | ||||
|     } | ||||
|   } | ||||
| 
 | ||||
|  | @ -313,7 +313,7 @@ library ValidationLogic { | |||
|   ) external view { | ||||
|     uint256 underlyingBalance = IERC20(reserve.aTokenAddress).balanceOf(msg.sender); | ||||
| 
 | ||||
|     require(underlyingBalance > 0, UNDERLYING_BALANCE_NOT_GREATER_THAN_0); | ||||
|     require(underlyingBalance > 0, Errors.UNDERLYING_BALANCE_NOT_GREATER_THAN_0); | ||||
| 
 | ||||
|     require( | ||||
|       GenericLogic.balanceDecreaseAllowed( | ||||
|  | @ -325,7 +325,7 @@ library ValidationLogic { | |||
|         reserves, | ||||
|         oracle | ||||
|       ), | ||||
|       DEPOSIT_ALREADY_IN_USE | ||||
|       Errors.DEPOSIT_ALREADY_IN_USE | ||||
|     ); | ||||
|   } | ||||
| } | ||||
|  |  | |||
|  | @ -4,7 +4,7 @@ pragma solidity ^0.6.8; | |||
| import {ERC20} from './ERC20.sol'; | ||||
| import {LendingPool} from '../lendingpool/LendingPool.sol'; | ||||
| import {WadRayMath} from '../libraries/math/WadRayMath.sol'; | ||||
| import {Errors} from '../libraries/helpers/Errors'; | ||||
| import {Errors} from '../libraries/helpers/Errors.sol'; | ||||
| import {SafeERC20} from '@openzeppelin/contracts/token/ERC20/SafeERC20.sol'; | ||||
| import { | ||||
|   VersionedInitializable | ||||
|  | @ -35,12 +35,12 @@ contract AToken is VersionedInitializable, ERC20, IAToken { | |||
|   uint256 public constant ATOKEN_REVISION = 0x1; | ||||
| 
 | ||||
|   modifier onlyLendingPool { | ||||
|     require(msg.sender == address(_pool), CALLER_MUST_BE_LENDING_POOL); | ||||
|     require(msg.sender == address(_pool), Errors.CALLER_MUST_BE_LENDING_POOL); | ||||
|     _; | ||||
|   } | ||||
| 
 | ||||
|   modifier whenTransferAllowed(address from, uint256 amount) { | ||||
|     require(isTransferAllowed(from, amount), TRANSFER_CANNOT_BE_ALLOWED); | ||||
|     require(isTransferAllowed(from, amount), Errors.TRANSFER_CANNOT_BE_ALLOWED); | ||||
|     _; | ||||
|   } | ||||
| 
 | ||||
|  | @ -101,7 +101,7 @@ contract AToken is VersionedInitializable, ERC20, IAToken { | |||
|   function redirectInterestStreamOf(address from, address to) external override { | ||||
|     require( | ||||
|       msg.sender == _interestRedirectionAllowances[from], | ||||
|       CALLER_NOT_ALLOWED_TO_REDIRECT_INTEREST | ||||
|       Errors.NOT_ALLOWED_TO_REDIRECT_INTEREST | ||||
|     ); | ||||
|     _redirectInterestStream(from, to); | ||||
|   } | ||||
|  | @ -113,7 +113,7 @@ contract AToken is VersionedInitializable, ERC20, IAToken { | |||
|    * the allowance. | ||||
|    **/ | ||||
|   function allowInterestRedirectionTo(address to) external override { | ||||
|     require(to != msg.sender, CANNOT_GIVE_ALLOWANCE_TO_HIMSELF); | ||||
|     require(to != msg.sender, Errors.CANNOT_GIVE_ALLOWANCE_TO_HIMSELF); | ||||
|     _interestRedirectionAllowances[msg.sender] = to; | ||||
|     emit InterestRedirectionAllowanceChanged(msg.sender, to); | ||||
|   } | ||||
|  | @ -435,7 +435,7 @@ contract AToken is VersionedInitializable, ERC20, IAToken { | |||
|     address to, | ||||
|     uint256 value | ||||
|   ) internal { | ||||
|     require(value > 0, TRANSFER_AMOUNT_NOT_GT_0); | ||||
|     require(value > 0, Errors.TRANSFER_AMOUNT_NOT_GT_0); | ||||
| 
 | ||||
|     //cumulate the balance of the sender | ||||
|     (, uint256 fromBalance, uint256 fromBalanceIncrease, uint256 fromIndex) = _cumulateBalance( | ||||
|  | @ -484,7 +484,7 @@ contract AToken is VersionedInitializable, ERC20, IAToken { | |||
|   function _redirectInterestStream(address from, address to) internal { | ||||
|     address currentRedirectionAddress = _interestRedirectionAddresses[from]; | ||||
| 
 | ||||
|     require(to != currentRedirectionAddress, INTEREST_ALREADY_REDIRECTED); | ||||
|     require(to != currentRedirectionAddress, Errors.INTEREST_ALREADY_REDIRECTED); | ||||
| 
 | ||||
|     //accumulates the accrued interest to the principal | ||||
|     ( | ||||
|  | @ -494,7 +494,7 @@ contract AToken is VersionedInitializable, ERC20, IAToken { | |||
|       uint256 fromIndex | ||||
|     ) = _cumulateBalance(from); | ||||
| 
 | ||||
|     require(fromBalance > 0, NO_VALID_BALANCE_FOR_REDIRECT_INT_STREAM); | ||||
|     require(fromBalance > 0, Errors.NO_VALID_BALANCE_FOR_REDIRECT_INT_STREAM); | ||||
| 
 | ||||
|     //if the user is already redirecting the interest to someone, before changing | ||||
|     //the redirection address we substract the redirected balance of the previous | ||||
|  |  | |||
|  | @ -82,6 +82,28 @@ export enum ProtocolErrors { | |||
|   TRANSFER_AMOUNT_NOT_GT_0 = '31', // 'Transferred amount needs to be greater than zero'
 | ||||
|   INTEREST_ALREADY_REDIRECTED = '32', // 'Interest is already redirected to the user'
 | ||||
|   NO_VALID_BALANCE_FOR_REDIRECT_INT_STREAM = '33', // 'Interest stream can only be redirected if there is a valid balance'
 | ||||
| 
 | ||||
|   // old
 | ||||
| 
 | ||||
|   INVALID_CONFIGURATOR_CALLER_MSG = 'The caller must be a lending pool configurator contract', | ||||
|   INVALID_POOL_CALLER_MSG = 'The caller must be a lending pool contract', | ||||
|   // INVALID_POOL_CALLER_MSG_1 = 'The caller of this function must be a lending pool', => CALLER_MUST_BE_LENDING_POOL
 | ||||
|   INVALID_POOL_MANAGER_CALLER_MSG = 'The caller must be a lending pool manager', | ||||
|   INVALID_FROM_BALANCE_AFTER_TRANSFER = 'Invalid from balance after transfer', | ||||
|   INVALID_TO_BALANCE_AFTER_TRANSFER = 'Invalid from balance after transfer', | ||||
|   INVALID_OWNER_REVERT_MSG = 'Ownable: caller is not the owner', | ||||
|   INVALID_REDIRECTED_BALANCE_BEFORE_TRANSFER = 'Invalid redirected balance before transfer', | ||||
|   INVALID_REDIRECTED_BALANCE_AFTER_TRANSFER = 'Invalid redirected balance after transfer', | ||||
|   INVALID_REDIRECTION_ADDRESS = 'Invalid redirection address', | ||||
|   TRANSFERRED_AMOUNT_GT_ZERO = 'Transferred amount needs to be greater than zero', | ||||
|   ZERO_COLLATERAL = 'The collateral balance is 0', | ||||
|   INCONSISTENT_PROTOCOL_BALANCE = 'The actual balance of the protocol is inconsistent', | ||||
|   TOO_SMALL_FLASH_LOAN = 'The requested amount is too small for a FlashLoan.', | ||||
|   // NOT_ENOUGH_LIQUIDITY_TO_BORROW = 'There is not enough liquidity available to borrow',
 | ||||
|   HF_IS_NOT_BELLOW_THRESHOLD = 'Health factor is not below the threshold', | ||||
|   INVALID_HF = 'Invalid health factor', | ||||
|   USER_DID_NOT_BORROW_SPECIFIED = 'User did not borrow the specified currency', | ||||
|   THE_COLLATERAL_CHOSEN_CANNOT_BE_LIQUIDATED = 'The collateral chosen cannot be liquidated', | ||||
| } | ||||
| 
 | ||||
| export enum OLD_ProtocolErrors { | ||||
|  |  | |||
|  | @ -5,7 +5,7 @@ import {getContract} from '../helpers/contracts-helpers'; | |||
| import {StableDebtToken} from '../types/StableDebtToken'; | ||||
| 
 | ||||
| makeSuite('Stable debt token tests', (testEnv: TestEnv) => { | ||||
|   const {INVALID_POOL_CALLER_MSG_1} = ProtocolErrors; | ||||
|   const {CALLER_MUST_BE_LENDING_POOL} = ProtocolErrors; | ||||
| 
 | ||||
|   it('Tries to invoke mint not being the LendingPool', async () => { | ||||
|     const {deployer, pool, dai} = testEnv; | ||||
|  | @ -19,7 +19,7 @@ makeSuite('Stable debt token tests', (testEnv: TestEnv) => { | |||
|     ); | ||||
| 
 | ||||
|     await expect(stableDebtContract.mint(deployer.address, '1', '1')).to.be.revertedWith( | ||||
|       INVALID_POOL_CALLER_MSG_1 | ||||
|       CALLER_MUST_BE_LENDING_POOL | ||||
|     ); | ||||
|   }); | ||||
| 
 | ||||
|  | @ -35,7 +35,7 @@ makeSuite('Stable debt token tests', (testEnv: TestEnv) => { | |||
|     ); | ||||
| 
 | ||||
|     await expect(stableDebtContract.burn(deployer.address, '1')).to.be.revertedWith( | ||||
|       INVALID_POOL_CALLER_MSG_1 | ||||
|       CALLER_MUST_BE_LENDING_POOL | ||||
|     ); | ||||
|   }); | ||||
| }); | ||||
|  |  | |||
|  | @ -5,7 +5,7 @@ import {getContract} from '../helpers/contracts-helpers'; | |||
| import {VariableDebtToken} from '../types/VariableDebtToken'; | ||||
| 
 | ||||
| makeSuite('Variable debt token tests', (testEnv: TestEnv) => { | ||||
|   const {INVALID_POOL_CALLER_MSG_1} = ProtocolErrors; | ||||
|   const {CALLER_MUST_BE_LENDING_POOL} = ProtocolErrors; | ||||
| 
 | ||||
|   it('Tries to invoke mint not being the LendingPool', async () => { | ||||
|     const {deployer, pool, dai} = testEnv; | ||||
|  | @ -19,7 +19,7 @@ makeSuite('Variable debt token tests', (testEnv: TestEnv) => { | |||
|     ); | ||||
| 
 | ||||
|     await expect(variableDebtContract.mint(deployer.address, '1')).to.be.revertedWith( | ||||
|       INVALID_POOL_CALLER_MSG_1 | ||||
|       CALLER_MUST_BE_LENDING_POOL | ||||
|     ); | ||||
|   }); | ||||
| 
 | ||||
|  | @ -35,7 +35,7 @@ makeSuite('Variable debt token tests', (testEnv: TestEnv) => { | |||
|     ); | ||||
| 
 | ||||
|     await expect(variableDebtContract.burn(deployer.address, '1')).to.be.revertedWith( | ||||
|       INVALID_POOL_CALLER_MSG_1 | ||||
|       CALLER_MUST_BE_LENDING_POOL | ||||
|     ); | ||||
|   }); | ||||
| }); | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue
	
	Block a user
	 pol
						pol