Skip to Content
docs

Aave V3 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

The first address argument of each method is unused and kept for backward compatibility; the pool is fixed at deployment.

depositETH

Solidity
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.

Pass the gas token amount to supply in msg.value.

Input Parameters:

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

withdrawETH

Solidity
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 type(uint256).max, the entire balance is withdrawn.

First approve the WrappedTokenGateway to spend the user’s aWETH, for example IERC20(aWETHAddress).approve(wrappedTokenGatewayAddress, amount).

Input Parameters:

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

repayETH

Solidity
function repayETH(
    address,
    uint256 amount,
    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 type(uint256).max is passed).

Pass the gas token amount to repay in msg.value.

Input Parameters:

NameTypeDescription
amountuint256The amount to repay, or type(uint256).max if the user wants to repay everything
onBehalfOfaddressThe address for which msg.sender is repaying

borrowETH

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

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

First grant the WrappedTokenGateway credit delegation on WETH (or the network’s wrapped gas token), for example IVariableDebtToken(variableDebtWETHAddress).approveDelegation(wrappedTokenGatewayAddress, amount).

Input Parameters:

NameTypeDescription
amountuint256The amount of ETH to borrow
referralCodeuint16Inactive, can pass 0 as placeholder

withdrawETHWithPermit

Solidity
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 type(uint256).max, 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 EIP-712 permit signature
permitRbytes32R parameter of EIP-712 permit signature
permitSbytes32S parameter of EIP-712 permit signature

View Methods

getWETHAddress

Solidity
function getWETHAddress() external view returns (address)

Get WETH address used by WrappedTokenGatewayV3.

Return Values:

TypeDescription
addressThe WETH address used by WrappedTokenGatewayV3