Added test fixes to support latest stable fix

This commit is contained in:
David Racero 2021-01-21 00:42:39 +01:00
parent a72b73d804
commit c7a8f41d46
8 changed files with 194 additions and 190 deletions

View File

@ -13,7 +13,7 @@
"compile": "SKIP_LOAD=true hardhat compile",
"console:fork": "MAINNET_FORK=true hardhat console",
"test": "TS_NODE_TRANSPILE_ONLY=1 hardhat test ./test/*.spec.ts",
"test-scenarios": "npm run test -- test/__setup.spec.ts test/scenario.spec.ts",
"test-scenarios": "npx hardhat test test/__setup.spec.ts test/scenario.spec.ts",
"test-repay-with-collateral": "hardhat test test/__setup.spec.ts test/repay-with-collateral.spec.ts",
"test-liquidate-with-collateral": "hardhat test test/__setup.spec.ts test/flash-liquidation-with-collateral.spec.ts",
"test-liquidate-underlying": "hardhat test test/__setup.spec.ts test/liquidation-underlying.spec.ts",

View File

@ -208,6 +208,15 @@
},
"expected": "revert",
"revertMessage": "The collateral balance is 0"
},
{
"name": "withdraw",
"args": {
"reserve": "DAI",
"amount": "1000",
"user": "1"
},
"expected": "success"
}
]
},

View File

@ -10,7 +10,7 @@
"args": {
"reserve": "WETH",
"amount": "1000",
"user": "0"
"user": "3"
},
"expected": "success"
},
@ -18,7 +18,7 @@
"name": "approve",
"args": {
"reserve": "WETH",
"user": "0"
"user": "3"
},
"expected": "success"
},
@ -27,6 +27,32 @@
"args": {
"reserve": "WETH",
"amount": "1000",
"user": "3"
},
"expected": "success"
},
{
"name": "mint",
"args": {
"reserve": "DAI",
"amount": "1000",
"user": "0"
},
"expected": "success"
},
{
"name": "approve",
"args": {
"reserve": "DAI",
"user": "0"
},
"expected": "success"
},
{
"name": "deposit",
"args": {
"reserve": "DAI",
"amount": "1000",
"user": "0"
},
"expected": "success"

View File

@ -8,7 +8,7 @@
{
"name": "rebalanceStableBorrowRate",
"args": {
"reserve": "DAI",
"reserve": "USDC",
"user": "0",
"target": "1",
"borrowRateMode": "variable"
@ -19,12 +19,12 @@
]
},
{
"description": "User 0 deposits 1000 DAI, user 1 deposits 5 ETH, borrows 600 DAI at a variable rate, user 0 rebalances user 1 (revert expected)",
"description": "User 0 deposits 1000 USDC, user 1 deposits 5 ETH, borrows 600 DAI at a variable rate, user 0 rebalances user 1 (revert expected)",
"actions": [
{
"name": "mint",
"args": {
"reserve": "DAI",
"reserve": "USDC",
"amount": "1000",
"user": "0"
},
@ -33,7 +33,7 @@
{
"name": "approve",
"args": {
"reserve": "DAI",
"reserve": "USDC",
"user": "0"
},
"expected": "success"
@ -41,7 +41,7 @@
{
"name": "deposit",
"args": {
"reserve": "DAI",
"reserve": "USDC",
"amount": "1000",
"user": "0"
},
@ -51,7 +51,7 @@
"name": "mint",
"args": {
"reserve": "WETH",
"amount": "5",
"amount": "7",
"user": "1"
},
"expected": "success"
@ -69,7 +69,7 @@
"args": {
"reserve": "WETH",
"amount": "5",
"amount": "7",
"user": "1"
},
"expected": "success"
@ -77,18 +77,17 @@
{
"name": "borrow",
"args": {
"reserve": "DAI",
"reserve": "USDC",
"amount": "250",
"borrowRateMode": "stable",
"user": "1",
"timeTravel": "365"
"user": "1"
},
"expected": "success"
},
{
"name": "rebalanceStableBorrowRate",
"args": {
"reserve": "DAI",
"reserve": "USDC",
"user": "0",
"target": "1"
},
@ -103,18 +102,17 @@
{
"name": "borrow",
"args": {
"reserve": "DAI",
"reserve": "USDC",
"amount": "200",
"borrowRateMode": "stable",
"user": "1",
"timeTravel": "365"
"borrowRateMode": "variable",
"user": "1"
},
"expected": "success"
},
{
"name": "rebalanceStableBorrowRate",
"args": {
"reserve": "DAI",
"reserve": "USDC",
"user": "0",
"target": "1"
},
@ -129,18 +127,17 @@
{
"name": "borrow",
"args": {
"reserve": "DAI",
"reserve": "USDC",
"amount": "200",
"borrowRateMode": "stable",
"user": "1",
"timeTravel": "365"
"borrowRateMode": "variable",
"user": "1"
},
"expected": "success"
},
{
"name": "rebalanceStableBorrowRate",
"args": {
"reserve": "DAI",
"reserve": "USDC",
"user": "0",
"target": "1"
},
@ -155,18 +152,17 @@
{
"name": "borrow",
"args": {
"reserve": "DAI",
"amount": "100",
"borrowRateMode": "stable",
"user": "1",
"timeTravel": "365"
"reserve": "USDC",
"amount": "280",
"borrowRateMode": "variable",
"user": "1"
},
"expected": "success"
},
{
"name": "rebalanceStableBorrowRate",
"args": {
"reserve": "DAI",
"reserve": "USDC",
"user": "0",
"target": "1"
},
@ -175,75 +171,24 @@
}
]
},
{
"description": "User 2 deposits ETH and borrows the remaining DAI, causing the stable rates to rise (usage ratio = 94%). User 0 tries to rebalance user 1 (revert expected)",
"actions": [
{
"name": "mint",
"args": {
"reserve": "WETH",
"amount": "5",
"user": "2"
},
"expected": "success"
},
{
"name": "approve",
"args": {
"reserve": "WETH",
"user": "2"
},
"expected": "success"
},
{
"name": "deposit",
"args": {
"reserve": "WETH",
"amount": "5",
"user": "2"
},
"expected": "success"
},
{
"name": "borrow",
"args": {
"reserve": "DAI",
"amount": "190",
"borrowRateMode": "variable",
"user": "2"
},
"expected": "success"
},
{
"name": "rebalanceStableBorrowRate",
"args": {
"reserve": "DAI",
"user": "0",
"target": "1"
},
"expected": "revert",
"revertMessage": "Interest rate rebalance conditions were not met"
}
]
},
{
"description": "User 2 borrows the remaining DAI (usage ratio = 100%). User 0 rebalances user 1",
"description": "User 0 borrows the remaining USDC (usage ratio = 100%). User 0 rebalances user 1",
"actions": [
{
"name": "borrow",
"args": {
"reserve": "DAI",
"amount": "60",
"reserve": "USDC",
"amount": "20",
"borrowRateMode": "variable",
"user": "2"
"user": "1"
},
"expected": "success"
},
{
"name": "rebalanceStableBorrowRate",
"args": {
"reserve": "DAI",
"reserve": "USDC",
"user": "0",
"target": "1"
},

View File

@ -1,28 +1,28 @@
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';
makeSuite('Mainnet Check list', (testEnv: TestEnv) => {
const zero = BigNumber.from('0');
const depositSize = parseEther('5');
const daiSize = parseEther('10000');
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,22 +99,26 @@ 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});
// Deposit 10000 DAI
await dai.connect(user.signer).mint(daiSize);
await dai.connect(user.signer).approve(pool.address, daiSize);
await pool.connect(user.signer).deposit(dai.address, daiSize, user.address, '0');
const aTokensBalance = await aWETH.balanceOf(user.address);
const aTokensBalance = await aDai.balanceOf(user.address);
expect(aTokensBalance).to.be.gt(zero);
expect(aTokensBalance).to.be.gte(depositSize);
expect(aTokensBalance).to.be.gte(daiSize);
// Borrow WETH with WETH as collateral
await waitForTx(
@ -129,7 +133,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 +141,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 +174,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 +184,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 +203,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 +226,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 +248,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 +267,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 +285,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 +297,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 +332,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 +343,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,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

@ -803,15 +803,15 @@ makeSuite('Uniswap adapters', (testEnv: TestEnv) => {
const userAddress = users[0].address;
// Add deposit for user
await dai.mint(parseEther('20'));
await dai.approve(pool.address, parseEther('20'));
await pool.deposit(dai.address, parseEther('20'), userAddress, 0);
await dai.mint(parseEther('30'));
await dai.approve(pool.address, parseEther('30'));
await pool.deposit(dai.address, parseEther('30'), userAddress, 0);
const amountCollateralToSwap = parseEther('10');
const debtAmount = parseEther('10');
// Open user Debt
await pool.connect(user).borrow(dai.address, debtAmount, 1, 0, userAddress);
await pool.connect(user).borrow(dai.address, debtAmount, 2, 0, userAddress);
const daiStableDebtTokenAddress = (
await helpersContract.getReserveTokensAddresses(dai.address)
@ -1376,16 +1376,16 @@ makeSuite('Uniswap adapters', (testEnv: TestEnv) => {
const userAddress = users[0].address;
// Add deposit for user
await dai.mint(parseEther('20'));
await dai.approve(pool.address, parseEther('20'));
await pool.deposit(dai.address, parseEther('20'), userAddress, 0);
await dai.mint(parseEther('30'));
await dai.approve(pool.address, parseEther('30'));
await pool.deposit(dai.address, parseEther('30'), userAddress, 0);
const amountCollateralToSwap = parseEther('4');
const debtAmount = parseEther('3');
// Open user Debt
await pool.connect(user).borrow(dai.address, debtAmount, 1, 0, userAddress);
await pool.connect(user).borrow(dai.address, debtAmount, 2, 0, userAddress);
const daiStableDebtTokenAddress = (
await helpersContract.getReserveTokensAddresses(dai.address)

View File

@ -1,25 +1,31 @@
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 daiSize = parseEther('10000');
it('Deposit WETH via WethGateway and DAI', async () => {
const { users, wethGateway, aWETH, dai, pool } = testEnv;
const user = users[1];
const depositor = users[0];
// Deposit liquidity with native ETH
await wethGateway
.connect(depositor.signer)
.depositETH(depositor.address, '0', { value: depositSize });
// 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 +34,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 +49,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 +71,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 +83,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,22 +102,32 @@ 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, aDai, weth, dai, pool, helpersContract } = testEnv;
const borrowSize = parseEther('1');
const repaySize = borrowSize.add(borrowSize.mul(5).div(100));
const user = users[1];
const depositor = users[0];
const {stableDebtTokenAddress} = await helpersContract.getReserveTokensAddresses(weth.address);
// Deposit with native ETH
await wethGateway
.connect(depositor.signer)
.depositETH(depositor.address, '0', { value: depositSize });
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});
// Deposit 10000 DAI
await dai.connect(user.signer).mint(daiSize);
await dai.connect(user.signer).approve(pool.address, daiSize);
await pool.connect(user.signer).deposit(dai.address, daiSize, user.address, '0');
const aTokensBalance = await aWETH.balanceOf(user.address);
const aTokensBalance = await aDai.balanceOf(user.address);
expect(aTokensBalance).to.be.gt(zero);
expect(aTokensBalance).to.be.gte(depositSize);
expect(aTokensBalance).to.be.gte(daiSize);
// Borrow WETH with WETH as collateral
await waitForTx(
@ -126,27 +142,31 @@ 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);
expect(debtBalanceAfterRepay).to.be.eq(zero);
// Withdraw DAI
await aDai.connect(user.signer).approve(pool.address, MAX_UINT_AMOUNT);
await pool.connect(user.signer).withdraw(dai.address, MAX_UINT_AMOUNT, user.address);
});
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 +187,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 +197,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 +216,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 +239,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 +261,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 +280,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 +298,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 +310,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 +336,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 +347,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);