# Wrapped Token Gateway

Tydro operates exclusively with ERC-20 [reserve](https://docs.tydro.com/primitives/reserve) tokens. To support native gas tokens such as ETH or POL, Tydro provides the WrappedTokenGateway (previously called WETHGateway).

This helper contract allows users to wrap or unwrap gas tokens so they can interact with Pool methods. Through WrappedTokenGateway, users can:

* Supply gas tokens
* Borrow gas tokens
* Repay positions using gas tokens
* Withdraw supplied gas tokens

The smart contract source code is available on Aave's [<mark style="color:blue;">GitHub</mark>](https://github.com/aave-dao/aave-v3-origin/blob/main/src/contracts/helpers/WrappedTokenGatewayV3.sol).

### Write Methods

#### depositETH

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

Wraps and supplies gas tokens to Tydro. 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:**

<table data-header-hidden><thead><tr><th valign="top"></th><th valign="top"></th><th></th></tr></thead><tbody><tr><td valign="top">Name</td><td valign="top">Type</td><td>Description</td></tr><tr><td valign="top">onBehalfOf</td><td valign="top">address</td><td>The address of the user who will receive the aTokens representing the supplied tokens</td></tr><tr><td valign="top">referralCode</td><td valign="top">uint16</td><td>Inactive, can pass 0 as placeholder</td></tr></tbody></table>

#### withdrawETH

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

Withdraws amount of the supplied wrapped gas token, unwraps it and transfers to the toaddress. 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:**

<table data-header-hidden><thead><tr><th valign="top"></th><th valign="top"></th><th></th></tr></thead><tbody><tr><td valign="top">Name</td><td valign="top">Type</td><td>Description</td></tr><tr><td valign="top">amount</td><td valign="top">uint256</td><td>amount of aWETH to withdraw and receive native ETH</td></tr><tr><td valign="top">to</td><td valign="top">address</td><td>The address of the user who will receive native ETH</td></tr></tbody></table>

#### 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:**

| Name       | Type    | Description                                                               |
| ---------- | ------- | ------------------------------------------------------------------------- |
| amount     | uint256 | The amount to repay, or uint256(-1) if the user wants to repay everything |
| rateMode   | uint256 | Should always be passed a value of 2 (variable rate mode)                 |
| onBehalfOf | address | The 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](https://docs.tydro.com/developers/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:**

| Name             | Type    | Description                                                                  |
| ---------------- | ------- | ---------------------------------------------------------------------------- |
| amount           | uint256 | The amount of ETH to borrow                                                  |
| interestRateMode | uint256 | Should always be passed a value of 2 (variable rate mode)                    |
| referralCode     | uint16  | Integrators 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 toaddress. If the amount is uint(-1), 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 ERC712 permit sig                       |
| permitR  | bytes32 | R parameter of ERC712 permit sig                       |
| permitS  | bytes32 | S parameter of ERC712 permit sig                       |

### View Methods

#### getWETHAddress

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

Get WETH address used by WrappedTokenGatewayV3.

**Return Values:**

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