mirror of
https://github.com/Instadapp/aave-protocol-v2.git
synced 2024-07-29 21:47:30 +00:00
Merge pull request #39 from aave/feat/update-wethgateway
Feat/update wethgateway
This commit is contained in:
commit
e9451c85eb
|
@ -18,39 +18,47 @@ contract WETHGateway is IWETHGateway, Ownable {
|
||||||
using UserConfiguration for DataTypes.UserConfigurationMap;
|
using UserConfiguration for DataTypes.UserConfigurationMap;
|
||||||
|
|
||||||
IWETH internal immutable WETH;
|
IWETH internal immutable WETH;
|
||||||
ILendingPool internal immutable POOL;
|
|
||||||
IAToken internal immutable aWETH;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dev Sets the WETH address and the LendingPoolAddressesProvider address. Infinite approves lending pool.
|
* @dev Sets the WETH address and the LendingPoolAddressesProvider address. Infinite approves lending pool.
|
||||||
* @param weth Address of the Wrapped Ether contract
|
* @param weth Address of the Wrapped Ether contract
|
||||||
* @param pool Address of the LendingPool contract
|
|
||||||
**/
|
**/
|
||||||
constructor(address weth, address pool) public {
|
constructor(address weth) public {
|
||||||
ILendingPool poolInstance = ILendingPool(pool);
|
|
||||||
WETH = IWETH(weth);
|
WETH = IWETH(weth);
|
||||||
POOL = poolInstance;
|
}
|
||||||
aWETH = IAToken(poolInstance.getReserveData(weth).aTokenAddress);
|
|
||||||
IWETH(weth).approve(pool, uint256(-1));
|
function authorizeLendingPool(address lendingPool) external onlyOwner {
|
||||||
|
WETH.approve(lendingPool, uint256(-1));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dev deposits WETH into the reserve, using native ETH. A corresponding amount of the overlying asset (aTokens)
|
* @dev deposits WETH into the reserve, using native ETH. A corresponding amount of the overlying asset (aTokens)
|
||||||
* is minted.
|
* 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 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.
|
* @param referralCode integrators are assigned a referral code and can potentially receive rewards.
|
||||||
**/
|
**/
|
||||||
function depositETH(address onBehalfOf, uint16 referralCode) external payable override {
|
function depositETH(
|
||||||
|
address lendingPool,
|
||||||
|
address onBehalfOf,
|
||||||
|
uint16 referralCode
|
||||||
|
) external payable override {
|
||||||
WETH.deposit{value: msg.value}();
|
WETH.deposit{value: msg.value}();
|
||||||
POOL.deposit(address(WETH), msg.value, onBehalfOf, referralCode);
|
ILendingPool(lendingPool).deposit(address(WETH), msg.value, onBehalfOf, referralCode);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dev withdraws the WETH _reserves of msg.sender.
|
* @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 amount amount of aWETH to withdraw and receive native ETH
|
||||||
* @param to address of the user who will receive native ETH
|
* @param to address of the user who will receive native ETH
|
||||||
*/
|
*/
|
||||||
function withdrawETH(uint256 amount, address to) external override {
|
function withdrawETH(
|
||||||
|
address lendingPool,
|
||||||
|
uint256 amount,
|
||||||
|
address to
|
||||||
|
) external override {
|
||||||
|
IAToken aWETH = IAToken(ILendingPool(lendingPool).getReserveData(address(WETH)).aTokenAddress);
|
||||||
uint256 userBalance = aWETH.balanceOf(msg.sender);
|
uint256 userBalance = aWETH.balanceOf(msg.sender);
|
||||||
uint256 amountToWithdraw = amount;
|
uint256 amountToWithdraw = amount;
|
||||||
|
|
||||||
|
@ -59,24 +67,29 @@ contract WETHGateway is IWETHGateway, Ownable {
|
||||||
amountToWithdraw = userBalance;
|
amountToWithdraw = userBalance;
|
||||||
}
|
}
|
||||||
aWETH.transferFrom(msg.sender, address(this), amountToWithdraw);
|
aWETH.transferFrom(msg.sender, address(this), amountToWithdraw);
|
||||||
POOL.withdraw(address(WETH), amountToWithdraw, address(this));
|
ILendingPool(lendingPool).withdraw(address(WETH), amountToWithdraw, address(this));
|
||||||
WETH.withdraw(amountToWithdraw);
|
WETH.withdraw(amountToWithdraw);
|
||||||
_safeTransferETH(to, amountToWithdraw);
|
_safeTransferETH(to, amountToWithdraw);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dev repays a borrow on the WETH reserve, for the specified amount (or for the whole amount, if uint256(-1) is specified).
|
* @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 amount the amount to repay, or uint256(-1) if the user wants to repay everything
|
||||||
* @param rateMode the rate mode to repay
|
* @param rateMode the rate mode to repay
|
||||||
* @param onBehalfOf the address for which msg.sender is repaying
|
* @param onBehalfOf the address for which msg.sender is repaying
|
||||||
*/
|
*/
|
||||||
function repayETH(
|
function repayETH(
|
||||||
|
address lendingPool,
|
||||||
uint256 amount,
|
uint256 amount,
|
||||||
uint256 rateMode,
|
uint256 rateMode,
|
||||||
address onBehalfOf
|
address onBehalfOf
|
||||||
) external payable override {
|
) external payable override {
|
||||||
(uint256 stableDebt, uint256 variableDebt) =
|
(uint256 stableDebt, uint256 variableDebt) =
|
||||||
Helpers.getUserCurrentDebtMemory(onBehalfOf, POOL.getReserveData(address(WETH)));
|
Helpers.getUserCurrentDebtMemory(
|
||||||
|
onBehalfOf,
|
||||||
|
ILendingPool(lendingPool).getReserveData(address(WETH))
|
||||||
|
);
|
||||||
|
|
||||||
uint256 paybackAmount =
|
uint256 paybackAmount =
|
||||||
DataTypes.InterestRateMode(rateMode) == DataTypes.InterestRateMode.STABLE
|
DataTypes.InterestRateMode(rateMode) == DataTypes.InterestRateMode.STABLE
|
||||||
|
@ -88,7 +101,7 @@ contract WETHGateway is IWETHGateway, Ownable {
|
||||||
}
|
}
|
||||||
require(msg.value >= paybackAmount, 'msg.value is less than repayment amount');
|
require(msg.value >= paybackAmount, 'msg.value is less than repayment amount');
|
||||||
WETH.deposit{value: paybackAmount}();
|
WETH.deposit{value: paybackAmount}();
|
||||||
POOL.repay(address(WETH), msg.value, rateMode, onBehalfOf);
|
ILendingPool(lendingPool).repay(address(WETH), msg.value, rateMode, onBehalfOf);
|
||||||
|
|
||||||
// refund remaining dust eth
|
// refund remaining dust eth
|
||||||
if (msg.value > paybackAmount) _safeTransferETH(msg.sender, msg.value - paybackAmount);
|
if (msg.value > paybackAmount) _safeTransferETH(msg.sender, msg.value - paybackAmount);
|
||||||
|
@ -96,16 +109,24 @@ 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`.
|
* @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 amount the amount of ETH to borrow
|
||||||
* @param interesRateMode the interest rate mode
|
* @param interesRateMode the interest rate mode
|
||||||
* @param referralCode integrators are assigned a referral code and can potentially receive rewards
|
* @param referralCode integrators are assigned a referral code and can potentially receive rewards
|
||||||
*/
|
*/
|
||||||
function borrowETH(
|
function borrowETH(
|
||||||
|
address lendingPool,
|
||||||
uint256 amount,
|
uint256 amount,
|
||||||
uint256 interesRateMode,
|
uint256 interesRateMode,
|
||||||
uint16 referralCode
|
uint16 referralCode
|
||||||
) external override {
|
) external override {
|
||||||
POOL.borrow(address(WETH), amount, interesRateMode, referralCode, msg.sender);
|
ILendingPool(lendingPool).borrow(
|
||||||
|
address(WETH),
|
||||||
|
amount,
|
||||||
|
interesRateMode,
|
||||||
|
referralCode,
|
||||||
|
msg.sender
|
||||||
|
);
|
||||||
WETH.withdraw(amount);
|
WETH.withdraw(amount);
|
||||||
_safeTransferETH(msg.sender, amount);
|
_safeTransferETH(msg.sender, amount);
|
||||||
}
|
}
|
||||||
|
@ -152,20 +173,6 @@ contract WETHGateway is IWETHGateway, Ownable {
|
||||||
return address(WETH);
|
return address(WETH);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @dev Get aWETH address used by WETHGateway
|
|
||||||
*/
|
|
||||||
function getAWETHAddress() external view returns (address) {
|
|
||||||
return address(aWETH);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @dev Get LendingPool address used by WETHGateway
|
|
||||||
*/
|
|
||||||
function getLendingPoolAddress() external view returns (address) {
|
|
||||||
return address(POOL);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dev Only WETH contract is allowed to transfer ETH here. Prevent other addresses to send Ether to this contract.
|
* @dev Only WETH contract is allowed to transfer ETH here. Prevent other addresses to send Ether to this contract.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -2,17 +2,27 @@
|
||||||
pragma solidity 0.6.12;
|
pragma solidity 0.6.12;
|
||||||
|
|
||||||
interface IWETHGateway {
|
interface IWETHGateway {
|
||||||
function depositETH(address onBehalfOf, uint16 referralCode) external payable;
|
function depositETH(
|
||||||
|
address lendingPool,
|
||||||
|
address onBehalfOf,
|
||||||
|
uint16 referralCode
|
||||||
|
) external payable;
|
||||||
|
|
||||||
function withdrawETH(uint256 amount, address onBehalfOf) external;
|
function withdrawETH(
|
||||||
|
address lendingPool,
|
||||||
|
uint256 amount,
|
||||||
|
address onBehalfOf
|
||||||
|
) external;
|
||||||
|
|
||||||
function repayETH(
|
function repayETH(
|
||||||
|
address lendingPool,
|
||||||
uint256 amount,
|
uint256 amount,
|
||||||
uint256 rateMode,
|
uint256 rateMode,
|
||||||
address onBehalfOf
|
address onBehalfOf
|
||||||
) external payable;
|
) external payable;
|
||||||
|
|
||||||
function borrowETH(
|
function borrowETH(
|
||||||
|
address lendingPool,
|
||||||
uint256 amount,
|
uint256 amount,
|
||||||
uint256 interesRateMode,
|
uint256 interesRateMode,
|
||||||
uint16 referralCode
|
uint16 referralCode
|
||||||
|
|
|
@ -310,18 +310,10 @@ export const deployStableDebtToken = async (
|
||||||
verify
|
verify
|
||||||
);
|
);
|
||||||
|
|
||||||
await instance.initialize(
|
await instance.initialize(args[0], args[1], args[2], '18', args[3], args[4]);
|
||||||
args[0],
|
|
||||||
args[1],
|
|
||||||
args[2],
|
|
||||||
"18",
|
|
||||||
args[3],
|
|
||||||
args[4]
|
|
||||||
);
|
|
||||||
|
|
||||||
return instance;
|
return instance;
|
||||||
}
|
};
|
||||||
|
|
||||||
|
|
||||||
export const deployVariableDebtToken = async (
|
export const deployVariableDebtToken = async (
|
||||||
args: [tEthereumAddress, tEthereumAddress, tEthereumAddress, string, string],
|
args: [tEthereumAddress, tEthereumAddress, tEthereumAddress, string, string],
|
||||||
|
@ -334,18 +326,10 @@ export const deployVariableDebtToken = async (
|
||||||
verify
|
verify
|
||||||
);
|
);
|
||||||
|
|
||||||
await instance.initialize(
|
await instance.initialize(args[0], args[1], args[2], '18', args[3], args[4]);
|
||||||
args[0],
|
|
||||||
args[1],
|
|
||||||
args[2],
|
|
||||||
"18",
|
|
||||||
args[3],
|
|
||||||
args[4]
|
|
||||||
);
|
|
||||||
|
|
||||||
return instance;
|
return instance;
|
||||||
}
|
};
|
||||||
|
|
||||||
|
|
||||||
export const deployGenericAToken = async (
|
export const deployGenericAToken = async (
|
||||||
[poolAddress, underlyingAssetAddress, treasuryAddress, incentivesController, name, symbol]: [
|
[poolAddress, underlyingAssetAddress, treasuryAddress, incentivesController, name, symbol]: [
|
||||||
|
@ -370,7 +354,7 @@ export const deployGenericAToken = async (
|
||||||
treasuryAddress,
|
treasuryAddress,
|
||||||
underlyingAssetAddress,
|
underlyingAssetAddress,
|
||||||
incentivesController,
|
incentivesController,
|
||||||
"18",
|
'18',
|
||||||
name,
|
name,
|
||||||
symbol
|
symbol
|
||||||
);
|
);
|
||||||
|
@ -378,9 +362,8 @@ export const deployGenericAToken = async (
|
||||||
return instance;
|
return instance;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const deployGenericATokenImpl = async (
|
export const deployGenericATokenImpl = async (verify: boolean) =>
|
||||||
verify: boolean
|
withSaveAndVerify(
|
||||||
) => withSaveAndVerify(
|
|
||||||
await new ATokenFactory(await getFirstSigner()).deploy(),
|
await new ATokenFactory(await getFirstSigner()).deploy(),
|
||||||
eContractid.AToken,
|
eContractid.AToken,
|
||||||
[],
|
[],
|
||||||
|
@ -410,17 +393,16 @@ export const deployDelegationAwareAToken = async (
|
||||||
treasuryAddress,
|
treasuryAddress,
|
||||||
underlyingAssetAddress,
|
underlyingAssetAddress,
|
||||||
incentivesController,
|
incentivesController,
|
||||||
"18",
|
'18',
|
||||||
name,
|
name,
|
||||||
symbol
|
symbol
|
||||||
)
|
);
|
||||||
|
|
||||||
return instance;
|
return instance;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const deployDelegationAwareATokenImpl = async (
|
export const deployDelegationAwareATokenImpl = async (verify: boolean) =>
|
||||||
verify: boolean
|
withSaveAndVerify(
|
||||||
) => withSaveAndVerify(
|
|
||||||
await new DelegationAwareATokenFactory(await getFirstSigner()).deploy(),
|
await new DelegationAwareATokenFactory(await getFirstSigner()).deploy(),
|
||||||
eContractid.DelegationAwareAToken,
|
eContractid.DelegationAwareAToken,
|
||||||
[],
|
[],
|
||||||
|
@ -489,10 +471,7 @@ export const deployATokensAndRatesHelper = async (
|
||||||
verify
|
verify
|
||||||
);
|
);
|
||||||
|
|
||||||
export const deployWETHGateway = async (
|
export const deployWETHGateway = async (args: [tEthereumAddress], verify?: boolean) =>
|
||||||
args: [tEthereumAddress, tEthereumAddress],
|
|
||||||
verify?: boolean
|
|
||||||
) =>
|
|
||||||
withSaveAndVerify(
|
withSaveAndVerify(
|
||||||
await new WETHGatewayFactory(await getFirstSigner()).deploy(...args),
|
await new WETHGatewayFactory(await getFirstSigner()).deploy(...args),
|
||||||
eContractid.WETHGateway,
|
eContractid.WETHGateway,
|
||||||
|
@ -500,6 +479,14 @@ export const deployWETHGateway = async (
|
||||||
verify
|
verify
|
||||||
);
|
);
|
||||||
|
|
||||||
|
export const authorizeWETHGateway = async (
|
||||||
|
wethGateWay: tEthereumAddress,
|
||||||
|
lendingPool: tEthereumAddress
|
||||||
|
) =>
|
||||||
|
await new WETHGatewayFactory(await getFirstSigner())
|
||||||
|
.attach(wethGateWay)
|
||||||
|
.authorizeLendingPool(lendingPool);
|
||||||
|
|
||||||
export const deployMockStableDebtToken = async (
|
export const deployMockStableDebtToken = async (
|
||||||
args: [tEthereumAddress, tEthereumAddress, tEthereumAddress, string, string],
|
args: [tEthereumAddress, tEthereumAddress, tEthereumAddress, string, string],
|
||||||
verify?: boolean
|
verify?: boolean
|
||||||
|
@ -511,18 +498,10 @@ export const deployMockStableDebtToken = async (
|
||||||
verify
|
verify
|
||||||
);
|
);
|
||||||
|
|
||||||
await instance.initialize(
|
await instance.initialize(args[0], args[1], args[2], '18', args[3], args[4]);
|
||||||
args[0],
|
|
||||||
args[1],
|
|
||||||
args[2],
|
|
||||||
"18",
|
|
||||||
args[3],
|
|
||||||
args[4]
|
|
||||||
);
|
|
||||||
|
|
||||||
return instance;
|
return instance;
|
||||||
}
|
};
|
||||||
|
|
||||||
|
|
||||||
export const deployWETHMocked = async (verify?: boolean) =>
|
export const deployWETHMocked = async (verify?: boolean) =>
|
||||||
withSaveAndVerify(
|
withSaveAndVerify(
|
||||||
|
@ -543,21 +522,13 @@ export const deployMockVariableDebtToken = async (
|
||||||
verify
|
verify
|
||||||
);
|
);
|
||||||
|
|
||||||
await instance.initialize(
|
await instance.initialize(args[0], args[1], args[2], '18', args[3], args[4]);
|
||||||
args[0],
|
|
||||||
args[1],
|
|
||||||
args[2],
|
|
||||||
"18",
|
|
||||||
args[3],
|
|
||||||
args[4]
|
|
||||||
);
|
|
||||||
|
|
||||||
return instance;
|
return instance;
|
||||||
}
|
};
|
||||||
|
|
||||||
|
|
||||||
export const deployMockAToken = async (
|
export const deployMockAToken = async (
|
||||||
args: [tEthereumAddress, tEthereumAddress, tEthereumAddress,tEthereumAddress, string, string],
|
args: [tEthereumAddress, tEthereumAddress, tEthereumAddress, tEthereumAddress, string, string],
|
||||||
verify?: boolean
|
verify?: boolean
|
||||||
) => {
|
) => {
|
||||||
const instance = await withSaveAndVerify(
|
const instance = await withSaveAndVerify(
|
||||||
|
@ -567,19 +538,10 @@ args: [tEthereumAddress, tEthereumAddress, tEthereumAddress,tEthereumAddress, st
|
||||||
verify
|
verify
|
||||||
);
|
);
|
||||||
|
|
||||||
await instance.initialize(
|
await instance.initialize(args[0], args[2], args[1], args[3], '18', args[4], args[5]);
|
||||||
args[0],
|
|
||||||
args[2],
|
|
||||||
args[1],
|
|
||||||
args[3],
|
|
||||||
"18",
|
|
||||||
args[4],
|
|
||||||
args[5],
|
|
||||||
);
|
|
||||||
|
|
||||||
return instance;
|
return instance;
|
||||||
}
|
};
|
||||||
|
|
||||||
|
|
||||||
export const deploySelfdestructTransferMock = async (verify?: boolean) =>
|
export const deploySelfdestructTransferMock = async (verify?: boolean) =>
|
||||||
withSaveAndVerify(
|
withSaveAndVerify(
|
||||||
|
|
|
@ -336,7 +336,7 @@ export interface IReserveParams extends IReserveBorrowParams, IReserveCollateral
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface IInterestRateStrategyParams {
|
export interface IInterestRateStrategyParams {
|
||||||
name: string,
|
name: string;
|
||||||
optimalUtilizationRate: string;
|
optimalUtilizationRate: string;
|
||||||
baseVariableBorrowRate: string;
|
baseVariableBorrowRate: string;
|
||||||
variableRateSlope1: string;
|
variableRateSlope1: string;
|
||||||
|
@ -452,6 +452,7 @@ export interface ICommonConfiguration {
|
||||||
ReservesConfig: iMultiPoolsAssets<IReserveParams>;
|
ReservesConfig: iMultiPoolsAssets<IReserveParams>;
|
||||||
ATokenDomainSeparator: iParamsPerNetwork<string>;
|
ATokenDomainSeparator: iParamsPerNetwork<string>;
|
||||||
WETH: iParamsPerNetwork<tEthereumAddress>;
|
WETH: iParamsPerNetwork<tEthereumAddress>;
|
||||||
|
WethGateway: iParamsPerNetwork<tEthereumAddress>;
|
||||||
ReserveFactorTreasuryAddress: iParamsPerNetwork<tEthereumAddress>;
|
ReserveFactorTreasuryAddress: iParamsPerNetwork<tEthereumAddress>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
import BigNumber from 'bignumber.js';
|
|
||||||
import { oneEther, oneRay, RAY, ZERO_ADDRESS } from '../../helpers/constants';
|
import { oneEther, oneRay, RAY, ZERO_ADDRESS } from '../../helpers/constants';
|
||||||
import { ICommonConfiguration, EthereumNetwork, eEthereumNetwork } from '../../helpers/types';
|
import { ICommonConfiguration, EthereumNetwork, eEthereumNetwork } from '../../helpers/types';
|
||||||
|
|
||||||
|
@ -196,6 +195,15 @@ export const CommonsConfig: ICommonConfiguration = {
|
||||||
[eEthereumNetwork.main]: '0xbd4765210d4167CE2A5b87280D9E8Ee316D5EC7C',
|
[eEthereumNetwork.main]: '0xbd4765210d4167CE2A5b87280D9E8Ee316D5EC7C',
|
||||||
[eEthereumNetwork.tenderlyMain]: '0xbd4765210d4167CE2A5b87280D9E8Ee316D5EC7C',
|
[eEthereumNetwork.tenderlyMain]: '0xbd4765210d4167CE2A5b87280D9E8Ee316D5EC7C',
|
||||||
},
|
},
|
||||||
|
WethGateway: {
|
||||||
|
[eEthereumNetwork.coverage]: '',
|
||||||
|
[eEthereumNetwork.hardhat]: '',
|
||||||
|
[eEthereumNetwork.buidlerevm]: '',
|
||||||
|
[eEthereumNetwork.kovan]: '0xf99b8E67a0E044734B01EC4586D1c88C9a869718',
|
||||||
|
[eEthereumNetwork.ropsten]: '',
|
||||||
|
[eEthereumNetwork.main]: '',
|
||||||
|
[eEthereumNetwork.tenderlyMain]: '',
|
||||||
|
},
|
||||||
TokenDistributor: {
|
TokenDistributor: {
|
||||||
[eEthereumNetwork.coverage]: '',
|
[eEthereumNetwork.coverage]: '',
|
||||||
[eEthereumNetwork.buidlerevm]: '',
|
[eEthereumNetwork.buidlerevm]: '',
|
||||||
|
|
|
@ -199,6 +199,15 @@ export const CommonsConfig: ICommonConfiguration = {
|
||||||
[eEthereumNetwork.main]: '0xbd4765210d4167CE2A5b87280D9E8Ee316D5EC7C',
|
[eEthereumNetwork.main]: '0xbd4765210d4167CE2A5b87280D9E8Ee316D5EC7C',
|
||||||
[eEthereumNetwork.tenderlyMain]: '0xbd4765210d4167CE2A5b87280D9E8Ee316D5EC7C',
|
[eEthereumNetwork.tenderlyMain]: '0xbd4765210d4167CE2A5b87280D9E8Ee316D5EC7C',
|
||||||
},
|
},
|
||||||
|
WethGateway: {
|
||||||
|
[eEthereumNetwork.coverage]: '',
|
||||||
|
[eEthereumNetwork.hardhat]: '',
|
||||||
|
[eEthereumNetwork.buidlerevm]: '',
|
||||||
|
[eEthereumNetwork.kovan]: '',
|
||||||
|
[eEthereumNetwork.ropsten]: '',
|
||||||
|
[eEthereumNetwork.main]: '',
|
||||||
|
[eEthereumNetwork.tenderlyMain]: '',
|
||||||
|
},
|
||||||
TokenDistributor: {
|
TokenDistributor: {
|
||||||
[eEthereumNetwork.coverage]: '',
|
[eEthereumNetwork.coverage]: '',
|
||||||
[eEthereumNetwork.buidlerevm]: '',
|
[eEthereumNetwork.buidlerevm]: '',
|
||||||
|
|
25493
package-lock.json
generated
25493
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
|
@ -32,7 +32,8 @@
|
||||||
"test-permit": "hardhat test test-suites/test-aave/__setup.spec.ts test-suites/test-aave/atoken-permit.spec.ts",
|
"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-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-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-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",
|
"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",
|
"dev:coverage": "buidler compile --force && buidler coverage --network coverage",
|
||||||
|
|
|
@ -5,7 +5,10 @@ import {
|
||||||
deployWalletBalancerProvider,
|
deployWalletBalancerProvider,
|
||||||
deployAaveProtocolDataProvider,
|
deployAaveProtocolDataProvider,
|
||||||
deployWETHGateway,
|
deployWETHGateway,
|
||||||
|
authorizeWETHGateway,
|
||||||
} from '../../helpers/contracts-deployments';
|
} from '../../helpers/contracts-deployments';
|
||||||
|
import { getParamPerNetwork } from '../../helpers/contracts-helpers';
|
||||||
|
import { eEthereumNetwork } from '../../helpers/types';
|
||||||
import {
|
import {
|
||||||
ConfigNames,
|
ConfigNames,
|
||||||
getReservesConfigByPool,
|
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)}`)
|
.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');
|
await localBRE.run('set-DRE');
|
||||||
|
const network = <eEthereumNetwork>localBRE.network.name;
|
||||||
const poolConfig = loadPoolConfig(pool);
|
const poolConfig = loadPoolConfig(pool);
|
||||||
const {
|
const {
|
||||||
ATokenNamePrefix,
|
ATokenNamePrefix,
|
||||||
StableDebtTokenNamePrefix,
|
StableDebtTokenNamePrefix,
|
||||||
VariableDebtTokenNamePrefix,
|
VariableDebtTokenNamePrefix,
|
||||||
SymbolPrefix,
|
SymbolPrefix,
|
||||||
|
WethGateway,
|
||||||
} = poolConfig;
|
} = poolConfig;
|
||||||
const mockTokens = await getAllMockedTokens();
|
const mockTokens = await getAllMockedTokens();
|
||||||
const allTokenAddresses = getAllTokenAddresses(mockTokens);
|
const allTokenAddresses = getAllTokenAddresses(mockTokens);
|
||||||
|
@ -87,6 +92,6 @@ task('dev:initialize-lending-pool', 'Initialize lending pool configuration.')
|
||||||
await insertContractAddressInDb(eContractid.AaveProtocolDataProvider, testHelpers.address);
|
await insertContractAddressInDb(eContractid.AaveProtocolDataProvider, testHelpers.address);
|
||||||
|
|
||||||
const lendingPoolAddress = await addressesProvider.getLendingPool();
|
const lendingPoolAddress = await addressesProvider.getLendingPool();
|
||||||
const wethAddress = await getWethAddress(poolConfig);
|
const gateWay = await getParamPerNetwork(WethGateway, network);
|
||||||
await deployWETHGateway([wethAddress, lendingPoolAddress]);
|
await authorizeWETHGateway(gateWay, lendingPoolAddress);
|
||||||
});
|
});
|
||||||
|
|
32
tasks/full/5-deploy-wethGateWay.ts
Normal file
32
tasks/full/5-deploy-wethGateWay.ts
Normal file
|
@ -0,0 +1,32 @@
|
||||||
|
import { task } from 'hardhat/config';
|
||||||
|
import { AaveConfig } from '../../markets/aave/index';
|
||||||
|
import { getParamPerNetwork } from '../../helpers/contracts-helpers';
|
||||||
|
import { loadPoolConfig, ConfigNames, getWethAddress } from '../../helpers/configuration';
|
||||||
|
import { deployWETHGateway } from '../../helpers/contracts-deployments';
|
||||||
|
import { DRE } from '../../helpers/misc-utils';
|
||||||
|
import { eEthereumNetwork } from '../../helpers/types';
|
||||||
|
|
||||||
|
const CONTRACT_NAME = 'WETHGateway';
|
||||||
|
|
||||||
|
task(`full-deploy-weth-gateway`, `Deploys the ${CONTRACT_NAME} contract`)
|
||||||
|
.addParam('pool', `Pool name to retrieve configuration, supported: ${Object.values(ConfigNames)}`)
|
||||||
|
.addFlag('verify', `Verify ${CONTRACT_NAME} contract via Etherscan API.`)
|
||||||
|
.setAction(async ({ verify, pool }, localBRE) => {
|
||||||
|
await localBRE.run('set-DRE');
|
||||||
|
const network = <eEthereumNetwork>localBRE.network.name;
|
||||||
|
const poolConfig = loadPoolConfig(pool);
|
||||||
|
const Weth = await getWethAddress(poolConfig);
|
||||||
|
const { WethGateway } = poolConfig;
|
||||||
|
|
||||||
|
if (!localBRE.network.config.chainId) {
|
||||||
|
throw new Error('INVALID_CHAIN_ID');
|
||||||
|
}
|
||||||
|
let gateWay = getParamPerNetwork(WethGateway, network);
|
||||||
|
if (gateWay === '') {
|
||||||
|
const wethGateWay = await deployWETHGateway([Weth], verify);
|
||||||
|
console.log(`${CONTRACT_NAME}.address`, wethGateWay.address);
|
||||||
|
console.log(`\tFinished ${CONTRACT_NAME} deployment`);
|
||||||
|
} else {
|
||||||
|
console.log(`Weth gateway already deployed. Address: ${gateWay}`);
|
||||||
|
}
|
||||||
|
});
|
|
@ -4,6 +4,7 @@ import {
|
||||||
deployLendingPoolCollateralManager,
|
deployLendingPoolCollateralManager,
|
||||||
deployWalletBalancerProvider,
|
deployWalletBalancerProvider,
|
||||||
deployWETHGateway,
|
deployWETHGateway,
|
||||||
|
authorizeWETHGateway,
|
||||||
} from '../../helpers/contracts-deployments';
|
} from '../../helpers/contracts-deployments';
|
||||||
import {
|
import {
|
||||||
loadPoolConfig,
|
loadPoolConfig,
|
||||||
|
@ -11,6 +12,7 @@ import {
|
||||||
getWethAddress,
|
getWethAddress,
|
||||||
getTreasuryAddress,
|
getTreasuryAddress,
|
||||||
} from '../../helpers/configuration';
|
} from '../../helpers/configuration';
|
||||||
|
import { getWETHGateway } from '../../helpers/contracts-getters';
|
||||||
import { eEthereumNetwork, ICommonConfiguration } from '../../helpers/types';
|
import { eEthereumNetwork, ICommonConfiguration } from '../../helpers/types';
|
||||||
import { waitForTx } from '../../helpers/misc-utils';
|
import { waitForTx } from '../../helpers/misc-utils';
|
||||||
import { initReservesByHelper, configureReservesByHelper } from '../../helpers/init-helpers';
|
import { initReservesByHelper, configureReservesByHelper } from '../../helpers/init-helpers';
|
||||||
|
@ -36,7 +38,8 @@ task('full:initialize-lending-pool', 'Initialize lending pool configuration.')
|
||||||
SymbolPrefix,
|
SymbolPrefix,
|
||||||
ReserveAssets,
|
ReserveAssets,
|
||||||
ReservesConfig,
|
ReservesConfig,
|
||||||
LendingPoolCollateralManager
|
LendingPoolCollateralManager,
|
||||||
|
WethGateway,
|
||||||
} = poolConfig as ICommonConfiguration;
|
} = poolConfig as ICommonConfiguration;
|
||||||
|
|
||||||
const reserveAssets = await getParamPerNetwork(ReserveAssets, network);
|
const reserveAssets = await getParamPerNetwork(ReserveAssets, network);
|
||||||
|
@ -66,9 +69,10 @@ task('full:initialize-lending-pool', 'Initialize lending pool configuration.')
|
||||||
);
|
);
|
||||||
await configureReservesByHelper(ReservesConfig, reserveAssets, testHelpers, admin);
|
await configureReservesByHelper(ReservesConfig, reserveAssets, testHelpers, admin);
|
||||||
|
|
||||||
|
let collateralManagerAddress = await getParamPerNetwork(
|
||||||
|
LendingPoolCollateralManager,
|
||||||
let collateralManagerAddress = await getParamPerNetwork(LendingPoolCollateralManager, network);
|
network
|
||||||
|
);
|
||||||
if (!collateralManagerAddress) {
|
if (!collateralManagerAddress) {
|
||||||
const collateralManager = await deployLendingPoolCollateralManager(verify);
|
const collateralManager = await deployLendingPoolCollateralManager(verify);
|
||||||
collateralManagerAddress = collateralManager.address;
|
collateralManagerAddress = collateralManager.address;
|
||||||
|
@ -81,10 +85,13 @@ task('full:initialize-lending-pool', 'Initialize lending pool configuration.')
|
||||||
|
|
||||||
await deployWalletBalancerProvider(verify);
|
await deployWalletBalancerProvider(verify);
|
||||||
|
|
||||||
const wethAddress = await getWethAddress(poolConfig);
|
|
||||||
const lendingPoolAddress = await addressesProvider.getLendingPool();
|
const lendingPoolAddress = await addressesProvider.getLendingPool();
|
||||||
|
|
||||||
await deployWETHGateway([wethAddress, lendingPoolAddress]);
|
let gateWay = getParamPerNetwork(WethGateway, network);
|
||||||
|
if (gateWay == '') {
|
||||||
|
gateWay = (await getWETHGateway()).address;
|
||||||
|
}
|
||||||
|
await authorizeWETHGateway(gateWay, lendingPoolAddress);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error(err);
|
console.error(err);
|
||||||
exit(1);
|
exit(1);
|
|
@ -29,15 +29,18 @@ task('aave:mainnet', 'Deploy development enviroment')
|
||||||
console.log('4. Deploy Data Provider');
|
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');
|
console.log('5. Deploy WETH Gateway');
|
||||||
|
await DRE.run('full-deploy-weth-gateway', { pool: POOL_NAME });
|
||||||
|
|
||||||
|
console.log('6. 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) {
|
if (verify) {
|
||||||
printContracts();
|
printContracts();
|
||||||
console.log('4. Veryfing contracts');
|
console.log('7. 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');
|
console.log('8. Veryfing aTokens and debtTokens');
|
||||||
await DRE.run('verify:tokens', { pool: POOL_NAME });
|
await DRE.run('verify:tokens', { pool: POOL_NAME });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -29,15 +29,18 @@ task('lp:mainnet', 'Deploy development enviroment')
|
||||||
console.log('4. Deploy Data Provider');
|
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');
|
console.log('5. Deploy WETH Gateway');
|
||||||
|
await DRE.run('full-deploy-weth-gateway', { pool: POOL_NAME });
|
||||||
|
|
||||||
|
console.log('6. 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) {
|
if (verify) {
|
||||||
printContracts();
|
printContracts();
|
||||||
console.log('4. Veryfing contracts');
|
console.log('7. 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');
|
console.log('8. Veryfing aTokens and debtTokens');
|
||||||
await DRE.run('verify:tokens', { pool: POOL_NAME });
|
await DRE.run('verify:tokens', { pool: POOL_NAME });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -89,10 +89,7 @@ task('verify:general', 'Deploy oracles for dev enviroment')
|
||||||
|
|
||||||
// WETHGateway
|
// WETHGateway
|
||||||
console.log('\n- Verifying WETHGateway...\n');
|
console.log('\n- Verifying WETHGateway...\n');
|
||||||
await verifyContract(wethGateway.address, [
|
await verifyContract(wethGateway.address, [await getWethAddress(poolConfig)]);
|
||||||
await getWethAddress(poolConfig),
|
|
||||||
lendingPoolProxy.address,
|
|
||||||
]);
|
|
||||||
}
|
}
|
||||||
// Lending Pool proxy
|
// Lending Pool proxy
|
||||||
console.log('\n- Verifying Lending Pool Proxy...\n');
|
console.log('\n- Verifying Lending Pool Proxy...\n');
|
||||||
|
|
|
@ -26,7 +26,9 @@ import {
|
||||||
deployUniswapLiquiditySwapAdapter,
|
deployUniswapLiquiditySwapAdapter,
|
||||||
deployUniswapRepayAdapter,
|
deployUniswapRepayAdapter,
|
||||||
deployFlashLiquidationAdapter,
|
deployFlashLiquidationAdapter,
|
||||||
|
authorizeWETHGateway,
|
||||||
} from '../../helpers/contracts-deployments';
|
} from '../../helpers/contracts-deployments';
|
||||||
|
import { eEthereumNetwork } from '../../helpers/types';
|
||||||
import { Signer } from 'ethers';
|
import { Signer } from 'ethers';
|
||||||
import { TokenContractId, eContractid, tEthereumAddress, AavePools } from '../../helpers/types';
|
import { TokenContractId, eContractid, tEthereumAddress, AavePools } from '../../helpers/types';
|
||||||
import { MintableERC20 } from '../../types/MintableERC20';
|
import { MintableERC20 } from '../../types/MintableERC20';
|
||||||
|
@ -95,7 +97,7 @@ const buildTestEnv = async (deployer: Signer, secondaryWallet: Signer) => {
|
||||||
const aaveAdmin = await deployer.getAddress();
|
const aaveAdmin = await deployer.getAddress();
|
||||||
|
|
||||||
const mockTokens = await deployAllMockTokens(deployer);
|
const mockTokens = await deployAllMockTokens(deployer);
|
||||||
console.log("Deployed mocks");
|
console.log('Deployed mocks');
|
||||||
const addressesProvider = await deployLendingPoolAddressesProvider(AaveConfig.MarketId);
|
const addressesProvider = await deployLendingPoolAddressesProvider(AaveConfig.MarketId);
|
||||||
await waitForTx(await addressesProvider.setPoolAdmin(aaveAdmin));
|
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);
|
const mockAggregators = await deployAllMockAggregators(MOCK_CHAINLINK_AGGREGATORS_PRICES);
|
||||||
console.log("Mock aggs deployed");
|
console.log('Mock aggs deployed');
|
||||||
const allTokenAddresses = Object.entries(mockTokens).reduce(
|
const allTokenAddresses = Object.entries(mockTokens).reduce(
|
||||||
(accum: { [tokenSymbol: string]: tEthereumAddress }, [tokenSymbol, tokenContract]) => ({
|
(accum: { [tokenSymbol: string]: tEthereumAddress }, [tokenSymbol, tokenContract]) => ({
|
||||||
...accum,
|
...accum,
|
||||||
|
@ -280,7 +282,8 @@ const buildTestEnv = async (deployer: Signer, secondaryWallet: Signer) => {
|
||||||
|
|
||||||
await deployWalletBalancerProvider();
|
await deployWalletBalancerProvider();
|
||||||
|
|
||||||
await deployWETHGateway([mockTokens.WETH.address, lendingPoolAddress]);
|
const gateWay = await deployWETHGateway([mockTokens.WETH.address]);
|
||||||
|
await authorizeWETHGateway(gateWay.address, lendingPoolAddress);
|
||||||
|
|
||||||
console.timeEnd('setup');
|
console.timeEnd('setup');
|
||||||
};
|
};
|
||||||
|
|
|
@ -14,7 +14,7 @@ makeSuite('Use native ETH at LendingPool via WETHGateway', (testEnv: TestEnv) =>
|
||||||
const depositSize = parseEther('5');
|
const depositSize = parseEther('5');
|
||||||
const daiSize = parseEther('10000');
|
const daiSize = parseEther('10000');
|
||||||
it('Deposit WETH via WethGateway and DAI', async () => {
|
it('Deposit WETH via WethGateway and DAI', async () => {
|
||||||
const { users, wethGateway, aWETH } = testEnv;
|
const { users, wethGateway, aWETH, pool } = testEnv;
|
||||||
|
|
||||||
const user = users[1];
|
const user = users[1];
|
||||||
const depositor = users[0];
|
const depositor = users[0];
|
||||||
|
@ -22,10 +22,12 @@ makeSuite('Use native ETH at LendingPool via WETHGateway', (testEnv: TestEnv) =>
|
||||||
// Deposit liquidity with native ETH
|
// Deposit liquidity with native ETH
|
||||||
await wethGateway
|
await wethGateway
|
||||||
.connect(depositor.signer)
|
.connect(depositor.signer)
|
||||||
.depositETH(depositor.address, '0', { value: depositSize });
|
.depositETH(pool.address, depositor.address, '0', { value: depositSize });
|
||||||
|
|
||||||
// Deposit with native ETH
|
// 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);
|
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
|
// 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)
|
await wethGateway
|
||||||
|
.connect(user.signer)
|
||||||
|
.withdrawETH(pool.address, partialWithdraw, user.address)
|
||||||
);
|
);
|
||||||
|
|
||||||
const afterPartialEtherBalance = await user.signer.getBalance();
|
const afterPartialEtherBalance = await user.signer.getBalance();
|
||||||
|
@ -87,7 +91,9 @@ makeSuite('Use native ETH at LendingPool via WETHGateway', (testEnv: TestEnv) =>
|
||||||
|
|
||||||
// Full withdraw
|
// Full withdraw
|
||||||
const { gasUsed: withdrawGas } = await waitForTx(
|
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();
|
const afterFullEtherBalance = await user.signer.getBalance();
|
||||||
|
@ -111,7 +117,7 @@ makeSuite('Use native ETH at LendingPool via WETHGateway', (testEnv: TestEnv) =>
|
||||||
// Deposit with native ETH
|
// Deposit with native ETH
|
||||||
await wethGateway
|
await wethGateway
|
||||||
.connect(depositor.signer)
|
.connect(depositor.signer)
|
||||||
.depositETH(depositor.address, '0', { value: depositSize });
|
.depositETH(pool.address, depositor.address, '0', { value: depositSize });
|
||||||
|
|
||||||
const { stableDebtTokenAddress } = await helpersContract.getReserveTokensAddresses(
|
const { stableDebtTokenAddress } = await helpersContract.getReserveTokensAddresses(
|
||||||
weth.address
|
weth.address
|
||||||
|
@ -142,7 +148,7 @@ makeSuite('Use native ETH at LendingPool via WETHGateway', (testEnv: TestEnv) =>
|
||||||
await waitForTx(
|
await waitForTx(
|
||||||
await wethGateway
|
await wethGateway
|
||||||
.connect(user.signer)
|
.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);
|
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);
|
const varDebtToken = await getVariableDebtToken(variableDebtTokenAddress);
|
||||||
|
|
||||||
// Deposit with native ETH
|
// 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);
|
const aTokensBalance = await aWETH.balanceOf(user.address);
|
||||||
|
|
||||||
|
@ -187,7 +195,7 @@ makeSuite('Use native ETH at LendingPool via WETHGateway', (testEnv: TestEnv) =>
|
||||||
await waitForTx(
|
await waitForTx(
|
||||||
await wethGateway
|
await wethGateway
|
||||||
.connect(user.signer)
|
.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);
|
const debtBalanceAfterPartialRepay = await varDebtToken.balanceOf(user.address);
|
||||||
|
@ -197,14 +205,14 @@ makeSuite('Use native ETH at LendingPool via WETHGateway', (testEnv: TestEnv) =>
|
||||||
await waitForTx(
|
await waitForTx(
|
||||||
await wethGateway
|
await wethGateway
|
||||||
.connect(user.signer)
|
.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);
|
const debtBalanceAfterFullRepay = await varDebtToken.balanceOf(user.address);
|
||||||
expect(debtBalanceAfterFullRepay).to.be.eq(zero);
|
expect(debtBalanceAfterFullRepay).to.be.eq(zero);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Borrow ETH via delegateApprove ETH and repays back', async () => {
|
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 borrowSize = parseEther('1');
|
||||||
const user = users[2];
|
const user = users[2];
|
||||||
const { variableDebtTokenAddress } = await helpersContract.getReserveTokensAddresses(
|
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);
|
expect(priorDebtBalance).to.be.eq(zero);
|
||||||
|
|
||||||
// Deposit WETH with native ETH
|
// 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);
|
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
|
// 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);
|
const debtBalance = await varDebtToken.balanceOf(user.address);
|
||||||
|
|
||||||
|
@ -239,7 +251,7 @@ makeSuite('Use native ETH at LendingPool via WETHGateway', (testEnv: TestEnv) =>
|
||||||
await waitForTx(
|
await waitForTx(
|
||||||
await wethGateway
|
await wethGateway
|
||||||
.connect(user.signer)
|
.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);
|
const debtBalanceAfterFullRepay = await varDebtToken.balanceOf(user.address);
|
||||||
expect(debtBalanceAfterFullRepay).to.be.eq(zero);
|
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');
|
).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 () => {
|
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 user = users[0];
|
||||||
|
|
|
@ -26,6 +26,7 @@ import {
|
||||||
deployUniswapLiquiditySwapAdapter,
|
deployUniswapLiquiditySwapAdapter,
|
||||||
deployUniswapRepayAdapter,
|
deployUniswapRepayAdapter,
|
||||||
deployFlashLiquidationAdapter,
|
deployFlashLiquidationAdapter,
|
||||||
|
authorizeWETHGateway
|
||||||
} from '../../helpers/contracts-deployments';
|
} from '../../helpers/contracts-deployments';
|
||||||
import { Signer } from 'ethers';
|
import { Signer } from 'ethers';
|
||||||
import { TokenContractId, eContractid, tEthereumAddress, AavePools } from '../../helpers/types';
|
import { TokenContractId, eContractid, tEthereumAddress, AavePools } from '../../helpers/types';
|
||||||
|
@ -279,7 +280,8 @@ const buildTestEnv = async (deployer: Signer, secondaryWallet: Signer) => {
|
||||||
|
|
||||||
await deployWalletBalancerProvider();
|
await deployWalletBalancerProvider();
|
||||||
|
|
||||||
await deployWETHGateway([mockTokens.WETH.address, lendingPoolAddress]);
|
const gateWay = await deployWETHGateway([mockTokens.WETH.address]);
|
||||||
|
await authorizeWETHGateway(gateWay.address, lendingPoolAddress);
|
||||||
|
|
||||||
console.timeEnd('setup');
|
console.timeEnd('setup');
|
||||||
};
|
};
|
||||||
|
|
|
@ -15,7 +15,7 @@ makeSuite('Use native ETH at LendingPool via WETHGateway', (testEnv: TestEnv) =>
|
||||||
const depositSize = parseEther('5');
|
const depositSize = parseEther('5');
|
||||||
const daiSize = parseEther('10000');
|
const daiSize = parseEther('10000');
|
||||||
it('Deposit WETH via WethGateway and DAI', async () => {
|
it('Deposit WETH via WethGateway and DAI', async () => {
|
||||||
const { users, wethGateway, aWETH } = testEnv;
|
const { users, wethGateway, aWETH, pool } = testEnv;
|
||||||
|
|
||||||
const user = users[1];
|
const user = users[1];
|
||||||
const depositor = users[0];
|
const depositor = users[0];
|
||||||
|
@ -23,10 +23,10 @@ makeSuite('Use native ETH at LendingPool via WETHGateway', (testEnv: TestEnv) =>
|
||||||
// Deposit liquidity with native ETH
|
// Deposit liquidity with native ETH
|
||||||
await wethGateway
|
await wethGateway
|
||||||
.connect(depositor.signer)
|
.connect(depositor.signer)
|
||||||
.depositETH(depositor.address, '0', { value: depositSize });
|
.depositETH(pool.address, depositor.address, '0', { value: depositSize });
|
||||||
|
|
||||||
// Deposit with native ETH
|
// 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);
|
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
|
// 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)
|
await wethGateway.connect(user.signer).withdrawETH(pool.address, partialWithdraw, user.address)
|
||||||
);
|
);
|
||||||
|
|
||||||
const afterPartialEtherBalance = await user.signer.getBalance();
|
const afterPartialEtherBalance = await user.signer.getBalance();
|
||||||
|
@ -88,7 +88,7 @@ makeSuite('Use native ETH at LendingPool via WETHGateway', (testEnv: TestEnv) =>
|
||||||
|
|
||||||
// Full withdraw
|
// Full withdraw
|
||||||
const { gasUsed: withdrawGas } = await waitForTx(
|
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();
|
const afterFullEtherBalance = await user.signer.getBalance();
|
||||||
|
@ -112,7 +112,7 @@ makeSuite('Use native ETH at LendingPool via WETHGateway', (testEnv: TestEnv) =>
|
||||||
// Deposit with native ETH
|
// Deposit with native ETH
|
||||||
await wethGateway
|
await wethGateway
|
||||||
.connect(depositor.signer)
|
.connect(depositor.signer)
|
||||||
.depositETH(depositor.address, '0', { value: depositSize });
|
.depositETH(pool.address, depositor.address, '0', { value: depositSize });
|
||||||
|
|
||||||
const { stableDebtTokenAddress } = await helpersContract.getReserveTokensAddresses(
|
const { stableDebtTokenAddress } = await helpersContract.getReserveTokensAddresses(
|
||||||
weth.address
|
weth.address
|
||||||
|
@ -168,7 +168,7 @@ makeSuite('Use native ETH at LendingPool via WETHGateway', (testEnv: TestEnv) =>
|
||||||
const varDebtToken = await getVariableDebtToken(variableDebtTokenAddress);
|
const varDebtToken = await getVariableDebtToken(variableDebtTokenAddress);
|
||||||
|
|
||||||
// Deposit with native ETH
|
// 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);
|
const aTokensBalance = await aWETH.balanceOf(user.address);
|
||||||
|
|
||||||
|
@ -189,7 +189,7 @@ makeSuite('Use native ETH at LendingPool via WETHGateway', (testEnv: TestEnv) =>
|
||||||
await waitForTx(
|
await waitForTx(
|
||||||
await wethGateway
|
await wethGateway
|
||||||
.connect(user.signer)
|
.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);
|
const debtBalanceAfterPartialRepay = await varDebtToken.balanceOf(user.address);
|
||||||
|
@ -199,14 +199,14 @@ makeSuite('Use native ETH at LendingPool via WETHGateway', (testEnv: TestEnv) =>
|
||||||
await waitForTx(
|
await waitForTx(
|
||||||
await wethGateway
|
await wethGateway
|
||||||
.connect(user.signer)
|
.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);
|
const debtBalanceAfterFullRepay = await varDebtToken.balanceOf(user.address);
|
||||||
expect(debtBalanceAfterFullRepay).to.be.eq(zero);
|
expect(debtBalanceAfterFullRepay).to.be.eq(zero);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Borrow ETH via delegateApprove ETH and repays back', async () => {
|
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 borrowSize = parseEther('1');
|
||||||
const user = users[2];
|
const user = users[2];
|
||||||
const { variableDebtTokenAddress } = await helpersContract.getReserveTokensAddresses(
|
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);
|
expect(priorDebtBalance).to.be.eq(zero);
|
||||||
|
|
||||||
// Deposit WETH with native ETH
|
// 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);
|
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
|
// 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);
|
const debtBalance = await varDebtToken.balanceOf(user.address);
|
||||||
|
|
||||||
|
@ -241,7 +241,7 @@ makeSuite('Use native ETH at LendingPool via WETHGateway', (testEnv: TestEnv) =>
|
||||||
await waitForTx(
|
await waitForTx(
|
||||||
await wethGateway
|
await wethGateway
|
||||||
.connect(user.signer)
|
.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);
|
const debtBalanceAfterFullRepay = await varDebtToken.balanceOf(user.address);
|
||||||
expect(debtBalanceAfterFullRepay).to.be.eq(zero);
|
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');
|
).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 () => {
|
it('Owner can do emergency token recovery', async () => {
|
||||||
const { users, dai, wethGateway, deployer } = testEnv;
|
const { users, dai, wethGateway, deployer } = testEnv;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user