From 1656f1c6a3a251d1a5bc258c4242fe7ab8b86040 Mon Sep 17 00:00:00 2001 From: Hadrien Charlanes Date: Mon, 22 Feb 2021 13:23:52 +0100 Subject: [PATCH] Added Weth gateway contract in config, updated deployment --- contracts/misc/WETHGateway.sol | 8 +- helpers/contracts-deployments.ts | 106 +++++++-------------- helpers/types.ts | 3 +- markets/aave/commons.ts | 10 +- markets/lp/commons.ts | 9 ++ package.json | 3 +- tasks/deployments/deploy-wethGateWay.ts | 21 ++++ tasks/dev/5_initialize.ts | 9 +- tasks/full/5_initialize.ts | 17 ++-- test-suites/test-aave/__setup.spec.ts | 11 ++- test-suites/test-aave/weth-gateway.spec.ts | 52 +++++----- test-suites/test-lp/__setup.spec.ts | 4 +- test-suites/test-lp/weth-gateway.spec.ts | 37 +++---- 13 files changed, 147 insertions(+), 143 deletions(-) create mode 100644 tasks/deployments/deploy-wethGateWay.ts diff --git a/contracts/misc/WETHGateway.sol b/contracts/misc/WETHGateway.sol index e2ef175c..336e8de2 100644 --- a/contracts/misc/WETHGateway.sol +++ b/contracts/misc/WETHGateway.sol @@ -28,16 +28,13 @@ contract WETHGateway is IWETHGateway, Ownable { } function authorizeLendingPool(address lendingPool) external onlyOwner { - require( - ILendingPool(lendingPool).getReserveData(address(WETH)).aTokenAddress != address(0), - 'AWETH_NOT_SETUP' - ); WETH.approve(lendingPool, uint256(-1)); } /** * @dev deposits WETH into the reserve, using native ETH. A corresponding amount of the overlying asset (aTokens) * is minted. + * @param lendingPool address of the targeted underlying lending pool * @param onBehalfOf address of the user who will receive the aTokens representing the deposit * @param referralCode integrators are assigned a referral code and can potentially receive rewards. **/ @@ -52,6 +49,7 @@ contract WETHGateway is IWETHGateway, Ownable { /** * @dev withdraws the WETH _reserves of msg.sender. + * @param lendingPool address of the targeted underlying lending pool * @param amount amount of aWETH to withdraw and receive native ETH * @param to address of the user who will receive native ETH */ @@ -76,6 +74,7 @@ contract WETHGateway is IWETHGateway, Ownable { /** * @dev repays a borrow on the WETH reserve, for the specified amount (or for the whole amount, if uint256(-1) is specified). + * @param lendingPool address of the targeted underlying lending pool * @param amount the amount to repay, or uint256(-1) if the user wants to repay everything * @param rateMode the rate mode to repay * @param onBehalfOf the address for which msg.sender is repaying @@ -110,6 +109,7 @@ contract WETHGateway is IWETHGateway, Ownable { /** * @dev borrow WETH, unwraps to ETH and send both the ETH and DebtTokens to msg.sender, via `approveDelegation` and onBehalf argument in `LendingPool.borrow`. + * @param lendingPool address of the targeted underlying lending pool * @param amount the amount of ETH to borrow * @param interesRateMode the interest rate mode * @param referralCode integrators are assigned a referral code and can potentially receive rewards diff --git a/helpers/contracts-deployments.ts b/helpers/contracts-deployments.ts index 2406c065..3c999cfb 100644 --- a/helpers/contracts-deployments.ts +++ b/helpers/contracts-deployments.ts @@ -310,18 +310,10 @@ export const deployStableDebtToken = async ( verify ); - await instance.initialize( - args[0], - args[1], - args[2], - "18", - args[3], - args[4] - ); + await instance.initialize(args[0], args[1], args[2], '18', args[3], args[4]); return instance; -} - +}; export const deployVariableDebtToken = async ( args: [tEthereumAddress, tEthereumAddress, tEthereumAddress, string, string], @@ -334,18 +326,10 @@ export const deployVariableDebtToken = async ( verify ); - await instance.initialize( - args[0], - args[1], - args[2], - "18", - args[3], - args[4] - ); + await instance.initialize(args[0], args[1], args[2], '18', args[3], args[4]); return instance; -} - +}; export const deployGenericAToken = async ( [poolAddress, underlyingAssetAddress, treasuryAddress, incentivesController, name, symbol]: [ @@ -364,23 +348,22 @@ export const deployGenericAToken = async ( [], verify ); - + await instance.initialize( - poolAddress, + poolAddress, treasuryAddress, - underlyingAssetAddress, - incentivesController, - "18", - name, + underlyingAssetAddress, + incentivesController, + '18', + name, symbol ); return instance; }; -export const deployGenericATokenImpl = async ( - verify: boolean -) => withSaveAndVerify( +export const deployGenericATokenImpl = async (verify: boolean) => + withSaveAndVerify( await new ATokenFactory(await getFirstSigner()).deploy(), eContractid.AToken, [], @@ -404,23 +387,22 @@ export const deployDelegationAwareAToken = async ( [], verify ); - + await instance.initialize( pool, treasuryAddress, underlyingAssetAddress, incentivesController, - "18", + '18', name, symbol - ) + ); return instance; }; -export const deployDelegationAwareATokenImpl = async ( - verify: boolean -) => withSaveAndVerify( +export const deployDelegationAwareATokenImpl = async (verify: boolean) => + withSaveAndVerify( await new DelegationAwareATokenFactory(await getFirstSigner()).deploy(), eContractid.DelegationAwareAToken, [], @@ -489,10 +471,7 @@ export const deployATokensAndRatesHelper = async ( verify ); -export const deployWETHGateway = async ( - args: [tEthereumAddress, tEthereumAddress], - verify?: boolean -) => +export const deployWETHGateway = async (args: [tEthereumAddress], verify?: boolean) => withSaveAndVerify( await new WETHGatewayFactory(await getFirstSigner()).deploy(...args), eContractid.WETHGateway, @@ -500,6 +479,14 @@ export const deployWETHGateway = async ( verify ); +export const authorizeWETHGateway = async ( + wethGateWay: tEthereumAddress, + lendingPool: tEthereumAddress +) => + await new WETHGatewayFactory(await getFirstSigner()) + .attach(wethGateWay) + .authorizeLendingPool(lendingPool); + export const deployMockStableDebtToken = async ( args: [tEthereumAddress, tEthereumAddress, tEthereumAddress, string, string], verify?: boolean @@ -511,18 +498,10 @@ export const deployMockStableDebtToken = async ( verify ); - await instance.initialize( - args[0], - args[1], - args[2], - "18", - args[3], - args[4] - ); + await instance.initialize(args[0], args[1], args[2], '18', args[3], args[4]); return instance; -} - +}; export const deployWETHMocked = async (verify?: boolean) => withSaveAndVerify( @@ -543,21 +522,13 @@ export const deployMockVariableDebtToken = async ( verify ); - await instance.initialize( - args[0], - args[1], - args[2], - "18", - args[3], - args[4] - ); + await instance.initialize(args[0], args[1], args[2], '18', args[3], args[4]); return instance; -} - +}; export const deployMockAToken = async ( -args: [tEthereumAddress, tEthereumAddress, tEthereumAddress,tEthereumAddress, string, string], + args: [tEthereumAddress, tEthereumAddress, tEthereumAddress, tEthereumAddress, string, string], verify?: boolean ) => { const instance = await withSaveAndVerify( @@ -566,20 +537,11 @@ args: [tEthereumAddress, tEthereumAddress, tEthereumAddress,tEthereumAddress, st [], verify ); - - await instance.initialize( - args[0], - args[2], - args[1], - args[3], - "18", - args[4], - args[5], - ); + + await instance.initialize(args[0], args[2], args[1], args[3], '18', args[4], args[5]); return instance; -} - +}; export const deploySelfdestructTransferMock = async (verify?: boolean) => withSaveAndVerify( diff --git a/helpers/types.ts b/helpers/types.ts index 57a9bfd3..76557658 100644 --- a/helpers/types.ts +++ b/helpers/types.ts @@ -336,7 +336,7 @@ export interface IReserveParams extends IReserveBorrowParams, IReserveCollateral } export interface IInterestRateStrategyParams { - name: string, + name: string; optimalUtilizationRate: string; baseVariableBorrowRate: string; variableRateSlope1: string; @@ -452,6 +452,7 @@ export interface ICommonConfiguration { ReservesConfig: iMultiPoolsAssets; ATokenDomainSeparator: iParamsPerNetwork; WETH: iParamsPerNetwork; + WethGateway: iParamsPerNetwork; ReserveFactorTreasuryAddress: iParamsPerNetwork; } diff --git a/markets/aave/commons.ts b/markets/aave/commons.ts index 5571be27..395910d8 100644 --- a/markets/aave/commons.ts +++ b/markets/aave/commons.ts @@ -1,4 +1,3 @@ -import BigNumber from 'bignumber.js'; import { oneEther, oneRay, RAY, ZERO_ADDRESS } from '../../helpers/constants'; import { ICommonConfiguration, EthereumNetwork, eEthereumNetwork } from '../../helpers/types'; @@ -196,6 +195,15 @@ export const CommonsConfig: ICommonConfiguration = { [eEthereumNetwork.main]: '0xbd4765210d4167CE2A5b87280D9E8Ee316D5EC7C', [eEthereumNetwork.tenderlyMain]: '0xbd4765210d4167CE2A5b87280D9E8Ee316D5EC7C', }, + WethGateway: { + [eEthereumNetwork.coverage]: '', + [eEthereumNetwork.hardhat]: '', + [eEthereumNetwork.buidlerevm]: '', + [eEthereumNetwork.kovan]: '', + [eEthereumNetwork.ropsten]: '', + [eEthereumNetwork.main]: '', + [eEthereumNetwork.tenderlyMain]: '', + }, TokenDistributor: { [eEthereumNetwork.coverage]: '', [eEthereumNetwork.buidlerevm]: '', diff --git a/markets/lp/commons.ts b/markets/lp/commons.ts index d29b7d29..e02676ae 100644 --- a/markets/lp/commons.ts +++ b/markets/lp/commons.ts @@ -199,6 +199,15 @@ export const CommonsConfig: ICommonConfiguration = { [eEthereumNetwork.main]: '0xbd4765210d4167CE2A5b87280D9E8Ee316D5EC7C', [eEthereumNetwork.tenderlyMain]: '0xbd4765210d4167CE2A5b87280D9E8Ee316D5EC7C', }, + WethGateway: { + [eEthereumNetwork.coverage]: '', + [eEthereumNetwork.hardhat]: '', + [eEthereumNetwork.buidlerevm]: '', + [eEthereumNetwork.kovan]: '', + [eEthereumNetwork.ropsten]: '', + [eEthereumNetwork.main]: '', + [eEthereumNetwork.tenderlyMain]: '', + }, TokenDistributor: { [eEthereumNetwork.coverage]: '', [eEthereumNetwork.buidlerevm]: '', diff --git a/package.json b/package.json index b2492041..8c78210e 100644 --- a/package.json +++ b/package.json @@ -32,7 +32,8 @@ "test-permit": "hardhat test test-suites/test-aave/__setup.spec.ts test-suites/test-aave/atoken-permit.spec.ts", "test-stable-and-atokens": "hardhat test test-suites/test-aave/__setup.spec.ts test-suites/test-aave/atoken-transfer.spec.ts test-suites/test-aave/stable-token.spec.ts", "test-subgraph:scenarios": "hardhat --network hardhatevm_docker test test-suites/test-aave/__setup.spec.ts test-suites/test-aave/subgraph-scenarios.spec.ts", - "test-weth": "hardhat test test-suites/test-aave/__setup.spec.ts test-suites/test-aave/weth-gateway.spec.ts", + "test-weth:main": "hardhat test test-suites/test-aave/__setup.spec.ts test-suites/test-aave/weth-gateway.spec.ts", + "test-weth:lp": "hardhat test test-suites/test-lp/__setup.spec.ts test-suites/test-lp/weth-gateway.spec.ts", "test-uniswap": "hardhat test test-suites/test-aave/__setup.spec.ts test-suites/test-aave/uniswapAdapters*.spec.ts", "test:main:check-list": "MAINNET_FORK=true TS_NODE_TRANSPILE_ONLY=1 hardhat test test-suites/test-aave/__setup.spec.ts test-suites/test-aave/mainnet/check-list.spec.ts", "dev:coverage": "buidler compile --force && buidler coverage --network coverage", diff --git a/tasks/deployments/deploy-wethGateWay.ts b/tasks/deployments/deploy-wethGateWay.ts new file mode 100644 index 00000000..83611efc --- /dev/null +++ b/tasks/deployments/deploy-wethGateWay.ts @@ -0,0 +1,21 @@ +import { task } from 'hardhat/config'; + +import { deployWETHGateway } from '../../helpers/contracts-deployments'; + +const CONTRACT_NAME = 'WETHGateway'; + +task(`deploy-${CONTRACT_NAME}`, `Deploys the ${CONTRACT_NAME} contract`) + .addParam('weth', 'Address of the weth token') + .addFlag('verify', `Verify ${CONTRACT_NAME} contract via Etherscan API.`) + .setAction(async ({ weth, verify }, localBRE) => { + await localBRE.run('set-DRE'); + + if (!localBRE.network.config.chainId) { + throw new Error('INVALID_CHAIN_ID'); + } + + const wethGateWay = await deployWETHGateway([weth], verify); + console.log(`${CONTRACT_NAME}.address`, wethGateWay.address); + + console.log(`\tFinished ${CONTRACT_NAME} deployment`); + }); diff --git a/tasks/dev/5_initialize.ts b/tasks/dev/5_initialize.ts index 983b7454..6c11ad6d 100644 --- a/tasks/dev/5_initialize.ts +++ b/tasks/dev/5_initialize.ts @@ -5,7 +5,10 @@ import { deployWalletBalancerProvider, deployAaveProtocolDataProvider, deployWETHGateway, + authorizeWETHGateway, } from '../../helpers/contracts-deployments'; +import { getParamPerNetwork } from '../../helpers/contracts-helpers'; +import { eEthereumNetwork } from '../../helpers/types'; import { ConfigNames, getReservesConfigByPool, @@ -30,12 +33,14 @@ task('dev:initialize-lending-pool', 'Initialize lending pool configuration.') .addParam('pool', `Pool name to retrieve configuration, supported: ${Object.values(ConfigNames)}`) .setAction(async ({ verify, pool }, localBRE) => { await localBRE.run('set-DRE'); + const network = localBRE.network.name; const poolConfig = loadPoolConfig(pool); const { ATokenNamePrefix, StableDebtTokenNamePrefix, VariableDebtTokenNamePrefix, SymbolPrefix, + WethGateway, } = poolConfig; const mockTokens = await getAllMockedTokens(); const allTokenAddresses = getAllTokenAddresses(mockTokens); @@ -87,6 +92,6 @@ task('dev:initialize-lending-pool', 'Initialize lending pool configuration.') await insertContractAddressInDb(eContractid.AaveProtocolDataProvider, testHelpers.address); const lendingPoolAddress = await addressesProvider.getLendingPool(); - const wethAddress = await getWethAddress(poolConfig); - await deployWETHGateway([wethAddress, lendingPoolAddress]); + const gateWay = await getParamPerNetwork(WethGateway, network); + await authorizeWETHGateway(gateWay, lendingPoolAddress); }); diff --git a/tasks/full/5_initialize.ts b/tasks/full/5_initialize.ts index 99725034..2e92ad90 100644 --- a/tasks/full/5_initialize.ts +++ b/tasks/full/5_initialize.ts @@ -4,6 +4,7 @@ import { deployLendingPoolCollateralManager, deployWalletBalancerProvider, deployWETHGateway, + authorizeWETHGateway, } from '../../helpers/contracts-deployments'; import { loadPoolConfig, @@ -29,14 +30,15 @@ task('full:initialize-lending-pool', 'Initialize lending pool configuration.') await localBRE.run('set-DRE'); const network = localBRE.network.name; const poolConfig = loadPoolConfig(pool); - const { + const { ATokenNamePrefix, StableDebtTokenNamePrefix, VariableDebtTokenNamePrefix, SymbolPrefix, ReserveAssets, ReservesConfig, - LendingPoolCollateralManager + LendingPoolCollateralManager, + WethGateway, } = poolConfig as ICommonConfiguration; const reserveAssets = await getParamPerNetwork(ReserveAssets, network); @@ -66,9 +68,10 @@ task('full:initialize-lending-pool', 'Initialize lending pool configuration.') ); await configureReservesByHelper(ReservesConfig, reserveAssets, testHelpers, admin); - - - let collateralManagerAddress = await getParamPerNetwork(LendingPoolCollateralManager, network); + let collateralManagerAddress = await getParamPerNetwork( + LendingPoolCollateralManager, + network + ); if (!collateralManagerAddress) { const collateralManager = await deployLendingPoolCollateralManager(verify); collateralManagerAddress = collateralManager.address; @@ -81,10 +84,10 @@ task('full:initialize-lending-pool', 'Initialize lending pool configuration.') await deployWalletBalancerProvider(verify); - const wethAddress = await getWethAddress(poolConfig); const lendingPoolAddress = await addressesProvider.getLendingPool(); - await deployWETHGateway([wethAddress, lendingPoolAddress]); + const gateWay = await getParamPerNetwork(WethGateway, network); + await authorizeWETHGateway(gateWay, lendingPoolAddress); } catch (err) { console.error(err); exit(1); diff --git a/test-suites/test-aave/__setup.spec.ts b/test-suites/test-aave/__setup.spec.ts index 006e0d74..9fc9d4f8 100644 --- a/test-suites/test-aave/__setup.spec.ts +++ b/test-suites/test-aave/__setup.spec.ts @@ -26,7 +26,9 @@ import { deployUniswapLiquiditySwapAdapter, deployUniswapRepayAdapter, deployFlashLiquidationAdapter, + authorizeWETHGateway, } from '../../helpers/contracts-deployments'; +import { eEthereumNetwork } from '../../helpers/types'; import { Signer } from 'ethers'; import { TokenContractId, eContractid, tEthereumAddress, AavePools } from '../../helpers/types'; import { MintableERC20 } from '../../types/MintableERC20'; @@ -95,7 +97,7 @@ const buildTestEnv = async (deployer: Signer, secondaryWallet: Signer) => { const aaveAdmin = await deployer.getAddress(); const mockTokens = await deployAllMockTokens(deployer); - console.log("Deployed mocks"); + console.log('Deployed mocks'); const addressesProvider = await deployLendingPoolAddressesProvider(AaveConfig.MarketId); await waitForTx(await addressesProvider.setPoolAdmin(aaveAdmin)); @@ -191,7 +193,7 @@ const buildTestEnv = async (deployer: Signer, secondaryWallet: Signer) => { ); const mockAggregators = await deployAllMockAggregators(MOCK_CHAINLINK_AGGREGATORS_PRICES); - console.log("Mock aggs deployed"); + console.log('Mock aggs deployed'); const allTokenAddresses = Object.entries(mockTokens).reduce( (accum: { [tokenSymbol: string]: tEthereumAddress }, [tokenSymbol, tokenContract]) => ({ ...accum, @@ -237,7 +239,7 @@ const buildTestEnv = async (deployer: Signer, secondaryWallet: Signer) => { const config = loadPoolConfig(ConfigNames.Aave); - const { + const { ATokenNamePrefix, StableDebtTokenNamePrefix, VariableDebtTokenNamePrefix, @@ -280,7 +282,8 @@ const buildTestEnv = async (deployer: Signer, secondaryWallet: Signer) => { await deployWalletBalancerProvider(); - await deployWETHGateway([mockTokens.WETH.address, lendingPoolAddress]); + const gateWay = await deployWETHGateway([mockTokens.WETH.address]); + await authorizeWETHGateway(gateWay.address, lendingPoolAddress); console.timeEnd('setup'); }; diff --git a/test-suites/test-aave/weth-gateway.spec.ts b/test-suites/test-aave/weth-gateway.spec.ts index 22939f5c..b1980d68 100644 --- a/test-suites/test-aave/weth-gateway.spec.ts +++ b/test-suites/test-aave/weth-gateway.spec.ts @@ -14,7 +14,7 @@ makeSuite('Use native ETH at LendingPool via WETHGateway', (testEnv: TestEnv) => const depositSize = parseEther('5'); const daiSize = parseEther('10000'); it('Deposit WETH via WethGateway and DAI', async () => { - const { users, wethGateway, aWETH } = testEnv; + const { users, wethGateway, aWETH, pool } = testEnv; const user = users[1]; const depositor = users[0]; @@ -22,10 +22,12 @@ makeSuite('Use native ETH at LendingPool via WETHGateway', (testEnv: TestEnv) => // Deposit liquidity with native ETH await wethGateway .connect(depositor.signer) - .depositETH(depositor.address, '0', { value: depositSize }); + .depositETH(pool.address, 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(pool.address, user.address, '0', { value: depositSize }); const aTokensBalance = await aWETH.balanceOf(user.address); @@ -53,7 +55,9 @@ makeSuite('Use native ETH at LendingPool via WETHGateway', (testEnv: TestEnv) => // Partial Withdraw and send native Ether to user const { gasUsed: withdrawGas } = await waitForTx( - await wethGateway.connect(user.signer).withdrawETH(partialWithdraw, user.address) + await wethGateway + .connect(user.signer) + .withdrawETH(pool.address, partialWithdraw, user.address) ); const afterPartialEtherBalance = await user.signer.getBalance(); @@ -87,7 +91,9 @@ makeSuite('Use native ETH at LendingPool via WETHGateway', (testEnv: TestEnv) => // Full withdraw const { gasUsed: withdrawGas } = await waitForTx( - await wethGateway.connect(user.signer).withdrawETH(MAX_UINT_AMOUNT, user.address) + await wethGateway + .connect(user.signer) + .withdrawETH(pool.address, MAX_UINT_AMOUNT, user.address) ); const afterFullEtherBalance = await user.signer.getBalance(); @@ -111,7 +117,7 @@ makeSuite('Use native ETH at LendingPool via WETHGateway', (testEnv: TestEnv) => // Deposit with native ETH await wethGateway .connect(depositor.signer) - .depositETH(depositor.address, '0', { value: depositSize }); + .depositETH(pool.address, depositor.address, '0', { value: depositSize }); const { stableDebtTokenAddress } = await helpersContract.getReserveTokensAddresses( weth.address @@ -142,7 +148,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(pool.address, MAX_UINT_AMOUNT, '1', user.address, { value: repaySize }) ); const debtBalanceAfterRepay = await stableDebtToken.balanceOf(user.address); @@ -166,7 +172,9 @@ makeSuite('Use native ETH at LendingPool via WETHGateway', (testEnv: TestEnv) => 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(pool.address, user.address, '0', { value: depositSize }); const aTokensBalance = await aWETH.balanceOf(user.address); @@ -187,7 +195,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(pool.address, partialPayment, '2', user.address, { value: partialPayment }) ); const debtBalanceAfterPartialRepay = await varDebtToken.balanceOf(user.address); @@ -197,14 +205,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: repaySize }) + .repayETH(pool.address, 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, pool } = testEnv; const borrowSize = parseEther('1'); const user = users[2]; const { variableDebtTokenAddress } = await helpersContract.getReserveTokensAddresses( @@ -216,7 +224,9 @@ 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(pool.address, user.address, '0', { value: depositSize }); const aTokensBalance = await aWETH.balanceOf(user.address); @@ -229,7 +239,9 @@ makeSuite('Use native ETH at LendingPool via WETHGateway', (testEnv: TestEnv) => ); // Borrows ETH with WETH as collateral - await waitForTx(await wethGateway.connect(user.signer).borrowETH(borrowSize, '2', '0')); + await waitForTx( + await wethGateway.connect(user.signer).borrowETH(pool.address, borrowSize, '2', '0') + ); const debtBalance = await varDebtToken.balanceOf(user.address); @@ -239,7 +251,7 @@ 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(pool.address, MAX_UINT_AMOUNT, '2', user.address, { value: borrowSize.mul(2) }) ); const debtBalanceAfterFullRepay = await varDebtToken.balanceOf(user.address); expect(debtBalanceAfterFullRepay).to.be.eq(zero); @@ -297,18 +309,6 @@ makeSuite('Use native ETH at LendingPool via WETHGateway', (testEnv: TestEnv) => ).to.be.revertedWith('Fallback not allowed'); }); - it('Getters should retrieve correct state', async () => { - const { aWETH, weth, pool, wethGateway } = testEnv; - - const WETHAddress = await wethGateway.getWETHAddress(); - const aWETHAddress = await wethGateway.getAWETHAddress(); - const poolAddress = await wethGateway.getLendingPoolAddress(); - - expect(WETHAddress).to.be.equal(weth.address); - expect(aWETHAddress).to.be.equal(aWETH.address); - expect(poolAddress).to.be.equal(pool.address); - }); - it('Owner can do emergency token recovery', async () => { const { users, dai, wethGateway, deployer } = testEnv; const user = users[0]; diff --git a/test-suites/test-lp/__setup.spec.ts b/test-suites/test-lp/__setup.spec.ts index 09c02efc..23843a6c 100644 --- a/test-suites/test-lp/__setup.spec.ts +++ b/test-suites/test-lp/__setup.spec.ts @@ -26,6 +26,7 @@ import { deployUniswapLiquiditySwapAdapter, deployUniswapRepayAdapter, deployFlashLiquidationAdapter, + authorizeWETHGateway } from '../../helpers/contracts-deployments'; import { Signer } from 'ethers'; import { TokenContractId, eContractid, tEthereumAddress, AavePools } from '../../helpers/types'; @@ -279,7 +280,8 @@ const buildTestEnv = async (deployer: Signer, secondaryWallet: Signer) => { await deployWalletBalancerProvider(); - await deployWETHGateway([mockTokens.WETH.address, lendingPoolAddress]); + const gateWay = await deployWETHGateway([mockTokens.WETH.address]); + await authorizeWETHGateway(gateWay.address, lendingPoolAddress); console.timeEnd('setup'); }; diff --git a/test-suites/test-lp/weth-gateway.spec.ts b/test-suites/test-lp/weth-gateway.spec.ts index b8a0216a..80a3b169 100644 --- a/test-suites/test-lp/weth-gateway.spec.ts +++ b/test-suites/test-lp/weth-gateway.spec.ts @@ -15,7 +15,7 @@ makeSuite('Use native ETH at LendingPool via WETHGateway', (testEnv: TestEnv) => const depositSize = parseEther('5'); const daiSize = parseEther('10000'); it('Deposit WETH via WethGateway and DAI', async () => { - const { users, wethGateway, aWETH } = testEnv; + const { users, wethGateway, aWETH, pool } = testEnv; const user = users[1]; const depositor = users[0]; @@ -23,10 +23,10 @@ makeSuite('Use native ETH at LendingPool via WETHGateway', (testEnv: TestEnv) => // Deposit liquidity with native ETH await wethGateway .connect(depositor.signer) - .depositETH(depositor.address, '0', { value: depositSize }); + .depositETH(pool.address, 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(pool.address, user.address, '0', { value: depositSize }); const aTokensBalance = await aWETH.balanceOf(user.address); @@ -54,7 +54,7 @@ makeSuite('Use native ETH at LendingPool via WETHGateway', (testEnv: TestEnv) => // Partial Withdraw and send native Ether to user const { gasUsed: withdrawGas } = await waitForTx( - await wethGateway.connect(user.signer).withdrawETH(partialWithdraw, user.address) + await wethGateway.connect(user.signer).withdrawETH(pool.address, partialWithdraw, user.address) ); const afterPartialEtherBalance = await user.signer.getBalance(); @@ -88,7 +88,7 @@ makeSuite('Use native ETH at LendingPool via WETHGateway', (testEnv: TestEnv) => // Full withdraw const { gasUsed: withdrawGas } = await waitForTx( - await wethGateway.connect(user.signer).withdrawETH(MAX_UINT_AMOUNT, user.address) + await wethGateway.connect(user.signer).withdrawETH(pool.address, MAX_UINT_AMOUNT, user.address) ); const afterFullEtherBalance = await user.signer.getBalance(); @@ -112,7 +112,7 @@ makeSuite('Use native ETH at LendingPool via WETHGateway', (testEnv: TestEnv) => // Deposit with native ETH await wethGateway .connect(depositor.signer) - .depositETH(depositor.address, '0', { value: depositSize }); + .depositETH(pool.address, depositor.address, '0', { value: depositSize }); const { stableDebtTokenAddress } = await helpersContract.getReserveTokensAddresses( weth.address @@ -168,7 +168,7 @@ makeSuite('Use native ETH at LendingPool via WETHGateway', (testEnv: TestEnv) => 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(pool.address, user.address, '0', { value: depositSize }); const aTokensBalance = await aWETH.balanceOf(user.address); @@ -189,7 +189,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(pool.address, partialPayment, '2', user.address, { value: partialPayment }) ); const debtBalanceAfterPartialRepay = await varDebtToken.balanceOf(user.address); @@ -199,14 +199,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: repaySize }) + .repayETH(pool.address, 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, pool } = testEnv; const borrowSize = parseEther('1'); const user = users[2]; const { variableDebtTokenAddress } = await helpersContract.getReserveTokensAddresses( @@ -218,7 +218,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(pool.address, user.address, '0', { value: depositSize }); const aTokensBalance = await aWETH.balanceOf(user.address); @@ -231,7 +231,7 @@ makeSuite('Use native ETH at LendingPool via WETHGateway', (testEnv: TestEnv) => ); // Borrows ETH with WETH as collateral - await waitForTx(await wethGateway.connect(user.signer).borrowETH(borrowSize, '2', '0')); + await waitForTx(await wethGateway.connect(user.signer).borrowETH(pool.address, borrowSize, '2', '0')); const debtBalance = await varDebtToken.balanceOf(user.address); @@ -241,7 +241,7 @@ 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(pool.address, MAX_UINT_AMOUNT, '2', user.address, { value: borrowSize.mul(2) }) ); const debtBalanceAfterFullRepay = await varDebtToken.balanceOf(user.address); expect(debtBalanceAfterFullRepay).to.be.eq(zero); @@ -299,17 +299,6 @@ makeSuite('Use native ETH at LendingPool via WETHGateway', (testEnv: TestEnv) => ).to.be.revertedWith('Fallback not allowed'); }); - it('Getters should retrieve correct state', async () => { - const { aWETH, weth, pool, wethGateway } = testEnv; - - const WETHAddress = await wethGateway.getWETHAddress(); - const aWETHAddress = await wethGateway.getAWETHAddress(); - const poolAddress = await wethGateway.getLendingPoolAddress(); - - expect(WETHAddress).to.be.equal(weth.address); - expect(aWETHAddress).to.be.equal(aWETH.address); - expect(poolAddress).to.be.equal(pool.address); - }); it('Owner can do emergency token recovery', async () => { const { users, dai, wethGateway, deployer } = testEnv;