# L2TokenReceiverV2

## Introduction

The `L2TokenReceiverV2` contract is a component of the protocol deployed on Arbitrum (L2). It is responsible for receiving stETH yield sent from Ethereum (L1) via the Arbitrum Bridge. Upon receipt, the yield is stored within the contract and can later be  converted into MOR tokens to support liquidity or distribution.

### Key Responsibilities

* Bridged token receiver: handles incoming stETH/wstETH tokens from the L1Sender contract via Arbitrum Bridge.
* Uniswap v3 Integration: enables the protocol to swap tokens or increase liquidity in Uniswap v3 pools.

***

## Storage

### router

The address of Uniswap v3 `SwapRouter` used for swaps.

```solidity
address public router;
```

### nonfungiblePositionManager

The address of Uniswap v3 `NonfungiblePositionManager` used for adding liquidity and collect fees.

```solidity
address public nonfungiblePositionManager;
```

### firstSwapParams

Holds the current token swap configuration for Uniswap v3 operations. Uses for wstETH/wETH pair.

```solidity
SwapParams public firstSwapParams;

struct SwapParams {
  address tokenIn;
  address tokenOut;
  uint24 fee;
  uint160 sqrtPriceLimitX96;
}
```

| Field               | Description                                                          |
| ------------------- | -------------------------------------------------------------------- |
| `tokenIn`           | Address of the token to be swapped from (input token).               |
| `tokenOut`          | Address of the token to be swapped to (output token).                |
| `fee`               | Uniswap v3 pool fee tier in hundredths of a bip (e.g., 3000 = 0.3%). |
| `sqrtPriceLimitX96` | Optional price limit for swap.                                       |

### secondSwapParams

Holds the current token swap configuration for Uniswap v3 operations. Uses for wETH/MOR pair.

```solidity
SwapParams public secondSwapParams;
```

## Write functions for the contract owner

### L2TokenReceiver\_\_init

Initializes the contract during deployment (used with proxies). Can only be called once.

```solidity
function L2TokenReceiver__init(
    address router_,
    address nonfungiblePositionManager_,
    SwapParams memory secondSwapParams_
) external initializer
```

| Name                          | Description                                                  |
| ----------------------------- | ------------------------------------------------------------ |
| `router_`                     | Address of Uniswap v3 `SwapRouter` contract.                 |
| `nonfungiblePositionManager_` | Address of Uniswap v3 `NonfungiblePositionManager` contract. |
| `secondSwapParams_`           | Swap parameters for the Uniswap wETH/MOR pool.               |

### editParams

Allows the contract owner to update swap parameters and reapprove token allowances.

```solidity
function editParams(
  SwapParams memory newParams_,
  bool isEditFirstParams_
) external onlyOwner
```

| Parameter            | Description                                                             |
| -------------------- | ----------------------------------------------------------------------- |
| `newParams_`         | New `SwapParams` struct for the Uniswap pool.                           |
| `isEditFirstParams_` | `True` - when edit the wstETH/wETH pair. `False` for the wETH/MOR pair. |

***

### swap

Performs a token swap using Uniswap v3 router.

```solidity
function swap(
  uint256 amountIn_,
  uint256 amountOutMinimum_,
  uint256 deadline_,
  bool isUseFirstSwapParams_
) external onlyOwner returns (uint256)
```

| Parameter            | Description                                                               |
| -------------------- | ------------------------------------------------------------------------- |
| `amountIn_`          | Amount of input token to swap. See the token decimals for the precision.  |
| `amountOutMinimum_`  | Minimum expected output amount. See the token decimals for the precision. |
| `deadline_`          | Expiry timestamp in seconds for the transaction.                          |
| `isEditFirstParams_` | `True` - when use the wstETH/wETH pair. `False` for the wETH/MOR pair.    |

Returns: output token amount.

### increaseLiquidityCurrentRange

Adds liquidity to an existing Uniswap NFT position.

```solidity
function increaseLiquidityCurrentRange(
  uint256 tokenId_,
  uint256 amountAdd0_,
  uint256 amountAdd1_,
  uint256 amountMin0_,
  uint256 amountMin1_
) external onlyOwner returns (
  uint128 liquidity_,
  uint256 amount0_,
  uint256 amount1_
 )
```

| Parameter     | Description                                                           |
| ------------- | --------------------------------------------------------------------- |
| `tokenId_`    | NFT ID of the position.                                               |
| `amountAdd0_` | Desired amount for token 0. See the token decimals for the precision. |
| `amountAdd1_` | Desired amount for token 1. See the token decimals for the precision. |
| `amountMin0_` | Minimum amount of token 0. See the token decimals for the precision.  |
| `amountMin1_` | Minimum amount of token 1. See the token decimals for the precision.  |

### collectFees

Collects all available fees from a Uniswap NFT liquidity position. Returns the collected amounts of token0 and token1.

```solidity
function collectFees(
  uint256 tokenId_
) external returns (uint256 amount0_, uint256 amount1_)
```

| Parameter  | Description            |
| ---------- | ---------------------- |
| `tokenId_` | NFT ID of the position |

## Read functions

### supportsInterface

Used for interface detection (ERC165). Returns true if the contract supports a specific `interfaceId_`. Supports `IL2TokenReceiverV2`, `IERC165`.

```solidity
function supportsInterface(bytes4 interfaceId_) external pure returns (bool)
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://gitbook.mor.org/smart-contracts/documentation/distribution-protocol/v7-protocol/contracts/l2tokenreceiverv2.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
