# singleLiquidityWrapper.sol

**Primary Uses -** Unique to uTrade, the Single Liquidity Wrapper allows MATIC or any ERC-20 token on Matic to be converted into a LP pool. For example, MATIC can be added using the wrapper to supply liquidity for a BUSD / WMATIC pair. The wrapper allows LP tokens to exit in a similar fashion. The functionality from this wrapper simplifies applications such as compounding or fee-on-transfer additions to liquidity pools.

## uTrade V2 Single Liquidity Wrapper Code / Interfaces

|                                                      |                                                                                                                                                   |
| ---------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------- |
| uTrade V2 Single Liquidity Wrapper (Solidity)        | [PolygonScan Verified](https://polygonscan.com/address/0x692F3360166fb7654026a89801DdE9F684F8F8b0#code)                                           |
| uTrade V2 Single Liquidity Wrapper Interface as JSON | [GitHub](https://github.com/unifiprotocol/uTradeV2-core/blob/52d66be2a472b9697a577757a0446076b6c32001/ABI/JSON/IUnifiSingleLiquidityWrapper.json) |
| uTrade V2 Single Liquidity Wrapper as Typescript     | [GitHub](https://github.com/unifiprotocol/uTradeV2-core/blob/52d66be2a472b9697a577757a0446076b6c32001/ABI/TS/IUnifiSingleLiquidityWrapper.ts)     |
| Import statement codeblock (when available)          |                                                                                                                                                   |

## uTrade V2 Single Liquidity Wrapper Contract Addresses

| Network          | Address                                                                                                                           |
| ---------------- | --------------------------------------------------------------------------------------------------------------------------------- |
| Polygon Main Net | `0x692F3360166fb7654026a89801DdE9F684F8F8b0` ([Link](https://polygonscan.com/address/0x692F3360166fb7654026a89801DdE9F684F8F8b0)) |

### convertSingleAssetToLiquidity

```
function convertSingleAssetToLiquidity(address tokenA, address requireToken, uint amount, address to, uint minOut) external ;
```

The `convertSingleAssetToLiquidity`function converts one of the assets that a liquidity pool contains into a LP token. It does so by first converting the exact amount of one token required for an equal amount of the other asset that makes up the pool. Next, the two equal values of tokens are added to the liquidity pool. And lastly, the LP tokens are sent to the address provided.&#x20;

| Parameter      | Type    | Description                                                                                                                                                                   |
| -------------- | ------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| *tokenA*       | address | The contract address of the provided token to be converted into the LP token.                                                                                                 |
| *requireToken* | address | The contract address of the other token in the liquidity pool. In other words, the asset that half of *tokenA* will be converted to that will be added to the liquidity pool. |
| *amount*       | uint    | The amount of *tokenA* to be sent to the liquidity pool.                                                                                                                      |
| *to*           | address | The recipient of the LP tokens.                                                                                                                                               |
| *minOut*       | uint    | The minimum amount of the received LP tokens that is acceptable. If the amount to be received is below this number, this transaction will revert.                             |

### convertSingleAssetToLiquidityEth

```
function convertSingleAssetToLiquidityEth(address requireToken, address to, uint minOut) payable external ;
```

The `convertSingleAssetToLiquidityETH`function converts MATIC  into a LP token. It does so by first converting the provided MATIC into equal amounts of the two tokens that make up the liquidity pool. Next, the two equal values of tokens are added to the liquidity pool. And lastly, the LP tokens are sent to the address provided. The MATIC value is sent as a msg.value parameter. One of the two assets can be WMATIC.

#### Parameter Breakdown

| Parameter                                        | Type    | Description                                                                                                                                       |
| ------------------------------------------------ | ------- | ------------------------------------------------------------------------------------------------------------------------------------------------- |
| <p><em>amountIn</em><br><em>(msg.value)</em></p> | uint    | The amount of MATIC to be converted to the two tokens that make up a liquidity pool. Sent as the message value.                                   |
| *requireToken*                                   | address | The address of the LP token token contract that is being supplied.                                                                                |
| *to*                                             | address | The recipient of the LP tokens.                                                                                                                   |
| *minOut*                                         | uint    | The minimum amount of the received LP tokens that is acceptable. If the amount to be received is below this number, this transaction will revert. |

### convertSingleAssetToOtherLiquidity

```
function convertSingleAssetToOtherLiquidity(address depositToken, address requireTokenA,address requireTokenB , uint amount , address to, address[] calldata path1, address[] calldata path2,uint minOut) external ;
```

The `convertSingleAssetToOtherLiquidity`function converts any ERC-20 token available on uTrade V2 to a uTrade V2 LP token made up of two different tokens. In other words, a token that is not included in a liquidity pair will be converted to the two tokens that do make up the liquidity pair, and added to the liquidity pool.&#x20;

| Parameter       | Type    | Description                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     |
| --------------- | ------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| *depositToken*  | address | The contract address of the provided token to be converted into the LP token.                                                                                                                                                                                                                                                                                                                                                                                                                                                                   |
| *requireTokenA* | address | The contract address of *tokenA* in the desired liquidity pair.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 |
| *requireTokenB* | address | The contract address of *tokenB* in the desired liquidity pair.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 |
| *amount*        | uint    | The amount of the *depositToken* to be converted to the two liquidity pool tokens.                                                                                                                                                                                                                                                                                                                                                                                                                                                              |
| *to*            | address | The recipient of the LP tokens.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 |
| *path1*         | address | <p>The pathway to change <em>depositToken</em> into <em>requireTokenA</em>, consisting of an array of token addresses. Each token must have an existing liquidity pool, as well as have liquidity.<br></p><p>In other words, the path represents the pathway from the token you are providing to the first token that makes up the liquidity pool you are adding to. If there is no direct pair, multiple addresses will be required. The last token contract address in <em>path1</em> will be the first token in the liquidity pair.</p>      |
| *path2*         | address | <p>The pathway to change the <em>depositToken</em> into <em>requireTokenB</em>, consisting of an array of token addresses. Each token must have an existing liquidity pool, as well as have liquidity.<br></p><p>In other words, the path represents the pathway from the token you are providing to the first token that makes up the liquidity pool you are adding to. If there is no direct pair, multiple addresses will be required. The last token contract address in <em>path2</em> will be the second token in the liquidity pair.</p> |
| *minOut*        | uint    | The minimum amount of the received LP tokens that is acceptable. If the amount to be received is below this number, this transaction will revert.                                                                                                                                                                                                                                                                                                                                                                                               |

### convertSingleAssetToOtherLiquidityETH

```
function convertSingleAssetToOtherLiquidityETH( address requireTokenA,address requireTokenB  , address to, address[] calldata path1, address[] calldata path2,uint minOut) payable external ;
```

The `convertSingleAssetToOtherLiquidityETH`function converts MATIC to an uTrade V2 LP token made up of two different tokens. In other words, MATIC will be converted to the two tokens that make up a liquidity pair, and then the two tokens are added to the liquidity pool.&#x20;

| Parameter                                        | Type    | Description                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             |
| ------------------------------------------------ | ------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| <p><em>amountIn</em><br><em>(msg.value)</em></p> | uint    | The amount of MATIC to be converted to the two tokens that make up a liquidity pool. Sent as the message value.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         |
| *requireTokenA*                                  | address | The contract address of tokenA in the desired liquidity pair.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           |
| *requireTokenB*                                  | address | The contract address of tokenB in the desired liquidity pair.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           |
| *to*                                             | address | The recipient of the LP tokens.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         |
| *path1*                                          | address | <p>The pathway to change MATIC into <em>requireTokenA</em>, consisting of an array of token addresses. Each token must have an existing liquidity pool, as well as have liquidity. The first address must be WMATIC's contract address.<br></p><p>In other words, the path represents the pathway from the token you are providing to the first token that makes up the liquidity pool you are adding to. As MATIC must be converted to WMATIC, multiple addresses will be required. The last token contract address in <em>path1</em> will be the first token in the liquidity pair.</p>               |
| *path2*                                          | address | <p>The pathway to change MATIC into <em>requireTokenB</em>, consisting of an array of token addresses. Each token must have an existing liquidity pool, as well as have liquidity. The first address in the array must be WMATIC's contract address.<br></p><p>In other words, the path represents the pathway from the token you are providing to the first token that makes up the liquidity pool you are adding to. As MATIC must be converted to WMATIC, multiple addresses will be required. The last token contract address in <em>path2</em> will be the second token in the liquidity pair.</p> |
| *minOut*                                         | uint    | The minimum amount of the received LP tokens that is acceptable. If the amount to be received is below this number, this transaction will revert.                                                                                                                                                                                                                                                                                                                                                                                                                                                       |

### withdrawSupplyAsSingleAsset

```
function withdrawSupplyAsSingleAsset( address receiveToken , address liquidityToken ,address tokenA,address tokenB, address payable to, uint amount, bool toReceiveWNative,uint minOut) external ;
```

The `withdrawSupplyAsSingleAsset` function withdraws a user's liquidity from a pool, and converts it to one of the two tokens that makes up the liquidity pool. In other words, it redeems an LP token for one of the two assets that make up an LP token.

#### Parameter Breakdown

| Parameter          | Type    | Description                                                                                                                                                        |
| ------------------ | ------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| *receiveToken*     | address | The address of the token contract of the preferred token to be withdrawn. This determines which of the two tokens the LP will be converted to.                     |
| *liquidityToken*   | address | The address of the token contract for the LP token to be converted.                                                                                                |
| *tokenA*           | address | The address of the token contract for the first token in the liquidity pool.                                                                                       |
| *tokenB*           | address | The address of the token contract for the second token in the liquidity pool.                                                                                      |
| *to*               | address | The address to where the single asset will be sent.                                                                                                                |
| *amount*           | uint    | The amount of LP tokens to be removed.                                                                                                                             |
| *toReceiveWNative* | bool    | A true/false value if one of the assets to be received is native BNB. If true, the *receiveToken* address should be WBNB, as it will unwrap WMATIC and send MATIC. |
| *minOut*           | uint    | The minimum amount of the received asset that is acceptable. If the amount to be received is below this number, this transaction will revert.                      |

### withdrawSupplyAsOtherSingleAsset

```
function withdrawSupplyAsOtherSingleAsset(address receiveToken, address liquidityToken, address tokenA, address tokenB, address payable to, uint amount, address[] calldata path1, address[] calldata path2, bool toReceiveWNative, uint minOut) external ;
```

The `withdrawSupplyAsOtherSingleAsset`function withdraws a user's liquidity from a pool, and converts it to any other asset that is available on uTrade V2. In other words, it redeems an LP token for MATIC or any ERC-20 token available.

#### Parameter Breakdown

| Parameter          | Type    | Description                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 |
| ------------------ | ------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| *receiveToken*     | address | The address of the token contract of the preferred token to be withdrawn. This determines which of the two tokens the LP will be converted to.                                                                                                                                                                                                                                                                                                                                              |
| *liquidityToken*   | address | The address of the token contract for the LP token to be converted.                                                                                                                                                                                                                                                                                                                                                                                                                         |
| *tokenA*           | address | The address of the token contract for the first token in the liquidity pool.                                                                                                                                                                                                                                                                                                                                                                                                                |
| *tokenB*           | address | The address of the token contract for the second token in the liquidity pool.                                                                                                                                                                                                                                                                                                                                                                                                               |
| *to*               | address | The address to where the single asset will be sent.                                                                                                                                                                                                                                                                                                                                                                                                                                         |
| *amount*           | uint    | The amount of LP tokens to be removed.                                                                                                                                                                                                                                                                                                                                                                                                                                                      |
| *path1*            | address | <p>The pathway to change <em>tokenA</em> into the desired asset, consisting of an array of token addresses. Each token must have an existing liquidity pool, as well as have liquidity.<br></p><p>In other words, the path represents the pathway from <em>tokenA</em> to the withdraw token. If there is no direct pair, multiple addresses will be required. The last token contract address in <em>path1</em> must be the same as the last token contract address in <em>path2.</em></p> |
| *path2*            | address | <p>The pathway to change <em>tokenB</em> into the desired asset, consisting of an array of addresses. Each token must have an existing liquidity pool, as well as have liquidity.<br></p><p>In other words, the path represents the pathway from <em>tokenB</em> to the withdraw token. If there is no direct pair, multiple addresses will be required. The last token contract address in <em>path2</em> must be the same as the last token contract address in <em>path1.</em></p>       |
| *toReceiveWNative* | bool    | A true/false value if one of the assets to be received is native MATIC. If true, the *receiveToken* address should be WMATIC, as it will unwrap WMATIC and send MATIC.                                                                                                                                                                                                                                                                                                                      |
| *minOut*           | uint    | The minimum amount of the received asset that is acceptable. If the amount to be received is below this number, this transaction will revert.                                                                                                                                                                                                                                                                                                                                               |

## &#x20;Interface Code

```
interface IUnifiSingleLiquidity {
    function convertSingleAssetToLiquidity(address tokenA, address requireToken, uint amount, address to, uint minOut) external ;
    function convertSingleAssetToLiquidityEth(address requireToken, address to, uint minOut) payable external ;
    function convertSingleAssetToOtherLiquidity(address depositToken, address requireTokenA, address requireTokenB, uint amount, address to, address[] calldata path1, address[] calldata path2, uint minOut) external ;
    function convertSingleAssetToOtherLiquidityETH(address requireTokenA, address requireTokenB, address to, address[] calldata path1, address[] calldata path2, uint minOut) payable external ;
    function withdrawSupplyAsSingleAsset(address receiveToken, address liquidityToken, address tokenA, address tokenB, address payable to, uint amount, bool toReceiveWNative, uint minOut) external ;
    function withdrawSupplyAsOtherSingleAsset(address receiveToken, address liquidityToken, address tokenA, address tokenB, address payable to, uint amount, address[] calldata path1, address[] calldata path2, bool toReceiveWNative, uint minOut) external ;
}
```
