mirror of
https://github.com/Instadapp/aave-protocol-v2.git
synced 2024-07-29 21:47:30 +00:00
Updated WETHGateway for withdrawETHWithPermit
This commit is contained in:
parent
3a6948ce2c
commit
1316cf48e4
|
@ -131,6 +131,37 @@ contract WETHGateway is IWETHGateway, Ownable {
|
||||||
_safeTransferETH(msg.sender, amount);
|
_safeTransferETH(msg.sender, amount);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @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
|
||||||
|
*/
|
||||||
|
function withdrawETHWithPermit(
|
||||||
|
address lendingPool,
|
||||||
|
uint256 amount,
|
||||||
|
address to,
|
||||||
|
uint256 deadline,
|
||||||
|
uint8 permitV,
|
||||||
|
bytes32 permitR,
|
||||||
|
bytes32 permitS
|
||||||
|
) external override {
|
||||||
|
IAToken aWETH = IAToken(ILendingPool(lendingPool).getReserveData(address(WETH)).aTokenAddress);
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
// chosing to permit `amount`and not `amountToWithdraw`, easier for frontends, intregrators.
|
||||||
|
aWETH.permit(msg.sender, address(this), amount, deadline, permitV, permitR, permitS);
|
||||||
|
aWETH.transferFrom(msg.sender, address(this), amountToWithdraw);
|
||||||
|
ILendingPool(lendingPool).withdraw(address(WETH), amountToWithdraw, address(this));
|
||||||
|
WETH.withdraw(amountToWithdraw);
|
||||||
|
_safeTransferETH(to, amountToWithdraw);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dev transfer ETH to an address, revert if it fails.
|
* @dev transfer ETH to an address, revert if it fails.
|
||||||
* @param to recipient of the transfer
|
* @param to recipient of the transfer
|
||||||
|
|
Loading…
Reference in New Issue
Block a user