diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index b012440d..45329d30 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,5 +1,22 @@ stages: - checks + - prepare + - publish + +variables: + IMAGE: ${CI_REGISTRY_IMAGE}:${CI_COMMIT_SHA} + +lint: + stage: checks + tags: + - aave-build-runner + before_script: + - docker-compose -p ${CI_JOB_ID} -f docker-compose.test.yml build + script: + - docker-compose -p ${CI_JOB_ID} -f docker-compose.test.yml run contracts-env npm run prettier:check + after_script: + - docker-compose -p ${CI_JOB_ID} -f docker-compose.test.yml run contracts-env npm run ci:clean + - docker-compose -p ${CI_JOB_ID} -f docker-compose.test.yml down test: stage: checks @@ -12,7 +29,9 @@ test: after_script: - docker-compose -p ${CI_JOB_ID} -f docker-compose.test.yml run contracts-env npm run ci:clean - docker-compose -p ${CI_JOB_ID} -f docker-compose.test.yml down - + only: + - master + - merge_requests deploy-mainnet-fork: tags: - aave-build-runner @@ -24,6 +43,9 @@ deploy-mainnet-fork: after_script: - docker-compose -p ${CI_JOB_ID} -f docker-compose.test.yml run contracts-env npm run ci:clean - docker-compose -p ${CI_JOB_ID} -f docker-compose.test.yml down + only: + - master + - merge_requests certora-test: stage: checks @@ -40,3 +62,31 @@ certora-test: - certoraRun specs/harness/StableDebtTokenHarness.sol:StableDebtTokenHarness --solc_args "['--optimize']" --verify StableDebtTokenHarness:specs/StableDebtToken.spec --settings -assumeUnwindCond,-b=4 --cache StableDebtToken --cloud - certoraRun specs/harness/UserConfigurationHarness.sol --verify UserConfigurationHarness:specs/UserConfiguration.spec --solc_args "['--optimize']" --settings -useBitVectorTheory --cache UserConfiguration --cloud - certoraRun contracts/protocol/tokenization/VariableDebtToken.sol:VariableDebtToken specs/harness/LendingPoolHarnessForVariableDebtToken.sol --solc_args "['--optimize']" --link VariableDebtToken:POOL=LendingPoolHarnessForVariableDebtToken --verify VariableDebtToken:specs/VariableDebtToken.spec --settings -assumeUnwindCond,-useNonLinearArithmetic,-b=4 --cache VariableDebtToken --cloud + only: + - master + - merge_requests + +prepare: + stage: prepare + tags: + - docker-builder + script: + - docker build -t ${IMAGE} . + - docker login -u gitlab-ci-token -p $CI_BUILD_TOKEN $CI_REGISTRY + - docker push ${IMAGE} + only: + - master + +publish: + image: ${IMAGE} + tags: + - docker + stage: publish + script: + - npm ci + - echo //registry.npmjs.org/:_authToken=${NPM_V2_PACKAGES_TOKEN} > .npmrc + - npm run compile + - ${VERSION} + - npm publish --access public + only: + - master diff --git a/README.md b/README.md index aba2356e..739ef23c 100644 --- a/README.md +++ b/README.md @@ -39,6 +39,37 @@ A more detailed and technical description of the protocol can be found in this r You can join at the [Discord](http://aave.com/discord) channel or at the [Governance Forum](https://governance.aave.com/) for asking questions about the protocol or talk about Aave with other peers. +## Getting Started + +You can install `@aave/protocol-v2` as an NPM package in your Hardhat, Buidler or Truffle project to import the contracts and interfaces: + +`npm install @aave/protocol-v2` + +Import at Solidity files: + +``` +import {ILendingPool} from "@aave/protocol-v2/contracts/interfaces/ILendingPool.sol"; + +contract Misc { + + function deposit(address pool, address token, address user, uint256 amount) { + ILendingPool(pool).deposit(token, amount, user, '0'); + {...} + } +} +``` + +The JSON artifacts with the ABI and Bytecode are also included into the bundled NPM package at `artifacts/` directory. + +Import JSON file via Node JS `require`: + +``` +const LendingPoolV2Artifact = require('@aave/protocol-v2/artifacts/contracts/protocol/lendingpool/LendingPool.sol/LendingPool.json'); + +// Log the ABI into console +console.log(LendingPoolV2Artifact.abi) +``` + ## Setup The repository uses Docker Compose to manage sensitive keys and load the configuration. Prior any action like test or deploy, you must run `docker-compose up` to start the `contracts-env` container, and then connect to the container console via `docker-compose exec contracts-env bash`. diff --git a/contracts/adapters/BaseUniswapAdapter.sol b/contracts/adapters/BaseUniswapAdapter.sol index 64b5e9ce..a36bfe2f 100644 --- a/contracts/adapters/BaseUniswapAdapter.sol +++ b/contracts/adapters/BaseUniswapAdapter.sol @@ -346,6 +346,21 @@ abstract contract BaseUniswapAdapter is FlashLoanReceiverBase, IBaseUniswapAdapt // Subtract flash loan fee uint256 finalAmountIn = amountIn.sub(amountIn.mul(FLASHLOAN_PREMIUM_TOTAL).div(10000)); + if (reserveIn == reserveOut) { + uint256 reserveDecimals = _getDecimals(reserveIn); + address[] memory path = new address[](1); + path[0] = reserveIn; + + return + AmountCalc( + finalAmountIn, + finalAmountIn.mul(10**18).div(amountIn), + _calcUsdValue(reserveIn, amountIn, reserveDecimals), + _calcUsdValue(reserveIn, finalAmountIn, reserveDecimals), + path + ); + } + address[] memory simplePath = new address[](2); simplePath[0] = reserveIn; simplePath[1] = reserveOut; @@ -421,6 +436,23 @@ abstract contract BaseUniswapAdapter is FlashLoanReceiverBase, IBaseUniswapAdapt address reserveOut, uint256 amountOut ) internal view returns (AmountCalc memory) { + if (reserveIn == reserveOut) { + // Add flash loan fee + uint256 amountIn = amountOut.add(amountOut.mul(FLASHLOAN_PREMIUM_TOTAL).div(10000)); + uint256 reserveDecimals = _getDecimals(reserveIn); + address[] memory path = new address[](1); + path[0] = reserveIn; + + return + AmountCalc( + amountIn, + amountOut.mul(10**18).div(amountIn), + _calcUsdValue(reserveIn, amountIn, reserveDecimals), + _calcUsdValue(reserveIn, amountOut, reserveDecimals), + path + ); + } + (uint256[] memory amounts, address[] memory path) = _getAmountsInAndPath(reserveIn, reserveOut, amountOut); diff --git a/contracts/dependencies/openzeppelin/contracts/Context.sol b/contracts/dependencies/openzeppelin/contracts/Context.sol index cfce1bfc..dc82ed76 100644 --- a/contracts/dependencies/openzeppelin/contracts/Context.sol +++ b/contracts/dependencies/openzeppelin/contracts/Context.sol @@ -12,11 +12,11 @@ pragma solidity 0.6.12; * This contract is only required for intermediate, library-like contracts. */ abstract contract Context { - function _msgSender() internal virtual view returns (address payable) { + function _msgSender() internal view virtual returns (address payable) { return msg.sender; } - function _msgData() internal virtual view returns (bytes memory) { + function _msgData() internal view virtual returns (bytes memory) { this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 return msg.data; } diff --git a/contracts/dependencies/openzeppelin/contracts/ERC20.sol b/contracts/dependencies/openzeppelin/contracts/ERC20.sol index e3946fb8..07fea73f 100644 --- a/contracts/dependencies/openzeppelin/contracts/ERC20.sol +++ b/contracts/dependencies/openzeppelin/contracts/ERC20.sol @@ -95,14 +95,14 @@ contract ERC20 is Context, IERC20 { /** * @dev See {IERC20-totalSupply}. */ - function totalSupply() public override view returns (uint256) { + function totalSupply() public view override returns (uint256) { return _totalSupply; } /** * @dev See {IERC20-balanceOf}. */ - function balanceOf(address account) public override view returns (uint256) { + function balanceOf(address account) public view override returns (uint256) { return _balances[account]; } @@ -124,9 +124,9 @@ contract ERC20 is Context, IERC20 { */ function allowance(address owner, address spender) public + view virtual override - view returns (uint256) { return _allowances[owner][spender]; diff --git a/contracts/dependencies/openzeppelin/upgradeability/BaseAdminUpgradeabilityProxy.sol b/contracts/dependencies/openzeppelin/upgradeability/BaseAdminUpgradeabilityProxy.sol index dd84184c..87e88957 100644 --- a/contracts/dependencies/openzeppelin/upgradeability/BaseAdminUpgradeabilityProxy.sol +++ b/contracts/dependencies/openzeppelin/upgradeability/BaseAdminUpgradeabilityProxy.sol @@ -24,7 +24,8 @@ contract BaseAdminUpgradeabilityProxy is BaseUpgradeabilityProxy { * This is the keccak-256 hash of "eip1967.proxy.admin" subtracted by 1, and is * validated in the constructor. */ - bytes32 internal constant ADMIN_SLOT = 0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103; + bytes32 internal constant ADMIN_SLOT = + 0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103; /** * @dev Modifier to check whether the `msg.sender` is the admin. diff --git a/contracts/dependencies/openzeppelin/upgradeability/BaseUpgradeabilityProxy.sol b/contracts/dependencies/openzeppelin/upgradeability/BaseUpgradeabilityProxy.sol index 8fb368f5..b0b82402 100644 --- a/contracts/dependencies/openzeppelin/upgradeability/BaseUpgradeabilityProxy.sol +++ b/contracts/dependencies/openzeppelin/upgradeability/BaseUpgradeabilityProxy.sol @@ -22,13 +22,14 @@ contract BaseUpgradeabilityProxy is Proxy { * This is the keccak-256 hash of "eip1967.proxy.implementation" subtracted by 1, and is * validated in the constructor. */ - bytes32 internal constant IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc; + bytes32 internal constant IMPLEMENTATION_SLOT = + 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc; /** * @dev Returns the current implementation. * @return impl Address of the current implementation */ - function _implementation() internal override view returns (address impl) { + function _implementation() internal view override returns (address impl) { bytes32 slot = IMPLEMENTATION_SLOT; //solium-disable-next-line assembly { diff --git a/contracts/dependencies/openzeppelin/upgradeability/Proxy.sol b/contracts/dependencies/openzeppelin/upgradeability/Proxy.sol index 0148899b..ab20b9ad 100644 --- a/contracts/dependencies/openzeppelin/upgradeability/Proxy.sol +++ b/contracts/dependencies/openzeppelin/upgradeability/Proxy.sol @@ -20,7 +20,7 @@ abstract contract Proxy { /** * @return The Address of the implementation. */ - function _implementation() internal virtual view returns (address); + function _implementation() internal view virtual returns (address); /** * @dev Delegates execution to an implementation contract. diff --git a/contracts/deployments/ATokensAndRatesHelper.sol b/contracts/deployments/ATokensAndRatesHelper.sol index a29dc6f2..0593178a 100644 --- a/contracts/deployments/ATokensAndRatesHelper.sol +++ b/contracts/deployments/ATokensAndRatesHelper.sol @@ -112,10 +112,7 @@ contract ATokensAndRatesHelper is Ownable { liquidationBonuses[i] ); - configurator.enableBorrowingOnReserve( - assets[i], - stableBorrowingEnabled[i] - ); + configurator.enableBorrowingOnReserve(assets[i], stableBorrowingEnabled[i]); configurator.setReserveFactor(assets[i], reserveFactors[i]); } } diff --git a/contracts/misc/AaveOracle.sol b/contracts/misc/AaveOracle.sol index b34d16b8..0cb8e180 100644 --- a/contracts/misc/AaveOracle.sol +++ b/contracts/misc/AaveOracle.sol @@ -80,7 +80,7 @@ contract AaveOracle is IPriceOracleGetter, Ownable { /// @notice Gets an asset price by address /// @param asset The asset address - function getAssetPrice(address asset) public override view returns (uint256) { + function getAssetPrice(address asset) public view override returns (uint256) { IChainlinkAggregator source = assetsSources[asset]; if (asset == WETH) { diff --git a/contracts/misc/WalletBalanceProvider.sol b/contracts/misc/WalletBalanceProvider.sol index cd4a81ce..3d4a9288 100644 --- a/contracts/misc/WalletBalanceProvider.sol +++ b/contracts/misc/WalletBalanceProvider.sol @@ -93,7 +93,8 @@ contract WalletBalanceProvider { uint256[] memory balances = new uint256[](reservesWithEth.length); for (uint256 j = 0; j < reserves.length; j++) { - DataTypes.ReserveConfigurationMap memory configuration = pool.getConfiguration(reservesWithEth[j]); + DataTypes.ReserveConfigurationMap memory configuration = + pool.getConfiguration(reservesWithEth[j]); (bool isActive, , , ) = configuration.getFlagsMemory(); diff --git a/contracts/mocks/flashloan/MockFlashLoanReceiver.sol b/contracts/mocks/flashloan/MockFlashLoanReceiver.sol index a0b3f8ca..9bf29730 100644 --- a/contracts/mocks/flashloan/MockFlashLoanReceiver.sol +++ b/contracts/mocks/flashloan/MockFlashLoanReceiver.sol @@ -68,9 +68,8 @@ contract MockFlashLoanReceiver is FlashLoanReceiverBase { 'Invalid balance for the contract' ); - uint256 amountToReturn = (_amountToApprove != 0) - ? _amountToApprove - : amounts[i].add(premiums[i]); + uint256 amountToReturn = + (_amountToApprove != 0) ? _amountToApprove : amounts[i].add(premiums[i]); //execution does not fail - mint tokens and return them to the _destination token.mint(premiums[i]); diff --git a/contracts/mocks/oracle/LendingRateOracle.sol b/contracts/mocks/oracle/LendingRateOracle.sol index 045a1d4c..44fe8aa1 100644 --- a/contracts/mocks/oracle/LendingRateOracle.sol +++ b/contracts/mocks/oracle/LendingRateOracle.sol @@ -8,7 +8,7 @@ contract LendingRateOracle is ILendingRateOracle, Ownable { mapping(address => uint256) borrowRates; mapping(address => uint256) liquidityRates; - function getMarketBorrowRate(address _asset) external override view returns (uint256) { + function getMarketBorrowRate(address _asset) external view override returns (uint256) { return borrowRates[_asset]; } diff --git a/contracts/mocks/oracle/PriceOracle.sol b/contracts/mocks/oracle/PriceOracle.sol index 183eff50..fe04a044 100644 --- a/contracts/mocks/oracle/PriceOracle.sol +++ b/contracts/mocks/oracle/PriceOracle.sol @@ -10,7 +10,7 @@ contract PriceOracle is IPriceOracle { event AssetPriceUpdated(address _asset, uint256 _price, uint256 timestamp); event EthPriceUpdated(uint256 _price, uint256 timestamp); - function getAssetPrice(address _asset) external override view returns (uint256) { + function getAssetPrice(address _asset) external view override returns (uint256) { return prices[_asset]; } diff --git a/contracts/protocol/lendingpool/DefaultReserveInterestRateStrategy.sol b/contracts/protocol/lendingpool/DefaultReserveInterestRateStrategy.sol index 6f45004c..c2584a22 100644 --- a/contracts/protocol/lendingpool/DefaultReserveInterestRateStrategy.sol +++ b/contracts/protocol/lendingpool/DefaultReserveInterestRateStrategy.sol @@ -139,9 +139,7 @@ contract DefaultReserveInterestRateStrategy is IReserveInterestRateStrategy { vars.currentLiquidityRate = 0; uint256 utilizationRate = - vars.totalDebt == 0 - ? 0 - : vars.totalDebt.rayDiv(availableLiquidity.add(vars.totalDebt)); + vars.totalDebt == 0 ? 0 : vars.totalDebt.rayDiv(availableLiquidity.add(vars.totalDebt)); vars.currentStableBorrowRate = ILendingRateOracle(addressesProvider.getLendingRateOracle()) .getMarketBorrowRate(reserve); diff --git a/contracts/protocol/libraries/aave-upgradeability/VersionedInitializable.sol b/contracts/protocol/libraries/aave-upgradeability/VersionedInitializable.sol index f2b73b8e..b8e356ae 100644 --- a/contracts/protocol/libraries/aave-upgradeability/VersionedInitializable.sol +++ b/contracts/protocol/libraries/aave-upgradeability/VersionedInitializable.sol @@ -50,14 +50,14 @@ abstract contract VersionedInitializable { } /** - * @dev returns the revision number of the contract - * Needs to be defined in the inherited class as a constant. - **/ + * @dev returns the revision number of the contract + * Needs to be defined in the inherited class as a constant. + **/ function getRevision() internal pure virtual returns (uint256); /** - * @dev Returns true if and only if the function is running in the constructor - **/ + * @dev Returns true if and only if the function is running in the constructor + **/ function isConstructor() private view returns (bool) { // extcodesize checks the size of the code stored in an address, and // address returns the current address. Since the code is still not diff --git a/contracts/protocol/libraries/configuration/ReserveConfiguration.sol b/contracts/protocol/libraries/configuration/ReserveConfiguration.sol index 60076a6f..5649a580 100644 --- a/contracts/protocol/libraries/configuration/ReserveConfiguration.sol +++ b/contracts/protocol/libraries/configuration/ReserveConfiguration.sol @@ -90,7 +90,10 @@ library ReserveConfiguration { * @param self The reserve configuration * @param bonus The new liquidation bonus **/ - function setLiquidationBonus(DataTypes.ReserveConfigurationMap memory self, uint256 bonus) internal pure { + function setLiquidationBonus(DataTypes.ReserveConfigurationMap memory self, uint256 bonus) + internal + pure + { require(bonus <= MAX_VALID_LIQUIDATION_BONUS, Errors.RC_INVALID_LIQ_BONUS); self.data = @@ -116,7 +119,10 @@ library ReserveConfiguration { * @param self The reserve configuration * @param decimals The decimals **/ - function setDecimals(DataTypes.ReserveConfigurationMap memory self, uint256 decimals) internal pure { + function setDecimals(DataTypes.ReserveConfigurationMap memory self, uint256 decimals) + internal + pure + { require(decimals <= MAX_VALID_DECIMALS, Errors.RC_INVALID_DECIMALS); self.data = (self.data & DECIMALS_MASK) | (decimals << RESERVE_DECIMALS_START_BIT_POSITION); @@ -127,7 +133,11 @@ library ReserveConfiguration { * @param self The reserve configuration * @return The decimals of the asset **/ - function getDecimals(DataTypes.ReserveConfigurationMap storage self) internal view returns (uint256) { + function getDecimals(DataTypes.ReserveConfigurationMap storage self) + internal + view + returns (uint256) + { return (self.data & ~DECIMALS_MASK) >> RESERVE_DECIMALS_START_BIT_POSITION; } @@ -176,7 +186,10 @@ library ReserveConfiguration { * @param self The reserve configuration * @param enabled True if the borrowing needs to be enabled, false otherwise **/ - function setBorrowingEnabled(DataTypes.ReserveConfigurationMap memory self, bool enabled) internal pure { + function setBorrowingEnabled(DataTypes.ReserveConfigurationMap memory self, bool enabled) + internal + pure + { self.data = (self.data & BORROWING_MASK) | (uint256(enabled ? 1 : 0) << BORROWING_ENABLED_START_BIT_POSITION); @@ -187,7 +200,11 @@ library ReserveConfiguration { * @param self The reserve configuration * @return The borrowing state **/ - function getBorrowingEnabled(DataTypes.ReserveConfigurationMap storage self) internal view returns (bool) { + function getBorrowingEnabled(DataTypes.ReserveConfigurationMap storage self) + internal + view + returns (bool) + { return (self.data & ~BORROWING_MASK) != 0; } @@ -196,10 +213,10 @@ library ReserveConfiguration { * @param self The reserve configuration * @param enabled True if the stable rate borrowing needs to be enabled, false otherwise **/ - function setStableRateBorrowingEnabled(DataTypes.ReserveConfigurationMap memory self, bool enabled) - internal - pure - { + function setStableRateBorrowingEnabled( + DataTypes.ReserveConfigurationMap memory self, + bool enabled + ) internal pure { self.data = (self.data & STABLE_BORROWING_MASK) | (uint256(enabled ? 1 : 0) << STABLE_BORROWING_ENABLED_START_BIT_POSITION); @@ -239,7 +256,11 @@ library ReserveConfiguration { * @param self The reserve configuration * @return The reserve factor **/ - function getReserveFactor(DataTypes.ReserveConfigurationMap storage self) internal view returns (uint256) { + function getReserveFactor(DataTypes.ReserveConfigurationMap storage self) + internal + view + returns (uint256) + { return (self.data & ~RESERVE_FACTOR_MASK) >> RESERVE_FACTOR_START_BIT_POSITION; } diff --git a/contracts/protocol/libraries/configuration/UserConfiguration.sol b/contracts/protocol/libraries/configuration/UserConfiguration.sol index b56f6140..2994f05d 100644 --- a/contracts/protocol/libraries/configuration/UserConfiguration.sol +++ b/contracts/protocol/libraries/configuration/UserConfiguration.sol @@ -53,11 +53,10 @@ library UserConfiguration { * @param reserveIndex The index of the reserve in the bitmap * @return True if the user has been using a reserve for borrowing or as collateral, false otherwise **/ - function isUsingAsCollateralOrBorrowing(DataTypes.UserConfigurationMap memory self, uint256 reserveIndex) - internal - pure - returns (bool) - { + function isUsingAsCollateralOrBorrowing( + DataTypes.UserConfigurationMap memory self, + uint256 reserveIndex + ) internal pure returns (bool) { require(reserveIndex < 128, Errors.UL_INVALID_INDEX); return (self.data >> (reserveIndex * 2)) & 3 != 0; } diff --git a/contracts/protocol/libraries/logic/GenericLogic.sol b/contracts/protocol/libraries/logic/GenericLogic.sol index e921ec52..d4081dda 100644 --- a/contracts/protocol/libraries/logic/GenericLogic.sol +++ b/contracts/protocol/libraries/logic/GenericLogic.sol @@ -65,7 +65,7 @@ library GenericLogic { if (!userConfig.isBorrowingAny() || !userConfig.isUsingAsCollateral(reservesData[asset].id)) { return true; } - + balanceDecreaseAllowedLocalVars memory vars; (, vars.liquidationThreshold, , vars.decimals, ) = reservesData[asset] @@ -73,7 +73,7 @@ library GenericLogic { .getParams(); if (vars.liquidationThreshold == 0) { - return true; + return true; } ( @@ -213,9 +213,7 @@ library GenericLogic { } } - vars.avgLtv = vars.totalCollateralInETH > 0 - ? vars.avgLtv.div(vars.totalCollateralInETH) - : 0; + vars.avgLtv = vars.totalCollateralInETH > 0 ? vars.avgLtv.div(vars.totalCollateralInETH) : 0; vars.avgLiquidationThreshold = vars.totalCollateralInETH > 0 ? vars.avgLiquidationThreshold.div(vars.totalCollateralInETH) : 0; @@ -265,8 +263,7 @@ library GenericLogic { uint256 totalDebtInETH, uint256 ltv ) internal pure returns (uint256) { - - uint256 availableBorrowsETH = totalCollateralInETH.percentMul(ltv); + uint256 availableBorrowsETH = totalCollateralInETH.percentMul(ltv); if (availableBorrowsETH < totalDebtInETH) { return 0; diff --git a/helpers/etherscan-verification.ts b/helpers/etherscan-verification.ts index 902cb2fe..ddbf80e4 100644 --- a/helpers/etherscan-verification.ts +++ b/helpers/etherscan-verification.ts @@ -1,7 +1,7 @@ -import {exit} from 'process'; +import { exit } from 'process'; import fs from 'fs'; -import {file} from 'tmp-promise'; -import {DRE} from './misc-utils'; +import { file } from 'tmp-promise'; +import { DRE } from './misc-utils'; const fatalErrors = [ `The address provided as argument contains a contract, but its bytecode`, @@ -43,7 +43,7 @@ export const verifyContract = async ( const msDelay = 3000; const times = 4; // Write a temporal file to host complex parameters for buidler-etherscan https://github.com/nomiclabs/buidler/tree/development/packages/buidler-etherscan#complex-arguments - const {fd, path, cleanup} = await file({ + const { fd, path, cleanup } = await file({ prefix: 'verify-params-', postfix: '.js', }); diff --git a/helpers/mock-helpers.ts b/helpers/mock-helpers.ts index 5989216d..11859d97 100644 --- a/helpers/mock-helpers.ts +++ b/helpers/mock-helpers.ts @@ -1,10 +1,10 @@ -import {tEthereumAddress} from './types'; -import {MockAggregator} from '../types/MockAggregator'; -import {MockTokenMap} from './contracts-helpers'; +import { tEthereumAddress } from './types'; +import { MockAggregator } from '../types/MockAggregator'; +import { MockTokenMap } from './contracts-helpers'; export const getAllTokenAddresses = (mockTokens: MockTokenMap) => Object.entries(mockTokens).reduce( - (accum: {[tokenSymbol: string]: tEthereumAddress}, [tokenSymbol, tokenContract]) => ({ + (accum: { [tokenSymbol: string]: tEthereumAddress }, [tokenSymbol, tokenContract]) => ({ ...accum, [tokenSymbol]: tokenContract.address, }), @@ -14,7 +14,7 @@ export const getAllAggregatorsAddresses = (mockAggregators: { [tokenSymbol: string]: MockAggregator; }) => Object.entries(mockAggregators).reduce( - (accum: {[tokenSymbol: string]: tEthereumAddress}, [tokenSymbol, aggregator]) => ({ + (accum: { [tokenSymbol: string]: tEthereumAddress }, [tokenSymbol, aggregator]) => ({ ...accum, [tokenSymbol]: aggregator.address, }), diff --git a/helpers/oracles-helpers.ts b/helpers/oracles-helpers.ts index 45cec5e2..9fd2ba44 100644 --- a/helpers/oracles-helpers.ts +++ b/helpers/oracles-helpers.ts @@ -7,16 +7,16 @@ import { SymbolMap, } from './types'; -import {LendingRateOracle} from '../types/LendingRateOracle'; -import {PriceOracle} from '../types/PriceOracle'; -import {MockAggregator} from '../types/MockAggregator'; -import {deployMockAggregator} from './contracts-deployments'; -import {chunk, waitForTx} from './misc-utils'; -import {getStableAndVariableTokensHelper} from './contracts-getters'; +import { LendingRateOracle } from '../types/LendingRateOracle'; +import { PriceOracle } from '../types/PriceOracle'; +import { MockAggregator } from '../types/MockAggregator'; +import { deployMockAggregator } from './contracts-deployments'; +import { chunk, waitForTx } from './misc-utils'; +import { getStableAndVariableTokensHelper } from './contracts-getters'; export const setInitialMarketRatesInRatesOracleByHelper = async ( marketRates: iMultiPoolsAssets, - assetsAddresses: {[x: string]: tEthereumAddress}, + assetsAddresses: { [x: string]: tEthereumAddress }, lendingRateOracleInstance: LendingRateOracle, admin: tEthereumAddress ) => { @@ -24,7 +24,7 @@ export const setInitialMarketRatesInRatesOracleByHelper = async ( const assetAddresses: string[] = []; const borrowRates: string[] = []; const symbols: string[] = []; - for (const [assetSymbol, {borrowRate}] of Object.entries(marketRates) as [ + for (const [assetSymbol, { borrowRate }] of Object.entries(marketRates) as [ string, IMarketRates ][]) { @@ -99,7 +99,7 @@ export const setAssetPricesInOracle = async ( }; export const deployMockAggregators = async (initialPrices: SymbolMap, verify?: boolean) => { - const aggregators: {[tokenSymbol: string]: MockAggregator} = {}; + const aggregators: { [tokenSymbol: string]: MockAggregator } = {}; for (const tokenContractName of Object.keys(initialPrices)) { if (tokenContractName !== 'ETH') { const priceIndex = Object.keys(initialPrices).findIndex( @@ -116,7 +116,7 @@ export const deployAllMockAggregators = async ( initialPrices: iAssetAggregatorBase, verify?: boolean ) => { - const aggregators: {[tokenSymbol: string]: MockAggregator} = {}; + const aggregators: { [tokenSymbol: string]: MockAggregator } = {}; for (const tokenContractName of Object.keys(initialPrices)) { if (tokenContractName !== 'ETH') { const priceIndex = Object.keys(initialPrices).findIndex( diff --git a/package.json b/package.json index 7ea71aea..d8db5d38 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,11 @@ { - "name": "protocol-v2", - "version": "1.0.0", + "name": "@aave/protocol-v2", + "version": "1.0.1", "description": "Aave Protocol V2 smart contracts", + "files": [ + "contracts", + "artifacts" + ], "scripts": { "run-env": "npm i && tail -f /dev/null", "hardhat": "hardhat", @@ -39,7 +43,8 @@ "aave:fork:main": "npm run compile && MAINNET_FORK=true hardhat aave:mainnet", "aave:main:full:migration": "npm run compile && npm run hardhat:main -- aave:mainnet --verify", "aave:main:full:initialize": "npm run compile && MAINNET_FORK=true full:initialize-tokens --pool Aave", - "dev:prettier": "prettier --write .", + "prettier:check": "npx prettier -c 'tasks/**/*.ts' 'contracts/**/*.sol' 'helpers/**/*.ts' 'test/**/*.ts'", + "prettier:write": "prettier --write 'tasks/**/*.ts' 'contracts/**/*.sol' 'helpers/**/*.ts' 'test/**/*.ts'", "ci:test": "npm run compile && npm run test", "ci:clean": "rm -rf ./artifacts ./cache ./types", "print-contracts:kovan": "npm run hardhat:kovan -- print-contracts", @@ -62,7 +67,8 @@ "main:initialize-tokens": "npm run compile && hardhat --network main full:initialize-tokens --pool Aave", "kovan:initialize-tokens": "npm run compile && hardhat --network kovan full:initialize-tokens --pool Aave", "external:deploy-assets-kovan": "npm run compile && hardhat --network kovan external:deploy-new-asset --symbol ${SYMBOL} --verify", - "external:deploy-assets-main": "npm run compile && hardhat --network main external:deploy-new-asset --symbol ${SYMBOL} --verify" + "external:deploy-assets-main": "npm run compile && hardhat --network main external:deploy-new-asset --symbol ${SYMBOL} --verify", + "prepublishOnly": "npm run compile" }, "devDependencies": { "@nomiclabs/buidler": "^1.4.7", @@ -113,38 +119,27 @@ }, "husky": { "hooks": { - "pre-commit": "pretty-quick --staged" + "pre-commit": "pretty-quick --staged --pattern 'contracts/**/*.sol' --pattern 'helpers/**/*.ts' --pattern 'test/**/*.ts' --pattern 'tasks/**/*.ts'" } }, "author": "Aave", "contributors": [ - { - "name": "Emilio Frangella", - "email": "emilio@aave.com" - }, - { - "name": "Ernesto Boado", - "email": "ernesto@aave.com" - }, - { - "name": "Andrey Kozlov", - "email": "andrey@aave.com" - }, - { - "name": "David Racero", - "email": "david.k@aave.com" - }, - { - "name": "Pol Sendra", - "email": "pol@aave.com" - }, - { - "name": "David Truong", - "email": "david@aave.com" - } + "Ernesto Boado ", + "Emilio Frangella ", + "Andrey Kozlov ", + "David Racero ", + "Pol Sendra ", + "David Truong " ], "license": "AGPLv3", "dependencies": { "tmp-promise": "^3.0.2" - } + }, + "keywords": [ + "aave", + "protocol", + "protocol-v2", + "ethereum", + "solidity" + ] } diff --git a/tasks/dev/1_mock_tokens.ts b/tasks/dev/1_mock_tokens.ts index 550135f5..cc4713c5 100644 --- a/tasks/dev/1_mock_tokens.ts +++ b/tasks/dev/1_mock_tokens.ts @@ -1,9 +1,9 @@ -import {task} from 'hardhat/config'; -import {deployAllMockTokens} from '../../helpers/contracts-deployments'; +import { task } from 'hardhat/config'; +import { deployAllMockTokens } from '../../helpers/contracts-deployments'; task('dev:deploy-mock-tokens', 'Deploy mock tokens for dev enviroment') .addFlag('verify', 'Verify contracts at Etherscan') - .setAction(async ({verify}, localBRE) => { + .setAction(async ({ verify }, localBRE) => { await localBRE.run('set-DRE'); await deployAllMockTokens(verify); }); diff --git a/tasks/dev/3_lending_pool.ts b/tasks/dev/3_lending_pool.ts index b1aeb58c..9936abfa 100644 --- a/tasks/dev/3_lending_pool.ts +++ b/tasks/dev/3_lending_pool.ts @@ -1,22 +1,22 @@ -import {task} from 'hardhat/config'; +import { task } from 'hardhat/config'; import { deployATokensAndRatesHelper, deployLendingPool, deployLendingPoolConfigurator, deployStableAndVariableTokensHelper, } from '../../helpers/contracts-deployments'; -import {eContractid} from '../../helpers/types'; -import {waitForTx} from '../../helpers/misc-utils'; +import { eContractid } from '../../helpers/types'; +import { waitForTx } from '../../helpers/misc-utils'; import { getLendingPoolAddressesProvider, getLendingPool, getLendingPoolConfiguratorProxy, } from '../../helpers/contracts-getters'; -import {insertContractAddressInDb} from '../../helpers/contracts-helpers'; +import { insertContractAddressInDb } from '../../helpers/contracts-helpers'; task('dev:deploy-lending-pool', 'Deploy lending pool for dev enviroment') .addFlag('verify', 'Verify contracts at Etherscan') - .setAction(async ({verify}, localBRE) => { + .setAction(async ({ verify }, localBRE) => { await localBRE.run('set-DRE'); const addressesProvider = await getLendingPoolAddressesProvider(); diff --git a/tasks/dev/4_oracles.ts b/tasks/dev/4_oracles.ts index 97f14c8a..dbb6e708 100644 --- a/tasks/dev/4_oracles.ts +++ b/tasks/dev/4_oracles.ts @@ -1,4 +1,4 @@ -import {task} from 'hardhat/config'; +import { task } from 'hardhat/config'; import { deployPriceOracle, deployAaveOracle, @@ -10,10 +10,10 @@ import { deployAllMockAggregators, setInitialMarketRatesInRatesOracleByHelper, } from '../../helpers/oracles-helpers'; -import {ICommonConfiguration, iAssetBase, TokenContractId} from '../../helpers/types'; -import {waitForTx} from '../../helpers/misc-utils'; -import {getAllAggregatorsAddresses, getAllTokenAddresses} from '../../helpers/mock-helpers'; -import {ConfigNames, loadPoolConfig, getWethAddress} from '../../helpers/configuration'; +import { ICommonConfiguration, iAssetBase, TokenContractId } from '../../helpers/types'; +import { waitForTx } from '../../helpers/misc-utils'; +import { getAllAggregatorsAddresses, getAllTokenAddresses } from '../../helpers/mock-helpers'; +import { ConfigNames, loadPoolConfig, getWethAddress } from '../../helpers/configuration'; import { getAllMockedTokens, getLendingPoolAddressesProvider, @@ -23,12 +23,12 @@ import { task('dev:deploy-oracles', 'Deploy oracles for dev enviroment') .addFlag('verify', 'Verify contracts at Etherscan') .addParam('pool', `Pool name to retrieve configuration, supported: ${Object.values(ConfigNames)}`) - .setAction(async ({verify, pool}, localBRE) => { + .setAction(async ({ verify, pool }, localBRE) => { await localBRE.run('set-DRE'); const poolConfig = loadPoolConfig(pool); const { - Mocks: {AllAssetsInitialPrices}, - ProtocolGlobalParams: {UsdAddress, MockUsdPriceInWei}, + Mocks: { AllAssetsInitialPrices }, + ProtocolGlobalParams: { UsdAddress, MockUsdPriceInWei }, LendingRateOracleRatesCommon, } = poolConfig as ICommonConfiguration; @@ -67,7 +67,7 @@ task('dev:deploy-oracles', 'Deploy oracles for dev enviroment') const lendingRateOracle = await deployLendingRateOracle(verify); await waitForTx(await addressesProvider.setLendingRateOracle(lendingRateOracle.address)); - const {USD, ...tokensAddressesWithoutUsd} = allTokenAddresses; + const { USD, ...tokensAddressesWithoutUsd } = allTokenAddresses; const allReservesAddresses = { ...tokensAddressesWithoutUsd, }; diff --git a/tasks/dev/5_initialize.ts b/tasks/dev/5_initialize.ts index c62f31ce..37744343 100644 --- a/tasks/dev/5_initialize.ts +++ b/tasks/dev/5_initialize.ts @@ -16,10 +16,7 @@ import { import { tEthereumAddress, AavePools, eContractid } from '../../helpers/types'; import { waitForTx, filterMapBy } from '../../helpers/misc-utils'; -import { - configureReservesByHelper, - initReservesByHelper, -} from '../../helpers/init-helpers'; +import { configureReservesByHelper, initReservesByHelper } from '../../helpers/init-helpers'; import { getAllTokenAddresses } from '../../helpers/mock-helpers'; import { ZERO_ADDRESS } from '../../helpers/constants'; import { @@ -60,12 +57,7 @@ task('dev:initialize-lending-pool', 'Initialize lending pool configuration.') ZERO_ADDRESS, verify ); - await configureReservesByHelper( - reservesParams, - protoPoolReservesAddresses, - testHelpers, - admin - ); + await configureReservesByHelper(reservesParams, protoPoolReservesAddresses, testHelpers, admin); const collateralManager = await deployLendingPoolCollateralManager(verify); await waitForTx( diff --git a/tasks/full/2_lending_pool.ts b/tasks/full/2_lending_pool.ts index 8d75ba5d..db0daabb 100644 --- a/tasks/full/2_lending_pool.ts +++ b/tasks/full/2_lending_pool.ts @@ -1,8 +1,5 @@ import { task } from 'hardhat/config'; -import { - getEthersSignersAddresses, - insertContractAddressInDb, -} from '../../helpers/contracts-helpers'; +import { insertContractAddressInDb } from '../../helpers/contracts-helpers'; import { deployATokensAndRatesHelper, deployLendingPool, diff --git a/tasks/full/5_initialize.ts b/tasks/full/5_initialize.ts index 444f55d8..af5484d9 100644 --- a/tasks/full/5_initialize.ts +++ b/tasks/full/5_initialize.ts @@ -6,13 +6,15 @@ import { deployAaveProtocolDataProvider, deployWETHGateway, } from '../../helpers/contracts-deployments'; -import { loadPoolConfig, ConfigNames, getWethAddress, getTreasuryAddress } from '../../helpers/configuration'; +import { + loadPoolConfig, + ConfigNames, + getWethAddress, + getTreasuryAddress, +} from '../../helpers/configuration'; import { eEthereumNetwork, ICommonConfiguration } from '../../helpers/types'; import { waitForTx } from '../../helpers/misc-utils'; -import { - initReservesByHelper, - configureReservesByHelper, -} from '../../helpers/init-helpers'; +import { initReservesByHelper, configureReservesByHelper } from '../../helpers/init-helpers'; import { exit } from 'process'; import { getAaveProtocolDataProvider, @@ -43,7 +45,14 @@ task('full:initialize-lending-pool', 'Initialize lending pool configuration.') const treasuryAddress = await getTreasuryAddress(poolConfig); - await initReservesByHelper(ReservesConfig, reserveAssets, admin, treasuryAddress, ZERO_ADDRESS, verify); + await initReservesByHelper( + ReservesConfig, + reserveAssets, + admin, + treasuryAddress, + ZERO_ADDRESS, + verify + ); await configureReservesByHelper(ReservesConfig, reserveAssets, testHelpers, admin); const collateralManager = await deployLendingPoolCollateralManager(verify); diff --git a/tasks/migrations/aave.dev.ts b/tasks/migrations/aave.dev.ts index 1892cb53..842d1861 100644 --- a/tasks/migrations/aave.dev.ts +++ b/tasks/migrations/aave.dev.ts @@ -1,11 +1,11 @@ -import {task} from 'hardhat/config'; -import {checkVerification} from '../../helpers/etherscan-verification'; -import {ConfigNames} from '../../helpers/configuration'; -import {printContracts} from '../../helpers/misc-utils'; +import { task } from 'hardhat/config'; +import { checkVerification } from '../../helpers/etherscan-verification'; +import { ConfigNames } from '../../helpers/configuration'; +import { printContracts } from '../../helpers/misc-utils'; task('aave:dev', 'Deploy development enviroment') .addOptionalParam('verify', 'Verify contracts at Etherscan') - .setAction(async ({verify}, localBRE) => { + .setAction(async ({ verify }, localBRE) => { const POOL_NAME = ConfigNames.Aave; await localBRE.run('set-DRE'); @@ -18,19 +18,19 @@ task('aave:dev', 'Deploy development enviroment') console.log('Migration started\n'); console.log('1. Deploy mock tokens'); - await localBRE.run('dev:deploy-mock-tokens', {verify}); + await localBRE.run('dev:deploy-mock-tokens', { verify }); console.log('2. Deploy address provider'); - await localBRE.run('dev:deploy-address-provider', {verify}); + await localBRE.run('dev:deploy-address-provider', { verify }); console.log('3. Deploy lending pool'); - await localBRE.run('dev:deploy-lending-pool', {verify}); + await localBRE.run('dev:deploy-lending-pool', { verify }); console.log('4. Deploy oracles'); - await localBRE.run('dev:deploy-oracles', {verify, pool: POOL_NAME}); + await localBRE.run('dev:deploy-oracles', { verify, pool: POOL_NAME }); console.log('5. Initialize lending pool'); - await localBRE.run('dev:initialize-lending-pool', {verify, pool: POOL_NAME}); + await localBRE.run('dev:initialize-lending-pool', { verify, pool: POOL_NAME }); console.log('\nFinished migration'); printContracts(); diff --git a/tasks/migrations/aave.mainnet.ts b/tasks/migrations/aave.mainnet.ts index 27f68268..96bcbbb8 100644 --- a/tasks/migrations/aave.mainnet.ts +++ b/tasks/migrations/aave.mainnet.ts @@ -1,7 +1,6 @@ import { task } from 'hardhat/config'; import { checkVerification } from '../../helpers/etherscan-verification'; import { ConfigNames } from '../../helpers/configuration'; -import { EthereumNetworkNames } from '../../helpers/types'; import { printContracts } from '../../helpers/misc-utils'; import { usingTenderly } from '../../helpers/tenderly-utils'; diff --git a/tasks/misc/print-contracts.ts b/tasks/misc/print-contracts.ts index d3caf0cc..a9e8b986 100644 --- a/tasks/misc/print-contracts.ts +++ b/tasks/misc/print-contracts.ts @@ -1,5 +1,5 @@ -import {task} from 'hardhat/config'; -import {printContracts} from '../../helpers/misc-utils'; +import { task } from 'hardhat/config'; +import { printContracts } from '../../helpers/misc-utils'; task('print-contracts', 'Inits the DRE, to have access to all the plugins').setAction( async ({}, localBRE) => { diff --git a/tasks/misc/verify-sc.ts b/tasks/misc/verify-sc.ts index 81f0970c..12484d47 100644 --- a/tasks/misc/verify-sc.ts +++ b/tasks/misc/verify-sc.ts @@ -1,5 +1,5 @@ -import {task} from 'hardhat/config'; -import {verifyContract, checkVerification} from '../../helpers/etherscan-verification'; +import { task } from 'hardhat/config'; +import { verifyContract, checkVerification } from '../../helpers/etherscan-verification'; interface VerifyParams { contractName: string; @@ -19,7 +19,7 @@ task('verify-sc', 'Inits the DRE, to have access to all the plugins') 'arguments for contract constructor', [] ) - .setAction(async ({address, constructorArguments = [], libraries}: VerifyParams, localBRE) => { + .setAction(async ({ address, constructorArguments = [], libraries }: VerifyParams, localBRE) => { await localBRE.run('set-DRE'); checkVerification(); diff --git a/test/addresses-provider-registry.spec.ts b/test/addresses-provider-registry.spec.ts index d26eae21..5ded1413 100644 --- a/test/addresses-provider-registry.spec.ts +++ b/test/addresses-provider-registry.spec.ts @@ -1,12 +1,12 @@ -import {TestEnv, makeSuite} from './helpers/make-suite'; -import {ZERO_ADDRESS} from '../helpers/constants'; -import {ProtocolErrors} from '../helpers/types'; +import { TestEnv, makeSuite } from './helpers/make-suite'; +import { ZERO_ADDRESS } from '../helpers/constants'; +import { ProtocolErrors } from '../helpers/types'; -const {expect} = require('chai'); +const { expect } = require('chai'); makeSuite('AddressesProviderRegistry', (testEnv: TestEnv) => { it('Checks the addresses provider is added to the registry', async () => { - const {addressesProvider, registry} = testEnv; + const { addressesProvider, registry } = testEnv; const providers = await registry.getAddressesProvidersList(); @@ -18,8 +18,8 @@ makeSuite('AddressesProviderRegistry', (testEnv: TestEnv) => { }); it('tries to register an addresses provider with id 0', async () => { - const {users, registry} = testEnv; - const {LPAPR_INVALID_ADDRESSES_PROVIDER_ID} = ProtocolErrors; + const { users, registry } = testEnv; + const { LPAPR_INVALID_ADDRESSES_PROVIDER_ID } = ProtocolErrors; await expect(registry.registerAddressesProvider(users[2].address, '0')).to.be.revertedWith( LPAPR_INVALID_ADDRESSES_PROVIDER_ID @@ -27,7 +27,7 @@ makeSuite('AddressesProviderRegistry', (testEnv: TestEnv) => { }); it('Registers a new mock addresses provider', async () => { - const {users, registry} = testEnv; + const { users, registry } = testEnv; //simulating an addresses provider using the users[1] wallet address await registry.registerAddressesProvider(users[1].address, '2'); @@ -42,7 +42,7 @@ makeSuite('AddressesProviderRegistry', (testEnv: TestEnv) => { }); it('Removes the mock addresses provider', async () => { - const {users, registry, addressesProvider} = testEnv; + const { users, registry, addressesProvider } = testEnv; const id = await registry.getAddressesProviderIdByAddress(users[1].address); @@ -61,9 +61,9 @@ makeSuite('AddressesProviderRegistry', (testEnv: TestEnv) => { }); it('Tries to remove a unregistered addressesProvider', async () => { - const {LPAPR_PROVIDER_NOT_REGISTERED} = ProtocolErrors; + const { LPAPR_PROVIDER_NOT_REGISTERED } = ProtocolErrors; - const {users, registry} = testEnv; + const { users, registry } = testEnv; await expect(registry.unregisterAddressesProvider(users[2].address)).to.be.revertedWith( LPAPR_PROVIDER_NOT_REGISTERED @@ -71,9 +71,9 @@ makeSuite('AddressesProviderRegistry', (testEnv: TestEnv) => { }); it('Tries to remove a unregistered addressesProvider', async () => { - const {LPAPR_PROVIDER_NOT_REGISTERED} = ProtocolErrors; + const { LPAPR_PROVIDER_NOT_REGISTERED } = ProtocolErrors; - const {users, registry} = testEnv; + const { users, registry } = testEnv; await expect(registry.unregisterAddressesProvider(users[2].address)).to.be.revertedWith( LPAPR_PROVIDER_NOT_REGISTERED @@ -81,7 +81,7 @@ makeSuite('AddressesProviderRegistry', (testEnv: TestEnv) => { }); it('Tries to add an already added addressesProvider with a different id. Should overwrite the previous id', async () => { - const {users, registry, addressesProvider} = testEnv; + const { users, registry, addressesProvider } = testEnv; await registry.registerAddressesProvider(addressesProvider.address, '2'); diff --git a/test/atoken-modifiers.spec.ts b/test/atoken-modifiers.spec.ts index 4649dc21..d379210c 100644 --- a/test/atoken-modifiers.spec.ts +++ b/test/atoken-modifiers.spec.ts @@ -1,33 +1,33 @@ -import {expect} from 'chai'; -import {makeSuite, TestEnv} from './helpers/make-suite'; -import {ProtocolErrors} from '../helpers/types'; +import { expect } from 'chai'; +import { makeSuite, TestEnv } from './helpers/make-suite'; +import { ProtocolErrors } from '../helpers/types'; makeSuite('AToken: Modifiers', (testEnv: TestEnv) => { - const {CT_CALLER_MUST_BE_LENDING_POOL} = ProtocolErrors; + const { CT_CALLER_MUST_BE_LENDING_POOL } = ProtocolErrors; it('Tries to invoke mint not being the LendingPool', async () => { - const {deployer, aDai} = testEnv; + const { deployer, aDai } = testEnv; await expect(aDai.mint(deployer.address, '1', '1')).to.be.revertedWith( CT_CALLER_MUST_BE_LENDING_POOL ); }); it('Tries to invoke burn not being the LendingPool', async () => { - const {deployer, aDai} = testEnv; + const { deployer, aDai } = testEnv; await expect(aDai.burn(deployer.address, deployer.address, '1', '1')).to.be.revertedWith( CT_CALLER_MUST_BE_LENDING_POOL ); }); it('Tries to invoke transferOnLiquidation not being the LendingPool', async () => { - const {deployer, users, aDai} = testEnv; + const { deployer, users, aDai } = testEnv; await expect( aDai.transferOnLiquidation(deployer.address, users[0].address, '1') ).to.be.revertedWith(CT_CALLER_MUST_BE_LENDING_POOL); }); it('Tries to invoke transferUnderlyingTo not being the LendingPool', async () => { - const {deployer, aDai} = testEnv; + const { deployer, aDai } = testEnv; await expect(aDai.transferUnderlyingTo(deployer.address, '1')).to.be.revertedWith( CT_CALLER_MUST_BE_LENDING_POOL ); diff --git a/test/atoken-transfer.spec.ts b/test/atoken-transfer.spec.ts index bba0da59..7414eea9 100644 --- a/test/atoken-transfer.spec.ts +++ b/test/atoken-transfer.spec.ts @@ -1,10 +1,10 @@ -import {APPROVAL_AMOUNT_LENDING_POOL, MAX_UINT_AMOUNT, ZERO_ADDRESS} from '../helpers/constants'; -import {convertToCurrencyDecimals} from '../helpers/contracts-helpers'; -import {expect} from 'chai'; -import {ethers} from 'ethers'; -import {RateMode, ProtocolErrors} from '../helpers/types'; -import {makeSuite, TestEnv} from './helpers/make-suite'; -import {CommonsConfig} from '../markets/aave/commons'; +import { APPROVAL_AMOUNT_LENDING_POOL, MAX_UINT_AMOUNT, ZERO_ADDRESS } from '../helpers/constants'; +import { convertToCurrencyDecimals } from '../helpers/contracts-helpers'; +import { expect } from 'chai'; +import { ethers } from 'ethers'; +import { RateMode, ProtocolErrors } from '../helpers/types'; +import { makeSuite, TestEnv } from './helpers/make-suite'; +import { CommonsConfig } from '../markets/aave/commons'; const AAVE_REFERRAL = CommonsConfig.ProtocolGlobalParams.AaveReferral; @@ -16,7 +16,7 @@ makeSuite('AToken: Transfer', (testEnv: TestEnv) => { } = ProtocolErrors; it('User 0 deposits 1000 DAI, transfers to user 1', async () => { - const {users, pool, dai, aDai} = testEnv; + const { users, pool, dai, aDai } = testEnv; await dai.connect(users[0].signer).mint(await convertToCurrencyDecimals(dai.address, '1000')); @@ -46,7 +46,7 @@ makeSuite('AToken: Transfer', (testEnv: TestEnv) => { }); it('User 0 deposits 1 WETH and user 1 tries to borrow the WETH with the received DAI as collateral', async () => { - const {users, pool, weth, helpersContract} = testEnv; + const { users, pool, weth, helpersContract } = testEnv; const userAddress = await pool.signer.getAddress(); await weth.connect(users[0].signer).mint(await convertToCurrencyDecimals(weth.address, '1')); @@ -75,7 +75,7 @@ makeSuite('AToken: Transfer', (testEnv: TestEnv) => { }); it('User 1 tries to transfer all the DAI used as collateral back to user 0 (revert expected)', async () => { - const {users, pool, aDai, dai, weth} = testEnv; + const { users, pool, aDai, dai, weth } = testEnv; const aDAItoTransfer = await convertToCurrencyDecimals(dai.address, '1000'); @@ -86,7 +86,7 @@ makeSuite('AToken: Transfer', (testEnv: TestEnv) => { }); it('User 1 tries to transfer a small amount of DAI used as collateral back to user 0', async () => { - const {users, pool, aDai, dai, weth} = testEnv; + const { users, pool, aDai, dai, weth } = testEnv; const aDAItoTransfer = await convertToCurrencyDecimals(dai.address, '100'); diff --git a/test/configurator.spec.ts b/test/configurator.spec.ts index e92b70bd..1d888db0 100644 --- a/test/configurator.spec.ts +++ b/test/configurator.spec.ts @@ -1,10 +1,10 @@ -import {TestEnv, makeSuite} from './helpers/make-suite'; -import {APPROVAL_AMOUNT_LENDING_POOL, RAY} from '../helpers/constants'; -import {convertToCurrencyDecimals} from '../helpers/contracts-helpers'; -import {ProtocolErrors} from '../helpers/types'; +import { TestEnv, makeSuite } from './helpers/make-suite'; +import { APPROVAL_AMOUNT_LENDING_POOL, RAY } from '../helpers/constants'; +import { convertToCurrencyDecimals } from '../helpers/contracts-helpers'; +import { ProtocolErrors } from '../helpers/types'; import { strategyWETH } from '../markets/aave/reservesConfigs'; -const {expect} = require('chai'); +const { expect } = require('chai'); makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => { const { @@ -18,7 +18,7 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => { } = ProtocolErrors; it('Reverts trying to set an invalid reserve factor', async () => { - const {configurator, weth} = testEnv; + const { configurator, weth } = testEnv; const invalidReserveFactor = 65536; @@ -28,22 +28,22 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => { }); it('Deactivates the ETH reserve', async () => { - const {configurator, weth, helpersContract} = testEnv; + const { configurator, weth, helpersContract } = testEnv; await configurator.deactivateReserve(weth.address); - const {isActive} = await helpersContract.getReserveConfigurationData(weth.address); + const { isActive } = await helpersContract.getReserveConfigurationData(weth.address); expect(isActive).to.be.equal(false); }); it('Rectivates the ETH reserve', async () => { - const {configurator, weth, helpersContract} = testEnv; + const { configurator, weth, helpersContract } = testEnv; await configurator.activateReserve(weth.address); - const {isActive} = await helpersContract.getReserveConfigurationData(weth.address); + const { isActive } = await helpersContract.getReserveConfigurationData(weth.address); expect(isActive).to.be.equal(true); }); it('Check the onlyAaveAdmin on deactivateReserve ', async () => { - const {configurator, users, weth} = testEnv; + const { configurator, users, weth } = testEnv; await expect( configurator.connect(users[2].signer).deactivateReserve(weth.address), CALLER_NOT_POOL_ADMIN @@ -51,7 +51,7 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => { }); it('Check the onlyAaveAdmin on activateReserve ', async () => { - const {configurator, users, weth} = testEnv; + const { configurator, users, weth } = testEnv; await expect( configurator.connect(users[2].signer).activateReserve(weth.address), CALLER_NOT_POOL_ADMIN @@ -59,9 +59,7 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => { }); it('Freezes the ETH reserve', async () => { - const {configurator, weth, helpersContract} = testEnv; - - + const { configurator, weth, helpersContract } = testEnv; await configurator.freezeReserve(weth.address); const { @@ -88,7 +86,7 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => { }); it('Unfreezes the ETH reserve', async () => { - const {configurator, helpersContract, weth} = testEnv; + const { configurator, helpersContract, weth } = testEnv; await configurator.unfreezeReserve(weth.address); const { @@ -115,7 +113,7 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => { }); it('Check the onlyAaveAdmin on freezeReserve ', async () => { - const {configurator, users, weth} = testEnv; + const { configurator, users, weth } = testEnv; await expect( configurator.connect(users[2].signer).freezeReserve(weth.address), CALLER_NOT_POOL_ADMIN @@ -123,7 +121,7 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => { }); it('Check the onlyAaveAdmin on unfreezeReserve ', async () => { - const {configurator, users, weth} = testEnv; + const { configurator, users, weth } = testEnv; await expect( configurator.connect(users[2].signer).unfreezeReserve(weth.address), CALLER_NOT_POOL_ADMIN @@ -131,7 +129,7 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => { }); it('Deactivates the ETH reserve for borrowing', async () => { - const {configurator, helpersContract, weth} = testEnv; + const { configurator, helpersContract, weth } = testEnv; await configurator.disableBorrowingOnReserve(weth.address); const { decimals, @@ -157,9 +155,9 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => { }); it('Activates the ETH reserve for borrowing', async () => { - const {configurator, weth, helpersContract} = testEnv; + const { configurator, weth, helpersContract } = testEnv; await configurator.enableBorrowingOnReserve(weth.address, true); - const {variableBorrowIndex} = await helpersContract.getReserveData(weth.address); + const { variableBorrowIndex } = await helpersContract.getReserveData(weth.address); const { decimals, @@ -187,7 +185,7 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => { }); it('Check the onlyAaveAdmin on disableBorrowingOnReserve ', async () => { - const {configurator, users, weth} = testEnv; + const { configurator, users, weth } = testEnv; await expect( configurator.connect(users[2].signer).disableBorrowingOnReserve(weth.address), CALLER_NOT_POOL_ADMIN @@ -195,7 +193,7 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => { }); it('Check the onlyAaveAdmin on enableBorrowingOnReserve ', async () => { - const {configurator, users, weth} = testEnv; + const { configurator, users, weth } = testEnv; await expect( configurator.connect(users[2].signer).enableBorrowingOnReserve(weth.address, true), CALLER_NOT_POOL_ADMIN @@ -203,7 +201,7 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => { }); it('Deactivates the ETH reserve as collateral', async () => { - const {configurator, helpersContract, weth} = testEnv; + const { configurator, helpersContract, weth } = testEnv; await configurator.configureReserveAsCollateral(weth.address, 0, 0, 0); const { @@ -230,7 +228,7 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => { }); it('Activates the ETH reserve as collateral', async () => { - const {configurator, helpersContract, weth} = testEnv; + const { configurator, helpersContract, weth } = testEnv; await configurator.configureReserveAsCollateral(weth.address, '8000', '8250', '10500'); const { @@ -257,7 +255,7 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => { }); it('Check the onlyAaveAdmin on configureReserveAsCollateral ', async () => { - const {configurator, users, weth} = testEnv; + const { configurator, users, weth } = testEnv; await expect( configurator .connect(users[2].signer) @@ -267,7 +265,7 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => { }); it('Disable stable borrow rate on the ETH reserve', async () => { - const {configurator, helpersContract, weth} = testEnv; + const { configurator, helpersContract, weth } = testEnv; await configurator.disableReserveStableRate(weth.address); const { decimals, @@ -293,7 +291,7 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => { }); it('Enables stable borrow rate on the ETH reserve', async () => { - const {configurator, helpersContract, weth} = testEnv; + const { configurator, helpersContract, weth } = testEnv; await configurator.enableReserveStableRate(weth.address); const { decimals, @@ -319,7 +317,7 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => { }); it('Check the onlyAaveAdmin on disableReserveStableRate', async () => { - const {configurator, users, weth} = testEnv; + const { configurator, users, weth } = testEnv; await expect( configurator.connect(users[2].signer).disableReserveStableRate(weth.address), CALLER_NOT_POOL_ADMIN @@ -327,7 +325,7 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => { }); it('Check the onlyAaveAdmin on enableReserveStableRate', async () => { - const {configurator, users, weth} = testEnv; + const { configurator, users, weth } = testEnv; await expect( configurator.connect(users[2].signer).enableReserveStableRate(weth.address), CALLER_NOT_POOL_ADMIN @@ -335,7 +333,7 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => { }); it('Changes the reserve factor of WETH', async () => { - const {configurator, helpersContract, weth} = testEnv; + const { configurator, helpersContract, weth } = testEnv; await configurator.setReserveFactor(weth.address, '1000'); const { decimals, @@ -361,7 +359,7 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => { }); it('Check the onlyLendingPoolManager on setReserveFactor', async () => { - const {configurator, users, weth} = testEnv; + const { configurator, users, weth } = testEnv; await expect( configurator.connect(users[2].signer).setReserveFactor(weth.address, '2000'), CALLER_NOT_POOL_ADMIN @@ -369,7 +367,7 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => { }); it('Reverts when trying to disable the DAI reserve with liquidity on it', async () => { - const {dai, pool, configurator} = testEnv; + const { dai, pool, configurator } = testEnv; const userAddress = await pool.signer.getAddress(); await dai.mint(await convertToCurrencyDecimals(dai.address, '1000')); diff --git a/test/flashloan.spec.ts b/test/flashloan.spec.ts index 7bfa2781..c6e5dcff 100644 --- a/test/flashloan.spec.ts +++ b/test/flashloan.spec.ts @@ -1,20 +1,20 @@ import BigNumber from 'bignumber.js'; -import {TestEnv, makeSuite} from './helpers/make-suite'; -import {APPROVAL_AMOUNT_LENDING_POOL, oneRay} from '../helpers/constants'; -import {convertToCurrencyDecimals, getContract} from '../helpers/contracts-helpers'; -import {ethers} from 'ethers'; -import {MockFlashLoanReceiver} from '../types/MockFlashLoanReceiver'; -import {ProtocolErrors, eContractid} from '../helpers/types'; -import {VariableDebtToken} from '../types/VariableDebtToken'; -import {StableDebtToken} from '../types/StableDebtToken'; +import { TestEnv, makeSuite } from './helpers/make-suite'; +import { APPROVAL_AMOUNT_LENDING_POOL, oneRay } from '../helpers/constants'; +import { convertToCurrencyDecimals, getContract } from '../helpers/contracts-helpers'; +import { ethers } from 'ethers'; +import { MockFlashLoanReceiver } from '../types/MockFlashLoanReceiver'; +import { ProtocolErrors, eContractid } from '../helpers/types'; +import { VariableDebtToken } from '../types/VariableDebtToken'; +import { StableDebtToken } from '../types/StableDebtToken'; import { getMockFlashLoanReceiver, getStableDebtToken, getVariableDebtToken, } from '../helpers/contracts-getters'; -const {expect} = require('chai'); +const { expect } = require('chai'); makeSuite('LendingPool FlashLoan function', (testEnv: TestEnv) => { let _mockFlashLoanReceiver = {} as MockFlashLoanReceiver; @@ -32,7 +32,7 @@ makeSuite('LendingPool FlashLoan function', (testEnv: TestEnv) => { }); it('Deposits WETH into the reserve', async () => { - const {pool, weth} = testEnv; + const { pool, weth } = testEnv; const userAddress = await pool.signer.getAddress(); const amountToDeposit = ethers.utils.parseEther('1'); @@ -44,7 +44,7 @@ makeSuite('LendingPool FlashLoan function', (testEnv: TestEnv) => { }); it('Takes WETH flashloan with mode = 0, returns the funds correctly', async () => { - const {pool, helpersContract, weth} = testEnv; + const { pool, helpersContract, weth } = testEnv; await pool.flashLoan( _mockFlashLoanReceiver.address, @@ -73,7 +73,7 @@ makeSuite('LendingPool FlashLoan function', (testEnv: TestEnv) => { }); it('Takes an ETH flashloan with mode = 0 as big as the available liquidity', async () => { - const {pool, helpersContract, weth} = testEnv; + const { pool, helpersContract, weth } = testEnv; const reserveDataBefore = await helpersContract.getReserveData(weth.address); const txResult = await pool.flashLoan( @@ -101,7 +101,7 @@ makeSuite('LendingPool FlashLoan function', (testEnv: TestEnv) => { }); it('Takes WETH flashloan, does not return the funds with mode = 0. (revert expected)', async () => { - const {pool, weth, users} = testEnv; + const { pool, weth, users } = testEnv; const caller = users[1]; await _mockFlashLoanReceiver.setFailExecutionTransfer(true); @@ -121,7 +121,7 @@ makeSuite('LendingPool FlashLoan function', (testEnv: TestEnv) => { }); it('Takes WETH flashloan, simulating a receiver as EOA (revert expected)', async () => { - const {pool, weth, users} = testEnv; + const { pool, weth, users } = testEnv; const caller = users[1]; await _mockFlashLoanReceiver.setFailExecutionTransfer(true); await _mockFlashLoanReceiver.setSimulateEOA(true); @@ -142,7 +142,7 @@ makeSuite('LendingPool FlashLoan function', (testEnv: TestEnv) => { }); it('Takes a WETH flashloan with an invalid mode. (revert expected)', async () => { - const {pool, weth, users} = testEnv; + const { pool, weth, users } = testEnv; const caller = users[1]; await _mockFlashLoanReceiver.setSimulateEOA(false); await _mockFlashLoanReceiver.setFailExecutionTransfer(true); @@ -163,7 +163,7 @@ makeSuite('LendingPool FlashLoan function', (testEnv: TestEnv) => { }); 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 () => { - const {dai, pool, weth, users, helpersContract} = testEnv; + const { dai, pool, weth, users, helpersContract } = testEnv; const caller = users[1]; @@ -188,7 +188,7 @@ makeSuite('LendingPool FlashLoan function', (testEnv: TestEnv) => { '0x10', '0' ); - const {variableDebtTokenAddress} = await helpersContract.getReserveTokensAddresses( + const { variableDebtTokenAddress } = await helpersContract.getReserveTokensAddresses( weth.address ); @@ -200,7 +200,7 @@ makeSuite('LendingPool FlashLoan function', (testEnv: TestEnv) => { }); it('tries to take a flashloan that is bigger than the available liquidity (revert expected)', async () => { - const {pool, weth, users} = testEnv; + const { pool, weth, users } = testEnv; const caller = users[1]; await expect( @@ -218,7 +218,7 @@ makeSuite('LendingPool FlashLoan function', (testEnv: TestEnv) => { }); it('tries to take a flashloan using a non contract address as receiver (revert expected)', async () => { - const {pool, deployer, weth, users} = testEnv; + const { pool, deployer, weth, users } = testEnv; const caller = users[1]; await expect( @@ -235,7 +235,7 @@ makeSuite('LendingPool FlashLoan function', (testEnv: TestEnv) => { }); it('Deposits USDC into the reserve', async () => { - const {usdc, pool} = testEnv; + const { usdc, pool } = testEnv; const userAddress = await pool.signer.getAddress(); await usdc.mint(await convertToCurrencyDecimals(usdc.address, '1000')); @@ -248,7 +248,7 @@ makeSuite('LendingPool FlashLoan function', (testEnv: TestEnv) => { }); it('Takes out a 500 USDC flashloan, returns the funds correctly', async () => { - const {usdc, pool, helpersContract, deployer: depositor} = testEnv; + const { usdc, pool, helpersContract, deployer: depositor } = testEnv; await _mockFlashLoanReceiver.setFailExecutionTransfer(false); @@ -268,7 +268,6 @@ makeSuite('LendingPool FlashLoan function', (testEnv: TestEnv) => { const reserveDataAfter = helpersContract.getReserveData(usdc.address); - const reserveData = await helpersContract.getReserveData(usdc.address); const userData = await helpersContract.getUserReserveData(usdc.address, depositor.address); @@ -292,7 +291,7 @@ makeSuite('LendingPool FlashLoan function', (testEnv: TestEnv) => { }); it('Takes out a 500 USDC flashloan with mode = 0, does not return the funds. (revert expected)', async () => { - const {usdc, pool, users} = testEnv; + const { usdc, pool, users } = testEnv; const caller = users[2]; const flashloanAmount = await convertToCurrencyDecimals(usdc.address, '500'); @@ -315,7 +314,7 @@ makeSuite('LendingPool FlashLoan function', (testEnv: TestEnv) => { }); 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 () => { - const {usdc, pool, weth, users, helpersContract} = testEnv; + const { usdc, pool, weth, users, helpersContract } = testEnv; const caller = users[2]; @@ -342,7 +341,7 @@ makeSuite('LendingPool FlashLoan function', (testEnv: TestEnv) => { '0x10', '0' ); - const {variableDebtTokenAddress} = await helpersContract.getReserveTokensAddresses( + const { variableDebtTokenAddress } = await helpersContract.getReserveTokensAddresses( usdc.address ); @@ -354,7 +353,7 @@ makeSuite('LendingPool FlashLoan function', (testEnv: TestEnv) => { }); it('Caller deposits 1000 DAI as collateral, Takes a WETH flashloan with mode = 0, does not approve the transfer of the funds', async () => { - const {dai, pool, weth, users} = testEnv; + const { dai, pool, weth, users } = testEnv; const caller = users[3]; await dai.connect(caller.signer).mint(await convertToCurrencyDecimals(dai.address, '1000')); @@ -386,7 +385,7 @@ makeSuite('LendingPool FlashLoan function', (testEnv: TestEnv) => { }); it('Caller takes a WETH flashloan with mode = 1', async () => { - const {dai, pool, weth, users, helpersContract} = testEnv; + const { dai, pool, weth, users, helpersContract } = testEnv; const caller = users[3]; @@ -406,7 +405,9 @@ makeSuite('LendingPool FlashLoan function', (testEnv: TestEnv) => { '0' ); - const {stableDebtTokenAddress} = await helpersContract.getReserveTokensAddresses(weth.address); + const { stableDebtTokenAddress } = await helpersContract.getReserveTokensAddresses( + weth.address + ); const wethDebtToken = await getStableDebtToken(stableDebtTokenAddress); @@ -416,7 +417,7 @@ makeSuite('LendingPool FlashLoan function', (testEnv: TestEnv) => { }); it('Caller takes a WETH flashloan with mode = 1 onBehalfOf user without allowance', async () => { - const {dai, pool, weth, users, helpersContract} = testEnv; + const { dai, pool, weth, users, helpersContract } = testEnv; const caller = users[5]; const onBehalfOf = users[4]; @@ -452,7 +453,7 @@ makeSuite('LendingPool FlashLoan function', (testEnv: TestEnv) => { }); it('Caller takes a WETH flashloan with mode = 1 onBehalfOf user with allowance. A loan for onBehalfOf is creatd.', async () => { - const {dai, pool, weth, users, helpersContract} = testEnv; + const { dai, pool, weth, users, helpersContract } = testEnv; const caller = users[5]; const onBehalfOf = users[4]; @@ -480,7 +481,9 @@ makeSuite('LendingPool FlashLoan function', (testEnv: TestEnv) => { '0' ); - const {stableDebtTokenAddress} = await helpersContract.getReserveTokensAddresses(weth.address); + const { stableDebtTokenAddress } = await helpersContract.getReserveTokensAddresses( + weth.address + ); const wethDebtToken = await getStableDebtToken(stableDebtTokenAddress); diff --git a/test/helpers/scenario-engine.ts b/test/helpers/scenario-engine.ts index bb4f82f8..92c686f4 100644 --- a/test/helpers/scenario-engine.ts +++ b/test/helpers/scenario-engine.ts @@ -1,4 +1,4 @@ -import {TestEnv, SignerWithAddress} from './make-suite'; +import { TestEnv, SignerWithAddress } from './make-suite'; import { mint, approve, @@ -11,7 +11,7 @@ import { rebalanceStableBorrowRate, delegateBorrowAllowance, } from './actions'; -import {RateMode} from '../../helpers/types'; +import { RateMode } from '../../helpers/types'; export interface Action { name: string; @@ -33,14 +33,14 @@ export interface Scenario { export const executeStory = async (story: Story, testEnv: TestEnv) => { for (const action of story.actions) { - const {users} = testEnv; + const { users } = testEnv; await executeAction(action, users, testEnv); } }; const executeAction = async (action: Action, users: SignerWithAddress[], testEnv: TestEnv) => { - const {reserve, user: userIndex, borrowRateMode} = action.args; - const {name, expected, revertMessage} = action; + const { reserve, user: userIndex, borrowRateMode } = action.args; + const { name, expected, revertMessage } = action; if (!name || name === '') { throw 'Action name is missing'; @@ -75,7 +75,7 @@ const executeAction = async (action: Action, users: SignerWithAddress[], testEnv switch (name) { case 'mint': - const {amount} = action.args; + const { amount } = action.args; if (!amount || amount === '') { throw `Invalid amount of ${reserve} to mint`; @@ -90,7 +90,7 @@ const executeAction = async (action: Action, users: SignerWithAddress[], testEnv case 'deposit': { - const {amount, sendValue, onBehalfOf: onBehalfOfIndex} = action.args; + const { amount, sendValue, onBehalfOf: onBehalfOfIndex } = action.args; const onBehalfOf = onBehalfOfIndex ? users[parseInt(onBehalfOfIndex)].address : user.address; @@ -114,7 +114,7 @@ const executeAction = async (action: Action, users: SignerWithAddress[], testEnv case 'delegateBorrowAllowance': { - const {amount, toUser: toUserIndex} = action.args; + const { amount, toUser: toUserIndex } = action.args; const toUser = users[parseInt(toUserIndex, 10)].address; if (!amount || amount === '') { throw `Invalid amount to deposit into the ${reserve} reserve`; @@ -135,7 +135,7 @@ const executeAction = async (action: Action, users: SignerWithAddress[], testEnv case 'withdraw': { - const {amount} = action.args; + const { amount } = action.args; if (!amount || amount === '') { throw `Invalid amount to withdraw from the ${reserve} reserve`; @@ -146,7 +146,7 @@ const executeAction = async (action: Action, users: SignerWithAddress[], testEnv break; case 'borrow': { - const {amount, timeTravel, onBehalfOf: onBehalfOfIndex} = action.args; + const { amount, timeTravel, onBehalfOf: onBehalfOfIndex } = action.args; const onBehalfOf = onBehalfOfIndex ? users[parseInt(onBehalfOfIndex)].address @@ -172,8 +172,8 @@ const executeAction = async (action: Action, users: SignerWithAddress[], testEnv case 'repay': { - const {amount, borrowRateMode, sendValue} = action.args; - let {onBehalfOf: onBehalfOfIndex} = action.args; + const { amount, borrowRateMode, sendValue } = action.args; + let { onBehalfOf: onBehalfOfIndex } = action.args; if (!amount || amount === '') { throw `Invalid amount to repay into the ${reserve} reserve`; @@ -205,7 +205,7 @@ const executeAction = async (action: Action, users: SignerWithAddress[], testEnv case 'setUseAsCollateral': { - const {useAsCollateral} = action.args; + const { useAsCollateral } = action.args; if (!useAsCollateral || useAsCollateral === '') { throw `A valid value for useAsCollateral needs to be set when calling setUseReserveAsCollateral on reserve ${reserve}`; @@ -220,7 +220,7 @@ const executeAction = async (action: Action, users: SignerWithAddress[], testEnv case 'rebalanceStableBorrowRate': { - const {target: targetIndex} = action.args; + const { target: targetIndex } = action.args; if (!targetIndex || targetIndex === '') { throw `A target must be selected when trying to rebalance a stable rate`; diff --git a/test/helpers/utils/math.ts b/test/helpers/utils/math.ts index 66be629c..efd296e0 100644 --- a/test/helpers/utils/math.ts +++ b/test/helpers/utils/math.ts @@ -1,5 +1,13 @@ import BigNumber from 'bignumber.js'; -import {RAY, WAD, HALF_RAY, HALF_WAD, WAD_RAY_RATIO, HALF_PERCENTAGE, PERCENTAGE_FACTOR} from '../../../helpers/constants'; +import { + RAY, + WAD, + HALF_RAY, + HALF_WAD, + WAD_RAY_RATIO, + HALF_PERCENTAGE, + PERCENTAGE_FACTOR, +} from '../../../helpers/constants'; declare module 'bignumber.js' { interface BigNumber { @@ -68,19 +76,22 @@ BigNumber.prototype.wadToRay = function (): BigNumber { return this.multipliedBy(WAD_RAY_RATIO).decimalPlaces(0, BigNumber.ROUND_DOWN); }; - - - BigNumber.prototype.halfPercentage = (): BigNumber => { return new BigNumber(HALF_PERCENTAGE).decimalPlaces(0, BigNumber.ROUND_DOWN); }; BigNumber.prototype.percentMul = function (b: BigNumber): BigNumber { - return this.halfPercentage().plus(this.multipliedBy(b)).div(PERCENTAGE_FACTOR).decimalPlaces(0, BigNumber.ROUND_DOWN); + return this.halfPercentage() + .plus(this.multipliedBy(b)) + .div(PERCENTAGE_FACTOR) + .decimalPlaces(0, BigNumber.ROUND_DOWN); }; BigNumber.prototype.percentDiv = function (a: BigNumber): BigNumber { const halfA = a.div(2).decimalPlaces(0, BigNumber.ROUND_DOWN); - return halfA.plus(this.multipliedBy(PERCENTAGE_FACTOR)).div(a).decimalPlaces(0, BigNumber.ROUND_DOWN); -}; \ No newline at end of file + return halfA + .plus(this.multipliedBy(PERCENTAGE_FACTOR)) + .div(a) + .decimalPlaces(0, BigNumber.ROUND_DOWN); +}; diff --git a/test/lending-pool-addresses-provider.spec.ts b/test/lending-pool-addresses-provider.spec.ts index f87ccaf1..48570458 100644 --- a/test/lending-pool-addresses-provider.spec.ts +++ b/test/lending-pool-addresses-provider.spec.ts @@ -1,19 +1,19 @@ -import {expect} from 'chai'; -import {createRandomAddress} from '../helpers/misc-utils'; -import {makeSuite, TestEnv} from './helpers/make-suite'; -import {ProtocolErrors} from '../helpers/types'; -import {ethers} from 'ethers'; -import {ZERO_ADDRESS} from '../helpers/constants'; -import {waitForTx} from '../helpers/misc-utils'; -import {deployLendingPool} from '../helpers/contracts-deployments'; +import { expect } from 'chai'; +import { createRandomAddress } from '../helpers/misc-utils'; +import { makeSuite, TestEnv } from './helpers/make-suite'; +import { ProtocolErrors } from '../helpers/types'; +import { ethers } from 'ethers'; +import { ZERO_ADDRESS } from '../helpers/constants'; +import { waitForTx } from '../helpers/misc-utils'; +import { deployLendingPool } from '../helpers/contracts-deployments'; -const {utils} = ethers; +const { utils } = ethers; makeSuite('LendingPoolAddressesProvider', (testEnv: TestEnv) => { it('Test the accessibility of the LendingPoolAddressesProvider', async () => { - const {addressesProvider, users} = testEnv; + const { addressesProvider, users } = testEnv; const mockAddress = createRandomAddress(); - const {INVALID_OWNER_REVERT_MSG} = ProtocolErrors; + const { INVALID_OWNER_REVERT_MSG } = ProtocolErrors; await addressesProvider.transferOwnership(users[1].address); @@ -30,10 +30,7 @@ makeSuite('LendingPoolAddressesProvider', (testEnv: TestEnv) => { } await expect( - addressesProvider.setAddress( - utils.keccak256(utils.toUtf8Bytes('RANDOM_ID')), - mockAddress - ) + addressesProvider.setAddress(utils.keccak256(utils.toUtf8Bytes('RANDOM_ID')), mockAddress) ).to.be.revertedWith(INVALID_OWNER_REVERT_MSG); await expect( @@ -42,16 +39,14 @@ makeSuite('LendingPoolAddressesProvider', (testEnv: TestEnv) => { mockAddress ) ).to.be.revertedWith(INVALID_OWNER_REVERT_MSG); - }); it('Tests adding a proxied address with `setAddressAsProxy()`', async () => { - const {addressesProvider, users} = testEnv; - const {INVALID_OWNER_REVERT_MSG} = ProtocolErrors; + const { addressesProvider, users } = testEnv; + const { INVALID_OWNER_REVERT_MSG } = ProtocolErrors; const currentAddressesProviderOwner = users[1]; - const mockLendingPool = await deployLendingPool(); const proxiedAddressId = utils.keccak256(utils.toUtf8Bytes('RANDOM_PROXIED')); @@ -74,10 +69,9 @@ makeSuite('LendingPoolAddressesProvider', (testEnv: TestEnv) => { expect(proxiedAddressSetReceipt.events[1].args?.hasProxy).to.be.equal(true); }); - it('Tests adding a non proxied address with `setAddress()`', async () => { - const {addressesProvider, users} = testEnv; - const {INVALID_OWNER_REVERT_MSG} = ProtocolErrors; + const { addressesProvider, users } = testEnv; + const { INVALID_OWNER_REVERT_MSG } = ProtocolErrors; const currentAddressesProviderOwner = users[1]; const mockNonProxiedAddress = createRandomAddress(); @@ -103,6 +97,5 @@ makeSuite('LendingPoolAddressesProvider', (testEnv: TestEnv) => { mockNonProxiedAddress ); expect(nonProxiedAddressSetReceipt.events[0].args?.hasProxy).to.be.equal(false); - }); }); diff --git a/test/liquidation-underlying.spec.ts b/test/liquidation-underlying.spec.ts index 3d28eaa1..0e37d331 100644 --- a/test/liquidation-underlying.spec.ts +++ b/test/liquidation-underlying.spec.ts @@ -1,33 +1,33 @@ import BigNumber from 'bignumber.js'; -import {DRE, increaseTime} from '../helpers/misc-utils'; -import {APPROVAL_AMOUNT_LENDING_POOL, oneEther} from '../helpers/constants'; -import {convertToCurrencyDecimals} from '../helpers/contracts-helpers'; -import {makeSuite} from './helpers/make-suite'; -import {ProtocolErrors, RateMode} from '../helpers/types'; -import {calcExpectedStableDebtTokenBalance} from './helpers/utils/calculations'; -import {getUserData} from './helpers/utils/helpers'; -import {CommonsConfig} from '../markets/aave/commons'; +import { DRE, increaseTime } from '../helpers/misc-utils'; +import { APPROVAL_AMOUNT_LENDING_POOL, oneEther } from '../helpers/constants'; +import { convertToCurrencyDecimals } from '../helpers/contracts-helpers'; +import { makeSuite } from './helpers/make-suite'; +import { ProtocolErrors, RateMode } from '../helpers/types'; +import { calcExpectedStableDebtTokenBalance } from './helpers/utils/calculations'; +import { getUserData } from './helpers/utils/helpers'; +import { CommonsConfig } from '../markets/aave/commons'; -import {parseEther} from 'ethers/lib/utils'; +import { parseEther } from 'ethers/lib/utils'; const chai = require('chai'); -const {expect} = chai; +const { expect } = chai; makeSuite('LendingPool liquidation - liquidator receiving the underlying asset', (testEnv) => { - const {INVALID_HF} = ProtocolErrors; + const { INVALID_HF } = ProtocolErrors; before('Before LendingPool liquidation: set config', () => { - BigNumber.config({DECIMAL_PLACES: 0, ROUNDING_MODE: BigNumber.ROUND_DOWN}); + BigNumber.config({ DECIMAL_PLACES: 0, ROUNDING_MODE: BigNumber.ROUND_DOWN }); }); after('After LendingPool liquidation: reset config', () => { - BigNumber.config({DECIMAL_PLACES: 20, ROUNDING_MODE: BigNumber.ROUND_HALF_UP}); + BigNumber.config({ DECIMAL_PLACES: 20, ROUNDING_MODE: BigNumber.ROUND_HALF_UP }); }); it("It's not possible to liquidate on a non-active collateral or a non active principal", async () => { - const {configurator, weth, pool, users, dai} = testEnv; + const { configurator, weth, pool, users, dai } = testEnv; const user = users[1]; await configurator.deactivateReserve(weth.address); @@ -47,7 +47,7 @@ makeSuite('LendingPool liquidation - liquidator receiving the underlying asset', }); it('Deposits WETH, borrows DAI', async () => { - const {dai, weth, users, pool, oracle} = testEnv; + const { dai, weth, users, pool, oracle } = testEnv; const depositor = users[0]; const borrower = users[1]; @@ -102,7 +102,7 @@ makeSuite('LendingPool liquidation - liquidator receiving the underlying asset', }); it('Drop the health factor below 1', async () => { - const {dai, weth, users, pool, oracle} = testEnv; + const { dai, weth, users, pool, oracle } = testEnv; const borrower = users[1]; const daiPrice = await oracle.getAssetPrice(dai.address); @@ -121,7 +121,7 @@ makeSuite('LendingPool liquidation - liquidator receiving the underlying asset', }); it('Liquidates the borrow', async () => { - const {dai, weth, users, pool, oracle, helpersContract} = testEnv; + const { dai, weth, users, pool, oracle, helpersContract } = testEnv; const liquidator = users[3]; const borrower = users[1]; @@ -226,7 +226,7 @@ makeSuite('LendingPool liquidation - liquidator receiving the underlying asset', }); it('User 3 deposits 1000 USDC, user 4 1 WETH, user 4 borrows - drops HF, liquidates the borrow', async () => { - const {usdc, users, pool, oracle, weth, helpersContract} = testEnv; + const { usdc, users, pool, oracle, weth, helpersContract } = testEnv; const depositor = users[3]; const borrower = users[4]; @@ -379,7 +379,7 @@ makeSuite('LendingPool liquidation - liquidator receiving the underlying asset', }); it('User 4 deposits 10 AAVE - drops HF, liquidates the AAVE, which results on a lower amount being liquidated', async () => { - const {aave, usdc, users, pool, oracle, helpersContract} = testEnv; + const { aave, usdc, users, pool, oracle, helpersContract } = testEnv; const depositor = users[3]; const borrower = users[4]; diff --git a/test/mainnet/check-list.spec.ts b/test/mainnet/check-list.spec.ts index b6b30bc1..99020fa2 100644 --- a/test/mainnet/check-list.spec.ts +++ b/test/mainnet/check-list.spec.ts @@ -99,7 +99,7 @@ makeSuite('Mainnet Check list', (testEnv: TestEnv) => { }); it('Borrow stable WETH and Full Repay with ETH', async () => { - const { users, wethGateway, aWETH, weth, pool, helpersContract } = testEnv; + const { users, wethGateway, aWETH, dai, aDai, weth, pool, helpersContract } = testEnv; const borrowSize = parseEther('1'); const repaySize = borrowSize.add(borrowSize.mul(5).div(100)); const user = users[1]; diff --git a/test/pausable-functions.spec.ts b/test/pausable-functions.spec.ts index 56278f66..2ac975ac 100644 --- a/test/pausable-functions.spec.ts +++ b/test/pausable-functions.spec.ts @@ -1,13 +1,13 @@ -import {makeSuite, TestEnv} from './helpers/make-suite'; -import {ProtocolErrors, RateMode} from '../helpers/types'; -import {APPROVAL_AMOUNT_LENDING_POOL, oneEther} from '../helpers/constants'; -import {convertToCurrencyDecimals} from '../helpers/contracts-helpers'; -import {parseEther, parseUnits} from 'ethers/lib/utils'; -import {BigNumber} from 'bignumber.js'; -import {MockFlashLoanReceiver} from '../types/MockFlashLoanReceiver'; -import {getMockFlashLoanReceiver} from '../helpers/contracts-getters'; +import { makeSuite, TestEnv } from './helpers/make-suite'; +import { ProtocolErrors, RateMode } from '../helpers/types'; +import { APPROVAL_AMOUNT_LENDING_POOL, oneEther } from '../helpers/constants'; +import { convertToCurrencyDecimals } from '../helpers/contracts-helpers'; +import { parseEther, parseUnits } from 'ethers/lib/utils'; +import { BigNumber } from 'bignumber.js'; +import { MockFlashLoanReceiver } from '../types/MockFlashLoanReceiver'; +import { getMockFlashLoanReceiver } from '../helpers/contracts-getters'; -const {expect} = require('chai'); +const { expect } = require('chai'); makeSuite('Pausable Pool', (testEnv: TestEnv) => { let _mockFlashLoanReceiver = {} as MockFlashLoanReceiver; @@ -23,7 +23,7 @@ makeSuite('Pausable Pool', (testEnv: TestEnv) => { }); it('User 0 deposits 1000 DAI. Configurator pauses pool. Transfers to user 1 reverts. Configurator unpauses the network and next transfer succees', async () => { - const {users, pool, dai, aDai, configurator} = testEnv; + const { users, pool, dai, aDai, configurator } = testEnv; const amountDAItoDeposit = await convertToCurrencyDecimals(dai.address, '1000'); @@ -78,7 +78,7 @@ makeSuite('Pausable Pool', (testEnv: TestEnv) => { }); it('Deposit', async () => { - const {users, pool, dai, aDai, configurator} = testEnv; + const { users, pool, dai, aDai, configurator } = testEnv; const amountDAItoDeposit = await convertToCurrencyDecimals(dai.address, '1000'); @@ -98,7 +98,7 @@ makeSuite('Pausable Pool', (testEnv: TestEnv) => { }); it('Withdraw', async () => { - const {users, pool, dai, aDai, configurator} = testEnv; + const { users, pool, dai, aDai, configurator } = testEnv; const amountDAItoDeposit = await convertToCurrencyDecimals(dai.address, '1000'); @@ -123,7 +123,7 @@ makeSuite('Pausable Pool', (testEnv: TestEnv) => { }); it('Borrow', async () => { - const {pool, dai, users, configurator} = testEnv; + const { pool, dai, users, configurator } = testEnv; const user = users[1]; // Pause the pool @@ -139,7 +139,7 @@ makeSuite('Pausable Pool', (testEnv: TestEnv) => { }); it('Repay', async () => { - const {pool, dai, users, configurator} = testEnv; + const { pool, dai, users, configurator } = testEnv; const user = users[1]; // Pause the pool @@ -155,7 +155,7 @@ makeSuite('Pausable Pool', (testEnv: TestEnv) => { }); it('Flash loan', async () => { - const {dai, pool, weth, users, configurator} = testEnv; + const { dai, pool, weth, users, configurator } = testEnv; const caller = users[3]; @@ -185,7 +185,7 @@ makeSuite('Pausable Pool', (testEnv: TestEnv) => { }); it('Liquidation call', async () => { - const {users, pool, usdc, oracle, weth, configurator, helpersContract} = testEnv; + const { users, pool, usdc, oracle, weth, configurator, helpersContract } = testEnv; const depositor = users[3]; const borrower = users[4]; @@ -266,7 +266,7 @@ makeSuite('Pausable Pool', (testEnv: TestEnv) => { }); it('SwapBorrowRateMode', async () => { - const {pool, weth, dai, usdc, users, configurator} = testEnv; + const { pool, weth, dai, usdc, users, configurator } = testEnv; const user = users[1]; const amountWETHToDeposit = parseEther('10'); const amountDAIToDeposit = parseEther('120'); @@ -295,7 +295,7 @@ makeSuite('Pausable Pool', (testEnv: TestEnv) => { }); it('RebalanceStableBorrowRate', async () => { - const {pool, dai, users, configurator} = testEnv; + const { pool, dai, users, configurator } = testEnv; const user = users[1]; // Pause pool await configurator.connect(users[1].signer).setPoolPause(true); @@ -309,7 +309,7 @@ makeSuite('Pausable Pool', (testEnv: TestEnv) => { }); it('setUserUseReserveAsCollateral', async () => { - const {pool, weth, users, configurator} = testEnv; + const { pool, weth, users, configurator } = testEnv; const user = users[1]; const amountWETHToDeposit = parseEther('1'); diff --git a/test/stable-token.spec.ts b/test/stable-token.spec.ts index 1f58965f..ab588a81 100644 --- a/test/stable-token.spec.ts +++ b/test/stable-token.spec.ts @@ -1,13 +1,13 @@ -import {expect} from 'chai'; -import {makeSuite, TestEnv} from './helpers/make-suite'; -import {ProtocolErrors} from '../helpers/types'; -import {getStableDebtToken} from '../helpers/contracts-getters'; +import { expect } from 'chai'; +import { makeSuite, TestEnv } from './helpers/make-suite'; +import { ProtocolErrors } from '../helpers/types'; +import { getStableDebtToken } from '../helpers/contracts-getters'; makeSuite('Stable debt token tests', (testEnv: TestEnv) => { - const {CT_CALLER_MUST_BE_LENDING_POOL} = ProtocolErrors; + const { CT_CALLER_MUST_BE_LENDING_POOL } = ProtocolErrors; it('Tries to invoke mint not being the LendingPool', async () => { - const {deployer, pool, dai, helpersContract} = testEnv; + const { deployer, pool, dai, helpersContract } = testEnv; const daiStableDebtTokenAddress = (await helpersContract.getReserveTokensAddresses(dai.address)) .stableDebtTokenAddress; @@ -20,7 +20,7 @@ makeSuite('Stable debt token tests', (testEnv: TestEnv) => { }); it('Tries to invoke burn not being the LendingPool', async () => { - const {deployer, dai, helpersContract} = testEnv; + const { deployer, dai, helpersContract } = testEnv; const daiStableDebtTokenAddress = (await helpersContract.getReserveTokensAddresses(dai.address)) .stableDebtTokenAddress; diff --git a/test/subgraph-scenarios.spec.ts b/test/subgraph-scenarios.spec.ts index c756ce50..27f0b994 100644 --- a/test/subgraph-scenarios.spec.ts +++ b/test/subgraph-scenarios.spec.ts @@ -1,11 +1,11 @@ -import {configuration as actionsConfiguration} from './helpers/actions'; -import {configuration as calculationsConfiguration} from './helpers/utils/calculations'; +import { configuration as actionsConfiguration } from './helpers/actions'; +import { configuration as calculationsConfiguration } from './helpers/utils/calculations'; import BigNumber from 'bignumber.js'; -import {makeSuite} from './helpers/make-suite'; -import {getReservesConfigByPool} from '../helpers/configuration'; -import {AavePools, iAavePoolAssets, IReserveParams} from '../helpers/types'; -import {executeStory} from './helpers/scenario-engine'; +import { makeSuite } from './helpers/make-suite'; +import { getReservesConfigByPool } from '../helpers/configuration'; +import { AavePools, iAavePoolAssets, IReserveParams } from '../helpers/types'; +import { executeStory } from './helpers/scenario-engine'; makeSuite('Subgraph scenario tests', async (testEnv) => { let story: any; @@ -14,7 +14,7 @@ makeSuite('Subgraph scenario tests', async (testEnv) => { const scenario = require(`./helpers/scenarios/borrow-repay-stable`); story = scenario.stories[0]; // Sets BigNumber for this suite, instead of globally - BigNumber.config({DECIMAL_PLACES: 0, ROUNDING_MODE: BigNumber.ROUND_DOWN}); + BigNumber.config({ DECIMAL_PLACES: 0, ROUNDING_MODE: BigNumber.ROUND_DOWN }); actionsConfiguration.skipIntegrityCheck = false; //set this to true to execute solidity-coverage @@ -24,7 +24,7 @@ makeSuite('Subgraph scenario tests', async (testEnv) => { }); after('Reset', () => { // Reset BigNumber - BigNumber.config({DECIMAL_PLACES: 20, ROUNDING_MODE: BigNumber.ROUND_HALF_UP}); + BigNumber.config({ DECIMAL_PLACES: 20, ROUNDING_MODE: BigNumber.ROUND_HALF_UP }); }); it('deposit-borrow', async () => { await executeStory(story, testEnv); diff --git a/test/upgradeability.spec.ts b/test/upgradeability.spec.ts index 92ab1ee1..28e1c335 100644 --- a/test/upgradeability.spec.ts +++ b/test/upgradeability.spec.ts @@ -1,11 +1,11 @@ -import {expect} from 'chai'; -import {makeSuite, TestEnv} from './helpers/make-suite'; -import {ProtocolErrors, eContractid} from '../helpers/types'; -import {deployContract, getContract} from '../helpers/contracts-helpers'; -import {MockAToken} from '../types/MockAToken'; -import {MockStableDebtToken} from '../types/MockStableDebtToken'; -import {MockVariableDebtToken} from '../types/MockVariableDebtToken'; -import {ZERO_ADDRESS} from '../helpers/constants'; +import { expect } from 'chai'; +import { makeSuite, TestEnv } from './helpers/make-suite'; +import { ProtocolErrors, eContractid } from '../helpers/types'; +import { deployContract, getContract } from '../helpers/contracts-helpers'; +import { MockAToken } from '../types/MockAToken'; +import { MockStableDebtToken } from '../types/MockStableDebtToken'; +import { MockVariableDebtToken } from '../types/MockVariableDebtToken'; +import { ZERO_ADDRESS } from '../helpers/constants'; import { getAToken, getMockStableDebtToken, @@ -19,13 +19,13 @@ import { } from '../helpers/contracts-deployments'; makeSuite('Upgradeability', (testEnv: TestEnv) => { - const {CALLER_NOT_POOL_ADMIN} = ProtocolErrors; + const { CALLER_NOT_POOL_ADMIN } = ProtocolErrors; let newATokenAddress: string; let newStableTokenAddress: string; let newVariableTokenAddress: string; before('deploying instances', async () => { - const {dai, pool} = testEnv; + const { dai, pool } = testEnv; const aTokenInstance = await deployMockAToken([ pool.address, dai.address, @@ -57,7 +57,7 @@ makeSuite('Upgradeability', (testEnv: TestEnv) => { }); it('Tries to update the DAI Atoken implementation with a different address than the lendingPoolManager', async () => { - const {dai, configurator, users} = testEnv; + const { dai, configurator, users } = testEnv; await expect( configurator.connect(users[1].signer).updateAToken(dai.address, newATokenAddress) @@ -65,7 +65,7 @@ makeSuite('Upgradeability', (testEnv: TestEnv) => { }); it('Upgrades the DAI Atoken implementation ', async () => { - const {dai, configurator, aDai} = testEnv; + const { dai, configurator, aDai } = testEnv; const name = await (await getAToken(newATokenAddress)).name(); @@ -77,7 +77,7 @@ makeSuite('Upgradeability', (testEnv: TestEnv) => { }); it('Tries to update the DAI Stable debt token implementation with a different address than the lendingPoolManager', async () => { - const {dai, configurator, users} = testEnv; + const { dai, configurator, users } = testEnv; await expect( configurator @@ -87,13 +87,13 @@ makeSuite('Upgradeability', (testEnv: TestEnv) => { }); it('Upgrades the DAI stable debt token implementation ', async () => { - const {dai, configurator, pool, helpersContract} = testEnv; + const { dai, configurator, pool, helpersContract } = testEnv; const name = await (await getAToken(newATokenAddress)).name(); await configurator.updateStableDebtToken(dai.address, newStableTokenAddress); - const {stableDebtTokenAddress} = await helpersContract.getReserveTokensAddresses(dai.address); + const { stableDebtTokenAddress } = await helpersContract.getReserveTokensAddresses(dai.address); const debtToken = await getMockStableDebtToken(stableDebtTokenAddress); @@ -103,7 +103,7 @@ makeSuite('Upgradeability', (testEnv: TestEnv) => { }); it('Tries to update the DAI variable debt token implementation with a different address than the lendingPoolManager', async () => { - const {dai, configurator, users} = testEnv; + const { dai, configurator, users } = testEnv; await expect( configurator @@ -113,13 +113,15 @@ makeSuite('Upgradeability', (testEnv: TestEnv) => { }); it('Upgrades the DAI variable debt token implementation ', async () => { - const {dai, configurator, pool, helpersContract} = testEnv; + const { dai, configurator, pool, helpersContract } = testEnv; const name = await (await getAToken(newATokenAddress)).name(); await configurator.updateVariableDebtToken(dai.address, newVariableTokenAddress); - const {variableDebtTokenAddress} = await helpersContract.getReserveTokensAddresses(dai.address); + const { variableDebtTokenAddress } = await helpersContract.getReserveTokensAddresses( + dai.address + ); const debtToken = await getMockVariableDebtToken(variableDebtTokenAddress); diff --git a/test/variable-debt-token.spec.ts b/test/variable-debt-token.spec.ts index 71dbecd2..0faf7087 100644 --- a/test/variable-debt-token.spec.ts +++ b/test/variable-debt-token.spec.ts @@ -1,13 +1,13 @@ -import {expect} from 'chai'; -import {makeSuite, TestEnv} from './helpers/make-suite'; -import {ProtocolErrors, TokenContractId, eContractid} from '../helpers/types'; -import {getVariableDebtToken} from '../helpers/contracts-getters'; +import { expect } from 'chai'; +import { makeSuite, TestEnv } from './helpers/make-suite'; +import { ProtocolErrors, TokenContractId, eContractid } from '../helpers/types'; +import { getVariableDebtToken } from '../helpers/contracts-getters'; makeSuite('Variable debt token tests', (testEnv: TestEnv) => { - const {CT_CALLER_MUST_BE_LENDING_POOL} = ProtocolErrors; + const { CT_CALLER_MUST_BE_LENDING_POOL } = ProtocolErrors; it('Tries to invoke mint not being the LendingPool', async () => { - const {deployer, pool, dai, helpersContract} = testEnv; + const { deployer, pool, dai, helpersContract } = testEnv; const daiVariableDebtTokenAddress = ( await helpersContract.getReserveTokensAddresses(dai.address) @@ -21,7 +21,7 @@ makeSuite('Variable debt token tests', (testEnv: TestEnv) => { }); it('Tries to invoke burn not being the LendingPool', async () => { - const {deployer, pool, dai, helpersContract} = testEnv; + const { deployer, pool, dai, helpersContract } = testEnv; const daiVariableDebtTokenAddress = ( await helpersContract.getReserveTokensAddresses(dai.address) diff --git a/test/weth-gateway.spec.ts b/test/weth-gateway.spec.ts index 1b3f93ea..eadf9703 100644 --- a/test/weth-gateway.spec.ts +++ b/test/weth-gateway.spec.ts @@ -14,7 +14,7 @@ makeSuite('Use native ETH at LendingPool via WETHGateway', (testEnv: TestEnv) => const depositSize = parseEther('5'); const daiSize = parseEther('10000'); it('Deposit WETH via WethGateway and DAI', async () => { - const { users, wethGateway, aWETH, dai, pool } = testEnv; + const { users, wethGateway, aWETH } = testEnv; const user = users[1]; const depositor = users[0];