# MidasRouter

### MidasRouter

Main contract to interact with to swap and manage liquidity on Midaswap.

#### constructor

```Solidity
constructor(IWETH _weth, IMidasFactory721 _factory)
```

#### receive

```Solidity
receive() external payable
```

*Receive function that only accepts ETH from the WETH contract*

#### addLiquidityERC721

```Solidity
function addLiquidityERC721(address _tokenX, address _tokenY, uint24[] calldata _ids, uint256[] calldata _tokenIds, uint256 _deadline) external override ensure(_deadline)
```

Function to add liquidity of NFTs and wrap the position with an ERC-721 token.

**Parameters**

| **Name**   | **Type**            | **Description**                         |
| ---------- | ------------------- | --------------------------------------- |
| \_tokenX   | address             | The address of ERC-721 asset            |
| \_tokenY   | address             | The address of ERC-20 asset             |
| \_ids      | uint24\[] calldata  | The list of ids to add liquidity        |
| \_tokenIds | uint256\[] calldata | The list of tokenIds of NFT to be added |
| \_deadline | uint256             | The deadline of the tx                  |

**Return Values**

| **Name**  | **Type** | **Description**        |
| --------- | -------- | ---------------------- |
| idAmount  | uint256  | The amount of ids      |
| lpTokenId | uint128  | The ID of the LP token |

#### addLiquidityERC20

```Solidity
function addLiquidityERC20(address _tokenX, address _tokenY, uint24[] calldata _ids, uint256 _deadline) external override ensure(_deadline)
```

Function to add liquidity of FT and wrap the position with an ERC-721 token.

**Parameters**

| **Name**   | **Type**           | **Description**                  |
| ---------- | ------------------ | -------------------------------- |
| \_tokenX   | address            | The address of ERC-721 asset     |
| \_tokenY   | address            | The address of ERC-20 asset      |
| \_ids      | uint24\[] calldata | The list of ids to add liquidity |
| \_deadline | uint256            | The deadline of the tx           |

**Return Values**

| **Name**  | **Type** | **Description**        |
| --------- | -------- | ---------------------- |
| idAmount  | uint256  | The amount of ids      |
| lpTokenId | uint128  | The ID of the LP token |

#### addLiquidityETH

```Solidity
function addLiquidityETH(address _tokenX, address _tokenY, uint24[] calldata _ids, uint256 _deadline) external override ensure(_deadline)
```

Function to add liquidity of ETH and wrap the position with an ERC-721 token.

**Parameters**

| **Name**   | **Type**           | **Description**                  |
| ---------- | ------------------ | -------------------------------- |
| \_tokenX   | address            | The address of ERC-721 asset     |
| \_tokenY   | address            | The address of ERC-20 asset      |
| \_ids      | uint24\[] calldata | The list of ids to add liquidity |
| \_deadline | uint256            | The deadline of the tx           |

**Return Values**

| **Name**  | **Type** | **Description**        |
| --------- | -------- | ---------------------- |
| idAmount  | uint256  | The amount of ids      |
| lpTokenId | uint128  | The ID of the LP token |

#### removeLiquidity

```Solidity
function removeLiquidity(address _tokenX, address _tokenY, uint128 _lpTokenId, uint256 _deadline) external override ensure(_deadline)
```

Function to remove liquidity and burn the LP token.

**Parameters**

| **Name**    | **Type** | **Description**              |
| ----------- | -------- | ---------------------------- |
| \_tokenX    | address  | The address of ERC-721 asset |
| \_tokenY    | address  | The address of ERC-20 asset  |
| \_lpTokenId | uint128  | The ID of LP token           |
| \_deadline  | uint256  | The deadline of the tx       |

**Return Values**

| **Name**  | **Type** | **Description**   |
| --------- | -------- | ----------------- |
| nftAmount | uint256  | The amount of NFT |
| ftAmount  | uint256  | The amount of FT  |

#### removeLiquidityETH

```Solidity
function removeLiquidityETH(address _tokenX, address _tokenY, uint128 _lpTokenId, uint256 _deadline) external override ensure(_deadline)
```

Function to remove liquidity of ETH and burn the LP token.

**Parameters**

| **Name**    | **Type** | **Description**              |
| ----------- | -------- | ---------------------------- |
| \_tokenX    | address  | The address of ERC-721 asset |
| \_tokenY    | address  | The address of ERC-20 asset  |
| \_lpTokenId | uint128  | The ID of LP token           |
| \_deadline  | uint256  | The deadline of the tx       |

**Return Values**

| **Name**  | **Type** | **Description**   |
| --------- | -------- | ----------------- |
| nftAmount | uint256  | The amount of NFT |
| ftAmount  | uint256  | The amount of FT  |

#### sellItems

```Solidity
function sellItems(address _tokenX, address _tokenY, uint256[] calldata _tokenIds, uint256 _deadline) external override ensure(_deadline)
```

Function to sell NFTs and receive FT.

**Parameters**

| **Name**   | **Type**            | **Description**                         |
| ---------- | ------------------- | --------------------------------------- |
| \_tokenX   | address             | The address of ERC-721 asset            |
| \_tokenY   | address             | The address of ERC-20 asset             |
| \_tokenIds | uint256\[] calldata | The list of tokenIds of NFT to be added |
| \_deadline | uint256             | The deadline of the tx                  |

**Return Values**

| **Name**   | **Type** | **Description**             |
| ---------- | -------- | --------------------------- |
| \_ftAmount | uint256  | The amount of FT to receive |

#### sellItemsToETH

```Solidity
function sellItemsToETH(address _tokenX, address _tokenY, uint256[] calldata _tokenIds, uint256 _deadline) external override ensure(_deadline)
```

Function to sell NFTs and receive ETH.

**Parameters**

| **Name**   | **Type**            | **Description**                         |
| ---------- | ------------------- | --------------------------------------- |
| \_tokenX   | address             | The address of ERC-721 asset            |
| \_tokenY   | address             | The address of ERC-20 asset             |
| \_tokenIds | uint256\[] calldata | The list of tokenIds of NFT to be added |
| \_deadline | uint256             | The deadline of the tx                  |

**Return Values**

| **Name**   | **Type** | **Description**             |
| ---------- | -------- | --------------------------- |
| \_ftAmount | uint256  | The amount of FT to receive |

#### buyItems

```Solidity
function buyItems(address _tokenX, address _tokenY, uint256[] calldata _tokenIds, uint256 _deadline) external override ensure(_deadline)
```

Function to buy NFTs and give out FT.

**Parameters**

| **Name**   | **Type**            | **Description**                         |
| ---------- | ------------------- | --------------------------------------- |
| \_tokenX   | address             | The address of ERC-721 asset            |
| \_tokenY   | address             | The address of ERC-20 asset             |
| \_tokenIds | uint256\[] calldata | The list of tokenIds of NFT to be added |
| \_deadline | uint256             | The deadline of the tx                  |

**Return Values**

| **Name**   | **Type** | **Description**             |
| ---------- | -------- | --------------------------- |
| \_ftAmount | uint256  | The amount of FT to receive |

#### buyItemsWithETH

```Solidity
function buyItems(address _tokenX, address _tokenY, uint256[] calldata _tokenIds, uint256 _deadline) external override ensure(_deadline)
```

Function to buy NFTs and give out ETH.

**Parameters**

| **Name**   | **Type**            | **Description**                         |
| ---------- | ------------------- | --------------------------------------- |
| \_tokenX   | address             | The address of ERC-721 asset            |
| \_tokenY   | address             | The address of ERC-20 asset             |
| \_tokenIds | uint256\[] calldata | The list of tokenIds of NFT to be added |
| \_deadline | uint256             | The deadline of the tx                  |

**Return Values**

| **Name**   | **Type** | **Description**             |
| ---------- | -------- | --------------------------- |
| \_ftAmount | uint256  | The amount of FT to receive |

#### openLimitOrder

```Solidity
function openLimitOrder(address _tokenX, address _tokenY, uint24[] calldata _ids, uint256[] calldata _tokenIds, uint256 _deadline) external override ensure(_deadline)
```

Function to open a limit order to sell NFTs at spot prices.

**Parameters**

| **Name**   | **Type**            | **Description**                         |
| ---------- | ------------------- | --------------------------------------- |
| \_tokenX   | address             | The address of ERC-721 asset            |
| \_tokenY   | address             | The address of ERC-20 asset             |
| \_ids      | uint24\[] calldata  | The list of ids of limited price        |
| \_tokenIds | uint256\[] calldata | The list of tokenIds of NFT to be added |
| \_deadline | uint256             | The deadline of the tx                  |

**Return Values**

| **Name**    | **Type** | **Description**                         |
| ----------- | -------- | --------------------------------------- |
| \_ftAmount  | uint256  | The amount of FT to receive             |
| \_lpTokenId | uint128  | The ID of LP token to redeem the income |

#### openMultiLimitOrders

```Solidity
function openMultiLimitOrders(address _tokenX, address _tokenY, uint24[] calldata _ids, uint256[] calldata _tokenIds, uint256 _deadline) external override ensure(_deadline)
```

Function to open multiple limit orders to sell NFTs at spot prices.

**Parameters**

| **Name**   | **Type**            | **Description**                         |
| ---------- | ------------------- | --------------------------------------- |
| \_tokenX   | address             | The address of ERC-721 asset            |
| \_tokenY   | address             | The address of ERC-20 asset             |
| \_ids      | uint24\[] calldata  | The list of ids of limited price        |
| \_tokenIds | uint256\[] calldata | The list of tokenIds of NFT to be added |
| \_deadline | uint256             | The deadline of the tx                  |

**Return Values**

| **Name**   | **Type**          | **Description**                          |
| ---------- | ----------------- | ---------------------------------------- |
| lpTokenIds | uint128\[] memory | The IDs of LP token to redeem the income |

#### claimFee

```Solidity
function claimFee(address _tokenX, address _tokenY, uint128 _lpTokenId) external override
```

Function for LPs to claim the swap fees from one position.

**Parameters**

| **Name**    | **Type** | **Description**              |
| ----------- | -------- | ---------------------------- |
| \_tokenX    | address  | The address of ERC-721 asset |
| \_tokenY    | address  | The address of ERC-20 asset  |
| \_lpTokenId | uint128  | The ID of LP token           |

**Return Values**

| **Name**     | **Type** | **Description**                 |
| ------------ | -------- | ------------------------------- |
| \_feeClaimed | uint128  | The amount of fee to be claimed |

#### claimAll

```Solidity
function claimAll(address _tokenX, address _tokenY, uint128[] calldata _lpTokenId) external override
```

Function for LPs to claim the swap fees from multiple positions.

**Parameters**

| **Name**    | **Type**            | **Description**              |
| ----------- | ------------------- | ---------------------------- |
| \_tokenX    | address             | The address of ERC-721 asset |
| \_tokenY    | address             | The address of ERC-20 asset  |
| \_lpTokenId | uint128\[] calldata | The IDs of LP token          |

**Return Values**

| **Name**     | **Type** | **Description**                 |
| ------------ | -------- | ------------------------------- |
| \_feeClaimed | uint128  | The amount of fee to be claimed |

#### getAmountsToAdd

```Solidity
function getAmountsToAdd(address _pair, uint24[] calldata _ids) public view
```

Function to get a quote for the FT amount to add.

**Parameters**

| **Name** | **Type**           | **Description**                  |
| -------- | ------------------ | -------------------------------- |
| \_pair   | address            | The address of the Midas pair    |
| \_ids    | uint24\[] calldata | The list of ids of limited price |

**Return Values**

| **Name** | **Type** | **Description**                |
| -------- | -------- | ------------------------------ |
| ftAmount | uint256  | The amount of FT needed to add |

#### getMinAmountIn

```Solidity
function getMinAmountIn(address _pair, uint256[] calldata _tokenIds) public view
```

Function to get a quote for buying specific NFTs.

**Parameters**

| **Name**   | **Type**            | **Description**                         |
| ---------- | ------------------- | --------------------------------------- |
| \_pair     | address             | The address of the Midas pair           |
| \_tokenIds | uint256\[] calldata | The list of tokenIds of NFT to be added |

**Return Values**

| **Name**    | **Type** | **Description**                |
| ----------- | -------- | ------------------------------ |
| totalAmount | uint256  | The amount of FT needed to pay |
