# Aave V3 Wrapped Token Gateway

The Aave Protocol operates exclusively with ERC-20 [reserve](../concepts/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](https://github.com/aave-dao/aave-v3-origin/blob/main/src/contracts/helpers/WrappedTokenGatewayV3.sol).

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

> [!NOTE]
> Pass the gas token amount to supply in `msg.value`.

**Input Parameters:**

| Name         | Type      | Description                                                                           |
| :----------- | :-------- | :------------------------------------------------------------------------------------ |
| **onBehalfOf** | `address` | The address of the user who will receive the aTokens representing the supplied tokens |
| **referralCode** | `uint16`  | Inactive, 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.

> [!NOTE]
> First approve the WrappedTokenGateway to spend the user’s aWETH, for example
> `IERC20(aWETHAddress).approve(wrappedTokenGatewayAddress, amount)`.

**Input Parameters:**

| Name   | Type      | Description                                            |
| :----- | :-------- | :----------------------------------------------------- |
| **amount** | `uint256` | The amount of aWETH to withdraw and receive native ETH |
| **to** | `address` | The 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).

> [!NOTE]
> Pass the gas token amount to repay in `msg.value`.

**Input Parameters:**

| Name       | Type      | Description                                                                 |
| :--------- | :-------- | :-------------------------------------------------------------------------- |
| **amount** | `uint256` | The amount to repay, or `type(uint256).max` if the user wants to repay everything |
| **onBehalfOf** | `address` | The 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`.

> [!NOTE]
> First grant the WrappedTokenGateway [credit
> delegation](/aave-v3/guides/credit-delegation) on WETH (or the network’s
> wrapped gas token), for example
> `IVariableDebtToken(variableDebtWETHAddress).approveDelegation(wrappedTokenGatewayAddress,
> amount)`.

**Input Parameters:**

| Name             | Type      | Description                                                                  |
| :--------------- | :-------- | :--------------------------------------------------------------------------- |
| **amount**       | `uint256` | The amount of ETH to borrow                                                  |
| **referralCode** | `uint16`  | Inactive, 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:**

| Name     | Type      | Description                                            |
| :------- | :-------- | :----------------------------------------------------- |
| **amount** | `uint256` | The amount of aWETH to withdraw and receive native ETH |
| **to**   | `address` | The address of the user who will receive native ETH    |
| **deadline** | `uint256` | Timestamp of signature expiration                      |
| **permitV** | `uint8`   | V parameter of EIP-712 permit signature                |
| **permitR** | `bytes32` | R parameter of EIP-712 permit signature                |
| **permitS** | `bytes32` | S parameter of EIP-712 permit signature                |

## View Methods

### getWETHAddress

```solidity
function getWETHAddress() external view returns (address)
```

Get WETH address used by WrappedTokenGatewayV3.

**Return Values:**

| Type      | Description                                    |
| :-------- | :--------------------------------------------- |
| `address` | The WETH address used by WrappedTokenGatewayV3 |
