Merge branch '198-add-lint-ci-ctep-to-reject-unformatted-code' into 'master'

Add lint CI ctep to reject unformatted code

See merge request aave-tech/protocol-v2!225
This commit is contained in:
Ernesto Boado 2021-01-28 13:32:39 +00:00
commit b029c9436e
56 changed files with 2108 additions and 3715 deletions

View File

@ -1,6 +1,18 @@
stages:
- checks
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
tags:

View File

@ -441,7 +441,7 @@ abstract contract BaseUniswapAdapter is FlashLoanReceiverBase, IBaseUniswapAdapt
uint256 reserveDecimals = _getDecimals(reserveIn);
address[] memory path = new address[](1);
path[0] = reserveIn;
return
AmountCalc(
amountIn,

View File

@ -187,16 +187,16 @@ contract UniswapLiquiditySwapAdapter is BaseUniswapAdapter {
* @param permitSignature List of struct containing the permit signature
* @param useEthPath true if the swap needs to occur using ETH in the routing, false otherwise
*/
struct SwapLiquidityLocalVars {
address aToken;
uint256 aTokenInitiatorBalance;
uint256 amountToSwap;
uint256 receivedAmount;
uint256 flashLoanDebt;
uint256 amountToPull;
address aToken;
uint256 aTokenInitiatorBalance;
uint256 amountToSwap;
uint256 receivedAmount;
uint256 flashLoanDebt;
uint256 amountToPull;
}
function _swapLiquidity(
address assetFrom,
address assetTo,
@ -208,19 +208,22 @@ contract UniswapLiquiditySwapAdapter is BaseUniswapAdapter {
PermitSignature memory permitSignature,
bool useEthPath
) internal {
SwapLiquidityLocalVars memory vars;
vars.aToken = _getReserveData(assetFrom).aTokenAddress;
vars.aTokenInitiatorBalance = IERC20(vars.aToken).balanceOf(initiator);
vars.amountToSwap =
swapAllBalance && vars.aTokenInitiatorBalance.sub(premium) <= amount
? vars.aTokenInitiatorBalance.sub(premium)
: amount;
vars.amountToSwap = swapAllBalance && vars.aTokenInitiatorBalance.sub(premium) <= amount
? vars.aTokenInitiatorBalance.sub(premium)
: amount;
vars.receivedAmount =
_swapExactTokensForTokens(assetFrom, assetTo, vars.amountToSwap, minAmountToReceive, useEthPath);
vars.receivedAmount = _swapExactTokensForTokens(
assetFrom,
assetTo,
vars.amountToSwap,
minAmountToReceive,
useEthPath
);
// Deposit new reserve
IERC20(assetTo).safeApprove(address(LENDING_POOL), 0);
@ -277,4 +280,4 @@ contract UniswapLiquiditySwapAdapter is BaseUniswapAdapter {
useEthPath
);
}
}
}

View File

@ -200,7 +200,13 @@ contract UniswapRepayAdapter is BaseUniswapAdapter {
);
// Swap collateral asset to the debt asset
_swapTokensForExactTokens(collateralAsset, debtAsset, amounts[0], neededForFlashLoanDebt, useEthPath);
_swapTokensForExactTokens(
collateralAsset,
debtAsset,
amounts[0],
neededForFlashLoanDebt,
useEthPath
);
} else {
// Pull aTokens from user
_pullAToken(
@ -256,4 +262,4 @@ contract UniswapRepayAdapter is BaseUniswapAdapter {
useEthPath
);
}
}
}

View File

@ -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;
}

View File

@ -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];

View File

@ -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.

View File

@ -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 {

View File

@ -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.

View File

@ -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]);
}
}

View File

@ -11,14 +11,20 @@ interface IUniswapV2Router02 {
) external returns (uint256[] memory amounts);
function swapTokensForExactTokens(
uint amountOut,
uint amountInMax,
uint256 amountOut,
uint256 amountInMax,
address[] calldata path,
address to,
uint deadline
uint256 deadline
) external returns (uint256[] memory amounts);
function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts);
function getAmountsOut(uint256 amountIn, address[] calldata path)
external
view
returns (uint256[] memory amounts);
function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts);
function getAmountsIn(uint256 amountOut, address[] calldata path)
external
view
returns (uint256[] memory amounts);
}

View File

@ -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) {

View File

@ -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();

View File

@ -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]);

View File

@ -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];
}

View File

@ -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];
}

View File

@ -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);

View File

@ -144,7 +144,7 @@ contract LendingPool is VersionedInitializable, ILendingPool, LendingPoolStorage
address asset,
uint256 amount,
address to
) external override whenNotPaused returns (uint256) {
) external override whenNotPaused returns (uint256) {
DataTypes.ReserveData storage reserve = _reserves[asset];
address aToken = reserve.aTokenAddress;

View File

@ -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

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;

View File

@ -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',
});

View File

@ -2,13 +2,13 @@ import BigNumber from 'bignumber.js';
import BN = require('bn.js');
import low from 'lowdb';
import FileSync from 'lowdb/adapters/FileSync';
import {WAD} from './constants';
import {Wallet, ContractTransaction} from 'ethers';
import {HardhatRuntimeEnvironment} from 'hardhat/types';
import {BuidlerRuntimeEnvironment} from '@nomiclabs/buidler/types';
import {tEthereumAddress} from './types';
import {isAddress} from 'ethers/lib/utils';
import {isZeroAddress} from 'ethereumjs-util';
import { WAD } from './constants';
import { Wallet, ContractTransaction } from 'ethers';
import { HardhatRuntimeEnvironment } from 'hardhat/types';
import { BuidlerRuntimeEnvironment } from '@nomiclabs/buidler/types';
import { tEthereumAddress } from './types';
import { isAddress } from 'ethers/lib/utils';
import { isZeroAddress } from 'ethereumjs-util';
export const toWad = (value: string | number) => new BigNumber(value).times(WAD).toFixed();
@ -49,10 +49,10 @@ export const increaseTime = async (secondsToIncrease: number) => {
export const waitForTx = async (tx: ContractTransaction) => await tx.wait(1);
export const filterMapBy = (raw: {[key: string]: any}, fn: (key: string) => boolean) =>
export const filterMapBy = (raw: { [key: string]: any }, fn: (key: string) => boolean) =>
Object.keys(raw)
.filter(fn)
.reduce<{[key: string]: any}>((obj, key) => {
.reduce<{ [key: string]: any }>((obj, key) => {
obj[key] = raw[key];
return obj;
}, {});

View File

@ -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,
}),

View File

@ -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<IMarketRates>,
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<string>, 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<string>,
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(

4814
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -39,7 +39,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",
@ -113,7 +114,7 @@
},
"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",

View File

@ -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);
});

View File

@ -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();

View File

@ -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,
};

View File

@ -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(

View File

@ -1,4 +1,4 @@
import {task} from 'hardhat/config';
import { task } from 'hardhat/config';
import {
getEthersSignersAddresses,
insertContractAddressInDb,
@ -9,8 +9,8 @@ import {
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,
@ -19,7 +19,7 @@ import {
task('full:deploy-lending-pool', 'Deploy lending pool for dev enviroment')
.addFlag('verify', 'Verify contracts at Etherscan')
.setAction(async ({verify}, DRE) => {
.setAction(async ({ verify }, DRE) => {
try {
await DRE.run('set-DRE');

View File

@ -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);

View File

@ -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();

View File

@ -1,13 +1,13 @@
import {task} from 'hardhat/config';
import {ExternalProvider} from '@ethersproject/providers';
import {checkVerification} from '../../helpers/etherscan-verification';
import {ConfigNames} from '../../helpers/configuration';
import {EthereumNetworkNames} from '../../helpers/types';
import {printContracts} from '../../helpers/misc-utils';
import { task } from 'hardhat/config';
import { ExternalProvider } from '@ethersproject/providers';
import { checkVerification } from '../../helpers/etherscan-verification';
import { ConfigNames } from '../../helpers/configuration';
import { EthereumNetworkNames } from '../../helpers/types';
import { printContracts } from '../../helpers/misc-utils';
task('aave:mainnet', 'Deploy development enviroment')
.addFlag('verify', 'Verify contracts at Etherscan')
.setAction(async ({verify}, DRE) => {
.setAction(async ({ verify }, DRE) => {
const POOL_NAME = ConfigNames.Aave;
const network = <EthereumNetworkNames>DRE.network.name;
await DRE.run('set-DRE');
@ -27,27 +27,27 @@ task('aave:mainnet', 'Deploy development enviroment')
console.log('Migration started\n');
console.log('1. Deploy address provider');
await DRE.run('full:deploy-address-provider', {pool: POOL_NAME});
await DRE.run('full:deploy-address-provider', { pool: POOL_NAME });
console.log('2. Deploy lending pool');
await DRE.run('full:deploy-lending-pool');
console.log('3. Deploy oracles');
await DRE.run('full:deploy-oracles', {pool: POOL_NAME});
await DRE.run('full:deploy-oracles', { pool: POOL_NAME });
console.log('4. Deploy Data Provider');
await DRE.run('full:data-provider', {pool: POOL_NAME});
await DRE.run('full:data-provider', { pool: POOL_NAME });
console.log('5. Initialize lending pool');
await DRE.run('full:initialize-lending-pool', {pool: POOL_NAME});
await DRE.run('full:initialize-lending-pool', { pool: POOL_NAME });
if (verify) {
printContracts();
console.log('4. Veryfing contracts');
await DRE.run('verify:general', {all: true, pool: POOL_NAME});
await DRE.run('verify:general', { all: true, pool: POOL_NAME });
console.log('5. Veryfing aTokens and debtTokens');
await DRE.run('verify:tokens', {pool: POOL_NAME});
await DRE.run('verify:tokens', { pool: POOL_NAME });
}
if (network.includes('tenderly')) {

View File

@ -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) => {

View File

@ -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();

View File

@ -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');

View File

@ -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
);

View File

@ -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');

View File

@ -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'));

View File

@ -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);

View File

@ -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`;

View File

@ -1211,7 +1211,6 @@ export const calcExpectedInterestRates = (
): BigNumber[] => {
const { reservesParams } = configuration;
const reserveIndex = Object.keys(reservesParams).findIndex((value) => value === reserveSymbol);
const [, reserveConfiguration] = (Object.entries(reservesParams) as [string, IReserveParams][])[
reserveIndex

View File

@ -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);
};
return halfA
.plus(this.multipliedBy(PERCENTAGE_FACTOR))
.div(a)
.decimalPlaces(0, BigNumber.ROUND_DOWN);
};

View File

@ -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);
});
});

View File

@ -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];

View File

@ -1,14 +1,14 @@
import {MAX_UINT_AMOUNT} from '../../helpers/constants';
import {convertToCurrencyDecimals} from '../../helpers/contracts-helpers';
import {makeSuite, TestEnv} from '../helpers/make-suite';
import {parseEther} from 'ethers/lib/utils';
import {DRE, waitForTx} from '../../helpers/misc-utils';
import {BigNumber} from 'ethers';
import {getStableDebtToken, getVariableDebtToken} from '../../helpers/contracts-getters';
import {deploySelfdestructTransferMock} from '../../helpers/contracts-deployments';
import {IUniswapV2Router02Factory} from '../../types/IUniswapV2Router02Factory';
import { MAX_UINT_AMOUNT } from '../../helpers/constants';
import { convertToCurrencyDecimals } from '../../helpers/contracts-helpers';
import { makeSuite, TestEnv } from '../helpers/make-suite';
import { parseEther } from 'ethers/lib/utils';
import { DRE, waitForTx } from '../../helpers/misc-utils';
import { BigNumber } from 'ethers';
import { getStableDebtToken, getVariableDebtToken } from '../../helpers/contracts-getters';
import { deploySelfdestructTransferMock } from '../../helpers/contracts-deployments';
import { IUniswapV2Router02Factory } from '../../types/IUniswapV2Router02Factory';
const {expect} = require('chai');
const { expect } = require('chai');
const UNISWAP_ROUTER = '0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D';
@ -17,12 +17,12 @@ makeSuite('Mainnet Check list', (testEnv: TestEnv) => {
const depositSize = parseEther('5');
it('Deposit WETH', async () => {
const {users, wethGateway, aWETH, pool} = testEnv;
const { users, wethGateway, aWETH, pool } = testEnv;
const user = users[1];
// Deposit with native ETH
await wethGateway.connect(user.signer).depositETH(user.address, '0', {value: depositSize});
await wethGateway.connect(user.signer).depositETH(user.address, '0', { value: depositSize });
const aTokensBalance = await aWETH.balanceOf(user.address);
@ -31,7 +31,7 @@ makeSuite('Mainnet Check list', (testEnv: TestEnv) => {
});
it('Withdraw WETH - Partial', async () => {
const {users, wethGateway, aWETH, pool} = testEnv;
const { users, wethGateway, aWETH, pool } = testEnv;
const user = users[1];
const priorEthersBalance = await user.signer.getBalance();
@ -46,10 +46,10 @@ makeSuite('Mainnet Check list', (testEnv: TestEnv) => {
const approveTx = await aWETH
.connect(user.signer)
.approve(wethGateway.address, MAX_UINT_AMOUNT);
const {gasUsed: approveGas} = await waitForTx(approveTx);
const { gasUsed: approveGas } = await waitForTx(approveTx);
// Partial Withdraw and send native Ether to user
const {gasUsed: withdrawGas} = await waitForTx(
const { gasUsed: withdrawGas } = await waitForTx(
await wethGateway.connect(user.signer).withdrawETH(partialWithdraw, user.address)
);
@ -68,7 +68,7 @@ makeSuite('Mainnet Check list', (testEnv: TestEnv) => {
});
it('Withdraw WETH - Full', async () => {
const {users, aWETH, wethGateway, pool} = testEnv;
const { users, aWETH, wethGateway, pool } = testEnv;
const user = users[1];
const priorEthersBalance = await user.signer.getBalance();
@ -80,10 +80,10 @@ makeSuite('Mainnet Check list', (testEnv: TestEnv) => {
const approveTx = await aWETH
.connect(user.signer)
.approve(wethGateway.address, MAX_UINT_AMOUNT);
const {gasUsed: approveGas} = await waitForTx(approveTx);
const { gasUsed: approveGas } = await waitForTx(approveTx);
// Full withdraw
const {gasUsed: withdrawGas} = await waitForTx(
const { gasUsed: withdrawGas } = await waitForTx(
await wethGateway.connect(user.signer).withdrawETH(MAX_UINT_AMOUNT, user.address)
);
@ -99,17 +99,19 @@ 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, weth, pool, helpersContract } = testEnv;
const borrowSize = parseEther('1');
const repaySize = borrowSize.add(borrowSize.mul(5).div(100));
const user = users[1];
const {stableDebtTokenAddress} = await helpersContract.getReserveTokensAddresses(weth.address);
const { stableDebtTokenAddress } = await helpersContract.getReserveTokensAddresses(
weth.address
);
const stableDebtToken = await getStableDebtToken(stableDebtTokenAddress);
// Deposit with native ETH
await wethGateway.connect(user.signer).depositETH(user.address, '0', {value: depositSize});
await wethGateway.connect(user.signer).depositETH(user.address, '0', { value: depositSize });
const aTokensBalance = await aWETH.balanceOf(user.address);
@ -129,7 +131,7 @@ makeSuite('Mainnet Check list', (testEnv: TestEnv) => {
await waitForTx(
await wethGateway
.connect(user.signer)
.repayETH(MAX_UINT_AMOUNT, '1', user.address, {value: repaySize})
.repayETH(MAX_UINT_AMOUNT, '1', user.address, { value: repaySize })
);
const debtBalanceAfterRepay = await stableDebtToken.balanceOf(user.address);
@ -137,19 +139,19 @@ makeSuite('Mainnet Check list', (testEnv: TestEnv) => {
});
it('Borrow variable WETH and Full Repay with ETH', async () => {
const {users, wethGateway, aWETH, weth, pool, helpersContract} = testEnv;
const { users, wethGateway, aWETH, weth, pool, helpersContract } = testEnv;
const borrowSize = parseEther('1');
const repaySize = borrowSize.add(borrowSize.mul(5).div(100));
const user = users[1];
const {variableDebtTokenAddress} = await helpersContract.getReserveTokensAddresses(
const { variableDebtTokenAddress } = await helpersContract.getReserveTokensAddresses(
weth.address
);
const varDebtToken = await getVariableDebtToken(variableDebtTokenAddress);
// Deposit with native ETH
await wethGateway.connect(user.signer).depositETH(user.address, '0', {value: depositSize});
await wethGateway.connect(user.signer).depositETH(user.address, '0', { value: depositSize });
const aTokensBalance = await aWETH.balanceOf(user.address);
@ -170,7 +172,7 @@ makeSuite('Mainnet Check list', (testEnv: TestEnv) => {
await waitForTx(
await wethGateway
.connect(user.signer)
.repayETH(partialPayment, '2', user.address, {value: partialPayment})
.repayETH(partialPayment, '2', user.address, { value: partialPayment })
);
const debtBalanceAfterPartialRepay = await varDebtToken.balanceOf(user.address);
@ -180,17 +182,17 @@ makeSuite('Mainnet Check list', (testEnv: TestEnv) => {
await waitForTx(
await wethGateway
.connect(user.signer)
.repayETH(MAX_UINT_AMOUNT, '2', user.address, {value: repaySize})
.repayETH(MAX_UINT_AMOUNT, '2', user.address, { value: repaySize })
);
const debtBalanceAfterFullRepay = await varDebtToken.balanceOf(user.address);
expect(debtBalanceAfterFullRepay).to.be.eq(zero);
});
it('Borrow ETH via delegateApprove ETH and repays back', async () => {
const {users, wethGateway, aWETH, weth, helpersContract} = testEnv;
const { users, wethGateway, aWETH, weth, helpersContract } = testEnv;
const borrowSize = parseEther('1');
const user = users[2];
const {variableDebtTokenAddress} = await helpersContract.getReserveTokensAddresses(
const { variableDebtTokenAddress } = await helpersContract.getReserveTokensAddresses(
weth.address
);
const varDebtToken = await getVariableDebtToken(variableDebtTokenAddress);
@ -199,7 +201,7 @@ makeSuite('Mainnet Check list', (testEnv: TestEnv) => {
expect(priorDebtBalance).to.be.eq(zero);
// Deposit WETH with native ETH
await wethGateway.connect(user.signer).depositETH(user.address, '0', {value: depositSize});
await wethGateway.connect(user.signer).depositETH(user.address, '0', { value: depositSize });
const aTokensBalance = await aWETH.balanceOf(user.address);
@ -222,14 +224,14 @@ makeSuite('Mainnet Check list', (testEnv: TestEnv) => {
await waitForTx(
await wethGateway
.connect(user.signer)
.repayETH(MAX_UINT_AMOUNT, '2', user.address, {value: borrowSize.mul(2)})
.repayETH(MAX_UINT_AMOUNT, '2', user.address, { value: borrowSize.mul(2) })
);
const debtBalanceAfterFullRepay = await varDebtToken.balanceOf(user.address);
expect(debtBalanceAfterFullRepay).to.be.eq(zero);
});
it('Should revert if receiver function receives Ether if not WETH', async () => {
const {users, wethGateway} = testEnv;
const { users, wethGateway } = testEnv;
const user = users[0];
const amount = parseEther('1');
@ -244,7 +246,7 @@ makeSuite('Mainnet Check list', (testEnv: TestEnv) => {
});
it('Should revert if fallback functions is called with Ether', async () => {
const {users, wethGateway} = testEnv;
const { users, wethGateway } = testEnv;
const user = users[0];
const amount = parseEther('1');
const fakeABI = ['function wantToCallFallback()'];
@ -263,7 +265,7 @@ makeSuite('Mainnet Check list', (testEnv: TestEnv) => {
});
it('Should revert if fallback functions is called', async () => {
const {users, wethGateway} = testEnv;
const { users, wethGateway } = testEnv;
const user = users[0];
const fakeABI = ['function wantToCallFallback()'];
@ -281,7 +283,7 @@ makeSuite('Mainnet Check list', (testEnv: TestEnv) => {
});
it('Getters should retrieve correct state', async () => {
const {aWETH, weth, pool, wethGateway} = testEnv;
const { aWETH, weth, pool, wethGateway } = testEnv;
const WETHAddress = await wethGateway.getWETHAddress();
const aWETHAddress = await wethGateway.getAWETHAddress();
@ -293,7 +295,7 @@ makeSuite('Mainnet Check list', (testEnv: TestEnv) => {
});
it('Owner can do emergency token recovery', async () => {
const {users, weth, dai, wethGateway, deployer} = testEnv;
const { users, weth, dai, wethGateway, deployer } = testEnv;
const user = users[0];
const amount = parseEther('1');
@ -328,7 +330,7 @@ makeSuite('Mainnet Check list', (testEnv: TestEnv) => {
});
it('Owner can do emergency native ETH recovery', async () => {
const {users, wethGateway, deployer} = testEnv;
const { users, wethGateway, deployer } = testEnv;
const user = users[0];
const amount = parseEther('1');
const userBalancePriorCall = await user.signer.getBalance();
@ -339,13 +341,13 @@ makeSuite('Mainnet Check list', (testEnv: TestEnv) => {
// Selfdestruct the mock, pointing to WETHGateway address
const callTx = await selfdestructContract
.connect(user.signer)
.destroyAndTransfer(wethGateway.address, {value: amount});
const {gasUsed} = await waitForTx(callTx);
.destroyAndTransfer(wethGateway.address, { value: amount });
const { gasUsed } = await waitForTx(callTx);
const gasFees = gasUsed.mul(callTx.gasPrice);
const userBalanceAfterCall = await user.signer.getBalance();
expect(userBalanceAfterCall).to.be.eq(userBalancePriorCall.sub(amount).sub(gasFees), '');
'User should have lost the funds';
('User should have lost the funds');
// Recover the funds from the contract and sends back to the user
await wethGateway.connect(deployer.signer).emergencyEtherTransfer(user.address, amount);

View File

@ -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');

View File

@ -1,12 +1,12 @@
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 fs from 'fs';
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';
const scenarioFolder = './test/helpers/scenarios/';
@ -20,7 +20,7 @@ fs.readdirSync(scenarioFolder).forEach((file) => {
makeSuite(scenario.title, async (testEnv) => {
before('Initializing configuration', async () => {
// 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
@ -30,7 +30,7 @@ fs.readdirSync(scenarioFolder).forEach((file) => {
});
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 });
});
for (const story of scenario.stories) {

View File

@ -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;

View File

@ -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);

View File

@ -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);

View File

@ -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)

View File

@ -1,25 +1,25 @@
import {MAX_UINT_AMOUNT} from '../helpers/constants';
import {convertToCurrencyDecimals} from '../helpers/contracts-helpers';
import {makeSuite, TestEnv} from './helpers/make-suite';
import {parseEther} from 'ethers/lib/utils';
import {DRE, waitForTx} from '../helpers/misc-utils';
import {BigNumber} from 'ethers';
import {getStableDebtToken, getVariableDebtToken} from '../helpers/contracts-getters';
import {deploySelfdestructTransferMock} from '../helpers/contracts-deployments';
import { MAX_UINT_AMOUNT } from '../helpers/constants';
import { convertToCurrencyDecimals } from '../helpers/contracts-helpers';
import { makeSuite, TestEnv } from './helpers/make-suite';
import { parseEther } from 'ethers/lib/utils';
import { DRE, waitForTx } from '../helpers/misc-utils';
import { BigNumber } from 'ethers';
import { getStableDebtToken, getVariableDebtToken } from '../helpers/contracts-getters';
import { deploySelfdestructTransferMock } from '../helpers/contracts-deployments';
const {expect} = require('chai');
const { expect } = require('chai');
makeSuite('Use native ETH at LendingPool via WETHGateway', (testEnv: TestEnv) => {
const zero = BigNumber.from('0');
const depositSize = parseEther('5');
it('Deposit WETH', async () => {
const {users, wethGateway, aWETH, pool} = testEnv;
const { users, wethGateway, aWETH, pool } = testEnv;
const user = users[1];
// Deposit with native ETH
await wethGateway.connect(user.signer).depositETH(user.address, '0', {value: depositSize});
await wethGateway.connect(user.signer).depositETH(user.address, '0', { value: depositSize });
const aTokensBalance = await aWETH.balanceOf(user.address);
@ -28,7 +28,7 @@ makeSuite('Use native ETH at LendingPool via WETHGateway', (testEnv: TestEnv) =>
});
it('Withdraw WETH - Partial', async () => {
const {users, wethGateway, aWETH, pool} = testEnv;
const { users, wethGateway, aWETH, pool } = testEnv;
const user = users[1];
const priorEthersBalance = await user.signer.getBalance();
@ -43,10 +43,10 @@ makeSuite('Use native ETH at LendingPool via WETHGateway', (testEnv: TestEnv) =>
const approveTx = await aWETH
.connect(user.signer)
.approve(wethGateway.address, MAX_UINT_AMOUNT);
const {gasUsed: approveGas} = await waitForTx(approveTx);
const { gasUsed: approveGas } = await waitForTx(approveTx);
// Partial Withdraw and send native Ether to user
const {gasUsed: withdrawGas} = await waitForTx(
const { gasUsed: withdrawGas } = await waitForTx(
await wethGateway.connect(user.signer).withdrawETH(partialWithdraw, user.address)
);
@ -65,7 +65,7 @@ makeSuite('Use native ETH at LendingPool via WETHGateway', (testEnv: TestEnv) =>
});
it('Withdraw WETH - Full', async () => {
const {users, aWETH, wethGateway, pool} = testEnv;
const { users, aWETH, wethGateway, pool } = testEnv;
const user = users[1];
const priorEthersBalance = await user.signer.getBalance();
@ -77,10 +77,10 @@ makeSuite('Use native ETH at LendingPool via WETHGateway', (testEnv: TestEnv) =>
const approveTx = await aWETH
.connect(user.signer)
.approve(wethGateway.address, MAX_UINT_AMOUNT);
const {gasUsed: approveGas} = await waitForTx(approveTx);
const { gasUsed: approveGas } = await waitForTx(approveTx);
// Full withdraw
const {gasUsed: withdrawGas} = await waitForTx(
const { gasUsed: withdrawGas } = await waitForTx(
await wethGateway.connect(user.signer).withdrawETH(MAX_UINT_AMOUNT, user.address)
);
@ -96,17 +96,19 @@ makeSuite('Use native ETH at LendingPool via WETHGateway', (testEnv: TestEnv) =>
});
it('Borrow stable WETH and Full Repay with ETH', async () => {
const {users, wethGateway, aWETH, weth, pool, helpersContract} = testEnv;
const { users, wethGateway, aWETH, weth, pool, helpersContract } = testEnv;
const borrowSize = parseEther('1');
const repaySize = borrowSize.add(borrowSize.mul(5).div(100));
const user = users[1];
const {stableDebtTokenAddress} = await helpersContract.getReserveTokensAddresses(weth.address);
const { stableDebtTokenAddress } = await helpersContract.getReserveTokensAddresses(
weth.address
);
const stableDebtToken = await getStableDebtToken(stableDebtTokenAddress);
// Deposit with native ETH
await wethGateway.connect(user.signer).depositETH(user.address, '0', {value: depositSize});
await wethGateway.connect(user.signer).depositETH(user.address, '0', { value: depositSize });
const aTokensBalance = await aWETH.balanceOf(user.address);
@ -126,7 +128,7 @@ makeSuite('Use native ETH at LendingPool via WETHGateway', (testEnv: TestEnv) =>
await waitForTx(
await wethGateway
.connect(user.signer)
.repayETH(MAX_UINT_AMOUNT, '1', user.address, {value: repaySize})
.repayETH(MAX_UINT_AMOUNT, '1', user.address, { value: repaySize })
);
const debtBalanceAfterRepay = await stableDebtToken.balanceOf(user.address);
@ -134,19 +136,19 @@ makeSuite('Use native ETH at LendingPool via WETHGateway', (testEnv: TestEnv) =>
});
it('Borrow variable WETH and Full Repay with ETH', async () => {
const {users, wethGateway, aWETH, weth, pool, helpersContract} = testEnv;
const { users, wethGateway, aWETH, weth, pool, helpersContract } = testEnv;
const borrowSize = parseEther('1');
const repaySize = borrowSize.add(borrowSize.mul(5).div(100));
const user = users[1];
const {variableDebtTokenAddress} = await helpersContract.getReserveTokensAddresses(
const { variableDebtTokenAddress } = await helpersContract.getReserveTokensAddresses(
weth.address
);
const varDebtToken = await getVariableDebtToken(variableDebtTokenAddress);
// Deposit with native ETH
await wethGateway.connect(user.signer).depositETH(user.address, '0', {value: depositSize});
await wethGateway.connect(user.signer).depositETH(user.address, '0', { value: depositSize });
const aTokensBalance = await aWETH.balanceOf(user.address);
@ -167,7 +169,7 @@ makeSuite('Use native ETH at LendingPool via WETHGateway', (testEnv: TestEnv) =>
await waitForTx(
await wethGateway
.connect(user.signer)
.repayETH(partialPayment, '2', user.address, {value: partialPayment})
.repayETH(partialPayment, '2', user.address, { value: partialPayment })
);
const debtBalanceAfterPartialRepay = await varDebtToken.balanceOf(user.address);
@ -177,17 +179,17 @@ makeSuite('Use native ETH at LendingPool via WETHGateway', (testEnv: TestEnv) =>
await waitForTx(
await wethGateway
.connect(user.signer)
.repayETH(MAX_UINT_AMOUNT, '2', user.address, {value: repaySize})
.repayETH(MAX_UINT_AMOUNT, '2', user.address, { value: repaySize })
);
const debtBalanceAfterFullRepay = await varDebtToken.balanceOf(user.address);
expect(debtBalanceAfterFullRepay).to.be.eq(zero);
});
it('Borrow ETH via delegateApprove ETH and repays back', async () => {
const {users, wethGateway, aWETH, weth, helpersContract} = testEnv;
const { users, wethGateway, aWETH, weth, helpersContract } = testEnv;
const borrowSize = parseEther('1');
const user = users[2];
const {variableDebtTokenAddress} = await helpersContract.getReserveTokensAddresses(
const { variableDebtTokenAddress } = await helpersContract.getReserveTokensAddresses(
weth.address
);
const varDebtToken = await getVariableDebtToken(variableDebtTokenAddress);
@ -196,7 +198,7 @@ makeSuite('Use native ETH at LendingPool via WETHGateway', (testEnv: TestEnv) =>
expect(priorDebtBalance).to.be.eq(zero);
// Deposit WETH with native ETH
await wethGateway.connect(user.signer).depositETH(user.address, '0', {value: depositSize});
await wethGateway.connect(user.signer).depositETH(user.address, '0', { value: depositSize });
const aTokensBalance = await aWETH.balanceOf(user.address);
@ -219,14 +221,14 @@ makeSuite('Use native ETH at LendingPool via WETHGateway', (testEnv: TestEnv) =>
await waitForTx(
await wethGateway
.connect(user.signer)
.repayETH(MAX_UINT_AMOUNT, '2', user.address, {value: borrowSize.mul(2)})
.repayETH(MAX_UINT_AMOUNT, '2', user.address, { value: borrowSize.mul(2) })
);
const debtBalanceAfterFullRepay = await varDebtToken.balanceOf(user.address);
expect(debtBalanceAfterFullRepay).to.be.eq(zero);
});
it('Should revert if receiver function receives Ether if not WETH', async () => {
const {users, wethGateway} = testEnv;
const { users, wethGateway } = testEnv;
const user = users[0];
const amount = parseEther('1');
@ -241,7 +243,7 @@ makeSuite('Use native ETH at LendingPool via WETHGateway', (testEnv: TestEnv) =>
});
it('Should revert if fallback functions is called with Ether', async () => {
const {users, wethGateway} = testEnv;
const { users, wethGateway } = testEnv;
const user = users[0];
const amount = parseEther('1');
const fakeABI = ['function wantToCallFallback()'];
@ -260,7 +262,7 @@ makeSuite('Use native ETH at LendingPool via WETHGateway', (testEnv: TestEnv) =>
});
it('Should revert if fallback functions is called', async () => {
const {users, wethGateway} = testEnv;
const { users, wethGateway } = testEnv;
const user = users[0];
const fakeABI = ['function wantToCallFallback()'];
@ -278,7 +280,7 @@ makeSuite('Use native ETH at LendingPool via WETHGateway', (testEnv: TestEnv) =>
});
it('Getters should retrieve correct state', async () => {
const {aWETH, weth, pool, wethGateway} = testEnv;
const { aWETH, weth, pool, wethGateway } = testEnv;
const WETHAddress = await wethGateway.getWETHAddress();
const aWETHAddress = await wethGateway.getAWETHAddress();
@ -290,7 +292,7 @@ makeSuite('Use native ETH at LendingPool via WETHGateway', (testEnv: TestEnv) =>
});
it('Owner can do emergency token recovery', async () => {
const {users, dai, wethGateway, deployer} = testEnv;
const { users, dai, wethGateway, deployer } = testEnv;
const user = users[0];
const amount = parseEther('1');
@ -316,7 +318,7 @@ makeSuite('Use native ETH at LendingPool via WETHGateway', (testEnv: TestEnv) =>
});
it('Owner can do emergency native ETH recovery', async () => {
const {users, wethGateway, deployer} = testEnv;
const { users, wethGateway, deployer } = testEnv;
const user = users[0];
const amount = parseEther('1');
const userBalancePriorCall = await user.signer.getBalance();
@ -327,13 +329,13 @@ makeSuite('Use native ETH at LendingPool via WETHGateway', (testEnv: TestEnv) =>
// Selfdestruct the mock, pointing to WETHGateway address
const callTx = await selfdestructContract
.connect(user.signer)
.destroyAndTransfer(wethGateway.address, {value: amount});
const {gasUsed} = await waitForTx(callTx);
.destroyAndTransfer(wethGateway.address, { value: amount });
const { gasUsed } = await waitForTx(callTx);
const gasFees = gasUsed.mul(callTx.gasPrice);
const userBalanceAfterCall = await user.signer.getBalance();
expect(userBalanceAfterCall).to.be.eq(userBalancePriorCall.sub(amount).sub(gasFees), '');
'User should have lost the funds';
('User should have lost the funds');
// Recover the funds from the contract and sends back to the user
await wethGateway.connect(deployer.signer).emergencyEtherTransfer(user.address, amount);