Cached the aWETH address

This commit is contained in:
The3D 2020-11-03 13:45:54 +01:00
parent f70754263d
commit e8028416d6
2 changed files with 13 additions and 15 deletions

View File

@ -17,6 +17,7 @@ contract WETHGateway is IWETHGateway {
IWETH public immutable WETH;
ILendingPool public immutable POOL;
IAToken public immutable aWETH;
/**
* @dev Sets the WETH address and the LendingPoolAddressesProvider address. Infinite approves lending pool.
@ -24,8 +25,10 @@ contract WETHGateway is IWETHGateway {
* @param pool Address of the LendingPool contract
**/
constructor(address weth, address pool) public {
ILendingPool poolInstance = ILendingPool(pool);
WETH = IWETH(weth);
POOL = ILendingPool(pool);
POOL = poolInstance;
aWETH = IAToken(poolInstance.getReserveData(weth).aTokenAddress);
IWETH(weth).approve(pool, uint256(-1));
}
@ -46,20 +49,14 @@ contract WETHGateway is IWETHGateway {
* @param to address of the user who will receive native ETH
*/
function withdrawETH(uint256 amount, address to) external override {
uint256 userBalance = IAToken(POOL.getReserveData(address(WETH)).aTokenAddress).balanceOf(
msg.sender
);
uint256 userBalance = aWETH.balanceOf(msg.sender);
uint256 amountToWithdraw = amount;
// if amount is equal to uint(-1), the user wants to redeem everything
if (amount == type(uint256).max) {
amountToWithdraw = userBalance;
}
IAToken(POOL.getReserveData(address(WETH)).aTokenAddress).transferFrom(
msg.sender,
address(this),
amountToWithdraw
);
aWETH.transferFrom(msg.sender, address(this), amountToWithdraw);
POOL.withdraw(address(WETH), amountToWithdraw, address(this));
WETH.withdraw(amountToWithdraw);
safeTransferETH(to, amountToWithdraw);

View File

@ -171,7 +171,7 @@
},
"ReserveLogic": {
"buidlerevm": {
"address": "0xFAe0fd738dAbc8a0426F47437322b6d026A9FD95",
"address": "0x920d847fE49E54C19047ba8bc236C45A8068Bca7",
"deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6"
},
"kovan": {
@ -181,19 +181,20 @@
},
"GenericLogic": {
"buidlerevm": {
"address": "0x6082731fdAba4761277Fb31299ebC782AD3bCf24",
"address": "0xA4765Ff72A9F3CfE73089bb2c3a41B838DF71574",
"deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6"
}
},
"ValidationLogic": {
"buidlerevm": {
"address": "0x8456161947DFc1fC159A0B26c025cD2b4bba0c3e",
"address": "0x35c1419Da7cf0Ff885B8Ef8EA9242FEF6800c99b",
"deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6"
}
},
"LendingPool": {
"buidlerevm": {
"address": "0xD9273d497eDBC967F39d419461CfcF382a0A822e"
"address": "0xe2607EabC87fd0A4856840bF23da8458cDF0434F",
"deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6"
}
},
"LendingPoolConfigurator": {
@ -209,7 +210,7 @@
},
"ATokensAndRatesHelper": {
"buidlerevm": {
"address": "0x06bA8d8af0dF898D0712DffFb0f862cC51AF45c2",
"address": "0xA4765Ff72A9F3CfE73089bb2c3a41B838DF71574",
"deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6"
}
},
@ -301,4 +302,4 @@
"deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6"
}
}
}
}