# WrappedTokenBridge

The `WrappedTokenBridge` enables users to wrap a token and transfer it to another chain in a single transaction using CCIP. Additionally it can receive a CCIP token transfer from another chain and automatically unwrap tokens before sending them to their final destination.

*This contract is used to handle stLINK <-> wstLINK transfers between the primary chain and secondary chains.*

## View Functions

### getRouter

Returns the current CCIP router

```solidity
function getRouter() public view returns (address)
```

#### Return Values

| Name   | Type    | Description    |
| ------ | ------- | -------------- |
| router | address | router address |

### linkToken

Returns the address of the LINK token

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

#### Return Values

| Name      | Type    | Description           |
| --------- | ------- | --------------------- |
| linkToken | address | address of LINK token |

### token

Returns the address of the underlying token bridged by this contract

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

#### Return Values

| Name            | Type    | Description                 |
| --------------- | ------- | --------------------------- |
| underlyingToken | address | address of underlying token |

### wrappedToken

Returns the address of the wrapped token bridged by this contract

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

#### Return Values

| Name         | Type    | Description              |
| ------------ | ------- | ------------------------ |
| wrappedToken | address | address of wrapped token |

### getFee

Returns the current fee for a token transfer

```solidity
function getFee(uint64 _destinationChainSelector, uint256 _amount, bool _payNative) external view returns (uint256)
```

#### Parameters

| Name                       | Type    | Description                                      |
| -------------------------- | ------- | ------------------------------------------------ |
| \_destinationChainSelector | uint64  | id of destination chain                          |
| \_amount                   | uint256 | amount of tokens to transfer                     |
| \_payNative                | bool    | whether fee should be paid natively or with LINK |

#### Return Values

| Name | Type    | Description |
| ---- | ------- | ----------- |
| fee  | uint256 | current fee |

## Write Functions

### setRouter

Sets the CCIP router

```solidity
function setRouter(address _router) external
```

#### Parameters

| Name     | Type    | Description    |
| -------- | ------- | -------------- |
| \_router | address | router address |

### onTokenTransfer

ERC677 implementation to receive a token transfer to be wrapped and sent to a destination chain

```solidity
function onTokenTransfer(address _sender, uint256 _value, bytes _calldata) external
```

#### Parameters

| Name       | Type    | Description                                                                                                |
| ---------- | ------- | ---------------------------------------------------------------------------------------------------------- |
| \_sender   | address | address of sender                                                                                          |
| \_value    | uint256 | amount of tokens transferred                                                                               |
| \_calldata | bytes   | encoded calldata consisting of destinationChainSelector (uint64), receiver (address), maxLINKFee (uint256) |

### transferTokens

Wraps and transfers tokens to a destination chain

```solidity
function transferTokens(uint64 _destinationChainSelector, address _receiver, uint256 _amount, bool _payNative, uint256 _maxLINKFee) external payable returns (bytes32 messageId)
```

#### Parameters

| Name                       | Type    | Description                                      |
| -------------------------- | ------- | ------------------------------------------------ |
| \_destinationChainSelector | uint64  | id of destination chain                          |
| \_receiver                 | address | address to receive tokens on destination chain   |
| \_amount                   | uint256 | amount of tokens to transfer                     |
| \_payNative                | bool    | whether fee should be paid natively or with LINK |
| \_maxLINKFee               | uint256 | call will revert if LINK fee exceeds this value  |

### recoverTokens

Withdraws tokens held by this contract

```solidity
function recoverTokens(address[] _tokens, uint256[] _amounts, address _receiver) external
```

#### Parameters

| Name       | Type       | Description                               |
| ---------- | ---------- | ----------------------------------------- |
| \_tokens   | address\[] | list of tokens to withdraw                |
| \_amounts  | uint256\[] | list of corresponding amounts to withdraw |
| \_receiver | address    | address to receive tokens                 |
