From 948bd960be1bc345b2c54171271717039e0e076f Mon Sep 17 00:00:00 2001 From: The3D Date: Mon, 28 Sep 2020 19:33:39 +0200 Subject: [PATCH 01/35] Initial commit --- .../lendingpool/LendingPoolConfigurator.sol | 87 ++++++++++--------- contracts/libraries/helpers/Errors.sol | 1 + test/configurator.spec.ts | 2 +- 3 files changed, 47 insertions(+), 43 deletions(-) diff --git a/contracts/lendingpool/LendingPoolConfigurator.sol b/contracts/lendingpool/LendingPoolConfigurator.sol index 6bedff76..69b32cab 100644 --- a/contracts/lendingpool/LendingPoolConfigurator.sol +++ b/contracts/lendingpool/LendingPoolConfigurator.sol @@ -14,7 +14,7 @@ import {ILendingPoolAddressesProvider} from '../interfaces/ILendingPoolAddresses import {ILendingPool} from '../interfaces/ILendingPool.sol'; import {IERC20Detailed} from '../interfaces/IERC20Detailed.sol'; import {Errors} from '../libraries/helpers/Errors.sol'; - +import {PercentageMath} from '../libraries/math/PercentageMath.sol'; /** * @title LendingPoolConfigurator contract * @author Aave @@ -56,25 +56,19 @@ contract LendingPoolConfigurator is VersionedInitializable { event BorrowingDisabledOnReserve(address indexed asset); /** - * @dev emitted when a reserve is enabled as collateral. + * @dev emitted when a a reserve collateralization risk parameters are updated. * @param asset the address of the reserve * @param ltv the loan to value of the asset when used as collateral * @param liquidationThreshold the threshold at which loans using this asset as collateral will be considered undercollateralized * @param liquidationBonus the bonus liquidators receive to liquidate this asset **/ - event ReserveEnabledAsCollateral( + event CollateralConfigurationChanged( address indexed asset, uint256 ltv, uint256 liquidationThreshold, uint256 liquidationBonus ); - /** - * @dev emitted when a reserve is disabled as collateral - * @param asset the address of the reserve - **/ - event ReserveDisabledAsCollateral(address indexed asset); - /** * @dev emitted when stable rate borrowing is enabled on a reserve * @param asset the address of the reserve @@ -326,41 +320,45 @@ contract LendingPoolConfigurator is VersionedInitializable { } /** - * @dev enables a reserve to be used as collateral + * @dev configures the reserve collateralization parameters * @param asset the address of the reserve * @param ltv the loan to value of the asset when used as collateral * @param liquidationThreshold the threshold at which loans using this asset as collateral will be considered undercollateralized * @param liquidationBonus the bonus liquidators receive to liquidate this asset **/ - function enableReserveAsCollateral( + function configureReserveAsCollateral( address asset, uint256 ltv, uint256 liquidationThreshold, uint256 liquidationBonus ) external onlyAaveAdmin { + ReserveConfiguration.Map memory currentConfig = pool.getConfiguration(asset); + //validation of the parameters: the LTV can + //only be lower or equal than the liquidation threshold + //(otherwise a loan against the asset would cause instantaneous liquidation) + require(ltv <= liquidationThreshold, Errors.INVALID_CONFIGURATION); + + //liquidation bonus must be bigger than 100.00%, otherwise the liquidator would receive less + //collateral than needed to repay the debt + require(liquidationBonus > PercentageMath.PERCENTAGE_FACTOR, Errors.INVALID_CONFIGURATION); + + + //if the liquidation threshold is being set to 0, + // the reserve is being disabled as collateral. To do so, + //we need to ensure no liquidity is deposited + if(liquidationThreshold == 0) { + _checkNoLiquidity(asset); + } + currentConfig.setLtv(ltv); currentConfig.setLiquidationThreshold(liquidationThreshold); currentConfig.setLiquidationBonus(liquidationBonus); pool.setConfiguration(asset, currentConfig.data); - emit ReserveEnabledAsCollateral(asset, ltv, liquidationThreshold, liquidationBonus); - } - - /** - * @dev disables a reserve as collateral - * @param asset the address of the reserve - **/ - function disableReserveAsCollateral(address asset) external onlyAaveAdmin { - ReserveConfiguration.Map memory currentConfig = pool.getConfiguration(asset); - - currentConfig.setLtv(0); - - pool.setConfiguration(asset, currentConfig.data); - - emit ReserveDisabledAsCollateral(asset); + emit CollateralConfigurationChanged(asset, ltv, liquidationThreshold, liquidationBonus); } /** @@ -410,22 +408,8 @@ contract LendingPoolConfigurator is VersionedInitializable { * @param asset the address of the reserve **/ function deactivateReserve(address asset) external onlyAaveAdmin { - ( - uint256 availableLiquidity, - uint256 totalStableDebt, - uint256 totalVariableDebt, - , - , - , - , - , - , - - ) = pool.getReserveData(asset); - require( - availableLiquidity == 0 && totalStableDebt == 0 && totalVariableDebt == 0, - Errors.RESERVE_LIQUIDITY_NOT_0 - ); + + _checkNoLiquidity(asset); ReserveConfiguration.Map memory currentConfig = pool.getConfiguration(asset); @@ -601,4 +585,23 @@ contract LendingPoolConfigurator is VersionedInitializable { function setPoolPause(bool val) external onlyAaveAdmin { pool.setPause(val); } + + function _checkNoLiquidity(address asset) internal view { + ( + uint256 availableLiquidity, + uint256 totalStableDebt, + uint256 totalVariableDebt, + , + , + , + , + , + , + + ) = pool.getReserveData(asset); + require( + availableLiquidity == 0 && totalStableDebt == 0 && totalVariableDebt == 0, + Errors.RESERVE_LIQUIDITY_NOT_0 + ); + } } diff --git a/contracts/libraries/helpers/Errors.sol b/contracts/libraries/helpers/Errors.sol index 48fc7f32..3488fdae 100644 --- a/contracts/libraries/helpers/Errors.sol +++ b/contracts/libraries/helpers/Errors.sol @@ -61,6 +61,7 @@ library Errors { //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_CONFIGURATION = '52'; // 'Invalid risk parameters for the reserve' //require error messages - LendingPoolAddressesProviderRegistry string public constant PROVIDER_NOT_REGISTERED = '37'; // 'Provider is not registered' diff --git a/test/configurator.spec.ts b/test/configurator.spec.ts index 0fa3289c..7baf6838 100644 --- a/test/configurator.spec.ts +++ b/test/configurator.spec.ts @@ -104,7 +104,7 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => { it('Deactivates the ETH reserve as collateral', async () => { const {configurator, pool, weth} = testEnv; - await configurator.disableReserveAsCollateral(weth.address); + await configurator.configureReserveAsCollateral(weth.address, 0, 0, 0); const {usageAsCollateralEnabled} = await pool.getReserveConfigurationData(weth.address); expect(usageAsCollateralEnabled).to.be.equal(false); }); From 57ffc9c6139132fd69eb48fd034ffe081ee4f80e Mon Sep 17 00:00:00 2001 From: David Racero Date: Wed, 14 Oct 2020 11:03:32 +0200 Subject: [PATCH 02/35] Reorg errors library, sorted by error number, added prefix to each constant and a prefix glossary. --- .../LendingPoolAddressesProviderRegistry.sol | 2 +- contracts/lendingpool/LendingPool.sol | 20 +-- .../LendingPoolCollateralManager.sol | 10 +- .../lendingpool/LendingPoolConfigurator.sol | 4 +- contracts/libraries/helpers/Errors.sol | 143 +++++++++--------- contracts/libraries/logic/ReserveLogic.sol | 10 +- contracts/libraries/logic/ValidationLogic.sol | 102 +++++++------ contracts/libraries/math/PercentageMath.sol | 10 +- contracts/libraries/math/WadRayMath.sol | 24 +-- contracts/tokenization/AToken.sol | 8 +- contracts/tokenization/VariableDebtToken.sol | 4 +- contracts/tokenization/base/DebtTokenBase.sol | 2 +- helpers/types.ts | 112 +++++++------- test/addresses-provider-registry.spec.ts | 8 +- test/atoken-modifiers.spec.ts | 10 +- test/atoken-transfer.spec.ts | 14 +- test/collateral-swap.spec.ts | 18 +-- test/configurator.spec.ts | 70 ++++----- .../flash-liquidation-with-collateral.spec.ts | 4 +- test/flashloan.spec.ts | 18 +-- test/liquidation-atoken.spec.ts | 14 +- test/pausable-functions.spec.ts | 30 ++-- test/repay-with-collateral.spec.ts | 2 +- test/stable-token.spec.ts | 6 +- test/upgradeability.spec.ts | 8 +- test/variable-debt-token.spec.ts | 6 +- 26 files changed, 331 insertions(+), 328 deletions(-) diff --git a/contracts/configuration/LendingPoolAddressesProviderRegistry.sol b/contracts/configuration/LendingPoolAddressesProviderRegistry.sol index edc719ef..c61459ee 100644 --- a/contracts/configuration/LendingPoolAddressesProviderRegistry.sol +++ b/contracts/configuration/LendingPoolAddressesProviderRegistry.sol @@ -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); } diff --git a/contracts/lendingpool/LendingPool.sol b/contracts/lendingpool/LendingPool.sol index 21146298..6d63e714 100644 --- a/contracts/lendingpool/LendingPool.sol +++ b/contracts/lendingpool/LendingPool.sol @@ -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 ); } @@ -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) { @@ -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( @@ -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(); @@ -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)); @@ -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(); @@ -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)); @@ -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); @@ -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)); @@ -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; diff --git a/contracts/lendingpool/LendingPoolCollateralManager.sol b/contracts/lendingpool/LendingPoolCollateralManager.sol index 356ce1a4..b8fe3ba2 100644 --- a/contracts/lendingpool/LendingPoolCollateralManager.sol +++ b/contracts/lendingpool/LendingPoolCollateralManager.sol @@ -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 ); } } @@ -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); } /** @@ -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); } /** @@ -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); } /** diff --git a/contracts/lendingpool/LendingPoolConfigurator.sol b/contracts/lendingpool/LendingPoolConfigurator.sol index 3f8643ee..2641f9ab 100644 --- a/contracts/lendingpool/LendingPoolConfigurator.sol +++ b/contracts/lendingpool/LendingPoolConfigurator.sol @@ -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); _; } @@ -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); diff --git a/contracts/libraries/helpers/Errors.sol b/contracts/libraries/helpers/Errors.sol index ee71efaa..75d23dc2 100644 --- a/contracts/libraries/helpers/Errors.sol +++ b/contracts/libraries/helpers/Errors.sol @@ -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, diff --git a/contracts/libraries/logic/ReserveLogic.sol b/contracts/libraries/logic/ReserveLogic.sol index 8a3604f7..1afdde32 100644 --- a/contracts/libraries/logic/ReserveLogic.sol +++ b/contracts/libraries/logic/ReserveLogic.sol @@ -134,7 +134,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) @@ -185,7 +185,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); } @@ -203,7 +203,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()); @@ -385,7 +385,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); @@ -397,7 +397,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); } } diff --git a/contracts/libraries/logic/ValidationLogic.sol b/contracts/libraries/logic/ValidationLogic.sol index ee13232b..4c3a9fe8 100644 --- a/contracts/libraries/logic/ValidationLogic.sol +++ b/contracts/libraries/logic/ValidationLogic.sol @@ -37,9 +37,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); } /** @@ -58,9 +58,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( @@ -73,7 +73,7 @@ library ValidationLogic { reservesCount, oracle ), - Errors.TRANSFER_NOT_ALLOWED + Errors.VL_TRANSFER_NOT_ALLOWED ); } @@ -134,16 +134,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 ); ( @@ -161,11 +161,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. @@ -175,7 +175,7 @@ library ValidationLogic { require( vars.amountOfCollateralNeededETH <= vars.userCollateralBalanceETH, - Errors.COLLATERAL_CANNOT_COVER_NEW_BORROW + Errors.VL_COLLATERAL_CANNOT_COVER_NEW_BORROW ); /** @@ -190,20 +190,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, 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 ); //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, Errors.AMOUNT_BIGGER_THAN_MAX_LOAN_SIZE_STABLE); + require(amount <= maxLoanSizeStable, Errors.VL_AMOUNT_BIGGER_THAN_MAX_LOAN_SIZE_STABLE); } } @@ -225,21 +225,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 ); } @@ -260,13 +260,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(stableBorrowBalance > 0, Errors.NO_STABLE_RATE_LOAN_IN_RESERVE); + require(stableBorrowBalance > 0, Errors.VL_NO_STABLE_RATE_LOAN_IN_RESERVE); } else if (currentRateMode == ReserveLogic.InterestRateMode.VARIABLE) { - require(variableBorrowBalance > 0, Errors.NO_VARIABLE_RATE_LOAN_IN_RESERVE); + require(variableBorrowBalance > 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 @@ -274,17 +274,17 @@ 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 || stableBorrowBalance.add(variableBorrowBalance) > 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); } } @@ -308,7 +308,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( @@ -321,7 +321,7 @@ library ValidationLogic { reservesCount, oracle ), - Errors.DEPOSIT_ALREADY_IN_USE + Errors.VL_DEPOSIT_ALREADY_IN_USE ); } @@ -331,8 +331,11 @@ library ValidationLogic { * @param premium the premium paid on the flashloan **/ function validateFlashloan(uint256 mode, uint256 premium) internal pure { - require(premium > 0, Errors.REQUESTED_AMOUNT_TOO_SMALL); - require(mode <= uint256(ReserveLogic.InterestRateMode.VARIABLE), Errors.INVALID_FLASHLOAN_MODE); + require(premium > 0, Errors.LP_REQUESTED_AMOUNT_TOO_SMALL); + require( + mode <= uint256(ReserveLogic.InterestRateMode.VARIABLE), + Errors.LP_INVALID_FLASHLOAN_MODE + ); } /** @@ -355,13 +358,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 ); } @@ -372,18 +378,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); } /** @@ -408,7 +414,10 @@ 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 ( @@ -416,7 +425,7 @@ library ValidationLogic { ) { return ( uint256(Errors.CollateralManagerErrors.HEALTH_FACTOR_ABOVE_THRESHOLD), - Errors.HEALTH_FACTOR_NOT_BELOW_THRESHOLD + Errors.LPCM_HEALTH_FACTOR_NOT_BELOW_THRESHOLD ); } @@ -428,7 +437,7 @@ library ValidationLogic { if (!isCollateralEnabled) { return ( uint256(Errors.CollateralManagerErrors.COLLATERAL_CANNOT_BE_LIQUIDATED), - Errors.COLLATERAL_CANNOT_BE_LIQUIDATED + Errors.LPCM_COLLATERAL_CANNOT_BE_LIQUIDATED ); } } @@ -436,11 +445,11 @@ library ValidationLogic { 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); } /** @@ -459,21 +468,24 @@ library ValidationLogic { if (fromAsset == toAsset) { return ( uint256(Errors.CollateralManagerErrors.INVALID_EQUAL_ASSETS_TO_SWAP), - Errors.INVALID_EQUAL_ASSETS_TO_SWAP + Errors.LP_INVALID_EQUAL_ASSETS_TO_SWAP ); } (bool isToActive, bool isToFreezed, , ) = toReserve.configuration.getFlags(); if (!fromReserve.configuration.getActive() || !isToActive) { - return (uint256(Errors.CollateralManagerErrors.NO_ACTIVE_RESERVE), Errors.NO_ACTIVE_RESERVE); + return ( + uint256(Errors.CollateralManagerErrors.NO_ACTIVE_RESERVE), + Errors.VL_NO_ACTIVE_RESERVE + ); } if (isToFreezed) { return ( uint256(Errors.CollateralManagerErrors.NO_UNFREEZED_RESERVE), - Errors.NO_UNFREEZED_RESERVE + Errors.VL_NO_UNFREEZED_RESERVE ); } - return (uint256(Errors.CollateralManagerErrors.NO_ERROR), Errors.NO_ERRORS); + return (uint256(Errors.CollateralManagerErrors.NO_ERROR), Errors.LPCM_NO_ERRORS); } } diff --git a/contracts/libraries/math/PercentageMath.sol b/contracts/libraries/math/PercentageMath.sol index b853f1db..dabe5f38 100644 --- a/contracts/libraries/math/PercentageMath.sol +++ b/contracts/libraries/math/PercentageMath.sol @@ -28,11 +28,11 @@ library PercentageMath { uint256 result = value * percentage; - require(result / value == percentage, Errors.MULTIPLICATION_OVERFLOW); + require(result / value == percentage, Errors.MATH_MULTIPLICATION_OVERFLOW); result += HALF_PERCENT; - require(result >= HALF_PERCENT, Errors.ADDITION_OVERFLOW); + require(result >= HALF_PERCENT, Errors.MATH_ADDITION_OVERFLOW); return result / PERCENTAGE_FACTOR; } @@ -44,16 +44,16 @@ 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; uint256 result = value * PERCENTAGE_FACTOR; - require(result / PERCENTAGE_FACTOR == value, Errors.MULTIPLICATION_OVERFLOW); + require(result / PERCENTAGE_FACTOR == value, Errors.MATH_MULTIPLICATION_OVERFLOW); result += halfPercentage; - require(result >= halfPercentage, Errors.ADDITION_OVERFLOW); + require(result >= halfPercentage, Errors.MATH_ADDITION_OVERFLOW); return result / percentage; } diff --git a/contracts/libraries/math/WadRayMath.sol b/contracts/libraries/math/WadRayMath.sol index 7da5fc81..ae14a0d7 100644 --- a/contracts/libraries/math/WadRayMath.sol +++ b/contracts/libraries/math/WadRayMath.sol @@ -60,11 +60,11 @@ library WadRayMath { uint256 result = a * b; - require(result / a == b, Errors.MULTIPLICATION_OVERFLOW); + require(result / a == b, Errors.MATH_MULTIPLICATION_OVERFLOW); result += halfWAD; - require(result >= halfWAD, Errors.ADDITION_OVERFLOW); + require(result >= halfWAD, Errors.MATH_ADDITION_OVERFLOW); return result / WAD; } @@ -76,17 +76,17 @@ 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; uint256 result = a * WAD; - require(result / WAD == a, Errors.MULTIPLICATION_OVERFLOW); + require(result / WAD == a, Errors.MATH_MULTIPLICATION_OVERFLOW); result += halfB; - require(result >= halfB, Errors.ADDITION_OVERFLOW); + require(result >= halfB, Errors.MATH_ADDITION_OVERFLOW); return result / b; } @@ -104,11 +104,11 @@ library WadRayMath { uint256 result = a * b; - require(result / a == b, Errors.MULTIPLICATION_OVERFLOW); + require(result / a == b, Errors.MATH_MULTIPLICATION_OVERFLOW); result += halfRAY; - require(result >= halfRAY, Errors.ADDITION_OVERFLOW); + require(result >= halfRAY, Errors.MATH_ADDITION_OVERFLOW); return result / RAY; } @@ -120,17 +120,17 @@ 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; uint256 result = a * RAY; - require(result / RAY == a, Errors.MULTIPLICATION_OVERFLOW); + require(result / RAY == a, Errors.MATH_MULTIPLICATION_OVERFLOW); result += halfB; - require(result >= halfB, Errors.ADDITION_OVERFLOW); + require(result >= halfB, Errors.MATH_ADDITION_OVERFLOW); return result / b; } @@ -143,7 +143,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; } @@ -155,7 +155,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; } } diff --git a/contracts/tokenization/AToken.sol b/contracts/tokenization/AToken.sol index 3e6d4c76..1c95a67d 100644 --- a/contracts/tokenization/AToken.sol +++ b/contracts/tokenization/AToken.sol @@ -42,7 +42,7 @@ contract AToken is VersionedInitializable, IncentivizedERC20, IAToken { bytes32 public DOMAIN_SEPARATOR; modifier onlyLendingPool { - require(msg.sender == address(POOL), Errors.CALLER_MUST_BE_LENDING_POOL); + require(msg.sender == address(POOL), Errors.AT_CALLER_MUST_BE_LENDING_POOL); _; } @@ -102,7 +102,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 @@ -126,7 +126,7 @@ contract AToken is VersionedInitializable, IncentivizedERC20, IAToken { uint256 index ) external override onlyLendingPool { 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 @@ -315,7 +315,7 @@ contract AToken is VersionedInitializable, IncentivizedERC20, IAToken { bool validate ) internal { if (validate) { - require(isTransferAllowed(from, amount), Errors.TRANSFER_NOT_ALLOWED); + require(isTransferAllowed(from, amount), Errors.VL_TRANSFER_NOT_ALLOWED); } uint256 index = POOL.getReserveNormalizedIncome(UNDERLYING_ASSET_ADDRESS); diff --git a/contracts/tokenization/VariableDebtToken.sol b/contracts/tokenization/VariableDebtToken.sol index f8e48af9..2ed90526 100644 --- a/contracts/tokenization/VariableDebtToken.sol +++ b/contracts/tokenization/VariableDebtToken.sol @@ -61,7 +61,7 @@ contract VariableDebtToken is DebtTokenBase, IVariableDebtToken { uint256 index ) external override onlyLendingPool { uint256 amountScaled = amount.rayDiv(index); - require(amountScaled != 0, Errors.INVALID_MINT_AMOUNT); + require(amountScaled != 0, Errors.AT_INVALID_MINT_AMOUNT); _mint(user, amountScaled); @@ -80,7 +80,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); diff --git a/contracts/tokenization/base/DebtTokenBase.sol b/contracts/tokenization/base/DebtTokenBase.sol index 36d99d8e..59bd1ef5 100644 --- a/contracts/tokenization/base/DebtTokenBase.sol +++ b/contracts/tokenization/base/DebtTokenBase.sol @@ -26,7 +26,7 @@ abstract contract DebtTokenBase is IncentivizedERC20, VersionedInitializable { * @dev Only lending pool can call functions marked by this modifier **/ modifier onlyLendingPool { - require(msg.sender == address(POOL), Errors.CALLER_MUST_BE_LENDING_POOL); + require(msg.sender == address(POOL), Errors.AT_CALLER_MUST_BE_LENDING_POOL); _; } diff --git a/helpers/types.ts b/helpers/types.ts index 0b5e4a33..4a271acd 100644 --- a/helpers/types.ts +++ b/helpers/types.ts @@ -58,64 +58,62 @@ export enum eContractid { TokenDistributor = 'TokenDistributor', } +/* + * 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' - 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' - - //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 + 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' + AT_CALLER_MUST_BE_LENDING_POOL = '28', // 'The caller of this function must be a lending pool' + AT_CANNOT_GIVE_ALLOWANCE_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 = '34', // 'Reserve has already been initialized' + LPC_CALLER_NOT_AAVE_ADMIN = '35', // 'The caller must be the aave admin' + LPC_RESERVE_LIQUIDITY_NOT_0 = '36', // 'The liquidity of the reserve needs to be 0' + LPAPR_PROVIDER_NOT_REGISTERED = '37', // 'Provider is not registered' + LPCM_HEALTH_FACTOR_NOT_BELOW_THRESHOLD = '38', // 'Health factor is not below the threshold' + LPCM_COLLATERAL_CANNOT_BE_LIQUIDATED = '39', // 'The collateral chosen cannot be liquidated' + LPCM_SPECIFIED_CURRENCY_NOT_BORROWED_BY_USER = '40', // 'User did not borrow the specified currency' + LPCM_NOT_ENOUGH_LIQUIDITY_TO_LIQUIDATE = '41', // "There isn't enough liquidity available to liquidate" + LPCM_NO_ERRORS = '42', // 'No errors' + LP_INVALID_FLASHLOAN_MODE = '43', //Invalid flashloan mode + LP_INVALID_EQUAL_ASSETS_TO_SWAP = '56', // User can't use same reserve as destination of liquidity swap + P_IS_PAUSED = '58', // Pool is paused + LP_INVALID_FLASH_LOAN_EXECUTOR_RETURN = '60', // The flash loan received returned 0 (EOA) // old diff --git a/test/addresses-provider-registry.spec.ts b/test/addresses-provider-registry.spec.ts index 457514e4..5eb61aa0 100644 --- a/test/addresses-provider-registry.spec.ts +++ b/test/addresses-provider-registry.spec.ts @@ -54,22 +54,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 ); }); diff --git a/test/atoken-modifiers.spec.ts b/test/atoken-modifiers.spec.ts index 98495dec..e1b00203 100644 --- a/test/atoken-modifiers.spec.ts +++ b/test/atoken-modifiers.spec.ts @@ -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 ); }); }); diff --git a/test/atoken-transfer.spec.ts b/test/atoken-transfer.spec.ts index 0e207e17..085879a1 100644 --- a/test/atoken-transfer.spec.ts +++ b/test/atoken-transfer.spec.ts @@ -15,9 +15,9 @@ makeSuite('AToken: Transfer', (testEnv: TestEnv) => { INVALID_FROM_BALANCE_AFTER_TRANSFER, INVALID_TO_BALANCE_AFTER_TRANSFER, // ZERO_COLLATERAL, - COLLATERAL_BALANCE_IS_0, - TRANSFER_NOT_ALLOWED, - IS_PAUSED, + VL_COLLATERAL_BALANCE_IS_0, + VL_TRANSFER_NOT_ALLOWED, + P_IS_PAUSED, } = ProtocolErrors; it('User 0 deposits 1000 DAI, transfers to user 1', async () => { @@ -67,8 +67,8 @@ makeSuite('AToken: Transfer', (testEnv: TestEnv) => { AAVE_REFERRAL, users[1].address ), - COLLATERAL_BALANCE_IS_0 - ).to.be.revertedWith(COLLATERAL_BALANCE_IS_0); + VL_COLLATERAL_BALANCE_IS_0 + ).to.be.revertedWith(VL_COLLATERAL_BALANCE_IS_0); }); it('User 1 sets the DAI as collateral and borrows, tries to transfer everything back to user 0 (revert expected)', async () => { @@ -89,7 +89,7 @@ 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); }); }); diff --git a/test/collateral-swap.spec.ts b/test/collateral-swap.spec.ts index 18b39308..d18d80c4 100644 --- a/test/collateral-swap.spec.ts +++ b/test/collateral-swap.spec.ts @@ -14,10 +14,10 @@ const {expect} = require('chai'); makeSuite('LendingPool SwapDeposit function', (testEnv: TestEnv) => { let _mockSwapAdapter = {} as MockSwapAdapter; const { - HEALTH_FACTOR_LOWER_THAN_LIQUIDATION_THRESHOLD, - NO_UNFREEZED_RESERVE, - NO_ACTIVE_RESERVE, - INVALID_EQUAL_ASSETS_TO_SWAP, + VL_HEALTH_FACTOR_LOWER_THAN_LIQUIDATION_THRESHOLD, + VL_NO_UNFREEZED_RESERVE, + VL_NO_ACTIVE_RESERVE, + LP_INVALID_EQUAL_ASSETS_TO_SWAP, } = ProtocolErrors; before(async () => { @@ -35,7 +35,7 @@ makeSuite('LendingPool SwapDeposit function', (testEnv: TestEnv) => { '1'.toString(), '0x10' ) - ).to.be.revertedWith(INVALID_EQUAL_ASSETS_TO_SWAP); + ).to.be.revertedWith(LP_INVALID_EQUAL_ASSETS_TO_SWAP); }); it('Should not allow to swap if from or to reserves are not active', async () => { @@ -51,7 +51,7 @@ makeSuite('LendingPool SwapDeposit function', (testEnv: TestEnv) => { '1'.toString(), '0x10' ) - ).to.be.revertedWith(NO_ACTIVE_RESERVE); + ).to.be.revertedWith(VL_NO_ACTIVE_RESERVE); await configurator.activateReserve(weth.address); await configurator.deactivateReserve(dai.address); @@ -64,7 +64,7 @@ makeSuite('LendingPool SwapDeposit function', (testEnv: TestEnv) => { '1'.toString(), '0x10' ) - ).to.be.revertedWith(NO_ACTIVE_RESERVE); + ).to.be.revertedWith(VL_NO_ACTIVE_RESERVE); //cleanup state await configurator.activateReserve(dai.address); @@ -189,7 +189,7 @@ makeSuite('LendingPool SwapDeposit function', (testEnv: TestEnv) => { await expect( pool.swapLiquidity(_mockSwapAdapter.address, weth.address, dai.address, amountToSwap, '0x10') - ).to.be.revertedWith(HEALTH_FACTOR_LOWER_THAN_LIQUIDATION_THRESHOLD); + ).to.be.revertedWith(VL_HEALTH_FACTOR_LOWER_THAN_LIQUIDATION_THRESHOLD); }); it('Should set usage as collateral to false if no leftovers after swap', async () => { @@ -250,7 +250,7 @@ makeSuite('LendingPool SwapDeposit function', (testEnv: TestEnv) => { '1'.toString(), '0x10' ) - ).to.be.revertedWith(NO_UNFREEZED_RESERVE); + ).to.be.revertedWith(VL_NO_UNFREEZED_RESERVE); //cleanup state await configurator.unfreezeReserve(dai.address); diff --git a/test/configurator.spec.ts b/test/configurator.spec.ts index 5056eb8a..b7646740 100644 --- a/test/configurator.spec.ts +++ b/test/configurator.spec.ts @@ -10,7 +10,7 @@ const APPROVAL_AMOUNT_LENDING_POOL = const {expect} = require('chai'); makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => { - const {CALLER_NOT_AAVE_ADMIN, RESERVE_LIQUIDITY_NOT_0} = ProtocolErrors; + const {LPC_CALLER_NOT_AAVE_ADMIN, LPC_RESERVE_LIQUIDITY_NOT_0} = ProtocolErrors; it('Deactivates the ETH reserve', async () => { const {configurator, pool, weth} = testEnv; @@ -31,16 +31,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 () => { @@ -100,16 +100,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 () => { @@ -172,16 +172,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 () => { @@ -241,8 +241,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 () => { @@ -251,8 +251,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 () => { @@ -311,16 +311,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 () => { @@ -353,8 +353,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 () => { @@ -387,8 +387,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 () => { @@ -421,8 +421,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 () => { @@ -455,24 +455,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 () => { @@ -489,7 +489,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); }); }); diff --git a/test/flash-liquidation-with-collateral.spec.ts b/test/flash-liquidation-with-collateral.spec.ts index fd157282..4dea77ab 100644 --- a/test/flash-liquidation-with-collateral.spec.ts +++ b/test/flash-liquidation-with-collateral.spec.ts @@ -16,7 +16,7 @@ const {expect} = require('chai'); const {parseUnits, parseEther} = ethers.utils; makeSuite('LendingPool. repayWithCollateral() with liquidator', (testEnv: TestEnv) => { - const {INVALID_HF, COLLATERAL_CANNOT_BE_LIQUIDATED, IS_PAUSED} = ProtocolErrors; + const {INVALID_HF, LPCM_COLLATERAL_CANNOT_BE_LIQUIDATED, P_IS_PAUSED} = ProtocolErrors; it('User 1 provides some liquidity for others to borrow', async () => { const {pool, weth, dai, usdc, deployer} = testEnv; @@ -898,7 +898,7 @@ makeSuite('LendingPool. repayWithCollateral() with liquidator', (testEnv: TestEn mockSwapAdapter.address, '0x' ) - ).to.be.revertedWith(COLLATERAL_CANNOT_BE_LIQUIDATED); + ).to.be.revertedWith(LPCM_COLLATERAL_CANNOT_BE_LIQUIDATED); const repayWithCollateralTimestamp = await timeLatest(); diff --git a/test/flashloan.spec.ts b/test/flashloan.spec.ts index 93d748b0..cee42a73 100644 --- a/test/flashloan.spec.ts +++ b/test/flashloan.spec.ts @@ -18,13 +18,13 @@ 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, + LP_REQUESTED_AMOUNT_TOO_SMALL, TRANSFER_AMOUNT_EXCEEDS_BALANCE, - INVALID_FLASHLOAN_MODE, + LP_INVALID_FLASHLOAN_MODE, SAFEERC20_LOWLEVEL_CALL, - IS_PAUSED, - INVALID_FLASH_LOAN_EXECUTOR_RETURN, + P_IS_PAUSED, + LP_INVALID_FLASH_LOAN_EXECUTOR_RETURN, } = ProtocolErrors; before(async () => { @@ -134,7 +134,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 () => { @@ -154,7 +154,7 @@ makeSuite('LendingPool FlashLoan function', (testEnv: TestEnv) => { '0x10', '0' ) - ).to.be.revertedWith(INVALID_FLASHLOAN_MODE); + ).to.be.revertedWith(LP_INVALID_FLASHLOAN_MODE); }); it('Caller deposits 1000 DAI as collateral, Takes WETH flashloan with mode = 2, does not return the funds. A variable loan for caller is created', async () => { @@ -206,7 +206,7 @@ makeSuite('LendingPool FlashLoan function', (testEnv: TestEnv) => { '0x10', '0' ) - ).to.be.revertedWith(REQUESTED_AMOUNT_TOO_SMALL); + ).to.be.revertedWith(LP_REQUESTED_AMOUNT_TOO_SMALL); }); it('tries to take a flashloan that is bigger than the available liquidity (revert expected)', async () => { @@ -296,7 +296,7 @@ makeSuite('LendingPool FlashLoan function', (testEnv: TestEnv) => { pool .connect(caller.signer) .flashLoan(_mockFlashLoanReceiver.address, usdc.address, flashloanAmount, 2, '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 () => { diff --git a/test/liquidation-atoken.spec.ts b/test/liquidation-atoken.spec.ts index 4f4eb667..52976429 100644 --- a/test/liquidation-atoken.spec.ts +++ b/test/liquidation-atoken.spec.ts @@ -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 () => { diff --git a/test/pausable-functions.spec.ts b/test/pausable-functions.spec.ts index 3403491c..c5e87322 100644 --- a/test/pausable-functions.spec.ts +++ b/test/pausable-functions.spec.ts @@ -12,8 +12,8 @@ makeSuite('Pausable Pool', (testEnv: TestEnv) => { let _mockFlashLoanReceiver = {} as MockFlashLoanReceiver; const { - IS_PAUSED, - TRANSFER_NOT_ALLOWED, + P_IS_PAUSED, + VL_TRANSFER_NOT_ALLOWED, INVALID_FROM_BALANCE_AFTER_TRANSFER, INVALID_TO_BALANCE_AFTER_TRANSFER, } = ProtocolErrors; @@ -44,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); @@ -91,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); @@ -116,7 +116,7 @@ makeSuite('Pausable Pool', (testEnv: TestEnv) => { // user tries to burn await expect( pool.connect(users[0].signer).withdraw(dai.address, amountDAItoDeposit) - ).to.revertedWith(IS_PAUSED); + ).to.revertedWith(P_IS_PAUSED); // Configurator unpauses the pool await configurator.setPoolPause(false); @@ -133,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); @@ -149,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 +165,7 @@ makeSuite('Pausable Pool', (testEnv: TestEnv) => { // Try to execute liquidation await expect( pool.connect(user.signer).swapLiquidity(user.address, dai.address, weth.address, '1', '0x') - ).revertedWith(IS_PAUSED); + ).revertedWith(P_IS_PAUSED); // Unpause the pool await configurator.setPoolPause(false); @@ -180,7 +180,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 @@ -207,7 +207,7 @@ makeSuite('Pausable Pool', (testEnv: TestEnv) => { mockSwapAdapter.address, '0x' ) - ).revertedWith(IS_PAUSED); + ).revertedWith(P_IS_PAUSED); // Unpause the pool await configurator.setPoolPause(false); @@ -229,7 +229,7 @@ makeSuite('Pausable Pool', (testEnv: TestEnv) => { pool .connect(caller.signer) .flashLoan(_mockFlashLoanReceiver.address, weth.address, flashAmount, 1, '0x10', '0') - ).revertedWith(IS_PAUSED); + ).revertedWith(P_IS_PAUSED); // Unpause pool await configurator.setPoolPause(false); @@ -307,7 +307,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); @@ -336,7 +336,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); @@ -350,7 +350,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); @@ -370,7 +370,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); diff --git a/test/repay-with-collateral.spec.ts b/test/repay-with-collateral.spec.ts index a6df9f99..81a96af9 100644 --- a/test/repay-with-collateral.spec.ts +++ b/test/repay-with-collateral.spec.ts @@ -37,7 +37,7 @@ export const expectRepayWithCollateralEvent = ( }; makeSuite('LendingPool. repayWithCollateral()', (testEnv: TestEnv) => { - const {IS_PAUSED} = ProtocolErrors; + const {P_IS_PAUSED} = ProtocolErrors; it("It's not possible to repayWithCollateral() on a non-active collateral or a non active principal", async () => { const {configurator, weth, pool, users, dai, mockSwapAdapter} = testEnv; const user = users[1]; diff --git a/test/stable-token.spec.ts b/test/stable-token.spec.ts index 1d6adcdb..d3313ff5 100644 --- a/test/stable-token.spec.ts +++ b/test/stable-token.spec.ts @@ -5,7 +5,7 @@ import {getContract} from '../helpers/contracts-helpers'; import {StableDebtToken} from '../types/StableDebtToken'; 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} = testEnv; @@ -19,7 +19,7 @@ makeSuite('Stable debt token tests', (testEnv: TestEnv) => { ); await expect(stableDebtContract.mint(deployer.address, '1', '1')).to.be.revertedWith( - CALLER_MUST_BE_LENDING_POOL + AT_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( - CALLER_MUST_BE_LENDING_POOL + AT_CALLER_MUST_BE_LENDING_POOL ); }); }); diff --git a/test/upgradeability.spec.ts b/test/upgradeability.spec.ts index 11680124..8c123181 100644 --- a/test/upgradeability.spec.ts +++ b/test/upgradeability.spec.ts @@ -13,7 +13,7 @@ import {MockVariableDebtToken} from '../types/MockVariableDebtToken'; import {ZERO_ADDRESS} from '../helpers/constants'; 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; @@ -61,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 () => { @@ -83,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 () => { @@ -112,7 +112,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 () => { diff --git a/test/variable-debt-token.spec.ts b/test/variable-debt-token.spec.ts index a79bdde2..bfc88f93 100644 --- a/test/variable-debt-token.spec.ts +++ b/test/variable-debt-token.spec.ts @@ -5,7 +5,7 @@ import {getContract} from '../helpers/contracts-helpers'; import {VariableDebtToken} from '../types/VariableDebtToken'; 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} = testEnv; @@ -19,7 +19,7 @@ makeSuite('Variable debt token tests', (testEnv: TestEnv) => { ); await expect(variableDebtContract.mint(deployer.address, '1', '1')).to.be.revertedWith( - CALLER_MUST_BE_LENDING_POOL + AT_CALLER_MUST_BE_LENDING_POOL ); }); @@ -35,7 +35,7 @@ makeSuite('Variable debt token tests', (testEnv: TestEnv) => { ); await expect(variableDebtContract.burn(deployer.address, '1', '1')).to.be.revertedWith( - CALLER_MUST_BE_LENDING_POOL + AT_CALLER_MUST_BE_LENDING_POOL ); }); }); From 224712f9d5cee8b4a4c37af6b4a5d0ee46b540bd Mon Sep 17 00:00:00 2001 From: pistiner <59415933+orpistiner@users.noreply.github.com> Date: Thu, 15 Oct 2020 00:59:12 +0300 Subject: [PATCH 03/35] Aave integration - first step --- contracts/tokenization/StableDebtToken.sol | 2 +- runUserConfigCLI.sh | 1 + runVariableTokenCLI.sh | 1 + specs/StableDebtToken.spec | 165 +++++++++++++ specs/UserConfiguration.spec | 66 +++++ specs/VariableDebtToken.spec | 173 +++++++++++++ specs/harness/LendingPoolHarness.sol | 273 +++++++++++++++++++++ specs/harness/StableDebtTokenHarness.sol | 31 +++ specs/harness/UserConfigurationHarness.sol | 78 ++++++ 9 files changed, 789 insertions(+), 1 deletion(-) create mode 100644 runUserConfigCLI.sh create mode 100644 runVariableTokenCLI.sh create mode 100644 specs/StableDebtToken.spec create mode 100644 specs/UserConfiguration.spec create mode 100644 specs/VariableDebtToken.spec create mode 100644 specs/harness/LendingPoolHarness.sol create mode 100644 specs/harness/StableDebtTokenHarness.sol create mode 100644 specs/harness/UserConfigurationHarness.sol diff --git a/contracts/tokenization/StableDebtToken.sol b/contracts/tokenization/StableDebtToken.sol index 160d0f88..e0f48836 100644 --- a/contracts/tokenization/StableDebtToken.sol +++ b/contracts/tokenization/StableDebtToken.sol @@ -280,7 +280,7 @@ contract StableDebtToken is IStableDebtToken, DebtTokenBase { * @param avgRate the average rate at which calculate the total supply * @return The debt balance of the user since the last burn/mint action **/ - function _calcTotalSupply(uint256 avgRate) internal view returns(uint256) { + function _calcTotalSupply(uint256 avgRate) internal virtual view returns(uint256) { // Certora: Added virtual modifier uint256 principalSupply = super.totalSupply(); if (principalSupply == 0) { diff --git a/runUserConfigCLI.sh b/runUserConfigCLI.sh new file mode 100644 index 00000000..f3ddbacc --- /dev/null +++ b/runUserConfigCLI.sh @@ -0,0 +1 @@ +certoraRun specs/harness/UserConfigurationHarness.sol --solc solc6.8 --verify UserConfigurationHarness:specs/UserConfiguration.spec --settings -useBitVectorTheory --staging master diff --git a/runVariableTokenCLI.sh b/runVariableTokenCLI.sh new file mode 100644 index 00000000..2b7abdc4 --- /dev/null +++ b/runVariableTokenCLI.sh @@ -0,0 +1 @@ +certoraRun contracts/tokenization/VariableDebtToken.sol:VariableDebtToken specs/harness/LendingPoolHarness.sol --solc solc6.8 --link VariableDebtToken:POOL=LendingPoolHarness --verify VariableDebtToken:specs/VariableDebtToken.spec --settings -assumeUnwindCond,-useNonLinearArithmetic --cache VariableDebtToken --staging master \ No newline at end of file diff --git a/specs/StableDebtToken.spec b/specs/StableDebtToken.spec new file mode 100644 index 00000000..fba0f8ba --- /dev/null +++ b/specs/StableDebtToken.spec @@ -0,0 +1,165 @@ +methods { + getUserLastUpdated(address) returns uint40 envfree +} + +ghost ghostSupply() returns uint256; + +hook Sstore (slot 0)[address a] uint256 balance (uint256 old_balance) STORAGE { + require old_balance <= ghostSupply(); + havoc ghostSupply assuming ghostSupply@new() == ghostSupply@old() + (balance - old_balance); +} + +rule integrityTimeStamp(address user, method f) { + env e; + require sinvoke getIncentivesController(e) == 0; + require getUserLastUpdated(user) <= e.block.timestamp; + calldataarg arg; + sinvoke f(e,arg); + assert getUserLastUpdated(user) <= e.block.timestamp; +} + +rule totalSupplyInvariant(method f) { + env e; + require sinvoke getIncentivesController(e) == 0; + require totalSupply(e) == ghostSupply(); + calldataarg arg; + sinvoke f(e, arg); + assert totalSupply(e) == ghostSupply(); +} + +/** +TotalSupply is the sum of all users’ balances + +totalSupply(t) = Σaddress u. balanceOf(u,t) + +Check that each possible opertaion changes the balance of at most one user +*/ +rule balanceOfChange(address a, address b, method f ) +{ + env e; + require a!=b; + require sinvoke getIncentivesController(e) == 0; + uint256 balanceABefore = sinvoke balanceOf(e,a); + uint256 balanceBBefore = sinvoke balanceOf(e,b); + + calldataarg arg; + sinvoke f(e, arg); + + uint256 balanceAAfter = sinvoke balanceOf(e,a); + uint256 balanceBAfter = sinvoke balanceOf(e,b); + + assert ( balanceABefore == balanceAAfter || balanceBBefore == balanceBAfter ); +} + +/** +Check that the change to total supply is coherent with the changes to balance +*/ +rule integirtyBalanceOfTotalSupply(address a, method f ) +{ + env e; + require sinvoke getIncentivesController(e) == 0; + uint256 balanceABefore = sinvoke balanceOf(e,a); + uint256 totalSupplyBefore = sinvoke totalSupply(e); + + calldataarg arg; + sinvoke f(e, arg); + require (f.selector != burn(address,uint256).selector ); + uint256 balanceAAfter = sinvoke balanceOf(e,a); + uint256 totalSupplyAfter = sinvoke totalSupply(e); + + assert (balanceAAfter != balanceABefore => ( balanceAAfter - balanceABefore == totalSupplyAfter - totalSupplyBefore)); +} + +/* Burn behaves differently and due to accumulation errors might have less total supply than the balance +*/ +rule integirtyBalanceOfTotalSupplyOnBurn(address a, method f) +{ + env e; + require sinvoke getIncentivesController(e) == 0; + uint256 balanceABefore = sinvoke balanceOf(e,a); + uint256 totalSupplyBefore = sinvoke totalSupply(e); + + uint256 x; + sinvoke burn(e, a, x); + uint256 balanceAAfter = sinvoke balanceOf(e,a); + uint256 totalSupplyAfter = sinvoke totalSupply(e); + if (totalSupplyBefore > x) + assert (balanceAAfter != balanceABefore => ( balanceAAfter - balanceABefore == totalSupplyAfter - totalSupplyBefore)); + else + assert (totalSupplyAfter == 0 ); +} + +/** +Mint inceases the balanceOf user a as expected +*/ +rule integrityMint(address a, uint256 x) { + env e; + require sinvoke getIncentivesController(e) == 0; + uint256 index; + uint256 balancebefore = sinvoke balanceOf(e,a); + sinvoke mint(e,a,x,index); + + uint256 balanceAfter = sinvoke balanceOf(e,a); + assert balanceAfter == balancebefore+x; +} + +/** +Mint is additive, can performed either all at once or gradually +mint(u,x); mint(u,y) ~ mint(u,x+y) at the same timestamp +*/ +rule additiveMint(address a, uint256 x, uint256 y) { + env e; + require sinvoke getIncentivesController(e) == 0; + uint256 index; + storage initialStorage = lastStorage; + sinvoke mint(e,a,x,index); + sinvoke mint(e,a,y,index); + uint256 balanceScenario1 = sinvoke balanceOf(e,a); + uint t = x + y; + sinvoke mint(e,a, t ,index) at initialStorage; + + uint256 balanceScenario2 = sinvoke balanceOf(e,a); + assert balanceScenario1 == balanceScenario2, "mint is not additive"; +} + +rule integrityBurn(address a, uint256 x) { + env e; + require sinvoke getIncentivesController(e) == 0; + uint256 index; + uint256 balancebefore = sinvoke balanceOf(e,a); + sinvoke burn(e,a,x); + + uint256 balanceAfter = sinvoke balanceOf(e,a); + assert balanceAfter == balancebefore - x; +} + +rule additiveBurn(address a, uint256 x, uint256 y) { + env e; + require sinvoke getIncentivesController(e) == 0; + storage initialStorage = lastStorage; + sinvoke burn(e, a, x); + sinvoke burn(e, a, y); + uint256 balanceScenario1 = balanceOf(e, a); + uint t = x + y; + sinvoke burn(e, a, t) at initialStorage; + + uint256 balanceScenario2 = balanceOf(e, a); + assert balanceScenario1 == balanceScenario2, "burn is not additive"; +} + + +/** +mint and burn are inverse operations +Thus, totalSupply is back to initial state +BalanceOf user is back to initial state */ +rule inverseMintBurn(address a, uint256 x) { + env e; + require sinvoke getIncentivesController(e) == 0; + uint256 index; + uint256 balancebefore = sinvoke balanceOf(e,a); + sinvoke mint(e,a,x,index); + sinvoke burn(e,a,x); + uint256 balanceAfter = sinvoke balanceOf(e,a); + assert balancebefore == balanceAfter, "burn is not inverse of mint"; +} + diff --git a/specs/UserConfiguration.spec b/specs/UserConfiguration.spec new file mode 100644 index 00000000..14fce3a6 --- /dev/null +++ b/specs/UserConfiguration.spec @@ -0,0 +1,66 @@ +methods { + setBorrowing(address, uint256, bool) envfree + setUsingAsCollateral(address, uint256, bool) envfree + isUsingAsCollateralOrBorrowing(address, uint256) returns bool envfree + isBorrowing(address, uint256) returns bool envfree + isUsingAsCollateral(address, uint256) returns bool envfree + isBorrowingAny(address ) returns bool envfree + isEmpty(address ) returns bool envfree +} + +invariant empty(address user, uint256 reserveIndex ) + isEmpty(user) => !isBorrowingAny(user) && !isUsingAsCollateralOrBorrowing(user, reserveIndex) + +invariant notEmpty(address user, uint256 reserveIndex ) + ( isBorrowingAny(user) || isUsingAsCollateral(user, reserveIndex)) => !isEmpty(user) + + +invariant borrowing(address user, uint256 reserveIndex ) + isBorrowing(user, reserveIndex) => isBorrowingAny(user) + +invariant collateralOrBorrowing(address user, uint256 reserveIndex ) + ( isUsingAsCollateral(user, reserveIndex) || isBorrowing(user, reserveIndex) ) <=> isUsingAsCollateralOrBorrowing(user, reserveIndex) + + + +rule setBorrowing(address user, uint256 reserveIndex, bool borrowing) +{ + require reserveIndex < 128; + + setBorrowing(user, reserveIndex, borrowing); + assert isBorrowing(user, reserveIndex) == borrowing, "unexpected result"; +} + +rule setBorrowingNoChangeToOther(address user, uint256 reserveIndex, uint256 reserveIndexOther, bool borrowing) +{ + require reserveIndexOther != reserveIndex; + require reserveIndexOther < 128 && reserveIndex < 128; + bool otherReserveBorrowing = isBorrowing(user, reserveIndexOther); + bool otherReserveCollateral = isUsingAsCollateral(user,reserveIndexOther); + + setBorrowing(user, reserveIndex, borrowing); + assert otherReserveBorrowing == isBorrowing(user, reserveIndexOther) && + otherReserveCollateral == isUsingAsCollateral(user,reserveIndexOther), "changed to other reserve"; +} + + +rule setUsingAsCollateral(address user, uint256 reserveIndex, bool usingAsCollateral) +{ + require reserveIndex < 128; + + setUsingAsCollateral(user, reserveIndex, usingAsCollateral); + assert isUsingAsCollateral(user, reserveIndex) == usingAsCollateral, "unexpected result"; +} + + +rule setUsingAsCollateralNoChangeToOther(address user, uint256 reserveIndex, uint256 reserveIndexOther, bool usingAsCollateral) +{ + require reserveIndexOther != reserveIndex; + require reserveIndexOther < 128 && reserveIndex < 128; + bool otherReserveBorrowing = isBorrowing(user, reserveIndexOther); + bool otherReserveCollateral = isUsingAsCollateral(user,reserveIndexOther); + + setUsingAsCollateral(user, reserveIndex, usingAsCollateral); + assert otherReserveBorrowing == isBorrowing(user, reserveIndexOther) && + otherReserveCollateral == isUsingAsCollateral(user,reserveIndexOther), "changed to other reserve"; +} diff --git a/specs/VariableDebtToken.spec b/specs/VariableDebtToken.spec new file mode 100644 index 00000000..854ee9d7 --- /dev/null +++ b/specs/VariableDebtToken.spec @@ -0,0 +1,173 @@ +using LendingPoolHarness as POOL +/** +TotalSupply is the sum of all users’ balances + +totalSupply(t) = Σaddress u. balanceOf(u,t) + +Check that each possible opertaion changes the balance of at most one user +*/ +rule balanceOfChange(address a, address b, method f) +{ + env e; + require a!=b ; + uint256 balanceABefore = sinvoke balanceOf(e, a); + uint256 balanceBBefore = sinvoke balanceOf(e, b); + + calldataarg arg; + sinvoke f(e, arg); + + uint256 balanceAAfter = sinvoke balanceOf(e, a); + uint256 balanceBAfter = sinvoke balanceOf(e, b); + + assert ( balanceABefore == balanceAAfter || balanceBBefore == balanceBAfter ); +} + +/* +Check that the changed to total supply is coherent with the changes to balance +*/ + +rule integirtyBalanceOfTotalSupply(address a, method f ) +{ + env e; + + uint256 balanceABefore = balanceOf(e, a); + uint256 totalSupplyBefore = totalSupply(e); + + calldataarg arg; + sinvoke f(e, arg); + require (f.selector != burn(address, uint256, uint256).selector && + f.selector != mint(address, uint256, uint256).selector ) ; + uint256 balanceAAfter = balanceOf(e, a); + uint256 totalSupplyAfter = totalSupply(e); + + assert (balanceAAfter != balanceABefore => ( balanceAAfter - balanceABefore == totalSupplyAfter - totalSupplyBefore)); +} + +/* Burn behaves deferently and due to accumulation errors might hace less total supply then the balance +*/ + +rule integirtyBalanceOfTotalSupplyOnBurn(address a, method f ) +{ + env e; + + uint256 balanceABefore = balanceOf(e, a); + uint256 totalSupplyBefore = totalSupply(e); + + uint256 x; + address asset; + uint256 index = POOL.getReserveNormalizedVariableDebt(e, asset); + sinvoke burn(e, a, x, index); + uint256 balanceAAfter = balanceOf(e, a); + uint256 totalSupplyAfter = totalSupply(e); + assert (balanceAAfter != balanceABefore => ( balanceAAfter - balanceABefore == totalSupplyAfter - totalSupplyBefore)); +} + +rule integirtyBalanceOfTotalSupplyOnMint(address a, method f ) +{ + env e; + + uint256 balanceABefore = balanceOf(e, a); + uint256 totalSupplyBefore = totalSupply(e); + + uint256 x; + address asset; + uint256 index = POOL.getReserveNormalizedVariableDebt(e, asset); + sinvoke mint(e, a, x, index); + uint256 balanceAAfter = balanceOf(e, a); + uint256 totalSupplyAfter = totalSupply(e); + assert (balanceAAfter != balanceABefore => ( balanceAAfter - balanceABefore == totalSupplyAfter - totalSupplyBefore)); +} + +/** +Minting an amount of x tokens for user u increases their balance by x, up to rounding errors. +{ b= balanceOf(u,t) } +mint(u,x,index) +{ balanceOf(u,t) = b + x } + +*/ +rule integrityMint(address a, uint256 x) { + env e; + address asset; + uint256 index = POOL.getReserveNormalizedVariableDebt(e,asset); + uint256 balancebefore = balanceOf(e, a); + sinvoke mint(e, a, x, index); + + uint256 balanceAfter = balanceOf(e, a); + assert balanceAfter == balancebefore+x; +} + +/** +Mint is additive, can performed either all at once or gradually +mint(u,x); mint(u,y) ~ mint(u,x+y) at the same timestamp +*/ +rule additiveMint(address a, uint256 x, uint256 y) { + env e; + address asset; + uint256 index = POOL.getReserveNormalizedVariableDebt(e, asset); + storage initialStorage = lastStorage; + sinvoke mint(e, a, x, index); + sinvoke mint(e, a, y, index); + uint256 balanceScenario1 = balanceOf(e, a); + uint t = x + y; + sinvoke mint(e, a, t ,index) at initialStorage; + + uint256 balanceScenario2 = balanceOf(e, a); + assert balanceScenario1 == balanceScenario2, "mint is not additive"; +} + +/** +Transfer of x amount of tokens from user u where receiver is user u’ +{bu = balanceOf(u) } + burn(u, u’, x) +{balanceOf(u) = bu - x } +*/ +rule integrityBurn(address a, uint256 x) { + env e; + address asset; + uint256 index = POOL.getReserveNormalizedVariableDebt(e, asset); + uint256 balancebefore = balanceOf(e, a); + sinvoke burn(e, a, x, index); + + uint256 balanceAfter = balanceOf(e, a); + assert balanceAfter == balancebefore - x; +} +/** +Minting is additive, i.e., it can be performed either all at once or in steps. + +burn(u, u’, x); burn(u, u’, y) ~ burn(u, u’, x+y) +*/ +rule additiveBurn(address a, uint256 x, uint256 y) { + env e; + address asset; + uint256 index = POOL.getReserveNormalizedVariableDebt(e, asset); + storage initialStorage = lastStorage; + sinvoke burn(e, a, x, index); + sinvoke burn(e, a, y, index); + uint256 balanceScenario1 = balanceOf(e, a); + uint t = x + y; + sinvoke burn(e, a, t ,index) at initialStorage; + + uint256 balanceScenario2 = balanceOf(e, a); + assert balanceScenario1 == balanceScenario2, "burn is not additive"; +} + +/** +Minting and burning are inverse operations. + +{bu = balanceOf(u) } +mint(u,x); burn(u, u, x) + {balanceOf(u) = bu } +*/ +rule inverseMintBurn(address a, uint256 x) { + env e; + address asset; + uint256 index = POOL.getReserveNormalizedVariableDebt(e, asset); + uint256 balancebefore = balanceOf(e, a); + sinvoke mint(e, a, x, index); + sinvoke burn(e, a, x, index); + uint256 balanceAfter = balanceOf(e, a); + assert balancebefore == balanceAfter, "burn is not inverse of mint"; +} + + + diff --git a/specs/harness/LendingPoolHarness.sol b/specs/harness/LendingPoolHarness.sol new file mode 100644 index 00000000..7c099ab2 --- /dev/null +++ b/specs/harness/LendingPoolHarness.sol @@ -0,0 +1,273 @@ +pragma solidity ^0.6.8; +pragma experimental ABIEncoderV2; + +import {ReserveConfiguration} from '../../contracts/libraries/configuration/ReserveConfiguration.sol'; +import {ILendingPool} from '../../contracts/interfaces/ILendingPool.sol'; +import {LendingPool} from '../../contracts/lendingpool/LendingPool.sol'; + +/* +Certora: Harness that delegates calls to the original LendingPool. +*/ +contract LendingPoolHarness is ILendingPool { + + LendingPool private originalPool; + + function deposit( + address asset, + uint256 amount, + address onBehalfOf, + uint16 referralCode + ) external override { + originalPool.deposit(asset, amount, onBehalfOf, referralCode); + } + + function withdraw(address asset, uint256 amount) external override { + originalPool.withdraw(asset, amount); + } + + function getBorrowAllowance( + address fromUser, + address toUser, + address asset, + uint256 interestRateMode + ) external override view returns (uint256) { + return originalPool.getBorrowAllowance(fromUser, toUser, asset, interestRateMode); + } + + function delegateBorrowAllowance( + address asset, + address user, + uint256 interestRateMode, + uint256 amount + ) external override { + originalPool.delegateBorrowAllowance(asset, user, interestRateMode, amount); + } + + function borrow( + address asset, + uint256 amount, + uint256 interestRateMode, + uint16 referralCode, + address onBehalfOf + ) external override { + originalPool.borrow(asset, amount, interestRateMode, referralCode, onBehalfOf); + } + + function repay( + address asset, + uint256 amount, + uint256 rateMode, + address onBehalfOf + ) external override { + originalPool.repay(asset, amount, rateMode, onBehalfOf); + } + + function swapBorrowRateMode(address asset, uint256 rateMode) external override { + originalPool.swapBorrowRateMode(asset, rateMode); + } + + function rebalanceStableBorrowRate(address asset, address user) external override { + originalPool.rebalanceStableBorrowRate(asset, user); + } + + function setUserUseReserveAsCollateral(address asset, bool useAsCollateral) external override { + originalPool.setUserUseReserveAsCollateral(asset, useAsCollateral); + } + + function liquidationCall( + address collateral, + address asset, + address user, + uint256 purchaseAmount, + bool receiveAToken + ) external override { + originalPool.liquidationCall(collateral, asset, user, purchaseAmount, receiveAToken); + } + + function repayWithCollateral( + address collateral, + address principal, + address user, + uint256 principalAmount, + address receiver, + bytes calldata params + ) external override { + originalPool.repayWithCollateral(collateral, principal, user, principalAmount, receiver, params); + } + + function flashLoan( + address receiverAddress, + address asset, + uint256 amount, + uint256 mode, + bytes calldata params, + uint16 referralCode + ) external override { + originalPool.flashLoan(receiverAddress, asset, amount, mode, params, referralCode); + } + + function swapLiquidity( + address receiverAddress, + address fromAsset, + address toAsset, + uint256 amountToSwap, + bytes calldata params + ) external override { + originalPool.swapLiquidity(receiverAddress, fromAsset, toAsset, amountToSwap, params); + } + + function getReserveConfigurationData(address asset) + external + override + view + returns ( + uint256 decimals, + uint256 ltv, + uint256 liquidationThreshold, + uint256 liquidationBonus, + uint256 reserveFactor, + address interestRateStrategyAddress, + bool usageAsCollateralEnabled, + bool borrowingEnabled, + bool stableBorrowRateEnabled, + bool isActive, + bool isFreezed + ) + { + return originalPool.getReserveConfigurationData(asset); + } + + function getReserveTokensAddresses(address asset) + external + override + view + returns ( + address aTokenAddress, + address stableDebtTokenAddress, + address variableDebtTokenAddress + ) + { + return originalPool.getReserveTokensAddresses(asset); + } + + function getReserveData(address asset) + external + override + view + returns ( + uint256 availableLiquidity, + uint256 totalStableDebt, + uint256 totalVariableDebt, + uint256 liquidityRate, + uint256 variableBorrowRate, + uint256 stableBorrowRate, + uint256 averageStableBorrowRate, + uint256 liquidityIndex, + uint256 variableBorrowIndex, + uint40 lastUpdateTimestamp + ) + { + return originalPool.getReserveData(asset); + } + + function getUserAccountData(address user) + external + override + view + returns ( + uint256 totalCollateralETH, + uint256 totalBorrowsETH, + uint256 availableBorrowsETH, + uint256 currentLiquidationThreshold, + uint256 ltv, + uint256 healthFactor + ) + { + return originalPool.getUserAccountData(user); + } + + function getUserReserveData(address asset, address user) + external + override + view + returns ( + uint256 currentATokenBalance, + uint256 currentStableDebt, + uint256 currentVariableDebt, + uint256 principalStableDebt, + uint256 scaledVariableDebt, + uint256 stableBorrowRate, + uint256 liquidityRate, + uint40 stableRateLastUpdated, + bool usageAsCollateralEnabled + ) + { + return originalPool.getUserReserveData(asset, user); + } + + function getReserves() external override view returns (address[] memory) { + return originalPool.getReserves(); + } + + function initReserve( + address asset, + address aTokenAddress, + address stableDebtAddress, + address variableDebtAddress, + address interestRateStrategyAddress + ) external override { + originalPool.initReserve(asset, aTokenAddress, stableDebtAddress, variableDebtAddress, interestRateStrategyAddress); + } + + function setReserveInterestRateStrategyAddress(address asset, address rateStrategyAddress) + external + override + { + originalPool.setReserveInterestRateStrategyAddress(asset, rateStrategyAddress); + } + + function setConfiguration(address asset, uint256 configuration) external override { + originalPool.setConfiguration(asset, configuration); + } + + function getConfiguration(address asset) + external + override + view + returns (ReserveConfiguration.Map memory) + { + return originalPool.getConfiguration(asset); + } + + function getReserveNormalizedIncome(address asset) external override view returns (uint256) { + return originalPool.getReserveNormalizedIncome(asset); + } + + mapping(uint256 => uint256) private reserveNormalizedVariableDebt; + + function getReserveNormalizedVariableDebt(address asset) + external + override + view + returns (uint256) + { + require(reserveNormalizedVariableDebt[block.timestamp] == 1e27); + return reserveNormalizedVariableDebt[block.timestamp]; + } + + function balanceDecreaseAllowed( + address asset, + address user, + uint256 amount + ) external override view returns (bool) { + return originalPool.balanceDecreaseAllowed(asset, user, amount); + } + + function setPause(bool val) external override { + originalPool.setPause(val); + } + + function paused() external override view returns (bool) { + return originalPool.paused(); + } +} \ No newline at end of file diff --git a/specs/harness/StableDebtTokenHarness.sol b/specs/harness/StableDebtTokenHarness.sol new file mode 100644 index 00000000..be2471be --- /dev/null +++ b/specs/harness/StableDebtTokenHarness.sol @@ -0,0 +1,31 @@ +pragma solidity ^0.6.8; + +import {Context} from '@openzeppelin/contracts/GSN/Context.sol'; +import {IERC20} from '@openzeppelin/contracts/token/ERC20/IERC20.sol'; +import {SafeMath} from '@openzeppelin/contracts/math/SafeMath.sol'; +import {StableDebtToken} from '../../contracts/tokenization/StableDebtToken.sol'; +import {IncentivizedERC20} from '../../contracts/tokenization/IncentivizedERC20.sol'; + +contract StableDebtTokenHarness is StableDebtToken { + + constructor( + address pool, + address underlyingAsset, + string memory name, + string memory symbol, + address incentivesController + ) public StableDebtToken(pool, underlyingAsset, name, symbol, incentivesController) {} + + function balanceOf(address account) public override view returns (uint256) { + return IncentivizedERC20.balanceOf(account); + } + + function _calcTotalSupply(uint256 avgRate) internal override view returns (uint256) { + return IncentivizedERC20.totalSupply(); + } + + function getIncentivesController() public view returns (address) { + return address(_incentivesController); + } + +} \ No newline at end of file diff --git a/specs/harness/UserConfigurationHarness.sol b/specs/harness/UserConfigurationHarness.sol new file mode 100644 index 00000000..03574a99 --- /dev/null +++ b/specs/harness/UserConfigurationHarness.sol @@ -0,0 +1,78 @@ +pragma solidity ^0.6.8; +pragma experimental ABIEncoderV2; + +import {UserConfiguration} from 'contracts/libraries/configuration/UserConfiguration.sol'; + + +/* +A wrapper contract for calling functions from the library UserConfiguration. +*/ +contract UserConfigurationHarness { + + UserConfiguration.Map internal usersConfig; + + function setBorrowing( + address user, + uint256 reserveIndex, + bool borrowing + ) public { + UserConfiguration.setBorrowing(usersConfig, reserveIndex, borrowing); + } + + function setUsingAsCollateral( + address user, + uint256 reserveIndex, + bool _usingAsCollateral + ) public { + UserConfiguration.setUsingAsCollateral(usersConfig, reserveIndex, _usingAsCollateral); + } + + function isUsingAsCollateralOrBorrowing( + address user, + uint256 reserveIndex) + public + view + returns (bool) { + return UserConfiguration.isUsingAsCollateralOrBorrowing(usersConfig, reserveIndex); + } + + function isBorrowing( + address user, + uint256 reserveIndex) + public + view + returns (bool) { + return UserConfiguration.isBorrowing(usersConfig, reserveIndex); + } + + function isUsingAsCollateral( + address user, + uint256 reserveIndex) + public + view + returns (bool) { + return UserConfiguration.isUsingAsCollateral(usersConfig, reserveIndex); + } + + function isBorrowingAny( + address user) + public + view + returns (bool) { + return UserConfiguration.isBorrowingAny(usersConfig); + } + + function isEmpty( + address user) + public + view + returns (bool) { + return UserConfiguration.isEmpty(usersConfig); + } + + /* + Mimics the original constructor of the contract. + */ + function init_state() public { } +} + From 479aa3ef8e1172aa9c43e3d2151e1e884a8c2180 Mon Sep 17 00:00:00 2001 From: David Racero Date: Thu, 15 Oct 2020 09:38:46 +0200 Subject: [PATCH 04/35] Updated numbers --- contracts/libraries/helpers/Errors.sol | 60 +++++++++++++------------- helpers/types.ts | 46 +++++++++++++------- 2 files changed, 60 insertions(+), 46 deletions(-) diff --git a/contracts/libraries/helpers/Errors.sol b/contracts/libraries/helpers/Errors.sol index 75d23dc2..19ec4619 100644 --- a/contracts/libraries/helpers/Errors.sol +++ b/contracts/libraries/helpers/Errors.sol @@ -45,36 +45,36 @@ library Errors { 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'; + string public constant AT_CANNOT_GIVE_ALLOWANCE_TO_HIMSELF = '29'; // 'User cannot give allowance to himself' + string public constant AT_TRANSFER_AMOUNT_NOT_GT_0 = '30'; // 'Transferred amount needs to be greater than zero' + string public constant RL_RESERVE_ALREADY_INITIALIZED = '31'; // 'Reserve has already been initialized' + string public constant LPC_CALLER_NOT_AAVE_ADMIN = '32'; // 'The caller must be the aave admin' + string public constant LPC_RESERVE_LIQUIDITY_NOT_0 = '33'; // 'The liquidity of the reserve needs to be 0' + string public constant LPAPR_PROVIDER_NOT_REGISTERED = '34'; // 'Provider is not registered' + string public constant LPCM_HEALTH_FACTOR_NOT_BELOW_THRESHOLD = '35'; // 'Health factor is not below the threshold' + string public constant LPCM_COLLATERAL_CANNOT_BE_LIQUIDATED = '36'; // 'The collateral chosen cannot be liquidated' + string public constant LPCM_SPECIFIED_CURRENCY_NOT_BORROWED_BY_USER = '37'; // 'User did not borrow the specified currency' + string public constant LPCM_NOT_ENOUGH_LIQUIDITY_TO_LIQUIDATE = '38'; // "There isn't enough liquidity available to liquidate" + string public constant LPCM_NO_ERRORS = '39'; // 'No errors' + string public constant LP_INVALID_FLASHLOAN_MODE = '40'; //Invalid flashloan mode selected + string public constant MATH_MULTIPLICATION_OVERFLOW = '41'; + string public constant MATH_ADDITION_OVERFLOW = '42'; + string public constant MATH_DIVISION_BY_ZERO = '43'; + string public constant RL_LIQUIDITY_INDEX_OVERFLOW = '44'; // Liquidity index overflows uint128 + string public constant RL_VARIABLE_BORROW_INDEX_OVERFLOW = '45'; // Variable borrow index overflows uint128 + string public constant RL_LIQUIDITY_RATE_OVERFLOW = '46'; // Liquidity rate overflows uint128 + string public constant RL_VARIABLE_BORROW_RATE_OVERFLOW = '47'; // Variable borrow rate overflows uint128 + string public constant RL_STABLE_BORROW_RATE_OVERFLOW = '48'; // Stable borrow rate overflows uint128 + string public constant AT_INVALID_MINT_AMOUNT = '49'; //invalid amount to mint + string public constant LP_FAILED_REPAY_WITH_COLLATERAL = '50'; + string public constant AT_INVALID_BURN_AMOUNT = '51'; //invalid amount to burn + string public constant LP_BORROW_ALLOWANCE_ARE_NOT_ENOUGH = '52'; // User borrows on behalf, but allowance are too small + string public constant LP_FAILED_COLLATERAL_SWAP = '53'; + string public constant LP_INVALID_EQUAL_ASSETS_TO_SWAP = '54'; + string public constant LP_REENTRANCY_NOT_ALLOWED = '55'; + string public constant P_IS_PAUSED = '56'; // 'Pool is paused' + string public constant LP_NO_MORE_RESERVES_ALLOWED = '57'; + string public constant LP_INVALID_FLASH_LOAN_EXECUTOR_RETURN = '58'; enum CollateralManagerErrors { NO_ERROR, NO_COLLATERAL_AVAILABLE, diff --git a/helpers/types.ts b/helpers/types.ts index 4a271acd..4897bbb8 100644 --- a/helpers/types.ts +++ b/helpers/types.ts @@ -99,22 +99,36 @@ export enum ProtocolErrors { 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' AT_CALLER_MUST_BE_LENDING_POOL = '28', // 'The caller of this function must be a lending pool' - AT_CANNOT_GIVE_ALLOWANCE_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 = '34', // 'Reserve has already been initialized' - LPC_CALLER_NOT_AAVE_ADMIN = '35', // 'The caller must be the aave admin' - LPC_RESERVE_LIQUIDITY_NOT_0 = '36', // 'The liquidity of the reserve needs to be 0' - LPAPR_PROVIDER_NOT_REGISTERED = '37', // 'Provider is not registered' - LPCM_HEALTH_FACTOR_NOT_BELOW_THRESHOLD = '38', // 'Health factor is not below the threshold' - LPCM_COLLATERAL_CANNOT_BE_LIQUIDATED = '39', // 'The collateral chosen cannot be liquidated' - LPCM_SPECIFIED_CURRENCY_NOT_BORROWED_BY_USER = '40', // 'User did not borrow the specified currency' - LPCM_NOT_ENOUGH_LIQUIDITY_TO_LIQUIDATE = '41', // "There isn't enough liquidity available to liquidate" - LPCM_NO_ERRORS = '42', // 'No errors' - LP_INVALID_FLASHLOAN_MODE = '43', //Invalid flashloan mode - LP_INVALID_EQUAL_ASSETS_TO_SWAP = '56', // User can't use same reserve as destination of liquidity swap - P_IS_PAUSED = '58', // Pool is paused - LP_INVALID_FLASH_LOAN_EXECUTOR_RETURN = '60', // The flash loan received returned 0 (EOA) - + AT_CANNOT_GIVE_ALLOWANCE_TO_HIMSELF = '29', // 'User cannot give allowance to himself' + AT_TRANSFER_AMOUNT_NOT_GT_0 = '30', // 'Transferred amount needs to be greater than zero' + RL_RESERVE_ALREADY_INITIALIZED = '31', // 'Reserve has already been initialized' + LPC_CALLER_NOT_AAVE_ADMIN = '32', // 'The caller must be the aave admin' + LPC_RESERVE_LIQUIDITY_NOT_0 = '33', // 'The liquidity of the reserve needs to be 0' + LPAPR_PROVIDER_NOT_REGISTERED = '34', // 'Provider is not registered' + LPCM_HEALTH_FACTOR_NOT_BELOW_THRESHOLD = '35', // 'Health factor is not below the threshold' + LPCM_COLLATERAL_CANNOT_BE_LIQUIDATED = '36', // 'The collateral chosen cannot be liquidated' + LPCM_SPECIFIED_CURRENCY_NOT_BORROWED_BY_USER = '37', // 'User did not borrow the specified currency' + LPCM_NOT_ENOUGH_LIQUIDITY_TO_LIQUIDATE = '38', // "There isn't enough liquidity available to liquidate" + LPCM_NO_ERRORS = '39', // 'No errors' + LP_INVALID_FLASHLOAN_MODE = '40', //Invalid flashloan mode selected + MATH_MULTIPLICATION_OVERFLOW = '41', + MATH_ADDITION_OVERFLOW = '42', + MATH_DIVISION_BY_ZERO = '43', + RL_LIQUIDITY_INDEX_OVERFLOW = '44', // Liquidity index overflows uint128 + RL_VARIABLE_BORROW_INDEX_OVERFLOW = '45', // Variable borrow index overflows uint128 + RL_LIQUIDITY_RATE_OVERFLOW = '46', // Liquidity rate overflows uint128 + RL_VARIABLE_BORROW_RATE_OVERFLOW = '47', // Variable borrow rate overflows uint128 + RL_STABLE_BORROW_RATE_OVERFLOW = '48', // Stable borrow rate overflows uint128 + AT_INVALID_MINT_AMOUNT = '49', //invalid amount to mint + LP_FAILED_REPAY_WITH_COLLATERAL = '50', + AT_INVALID_BURN_AMOUNT = '51', //invalid amount to burn + LP_BORROW_ALLOWANCE_ARE_NOT_ENOUGH = '52', // User borrows on behalf, but allowance are too small + LP_FAILED_COLLATERAL_SWAP = '53', + LP_INVALID_EQUAL_ASSETS_TO_SWAP = '54', + LP_REENTRANCY_NOT_ALLOWED = '55', + P_IS_PAUSED = '56', // 'Pool is paused' + LP_NO_MORE_RESERVES_ALLOWED = '57', + LP_INVALID_FLASH_LOAN_EXECUTOR_RETURN = '58', // old INVALID_FROM_BALANCE_AFTER_TRANSFER = 'Invalid from balance after transfer', From a2127a5b56ebdd78e29b22b9aac96b1e9fe67c1a Mon Sep 17 00:00:00 2001 From: Shelly Grossman Date: Mon, 19 Oct 2020 14:15:33 +0300 Subject: [PATCH 05/35] runner script for stable token --- runStableTokenCLI.sh | 1 + 1 file changed, 1 insertion(+) create mode 100644 runStableTokenCLI.sh diff --git a/runStableTokenCLI.sh b/runStableTokenCLI.sh new file mode 100644 index 00000000..658c7663 --- /dev/null +++ b/runStableTokenCLI.sh @@ -0,0 +1 @@ +certoraRun specs/harness/StableDebtTokenHarness.sol:StableDebtTokenHarness --solc solc6.8 --verify StableDebtTokenHarness:specs/StableDebtToken.spec --settings -assumeUnwindCond,-useNonLinearArithmetic --cache StableDebtToken --staging master \ No newline at end of file From 3f714b9dc848d28d1753fd8a673038fda4f024ed Mon Sep 17 00:00:00 2001 From: eboado Date: Wed, 28 Oct 2020 11:48:55 +0100 Subject: [PATCH 06/35] - Fixed non-initialized availableLiquidity on validateBorrow() --- contracts/lendingpool/LendingPool.sol | 1 + contracts/libraries/logic/ValidationLogic.sol | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/contracts/lendingpool/LendingPool.sol b/contracts/lendingpool/LendingPool.sol index c63ff348..b387f59f 100644 --- a/contracts/lendingpool/LendingPool.sol +++ b/contracts/lendingpool/LendingPool.sol @@ -844,6 +844,7 @@ contract LendingPool is VersionedInitializable, ILendingPool, LendingPoolStorage ); ValidationLogic.validateBorrow( + vars.asset, reserve, vars.onBehalfOf, vars.amount, diff --git a/contracts/libraries/logic/ValidationLogic.sol b/contracts/libraries/logic/ValidationLogic.sol index 947d84ea..08f0ba35 100644 --- a/contracts/libraries/logic/ValidationLogic.sol +++ b/contracts/libraries/logic/ValidationLogic.sol @@ -99,6 +99,7 @@ library ValidationLogic { /** * @dev validates a borrow. + * @param asset the address of the asset to borrow * @param reserve the reserve state from which the user is borrowing * @param userAddress the address of the user * @param amount the amount to be borrowed @@ -112,6 +113,7 @@ library ValidationLogic { */ function validateBorrow( + address asset, ReserveLogic.ReserveData storage reserve, address userAddress, uint256 amount, @@ -198,6 +200,8 @@ library ValidationLogic { Errors.CALLATERAL_SAME_AS_BORROWING_CURRENCY ); + vars.availableLiquidity = IERC20(asset).balanceOf(reserve.aTokenAddress); + //calculate the max available loan size in stable rate mode as a percentage of the //available liquidity uint256 maxLoanSizeStable = vars.availableLiquidity.percentMul(maxStableLoanPercent); From a63e337222c6ccf17465d6240a6ed3e87e2d728e Mon Sep 17 00:00:00 2001 From: pistiner <59415933+orpistiner@users.noreply.github.com> Date: Thu, 29 Oct 2020 01:20:38 +0200 Subject: [PATCH 07/35] Updated spec harness and run.sh for VariableDebtToken contract --- runVariableTokenCLI.sh | 2 +- specs/VariableDebtToken.spec | 2 +- specs/harness/LendingPoolHarness.sol | 273 ------------------ ...LendingPoolHarnessForVariableDebtToken.sol | 193 +++++++++++++ 4 files changed, 195 insertions(+), 275 deletions(-) delete mode 100644 specs/harness/LendingPoolHarness.sol create mode 100644 specs/harness/LendingPoolHarnessForVariableDebtToken.sol diff --git a/runVariableTokenCLI.sh b/runVariableTokenCLI.sh index 2b7abdc4..483e152e 100644 --- a/runVariableTokenCLI.sh +++ b/runVariableTokenCLI.sh @@ -1 +1 @@ -certoraRun contracts/tokenization/VariableDebtToken.sol:VariableDebtToken specs/harness/LendingPoolHarness.sol --solc solc6.8 --link VariableDebtToken:POOL=LendingPoolHarness --verify VariableDebtToken:specs/VariableDebtToken.spec --settings -assumeUnwindCond,-useNonLinearArithmetic --cache VariableDebtToken --staging master \ No newline at end of file +certoraRun contracts/tokenization/VariableDebtToken.sol:VariableDebtToken specs/harness/LendingPoolHarnessForVariableDebtToken.sol --solc solc6.8 --link VariableDebtToken:POOL=LendingPoolHarnessForVariableDebtToken --verify VariableDebtToken:specs/VariableDebtToken.spec --settings -assumeUnwindCond,-useNonLinearArithmetic --cache VariableDebtToken --staging \ No newline at end of file diff --git a/specs/VariableDebtToken.spec b/specs/VariableDebtToken.spec index 854ee9d7..73e7e39c 100644 --- a/specs/VariableDebtToken.spec +++ b/specs/VariableDebtToken.spec @@ -1,4 +1,4 @@ -using LendingPoolHarness as POOL +using LendingPoolHarnessForVariableDebtToken as POOL /** TotalSupply is the sum of all users’ balances diff --git a/specs/harness/LendingPoolHarness.sol b/specs/harness/LendingPoolHarness.sol deleted file mode 100644 index 7c099ab2..00000000 --- a/specs/harness/LendingPoolHarness.sol +++ /dev/null @@ -1,273 +0,0 @@ -pragma solidity ^0.6.8; -pragma experimental ABIEncoderV2; - -import {ReserveConfiguration} from '../../contracts/libraries/configuration/ReserveConfiguration.sol'; -import {ILendingPool} from '../../contracts/interfaces/ILendingPool.sol'; -import {LendingPool} from '../../contracts/lendingpool/LendingPool.sol'; - -/* -Certora: Harness that delegates calls to the original LendingPool. -*/ -contract LendingPoolHarness is ILendingPool { - - LendingPool private originalPool; - - function deposit( - address asset, - uint256 amount, - address onBehalfOf, - uint16 referralCode - ) external override { - originalPool.deposit(asset, amount, onBehalfOf, referralCode); - } - - function withdraw(address asset, uint256 amount) external override { - originalPool.withdraw(asset, amount); - } - - function getBorrowAllowance( - address fromUser, - address toUser, - address asset, - uint256 interestRateMode - ) external override view returns (uint256) { - return originalPool.getBorrowAllowance(fromUser, toUser, asset, interestRateMode); - } - - function delegateBorrowAllowance( - address asset, - address user, - uint256 interestRateMode, - uint256 amount - ) external override { - originalPool.delegateBorrowAllowance(asset, user, interestRateMode, amount); - } - - function borrow( - address asset, - uint256 amount, - uint256 interestRateMode, - uint16 referralCode, - address onBehalfOf - ) external override { - originalPool.borrow(asset, amount, interestRateMode, referralCode, onBehalfOf); - } - - function repay( - address asset, - uint256 amount, - uint256 rateMode, - address onBehalfOf - ) external override { - originalPool.repay(asset, amount, rateMode, onBehalfOf); - } - - function swapBorrowRateMode(address asset, uint256 rateMode) external override { - originalPool.swapBorrowRateMode(asset, rateMode); - } - - function rebalanceStableBorrowRate(address asset, address user) external override { - originalPool.rebalanceStableBorrowRate(asset, user); - } - - function setUserUseReserveAsCollateral(address asset, bool useAsCollateral) external override { - originalPool.setUserUseReserveAsCollateral(asset, useAsCollateral); - } - - function liquidationCall( - address collateral, - address asset, - address user, - uint256 purchaseAmount, - bool receiveAToken - ) external override { - originalPool.liquidationCall(collateral, asset, user, purchaseAmount, receiveAToken); - } - - function repayWithCollateral( - address collateral, - address principal, - address user, - uint256 principalAmount, - address receiver, - bytes calldata params - ) external override { - originalPool.repayWithCollateral(collateral, principal, user, principalAmount, receiver, params); - } - - function flashLoan( - address receiverAddress, - address asset, - uint256 amount, - uint256 mode, - bytes calldata params, - uint16 referralCode - ) external override { - originalPool.flashLoan(receiverAddress, asset, amount, mode, params, referralCode); - } - - function swapLiquidity( - address receiverAddress, - address fromAsset, - address toAsset, - uint256 amountToSwap, - bytes calldata params - ) external override { - originalPool.swapLiquidity(receiverAddress, fromAsset, toAsset, amountToSwap, params); - } - - function getReserveConfigurationData(address asset) - external - override - view - returns ( - uint256 decimals, - uint256 ltv, - uint256 liquidationThreshold, - uint256 liquidationBonus, - uint256 reserveFactor, - address interestRateStrategyAddress, - bool usageAsCollateralEnabled, - bool borrowingEnabled, - bool stableBorrowRateEnabled, - bool isActive, - bool isFreezed - ) - { - return originalPool.getReserveConfigurationData(asset); - } - - function getReserveTokensAddresses(address asset) - external - override - view - returns ( - address aTokenAddress, - address stableDebtTokenAddress, - address variableDebtTokenAddress - ) - { - return originalPool.getReserveTokensAddresses(asset); - } - - function getReserveData(address asset) - external - override - view - returns ( - uint256 availableLiquidity, - uint256 totalStableDebt, - uint256 totalVariableDebt, - uint256 liquidityRate, - uint256 variableBorrowRate, - uint256 stableBorrowRate, - uint256 averageStableBorrowRate, - uint256 liquidityIndex, - uint256 variableBorrowIndex, - uint40 lastUpdateTimestamp - ) - { - return originalPool.getReserveData(asset); - } - - function getUserAccountData(address user) - external - override - view - returns ( - uint256 totalCollateralETH, - uint256 totalBorrowsETH, - uint256 availableBorrowsETH, - uint256 currentLiquidationThreshold, - uint256 ltv, - uint256 healthFactor - ) - { - return originalPool.getUserAccountData(user); - } - - function getUserReserveData(address asset, address user) - external - override - view - returns ( - uint256 currentATokenBalance, - uint256 currentStableDebt, - uint256 currentVariableDebt, - uint256 principalStableDebt, - uint256 scaledVariableDebt, - uint256 stableBorrowRate, - uint256 liquidityRate, - uint40 stableRateLastUpdated, - bool usageAsCollateralEnabled - ) - { - return originalPool.getUserReserveData(asset, user); - } - - function getReserves() external override view returns (address[] memory) { - return originalPool.getReserves(); - } - - function initReserve( - address asset, - address aTokenAddress, - address stableDebtAddress, - address variableDebtAddress, - address interestRateStrategyAddress - ) external override { - originalPool.initReserve(asset, aTokenAddress, stableDebtAddress, variableDebtAddress, interestRateStrategyAddress); - } - - function setReserveInterestRateStrategyAddress(address asset, address rateStrategyAddress) - external - override - { - originalPool.setReserveInterestRateStrategyAddress(asset, rateStrategyAddress); - } - - function setConfiguration(address asset, uint256 configuration) external override { - originalPool.setConfiguration(asset, configuration); - } - - function getConfiguration(address asset) - external - override - view - returns (ReserveConfiguration.Map memory) - { - return originalPool.getConfiguration(asset); - } - - function getReserveNormalizedIncome(address asset) external override view returns (uint256) { - return originalPool.getReserveNormalizedIncome(asset); - } - - mapping(uint256 => uint256) private reserveNormalizedVariableDebt; - - function getReserveNormalizedVariableDebt(address asset) - external - override - view - returns (uint256) - { - require(reserveNormalizedVariableDebt[block.timestamp] == 1e27); - return reserveNormalizedVariableDebt[block.timestamp]; - } - - function balanceDecreaseAllowed( - address asset, - address user, - uint256 amount - ) external override view returns (bool) { - return originalPool.balanceDecreaseAllowed(asset, user, amount); - } - - function setPause(bool val) external override { - originalPool.setPause(val); - } - - function paused() external override view returns (bool) { - return originalPool.paused(); - } -} \ No newline at end of file diff --git a/specs/harness/LendingPoolHarnessForVariableDebtToken.sol b/specs/harness/LendingPoolHarnessForVariableDebtToken.sol new file mode 100644 index 00000000..6cd8ec38 --- /dev/null +++ b/specs/harness/LendingPoolHarnessForVariableDebtToken.sol @@ -0,0 +1,193 @@ +pragma solidity ^0.6.8; +pragma experimental ABIEncoderV2; + +import {ReserveConfiguration} from '../../contracts/libraries/configuration/ReserveConfiguration.sol'; +import {UserConfiguration} from '../../contracts/libraries/configuration/UserConfiguration.sol'; +import {ReserveLogic} from '../../contracts/libraries/logic/ReserveLogic.sol'; +import {ILendingPool} from '../../contracts/interfaces/ILendingPool.sol'; +import {LendingPool} from '../../contracts/lendingpool/LendingPool.sol'; + +/* +Certora: Harness that delegates calls to the original LendingPool. +Used for the verification of the VariableDebtToken contract. +*/ +contract LendingPoolHarnessForVariableDebtToken is ILendingPool { + + LendingPool private originalPool; + + function deposit( + address asset, + uint256 amount, + address onBehalfOf, + uint16 referralCode + ) external override { + originalPool.deposit(asset, amount, onBehalfOf, referralCode); + } + + function withdraw(address asset, uint256 amount) external override { + originalPool.withdraw(asset, amount); + } + + function getBorrowAllowance( + address fromUser, + address toUser, + address asset, + uint256 interestRateMode + ) external override view returns (uint256) { + return originalPool.getBorrowAllowance(fromUser, toUser, asset, interestRateMode); + } + + function delegateBorrowAllowance( + address asset, + address user, + uint256 interestRateMode, + uint256 amount + ) external override { + originalPool.delegateBorrowAllowance(asset, user, interestRateMode, amount); + } + + function borrow( + address asset, + uint256 amount, + uint256 interestRateMode, + uint16 referralCode, + address onBehalfOf + ) external override { + originalPool.borrow(asset, amount, interestRateMode, referralCode, onBehalfOf); + } + + function repay( + address asset, + uint256 amount, + uint256 rateMode, + address onBehalfOf + ) external override { + originalPool.repay(asset, amount, rateMode, onBehalfOf); + } + + function swapBorrowRateMode(address asset, uint256 rateMode) external override { + originalPool.swapBorrowRateMode(asset, rateMode); + } + + function rebalanceStableBorrowRate(address asset, address user) external override { + originalPool.rebalanceStableBorrowRate(asset, user); + } + + function setUserUseReserveAsCollateral(address asset, bool useAsCollateral) external override { + originalPool.setUserUseReserveAsCollateral(asset, useAsCollateral); + } + + function liquidationCall( + address collateral, + address asset, + address user, + uint256 purchaseAmount, + bool receiveAToken + ) external override { + originalPool.liquidationCall(collateral, asset, user, purchaseAmount, receiveAToken); + } + + function flashLoan( + address receiver, + address[] calldata assets, + uint256[] calldata amounts, + uint256 mode, + bytes calldata params, + uint16 referralCode + ) external override { + originalPool.flashLoan(receiver, assets, amounts, mode, params, referralCode); + } + + function getReservesList() external override view returns (address[] memory) { + return originalPool.getReservesList(); + } + + function getReserveData(address asset) external override view returns (ReserveLogic.ReserveData memory) { + return originalPool.getReserveData(asset); + } + + function getUserConfiguration(address user) external override view returns (UserConfiguration.Map memory) { + return originalPool.getUserConfiguration(user); + } + + function getUserAccountData(address user) + external + override + view + returns ( + uint256 totalCollateralETH, + uint256 totalBorrowsETH, + uint256 availableBorrowsETH, + uint256 currentLiquidationThreshold, + uint256 ltv, + uint256 healthFactor + ) + { + return originalPool.getUserAccountData(user); + } + + function initReserve( + address asset, + address aTokenAddress, + address stableDebtAddress, + address variableDebtAddress, + address interestRateStrategyAddress + ) external override { + originalPool.initReserve(asset, aTokenAddress, stableDebtAddress, variableDebtAddress, interestRateStrategyAddress); + } + + function setReserveInterestRateStrategyAddress(address asset, address rateStrategyAddress) + external + override + { + originalPool.setReserveInterestRateStrategyAddress(asset, rateStrategyAddress); + } + + function setConfiguration(address asset, uint256 configuration) external override { + originalPool.setConfiguration(asset, configuration); + } + + function getConfiguration(address asset) + external + override + view + returns (ReserveConfiguration.Map memory) + { + return originalPool.getConfiguration(asset); + } + + mapping(uint256 => uint256) private reserveNormalizedIncome; + + function getReserveNormalizedIncome(address asset) external override view returns (uint256) { + require(reserveNormalizedIncome[block.timestamp] == 1e27); + return reserveNormalizedIncome[block.timestamp]; + } + + mapping(uint256 => uint256) private reserveNormalizedVariableDebt; + + function getReserveNormalizedVariableDebt(address asset) + external + override + view + returns (uint256) + { + require(reserveNormalizedVariableDebt[block.timestamp] == 1e27); + return reserveNormalizedVariableDebt[block.timestamp]; + } + + function balanceDecreaseAllowed( + address asset, + address user, + uint256 amount + ) external override view returns (bool) { + return originalPool.balanceDecreaseAllowed(asset, user, amount); + } + + function setPause(bool val) external override { + originalPool.setPause(val); + } + + function paused() external override view returns (bool) { + return originalPool.paused(); + } +} From 4030d487877f29d5e669b5f4efbfaeaa9db1d96e Mon Sep 17 00:00:00 2001 From: pistiner <59415933+orpistiner@users.noreply.github.com> Date: Thu, 29 Oct 2020 01:57:15 +0200 Subject: [PATCH 08/35] Fixes to run on StableDebtToken contract --- contracts/tokenization/StableDebtToken.sol | 2 +- specs/StableDebtToken.spec | 16 ---------------- specs/harness/StableDebtTokenHarness.sol | 3 --- 3 files changed, 1 insertion(+), 20 deletions(-) diff --git a/contracts/tokenization/StableDebtToken.sol b/contracts/tokenization/StableDebtToken.sol index 346d9719..a026cfc9 100644 --- a/contracts/tokenization/StableDebtToken.sol +++ b/contracts/tokenization/StableDebtToken.sol @@ -286,7 +286,7 @@ contract StableDebtToken is IStableDebtToken, DebtTokenBase { * @param avgRate the average rate at which calculate the total supply * @return The debt balance of the user since the last burn/mint action **/ - function _calcTotalSupply(uint256 avgRate) internal view returns (uint256) { + function _calcTotalSupply(uint256 avgRate) internal virtual view returns (uint256) { uint256 principalSupply = super.totalSupply(); if (principalSupply == 0) { diff --git a/specs/StableDebtToken.spec b/specs/StableDebtToken.spec index fba0f8ba..718dcb60 100644 --- a/specs/StableDebtToken.spec +++ b/specs/StableDebtToken.spec @@ -2,13 +2,6 @@ methods { getUserLastUpdated(address) returns uint40 envfree } -ghost ghostSupply() returns uint256; - -hook Sstore (slot 0)[address a] uint256 balance (uint256 old_balance) STORAGE { - require old_balance <= ghostSupply(); - havoc ghostSupply assuming ghostSupply@new() == ghostSupply@old() + (balance - old_balance); -} - rule integrityTimeStamp(address user, method f) { env e; require sinvoke getIncentivesController(e) == 0; @@ -18,15 +11,6 @@ rule integrityTimeStamp(address user, method f) { assert getUserLastUpdated(user) <= e.block.timestamp; } -rule totalSupplyInvariant(method f) { - env e; - require sinvoke getIncentivesController(e) == 0; - require totalSupply(e) == ghostSupply(); - calldataarg arg; - sinvoke f(e, arg); - assert totalSupply(e) == ghostSupply(); -} - /** TotalSupply is the sum of all users’ balances diff --git a/specs/harness/StableDebtTokenHarness.sol b/specs/harness/StableDebtTokenHarness.sol index be2471be..d314f8f0 100644 --- a/specs/harness/StableDebtTokenHarness.sol +++ b/specs/harness/StableDebtTokenHarness.sol @@ -1,8 +1,5 @@ pragma solidity ^0.6.8; -import {Context} from '@openzeppelin/contracts/GSN/Context.sol'; -import {IERC20} from '@openzeppelin/contracts/token/ERC20/IERC20.sol'; -import {SafeMath} from '@openzeppelin/contracts/math/SafeMath.sol'; import {StableDebtToken} from '../../contracts/tokenization/StableDebtToken.sol'; import {IncentivizedERC20} from '../../contracts/tokenization/IncentivizedERC20.sol'; From d4f0e05f06dd96fa877946c8dcee9264a8d4cbed Mon Sep 17 00:00:00 2001 From: pistiner <59415933+orpistiner@users.noreply.github.com> Date: Thu, 29 Oct 2020 01:58:20 +0200 Subject: [PATCH 09/35] Fixes to run on UserConfiguration library --- specs/harness/UserConfigurationHarness.sol | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/specs/harness/UserConfigurationHarness.sol b/specs/harness/UserConfigurationHarness.sol index 03574a99..81b2444e 100644 --- a/specs/harness/UserConfigurationHarness.sol +++ b/specs/harness/UserConfigurationHarness.sol @@ -1,8 +1,7 @@ pragma solidity ^0.6.8; pragma experimental ABIEncoderV2; -import {UserConfiguration} from 'contracts/libraries/configuration/UserConfiguration.sol'; - +import {UserConfiguration} from '../../contracts/libraries/configuration/UserConfiguration.sol'; /* A wrapper contract for calling functions from the library UserConfiguration. From edfe17bd971301fbb070a9514c76d04c8d53d0cf Mon Sep 17 00:00:00 2001 From: eboado Date: Thu, 29 Oct 2020 14:36:01 +0100 Subject: [PATCH 10/35] - Added batch to credit delegation --- contracts/interfaces/ILendingPool.sol | 20 ++++++++--------- contracts/lendingpool/LendingPool.sol | 30 ++++++++++++++++---------- contracts/libraries/helpers/Errors.sol | 3 +++ test/helpers/actions.ts | 25 +++++++++++++-------- test/helpers/scenario-engine.ts | 6 +++--- test/pausable-functions.spec.ts | 2 +- 6 files changed, 52 insertions(+), 34 deletions(-) diff --git a/contracts/interfaces/ILendingPool.sol b/contracts/interfaces/ILendingPool.sol index f44a458a..49869817 100644 --- a/contracts/interfaces/ILendingPool.sol +++ b/contracts/interfaces/ILendingPool.sol @@ -32,11 +32,11 @@ interface ILendingPool { event Withdraw(address indexed reserve, address indexed user, uint256 amount); event BorrowAllowanceDelegated( - address indexed asset, address indexed fromUser, address indexed toUser, - uint256 interestRateMode, - uint256 amount + address[] assets, + uint256[] interestRateModes, + uint256[] amounts ); /** * @dev emitted on borrow @@ -189,17 +189,17 @@ interface ILendingPool { function withdraw(address reserve, uint256 amount) external; /** - * @dev Sets allowance to borrow on a certain type of debt asset for a certain user address - * @param asset The underlying asset of the debt token + * @dev Sets allowance to borrow on a certain type of debt assets for a certain user address + * @param assets The underlying asset of each debt token * @param user The user to give allowance to - * @param interestRateMode Type of debt: 1 for stable, 2 for variable - * @param amount Allowance amount to borrow + * @param interestRateModes Types of debt: 1 for stable, 2 for variable + * @param amounts Allowance amounts to borrow **/ function delegateBorrowAllowance( - address asset, + address[] calldata assets, address user, - uint256 interestRateMode, - uint256 amount + uint256[] calldata interestRateModes, + uint256[] calldata amounts ) external; function getBorrowAllowance( diff --git a/contracts/lendingpool/LendingPool.sol b/contracts/lendingpool/LendingPool.sol index 3f490365..f77aac9d 100644 --- a/contracts/lendingpool/LendingPool.sol +++ b/contracts/lendingpool/LendingPool.sol @@ -179,23 +179,32 @@ contract LendingPool is VersionedInitializable, ILendingPool, LendingPoolStorage } /** - * @dev Sets allowance to borrow on a certain type of debt asset for a certain user address - * @param asset The underlying asset of the debt token + * @dev Sets allowance to borrow on a certain type of debt assets for a certain user address + * @param assets The underlying asset of each debt token * @param user The user to give allowance to - * @param interestRateMode Type of debt: 1 for stable, 2 for variable - * @param amount Allowance amount to borrow + * @param interestRateModes Types of debt: 1 for stable, 2 for variable + * @param amounts Allowance amounts to borrow **/ function delegateBorrowAllowance( - address asset, + address[] calldata assets, address user, - uint256 interestRateMode, - uint256 amount + uint256[] calldata interestRateModes, + uint256[] calldata amounts ) external override { _whenNotPaused(); - address debtToken = _reserves[asset].getDebtTokenAddress(interestRateMode); - _borrowAllowance[debtToken][msg.sender][user] = amount; - emit BorrowAllowanceDelegated(asset, msg.sender, user, interestRateMode, amount); + uint256 countAssets = assets.length; + require( + countAssets == interestRateModes.length && countAssets == amounts.length, + Errors.INCONSISTENT_PARAMS_LENGTH + ); + + for (uint256 i = 0; i < countAssets; i++) { + address debtToken = _reserves[assets[i]].getDebtTokenAddress(interestRateModes[i]); + _borrowAllowance[debtToken][msg.sender][user] = amounts[i]; + } + + emit BorrowAllowanceDelegated(msg.sender, user, assets, interestRateModes, amounts); } /** @@ -913,7 +922,6 @@ contract LendingPool is VersionedInitializable, ILendingPool, LendingPoolStorage * @dev adds a reserve to the array of the _reserves address **/ function _addReserveToList(address asset) internal { - uint256 reservesCount = _reservesCount; require(reservesCount < MAX_NUMBER_RESERVES, Errors.NO_MORE_RESERVES_ALLOWED); diff --git a/contracts/libraries/helpers/Errors.sol b/contracts/libraries/helpers/Errors.sol index 9ed7b07e..2bd24743 100644 --- a/contracts/libraries/helpers/Errors.sol +++ b/contracts/libraries/helpers/Errors.sol @@ -97,6 +97,9 @@ library Errors { string public constant INVALID_DECIMALS = '73'; string public constant INVALID_RESERVE_FACTOR = '74'; + // Credit delegation + string public constant INCONSISTENT_PARAMS_LENGTH = '75'; + enum CollateralManagerErrors { NO_ERROR, diff --git a/test/helpers/actions.ts b/test/helpers/actions.ts index 85d3eb00..60feac6a 100644 --- a/test/helpers/actions.ts +++ b/test/helpers/actions.ts @@ -279,9 +279,9 @@ export const withdraw = async ( }; export const delegateBorrowAllowance = async ( - reserveSymbol: string, - amount: string, - interestRateMode: string, + reserveSymbols: string[], + amounts: string[], + interestRateModes: string[], user: SignerWithAddress, receiver: tEthereumAddress, expectedResult: string, @@ -290,20 +290,27 @@ export const delegateBorrowAllowance = async ( ) => { const {pool} = testEnv; - const reserve = await getReserveAddressFromSymbol(reserveSymbol); - const amountToDelegate = await convertToCurrencyDecimals(reserve, amount); + const reserves : tEthereumAddress[] = [] + const amountsToDelegate: tEthereumAddress[] = [] + for (const reserveSymbol of reserveSymbols) { + const newLength = reserves.push(await getReserveAddressFromSymbol(reserveSymbol)) + amountsToDelegate.push(await (await convertToCurrencyDecimals(reserves[newLength-1], amounts[newLength-1])).toString()) + } const delegateAllowancePromise = pool .connect(user.signer) - .delegateBorrowAllowance(reserve, receiver, interestRateMode, amountToDelegate.toString()); + .delegateBorrowAllowance(reserves, receiver, interestRateModes, amountsToDelegate); if (expectedResult === 'revert') { await expect(delegateAllowancePromise, revertMessage).to.be.reverted; return; } else { await delegateAllowancePromise; - expect( - (await pool.getBorrowAllowance(user.address, receiver, reserve, interestRateMode)).toString() - ).to.be.equal(amountToDelegate.toString(), 'borrowAllowance are set incorrectly'); + for (const [i, reserve] of reserves.entries()) { + expect( + (await pool.getBorrowAllowance(user.address, receiver, reserve, interestRateModes[i])).toString() + ).to.be.equal(amountsToDelegate[i], 'borrowAllowance are set incorrectly'); + } + } }; diff --git a/test/helpers/scenario-engine.ts b/test/helpers/scenario-engine.ts index bb4f82f8..fe2e302a 100644 --- a/test/helpers/scenario-engine.ts +++ b/test/helpers/scenario-engine.ts @@ -121,9 +121,9 @@ const executeAction = async (action: Action, users: SignerWithAddress[], testEnv } await delegateBorrowAllowance( - reserve, - amount, - rateMode, + [reserve], + [amount], + [rateMode], user, toUser, expected, diff --git a/test/pausable-functions.spec.ts b/test/pausable-functions.spec.ts index 48c50ee2..a15ceb61 100644 --- a/test/pausable-functions.spec.ts +++ b/test/pausable-functions.spec.ts @@ -132,7 +132,7 @@ makeSuite('Pausable Pool', (testEnv: TestEnv) => { // Try to execute liquidation await expect( - pool.connect(user.signer).delegateBorrowAllowance(dai.address, toUser.address, '1', '1') + pool.connect(user.signer).delegateBorrowAllowance([dai.address], toUser.address, ['1'], ['1']) ).revertedWith(IS_PAUSED); // Unpause the pool From 38bb760112fe23f09eb5efb88e1ee24900c59fa7 Mon Sep 17 00:00:00 2001 From: eboado Date: Thu, 29 Oct 2020 14:55:11 +0100 Subject: [PATCH 11/35] - Added return of is first borrowing on debt tokens mint() --- contracts/lendingpool/LendingPool.sol | 17 +++++++++-------- contracts/tokenization/StableDebtToken.sol | 4 +++- .../interfaces/IStableDebtToken.sol | 2 +- 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/contracts/lendingpool/LendingPool.sol b/contracts/lendingpool/LendingPool.sol index 3f490365..1a589091 100644 --- a/contracts/lendingpool/LendingPool.sol +++ b/contracts/lendingpool/LendingPool.sol @@ -857,34 +857,35 @@ contract LendingPool is VersionedInitializable, ILendingPool, LendingPoolStorage oracle ); - uint256 reserveId = reserve.id; - if (!userConfig.isBorrowing(reserveId)) { - userConfig.setBorrowing(reserveId, true); - } - reserve.updateState(); //caching the current stable borrow rate uint256 currentStableRate = 0; - + + bool isFirstBorrowing = false; if ( ReserveLogic.InterestRateMode(vars.interestRateMode) == ReserveLogic.InterestRateMode.STABLE ) { currentStableRate = reserve.currentStableBorrowRate; - IStableDebtToken(reserve.stableDebtTokenAddress).mint( + isFirstBorrowing = IStableDebtToken(reserve.stableDebtTokenAddress).mint( vars.onBehalfOf, vars.amount, currentStableRate ); } else { - IVariableDebtToken(reserve.variableDebtTokenAddress).mint( + isFirstBorrowing = IVariableDebtToken(reserve.variableDebtTokenAddress).mint( vars.onBehalfOf, vars.amount, reserve.variableBorrowIndex ); } + uint256 reserveId = reserve.id; + if (isFirstBorrowing) { + userConfig.setBorrowing(reserveId, true); + } + reserve.updateInterestRates( vars.asset, vars.aTokenAddress, diff --git a/contracts/tokenization/StableDebtToken.sol b/contracts/tokenization/StableDebtToken.sol index 346d9719..29781919 100644 --- a/contracts/tokenization/StableDebtToken.sol +++ b/contracts/tokenization/StableDebtToken.sol @@ -97,7 +97,7 @@ contract StableDebtToken is IStableDebtToken, DebtTokenBase { address user, uint256 amount, uint256 rate - ) external override onlyLendingPool { + ) external override onlyLendingPool returns(bool) { MintLocalVars memory vars; //cumulates the user debt @@ -148,6 +148,8 @@ contract StableDebtToken is IStableDebtToken, DebtTokenBase { vars.newStableRate, vars.currentAvgStableRate ); + + return currentBalance == 0; } /** diff --git a/contracts/tokenization/interfaces/IStableDebtToken.sol b/contracts/tokenization/interfaces/IStableDebtToken.sol index 4c0d5940..4e04f704 100644 --- a/contracts/tokenization/interfaces/IStableDebtToken.sol +++ b/contracts/tokenization/interfaces/IStableDebtToken.sol @@ -62,7 +62,7 @@ interface IStableDebtToken { address user, uint256 amount, uint256 rate - ) external; + ) external returns(bool); /** * @dev burns debt of the target user. From 913a6a923756297b45d0ce6bd40d03414fd8df9a Mon Sep 17 00:00:00 2001 From: eboado Date: Thu, 29 Oct 2020 15:14:28 +0100 Subject: [PATCH 12/35] - Added batch of modes to flashLoan() --- contracts/interfaces/ILendingPool.sol | 6 ++--- contracts/lendingpool/LendingPool.sol | 13 +++++----- contracts/libraries/logic/ValidationLogic.sol | 17 +++++++++--- test/flashloan.spec.ts | 26 +++++++++---------- test/pausable-functions.spec.ts | 2 +- 5 files changed, 36 insertions(+), 28 deletions(-) diff --git a/contracts/interfaces/ILendingPool.sol b/contracts/interfaces/ILendingPool.sol index f44a458a..4d12b60f 100644 --- a/contracts/interfaces/ILendingPool.sol +++ b/contracts/interfaces/ILendingPool.sol @@ -106,7 +106,7 @@ interface ILendingPool { **/ event FlashLoan( address indexed target, - uint256 mode, + uint256[] modes, address[] assets, uint256[] amounts, uint256[] premiums, @@ -286,7 +286,7 @@ interface ILendingPool { * @param receiver The address of the contract receiving the funds. The receiver should implement the IFlashLoanReceiver interface. * @param assets the address of the principal reserve * @param amounts the amount requested for this flashloan - * @param mode the flashloan mode + * @param modes the flashloan mode * @param params a bytes array to be sent to the flashloan executor * @param referralCode the referral code of the caller **/ @@ -294,7 +294,7 @@ interface ILendingPool { address receiver, address[] calldata assets, uint256[] calldata amounts, - uint256 mode, + uint256[] calldata modes, bytes calldata params, uint16 referralCode ) external; diff --git a/contracts/lendingpool/LendingPool.sol b/contracts/lendingpool/LendingPool.sol index b0f960b3..618bd508 100644 --- a/contracts/lendingpool/LendingPool.sol +++ b/contracts/lendingpool/LendingPool.sol @@ -502,7 +502,7 @@ contract LendingPool is VersionedInitializable, ILendingPool, LendingPoolStorage * @param receiverAddress The address of the contract receiving the funds. The receiver should implement the IFlashLoanReceiver interface. * @param assets The addresss of the assets being flashborrowed * @param amounts The amounts requested for this flashloan for each asset - * @param mode Type of the debt to open if the flash loan is not returned. 0 -> Don't open any debt, just revert, 1 -> stable, 2 -> variable + * @param modes Types of the debt to open if the flash loan is not returned. 0 -> Don't open any debt, just revert, 1 -> stable, 2 -> variable * @param params Variadic packed params to pass to the receiver as extra information * @param referralCode Referral code of the flash loan **/ @@ -510,7 +510,7 @@ contract LendingPool is VersionedInitializable, ILendingPool, LendingPoolStorage address receiverAddress, address[] calldata assets, uint256[] calldata amounts, - uint256 mode, + uint256[] calldata modes, bytes calldata params, uint16 referralCode ) external override { @@ -518,13 +518,12 @@ contract LendingPool is VersionedInitializable, ILendingPool, LendingPoolStorage FlashLoanLocalVars memory vars; - ValidationLogic.validateFlashloan(assets, amounts, mode); + ValidationLogic.validateFlashloan(assets, amounts, modes); address[] memory aTokenAddresses = new address[](assets.length); uint256[] memory premiums = new uint256[](assets.length); vars.receiver = IFlashLoanReceiver(receiverAddress); - vars.debtMode = ReserveLogic.InterestRateMode(mode); for (vars.i = 0; vars.i < assets.length; vars.i++) { aTokenAddresses[vars.i] = _reserves[assets[vars.i]].aTokenAddress; @@ -546,7 +545,7 @@ contract LendingPool is VersionedInitializable, ILendingPool, LendingPoolStorage vars.currentAmount = amounts[vars.i]; vars.currentPremium = premiums[vars.i]; vars.currentATokenAddress = aTokenAddresses[vars.i]; - + vars.debtMode = ReserveLogic.InterestRateMode(modes[vars.i]); vars.currentAmountPlusPremium = vars.currentAmount.add(vars.currentPremium); if (vars.debtMode == ReserveLogic.InterestRateMode.NONE) { @@ -576,14 +575,14 @@ contract LendingPool is VersionedInitializable, ILendingPool, LendingPoolStorage msg.sender, msg.sender, vars.currentAmount, - mode, + modes[vars.i], vars.currentATokenAddress, referralCode, false ) ); } - emit FlashLoan(receiverAddress, mode, assets, amounts, premiums, referralCode); + emit FlashLoan(receiverAddress, modes, assets, amounts, premiums, referralCode); } } diff --git a/contracts/libraries/logic/ValidationLogic.sol b/contracts/libraries/logic/ValidationLogic.sol index 947d84ea..c2019fd6 100644 --- a/contracts/libraries/logic/ValidationLogic.sol +++ b/contracts/libraries/logic/ValidationLogic.sol @@ -326,17 +326,26 @@ library ValidationLogic { /** * @dev validates a flashloan action - * @param mode the flashloan mode (0 = classic flashloan, 1 = open a stable rate loan, 2 = open a variable rate loan) + * @param modes the flashloan modes (0 = classic flashloan, 1 = open a stable rate loan, 2 = open a variable rate loan) * @param assets the assets being flashborrowed * @param amounts the amounts for each asset being borrowed **/ function validateFlashloan( address[] memory assets, uint256[] memory amounts, - uint256 mode + uint256[] memory modes ) internal pure { - require(mode <= uint256(ReserveLogic.InterestRateMode.VARIABLE), Errors.INVALID_FLASHLOAN_MODE); - require(assets.length == amounts.length, Errors.INCONSISTENT_FLASHLOAN_PARAMS); + require( + assets.length == amounts.length && assets.length == modes.length, + Errors.INCONSISTENT_FLASHLOAN_PARAMS + ); + + for (uint256 i = 0; i < modes.length; i++) { + require( + modes[i] <= uint256(ReserveLogic.InterestRateMode.VARIABLE), + Errors.INVALID_FLASHLOAN_MODE + ); + } } /** diff --git a/test/flashloan.spec.ts b/test/flashloan.spec.ts index 305d674f..6df207c8 100644 --- a/test/flashloan.spec.ts +++ b/test/flashloan.spec.ts @@ -47,7 +47,7 @@ makeSuite('LendingPool FlashLoan function', (testEnv: TestEnv) => { _mockFlashLoanReceiver.address, [weth.address], [ethers.utils.parseEther('0.8')], - 0, + [0], '0x10', '0' ); @@ -76,7 +76,7 @@ makeSuite('LendingPool FlashLoan function', (testEnv: TestEnv) => { _mockFlashLoanReceiver.address, [weth.address], ['1000720000000000000'], - 0, + [0], '0x10', '0' ); @@ -107,7 +107,7 @@ makeSuite('LendingPool FlashLoan function', (testEnv: TestEnv) => { _mockFlashLoanReceiver.address, [weth.address], [ethers.utils.parseEther('0.8')], - 0, + [0], '0x10', '0' ) @@ -127,7 +127,7 @@ makeSuite('LendingPool FlashLoan function', (testEnv: TestEnv) => { _mockFlashLoanReceiver.address, [weth.address], [ethers.utils.parseEther('0.8')], - 0, + [0], '0x10', '0' ) @@ -147,7 +147,7 @@ makeSuite('LendingPool FlashLoan function', (testEnv: TestEnv) => { _mockFlashLoanReceiver.address, [weth.address], [ethers.utils.parseEther('0.8')], - 4, + [4], '0x10', '0' ) @@ -175,7 +175,7 @@ makeSuite('LendingPool FlashLoan function', (testEnv: TestEnv) => { _mockFlashLoanReceiver.address, [weth.address], [ethers.utils.parseEther('0.8')], - 2, + [2], '0x10', '0' ); @@ -201,7 +201,7 @@ makeSuite('LendingPool FlashLoan function', (testEnv: TestEnv) => { _mockFlashLoanReceiver.address, [weth.address], ['1004415000000000000'], //slightly higher than the available liquidity - 2, + [2], '0x10', '0' ), @@ -213,7 +213,7 @@ makeSuite('LendingPool FlashLoan function', (testEnv: TestEnv) => { const {pool, deployer, weth} = testEnv; await expect( - pool.flashLoan(deployer.address, [weth.address], ['1000000000000000000'], 2, '0x10', '0') + pool.flashLoan(deployer.address, [weth.address], ['1000000000000000000'], [2], '0x10', '0') ).to.be.reverted; }); @@ -241,7 +241,7 @@ makeSuite('LendingPool FlashLoan function', (testEnv: TestEnv) => { _mockFlashLoanReceiver.address, [usdc.address], [flashloanAmount], - 0, + [0], '0x10', '0' ); @@ -283,7 +283,7 @@ makeSuite('LendingPool FlashLoan function', (testEnv: TestEnv) => { _mockFlashLoanReceiver.address, [usdc.address], [flashloanAmount], - 2, + [2], '0x10', '0' ) @@ -309,7 +309,7 @@ makeSuite('LendingPool FlashLoan function', (testEnv: TestEnv) => { await pool .connect(caller.signer) - .flashLoan(_mockFlashLoanReceiver.address, [usdc.address], [flashloanAmount], 2, '0x10', '0'); + .flashLoan(_mockFlashLoanReceiver.address, [usdc.address], [flashloanAmount], [2], '0x10', '0'); const {variableDebtTokenAddress} = await helpersContract.getReserveTokensAddresses( usdc.address ); @@ -344,7 +344,7 @@ makeSuite('LendingPool FlashLoan function', (testEnv: TestEnv) => { await expect( pool .connect(caller.signer) - .flashLoan(_mockFlashLoanReceiver.address, [weth.address], [flashAmount], 0, '0x10', '0') + .flashLoan(_mockFlashLoanReceiver.address, [weth.address], [flashAmount], [0], '0x10', '0') ).to.be.revertedWith(SAFEERC20_LOWLEVEL_CALL); }); @@ -359,7 +359,7 @@ makeSuite('LendingPool FlashLoan function', (testEnv: TestEnv) => { await pool .connect(caller.signer) - .flashLoan(_mockFlashLoanReceiver.address, [weth.address], [flashAmount], 1, '0x10', '0'); + .flashLoan(_mockFlashLoanReceiver.address, [weth.address], [flashAmount], [1], '0x10', '0'); const {stableDebtTokenAddress} = await helpersContract.getReserveTokensAddresses(weth.address); diff --git a/test/pausable-functions.spec.ts b/test/pausable-functions.spec.ts index 2bf8be21..ae7e3874 100644 --- a/test/pausable-functions.spec.ts +++ b/test/pausable-functions.spec.ts @@ -187,7 +187,7 @@ makeSuite('Pausable Pool', (testEnv: TestEnv) => { await expect( pool .connect(caller.signer) - .flashLoan(_mockFlashLoanReceiver.address, [weth.address], [flashAmount], 1, '0x10', '0') + .flashLoan(_mockFlashLoanReceiver.address, [weth.address], [flashAmount], [1], '0x10', '0') ).revertedWith(IS_PAUSED); // Unpause pool From e4dc22e50ed2864787f06fd8154b1bc46483f571 Mon Sep 17 00:00:00 2001 From: emilio Date: Thu, 29 Oct 2020 18:03:19 +0100 Subject: [PATCH 13/35] Fixed events, removed unused constants in addressesProvider --- .../LendingPoolAddressesProvider.sol | 5 ----- contracts/interfaces/ILendingPool.sol | 2 +- contracts/lendingpool/LendingPool.sol | 2 +- .../lendingpool/LendingPoolConfigurator.sol | 20 +++++++++---------- deployed-contracts.json | 9 +++++---- 5 files changed, 17 insertions(+), 21 deletions(-) diff --git a/contracts/configuration/LendingPoolAddressesProvider.sol b/contracts/configuration/LendingPoolAddressesProvider.sol index 15b37635..38aa1280 100644 --- a/contracts/configuration/LendingPoolAddressesProvider.sol +++ b/contracts/configuration/LendingPoolAddressesProvider.sol @@ -19,16 +19,11 @@ contract LendingPoolAddressesProvider is Ownable, ILendingPoolAddressesProvider mapping(bytes32 => address) private _addresses; bytes32 private constant LENDING_POOL = 'LENDING_POOL'; - bytes32 private constant LENDING_POOL_CORE = 'LENDING_POOL_CORE'; bytes32 private constant LENDING_POOL_CONFIGURATOR = 'LENDING_POOL_CONFIGURATOR'; bytes32 private constant AAVE_ADMIN = 'AAVE_ADMIN'; bytes32 private constant LENDING_POOL_COLLATERAL_MANAGER = 'COLLATERAL_MANAGER'; - bytes32 private constant LENDING_POOL_FLASHLOAN_PROVIDER = 'FLASHLOAN_PROVIDER'; - bytes32 private constant DATA_PROVIDER = 'DATA_PROVIDER'; - bytes32 private constant ETHEREUM_ADDRESS = 'ETHEREUM_ADDRESS'; bytes32 private constant PRICE_ORACLE = 'PRICE_ORACLE'; bytes32 private constant LENDING_RATE_ORACLE = 'LENDING_RATE_ORACLE'; - bytes32 private constant WALLET_BALANCE_PROVIDER = 'WALLET_BALANCE_PROVIDER'; /** * @dev Sets an address for an id, allowing to cover it or not with a proxy diff --git a/contracts/interfaces/ILendingPool.sol b/contracts/interfaces/ILendingPool.sol index 450def2d..2e4e2d94 100644 --- a/contracts/interfaces/ILendingPool.sol +++ b/contracts/interfaces/ILendingPool.sol @@ -74,7 +74,7 @@ interface ILendingPool { * @param reserve the address of the reserve * @param user the address of the user executing the swap **/ - event Swap(address indexed reserve, address indexed user); + event Swap(address indexed reserve, address indexed user, uint256 rateMode); /** * @dev emitted when a user enables a reserve as collateral diff --git a/contracts/lendingpool/LendingPool.sol b/contracts/lendingpool/LendingPool.sol index 539b6ac6..2aa45f84 100644 --- a/contracts/lendingpool/LendingPool.sol +++ b/contracts/lendingpool/LendingPool.sol @@ -352,7 +352,7 @@ contract LendingPool is VersionedInitializable, ILendingPool, LendingPoolStorage reserve.updateInterestRates(asset, reserve.aTokenAddress, 0, 0); - emit Swap(asset, msg.sender); + emit Swap(asset, msg.sender, rateMode); } /** diff --git a/contracts/lendingpool/LendingPoolConfigurator.sol b/contracts/lendingpool/LendingPoolConfigurator.sol index c3da634c..1428805e 100644 --- a/contracts/lendingpool/LendingPoolConfigurator.sol +++ b/contracts/lendingpool/LendingPoolConfigurator.sol @@ -47,7 +47,7 @@ contract LendingPoolConfigurator is VersionedInitializable { * @param asset the address of the reserve * @param stableRateEnabled true if stable rate borrowing is enabled, false otherwise **/ - event BorrowingEnabledOnReserve(address asset, bool stableRateEnabled); + event BorrowingEnabledOnReserve(address indexed asset, bool stableRateEnabled); /** * @dev emitted when borrowing is disabled on a reserve @@ -116,42 +116,42 @@ contract LendingPoolConfigurator is VersionedInitializable { * @param asset the address of the reserve * @param ltv the new value for the loan to value **/ - event ReserveBaseLtvChanged(address asset, uint256 ltv); + event ReserveBaseLtvChanged(address indexed asset, uint256 ltv); /** * @dev emitted when a reserve factor is updated * @param asset the address of the reserve * @param factor the new reserve factor **/ - event ReserveFactorChanged(address asset, uint256 factor); + event ReserveFactorChanged(address indexed asset, uint256 factor); /** * @dev emitted when a reserve liquidation threshold is updated * @param asset the address of the reserve * @param threshold the new value for the liquidation threshold **/ - event ReserveLiquidationThresholdChanged(address asset, uint256 threshold); + event ReserveLiquidationThresholdChanged(address indexed asset, uint256 threshold); /** * @dev emitted when a reserve liquidation bonus is updated * @param asset the address of the reserve * @param bonus the new value for the liquidation bonus **/ - event ReserveLiquidationBonusChanged(address asset, uint256 bonus); + event ReserveLiquidationBonusChanged(address indexed asset, uint256 bonus); /** * @dev emitted when the reserve decimals are updated * @param asset the address of the reserve * @param decimals the new decimals **/ - event ReserveDecimalsChanged(address asset, uint256 decimals); + event ReserveDecimalsChanged(address indexed asset, uint256 decimals); /** * @dev emitted when a reserve interest strategy contract is updated * @param asset the address of the reserve * @param strategy the new address of the interest strategy contract **/ - event ReserveInterestRateStrategyChanged(address asset, address strategy); + event ReserveInterestRateStrategyChanged(address indexed asset, address strategy); /** * @dev emitted when an aToken implementation is upgraded @@ -159,7 +159,7 @@ contract LendingPoolConfigurator is VersionedInitializable { * @param proxy the aToken proxy address * @param implementation the new aToken implementation **/ - event ATokenUpgraded(address asset, address proxy, address implementation); + event ATokenUpgraded(address indexed asset, address indexed proxy, address indexed implementation); /** * @dev emitted when the implementation of a stable debt token is upgraded @@ -167,7 +167,7 @@ contract LendingPoolConfigurator is VersionedInitializable { * @param proxy the stable debt token proxy address * @param implementation the new aToken implementation **/ - event StableDebtTokenUpgraded(address asset, address proxy, address implementation); + event StableDebtTokenUpgraded(address indexed asset, address indexed proxy, address indexed implementation); /** * @dev emitted when the implementation of a variable debt token is upgraded @@ -175,7 +175,7 @@ contract LendingPoolConfigurator is VersionedInitializable { * @param proxy the variable debt token proxy address * @param implementation the new aToken implementation **/ - event VariableDebtTokenUpgraded(address asset, address proxy, address implementation); + event VariableDebtTokenUpgraded(address indexed asset, address indexed proxy, address indexed implementation); ILendingPoolAddressesProvider internal addressesProvider; ILendingPool internal pool; diff --git a/deployed-contracts.json b/deployed-contracts.json index 9690522a..401a2694 100644 --- a/deployed-contracts.json +++ b/deployed-contracts.json @@ -163,25 +163,26 @@ }, "ReserveLogic": { "buidlerevm": { - "address": "0xFAe0fd738dAbc8a0426F47437322b6d026A9FD95", + "address": "0x78Ee8Fb9fE5abD5e347Fc94c2fb85596d1f60e3c", "deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6" } }, "GenericLogic": { "buidlerevm": { - "address": "0x6082731fdAba4761277Fb31299ebC782AD3bCf24", + "address": "0x920d847fE49E54C19047ba8bc236C45A8068Bca7", "deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6" } }, "ValidationLogic": { "buidlerevm": { - "address": "0x8456161947DFc1fC159A0B26c025cD2b4bba0c3e", + "address": "0xA4765Ff72A9F3CfE73089bb2c3a41B838DF71574", "deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6" } }, "LendingPool": { "buidlerevm": { - "address": "0xD9273d497eDBC967F39d419461CfcF382a0A822e" + "address": "0x35c1419Da7cf0Ff885B8Ef8EA9242FEF6800c99b", + "deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6" } }, "LendingPoolConfigurator": { From 5cc6acce8612597bdcd43c8e217739770400c144 Mon Sep 17 00:00:00 2001 From: pistiner <59415933+orpistiner@users.noreply.github.com> Date: Thu, 29 Oct 2020 23:19:11 +0200 Subject: [PATCH 14/35] Updates in the specification of StableDebtToken --- runStableTokenCLI.sh | 2 +- specs/StableDebtToken.spec | 14 ++++++++++---- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/runStableTokenCLI.sh b/runStableTokenCLI.sh index 658c7663..8903f2f9 100644 --- a/runStableTokenCLI.sh +++ b/runStableTokenCLI.sh @@ -1 +1 @@ -certoraRun specs/harness/StableDebtTokenHarness.sol:StableDebtTokenHarness --solc solc6.8 --verify StableDebtTokenHarness:specs/StableDebtToken.spec --settings -assumeUnwindCond,-useNonLinearArithmetic --cache StableDebtToken --staging master \ No newline at end of file +certoraRun specs/harness/StableDebtTokenHarness.sol:StableDebtTokenHarness --solc solc6.8 --verify StableDebtTokenHarness:specs/StableDebtToken.spec --settings -assumeUnwindCond --cache StableDebtToken --staging master \ No newline at end of file diff --git a/specs/StableDebtToken.spec b/specs/StableDebtToken.spec index 718dcb60..0d6e0c5d 100644 --- a/specs/StableDebtToken.spec +++ b/specs/StableDebtToken.spec @@ -90,19 +90,25 @@ rule integrityMint(address a, uint256 x) { /** Mint is additive, can performed either all at once or gradually mint(u,x); mint(u,y) ~ mint(u,x+y) at the same timestamp + +Note: We assume that the stable rate of the user is 0. +The case where the rate is non-zero takes much more time to prove, +and therefore it is currently excluded from the CI. */ rule additiveMint(address a, uint256 x, uint256 y) { env e; require sinvoke getIncentivesController(e) == 0; + require getUserStableRate(e,a) == 0; uint256 index; storage initialStorage = lastStorage; sinvoke mint(e,a,x,index); sinvoke mint(e,a,y,index); uint256 balanceScenario1 = sinvoke balanceOf(e,a); - uint t = x + y; + + uint256 t = x + y; sinvoke mint(e,a, t ,index) at initialStorage; - - uint256 balanceScenario2 = sinvoke balanceOf(e,a); + + uint256 balanceScenario2 = sinvoke balanceOf(e,a); assert balanceScenario1 == balanceScenario2, "mint is not additive"; } @@ -124,7 +130,7 @@ rule additiveBurn(address a, uint256 x, uint256 y) { sinvoke burn(e, a, x); sinvoke burn(e, a, y); uint256 balanceScenario1 = balanceOf(e, a); - uint t = x + y; + uint256 t = x + y; sinvoke burn(e, a, t) at initialStorage; uint256 balanceScenario2 = balanceOf(e, a); From 22353eeee583426bf9525b4a3d08ee16e80633b8 Mon Sep 17 00:00:00 2001 From: pistiner <59415933+orpistiner@users.noreply.github.com> Date: Fri, 30 Oct 2020 01:07:30 +0200 Subject: [PATCH 15/35] Fixes to run on VariableDebtToken --- contracts/lendingpool/LendingPool.sol | 2 +- ...LendingPoolHarnessForVariableDebtToken.sol | 43 +++++++++++-------- 2 files changed, 25 insertions(+), 20 deletions(-) diff --git a/contracts/lendingpool/LendingPool.sol b/contracts/lendingpool/LendingPool.sol index 539b6ac6..34a36c96 100644 --- a/contracts/lendingpool/LendingPool.sol +++ b/contracts/lendingpool/LendingPool.sol @@ -691,7 +691,7 @@ contract LendingPool is VersionedInitializable, ILendingPool, LendingPoolStorage * @param asset the address of the reserve * @return the reserve normalized income */ - function getReserveNormalizedIncome(address asset) external override view returns (uint256) { + function getReserveNormalizedIncome(address asset) external virtual override view returns (uint256) { return _reserves[asset].getNormalizedIncome(); } diff --git a/specs/harness/LendingPoolHarnessForVariableDebtToken.sol b/specs/harness/LendingPoolHarnessForVariableDebtToken.sol index 6cd8ec38..1fdeffb0 100644 --- a/specs/harness/LendingPoolHarnessForVariableDebtToken.sol +++ b/specs/harness/LendingPoolHarnessForVariableDebtToken.sol @@ -87,17 +87,6 @@ contract LendingPoolHarnessForVariableDebtToken is ILendingPool { originalPool.liquidationCall(collateral, asset, user, purchaseAmount, receiveAToken); } - function flashLoan( - address receiver, - address[] calldata assets, - uint256[] calldata amounts, - uint256 mode, - bytes calldata params, - uint16 referralCode - ) external override { - originalPool.flashLoan(receiver, assets, amounts, mode, params, referralCode); - } - function getReservesList() external override view returns (address[] memory) { return originalPool.getReservesList(); } @@ -175,14 +164,6 @@ contract LendingPoolHarnessForVariableDebtToken is ILendingPool { return reserveNormalizedVariableDebt[block.timestamp]; } - function balanceDecreaseAllowed( - address asset, - address user, - uint256 amount - ) external override view returns (bool) { - return originalPool.balanceDecreaseAllowed(asset, user, amount); - } - function setPause(bool val) external override { originalPool.setPause(val); } @@ -190,4 +171,28 @@ contract LendingPoolHarnessForVariableDebtToken is ILendingPool { function paused() external override view returns (bool) { return originalPool.paused(); } + + function flashLoan( + address receiver, + address[] calldata assets, + uint256[] calldata amounts, + uint256 mode, + address onBehalfOf, + bytes calldata params, + uint16 referralCode + ) external override { + originalPool.flashLoan(receiver, assets, amounts, mode, onBehalfOf, params, referralCode); + } + + function finalizeTransfer( + address asset, + address from, + address to, + uint256 amount, + uint256 balanceFromAfter, + uint256 balanceToBefore + ) external override { + originalPool.finalizeTransfer(asset, from, to, amount, balanceFromAfter, balanceToBefore); + } + } From 7ae9a2df8f6acd99f25ac02f3a0020e5d9b04782 Mon Sep 17 00:00:00 2001 From: emilio Date: Fri, 30 Oct 2020 11:36:53 +0100 Subject: [PATCH 16/35] Updated variable names --- contracts/libraries/logic/ValidationLogic.sol | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/contracts/libraries/logic/ValidationLogic.sol b/contracts/libraries/logic/ValidationLogic.sol index 78f74154..d9824835 100644 --- a/contracts/libraries/logic/ValidationLogic.sol +++ b/contracts/libraries/logic/ValidationLogic.sol @@ -258,8 +258,8 @@ library ValidationLogic { function validateSwapRateMode( ReserveLogic.ReserveData storage reserve, UserConfiguration.Map storage userConfig, - uint256 stableBorrowBalance, - uint256 variableBorrowBalance, + uint256 stableDebt, + uint256 variableDebt, ReserveLogic.InterestRateMode currentRateMode ) external view { (bool isActive, bool isFreezed, , bool stableRateEnabled) = reserve.configuration.getFlags(); @@ -268,9 +268,9 @@ library ValidationLogic { require(!isFreezed, Errors.NO_UNFREEZED_RESERVE); if (currentRateMode == ReserveLogic.InterestRateMode.STABLE) { - require(stableBorrowBalance > 0, Errors.NO_STABLE_RATE_LOAN_IN_RESERVE); + require(stableDebt > 0, Errors.NO_STABLE_RATE_LOAN_IN_RESERVE); } else if (currentRateMode == ReserveLogic.InterestRateMode.VARIABLE) { - require(variableBorrowBalance > 0, Errors.NO_VARIABLE_RATE_LOAN_IN_RESERVE); + require(variableDebt > 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 @@ -283,7 +283,7 @@ library ValidationLogic { require( !userConfig.isUsingAsCollateral(reserve.id) || reserve.configuration.getLtv() == 0 || - stableBorrowBalance.add(variableBorrowBalance) > + stableDebt.add(variableDebt) > IERC20(reserve.aTokenAddress).balanceOf(msg.sender), Errors.CALLATERAL_SAME_AS_BORROWING_CURRENCY ); From a49f2744ee888f16e88ed79c6f9893d64249e6c2 Mon Sep 17 00:00:00 2001 From: emilio Date: Fri, 30 Oct 2020 11:38:49 +0100 Subject: [PATCH 17/35] Updated comments --- contracts/libraries/logic/ValidationLogic.sol | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/contracts/libraries/logic/ValidationLogic.sol b/contracts/libraries/logic/ValidationLogic.sol index d9824835..adbfdfc7 100644 --- a/contracts/libraries/logic/ValidationLogic.sol +++ b/contracts/libraries/logic/ValidationLogic.sol @@ -251,8 +251,8 @@ library ValidationLogic { * @dev validates a swap of borrow rate mode. * @param reserve the reserve state on which the user is swapping the rate * @param userConfig the user reserves configuration - * @param stableBorrowBalance the stable borrow balance of the user - * @param variableBorrowBalance the stable borrow balance of the user + * @param stableDebt the stable debt of the user + * @param variableDebt the variable debt of the user * @param currentRateMode the rate mode of the borrow */ function validateSwapRateMode( From de7ec39f24b8a4e44a7c82226a5bbd0df459eb98 Mon Sep 17 00:00:00 2001 From: eboado Date: Fri, 30 Oct 2020 11:42:27 +0100 Subject: [PATCH 18/35] - Fixed comment on ILendingPool --- contracts/interfaces/ILendingPool.sol | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/contracts/interfaces/ILendingPool.sol b/contracts/interfaces/ILendingPool.sol index a9a176f7..9dbb7c89 100644 --- a/contracts/interfaces/ILendingPool.sol +++ b/contracts/interfaces/ILendingPool.sol @@ -99,15 +99,13 @@ interface ILendingPool { /** * @dev emitted when a flashloan is executed * @param target the address of the flashLoanReceiver - * @param asset the address of the assets being flashborrowed + * @param asset the address of the asset being flashborrowed * @param amount the amount requested * @param premium the total fee on the amount * @param referralCode the referral code of the caller **/ event FlashLoan( address indexed target, - // uint256[] modes, - // address indexed onBehalfOf, address asset, uint256 amount, uint256 premium, From 092aacc85a162a45d56fcf69b53529d3fe586970 Mon Sep 17 00:00:00 2001 From: eboado Date: Fri, 30 Oct 2020 11:49:23 +0100 Subject: [PATCH 19/35] - Added initiator to flash loan event. --- contracts/interfaces/ILendingPool.sol | 2 ++ contracts/lendingpool/LendingPool.sol | 1 + 2 files changed, 3 insertions(+) diff --git a/contracts/interfaces/ILendingPool.sol b/contracts/interfaces/ILendingPool.sol index 9dbb7c89..55362ec1 100644 --- a/contracts/interfaces/ILendingPool.sol +++ b/contracts/interfaces/ILendingPool.sol @@ -99,6 +99,7 @@ interface ILendingPool { /** * @dev emitted when a flashloan is executed * @param target the address of the flashLoanReceiver + * @param initiator the address initiating the flash loan * @param asset the address of the asset being flashborrowed * @param amount the amount requested * @param premium the total fee on the amount @@ -106,6 +107,7 @@ interface ILendingPool { **/ event FlashLoan( address indexed target, + address initiator, address asset, uint256 amount, uint256 premium, diff --git a/contracts/lendingpool/LendingPool.sol b/contracts/lendingpool/LendingPool.sol index a90fc385..987d8eb9 100644 --- a/contracts/lendingpool/LendingPool.sol +++ b/contracts/lendingpool/LendingPool.sol @@ -595,6 +595,7 @@ contract LendingPool is VersionedInitializable, ILendingPool, LendingPoolStorage } emit FlashLoan( receiverAddress, + msg.sender, vars.currentAsset, vars.currentAmount, vars.currentPremium, From 910fa2dce6eba2a60aee033f9a0d5aaff63bd531 Mon Sep 17 00:00:00 2001 From: eboado Date: Fri, 30 Oct 2020 11:52:00 +0100 Subject: [PATCH 20/35] - Added indexed to flash loan events. --- contracts/interfaces/ILendingPool.sol | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/contracts/interfaces/ILendingPool.sol b/contracts/interfaces/ILendingPool.sol index 55362ec1..564392db 100644 --- a/contracts/interfaces/ILendingPool.sol +++ b/contracts/interfaces/ILendingPool.sol @@ -107,8 +107,8 @@ interface ILendingPool { **/ event FlashLoan( address indexed target, - address initiator, - address asset, + address indexed initiator, + address indexed asset, uint256 amount, uint256 premium, uint16 referralCode From af6b370f0e5da3e6aabb231e918c0bfda9615f40 Mon Sep 17 00:00:00 2001 From: eboado Date: Fri, 30 Oct 2020 11:55:28 +0100 Subject: [PATCH 21/35] - Removed from memory struct debtMode on flashLoan() --- contracts/lendingpool/LendingPool.sol | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/contracts/lendingpool/LendingPool.sol b/contracts/lendingpool/LendingPool.sol index 987d8eb9..471d986c 100644 --- a/contracts/lendingpool/LendingPool.sol +++ b/contracts/lendingpool/LendingPool.sol @@ -486,7 +486,6 @@ contract LendingPool is VersionedInitializable, ILendingPool, LendingPoolStorage struct FlashLoanLocalVars { IFlashLoanReceiver receiver; address oracle; - ReserveLogic.InterestRateMode debtMode; uint256 i; address currentAsset; address currentATokenAddress; @@ -548,10 +547,9 @@ contract LendingPool is VersionedInitializable, ILendingPool, LendingPoolStorage vars.currentAmount = amounts[vars.i]; vars.currentPremium = premiums[vars.i]; vars.currentATokenAddress = aTokenAddresses[vars.i]; - vars.debtMode = ReserveLogic.InterestRateMode(modes[vars.i]); vars.currentAmountPlusPremium = vars.currentAmount.add(vars.currentPremium); - if (vars.debtMode == ReserveLogic.InterestRateMode.NONE) { + if (ReserveLogic.InterestRateMode(modes[vars.i]) == ReserveLogic.InterestRateMode.NONE) { _reserves[vars.currentAsset].updateState(); _reserves[vars.currentAsset].cumulateToLiquidityIndex( IERC20(vars.currentATokenAddress).totalSupply(), From decf652e192e95f38952658a690a82f2c5dafdc4 Mon Sep 17 00:00:00 2001 From: emilio Date: Fri, 30 Oct 2020 11:55:50 +0100 Subject: [PATCH 22/35] Removed variable --- contracts/lendingpool/LendingPool.sol | 3 +-- deployed-contracts.json | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/contracts/lendingpool/LendingPool.sol b/contracts/lendingpool/LendingPool.sol index 1a589091..88ce5e9a 100644 --- a/contracts/lendingpool/LendingPool.sol +++ b/contracts/lendingpool/LendingPool.sol @@ -881,9 +881,8 @@ contract LendingPool is VersionedInitializable, ILendingPool, LendingPoolStorage ); } - uint256 reserveId = reserve.id; if (isFirstBorrowing) { - userConfig.setBorrowing(reserveId, true); + userConfig.setBorrowing(reserve.id, true); } reserve.updateInterestRates( diff --git a/deployed-contracts.json b/deployed-contracts.json index d7001b2a..4b961b6c 100644 --- a/deployed-contracts.json +++ b/deployed-contracts.json @@ -628,4 +628,4 @@ "deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6" } } -} +} \ No newline at end of file From 7227717a7a292353fd364fcf17123ee7a0f39429 Mon Sep 17 00:00:00 2001 From: eboado Date: Fri, 30 Oct 2020 12:06:02 +0100 Subject: [PATCH 23/35] - Removed modes from validateFlashLoan. Not needed as executeBorrow() will fail. --- contracts/lendingpool/LendingPool.sol | 2 +- contracts/libraries/logic/ValidationLogic.sol | 19 ++----------------- 2 files changed, 3 insertions(+), 18 deletions(-) diff --git a/contracts/lendingpool/LendingPool.sol b/contracts/lendingpool/LendingPool.sol index 471d986c..7e29b92d 100644 --- a/contracts/lendingpool/LendingPool.sol +++ b/contracts/lendingpool/LendingPool.sol @@ -520,7 +520,7 @@ contract LendingPool is VersionedInitializable, ILendingPool, LendingPoolStorage FlashLoanLocalVars memory vars; - ValidationLogic.validateFlashloan(assets, amounts, modes); + ValidationLogic.validateFlashloan(assets, amounts); address[] memory aTokenAddresses = new address[](assets.length); uint256[] memory premiums = new uint256[](assets.length); diff --git a/contracts/libraries/logic/ValidationLogic.sol b/contracts/libraries/logic/ValidationLogic.sol index cc771f8b..b677f34e 100644 --- a/contracts/libraries/logic/ValidationLogic.sol +++ b/contracts/libraries/logic/ValidationLogic.sol @@ -331,26 +331,11 @@ library ValidationLogic { /** * @dev validates a flashloan action - * @param modes the flashloan modes (0 = classic flashloan, 1 = open a stable rate loan, 2 = open a variable rate loan) * @param assets the assets being flashborrowed * @param amounts the amounts for each asset being borrowed **/ - function validateFlashloan( - address[] calldata assets, - uint256[] calldata amounts, - uint256[] calldata modes - ) external pure { - require( - assets.length == amounts.length && assets.length == modes.length, - Errors.INCONSISTENT_FLASHLOAN_PARAMS - ); - - for (uint256 i = 0; i < modes.length; i++) { - require( - modes[i] <= uint256(ReserveLogic.InterestRateMode.VARIABLE), - Errors.INVALID_FLASHLOAN_MODE - ); - } + function validateFlashloan(address[] memory assets, uint256[] memory amounts) internal pure { + require(assets.length == amounts.length, Errors.INCONSISTENT_FLASHLOAN_PARAMS); } /** From b2bbe62822bff23bfd1339b8084624e1fe29b735 Mon Sep 17 00:00:00 2001 From: eboado Date: Fri, 30 Oct 2020 12:38:41 +0100 Subject: [PATCH 24/35] - Added `to` to withdraw() --- contracts/interfaces/ILendingPool.sol | 10 ++++++++-- contracts/lendingpool/LendingPool.sol | 13 +++++++++---- test/helpers/actions.ts | 8 +++++--- test/pausable-functions.spec.ts | 12 ++++++++++-- 4 files changed, 32 insertions(+), 11 deletions(-) diff --git a/contracts/interfaces/ILendingPool.sol b/contracts/interfaces/ILendingPool.sol index 2e4e2d94..4848df78 100644 --- a/contracts/interfaces/ILendingPool.sol +++ b/contracts/interfaces/ILendingPool.sol @@ -27,9 +27,10 @@ interface ILendingPool { * @dev emitted during a withdraw action. * @param reserve the address of the reserve * @param user the address of the user + * @param to address that will receive the underlying * @param amount the amount to be withdrawn **/ - event Withdraw(address indexed reserve, address indexed user, uint256 amount); + event Withdraw(address indexed reserve, address indexed user, address indexed to, uint256 amount); event BorrowAllowanceDelegated( address indexed asset, @@ -188,8 +189,13 @@ interface ILendingPool { * @dev withdraws the assets of user. * @param reserve the address of the reserve * @param amount the underlying amount to be redeemed + * @param to address that will receive the underlying **/ - function withdraw(address reserve, uint256 amount) external; + function withdraw( + address reserve, + uint256 amount, + address to + ) external; /** * @dev Sets allowance to borrow on a certain type of debt asset for a certain user address diff --git a/contracts/lendingpool/LendingPool.sol b/contracts/lendingpool/LendingPool.sol index 3c2fcd8a..4faae912 100644 --- a/contracts/lendingpool/LendingPool.sol +++ b/contracts/lendingpool/LendingPool.sol @@ -120,8 +120,13 @@ contract LendingPool is VersionedInitializable, ILendingPool, LendingPoolStorage * @dev withdraws the _reserves of user. * @param asset the address of the reserve * @param amount the underlying amount to be redeemed + * @param to address that will receive the underlying **/ - function withdraw(address asset, uint256 amount) external override { + function withdraw( + address asset, + uint256 amount, + address to + ) external override { _whenNotPaused(); ReserveLogic.ReserveData storage reserve = _reserves[asset]; @@ -155,9 +160,9 @@ contract LendingPool is VersionedInitializable, ILendingPool, LendingPoolStorage _usersConfig[msg.sender].setUsingAsCollateral(reserve.id, false); } - IAToken(aToken).burn(msg.sender, msg.sender, amountToWithdraw, reserve.liquidityIndex); + IAToken(aToken).burn(msg.sender, to, amountToWithdraw, reserve.liquidityIndex); - emit Withdraw(asset, msg.sender, amountToWithdraw); + emit Withdraw(asset, msg.sender, to, amountToWithdraw); } /** @@ -892,7 +897,7 @@ contract LendingPool is VersionedInitializable, ILendingPool, LendingPoolStorage //caching the current stable borrow rate uint256 currentStableRate = 0; - + bool isFirstBorrowing = false; if ( ReserveLogic.InterestRateMode(vars.interestRateMode) == ReserveLogic.InterestRateMode.STABLE diff --git a/test/helpers/actions.ts b/test/helpers/actions.ts index 422b0455..82701087 100644 --- a/test/helpers/actions.ts +++ b/test/helpers/actions.ts @@ -231,7 +231,7 @@ export const withdraw = async ( if (expectedResult === 'success') { const txResult = await waitForTx( - await pool.connect(user.signer).withdraw(reserve, amountToWithdraw) + await pool.connect(user.signer).withdraw(reserve, amountToWithdraw, user.address) ); const { @@ -269,8 +269,10 @@ export const withdraw = async ( // ); // }); } else if (expectedResult === 'revert') { - await expect(pool.connect(user.signer).withdraw(reserve, amountToWithdraw), revertMessage).to.be - .reverted; + await expect( + pool.connect(user.signer).withdraw(reserve, amountToWithdraw, user.address), + revertMessage + ).to.be.reverted; } }; diff --git a/test/pausable-functions.spec.ts b/test/pausable-functions.spec.ts index 7a24da2d..72be7ada 100644 --- a/test/pausable-functions.spec.ts +++ b/test/pausable-functions.spec.ts @@ -116,7 +116,7 @@ makeSuite('Pausable Pool', (testEnv: TestEnv) => { // user tries to burn await expect( - pool.connect(users[0].signer).withdraw(dai.address, amountDAItoDeposit) + pool.connect(users[0].signer).withdraw(dai.address, amountDAItoDeposit, users[0].address) ).to.revertedWith(IS_PAUSED); // Configurator unpauses the pool @@ -187,7 +187,15 @@ makeSuite('Pausable Pool', (testEnv: TestEnv) => { await expect( pool .connect(caller.signer) - .flashLoan(_mockFlashLoanReceiver.address, [weth.address], [flashAmount], 1, caller.address, '0x10', '0') + .flashLoan( + _mockFlashLoanReceiver.address, + [weth.address], + [flashAmount], + 1, + caller.address, + '0x10', + '0' + ) ).revertedWith(IS_PAUSED); // Unpause pool From 631d6ebfcbcd6fadb0ea11baf5220e9b57863866 Mon Sep 17 00:00:00 2001 From: eboado Date: Fri, 30 Oct 2020 13:32:42 +0100 Subject: [PATCH 25/35] - Passed `initiator` param to flashLoan()'s executeOperation() receiver. - Removed unused ISwapAdapter. --- .../interfaces/IFlashLoanReceiver.sol | 1 + contracts/interfaces/ISwapAdapter.sol | 20 ------------------- contracts/lendingpool/LendingPool.sol | 5 ++--- .../LendingPoolCollateralManager.sol | 1 - .../mocks/flashloan/MockFlashLoanReceiver.sol | 2 ++ 5 files changed, 5 insertions(+), 24 deletions(-) delete mode 100644 contracts/interfaces/ISwapAdapter.sol diff --git a/contracts/flashloan/interfaces/IFlashLoanReceiver.sol b/contracts/flashloan/interfaces/IFlashLoanReceiver.sol index 784d0fa3..af9e384f 100644 --- a/contracts/flashloan/interfaces/IFlashLoanReceiver.sol +++ b/contracts/flashloan/interfaces/IFlashLoanReceiver.sol @@ -12,6 +12,7 @@ interface IFlashLoanReceiver { address[] calldata assets, uint256[] calldata amounts, uint256[] calldata premiums, + address initiator, bytes calldata params ) external returns (bool); } diff --git a/contracts/interfaces/ISwapAdapter.sol b/contracts/interfaces/ISwapAdapter.sol deleted file mode 100644 index ed91f95f..00000000 --- a/contracts/interfaces/ISwapAdapter.sol +++ /dev/null @@ -1,20 +0,0 @@ -// SPDX-License-Identifier: agpl-3.0 -pragma solidity ^0.6.8; - -interface ISwapAdapter { - /** - * @dev Swaps an `amountToSwap` of an asset to another, approving a `fundsDestination` to pull the funds - * @param assetToSwapFrom Origin asset - * @param assetToSwapTo Destination asset - * @param amountToSwap How much `assetToSwapFrom` needs to be swapped - * @param fundsDestination Address that will be pulling the swapped funds - * @param params Additional variadic field to include extra params - */ - function executeOperation( - address assetToSwapFrom, - address assetToSwapTo, - uint256 amountToSwap, - address fundsDestination, - bytes calldata params - ) external; -} diff --git a/contracts/lendingpool/LendingPool.sol b/contracts/lendingpool/LendingPool.sol index 3c2fcd8a..c6455947 100644 --- a/contracts/lendingpool/LendingPool.sol +++ b/contracts/lendingpool/LendingPool.sol @@ -20,7 +20,6 @@ import {IStableDebtToken} from '../tokenization/interfaces/IStableDebtToken.sol' import {IVariableDebtToken} from '../tokenization/interfaces/IVariableDebtToken.sol'; import {DebtTokenBase} from '../tokenization/base/DebtTokenBase.sol'; import {IFlashLoanReceiver} from '../flashloan/interfaces/IFlashLoanReceiver.sol'; -import {ISwapAdapter} from '../interfaces/ISwapAdapter.sol'; import {LendingPoolCollateralManager} from './LendingPoolCollateralManager.sol'; import {IPriceOracleGetter} from '../interfaces/IPriceOracleGetter.sol'; import {SafeERC20} from '../dependencies/openzeppelin/contracts/SafeERC20.sol'; @@ -539,7 +538,7 @@ contract LendingPool is VersionedInitializable, ILendingPool, LendingPoolStorage //execute action of the receiver require( - vars.receiver.executeOperation(assets, amounts, premiums, params), + vars.receiver.executeOperation(assets, amounts, premiums, msg.sender, params), Errors.INVALID_FLASH_LOAN_EXECUTOR_RETURN ); @@ -892,7 +891,7 @@ contract LendingPool is VersionedInitializable, ILendingPool, LendingPoolStorage //caching the current stable borrow rate uint256 currentStableRate = 0; - + bool isFirstBorrowing = false; if ( ReserveLogic.InterestRateMode(vars.interestRateMode) == ReserveLogic.InterestRateMode.STABLE diff --git a/contracts/lendingpool/LendingPoolCollateralManager.sol b/contracts/lendingpool/LendingPoolCollateralManager.sol index 16abdd10..96f555d3 100644 --- a/contracts/lendingpool/LendingPoolCollateralManager.sol +++ b/contracts/lendingpool/LendingPoolCollateralManager.sol @@ -15,7 +15,6 @@ import {Helpers} from '../libraries/helpers/Helpers.sol'; import {WadRayMath} from '../libraries/math/WadRayMath.sol'; import {PercentageMath} from '../libraries/math/PercentageMath.sol'; import {SafeERC20} from '../dependencies/openzeppelin/contracts/SafeERC20.sol'; -import {ISwapAdapter} from '../interfaces/ISwapAdapter.sol'; import {Errors} from '../libraries/helpers/Errors.sol'; import {ValidationLogic} from '../libraries/logic/ValidationLogic.sol'; import {LendingPoolStorage} from './LendingPoolStorage.sol'; diff --git a/contracts/mocks/flashloan/MockFlashLoanReceiver.sol b/contracts/mocks/flashloan/MockFlashLoanReceiver.sol index 7b72c2cb..215746ae 100644 --- a/contracts/mocks/flashloan/MockFlashLoanReceiver.sol +++ b/contracts/mocks/flashloan/MockFlashLoanReceiver.sol @@ -47,9 +47,11 @@ contract MockFlashLoanReceiver is FlashLoanReceiverBase { address[] memory assets, uint256[] memory amounts, uint256[] memory premiums, + address initiator, bytes memory params ) public override returns (bool) { params; + initiator; if (_failExecution) { emit ExecutedWithFail(assets, amounts, premiums); From 6f5bcddab16fe3779b15d8c61a5c8e5ac91f0e7d Mon Sep 17 00:00:00 2001 From: emilio Date: Fri, 30 Oct 2020 16:12:59 +0100 Subject: [PATCH 26/35] fixed tests --- buidler.config.ts | 2 +- contracts/lendingpool/LendingPool.sol | 3 +++ contracts/lendingpool/LendingPoolConfigurator.sol | 7 ++++++- deployed-contracts.json | 9 +++++---- 4 files changed, 15 insertions(+), 6 deletions(-) diff --git a/buidler.config.ts b/buidler.config.ts index 79b1d670..b487498a 100644 --- a/buidler.config.ts +++ b/buidler.config.ts @@ -11,7 +11,7 @@ usePlugin('buidler-typechain'); usePlugin('solidity-coverage'); usePlugin('@nomiclabs/buidler-waffle'); usePlugin('@nomiclabs/buidler-etherscan'); -usePlugin('buidler-gas-reporter'); +//usePlugin('buidler-gas-reporter'); const SKIP_LOAD = process.env.SKIP_LOAD === 'true'; const DEFAULT_BLOCK_GAS_LIMIT = 12000000; diff --git a/contracts/lendingpool/LendingPool.sol b/contracts/lendingpool/LendingPool.sol index 99734898..f385f53d 100644 --- a/contracts/lendingpool/LendingPool.sol +++ b/contracts/lendingpool/LendingPool.sol @@ -26,6 +26,8 @@ import {SafeERC20} from '../dependencies/openzeppelin/contracts/SafeERC20.sol'; import {ILendingPool} from '../interfaces/ILendingPool.sol'; import {LendingPoolStorage} from './LendingPoolStorage.sol'; import {IReserveInterestRateStrategy} from '../interfaces/IReserveInterestRateStrategy.sol'; +import "@nomiclabs/buidler/console.sol"; + /** * @title LendingPool contract @@ -93,6 +95,7 @@ contract LendingPool is VersionedInitializable, ILendingPool, LendingPoolStorage address onBehalfOf, uint16 referralCode ) external override { + console.log("Deposit"); _whenNotPaused(); ReserveLogic.ReserveData storage reserve = _reserves[asset]; diff --git a/contracts/lendingpool/LendingPoolConfigurator.sol b/contracts/lendingpool/LendingPoolConfigurator.sol index db8c2e67..1e8e9787 100644 --- a/contracts/lendingpool/LendingPoolConfigurator.sol +++ b/contracts/lendingpool/LendingPoolConfigurator.sol @@ -15,6 +15,7 @@ import {IERC20Detailed} from '../dependencies/openzeppelin/contracts/IERC20Detai import {Errors} from '../libraries/helpers/Errors.sol'; import {PercentageMath} from '../libraries/math/PercentageMath.sol'; import {ReserveLogic} from '../libraries/logic/ReserveLogic.sol'; +import "@nomiclabs/buidler/console.sol"; /** * @title LendingPoolConfigurator contract @@ -371,6 +372,7 @@ contract LendingPoolConfigurator is VersionedInitializable { // the reserve is being disabled as collateral. To do so, //we need to ensure no liquidity is deposited if(liquidationThreshold == 0) { + console.log("Checking no liquidity for the asset"); _checkNoLiquidity(asset); } @@ -432,7 +434,7 @@ contract LendingPoolConfigurator is VersionedInitializable { function deactivateReserve(address asset) external onlyAaveAdmin { _checkNoLiquidity(asset); - + ReserveConfiguration.Map memory currentConfig = pool.getConfiguration(asset); currentConfig.setActive(false); @@ -617,6 +619,9 @@ contract LendingPoolConfigurator is VersionedInitializable { uint256 availableLiquidity = IERC20Detailed(asset).balanceOf(reserveData.aTokenAddress); + console.log("Available liquidity %s", availableLiquidity); + console.log("liq rate %s", reserveData.currentLiquidityRate); + require( availableLiquidity == 0 && reserveData.currentLiquidityRate == 0, Errors.RESERVE_LIQUIDITY_NOT_0 diff --git a/deployed-contracts.json b/deployed-contracts.json index 9690522a..401a2694 100644 --- a/deployed-contracts.json +++ b/deployed-contracts.json @@ -163,25 +163,26 @@ }, "ReserveLogic": { "buidlerevm": { - "address": "0xFAe0fd738dAbc8a0426F47437322b6d026A9FD95", + "address": "0x78Ee8Fb9fE5abD5e347Fc94c2fb85596d1f60e3c", "deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6" } }, "GenericLogic": { "buidlerevm": { - "address": "0x6082731fdAba4761277Fb31299ebC782AD3bCf24", + "address": "0x920d847fE49E54C19047ba8bc236C45A8068Bca7", "deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6" } }, "ValidationLogic": { "buidlerevm": { - "address": "0x8456161947DFc1fC159A0B26c025cD2b4bba0c3e", + "address": "0xA4765Ff72A9F3CfE73089bb2c3a41B838DF71574", "deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6" } }, "LendingPool": { "buidlerevm": { - "address": "0xD9273d497eDBC967F39d419461CfcF382a0A822e" + "address": "0x35c1419Da7cf0Ff885B8Ef8EA9242FEF6800c99b", + "deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6" } }, "LendingPoolConfigurator": { From 929fd6bc83cacba43bd997c28de0299a48369c3b Mon Sep 17 00:00:00 2001 From: eboado Date: Fri, 30 Oct 2020 16:40:49 +0100 Subject: [PATCH 27/35] - Removed buidler console.log from LendingPool --- contracts/lendingpool/LendingPool.sol | 3 --- 1 file changed, 3 deletions(-) diff --git a/contracts/lendingpool/LendingPool.sol b/contracts/lendingpool/LendingPool.sol index b4438e65..410c592c 100644 --- a/contracts/lendingpool/LendingPool.sol +++ b/contracts/lendingpool/LendingPool.sol @@ -26,8 +26,6 @@ import {SafeERC20} from '../dependencies/openzeppelin/contracts/SafeERC20.sol'; import {ILendingPool} from '../interfaces/ILendingPool.sol'; import {LendingPoolStorage} from './LendingPoolStorage.sol'; import {IReserveInterestRateStrategy} from '../interfaces/IReserveInterestRateStrategy.sol'; -import "@nomiclabs/buidler/console.sol"; - /** * @title LendingPool contract @@ -95,7 +93,6 @@ contract LendingPool is VersionedInitializable, ILendingPool, LendingPoolStorage address onBehalfOf, uint16 referralCode ) external override { - console.log("Deposit"); _whenNotPaused(); ReserveLogic.ReserveData storage reserve = _reserves[asset]; From d6451553213335dbfedaf40161859049a67df1e5 Mon Sep 17 00:00:00 2001 From: emilio Date: Sat, 31 Oct 2020 12:17:59 +0100 Subject: [PATCH 28/35] Updated configureAsCollateral --- .../lendingpool/LendingPoolConfigurator.sol | 34 ++-- deployed-contracts.json | 9 +- package-lock.json | 174 +++++++++--------- 3 files changed, 110 insertions(+), 107 deletions(-) diff --git a/contracts/lendingpool/LendingPoolConfigurator.sol b/contracts/lendingpool/LendingPoolConfigurator.sol index d9b6c8d4..64d9ca79 100644 --- a/contracts/lendingpool/LendingPoolConfigurator.sol +++ b/contracts/lendingpool/LendingPoolConfigurator.sol @@ -15,7 +15,7 @@ import {IERC20Detailed} from '../dependencies/openzeppelin/contracts/IERC20Detai import {Errors} from '../libraries/helpers/Errors.sol'; import {PercentageMath} from '../libraries/math/PercentageMath.sol'; import {ReserveLogic} from '../libraries/logic/ReserveLogic.sol'; -import "@nomiclabs/buidler/console.sol"; +import '@nomiclabs/buidler/console.sol'; /** * @title LendingPoolConfigurator contract @@ -355,7 +355,7 @@ contract LendingPoolConfigurator is VersionedInitializable { } /** - * @dev configures the reserve collateralization parameters + * @dev configures the reserve collateralization parameters * @param asset the address of the reserve * @param ltv the loan to value of the asset when used as collateral * @param liquidationThreshold the threshold at which loans using this asset as collateral will be considered undercollateralized @@ -367,24 +367,30 @@ contract LendingPoolConfigurator is VersionedInitializable { uint256 liquidationThreshold, uint256 liquidationBonus ) external onlyAaveAdmin { + console.log('Liq threshold %s, liq bonus %s', liquidationThreshold, liquidationBonus); ReserveConfiguration.Map memory currentConfig = pool.getConfiguration(asset); - //validation of the parameters: the LTV can - //only be lower or equal than the liquidation threshold + //validation of the parameters: the LTV can + //only be lower or equal than the liquidation threshold //(otherwise a loan against the asset would cause instantaneous liquidation) require(ltv <= liquidationThreshold, Errors.INVALID_CONFIGURATION); - //liquidation bonus must be bigger than 100.00%, otherwise the liquidator would receive less - //collateral than needed to repay the debt - require(liquidationBonus > PercentageMath.PERCENTAGE_FACTOR, Errors.INVALID_CONFIGURATION); - + console.log('Liq threshold %s, liq bonus %s', liquidationThreshold, liquidationBonus); + + if (liquidationThreshold > 0) { + //liquidation bonus must be bigger than 100.00%, otherwise the liquidator would receive less + //collateral than needed to repay the debt + require(liquidationBonus > PercentageMath.PERCENTAGE_FACTOR, Errors.INVALID_CONFIGURATION); + } else { + require(liquidationBonus == 0, Errors.INVALID_CONFIGURATION); + } //if the liquidation threshold is being set to 0, // the reserve is being disabled as collateral. To do so, - //we need to ensure no liquidity is deposited - if(liquidationThreshold == 0) { - console.log("Checking no liquidity for the asset"); + //we need to ensure no liquidity is deposited + if (liquidationThreshold == 0) { + console.log('Checking no liquidity for the asset'); _checkNoLiquidity(asset); } @@ -444,7 +450,6 @@ contract LendingPoolConfigurator is VersionedInitializable { * @param asset the address of the reserve **/ function deactivateReserve(address asset) external onlyAaveAdmin { - _checkNoLiquidity(asset); ReserveConfiguration.Map memory currentConfig = pool.getConfiguration(asset); @@ -626,13 +631,12 @@ contract LendingPoolConfigurator is VersionedInitializable { } function _checkNoLiquidity(address asset) internal view { - ReserveLogic.ReserveData memory reserveData = pool.getReserveData(asset); uint256 availableLiquidity = IERC20Detailed(asset).balanceOf(reserveData.aTokenAddress); - console.log("Available liquidity %s", availableLiquidity); - console.log("liq rate %s", reserveData.currentLiquidityRate); + console.log('Available liquidity %s', availableLiquidity); + console.log('liq rate %s', reserveData.currentLiquidityRate); require( availableLiquidity == 0 && reserveData.currentLiquidityRate == 0, diff --git a/deployed-contracts.json b/deployed-contracts.json index 848902f0..642cd6a5 100644 --- a/deployed-contracts.json +++ b/deployed-contracts.json @@ -163,26 +163,25 @@ }, "ReserveLogic": { "buidlerevm": { - "address": "0x78Ee8Fb9fE5abD5e347Fc94c2fb85596d1f60e3c", + "address": "0xFAe0fd738dAbc8a0426F47437322b6d026A9FD95", "deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6" } }, "GenericLogic": { "buidlerevm": { - "address": "0x920d847fE49E54C19047ba8bc236C45A8068Bca7", + "address": "0x6082731fdAba4761277Fb31299ebC782AD3bCf24", "deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6" } }, "ValidationLogic": { "buidlerevm": { - "address": "0xA4765Ff72A9F3CfE73089bb2c3a41B838DF71574", + "address": "0x8456161947DFc1fC159A0B26c025cD2b4bba0c3e", "deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6" } }, "LendingPool": { "buidlerevm": { - "address": "0x35c1419Da7cf0Ff885B8Ef8EA9242FEF6800c99b", - "deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6" + "address": "0xD9273d497eDBC967F39d419461CfcF382a0A822e" } }, "LendingPoolConfigurator": { diff --git a/package-lock.json b/package-lock.json index 5b9d2c4c..de4f3707 100644 --- a/package-lock.json +++ b/package-lock.json @@ -5268,13 +5268,13 @@ "dependencies": { "ansi-regex": { "version": "4.1.0", - "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-4.1.0.tgz", + "resolved": false, "integrity": "sha512-1apePfXM1UOSqw0o9IiFAovVz9M5S1Dg+4TrDwfMewQ6p/rmMueb7tWZjQ1rx4Loy1ArBggoqGpfqqdI4rondg==", "dev": true }, "ansi-styles": { "version": "3.2.1", - "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-3.2.1.tgz", + "resolved": false, "integrity": "sha512-VT0ZI6kZRdTh8YyJw3SMbYm/u+NqfsAxEpWO0Pf9sq8/e94WxxOpPKx9FR1FlyCtOVDNOQ+8ntlqFxiRc+r5qA==", "dev": true, "requires": { @@ -5283,7 +5283,7 @@ }, "bindings": { "version": "1.5.0", - "resolved": "https://registry.npmjs.org/bindings/-/bindings-1.5.0.tgz", + "resolved": false, "integrity": "sha512-p2q/t/mhvuOj/UeLlV6566GD/guowlr0hHxClI0W9m7MWYkL1F0hLo+0Aexs9HSPCtR1SXQ0TD3MMKrXZajbiQ==", "dev": true, "requires": { @@ -5292,7 +5292,7 @@ }, "bip66": { "version": "1.1.5", - "resolved": "https://registry.npmjs.org/bip66/-/bip66-1.1.5.tgz", + "resolved": false, "integrity": "sha1-AfqHSHhcpwlV1QESF9GzE5lpyiI=", "dev": true, "requires": { @@ -5301,19 +5301,19 @@ }, "bn.js": { "version": "4.11.8", - "resolved": "https://registry.npmjs.org/bn.js/-/bn.js-4.11.8.tgz", + "resolved": false, "integrity": "sha512-ItfYfPLkWHUjckQCk8xC+LwxgK8NYcXywGigJgSwOP8Y2iyWT4f2vsZnoOXTTbo+o5yXmIUJ4gn5538SO5S3gA==", "dev": true }, "brorand": { "version": "1.1.0", - "resolved": "https://registry.npmjs.org/brorand/-/brorand-1.1.0.tgz", + "resolved": false, "integrity": "sha1-EsJe/kCkXjwyPrhnWgoM5XsiNx8=", "dev": true }, "browserify-aes": { "version": "1.2.0", - "resolved": "https://registry.npmjs.org/browserify-aes/-/browserify-aes-1.2.0.tgz", + "resolved": false, "integrity": "sha512-+7CHXqGuspUn/Sl5aO7Ea0xWGAtETPXNSAjHo48JfLdPWcMng33Xe4znFvQweqc/uzk5zSOI3H52CYnjCfb5hA==", "dev": true, "requires": { @@ -5327,25 +5327,25 @@ }, "buffer-from": { "version": "1.1.1", - "resolved": "https://registry.npmjs.org/buffer-from/-/buffer-from-1.1.1.tgz", + "resolved": false, "integrity": "sha512-MQcXEUbCKtEo7bhqEs6560Hyd4XaovZlO/k9V3hjVUF/zwW7KBVdSK4gIt/bzwS9MbR5qob+F5jusZsb0YQK2A==", "dev": true }, "buffer-xor": { "version": "1.0.3", - "resolved": "https://registry.npmjs.org/buffer-xor/-/buffer-xor-1.0.3.tgz", + "resolved": false, "integrity": "sha1-JuYe0UIvtw3ULm42cp7VHYVf6Nk=", "dev": true }, "camelcase": { "version": "5.3.1", - "resolved": "https://registry.npmjs.org/camelcase/-/camelcase-5.3.1.tgz", + "resolved": false, "integrity": "sha512-L28STB170nwWS63UjtlEOE3dldQApaJXZkOI1uMFfzf3rRuPegHaHesyee+YxQ+W6SvRDQV6UrdOdRiR153wJg==", "dev": true }, "cipher-base": { "version": "1.0.4", - "resolved": "https://registry.npmjs.org/cipher-base/-/cipher-base-1.0.4.tgz", + "resolved": false, "integrity": "sha512-Kkht5ye6ZGmwv40uUDZztayT2ThLQGfnj/T71N/XzeZeo3nf8foyW7zGTsPYkEya3m5f3cAypH+qe7YOrM1U2Q==", "dev": true, "requires": { @@ -5355,7 +5355,7 @@ }, "cliui": { "version": "5.0.0", - "resolved": "https://registry.npmjs.org/cliui/-/cliui-5.0.0.tgz", + "resolved": false, "integrity": "sha512-PYeGSEmmHM6zvoef2w8TPzlrnNpXIjTipYK780YswmIP9vjxmd6Y2a3CB2Ks6/AU8NHjZugXvo8w3oWM2qnwXA==", "dev": true, "requires": { @@ -5366,7 +5366,7 @@ }, "color-convert": { "version": "1.9.3", - "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-1.9.3.tgz", + "resolved": false, "integrity": "sha512-QfAUtd+vFdAtFQcC8CCyYt1fYWxSqAiK2cSD6zDB8N3cpsEBAvRxp9zOGg6G/SHHJYAT88/az/IuDGALsNVbGg==", "dev": true, "requires": { @@ -5375,13 +5375,13 @@ }, "color-name": { "version": "1.1.3", - "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.3.tgz", + "resolved": false, "integrity": "sha1-p9BVi9icQveV3UIyj3QIMcpTvCU=", "dev": true }, "create-hash": { "version": "1.2.0", - "resolved": "https://registry.npmjs.org/create-hash/-/create-hash-1.2.0.tgz", + "resolved": false, "integrity": "sha512-z00bCGNHDG8mHAkP7CtT1qVu+bFQUPjYq/4Iv3C3kWjTFV10zIjfSoeqXo9Asws8gwSHDGj/hl2u4OGIjapeCg==", "dev": true, "requires": { @@ -5394,7 +5394,7 @@ }, "create-hmac": { "version": "1.1.7", - "resolved": "https://registry.npmjs.org/create-hmac/-/create-hmac-1.1.7.tgz", + "resolved": false, "integrity": "sha512-MJG9liiZ+ogc4TzUwuvbER1JRdgvUFSB5+VR/g5h82fGaIRWMWddtKBHi7/sVhfjQZ6SehlyhvQYrcYkaUIpLg==", "dev": true, "requires": { @@ -5408,7 +5408,7 @@ }, "cross-spawn": { "version": "6.0.5", - "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-6.0.5.tgz", + "resolved": false, "integrity": "sha512-eTVLrBSt7fjbDygz805pMnstIs2VTBNkRm0qxZd+M7A5XDdxVRWO5MxGBXZhjY4cqLYLdtrGqRf8mBPmzwSpWQ==", "dev": true, "requires": { @@ -5421,13 +5421,13 @@ }, "decamelize": { "version": "1.2.0", - "resolved": "https://registry.npmjs.org/decamelize/-/decamelize-1.2.0.tgz", + "resolved": false, "integrity": "sha1-9lNNFRSCabIDUue+4m9QH5oZEpA=", "dev": true }, "drbg.js": { "version": "1.0.1", - "resolved": "https://registry.npmjs.org/drbg.js/-/drbg.js-1.0.1.tgz", + "resolved": false, "integrity": "sha1-Pja2xCs3BDgjzbwzLVjzHiRFSAs=", "dev": true, "requires": { @@ -5438,7 +5438,7 @@ }, "elliptic": { "version": "6.5.0", - "resolved": "https://registry.npmjs.org/elliptic/-/elliptic-6.5.0.tgz", + "resolved": false, "integrity": "sha512-eFOJTMyCYb7xtE/caJ6JJu+bhi67WCYNbkGSknu20pmM8Ke/bqOfdnZWxyoGN26JgfxTbXrsCkEw4KheCT/KGg==", "dev": true, "requires": { @@ -5453,13 +5453,13 @@ }, "emoji-regex": { "version": "7.0.3", - "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-7.0.3.tgz", + "resolved": false, "integrity": "sha512-CwBLREIQ7LvYFB0WyRvwhq5N5qPhc6PMjD6bYggFlI5YyDgl+0vxq5VHbMOFqLg7hfWzmu8T5Z1QofhmTIhItA==", "dev": true }, "end-of-stream": { "version": "1.4.1", - "resolved": "https://registry.npmjs.org/end-of-stream/-/end-of-stream-1.4.1.tgz", + "resolved": false, "integrity": "sha512-1MkrZNvWTKCaigbn+W15elq2BB/L22nqrSY5DKlo3X6+vclJm8Bb5djXJBmEX6fS3+zCh/F4VBK5Z2KxJt4s2Q==", "dev": true, "requires": { @@ -5468,7 +5468,7 @@ }, "ethereumjs-util": { "version": "6.1.0", - "resolved": "https://registry.npmjs.org/ethereumjs-util/-/ethereumjs-util-6.1.0.tgz", + "resolved": false, "integrity": "sha512-URESKMFbDeJxnAxPppnk2fN6Y3BIatn9fwn76Lm8bQlt+s52TpG8dN9M66MLPuRAiAOIqL3dfwqWJf0sd0fL0Q==", "dev": true, "requires": { @@ -5483,7 +5483,7 @@ }, "ethjs-util": { "version": "0.1.6", - "resolved": "https://registry.npmjs.org/ethjs-util/-/ethjs-util-0.1.6.tgz", + "resolved": false, "integrity": "sha512-CUnVOQq7gSpDHZVVrQW8ExxUETWrnrvXYvYz55wOU8Uj4VCgw56XC2B/fVqQN+f7gmrnRHSLVnFAwsCuNwji8w==", "dev": true, "requires": { @@ -5493,7 +5493,7 @@ }, "evp_bytestokey": { "version": "1.0.3", - "resolved": "https://registry.npmjs.org/evp_bytestokey/-/evp_bytestokey-1.0.3.tgz", + "resolved": false, "integrity": "sha512-/f2Go4TognH/KvCISP7OUsHn85hT9nUkxxA9BEWxFn+Oj9o8ZNLm/40hdlgSLyuOimsrTKLUMEorQexp/aPQeA==", "dev": true, "requires": { @@ -5503,7 +5503,7 @@ }, "execa": { "version": "1.0.0", - "resolved": "https://registry.npmjs.org/execa/-/execa-1.0.0.tgz", + "resolved": false, "integrity": "sha512-adbxcyWV46qiHyvSp50TKt05tB4tK3HcmF7/nxfAdhnox83seTDbwnaqKO4sXRy7roHAIFqJP/Rw/AuEbX61LA==", "dev": true, "requires": { @@ -5518,13 +5518,13 @@ }, "file-uri-to-path": { "version": "1.0.0", - "resolved": "https://registry.npmjs.org/file-uri-to-path/-/file-uri-to-path-1.0.0.tgz", + "resolved": false, "integrity": "sha512-0Zt+s3L7Vf1biwWZ29aARiVYLx7iMGnEUl9x33fbB/j3jR81u/O2LbqK+Bm1CDSNDKVtJ/YjwY7TUd5SkeLQLw==", "dev": true }, "find-up": { "version": "3.0.0", - "resolved": "https://registry.npmjs.org/find-up/-/find-up-3.0.0.tgz", + "resolved": false, "integrity": "sha512-1yD6RmLI1XBfxugvORwlck6f75tYL+iR0jqwsOrOxMZyGYqUuDhJ0l4AXdO1iX/FTs9cBAMEk1gWSEx1kSbylg==", "dev": true, "requires": { @@ -5533,13 +5533,13 @@ }, "get-caller-file": { "version": "2.0.5", - "resolved": "https://registry.npmjs.org/get-caller-file/-/get-caller-file-2.0.5.tgz", + "resolved": false, "integrity": "sha512-DyFP3BM/3YHTQOCUL/w0OZHR0lpKeGrxotcHWcqNEdnltqFwXVfhEBQ94eIo34AfQpo0rGki4cyIiftY06h2Fg==", "dev": true }, "get-stream": { "version": "4.1.0", - "resolved": "https://registry.npmjs.org/get-stream/-/get-stream-4.1.0.tgz", + "resolved": false, "integrity": "sha512-GMat4EJ5161kIy2HevLlr4luNjBgvmj413KaQA7jt4V8B4RDsfpHk7WQ9GVqfYyyx8OS/L66Kox+rJRNklLK7w==", "dev": true, "requires": { @@ -5548,7 +5548,7 @@ }, "hash-base": { "version": "3.0.4", - "resolved": "https://registry.npmjs.org/hash-base/-/hash-base-3.0.4.tgz", + "resolved": false, "integrity": "sha1-X8hoaEfs1zSZQDMZprCj8/auSRg=", "dev": true, "requires": { @@ -5558,7 +5558,7 @@ }, "hash.js": { "version": "1.1.7", - "resolved": "https://registry.npmjs.org/hash.js/-/hash.js-1.1.7.tgz", + "resolved": false, "integrity": "sha512-taOaskGt4z4SOANNseOviYDvjEJinIkRgmp7LbKP2YTTmVxWBl87s/uzK9r+44BclBSp2X7K1hqeNfz9JbBeXA==", "dev": true, "requires": { @@ -5568,7 +5568,7 @@ }, "hmac-drbg": { "version": "1.0.1", - "resolved": "https://registry.npmjs.org/hmac-drbg/-/hmac-drbg-1.0.1.tgz", + "resolved": false, "integrity": "sha1-0nRXAQJabHdabFRXk+1QL8DGSaE=", "dev": true, "requires": { @@ -5579,43 +5579,43 @@ }, "inherits": { "version": "2.0.4", - "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz", + "resolved": false, "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==", "dev": true }, "invert-kv": { "version": "2.0.0", - "resolved": "https://registry.npmjs.org/invert-kv/-/invert-kv-2.0.0.tgz", + "resolved": false, "integrity": "sha512-wPVv/y/QQ/Uiirj/vh3oP+1Ww+AWehmi1g5fFWGPF6IpCBCDVrhgHRMvrLfdYcwDh3QJbGXDW4JAuzxElLSqKA==", "dev": true }, "is-fullwidth-code-point": { "version": "2.0.0", - "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-2.0.0.tgz", + "resolved": false, "integrity": "sha1-o7MKXE8ZkYMWeqq5O+764937ZU8=", "dev": true }, "is-hex-prefixed": { "version": "1.0.0", - "resolved": "https://registry.npmjs.org/is-hex-prefixed/-/is-hex-prefixed-1.0.0.tgz", + "resolved": false, "integrity": "sha1-fY035q135dEnFIkTxXPggtd39VQ=", "dev": true }, "is-stream": { "version": "1.1.0", - "resolved": "https://registry.npmjs.org/is-stream/-/is-stream-1.1.0.tgz", + "resolved": false, "integrity": "sha1-EtSj3U5o4Lec6428hBc66A2RykQ=", "dev": true }, "isexe": { "version": "2.0.0", - "resolved": "https://registry.npmjs.org/isexe/-/isexe-2.0.0.tgz", + "resolved": false, "integrity": "sha1-6PvzdNxVb/iUehDcsFctYz8s+hA=", "dev": true }, "keccak": { "version": "1.4.0", - "resolved": "https://registry.npmjs.org/keccak/-/keccak-1.4.0.tgz", + "resolved": false, "integrity": "sha512-eZVaCpblK5formjPjeTBik7TAg+pqnDrMHIffSvi9Lh7PQgM1+hSzakUeZFCk9DVVG0dacZJuaz2ntwlzZUIBw==", "dev": true, "requires": { @@ -5627,7 +5627,7 @@ }, "lcid": { "version": "2.0.0", - "resolved": "https://registry.npmjs.org/lcid/-/lcid-2.0.0.tgz", + "resolved": false, "integrity": "sha512-avPEb8P8EGnwXKClwsNUgryVjllcRqtMYa49NTsbQagYuT1DcXnl1915oxWjoyGrXR6zH/Y0Zc96xWsPcoDKeA==", "dev": true, "requires": { @@ -5636,7 +5636,7 @@ }, "locate-path": { "version": "3.0.0", - "resolved": "https://registry.npmjs.org/locate-path/-/locate-path-3.0.0.tgz", + "resolved": false, "integrity": "sha512-7AO748wWnIhNqAuaty2ZWHkQHRSNfPVIsPIfwEOWO22AmaoVrWavlOcMR5nzTLNYvp36X220/maaRsrec1G65A==", "dev": true, "requires": { @@ -5646,7 +5646,7 @@ }, "map-age-cleaner": { "version": "0.1.3", - "resolved": "https://registry.npmjs.org/map-age-cleaner/-/map-age-cleaner-0.1.3.tgz", + "resolved": false, "integrity": "sha512-bJzx6nMoP6PDLPBFmg7+xRKeFZvFboMrGlxmNj9ClvX53KrmvM5bXFXEWjbz4cz1AFn+jWJ9z/DJSz7hrs0w3w==", "dev": true, "requires": { @@ -5655,7 +5655,7 @@ }, "md5.js": { "version": "1.3.5", - "resolved": "https://registry.npmjs.org/md5.js/-/md5.js-1.3.5.tgz", + "resolved": false, "integrity": "sha512-xitP+WxNPcTTOgnTJcrhM0xvdPepipPSf3I8EIpGKeFLjt3PlJLIDG3u8EX53ZIubkb+5U2+3rELYpEhHhzdkg==", "dev": true, "requires": { @@ -5666,7 +5666,7 @@ }, "mem": { "version": "4.3.0", - "resolved": "https://registry.npmjs.org/mem/-/mem-4.3.0.tgz", + "resolved": false, "integrity": "sha512-qX2bG48pTqYRVmDB37rn/6PT7LcR8T7oAX3bf99u1Tt1nzxYfxkgqDwUwolPlXweM0XzBOBFzSx4kfp7KP1s/w==", "dev": true, "requires": { @@ -5677,37 +5677,37 @@ }, "mimic-fn": { "version": "2.1.0", - "resolved": "https://registry.npmjs.org/mimic-fn/-/mimic-fn-2.1.0.tgz", + "resolved": false, "integrity": "sha512-OqbOk5oEQeAZ8WXWydlu9HJjz9WVdEIvamMCcXmuqUYjTknH/sqsWvhQ3vgwKFRR1HpjvNBKQ37nbJgYzGqGcg==", "dev": true }, "minimalistic-assert": { "version": "1.0.1", - "resolved": "https://registry.npmjs.org/minimalistic-assert/-/minimalistic-assert-1.0.1.tgz", + "resolved": false, "integrity": "sha512-UtJcAD4yEaGtjPezWuO9wC4nwUnVH/8/Im3yEHQP4b67cXlD/Qr9hdITCU1xDbSEXg2XKNaP8jsReV7vQd00/A==", "dev": true }, "minimalistic-crypto-utils": { "version": "1.0.1", - "resolved": "https://registry.npmjs.org/minimalistic-crypto-utils/-/minimalistic-crypto-utils-1.0.1.tgz", + "resolved": false, "integrity": "sha1-9sAMHAsIIkblxNmd+4x8CDsrWCo=", "dev": true }, "nan": { "version": "2.14.0", - "resolved": "https://registry.npmjs.org/nan/-/nan-2.14.0.tgz", + "resolved": false, "integrity": "sha512-INOFj37C7k3AfaNTtX8RhsTw7qRy7eLET14cROi9+5HAVbbHuIWUHEauBv5qT4Av2tWasiTY1Jw6puUNqRJXQg==", "dev": true }, "nice-try": { "version": "1.0.5", - "resolved": "https://registry.npmjs.org/nice-try/-/nice-try-1.0.5.tgz", + "resolved": false, "integrity": "sha512-1nh45deeb5olNY7eX82BkPO7SSxR5SSYJiPTrTdFUVYwAl8CKMA5N9PjTYkHiRjisVcxcQ1HXdLhx2qxxJzLNQ==", "dev": true }, "npm-run-path": { "version": "2.0.2", - "resolved": "https://registry.npmjs.org/npm-run-path/-/npm-run-path-2.0.2.tgz", + "resolved": false, "integrity": "sha1-NakjLfo11wZ7TLLd8jV7GHFTbF8=", "dev": true, "requires": { @@ -5716,7 +5716,7 @@ }, "once": { "version": "1.4.0", - "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", + "resolved": false, "integrity": "sha1-WDsap3WWHUsROsF9nFC6753Xa9E=", "dev": true, "requires": { @@ -5725,7 +5725,7 @@ }, "os-locale": { "version": "3.1.0", - "resolved": "https://registry.npmjs.org/os-locale/-/os-locale-3.1.0.tgz", + "resolved": false, "integrity": "sha512-Z8l3R4wYWM40/52Z+S265okfFj8Kt2cC2MKY+xNi3kFs+XGI7WXu/I309QQQYbRW4ijiZ+yxs9pqEhJh0DqW3Q==", "dev": true, "requires": { @@ -5736,25 +5736,25 @@ }, "p-defer": { "version": "1.0.0", - "resolved": "https://registry.npmjs.org/p-defer/-/p-defer-1.0.0.tgz", + "resolved": false, "integrity": "sha1-n26xgvbJqozXQwBKfU+WsZaw+ww=", "dev": true }, "p-finally": { "version": "1.0.0", - "resolved": "https://registry.npmjs.org/p-finally/-/p-finally-1.0.0.tgz", + "resolved": false, "integrity": "sha1-P7z7FbiZpEEjs0ttzBi3JDNqLK4=", "dev": true }, "p-is-promise": { "version": "2.1.0", - "resolved": "https://registry.npmjs.org/p-is-promise/-/p-is-promise-2.1.0.tgz", + "resolved": false, "integrity": "sha512-Y3W0wlRPK8ZMRbNq97l4M5otioeA5lm1z7bkNkxCka8HSPjR0xRWmpCmc9utiaLP9Jb1eD8BgeIxTW4AIF45Pg==", "dev": true }, "p-limit": { "version": "2.2.0", - "resolved": "https://registry.npmjs.org/p-limit/-/p-limit-2.2.0.tgz", + "resolved": false, "integrity": "sha512-pZbTJpoUsCzV48Mc9Nh51VbwO0X9cuPFE8gYwx9BTCt9SF8/b7Zljd2fVgOxhIF/HDTKgpVzs+GPhyKfjLLFRQ==", "dev": true, "requires": { @@ -5763,7 +5763,7 @@ }, "p-locate": { "version": "3.0.0", - "resolved": "https://registry.npmjs.org/p-locate/-/p-locate-3.0.0.tgz", + "resolved": false, "integrity": "sha512-x+12w/To+4GFfgJhBEpiDcLozRJGegY+Ei7/z0tSLkMmxGZNybVMSfWj9aJn8Z5Fc7dBUNJOOVgPv2H7IwulSQ==", "dev": true, "requires": { @@ -5772,25 +5772,25 @@ }, "p-try": { "version": "2.2.0", - "resolved": "https://registry.npmjs.org/p-try/-/p-try-2.2.0.tgz", + "resolved": false, "integrity": "sha512-R4nPAVTAU0B9D35/Gk3uJf/7XYbQcyohSKdvAxIRSNghFl4e71hVoGnBNQz9cWaXxO2I10KTC+3jMdvvoKw6dQ==", "dev": true }, "path-exists": { "version": "3.0.0", - "resolved": "https://registry.npmjs.org/path-exists/-/path-exists-3.0.0.tgz", + "resolved": false, "integrity": "sha1-zg6+ql94yxiSXqfYENe1mwEP1RU=", "dev": true }, "path-key": { "version": "2.0.1", - "resolved": "https://registry.npmjs.org/path-key/-/path-key-2.0.1.tgz", + "resolved": false, "integrity": "sha1-QRyttXTFoUDTpLGRDUDYDMn0C0A=", "dev": true }, "pump": { "version": "3.0.0", - "resolved": "https://registry.npmjs.org/pump/-/pump-3.0.0.tgz", + "resolved": false, "integrity": "sha512-LwZy+p3SFs1Pytd/jYct4wpv49HiYCqd9Rlc5ZVdk0V+8Yzv6jR5Blk3TRmPL1ft69TxP0IMZGJ+WPFU2BFhww==", "dev": true, "requires": { @@ -5800,19 +5800,19 @@ }, "require-directory": { "version": "2.1.1", - "resolved": "https://registry.npmjs.org/require-directory/-/require-directory-2.1.1.tgz", + "resolved": false, "integrity": "sha1-jGStX9MNqxyXbiNE/+f3kqam30I=", "dev": true }, "require-main-filename": { "version": "2.0.0", - "resolved": "https://registry.npmjs.org/require-main-filename/-/require-main-filename-2.0.0.tgz", + "resolved": false, "integrity": "sha512-NKN5kMDylKuldxYLSUfrbo5Tuzh4hd+2E8NPPX02mZtn1VuREQToYe/ZdlJy+J3uCpfaiGF05e7B8W0iXbQHmg==", "dev": true }, "ripemd160": { "version": "2.0.2", - "resolved": "https://registry.npmjs.org/ripemd160/-/ripemd160-2.0.2.tgz", + "resolved": false, "integrity": "sha512-ii4iagi25WusVoiC4B4lq7pbXfAp3D9v5CwfkY33vffw2+pkDjY1D8GaN7spsxvCSx8dkPqOZCEZyfxcmJG2IA==", "dev": true, "requires": { @@ -5822,7 +5822,7 @@ }, "rlp": { "version": "2.2.3", - "resolved": "https://registry.npmjs.org/rlp/-/rlp-2.2.3.tgz", + "resolved": false, "integrity": "sha512-l6YVrI7+d2vpW6D6rS05x2Xrmq8oW7v3pieZOJKBEdjuTF4Kz/iwk55Zyh1Zaz+KOB2kC8+2jZlp2u9L4tTzCQ==", "dev": true, "requires": { @@ -5832,13 +5832,13 @@ }, "safe-buffer": { "version": "5.2.0", - "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.0.tgz", + "resolved": false, "integrity": "sha512-fZEwUGbVl7kouZs1jCdMLdt95hdIv0ZeHg6L7qPeciMZhZ+/gdesW4wgTARkrFWEpspjEATAzUGPG8N2jJiwbg==", "dev": true }, "secp256k1": { "version": "3.7.1", - "resolved": "https://registry.npmjs.org/secp256k1/-/secp256k1-3.7.1.tgz", + "resolved": false, "integrity": "sha512-1cf8sbnRreXrQFdH6qsg2H71Xw91fCCS9Yp021GnUNJzWJS/py96fS4lHbnTnouLp08Xj6jBoBB6V78Tdbdu5g==", "dev": true, "requires": { @@ -5854,19 +5854,19 @@ }, "semver": { "version": "5.7.0", - "resolved": "https://registry.npmjs.org/semver/-/semver-5.7.0.tgz", + "resolved": false, "integrity": "sha512-Ya52jSX2u7QKghxeoFGpLwCtGlt7j0oY9DYb5apt9nPlJ42ID+ulTXESnt/qAQcoSERyZ5sl3LDIOw0nAn/5DA==", "dev": true }, "set-blocking": { "version": "2.0.0", - "resolved": "https://registry.npmjs.org/set-blocking/-/set-blocking-2.0.0.tgz", + "resolved": false, "integrity": "sha1-BF+XgtARrppoA93TgrJDkrPYkPc=", "dev": true }, "sha.js": { "version": "2.4.11", - "resolved": "https://registry.npmjs.org/sha.js/-/sha.js-2.4.11.tgz", + "resolved": false, "integrity": "sha512-QMEp5B7cftE7APOjk5Y6xgrbWu+WkLVQwk8JNjZ8nKRciZaByEW6MubieAiToS7+dwvrjGhH8jRXz3MVd0AYqQ==", "dev": true, "requires": { @@ -5876,7 +5876,7 @@ }, "shebang-command": { "version": "1.2.0", - "resolved": "https://registry.npmjs.org/shebang-command/-/shebang-command-1.2.0.tgz", + "resolved": false, "integrity": "sha1-RKrGW2lbAzmJaMOfNj/uXer98eo=", "dev": true, "requires": { @@ -5885,25 +5885,25 @@ }, "shebang-regex": { "version": "1.0.0", - "resolved": "https://registry.npmjs.org/shebang-regex/-/shebang-regex-1.0.0.tgz", + "resolved": false, "integrity": "sha1-2kL0l0DAtC2yypcoVxyxkMmO/qM=", "dev": true }, "signal-exit": { "version": "3.0.2", - "resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-3.0.2.tgz", + "resolved": false, "integrity": "sha1-tf3AjxKH6hF4Yo5BXiUTK3NkbG0=", "dev": true }, "source-map": { "version": "0.6.1", - "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz", + "resolved": false, "integrity": "sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==", "dev": true }, "source-map-support": { "version": "0.5.12", - "resolved": "https://registry.npmjs.org/source-map-support/-/source-map-support-0.5.12.tgz", + "resolved": false, "integrity": "sha512-4h2Pbvyy15EE02G+JOZpUCmqWJuqrs+sEkzewTm++BPi7Hvn/HwcqLAcNxYAyI0x13CpPPn+kMjl+hplXMHITQ==", "dev": true, "requires": { @@ -5913,7 +5913,7 @@ }, "string-width": { "version": "3.1.0", - "resolved": "https://registry.npmjs.org/string-width/-/string-width-3.1.0.tgz", + "resolved": false, "integrity": "sha512-vafcv6KjVZKSgz06oM/H6GDBrAtz8vdhQakGjFIvNrHA6y3HCF1CInLy+QLq8dTJPQ1b+KDUqDFctkdRW44e1w==", "dev": true, "requires": { @@ -5924,7 +5924,7 @@ }, "strip-ansi": { "version": "5.2.0", - "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-5.2.0.tgz", + "resolved": false, "integrity": "sha512-DuRs1gKbBqsMKIZlrffwlug8MHkcnpjs5VPmL1PAh+mA30U0DTotfDZ0d2UUsXpPmPmMMJ6W773MaA3J+lbiWA==", "dev": true, "requires": { @@ -5933,13 +5933,13 @@ }, "strip-eof": { "version": "1.0.0", - "resolved": "https://registry.npmjs.org/strip-eof/-/strip-eof-1.0.0.tgz", + "resolved": false, "integrity": "sha1-u0P/VZim6wXYm1n80SnJgzE2Br8=", "dev": true }, "strip-hex-prefix": { "version": "1.0.0", - "resolved": "https://registry.npmjs.org/strip-hex-prefix/-/strip-hex-prefix-1.0.0.tgz", + "resolved": false, "integrity": "sha1-DF8VX+8RUTczd96du1iNoFUA428=", "dev": true, "requires": { @@ -5948,7 +5948,7 @@ }, "which": { "version": "1.3.1", - "resolved": "https://registry.npmjs.org/which/-/which-1.3.1.tgz", + "resolved": false, "integrity": "sha512-HxJdYWq1MTIQbJ3nw0cqssHoTNU267KlrDuGZ1WYlxDStUtKUhOaJmh112/TZmHxxUfuJqPXSOm7tDyas0OSIQ==", "dev": true, "requires": { @@ -5957,13 +5957,13 @@ }, "which-module": { "version": "2.0.0", - "resolved": "https://registry.npmjs.org/which-module/-/which-module-2.0.0.tgz", + "resolved": false, "integrity": "sha1-2e8H3Od7mQK4o6j6SzHD4/fm6Ho=", "dev": true }, "wrap-ansi": { "version": "5.1.0", - "resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-5.1.0.tgz", + "resolved": false, "integrity": "sha512-QC1/iN/2/RPVJ5jYK8BGttj5z83LmSKmvbvrXPNCLZSEb32KKVDJDl/MOt2N01qU2H/FkzEa9PKto1BqDjtd7Q==", "dev": true, "requires": { @@ -5974,19 +5974,19 @@ }, "wrappy": { "version": "1.0.2", - "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", + "resolved": false, "integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=", "dev": true }, "y18n": { "version": "4.0.0", - "resolved": "https://registry.npmjs.org/y18n/-/y18n-4.0.0.tgz", + "resolved": false, "integrity": "sha512-r9S/ZyXu/Xu9q1tYlpsLIsa3EeLXXk0VwlxqTcFRfg9EhMW+17kbt9G0NrgCmhGb5vT2hyhJZLfDGx+7+5Uj/w==", "dev": true }, "yargs": { "version": "13.2.4", - "resolved": "https://registry.npmjs.org/yargs/-/yargs-13.2.4.tgz", + "resolved": false, "integrity": "sha512-HG/DWAJa1PAnHT9JAhNa8AbAv3FPaiLzioSjCcmuXXhP8MlpHO5vwls4g4j6n30Z74GVQj8Xa62dWVx1QCGklg==", "dev": true, "requires": { @@ -6005,7 +6005,7 @@ }, "yargs-parser": { "version": "13.1.1", - "resolved": "https://registry.npmjs.org/yargs-parser/-/yargs-parser-13.1.1.tgz", + "resolved": false, "integrity": "sha512-oVAVsHz6uFrg3XQheFII8ESO2ssAf9luWuAd6Wexsu4F3OtIW0o8IribPXYrD4WC24LWtPrJlGy87y5udK+dxQ==", "dev": true, "requires": { From 08c8482cc1b36555e010139e9d18f22e1a6bf578 Mon Sep 17 00:00:00 2001 From: emilio Date: Sat, 31 Oct 2020 12:33:26 +0100 Subject: [PATCH 29/35] Fixed conditions, removed console.log --- .../lendingpool/LendingPoolConfigurator.sol | 22 +++++-------------- 1 file changed, 5 insertions(+), 17 deletions(-) diff --git a/contracts/lendingpool/LendingPoolConfigurator.sol b/contracts/lendingpool/LendingPoolConfigurator.sol index 64d9ca79..4a4c2c6e 100644 --- a/contracts/lendingpool/LendingPoolConfigurator.sol +++ b/contracts/lendingpool/LendingPoolConfigurator.sol @@ -15,7 +15,6 @@ import {IERC20Detailed} from '../dependencies/openzeppelin/contracts/IERC20Detai import {Errors} from '../libraries/helpers/Errors.sol'; import {PercentageMath} from '../libraries/math/PercentageMath.sol'; import {ReserveLogic} from '../libraries/logic/ReserveLogic.sol'; -import '@nomiclabs/buidler/console.sol'; /** * @title LendingPoolConfigurator contract @@ -367,8 +366,6 @@ contract LendingPoolConfigurator is VersionedInitializable { uint256 liquidationThreshold, uint256 liquidationBonus ) external onlyAaveAdmin { - console.log('Liq threshold %s, liq bonus %s', liquidationThreshold, liquidationBonus); - ReserveConfiguration.Map memory currentConfig = pool.getConfiguration(asset); //validation of the parameters: the LTV can @@ -376,21 +373,15 @@ contract LendingPoolConfigurator is VersionedInitializable { //(otherwise a loan against the asset would cause instantaneous liquidation) require(ltv <= liquidationThreshold, Errors.INVALID_CONFIGURATION); - console.log('Liq threshold %s, liq bonus %s', liquidationThreshold, liquidationBonus); - - if (liquidationThreshold > 0) { + if (liquidationThreshold != 0) { //liquidation bonus must be bigger than 100.00%, otherwise the liquidator would receive less - //collateral than needed to repay the debt + //collateral than needed to cover the debt require(liquidationBonus > PercentageMath.PERCENTAGE_FACTOR, Errors.INVALID_CONFIGURATION); } else { require(liquidationBonus == 0, Errors.INVALID_CONFIGURATION); - } - - //if the liquidation threshold is being set to 0, - // the reserve is being disabled as collateral. To do so, - //we need to ensure no liquidity is deposited - if (liquidationThreshold == 0) { - console.log('Checking no liquidity for the asset'); + //if the liquidation threshold is being set to 0, + // the reserve is being disabled as collateral. To do so, + //we need to ensure no liquidity is deposited _checkNoLiquidity(asset); } @@ -635,9 +626,6 @@ contract LendingPoolConfigurator is VersionedInitializable { uint256 availableLiquidity = IERC20Detailed(asset).balanceOf(reserveData.aTokenAddress); - console.log('Available liquidity %s', availableLiquidity); - console.log('liq rate %s', reserveData.currentLiquidityRate); - require( availableLiquidity == 0 && reserveData.currentLiquidityRate == 0, Errors.RESERVE_LIQUIDITY_NOT_0 From f0a9d18f512135ce47dc8a31a558c44657ca7947 Mon Sep 17 00:00:00 2001 From: emilio Date: Sat, 31 Oct 2020 12:37:48 +0100 Subject: [PATCH 30/35] fixed gas reporter import --- buidler.config.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/buidler.config.ts b/buidler.config.ts index b487498a..79b1d670 100644 --- a/buidler.config.ts +++ b/buidler.config.ts @@ -11,7 +11,7 @@ usePlugin('buidler-typechain'); usePlugin('solidity-coverage'); usePlugin('@nomiclabs/buidler-waffle'); usePlugin('@nomiclabs/buidler-etherscan'); -//usePlugin('buidler-gas-reporter'); +usePlugin('buidler-gas-reporter'); const SKIP_LOAD = process.env.SKIP_LOAD === 'true'; const DEFAULT_BLOCK_GAS_LIMIT = 12000000; From 72fe4657828222c8204887d510760de0b6683aa2 Mon Sep 17 00:00:00 2001 From: emilio Date: Sat, 31 Oct 2020 12:42:14 +0100 Subject: [PATCH 31/35] fixed test --- test/configurator.spec.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/test/configurator.spec.ts b/test/configurator.spec.ts index aa3b7fe0..419577ee 100644 --- a/test/configurator.spec.ts +++ b/test/configurator.spec.ts @@ -241,7 +241,6 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => { }); it('Deactivates the ETH reserve as collateral', async () => { - const {configurator, helpersContract, weth} = testEnv; await configurator.configureReserveAsCollateral(weth.address, 0, 0, 0); @@ -295,12 +294,12 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => { expect(reserveFactor).to.be.equal(0); }); - it('Check the onlyAaveAdmin on enableReserveAsCollateral ', async () => { + it('Check the onlyAaveAdmin on configureReserveAsCollateral ', async () => { const {configurator, users, weth} = testEnv; await expect( configurator .connect(users[2].signer) - .configureReserveAsCollateral(weth.address, '75', '80', '105'), + .configureReserveAsCollateral(weth.address, '7500', '8000', '10500'), CALLER_NOT_AAVE_ADMIN ).to.be.revertedWith(CALLER_NOT_AAVE_ADMIN); }); From 05d426645dc2b57b3fa9767cec52578d151c2fb5 Mon Sep 17 00:00:00 2001 From: emilio Date: Sat, 31 Oct 2020 13:47:16 +0100 Subject: [PATCH 32/35] Changed freezed to frozen --- .../lendingpool/LendingPoolConfigurator.sol | 14 ++++++------- .../configuration/ReserveConfiguration.sol | 4 ++-- contracts/libraries/helpers/Errors.sol | 4 ++-- contracts/libraries/logic/ValidationLogic.sol | 21 ++++++++----------- helpers/types.ts | 2 +- 5 files changed, 21 insertions(+), 24 deletions(-) diff --git a/contracts/lendingpool/LendingPoolConfigurator.sol b/contracts/lendingpool/LendingPoolConfigurator.sol index b02b11f5..b442ce35 100644 --- a/contracts/lendingpool/LendingPoolConfigurator.sol +++ b/contracts/lendingpool/LendingPoolConfigurator.sol @@ -100,16 +100,16 @@ contract LendingPoolConfigurator is VersionedInitializable { event ReserveDeactivated(address indexed asset); /** - * @dev emitted when a reserve is freezed + * @dev emitted when a reserve is frozen * @param asset the address of the reserve **/ - event ReserveFreezed(address indexed asset); + event ReserveFrozen(address indexed asset); /** - * @dev emitted when a reserve is unfreezed + * @dev emitted when a reserve is unfrozen * @param asset the address of the reserve **/ - event ReserveUnfreezed(address indexed asset); + event ReserveUnfrozen(address indexed asset); /** * @dev emitted when a reserve loan to value is updated @@ -462,7 +462,7 @@ contract LendingPoolConfigurator is VersionedInitializable { } /** - * @dev freezes a reserve. A freezed reserve doesn't accept any new deposit, borrow or rate swap, but can accept repayments, liquidations, rate rebalances and redeems + * @dev freezes a reserve. A frozen reserve doesn't accept any new deposit, borrow or rate swap, but can accept repayments, liquidations, rate rebalances and redeems * @param asset the address of the reserve **/ function freezeReserve(address asset) external onlyAaveAdmin { @@ -472,7 +472,7 @@ contract LendingPoolConfigurator is VersionedInitializable { pool.setConfiguration(asset, currentConfig.data); - emit ReserveFreezed(asset); + emit ReserveFrozen(asset); } /** @@ -486,7 +486,7 @@ contract LendingPoolConfigurator is VersionedInitializable { pool.setConfiguration(asset, currentConfig.data); - emit ReserveUnfreezed(asset); + emit ReserveUnfrozen(asset); } /** diff --git a/contracts/libraries/configuration/ReserveConfiguration.sol b/contracts/libraries/configuration/ReserveConfiguration.sol index fcbafc2b..7951d91a 100644 --- a/contracts/libraries/configuration/ReserveConfiguration.sol +++ b/contracts/libraries/configuration/ReserveConfiguration.sol @@ -259,7 +259,7 @@ library ReserveConfiguration { /** * @dev gets the configuration flags of the reserve * @param self the reserve configuration - * @return the state flags representing active, freezed, borrowing enabled, stableRateBorrowing enabled + * @return the state flags representing active, frozen, borrowing enabled, stableRateBorrowing enabled **/ function getFlags(ReserveConfiguration.Map storage self) internal @@ -336,7 +336,7 @@ library ReserveConfiguration { /** * @dev gets the configuration flags of the reserve from a memory object * @param self the reserve configuration - * @return the state flags representing active, freezed, borrowing enabled, stableRateBorrowing enabled + * @return the state flags representing active, frozen, borrowing enabled, stableRateBorrowing enabled **/ function getFlagsMemory(ReserveConfiguration.Map memory self) internal diff --git a/contracts/libraries/helpers/Errors.sol b/contracts/libraries/helpers/Errors.sol index 7345c5c3..5fcc7cb3 100644 --- a/contracts/libraries/helpers/Errors.sol +++ b/contracts/libraries/helpers/Errors.sol @@ -19,7 +19,7 @@ pragma solidity ^0.6.8; library Errors { 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_RESERVE_FROZEN = '3'; // 'Action cannot be performed because the reserve is frozen' string public constant VL_CURRENT_AVAILABLE_LIQUIDITY_NOT_ENOUGH = '4'; // 'The current liquidity is not enough' string public constant VL_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.' @@ -102,6 +102,6 @@ library Errors { NO_ACTIVE_RESERVE, HEALTH_FACTOR_LOWER_THAN_LIQUIDATION_THRESHOLD, INVALID_EQUAL_ASSETS_TO_SWAP, - NO_UNFREEZED_RESERVE + FROZEN_RESERVE } } diff --git a/contracts/libraries/logic/ValidationLogic.sol b/contracts/libraries/logic/ValidationLogic.sol index 657b1d63..29595068 100644 --- a/contracts/libraries/logic/ValidationLogic.sol +++ b/contracts/libraries/logic/ValidationLogic.sol @@ -34,11 +34,11 @@ library ValidationLogic { * @param amount the amount to be deposited */ function validateDeposit(ReserveLogic.ReserveData storage reserve, uint256 amount) external view { - (bool isActive, bool isFreezed, , ) = reserve.configuration.getFlags(); + (bool isActive, bool isFrozen, , ) = reserve.configuration.getFlags(); require(amount > 0, Errors.VL_AMOUNT_NOT_GREATER_THAN_0); require(isActive, Errors.VL_NO_ACTIVE_RESERVE); - require(!isFreezed, Errors.VL_NO_UNFREEZED_RESERVE); + require(!isFrozen, Errors.VL_RESERVE_FROZEN); } /** @@ -97,7 +97,7 @@ library ValidationLogic { ReserveLogic.InterestRateMode rateMode; bool healthFactorBelowThreshold; bool isActive; - bool isFreezed; + bool isFrozen; bool borrowingEnabled; bool stableRateBorrowingEnabled; } @@ -133,15 +133,12 @@ library ValidationLogic { ) external view { ValidateBorrowLocalVars memory vars; - ( - vars.isActive, - vars.isFreezed, - vars.borrowingEnabled, - vars.stableRateBorrowingEnabled - ) = reserve.configuration.getFlags(); + (vars.isActive, vars.isFrozen, vars.borrowingEnabled, vars.stableRateBorrowingEnabled) = reserve + .configuration + .getFlags(); require(vars.isActive, Errors.VL_NO_ACTIVE_RESERVE); - require(!vars.isFreezed, Errors.VL_NO_UNFREEZED_RESERVE); + require(!vars.isFrozen, Errors.VL_RESERVE_FROZEN); require(vars.borrowingEnabled, Errors.VL_BORROWING_NOT_ENABLED); @@ -266,10 +263,10 @@ library ValidationLogic { uint256 variableDebt, ReserveLogic.InterestRateMode currentRateMode ) external view { - (bool isActive, bool isFreezed, , bool stableRateEnabled) = reserve.configuration.getFlags(); + (bool isActive, bool isFrozen, , bool stableRateEnabled) = reserve.configuration.getFlags(); require(isActive, Errors.VL_NO_ACTIVE_RESERVE); - require(!isFreezed, Errors.VL_NO_UNFREEZED_RESERVE); + require(!isFrozen, Errors.VL_RESERVE_FROZEN); if (currentRateMode == ReserveLogic.InterestRateMode.STABLE) { require(stableDebt > 0, Errors.VL_NO_STABLE_RATE_LOAN_IN_RESERVE); diff --git a/helpers/types.ts b/helpers/types.ts index 8e506fb7..5d5b079d 100644 --- a/helpers/types.ts +++ b/helpers/types.ts @@ -74,7 +74,7 @@ export enum eContractid { export enum ProtocolErrors { 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_RESERVE_FROZEN = '3', // 'Action requires an unfrozen 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.' From 07429b0a57161958dfbc7ef5f67598eb04c205fd Mon Sep 17 00:00:00 2001 From: emilio Date: Sat, 31 Oct 2020 13:55:19 +0100 Subject: [PATCH 33/35] Fixed P_IS_PAUSED --- contracts/lendingpool/LendingPool.sol | 2 +- contracts/libraries/helpers/Errors.sol | 2 +- helpers/types.ts | 2 +- test/liquidation-atoken.spec.ts | 2 +- test/pausable-functions.spec.ts | 24 ++++++++++++------------ 5 files changed, 16 insertions(+), 16 deletions(-) diff --git a/contracts/lendingpool/LendingPool.sol b/contracts/lendingpool/LendingPool.sol index 4057f3b9..23bf3e94 100644 --- a/contracts/lendingpool/LendingPool.sol +++ b/contracts/lendingpool/LendingPool.sol @@ -64,7 +64,7 @@ contract LendingPool is VersionedInitializable, ILendingPool, LendingPoolStorage * - The contract must not be paused. */ function _whenNotPaused() internal view { - require(!_paused, Errors.P_IS_PAUSED); + require(!_paused, Errors.LP_IS_PAUSED); } function getRevision() internal override pure returns (uint256) { diff --git a/contracts/libraries/helpers/Errors.sol b/contracts/libraries/helpers/Errors.sol index 5fcc7cb3..a2fea46a 100644 --- a/contracts/libraries/helpers/Errors.sol +++ b/contracts/libraries/helpers/Errors.sol @@ -80,7 +80,7 @@ library Errors { 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_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'; diff --git a/helpers/types.ts b/helpers/types.ts index 5d5b079d..b8c732fd 100644 --- a/helpers/types.ts +++ b/helpers/types.ts @@ -135,7 +135,7 @@ export enum ProtocolErrors { 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_IS_PAUSED = '64', // 'Pool is paused' LP_NO_MORE_RESERVES_ALLOWED = '65', LP_INVALID_FLASH_LOAN_EXECUTOR_RETURN = '66', RC_INVALID_LTV = '67', diff --git a/test/liquidation-atoken.spec.ts b/test/liquidation-atoken.spec.ts index 32e2b83c..8d4ba803 100644 --- a/test/liquidation-atoken.spec.ts +++ b/test/liquidation-atoken.spec.ts @@ -21,7 +21,7 @@ makeSuite('LendingPool liquidation - liquidator receiving aToken', (testEnv) => INVALID_HF, LPCM_SPECIFIED_CURRENCY_NOT_BORROWED_BY_USER, LPCM_COLLATERAL_CANNOT_BE_LIQUIDATED, - P_IS_PAUSED, + LP_IS_PAUSED, } = ProtocolErrors; it('LIQUIDATION - Deposits WETH, borrows DAI/Check liquidation fails because health factor is above 1', async () => { diff --git a/test/pausable-functions.spec.ts b/test/pausable-functions.spec.ts index 63334497..9c7f6473 100644 --- a/test/pausable-functions.spec.ts +++ b/test/pausable-functions.spec.ts @@ -13,7 +13,7 @@ makeSuite('Pausable Pool', (testEnv: TestEnv) => { let _mockFlashLoanReceiver = {} as MockFlashLoanReceiver; const { - P_IS_PAUSED, + LP_IS_PAUSED, INVALID_FROM_BALANCE_AFTER_TRANSFER, INVALID_TO_BALANCE_AFTER_TRANSFER, } = ProtocolErrors; @@ -44,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(P_IS_PAUSED); + ).to.revertedWith(LP_IS_PAUSED); const pausedFromBalance = await aDai.balanceOf(users[0].address); const pausedToBalance = await aDai.balanceOf(users[1].address); @@ -91,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(P_IS_PAUSED); + ).to.revertedWith(LP_IS_PAUSED); // Configurator unpauses the pool await configurator.setPoolPause(false); @@ -116,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(P_IS_PAUSED); + ).to.revertedWith(LP_IS_PAUSED); // Configurator unpauses the pool await configurator.setPoolPause(false); @@ -133,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(P_IS_PAUSED); + ).revertedWith(LP_IS_PAUSED); // Unpause the pool await configurator.setPoolPause(false); @@ -149,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(P_IS_PAUSED); + ).revertedWith(LP_IS_PAUSED); // Unpause the pool await configurator.setPoolPause(false); @@ -164,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( - P_IS_PAUSED + LP_IS_PAUSED ); // Unpause the pool @@ -195,7 +195,7 @@ makeSuite('Pausable Pool', (testEnv: TestEnv) => { '0x10', '0' ) - ).revertedWith(P_IS_PAUSED); + ).revertedWith(LP_IS_PAUSED); // Unpause pool await configurator.setPoolPause(false); @@ -276,7 +276,7 @@ makeSuite('Pausable Pool', (testEnv: TestEnv) => { // Do liquidation expect( pool.liquidationCall(weth.address, usdc.address, borrower.address, amountToLiquidate, true) - ).revertedWith(P_IS_PAUSED); + ).revertedWith(LP_IS_PAUSED); // Unpause pool await configurator.setPoolPause(false); @@ -305,7 +305,7 @@ makeSuite('Pausable Pool', (testEnv: TestEnv) => { // Try to repay await expect( pool.connect(user.signer).swapBorrowRateMode(usdc.address, RateMode.Stable) - ).revertedWith(P_IS_PAUSED); + ).revertedWith(LP_IS_PAUSED); // Unpause pool await configurator.setPoolPause(false); @@ -319,7 +319,7 @@ makeSuite('Pausable Pool', (testEnv: TestEnv) => { await expect( pool.connect(user.signer).rebalanceStableBorrowRate(dai.address, user.address) - ).revertedWith(P_IS_PAUSED); + ).revertedWith(LP_IS_PAUSED); // Unpause pool await configurator.setPoolPause(false); @@ -339,7 +339,7 @@ makeSuite('Pausable Pool', (testEnv: TestEnv) => { await expect( pool.connect(user.signer).setUserUseReserveAsCollateral(weth.address, false) - ).revertedWith(P_IS_PAUSED); + ).revertedWith(LP_IS_PAUSED); // Unpause pool await configurator.setPoolPause(false); From 5d25b362ca92f8077f92d25722aa04ec5bf0a8bb Mon Sep 17 00:00:00 2001 From: eboado Date: Sun, 1 Nov 2020 08:53:33 +0100 Subject: [PATCH 34/35] - Removed unused _flashLiquidationLocked from LendingPoolStorage. --- contracts/lendingpool/LendingPoolStorage.sol | 1 - 1 file changed, 1 deletion(-) diff --git a/contracts/lendingpool/LendingPoolStorage.sol b/contracts/lendingpool/LendingPoolStorage.sol index 1def3b12..ceeadd39 100644 --- a/contracts/lendingpool/LendingPoolStorage.sol +++ b/contracts/lendingpool/LendingPoolStorage.sol @@ -23,6 +23,5 @@ contract LendingPoolStorage { uint256 internal _reservesCount; - bool internal _flashLiquidationLocked; bool internal _paused; } From 860402a94cb9d03b9e0cd66ed89d641ee4a9f021 Mon Sep 17 00:00:00 2001 From: emilio Date: Mon, 2 Nov 2020 09:17:48 +0100 Subject: [PATCH 35/35] updated comment --- contracts/tokenization/AToken.sol | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contracts/tokenization/AToken.sol b/contracts/tokenization/AToken.sol index 0454f908..a6c1f00b 100644 --- a/contracts/tokenization/AToken.sol +++ b/contracts/tokenization/AToken.sol @@ -13,7 +13,7 @@ import {SafeERC20} from '../dependencies/openzeppelin/contracts/SafeERC20.sol'; /** * @title Aave ERC20 AToken * - * @dev Implementation of the interest bearing token for the DLP protocol. + * @dev Implementation of the interest bearing token for the Aave protocol. * @author Aave */ contract AToken is VersionedInitializable, IncentivizedERC20, IAToken {