Wrapped Token Gateway

The Aave Protocol operates exclusively with ERC-20 reserve tokens. To accommodate network gas tokens, the WrappedTokenGateway (previously called WETHGateway) is a helper contract that enables gas tokens (ETH, POL, etc.) to be wrapped or unwrapped to perform Aave Pool methods:

  • Supply

  • Borrow

  • Repay

  • Withdraw

The smart contract source code is available on GitHub.

Write Methods

depositETH

function depositETH(    address,    address onBehalfOf,    uint16 referralCode) external payable override

Wraps and supplies gas tokens to the Aave Protocol. A corresponding amount of the wrapped aTokens are minted to the onBehalfOf address.

The amount of network gas tokens to be supplied is specified in the msg.value field of the transaction.

Input Parameters:

NameTypeDescription
onBehalfOfaddressThe address of the user who will receive the aTokens representing the supplied tokens
referralCodeuint16Inactive, can pass 0 as placeholder

withdrawETH

function withdrawETH(    address,    uint256 amount,    address to) external override

Withdraws amount of the supplied wrapped gas token, unwraps it and transfers to the to address. If the amount is uint(-1), the entire balance is withdrawn.

The WrappedTokenGateway contract must have an approved token allowance to spend aWETH on behalf of the user, example: IERC20(aWETHAddress).approve(wrappedTokenGatewayAddress, amount)

Input Parameters:

NameTypeDescription
amountuint256amount of aWETH to withdraw and receive native ETH
toaddressThe address of the user who will receive native ETH

repayETH

function repayETH(    address,    uint256 amount,    uint256 rateMode,    address onBehalfOf) external payable override

Repays a borrow position of onBehalfOf's address for the specified amount (or for the whole amount, if amount of uint256(-1) is passed).

The amount of network gas token to be repaid must also be specified in the msg.value field of the transaction.

Input Parameters:

NameTypeDescription
amountuint256The amount to repay, or uint256(-1) if the user wants to repay everything
rateModeuint256Should always be passed a value of 2 (variable rate mode)
onBehalfOfaddressThe address for which msg.sender is repaying

borrowETH

function borrowETH(    address,    uint256 amount,    uint256 interestRateMode,    uint16 referralCode) external override

Borrows amount of unwrapped network gas tokens to msg.sender.

The WrappedTokenGateway contract must have an approved credit delegation to borrow WETH (or corresponding wrapped gas token of the network) on behalf of the the caller, example: IVariableDebtToken(wethAddress).approveDelegation(wrappedTokenGatewayAddress, amount)

Input Parameters:

NameTypeDescription
amountuint256The amount of ETH to borrow
interestRateModeuint256Should always be passed a value of 2 (variable rate mode)
referralCodeuint16Integrators are assigned a referral code and can potentially receive rewards

withdrawETHWithPermit

function withdrawETHWithPermit(    address,    uint256 amount,    address to,    uint256 deadline,    uint8 permitV,    bytes32 permitR,    bytes32 permitS) external override

Withdraws amount of the supplied wrapped gas token, unwraps it and transfers to the to address. If the amount is uint(-1), the entire balance is withdrawn.

Input Parameters:

NameTypeDescription
amountuint256The amount of aWETH to withdraw and receive native ETH
toaddressThe address of the user who will receive native ETH
deadlineuint256Timestamp of signature expiration
permitVuint8V parameter of ERC712 permit sig
permitRbytes32R parameter of ERC712 permit sig
permitSbytes32S parameter of ERC712 permit sig

View Methods

getWETHAddress

function getWETHAddress() external view returns (address)

Get WETH address used by WrappedTokenGatewayV3.

Return Values:

TypeDescription
addressThe WETH address used by WrappedTokenGatewayV3

Aave.com provides information and resources about the fundamentals of the decentralised non-custodial liquidity protocol called the Aave Protocol, comprised of open-source self-executing smart contracts that are deployed on various permissionless public blockchains, such as Ethereum (the "Aave Protocol" or the "Protocol"). Aave Labs does not control or operate any version of the Aave Protocol on any blockchain network.