# Welcome!

Unifi Protocol is a group of non-custodial, interoperable, decentralized, and multi-chain smart contracts providing the building blocks for the next generation of DeFi development.

![](/files/-MhMiOTjdWiGxPXvNzKE)

Unifi Protocol is the building blocks of an entire suite of DeFi products, portable from blockchain to blockchain. The following documentation lays out the individual components and contracts that make up our platform, feel free to join our [Telegram](https://t.me/unifi_protocol) so we can help you build!


# UNIFI / UP Token Contract Addresses

## UNIFI Token Addresses

UNIFI is the global governance token for the entire multi-chain protocol and the public face of the Unifi Protocol to be listed on major exchanges. Currently, UNIFI on Ethereum can be staked to earn rewards on our [UNIFI DAO Governance Page](https://gov.unifiprotocol.com/my-dashboard).   UNIFI on  can also participate in blockchain governance on our [UNIFI DAO Governance Page](https://gov.unifiprotocol.com/my-dashboard).  UNIFI token exists on BSC and Ethereum, and will be coming to each uTrade blockchain.  UNIFI is required to participate in UNIFI Super Pairs on each blockchain.  Super Pairs receive a portion of the trading fee from all preferred pairs on that blockchain.  \
\
Currently, UNIFI is on nine blockchains. \
\
To utilize the staking features of UNIFI, the UNIFI must be ERC-20, or in other words, on the Ethereum Network. \
\
To utilize the governing features of UNIFI, the UNIFI must be on Ethereum, Binance Smart Chain, Polygon, Fantom, Avalanche, or Harmony. \
\
Most centralized exchanges utilize ERC-20 UNIFI on the Ethereum Network and BEP-20 UNIFI on the Binance Smart Chain Network.

| Blockchain          | Ticker  | Address                                      | Explorer Link                                                                                         |
| ------------------- | ------- | -------------------------------------------- | ----------------------------------------------------------------------------------------------------- |
| Ethereum            | `UNIFI` | `0x441761326490cACF7aF299725B6292597EE822c2` | [Etherscan](https://etherscan.io/address/0x441761326490cACF7aF299725B6292597EE822c2)                  |
| Binance Smart Chain | `UNIFI` | `0x728C5baC3C3e370E372Fc4671f9ef6916b814d8B` | [BscScan](https://bscscan.com/address/0x728c5bac3c3e370e372fc4671f9ef6916b814d8b)                     |
| Harmony             | `UNIFI` | `0xEe7207c782d6937BE63E38FCF902fF59E5498386` | [Harmony Explorer](https://explorer.harmony.one/address/0xee7207c782d6937be63e38fcf902ff59e5498386)   |
| Ontology EVM        | `UNIFI` | `0xb510ac30c04c86Fc2FcFCc2012A415d2cEd8e629` | [ONT Explorer](https://explorer.ont.io/address/0xb510ac30c04c86Fc2FcFCc2012A415d2cEd8e629)            |
| Polygon             | `UNIFI` | `0xed6072Ef5032484c2CC5f76630310e4BD36e62d2` | [Polygonscan](https://polygonscan.com/token/0xed6072Ef5032484c2CC5f76630310e4BD36e62d2)               |
| IoTeX               | `UNIFI` | `0xd2eceda377dae9daf952c18786be736bec9312cc` | [IoTeXScan](https://iotexscan.io/address/0xd2eceda377dae9daf952c18786be736bec9312c)                   |
| BitTorrent          | `UNIFI` | `0x4d6a69c8700393cbd161a1799789345cc393a441` | [BTTCScan](https://scan.bt.io/#/token20/0x4d6a69c8700393cbd161a1799789345cc393a441)                   |
| Fantom              | `UNIFI` | `0x3824D0C574641CC8cb9253e6a84fE26E1E7a349F` | [FTMScan](https://ftmscan.com/token/0x3824d0c574641cc8cb9253e6a84fe26e1e7a349f)                       |
| Avalanche           | `UNIFI` | `0x42A99bB49b54811A95A36981Cb03d230A0Aef67B` | [AVAScan](https://avascan.info/blockchain/c/address/0x42A99bB49b54811A95A36981Cb03d230A0Aef67B/token) |

UNIFI also exists on Ethereum Ropsten Testnet as well Binance Smart Chain Testnet for developers who may wish to utilize them in building dApps.

| Blockchain                  | Ticker   | Address                                      | Link                                                                                                  |
| --------------------------- | -------- | -------------------------------------------- | ----------------------------------------------------------------------------------------------------- |
| Ethereum Ropsten            | `fakeU`  | `0x999d73539a35921D85d3cA326171735A70DE279E` | [Etherscan: Ropsten](https://ropsten.etherscan.io/address/0x999d73539a35921D85d3cA326171735A70DE279E) |
| Binance Smart Chain Testnet | `fakeUN` | `0x0B2419CC4968c737921e0F01372bDf759d417733` | [BscScan: Testnet](https://testnet.bscscan.com/address/0x0B2419CC4968c737921e0F01372bDf759d417733)    |

## UP Token Addresses

A blockchain specific liquidity mining token earned by liquidity providers. Smart contract governed minting ensures once mined, UP can only go **UP** in base token redemption value. The redemption value is different on each blockchain, and is labeled by the token name. For example, UPeth is UP with an Ethereum redemption value, and UPbnb is Binance Smart Chain’s UP with a BNB redemption value.

UP’s redemption value offers unique security and sustainability to Unifi tokenomics. UP also includes automatic yield farming and no staking, which greatly reduces network fees. UP also provides exclusive access to protocol specific opportunities to migration, allowing liquidity providers to earn UNIFI.  The minting rate of UP is governed by the current UP redeem rate.&#x20;

UP is available on any chain uTrade V1 or uTrade V2 in on. Each UP has its own redemption value - you can check the current value on [Unifi Report](https://unifi.report/up-stats).

| **Blockchain**      | **Address**                                                                                                                                               | **Explorer Link**                                                                                               |
| ------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------- |
| Avalanche C-Chain   | `0x172990f96914727e66be3fc9fe0f4c74fce06b43`                                                                                                              | [Snowtrace](https://snowtrace.io/address/0x172990f96914727e66be3fc9fe0f4c74fce06b43)                            |
| Binance Smart Chain | `0xb4E8D978bFf48c2D8FA241C0F323F71C1457CA81`                                                                                                              | [BscScan](https://bscscan.com/address/0xb4e8d978bff48c2d8fa241c0f323f71c1457ca81)                               |
| BitTorrent Chain    | `0x2220c7cd9946b9c03f0bdbbd24fa4df76e7c63e7`                                                                                                              | [BTTCscan](https://scan.bt.io/#/token20/0x2220c7cd9946b9c03f0bdbbd24fa4df76e7c63e7)                             |
| Ethereum            | `0xb6c5C839ceF46082A2B51164E8Db649c121f147E`                                                                                                              | [Etherscan](https://etherscan.io/address/0xb6c5c839cef46082a2b51164e8db649c121f147e)                            |
| Fantom              | 0x172990f96914727e66Be3fC9FE0f4C74FCe06B43                                                                                                                | [FTMScan](https://ftmscan.com/token/0x172990f96914727e66be3fc9fe0f4c74fce06b43)                                 |
| Harmony             | <p>One Format: <code>one1u0zxuhm69tfl0e5ujtltrj99mpr04xm0judmux</code></p><p>0x Format:</p><p><code>0xe3c46e5f7a2ad3f7e69c92feb1c8a5d846fa9b6f</code></p> | [Harmony Explorer](https://explorer.harmony.one/address/0xe3c46e5f7a2ad3f7e69c92feb1c8a5d846fa9b6f)             |
| Icon                | `cxce2b188690dcdf21e4d0868cc9aee9b8ab8e822e`                                                                                                              | [Icon Tracker](https://tracker.icon.foundation/contract/cxce2b188690dcdf21e4d0868cc9aee9b8ab8e822e)             |
| IoTeX               | `io1j9u0fmy20lm0uz8gfrh2c0wmuxjl43cdmgva4a`                                                                                                               | [IoTeX Explorer](https://iotexscan.io/token/io1j9u0fmy20lm0uz8gfrh2c0wmuxjl43cdmgva4a)                          |
| Ontology            | `25810fc676b1d3060a66cf004f6f759eadbee2a2`                                                                                                                | [Ontology Explorer](https://explorer.ont.io/token/detail/oep4/25810fc676b1d3060a66cf004f6f759eadbee2a2/UP/10/1) |
| Ontology EVM        | 0x172990f96914727e66Be3fC9FE0f4C74FCe06B43                                                                                                                | [Ont Explorer](https://explorer.ont.io/contract/other/0x172990f96914727e66Be3fC9FE0f4C74FCe06B43)               |
| Polygon             | `0x49B4D34eDCC985fEa2A8fBCC11Ec575283D10D87`                                                                                                              | [PolygonScan](https://polygonscan.com/address/0x49b4d34edcc985fea2a8fbcc11ec575283d10d87)                       |
| Tron                | `TJ93jQZibdB3sriHYb5nNwjgkPPAcFR7ty`                                                                                                                      | [Tronscan](https://tronscan.io/#/token20/TJ93jQZibdB3sriHYb5nNwjgkPPAcFR7ty)                                    |

UP also exists on Ethereum Ropsten Testnet as well Binance Smart Chain Testnet for developers who may wish to utilize them in building dApps.

| Blockchain                  | Ticker | Address                                      | Link                                                                                                  |
| --------------------------- | ------ | -------------------------------------------- | ----------------------------------------------------------------------------------------------------- |
| Ethereum Ropsten            | `FUP`  | `0x4393678D5bdD04a6eE5292B5bb1D8e205D9Dc556` | [Etherscan: Ropsten](https://ropsten.etherscan.io/address/0x4393678D5bdD04a6eE5292B5bb1D8e205D9Dc556) |
| Binance Smart Chain Testnet | `FUP`  | `0x2E37B22aEAAc7767998891E076AB56a6a8b8bbBF` | [BscScan: Testnet](https://testnet.bscscan.com/address/0x2E37B22aEAAc7767998891E076AB56a6a8b8bbBF)    |


# UNIFI / UP Exchanges

Looking to trade UNIFI or UP? UNIFI and UP are available on uTrade, as well as many other exchanges.\
\
Due to UNIFI and UP existing on multiple blockchains, different exchanges use different blockchains for UNIFI / UP. To help with finding the right exchange for you, the community has complied list of exchanges as well as the type of UNIFI / UP accepted.

## UNIFI

UNIFI currently exists on Ethereum, Harmony, Polygon, IoTeX, Avalanche, BitTorrent Chain, Fantom, Tron, and Ontology EVM.

| Exchange    | Type | ERC-20 | BEP-20 |
| ----------- | ---- | ------ | ------ |
| uTrade      | DEX  | ✔️     | ✔️     |
| Binance     | CEX  | ✔️     | ✔️     |
| Coinbase    | CEX  | ✔️     | ✔️     |
| Crypto.com  | CEX  | ✔️     |        |
| Huobi       | CEX  | ✔️     |        |
| Poloniex    | CEX  | ✔️     |        |
| MXC         | CEX  | ✔️     |        |
| Gate.io     | CEX  | ✔️     |        |
| KuCoin      | CEX  | ✔️     |        |
| Tokocrypto  | CEX  | ✔️     |        |
| BiTrue      | CEX  | ✔️     |        |
| BiBox       | CEX  | ✔️     |        |
| Jubex       | CEX  | ✔️     |        |
| LAToken     | CEX  | ✔️     |        |
| PancakeSwap | DEX  |        | ✔️     |
| Hotbit      | CEX  |        | ✔️     |

## UP

UP currently exists as a token on all of the blockchains that uTrade is on. Currently, that is Ethereum, Binance Smart Chain, Tron, Ontology, Ontology EVM, ICON, Harmony, IoTeX, Polygon, Avalanche, BitTorrent Chain, and Fantom.\
\
All of these tokens are tradeable on uTrade, and is likely where traders can find the most liquidity.  &#x20;

| Exchange | Type | Ethereum | Binance | Tron | Ontology | Icon | Harmony | IoTeX | Polygon |
| -------- | ---- | -------- | ------- | ---- | -------- | ---- | ------- | ----- | ------- |
| uTrade   | DEX  | ✔️       | ✔️      | ✔️   | ✔️       | ✔️   | ✔️      | ✔️    | ✔️      |
| JustSwap | DEX  |          |         | ✔️   |          |      |         |       |         |
| MXC      | CEX  |          |         | ✔️   |          |      |         |       |         |
| Hoo      | CEX  |          |         | ✔️   |          |      |         |       |         |
| Hotbit   | CEX  |          |         | ✔️   |          |      |         |       |         |
| Mimo     | DEX  |          |         |      |          |      |         | ✔️    |         |


# uTrade V2 Overview

uTrade V2 is an Automated Market Maker (AMM) utilizing Unifi Protocol's non-custodial, interoperable smart contracts operating on multiple blockchains.  uTrade V2 is maintained by the Unifi Protocol team, and acts as a working proof-of concept trading platform for harnessing multi-chain swaps and liquidity mining to power UNIFI, Unifi’s Global Governance Token.

## What is an Automated Market Maker?

An Automated Market Maker, or AMM, is a method of pricing assets in a decentralized way algorithmically instead of an order book of buy and sell orders. In other words, there is always buy and sell orders available, allowing users to trade as close to the quoted price as liquidity will allow. Market making is present in most asset classes. However, the innovation of automated market making is particular useful in cryptocurrency trading.&#x20;

* Tokens can lack significant liquidity. Trading on a traditional exchange requires somebody willing to be on the other end of the trade. AMMs ease this by having always-available liquidity at a price determined algorithmically.&#x20;
* Decentralized AMMs allow for users to maintain custody of their funds. Centralized exchanges offer a single point of attack for hackers. With AMMs, users are able to keep the funds in their own wallets and maintain their own private keys when trading.
* Accessibility. If the liquidity is there, anybody is able to utilize it.
* Decentralized AMMs are open and trustless. Many are open-source, and allow anybody to build their own dApps, bots, and more on top of a market.
* In providing liquidity, small investors are able to generate returns previously reserved for large, highly-capitalized firms.

## How do Automated Market Makers work?

Automated Market Makers utilize a series of smart contracts to allows any user to trade, provide liquidity, or even create their own market. Automated Market Makers are generally used by two types of market participants, traders and liquidity providers.

### Traders

Traders who buy and sell cryptocurrency utilize automated market makers due to their always available liquidity, instant accessibility, open nature of verifiable on-chain trades, the ability to maintain individual custody of funds, and so much more. But how does it work under the hood? What determines the price and how is this liquidity always available?\
\
Each liquidity pool is managed by a smart contract that contains two tokens to make up a pair. The tokens are priced using a constant formula of `x * y = k`. In this equation, *x* and *y* represent a pair's reserve balances. In other words, *x* and *y* are the amount of each token in the smart contract. These change any time liquidity is utilized in a trade. However, *k*, the product of multiplying *x* and *y* remains constant during a trade. This allows for the ratio, or price, to shift dynamically based on how much liquidity is being utilized for a trade, therefore there is always liquidity available. \
\
The `x * y = k` formula dictates the ratio, or price, when trading. The greater the amount of liquidity in a pool, the less price movement that occurs during a trade. This price movement is known as slippage - the amount of difference between the current ratio or price, and the ratio or price that will be executed based on the trade size. The lower the value of the order, the less slippage a trader will incur. \
\
Let's say a liquidity pool consists of 200 USDT and 2 BNB. This sets the ratio or price at 100 USDT for 1 BNB. If Gene buys 3 USDT worth of BNB, Gene will pay very close to the 100 USDT per BNB ratio. However, if Gene buys 75 USDT of BNB, the ratio will significantly move, resulting in Gene paying far more than 100 USDT per BNB.

### Liquidity Providers

Any user is able to reap the rewards of AMMs by providing liquidity. On uTrade, these rewards are in the form of UP tokens. UP is a token backed by that blockchain's selected base token, and is the backbone of uTrade's rewards for liquidity providers. UP is redeemable at anytime for the base tokens backing it. For example, UPbnb is backed by BNB and can be redeemed for BNB instantly. There is also a secondary market on uTrade V2 to sell UP to other traders. \
\
The redeem value of UP as measured in the number of base tokens.  This redeem value can only stay the same or increase.  A portion of trading fees are used to increase the redeem value of UP each time more UP is minted.  UP is minted by fees at a rate that matches its redeem value, meaning the mint rate declines as the redeem value increases.  UP awarded to liquidity providers can be retained for time to take advantage of the rising redeem value, or redeemed for the underlying base tokens.   \
\
Now, let's say liquidity is added to a pair, how does this effect the `x + y = k` equation? \
\
The x and y values, representing the two assets that make up the liquidity pool, will be added at the current ratio or price. This in turn, adjusts the k value. For example, if x = 200 USDT and y = 2 BNB, k would equal 400. If Genette adds their liquidity of 100 USDT and 1 BNB to the pair, k would equal 900. Therefore, higher value trades will be possible without as significant price slippage. This works out well for traders as it allows them to make larger trades, and also beneficial for liquidity providers, as larger liquidity pools tend to have more of their liquidity utilized, resulting in more volume and trading fees.

\
Architecture of uTrade V2
-------------------------

uTrade V2 builds upon the Uniswap's smart contract architecture by utilizing the unique tokenomics of UNIFI and UP. For further details on each contract, as well as breakdowns of each function contained within, consult the documentation for each chain.

### Controller

The Unifi Controller is responsible for the setting the variables of UP minting on individual pairs as well as updating the redeem value of UP tokens globally.&#x20;

### ERC-20

UnifiERC20.sol essentially ports the properties of ERC-20 tokens to Unifi LP Tokens, or uTokens. An example of this in practice would be the 'approve' transaction before a token is sent.

### Factory

The uTrade V2 Factory contract creates an LP token for any pairs listed on uTrade V2, and indexes them for easy retrieval. In addition, it can return the address of the LP token based on a call of the addresses of the two tokens that make up the liquidity pool.

### Pair

UnifiPair.sol is responsible for many of the functionalities of liquidity pool tokens and UP tokens. First, it is responsible for the issuing and burning of Liquidity Pool Tokens (uTokens). In addition, it allows for direct reads of the reserves and ratio of the liquidity pool, as well as swaps. Lastly, it is where UP claims are processed.&#x20;

### Router

The uTrade V2 Router is the 'brain' of uTrade. The router finds the optimal path for exchanging one token for another. Whenever a trade is made, your wallet sends funds to the router address. The router will then carry out as many transactions as necessary to acquire the desired token. The router also handles adding liquidity to liquidity pools, and sending the corresponding LP tokens to liquidity providers.

### Single Liquidity Wrapper

Unique to uTrade, the Single Liquidity Wrapper allows one BEP-20 token to be converted into a LP pool. For example, BUSD can be added using the wrapper to supply liquidity for a BUSD / WBNB pair. The additional functionality from this wrapper simplifies applications such as compounding or fee-on-transfer additions to liquidity pools.

## Further Reading

To learn more about how liquidity rewards are calculated, view the [Liquidity Rewards Explained](https://app.gitbook.com/@unifi-protocol/s/unifi-protocol/utrade-v2/up-mint-rate-explained).\
To learn more about the individual contracts, including source code, parameters, and live addresses, navigate to the chain you wish to explore.&#x20;


# Liquidity Rewards Explained

## UP Token

Liquidity rewards are dispensed as UP tokens - a blockchain specific liquidity mining token earned by liquidity providers. Smart contract governed minting ensures once mined, UP can only go **UP** in base token redemption value. The redemption value is different on each blockchain, and is labeled by the token name. For example, UPeth is UP with an Ethereum redemption value, and UPbnb is Binance Smart Chain’s UP with a BNB redemption value.&#x20;

UP’s redemption value offers unique security and sustainability to Unifi's tokenomics. UP also includes automatic yield farming and requires no staking, which greatly reduces network fees. In addition, UP provides exclusive access to protocol specific opportunities to migration, allowing liquidity providers to earn the governance token, UNIFI.

UP is available on any chain uTrade V1 or uTrade V2 is on. Each UP has its own redemption value - you can check the current value of each on [Unifi Report](https://unifi.report/up-stats).

## Trading Fee Breakdown

uTrade V2 is unique in that 100% of the trading fees go to liquidity providers. The following represents the target percentages for the whole ecosystem. It is important to note that this is not exact, but a strong guideline. This is due to a host of factors such as when UP is claimed, rounding, as well as the amount of volume in the ecosystem. In addition, different pairs offer different incentives - some with greater rewards such as Super Pairs. \
\
The current trading fee is 0.3% on most pairs, and 0.1% on stablecoin to stablecoin pairs such as USDT/BUSD.

### Global Average Trading Fee Breakdown

| Percent of Trading Fees | Percent of Trade Value (0.3% Fee) | Percent of Trade Value (0.1% Fee) | Use                 | Description                                                           |
| ----------------------- | --------------------------------- | --------------------------------- | ------------------- | --------------------------------------------------------------------- |
| 85%                     | 0.255%                            | 0.085%                            | LP Rewards          | Minted as UP for Liquidity Providers in the pool that is traded.      |
| 10%                     | 0.03%                             | 0.01%                             | Super Pair Rewards  | Minted as UP for the UNIFI "Super Pair" as rewards for UNIFI holders. |
| 5%                      | 0.015%                            | 0.005%                            | UP Redeem Increase  | Added to UP Redeem Value                                              |
| 0%                      | 0%                                | 0%                                | Unifi Protocol Team | No developer / team fee.                                              |

### LP Rewards

85% of trading fees are minted into UP, and allocated to liquidity providers of the pool where the trade occurred. This is referred to as the **effective mint rate** - the percent of trading fees that in minted into UP and returned to liquidity providers. Liquidity providers are rewarded based on their share of the total pool. For example, if Gene holds a 40% share of a liquidity pool, Gene is entitled to 40% of the fees that liquidity providers earn.

### Super Pair Rewards

Approximately 10% of trading fees from all preferred pairs are minted into UP, and allocated to uTrade's "Super Pairs". Super Pairs are liquidity pools that are extra incentivized by receiving rewards from trades that occur on that uTrade V2 blockchain. For example, a liquidity provider for a Super Pair that is on Binance Smart Chain will receive extra UPbnb from every trade in a preferred pair that occurs on uTrade V2 BSC.   Preferred pairs are pairs that mint UP as a liquidity provider reward.&#x20;

### UP Redeem Increase

5% of all trading fees are added as a base tokens to the UP Smart Contract, which increases the redeem value of UP on every trade. The base token redeem value of UP can only increase. Additionally, this serves as a deterrent to minting attacks.  Any minting of UP tokens will result in a partial diversion of provided fees to the increase UPs redeem value.&#x20;

### Unifi Protocol Team

Absolutely 0% of all trading fees go to the Unifi Protocol Team. Unifi was developed by a team focused on finding community centered approaches to blockchain projects. When the community benefits, so does the team, and so does Unifi Protocol. This means there is no need to divert fees to the team, a treasury, or any other name some AMMs might use to disguise this fee. 100% of all trading fees are used to reward participants in the Unifi Protocol ecosystem.&#x20;

## UP Liquidity Reward Calculation + Examples

The amount of claimable UP is calculated in the following way -\
\
`Rewards = Trading Fees * LP Reward Percentage * Share of Liquidity Pool`\
`UP Claim Amount = Rewards / UP Redeem Rate`

The UP Redeem Rate that is used is the current redeemable value when the UP is claimed.&#x20;

**A)** Let's say Gene provides 100% of the total value of a liquidity pool on uTrade V2 BSC. Since adding liquidity to the pool, the liquidity pool's volume has totaled 2,000 BNB. Gene is ready to claim his rewards. At a trading fee of 0.3%, 6 BNB will have been spent on trading fees. Of that 6 BNB, approximately 5.1 BNB will spent to mint UP for LP providers, 0.6 BNB will be spent to mint UP for Super Pairs, and 0.3 BNB will be used to increase the UP redeem peg. Assuming a 10 BNB per 1 UP mint rate, Gene's claim will be for 0.51 UPbnb.&#x20;

`5.1 BNB = 6 BNB * 0.85 * 100%`\
`0.51 UP = 5.1 BNB / 10 BNB`

**B)** Let's say Genette provides 100% of the total value of a liquidity pool on uTrade V2 ETH. Genette plays it safe, and prefers stablecoin pairings due to the reduced risk of divergence loss, so they have added liquidity to a USDC / USDT pair. Stablecoins have a lower trading fee. Since adding liquidity to the pool, the liquidity pool's volume has totaled 1000 ETH. Genette says it is time to cash out! At a trading fee of 0.1%, 1 ETH will have been spent on trading fees. With an effective mint rate of 85%, 0.85 ETH will be used to mint UP for liquidity providers, 0.1 ETH will be used to mint UP for Super Pairs, and 0.05 ETH will be used to increase the redeem value of UP. Assuming an UP redeem rate of 4 ETH, Genette's claim will be for 0.2125 UPeth.

`0.85 ETH = 1 ETH * 0.85 * 100%`\
`0.2125 UP = 0.85 ETH / 4 ETH`

**C)** Let's say Genezilla provides 50% of the total value of a liquidity pool on uTrade V2 TRX. Since adding liquidity to the pool, the liquidity pool's volume has totaled 100,000 TRX. Genezilla wants those sweet rewards. At a trading fee of 0.3%, 300 TRX will have been spent on trading fees. At a rate of 85%, 255 TRX will be used to mint UP for liquidity providers, 30 TRX will be used to mint UP for Super Pairs, and 15 TRX will be used to increase the redeem value of UP. As Genezilla provides 50% of the total value of a liquidity pool, Genezilla's share of those fees is 127.5 TRX. Assuming an UP redeem rate of 15 TRX, Genezilla's claim will be for 8.5 UPtrx.

`127.5 TRX = 300 TRX * 0.85 * 50%`\
`8.5 UP = 127.5 TRX / 15 TRX`

## UNIFI Super Pairs

![The Super Pair tag indicates which pairs are indeed, super.](/files/-MbeGDzynrFkgv3E0VK2)

Super Pairs are highly incentivized liquidity pools on uTrade V2. In addition to UP liquidity provider rewards, every trade in a preferred pair on mints UP which is sent to that blockchain's Super Pair liquidity pool. In other words, Super Pairs receive a portion of trading fees from many pairs on uTrade. \
\
For example, let's say a regular pair on uTrade Binance Smart Chain earns 50 BNB in trading fees. Of that, 5 BNB will be used to mint UP for a Super Pair, and be claimable by liquidity providers of that Super Pair, as well as their usual UP liquidity provider rewards.\
\
In the future, Unifi Protocol plans to have the UNIFI token available on every blockchain uTrade V2 is on. In the event that UNIFI is not yet available on the blockchain uTrade V2 is on, the Super Pair bonuses will be stored, and retained until UNIFI is available on that chain.&#x20;

## UP Non-Mintable Pairs

An edge case occurs if two custom tokens are listed in a pool without a routing path to the base token. In this case, UP will not be minted, and instead 90% trading fees will be dispensed to the liquidity pool. Rather than UP, liquidity providers earn the tokens that make up the pool.\
\
For example, let's say two custom tokens are pooled together on Binance Smart Chain as KittyKat (KAT) Token and DoggyDog (DOG) Token, therefore creating the KAT/DOG pool. KAT and DOG have no other pools on uTrade, therefore no BNB can used to mint UP.&#x20;

The trading fee on UP Non-Mintable pairs is 0.5%, of which 90% is added to the pool reserves. Each LP token represents a share of this pool. For example, let's say a pool contains 1000 KAT and 1000 DOG. Geneasaur wants to acquire some DOG tokens and spends 100 KAT tokens to buy DOG tokens, the pool will earn 0.45 KAT Tokens in trading fees.

## Formula - A Deeper Dive

The most accurate measure of the expected LP rewards is the **effective mint rate**, which represents the percentage of total fees that are used to mint UP for liquidity providers.&#x20;

![Hover Over This Question Mark - It's like Clippy for DeFi](/files/-MbhcZvws8NDsr-RdKXj)

Each pool will display the percentage of fees that go towards the UNIFI Super Pair, the UP Redeem value, as well as to liquidity providers by hovering off the trade fee question mark on the exchange fee page. Simply enter the two tokens on the exchange tab to discover these percentages.

#### Effective Mint Rate Calculation

`(Trading Fees * Global Mint Rate % * Local Mint Rate %) / UP Redeem Rate = UP Minted`\
`UP Minted * (100% * Super Pair %) = Effective Mint Rate` \
\
\
**The current global mint rate is 95%. The local mint rate is 100%.** \
Currently, the respective opposite values of 5% and 0% are used to increase the redeem value of UP.  In other words, these values are sent to the UP Smart Contract as native currency, therefore increasing the amount of native currency backing each UP Token. Following that, UP in minted using the BNB trading fees to be claimable by Super Pairs as well as the Liquidity Providers. \
\
As an example of this in practice, let's say 10 BNB is spent in trading fees on a pair with a 10% Super Pair allocation.\
\
`10 BNB Trading Fees * 95% Global Mint Rate = 9.5 BNB` \
First, 95%, or 9.5 BNB will be used to mint UP at the global mint rate. 0.5 BNB will be used to increase the UP Redeem Value by being sent to UPbnb smart contract.\
\
`9.5 BNB / 10 BNB UP Redeem Value = 0.95 UP` \
Then 9.5 BNB will be used to mint UP at the current UP redeem value. \
Let's say the current redeem value is 10 BNB. Therefore 9.5 BNB will mint 0.95 UP.\
\
`0.95 UP - 10% Super Pair Rewards = 0.82935 LP Rewards` \
Of the UP Minted, the Super Pair will receive 10% of the minted UP, or 0.095 UP. The liquidity provider would therefore receive 0.855 UP,. Therefore, the effective mint rate is 85.5%.

## Querying the Smart Contract for Mint Rates and Super Pair Rewards

You can retrieve the effective mint rate through read functions of uTrade v2 Smart Contracts. The **effective mint rate** can be calculated as a factor of the `getMintRate` and `getPairUPFee` function of the pair from the [UnifiController.sol](/utrade-v2/binance-smart-chain/unificontroller.sol) contract.

#### Mint Rate

```
 function getMintRate(address _pool ) external view returns (uint);
```

The function `getMintRate` returns the share of trading fees that is used to Mint UP token as a percentage factor of 10,000. Therefore, if the mint rate is 95%, the uint value returned will be 9500.

&#x20;`MintRate = 9500`\
&#x20;`Fees = 100`\
&#x20;`(MintRate * Fees) / 10000 = Fees to Mint UP`\
&#x20;`(9500 * 100) / 10000 = 95 to Mint UP`

As an example, assuming a 10 BNB to 1 UP redeem value, the above would mint 9.5 UP from 95 BNB in trading fees.

#### Super Pair Rewards&#x20;

```javascript
function getPairUPFee(address _pair) external view returns(uint fees);
```

The function `getPairUPFee` returns the share of UP rewards minted by this pool to be shared with the Super Pair as percentage factor of 10,000.  The following assumes a 10% share of UP to Super Pairs.

`PairUPFee = 1000`\
`UP minted = 9.5`\
`(PairUPFee * UP minted) / 10000 = Super Pair Share of UP minted`\
`(1000 * 9.5) / 10000 = 0.95 UP to Share to Super Pair`

Therefore, the above 9.5 UP will be split with 0.95 UP going to the Super Pair, and 8.55 UP going to the liquidity provider.


# Avalanche

Here you will find in-depth detail of the contracts that make up uTrade V2 on Avalanche. Each contract includes JSONs as well as Typescript files for integration into your project. Every effort is made to open-source all aspects of uTrade V2, but some do remain private.  When a contract is available, you will find a link to the Github source code.


# singleLiquidityWrapper.sol

**Primary Uses -** Unique to uTrade, the Single Liquidity Wrapper allows AVAX or any ERC-20 token to converted into a LP pool. For example, USDT.e can be added using the wrapper to supply liquidity for a USDC.e / WAVAX 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)        | [Github](https://github.com/unifiprotocol/utrade-contracts/blob/main/Avalanche/SingleLiquidity/singleLiquidityWrapper.sol)                        |
| 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                                                                                                                      |
| ----------------- | ---------------------------------------------------------------------------------------------------------------------------- |
| Avalanche C-Chain | 0x47Def99CaCB9d954f28945729840d934835e53c2 ([Link](https://snowtrace.io/address/0x47def99cacb9d954f28945729840d934835e53c2)) |

### 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;

<table data-header-hidden><thead><tr><th>Parameter</th><th width="150">Type</th><th>Description</th></tr></thead><tbody><tr><td>Parameter</td><td>Type</td><td>Description</td></tr><tr><td><em>tokenA</em></td><td>address</td><td>The contract address of the provided token to be converted into the LP token.</td></tr><tr><td><em>requireToken</em></td><td>address</td><td>The contract address of the other token in the liquidity pool. In other words, the asset that half of <em>tokenA</em> will be converted to that will be added to the liquidity pool.</td></tr><tr><td><em>amount</em></td><td>uint</td><td>The amount of <em>tokenA</em> to be sent to the liquidity pool.</td></tr><tr><td><em>to</em></td><td>address</td><td>The recipient of the LP tokens.</td></tr><tr><td><em>minOut</em></td><td>uint</td><td>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.</td></tr></tbody></table>

### convertSingleAssetToLiquidityEth

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

The `convertSingleAssetToLiquidityETH`function converts AVAX into a LP token. It does so by first converting the provided AVAX 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 AVAX value is sent as a msg.value parameter. One of the two assets can be WAVAX.

#### Parameter Breakdown

| Parameter                                        | Type    | Description                                                                                                                                       |
| ------------------------------------------------ | ------- | ------------------------------------------------------------------------------------------------------------------------------------------------- |
| <p><em>amountIn</em><br><em>(msg.value)</em></p> | uint    | The amount of AVAX 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 AVAX  to an uTrade V2 LP token made up of two different tokens. In other words, AVAX 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 AVAX 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 AVAX 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 WAVAX'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 AVAX must be converted to WAVAX, 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 AVAX 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 WAVAX'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 AVAX must be converted to WAVAX, 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 AVAX. If true, the *receiveToken* address should be WAVAX, as it will unwrap WAVAX and send AVAX. |
| *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 AVAX 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 AVAX. If true, the *receiveToken* address should be WAVAX, as it will unwrap WAVAX and send AVAX.                                                                                                                                                                                                                                                                                                                          |
| *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 ;
}
```


# UnifiController.sol


# UnifiERC20.sol

**Primary Uses -** UnifiERC20.sol essentially ports the properties of BEP-20 tokens on to Unifi LP Tokens, or uTokens. An example of this in practice would be the 'approve' transaction.

## uTrade V2 UnifiERC20 Code / Interfaces

|                                             |                                                                                                        |
| ------------------------------------------- | ------------------------------------------------------------------------------------------------------ |
| uTrade V2 UnifiERC20 (Solidity)             | [Github](https://github.com/unifiprotocol/utrade-contracts/blob/main/Avalanche/Factory/UnifiERC20.sol) |
| uTrade V2 AVAX Interfaces in Solidity       | [Github](https://github.com/unifiprotocol/utrade-contracts/blob/main/Avalanche/Factory/interfaces.sol) |
| Import statement codeblock (when available) |                                                                                                        |

## uTrade V2 UnifiERC20 Contract Addresses

Each uTrade V2 Liquidity Pool uses the uTrade V2 ERC20 Interface in the contract.&#x20;

## Events

### Approval

```
event Approval(address indexed owner, address indexed spender, uint value);
```

The `Approval` event is emitted anytime an `approve` or `permit` function is called.

### Transfer

```
event Transfer(address indexed from, address indexed to, uint value);
```

The `Transfer` event is emitted anytime a transfer of LP tokens occurs, by the `transfer`, `transferFrom`, `mint`, or `burn` functions.

## Read-Only Functions

### name

```
function name() external pure returns (string memory);
```

The `name` function will return "Unifi LPs" for all liquidity pool contracts.

### symbol

```
function symbol() external pure returns (string memory);
```

The `symbol` function will return "Unifi-LP" for all liquidity pool contracts.

### decimals

```
function decimals() external pure returns (uint8);
```

The `decimals` function returns "18" as a uint8 value, which is the precision for each uToken on uTrade V2.

### totalSupply

```
function totalSupply() external view returns (uint);
```

The `totalSupply` function returns the total amount uTokens for a pair.

### balanceOf

```
function balanceOf(address owner) external view returns (uint);
```

The `balanceOf` function returns the balance of uTokens for the provided address.

### allowance

```
function allowance(address owner, address spender) external view returns (uint);
```

The `allowance` function returns the amount of tokens an address is approved to transfer when using the `transferFrom` function.

### DOMAIN\_SEPARATOR

```
function DOMAIN_SEPARATOR() external view returns (bytes32);
```

The `DOMAIN_SEPARATOR` function is used in the `permit` function, and is one of the components that allows transactions to get through without a prior approve transaction. Calling a read function returns the bytes32 data that is required for use in `permit` function.

### PERMIT\_TYPEHASH

```
function PERMIT_TYPEHASH() external view returns (bytes32);
```

The `PERMIT_TYPEHASH` function is used in the `permit` function, and is one of the components that allows transactions to get through without a prior approve transaction. Calling a read function returns the bytes32 data that is required for use in the `permit` function.

### nonces

```
function nonces(address owner) external view returns (uint);
```

The `nonces` function is used in the permit function. It returns the current nonce of the *address* provided.

## State-Changing Functions

### approve

```
function approve(address spender, uint value) external returns (bool);
```

The `approve` function sets a *value* for  the amount of LP tokens the *address* provided is allowed to transfer. Returns a boolean value and emits the `Approval` event.

### transfer

```
function transfer(address to, uint value) external returns (bool);
```

The `transfer` function lets an address send uTokens from one address to another, and returns a boolean value and emits a `Transfer` event.

### transferFrom

```
function transferFrom(address from, address to, uint value) external returns (bool);
```

The `transferFrom` function sends uTokens from one address to another. This requires the sending address to have approval to send uTokens. Returns a boolean value and emits a `Transfer`event.

### permit

```
function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external;
```

The permit function allows a sender to use a signature in lieu of an approval transaction, and sets the allowance for an address to send.

#### Function Parameter Breakdown

| Parameter  | Type    | Description                                                                                                                                    |
| ---------- | ------- | ---------------------------------------------------------------------------------------------------------------------------------------------- |
| *owner*    | address | The owner of the address.                                                                                                                      |
| *spender*  | address | The spender of the uTokens.                                                                                                                    |
| *value*    | uint    | The amount of uTokens to be transferred.                                                                                                       |
| *deadline* | uint    | The UNIX timestamp for which this transaction must be completed. If the transaction is mined after this deadline, the transaction will revert. |
| *v*        | uint8   | The v value of the permit. This is one of the three values that makes up the approval signature.                                               |
| *r*        | bytes32 | The r value of the permit. This is one of the three values that makes up the approval signature.                                               |
| *s*        | bytes32 | The s value of the permit. This is one of the three values that makes up the approval signature.                                               |

## Interface Code

```
interface IUnifiERC20 {
    event Approval(address indexed owner, address indexed spender, uint value);
    event Transfer(address indexed from, address indexed to, uint value);

    function name() external pure returns (string memory);
    function symbol() external pure returns (string memory);
    function decimals() external pure returns (uint8);
    function totalSupply() external view returns (uint);
    function balanceOf(address owner) external view returns (uint);
    function allowance(address owner, address spender) external view returns (uint);

    function approve(address spender, uint value) external returns (bool);
    function transfer(address to, uint value) external returns (bool);
    function transferFrom(address from, address to, uint value) external returns (bool);

    function DOMAIN_SEPARATOR() external view returns (bytes32);
    function PERMIT_TYPEHASH() external pure returns (bytes32);
    function nonces(address owner) external view returns (uint);

    function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external;
}
```


# UnifiFactory.sol

**Primary Uses** - The uTrade V2 Factory contract creates an LP token for any pairs listed on uTrade V2, and indexes them for easy retrieval. In addition, it can return the address of the LP token based on a call of the addresses of the two tokens that make up the liquidity pool.

## uTrade V2 Factory Code / Interfaces

<table data-header-hidden><thead><tr><th width="277"></th><th></th></tr></thead><tbody><tr><td></td><td></td></tr><tr><td>uTrade V2 Factory (Solidity)</td><td><a href="https://github.com/unifiprotocol/utrade-contracts/blob/main/Avalanche/Factory/UnifiFactory.sol">GitHub</a></td></tr><tr><td>uTrade V2 Factory Interface as JSON</td><td><a href="https://github.com/unifiprotocol/uTradeV2-core/blob/52d66be2a472b9697a577757a0446076b6c32001/ABI/JSON/IUnifiFactory.json">GitHub</a></td></tr><tr><td>uTrade V2 Factory Interface as Typescript</td><td><a href="https://github.com/unifiprotocol/uTradeV2-core/blob/52d66be2a472b9697a577757a0446076b6c32001/ABI/TS/IUnifiFactory.ts">GitHub</a></td></tr><tr><td>Import statement codeblock (when available)</td><td></td></tr></tbody></table>

## uTrade V2 Factory Contract Addresses

| Network           | Address                                                                                                                        |
| ----------------- | ------------------------------------------------------------------------------------------------------------------------------ |
| Avalanche C-Chain | `0x839547067bc885db205F5fA42dcFeEcDFf5A8530` ([Link](https://snowtrace.io/address/0x839547067bc885db205f5fa42dcfeecdff5a8530)) |

## Events

### PairCreated

```
event PairCreated(address indexed token0, address indexed token1, address pair, uint);
```

Anytime a pair is created on uTrade V2 using the `createPair` function, a `PairCreated` event is emitted. Contracts can be deployed to listen for new pairs on the uTrade V2 AVAX Factory address.&#x20;

* *token0* is the token address of the first asset in the token pair.
* *token1* is the token address of the second asset in the token pair.
* *pair* is the address of the newly created uTrade V2 liquidity pool.
* *uint* refers to the index of this uTrade V2 Factor&#x79;*.* For example, the first liquidity pool created on uTrade V2 is 1, the second liquidity pool is 2, and so on. This number can used with the `allPairs(uint)` to return the address. The current number, and therefore the total number of LP pools on uTrade V2 AVAX, can be accessed using the `allPairsLength` function.

## Read-Only Functions <a href="#read-only-functions" id="read-only-functions"></a>

### getPair

```
function getPair(address tokenA, address tokenB) external view returns (address pair);
```

A call to the `getPair` function returns the address of the pair for *tokenA* and *tokenB*.

* If the pair does not exist, the call will return *address(0)*.&#x20;
* The order of the tokens is irrelevant in this call. For example, a call for USDT.e, WAVAX will return the same pair address as USDT.e, WAVAX.&#x20;

### allPairs

```
function allPairs(uint) external view returns (address pair);
```

A call to the `allPairs` function returns the address of a pair based on the indexed *uint* value assigned upon creation of the LP.

* For example, `allPairs(0)` will return the first pair created on uTrade V2 AVAX.
* &#x20;If the index number is too high, as in, there aren't enough pairs created yet, the function will return *address(0)*.

### allPairsLength

```
function allPairsLength() external view returns (uint);
```

A call to the `allPairsLength` function returns the current number of pairs.&#x20;

* For example, if there are 201 total liquidity pool pairs on uTrade V2 AVAX, this call will return *200* as an uint value.

### feeTo

```
function feeTo() external view returns (address);
```

A call to the `feeTo` function returns the percentage of trading fees that Unifi Protocol receives.&#x20;

* Due to the nature of UP Token economics, this is set to zero, but is preserved for flexibility in the future.

### feeToSetter

```
function feeToSetter() external view returns (address);
```

A call to the `feeToSetter` function returns the address to which the `feeTo` would send trading fees, if trading fees were collected.

## State-Changing Functions <a href="#state-changing-functions" id="state-changing-functions"></a>

### createPair

```
function createPair(address tokenA, address tokenB) external returns (address pair);
```

Creates a liquidity pool pair for *tokenA* and *tokenB* if one does not currently exist. After the function is confirmed on chain, a `PairCreated` event is emitted.

## Interface Code

```
interface UnifiFactory {  
  event PairCreated(address indexed token0, address indexed token1, address pair, uint);
  function getPair(address tokenA, address tokenB) external view returns (address pair);  
  function allPairs(uint) external view returns (address pair);  
  function allPairsLength() external view returns (uint);
  function feeTo() external view returns (address);  function feeToSetter() external view returns (address);
  function createPair(address tokenA, address tokenB) external returns (address pair);
  }
```

###

###


# UnifiPair.sol

**Primary Uses -** UnifiPair.sol is responsible for many of the functionalities of liquidity pool tokens and UP tokens. First, it is responsible for the issuing and burning of Liquidity Pool Tokens (uTokens). In addition, it allows for direct reads of the reserves and ratio of the liquidity pool, as well as swaps. Lastly, it is where UP claims are processed.&#x20;

## uTrade V2 Pair Code / Interfaces

|                                             |                                                                                                       |
| ------------------------------------------- | ----------------------------------------------------------------------------------------------------- |
| uTrade V2 Pair (Solidity)                   | [Github](https://github.com/unifiprotocol/utrade-contracts/blob/main/Avalanche/Factory/UnifiPair.sol) |
| uTrade V2 Pair Interface as JSON            | Link Here                                                                                             |
| uTrade V2 Pair as Typescript                | Link Here                                                                                             |
| Import statement codeblock (when available) |                                                                                                       |

## uTrade V2 Pair Contract Addresses

Each uTrade V2 Liquidity Pool uses the uTrade V2 ERC20 Interface in the contract.&#x20;

## Events

### Mint

```
event Mint(address indexed sender, uint amount0, uint amount1);
```

The `Mint` event is emitted any time liquidity tokens are created via the `mint` function. In other words, when a user adds liquidity to a pair, then they will receive LP tokens, therefore the `Mint` event will be emitted.

### Burn

```
event Burn(address indexed sender, uint amount0, uint amount1, address indexed to);
```

The `Burn` event is emitted any time liquidity tokens are burned via the `burn` function. In other words, when a user removes liquidity from a pair,  their LP tokens will be burned, therefore the `Burn` event will be emitted.

### Swap

```
event Swap(
        address indexed sender,
        uint amount0In,
        uint amount1In,
        uint amount0Out,
        uint amount1Out,
        address indexed to
 );
```

The `Swap` event is emitted any time the `swap` function is used. Under the hood, all trades on uTrade V2 are swaps. Therefore, any time somebody trades on the pair, the uTrade contract for that pair will emit a `Swap` event.

### Sync

```
event Sync(uint112 reserve0, uint112 reserve1);
```

The `Sync` event is emitted anytime a function occurs that may change the reserves of a token pair. In other words, anytime the amount of the two tokens within a liquidity pool may change. Therefore, whenever a`mint`, `burn`, `swap`, or `sync` function is called, the `Sync` event will be emitted.

## Read-Only Functions

### MINIMUM\_LIQUIDITY <a href="#minimum_liquidity" id="minimum_liquidity"></a>

```
function MINIMUM_LIQUIDITY() external pure returns (uint);
```

The `MINIMUM_LIQUIDITY`function will always return 1000. The function itself refers to the burning of initial LP tokens that occurs once when a pool is created. This burn of a tiny amount allows for cleaner LP token numbers therefore avoiding LP tokens being represented as very small decimals value. This allows the tick size to be more precise and prevents rounding errors.

### factory

```
function factory() external view returns (address);
```

The `factory` function will return the current factory address for uTrade V2.

### WBNB

```
function WBNB() external view returns (address);
```

The WBNB function will return the address of WAVAX on AVAX. As this does not change, it will always return `0xb31f66aa3c1e785363f0875a1b74e27b85fd66c7`.

### token0

```
function token0() external view returns (address);
```

The `token0` function will return the contract address of the first token that makes up the liquidity pair. In other words, if the liquidity pool is made up of USDT.e / USDC.e, it will return the contract address of USDT.e.

### token1

```
function token1() external view returns (address);
```

The `token1` function will return the contract address of the first token that makes up the liquidity pair. In other words, if the liquidity pool is made up of USDT.e / USDC.e, it will return the contract address of USDC.e.

### getReserves

```
function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast);
```

The `getReserves` function returns the reserves of the two tokens that make up the liquidity pool as *reserve0* and *reserve1*. These two values can be helpful in determining the current price of each asset. The function also returns a timestamp with the block number.

### price0CumulativeLast

```
function price0CumulativeLast() external view returns (uint);
```

The `price0CumulativeLast` function is for Oracle usage on uTrade V2. The value of *token0* is captured at the end of each block, and can be called using this function to feed into an Oracle to determine a more time-weighted 'average' price.&#x20;

### price1CumulativeLast

```
function price1CumulativeLast() external view returns (uint);
```

The `price1CumulativeLast` function is for Oracle usage on uTrade V2. The value of *token1* is captured at the end of each block, and can be called using this function to feed into an Oracle to determine a more time-weighted 'average' price.&#x20;

### kLast

```
function kLast() external view returns (uint);
```

The `kLast` function returns the value of *reserve0* \* *reserve1*, after any event that may have triggered a change in the liquidity. For example, the execution of a *swap* function or a *mint* function.

## State-Changing Functions

### mint

```
function mint(address to) external returns (uint liquidity);
```

The `mint` function creates the LP tokens that represent a user's tokens in a liquidity pool. For example, if a user provides 1 AVAX and 100 USDT.e liquidity to a pool, the Unifi Pair Smart Contract will mint an amount of uAVAXUSDT.e tokens. Will emit the `Mint`, `Sync`, and `Transfer` events.

### burn

```
function burn(address to) external returns (uint amount0, uint amount1);
```

The `burn` function destroys the LP tokens that represent a user's token in a liquidity pool. For example, if a user removes 1 AVAX and 100 USDT.e liquidity to a pool, the Unifi Pair Smart Contract will burn an amount of uAVAXUSDT.e tokens. Will emit the `Burn`, `Sync`, and `Transfer` events.

### claimUP

```
function claimUP(address to) external lock returns(uint) {
```

The `claimUP` function claims any UP earned from providing liquidity if any exists, and sends the UP to the address provided.

### swap

```
function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external;
```

The `swap` function exchanges one token for another. Under the hood, all trades on uTrade V2 use this function. The *calldata* must be 0 during a normal swap, but must contain data if executing a flash loan. Emits the `Swap` and `Sync` events.

### skim

```
function skim(address to) external;
```

The `skim` function operates as a safeguard if the amount of tokens causes a data error due to too large of a number in the reserves pools. In this unusual circumstance, this will trigger failures in trades. The `skim` function can be called to return the overflowed tokens to the caller.

### sync

```
function sync() external;
```

The `sync` function operates as a safeguard in certain events where the token balance changes outside of normal trading. An example would be an algorithmic stablecoin re-balancing, therefore lowering or raising the amount of the algorithmic stablecoin in the pool. The `sync` function may be called to reset the price ratio to the new reserves. Emits the `Sync`event.

## Interface Code

```
interface IUnifiPair {
    event Mint(address indexed sender, uint amount0, uint amount1);
    event Burn(address indexed sender, uint amount0, uint amount1, address indexed to);
    event Swap(
        address indexed sender,
        uint amount0In,
        uint amount1In,
        uint amount0Out,
        uint amount1Out,
        address indexed to
    );
    event Sync(uint112 reserve0, uint112 reserve1);

    function MINIMUM_LIQUIDITY() external pure returns (uint);
    function factory() external view returns (address);
    function token0() external view returns (address);
    function token1() external view returns (address);
    function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast);
    function price0CumulativeLast() external view returns (uint);
    function price1CumulativeLast() external view returns (uint);
    function kLast() external view returns (uint);

    function mint(address to) external returns (uint liquidity);
    function burn(address to) external returns (uint amount0, uint amount1);
    function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external;
    function skim(address to) external;
    function sync() external;

    function initialize(address, address) external;
}
```


# UnifiRouter.sol

**Primary Uses** - The uTrade V2 Router is the 'brain' of uTrade. The router finds the optimal path for exchanging one token for another. Whenever a trade is made, your wallet sends funds to the router address. The router will then carry out as many transactions as necessary to acquire the desired token. The router also handles adding liquidity to liquidity pools, and sending the corresponding LP tokens to liquidity providers.

## uTrade V2 Router Code / Interfaces

|                                             |                                                                                                                                   |
| ------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------- |
| uTrade V2 Router (Solidity)                 | [Github](https://github.com/unifiprotocol/utrade-contracts/blob/main/Avalanche/Router/router.sol)                                 |
| uTrade V2 Router Interface as JSON          | [GitHub](https://github.com/unifiprotocol/uTradeV2-core/blob/52d66be2a472b9697a577757a0446076b6c32001/ABI/JSON/IUnifiRouter.json) |
| uTrade V2 Router Interface as Typescript    | [GitHub](https://github.com/unifiprotocol/uTradeV2-core/blob/52d66be2a472b9697a577757a0446076b6c32001/ABI/TS/IUnifiRouter.ts)     |
| Import statement codeblock (when available) |                                                                                                                                   |

## uTrade V2 Router Contract Addresses

| Network           | Address                                                                                 |
| ----------------- | --------------------------------------------------------------------------------------- |
| Avalanche C-Chain | `0xBd562d5cF2c62Da3143D862aF39eDb6dF59A4679`([Link](#utrade-v2-router-code-interfaces)) |
|                   |                                                                                         |

### factory

```
function factory() external pure returns (address);
```

A call to the `factory` function returns the address of the current Factory used by uTrade v2. The current factory address for uTrade V2 on Avalanche is `0x839547067bc885db205F5fA42dcFeEcDFf5A8530`.

### WETH

```
function WETH() external pure returns (address);
```

A call to the `WETH` function returns the address of Wrapped AVAX (WAVAX) on Avalanche. As this address does not change, it will always return `0xb31f66aa3c1e785363f0875a1b74e27b85fd66c7`.

### quote

```
function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB);
```

A call to the `quote` function returns the amount of *tokenB* that will be received for an amount of *tokenA*. This can be used to calculate the exchange rate between two tokens without factoring in slippage or fees. By entering the amount of *tokenA,* the total amount of reserves of *tokenA* as *reserveA,* and the total amount of reserves of *tokenB* as *reserveB*, the call will return the equivalent amount of *tokenB*.

### getAmountOut

```
function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut, uint fee) external pure returns (uint amountOut);
```

A call to the `getAmountOut`function with the amount of the token being sent will return the maximum amount of a token to be received, accounting for fees and the total amount of reserves.

### getAmountIn

```
function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut, uint fee) external pure returns (uint amountIn);
```

A call to the `getAmountIn` function with the amount of the token you wish to receive will return the minimum amount required of the token you wish to send, accounting for fees and the total amount of reserves.

### getAmountsOut

```
function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts);
```

A call to the `getAmountsOut` function with the amount of the token being sent will return the maximum amount to be received of multiple different tokens. By entering multiple LP addresses in the *address* array, the function will return the maximum amount of each token that will be received. A call to this function uses the `getReserves` function from [UnifiPair.sol ](https://docs.unifiprotocol.com/utrade-v2/avalanche/unifipair.sol)to determine the reserves of the liquidity pool. Then, it calls the `getAmountOut` function to determine the amount of each token in the array that will be received for the *amountIn* value of a token.

### getAmountsIn <a href="#getamountsin" id="getamountsin"></a>

```
function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts);
```

A call to the `getAmountsIn` function with the desired amount of the token to be received will return the minimum amount required to be sent of multiple tokens. By entering multiple LP addresses in the *address* array, the function will return the minimum amount of each token that will need to be sent to receive the desired amount of a token. A call to this function uses the `getReserves` function from [UnifiPair.sol](https://docs.unifiprotocol.com/utrade-v2/avalanche/unifipair.sol) to determine the reserves of the liquidity pool. Then, it calls the `getAmountIn` function to determine the amount of each token in the array that will need to be sent for the *amountOut* value of a token.&#x20;

## State-Changing Functions - Liquidity <a href="#state-changing-functions" id="state-changing-functions"></a>

### addLiquidity

```
function addLiquidity(
        address tokenA,
        address tokenB,
        uint amountADesired,
        uint amountBDesired,
        uint amountAMin,
        uint amountBMin,
        address to,
        uint deadline
) external returns (uint amountA, uint amountB, uint liquidity);
```

The `addLiquidity` function adds the two tokens that make up the liquidity pool - *tokenA* and *tokenB* - at the proper ratio based on the reserves of the pool. For example, if the pool contains 500 USDT.e / 2 AVAX, a user's liquidity will be added at the ratio of 250 USDT.e to 1 AVAX, provided there is no price movements in the pair between when the user broadcasts the transaction to when it is mined. In the event of a price movement, the *amountADesired*, *amountBDesired*, *amountAMin*, and *amountBMin* act as a security measure against an adverse price movement. After the liquidity is added, the function sends the corresponding LP tokens to the sender.

In the case of a pool not existing for the two assets, one will be created using [UnifiFactory.sol](https://app.gitbook.com/@unifi-protocol/s/unifi-protocol/utrade-v2/binance-smart-chain/utrade-v2-factory) at the ratio of the assets supplied.

#### Function Parameters Breakdown

| Parameter        | Type    | Description                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          |
| ---------------- | ------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| *tokenA*         | address | Token address of the first asset in the token pair.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  |
| *tokenB*         | address | Token address of the second asset in the token pair.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 |
| *amountADesired* | uint    | The amount of *tokenA* to be added to liquidity if the value of *tokenA* goes down in comparison to *tokenB*.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        |
| *amountBDesired* | uint    | The amount of *tokenB* to be added to liquidity if the value of *tokenB* goes down in comparison to *tokenA.*                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        |
| *amountAMin*     | uint    | <p>Sets the minimum amount of <em>tokenA</em> that can added to the pool before the transaction reverts. This acts as a safeguard. <br></p><ul><li>If the value of <em>tokenA</em> rapidly increases in comparison to <em>tokenB</em>, the user will require less of <em>tokenA</em> to be added to the pool to maintain the original value of the submitted liquidity.</li><li>A user could potentially be adding liquidity during an outlier spike in value. If the amount of <em>tokenA</em> required falls below this value, the transaction will revert.</li><li>This value must be less than or equal to <em>amountADesired</em>.</li></ul>    |
| *amountBMin*     | uint    | <p>Sets the minimum amount of <em>tokenB</em> that can added to the pool before the transaction reverts. This acts as a safeguard.</p><p></p><ul><li>If the value of <em>tokenB</em> rapidly increases in comparison to <em>tokenA</em>, the user will require less of <em>tokenB</em> to be added to the pool to maintain the original value of the submitted liquidity.</li><li> A user could potentially be adding liquidity during an outlier spike in value. If the amount of <em>tokenB</em> required falls below this value, the transaction will revert.</li><li>This value must be less than or equal to <em>amountBDesired</em>.</li></ul> |
| *to*             | address | The address to which the LP tokens for the uTrade V2 pool will be sent.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              |
| *deadline*       | uint    | The UNIX timestamp for which this transaction must be completed. If the transaction is mined after this deadline, the transaction will revert.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       |

#### Function Return Parameter Breakdown

| Parameter   | Type | Description                                                                                                |
| ----------- | ---- | ---------------------------------------------------------------------------------------------------------- |
| *amountA*   | uint | The exact amount of *tokenA* that was sent to the pool.                                                    |
| *amountB*   | uint | The exact amount of *tokenB* that was sent to the pool.                                                    |
| *liquidity* | uint | The exact amount of liquidity tokens minted and sent to the address provided in the *to* paramete&#x72;*.* |

### addLiquidityETH

```
function addLiquidityETH(
        address token,
        uint amountTokenDesired,
        uint amountTokenMin,
        uint amountETHMin,
        address to,
        uint deadline
    ) external payable returns (uint amountToken, uint amountETH, uint liquidity);
```

The `addLiquidityEth` function is similar to the `addLiquidity` function except it accounts for one token being a native asset. In the case of Avalanche, this native asset would be AVAX. This function will convert AVAX to WAVAX, will pair that WAVAX with the supplied other token, and add the liquidity to the pool. This function will add at the ideal ratio based on when the transaction is mined.\
\
In the case of a pool not existing for AVAX and the token provided, one will be created using [UnifiFactory.sol](https://docs.unifiprotocol.com/utrade-v2/avalanche/unififactory.sol) at the ratio of the assets supplied.

* This function requires a *msg.value* with the amount of AVAX to be added.&#x20;
  * The *msg.value* acts as the amountETHDesired. As in, if the ratio between AVAX and the token being paired with it change, this is the number of AVAX that will be added to the pool.
  * Any leftover AVAX is returned to the *msg.sender* address.

#### Function Parameter Breakdown

| Parameter                      | Type    | Description                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  |
| ------------------------------ | ------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| *token*                        | address | The address of the supplied token for the liquidity pool. In other words, the asset that AVAX is paired with.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                |
| *amountTokenDesired*           | uint    | The amount of the supplied token to be added to liquidity if the value of token goes down in comparison to AVAX.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             |
| (*amountETHDesired*) msg.value | uint    | Sent as the msg.value, the amount of AVAX to be added to liquidity if the value of AVAX goes down in comparison to token.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    |
| *amountTokenMin*               | uint    | <p>Sets the minimum amount of the supplied token that can added to the pool before the transaction reverts. This acts as a safeguard. </p><p></p><ul><li>If the value of supplied token rapidly increases in comparison to AVAX, the user will require less of the token to be added to the pool to maintain the original value of the submitted liquidity.</li><li>A user could potentially be adding liquidity during an outlier spike in value. If the amount of the supplied token required falls below this value, the transaction will revert.</li><li>This value must be less than or equal to <em>amountTokenDesired</em>.</li></ul> |
| *amountETHMin*                 | uint    | <p></p><p>Sets the minimum amount of AVAX that can added to the pool before the transaction reverts. This acts as a safeguard. </p><p></p><ul><li>If the value of AVAX increases in comparison to the supplied token, the user will require less AVAX to be added to the pool to maintain the original value of the submitted liquidity.</li><li>A user could potentially be adding liquidity during an outlier spike in value. If the amount of AVAX required falls below this value, the transaction will revert.</li><li>This value must be less than or equal to <em>amountETHDesired</em>.</li></ul>                                    |
| *to*                           | address | The address to which the LP tokens for the uTrade V2 pool will be sent.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      |
| *deadline*                     | uint    | The UNIX timestamp for which this transaction must be completed. If the transaction is mined after this deadline, the transaction will revert.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               |

#### Function Return Parameter Breakdown

| Parameter     | Type | Description                                                                                                |
| ------------- | ---- | ---------------------------------------------------------------------------------------------------------- |
| *amountToken* | uint | The exact amount of the supplied token sent to the pool.                                                   |
| *amountETH*   | uint | The exact amount of AVAX converted to WAVAX, and then added to the pool.                                   |
| *liquidity*   | uint | The exact amount of liquidity tokens minted and sent to the address provided in the *to* paramete&#x72;*.* |

### removeLiquidity

```
function removeLiquidity(
        address tokenA,
        address tokenB,
        uint liquidity,
        uint amountAMin,
        uint amountBMin,
        address to,
        uint deadline
) external returns (uint amountA, uint amountB);
```

The `removeLiquidity` function removes the two tokens that make up liquidity from a pool. In other words, this function is used when the pool consists of two ERC-20 tokens.

* In the event one of the assets is paired with AVAX, AVAX will have been wrapped and paired with WAVAX (Wrapped AVAX). If the user wishes to withdraw WAVAX instead of withdrawing as AVAX, this function should be used instead of `removeLiquidityETH` .

#### Function Parameter Breakdown

| Parameter    | Type    | Description                                                                                                                                                                                                              |
| ------------ | ------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| *tokenA*     | address | Token address of the first asset in the pair.                                                                                                                                                                            |
| *tokenB*     | address | Token address of the second asset in the pair.                                                                                                                                                                           |
| *liquidity*  | uint    | The amount of liquidity tokens to be redeemed and removed.                                                                                                                                                               |
| *amountAMin* | uint    | Sets the minimum amount of *tokenA* to be removed from the the pool. This acts as a safeguard against removing liquidity during a spike in value. If the removed amount falls below this value, the transaction reverts. |
| *amountBMin* | uint    | Sets the minimum amount of *tokenB* to be removed from the the pool. This acts as a safeguard against removing liquidity during a spike in value. If the removed amount falls below this value, the transaction reverts. |
| *to*         | address | The address to where the redeemed tokens will be sent.                                                                                                                                                                   |
| *deadline*   | uint    | The UNIX timestamp for which this transaction must be completed. If the transaction is mined after this deadline, the transaction will revert.                                                                           |

#### Function Return Parameter Breakdown

| Parameter | Title | Description                                                                      |
| --------- | ----- | -------------------------------------------------------------------------------- |
| *amountA* | uint  | The exact amount of *tokenA* sent to the address provided in the *to* parameter. |
| *amountB* | uint  | The exact amount of *tokenB* sent to the address provided in the *to* parameter. |

### removeLiquidityETH

```
function removeLiquidityETH(
        address token,
        uint liquidity,
        uint amountTokenMin,
        uint amountETHMin,
        address to,
        uint deadline
) external returns (uint amountToken, uint amountETH);
```

The `removeLiquidityETH` function removes AVAX as well as the corresponding paired token in the liquidity pool. In other words, this function is used when the pool consists of WAVAX and a ERC-20 token.

* In the event one of the assets is paired with AVAX, AVAX has been wrapped into WAVAX (Wrapped AVAX). This function will unwrap the WAVAX as the liquidity removed. If the user wishes to withdraw WAVAX instead of withdrawing as AVAX, the `removeLiquidity` function should be used.

#### Function Parameter Breakdown

| Parameter        | Type    | Description                                                                                                                                                                                                             |
| ---------------- | ------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| *token*          | address | Token address of the ERC-20 asset in the pair.                                                                                                                                                                          |
| *liquidity*      | uint    | The amount of liquidity tokens to be redeemed and removed.                                                                                                                                                              |
| *amountTokenMin* | uint    | Sets the minimum amount of *token* to be removed from the the pool. This acts as a safeguard against removing liquidity during a spike in value. If the removed amount falls below this value, the transaction reverts. |
| *amountETHMin*   | uint    | Sets the minimum amount of AVAX to be removed from the the pool. This acts as a safeguard against removing liquidity during a spike in value. If the removed amount falls below this value, the transaction reverts.    |
| *to*             | address | The address to where AVAX and token will be sent.                                                                                                                                                                       |
| *deadline*       | uint    | The UNIX timestamp for which this transaction must be completed. If the transaction is mined after this deadline, the transaction will revert.                                                                          |

#### Function Return Parameter Breakdown

| Parameter     | Value | Description                                                                     |
| ------------- | ----- | ------------------------------------------------------------------------------- |
| *amountToken* | uint  | The exact amount of *token* sent to the address provided in the *to* parameter. |
| *amountETH*   | uint  | The exact amount of AVAX sent to the address provided in the *to* parameter.    |

### removeLiquidityWithPermit

```
function removeLiquidityWithPermit(
        address tokenA,
        address tokenB,
        uint liquidity,
        uint amountAMin,
        uint amountBMin,
        address to,
        uint deadline,
        bool approveMax, uint8 v, bytes32 r, bytes32 s
) external returns (uint amountA, uint amountB);
```

The `removeLiquidityWithPermit` functions removes the two tokens that make up liquidity from a pool. In other words, this function is used when the pool consists of two ERC-20 tokens. This function operates similarly to the `removeLiquidity` function with the added benefit of not requiring pre-approvals using [permit function](https://docs.unifiprotocol.com/utrade-v2/avalanche/unifierc20.sol) from the ERC-20 contract.

* In the event one of the assets is paired with AVAX, AVAX will have been wrapped and paired with WAVAX (Wrapped AVAX). If the user wishes to withdraw WAVAX instead of withdrawing as AVAX, this function should be used instead of `removeLiquidityETHWithPermit` .

#### Function Parameter Breakdown

| Parameter    | Type    | Description                                                                                                                                                                                                              |
| ------------ | ------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| *tokenA*     | address | Token address of the first asset in the pair.                                                                                                                                                                            |
| *tokenB*     | address | Token address of the second asset in the pair.                                                                                                                                                                           |
| *liquidity*  | uint    | The amount of liquidity tokens to be redeemed and removed.                                                                                                                                                               |
| *amountAMin* | uint    | Sets the minimum amount of *tokenA* to be removed from the the pool. This acts as a safeguard against removing liquidity during a spike in value. If the removed amount falls below this value, the transaction reverts. |
| *amountBMin* | uint    | Sets the minimum amount of *tokenB* to be removed from the the pool. This acts as a safeguard against removing liquidity during a spike in value. If the removed amount falls below this value, the transaction reverts. |
| *to*         | address | The address to where the redeemed tokens will be sent.                                                                                                                                                                   |
| *deadline*   | uint    | The UNIX timestamp for which this transaction must be completed. If the transaction is mined after this deadline, the transaction will revert.                                                                           |
| *approveMax* | bool    | Sets a true or false value on if approval amount in the signature is for liquidity or for uint(-1).                                                                                                                      |
| *v*          | uint8   | The v value of the permit. This is one of the three values that makes up the approval signature.                                                                                                                         |
| *r*          | bytes32 | The r value of the permit. This is one of the three values that makes up the approval signature.                                                                                                                         |
| *s*          | bytes32 | The s value of the permit. This is one of the three values that makes up the approval signature.                                                                                                                         |

#### Function Return Parameter Breakdown

| Parameter | Title | Description                                                                      |
| --------- | ----- | -------------------------------------------------------------------------------- |
| *amountA* | uint  | The exact amount of *tokenA* sent to the address provided in the *to* parameter. |
| *amountB* | uint  | The exact amount of *tokenB* sent to the address provided in the *to* parameter. |

### removeLiquidityETHWithPermit

```
function removeLiquidityETHWithPermit(
        address token,
        uint liquidity,
        uint amountTokenMin,
        uint amountETHMin,
        address to,
        uint deadline,
        bool approveMax, uint8 v, bytes32 r, bytes32 s
) external returns (uint amountToken, uint amountETH);
    
```

The `removeLiquidityETHWithPermit` function removes AVAX as well as the corresponding paired token in the liquidity pool. In other words, this function is used when the pool consists of WAVAX and a ERC-20 token. This function operates similarly to the `removeLiquidityETH`function with the added benefit of not requiring pre-approvals using [permit function](https://docs.unifiprotocol.com/utrade-v2/avalanche/unifierc20.sol) from the ERC-20 contract.

* In the event one of the assets is paired with AVAX, AVAX has been wrapped into WAVAX (Wrapped AVAX). This function will unwrap the WAVAX as the liquidity removed. If the user wishes to withdraw AVAX instead of withdrawing as AVAX, the `removeLiquidityWithPermit` function should be used.

#### Function Parameter Breakdown

| Parameter        | Type    | Description                                                                                                                                                                                                             |
| ---------------- | ------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| *token*          | address | Token address of the ERC-20 asset in the pair.                                                                                                                                                                          |
| *liquidity*      | uint    | The amount of liquidity tokens to be redeemed and removed.                                                                                                                                                              |
| *amountTokenMin* | uint    | Sets the minimum amount of *token* to be removed from the the pool. This acts as a safeguard against removing liquidity during a spike in value. If the removed amount falls below this value, the transaction reverts. |
| *amountETHMin*   | uint    | Sets the minimum amount of AVAX to be removed from the the pool. This acts as a safeguard against removing liquidity during a spike in value. If the removed amount falls below this value, the transaction reverts.    |
| *to*             | address | The address to where AVAX and token will be sent.                                                                                                                                                                       |
| *deadline*       | uint    | The UNIX timestamp for which this transaction must be completed. If the transaction is mined after this deadline, the transaction will revert.                                                                          |
| *v*              | uint8   | The v value of the permit. This is one of the three values that makes up the approval signature.                                                                                                                        |
| *r*              | bytes32 | The r value of the permit. This is one of the three values that makes up the approval signature.                                                                                                                        |
| *s*              | bytes32 | The s value of the permit. This is one of the three values that makes up the approval signature.                                                                                                                        |

#### Function Return Parameter Breakdown

| Parameter     | Value | Description                                                                     |
| ------------- | ----- | ------------------------------------------------------------------------------- |
| *amountToken* | uint  | The exact amount of *token* sent to the address provided in the *to* parameter. |
| *amountETH*   | uint  | The exact amount of AVAX sent to the address provided in the *to* parameter.    |

### removeLiquidityETHSupportingFeeOnTransferTokens

```
function removeLiquidityETHSupportingFeeOnTransferTokens(
        address token,
        uint liquidity,
        uint amountTokenMin,
        uint amountETHMin,
        address to,
        uint deadline
) external returns (uint amountETH);
```

The `removeLiquidityETHSupportingFeeOnTransferTokens`function is similar to the `removeLiquidityETH` function, and contains the same call parameters. This function removes AVAX as well as the corresponding paired token in the liquidity pool. In other words, this function is used when the pool consists of WAVAX and a ERC-20 token.&#x20;

However, this function allows for fee on transfer tokens, such as PAXG, to be used on uTrade.&#x20;

#### Function Parameter Breakdown

| Parameter        | Type    | Description                                                                                                                                                                                                             |
| ---------------- | ------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| *token*          | address | Token address of the ERC-20 asset in the pair.                                                                                                                                                                          |
| *liquidity*      | uint    | The amount of liquidity tokens to be redeemed and removed.                                                                                                                                                              |
| *amountTokenMin* | uint    | Sets the minimum amount of *token* to be removed from the the pool. This acts as a safeguard against removing liquidity during a spike in value. If the removed amount falls below this value, the transaction reverts. |
| *amountETHMin*   | uint    | Sets the minimum amount of AVAX to be removed from the the pool. This acts as a safeguard against removing liquidity during a spike in value. If the removed amount falls below this value, the transaction reverts.    |
| *to*             | address | The address to where AVAX and the paired token will be sent.                                                                                                                                                            |
| *deadline*       | uint    | The UNIX timestamp for which this transaction must be completed. If the transaction is mined after this deadline, the transaction will revert.                                                                          |

#### Function Return Parameter Breakdown

| Parameter   | Value | Description                                                                                                                                                                                                                    |
| ----------- | ----- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| *amountETH* | uint  | The exact amount of AVAX sent to the address provided in the *to* parameter. Note that the *amountToken* parameter is not returned. The amount of fee on transfer that a token may have is not available prior to transaction. |

### removeLiquidityETHWithPermitSupportingFeeOnTransferTokens

```
function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens(
        address token,
        uint liquidity,
        uint amountTokenMin,
        uint amountETHMin,
        address to,
        uint deadline,
        bool approveMax, uint8 v, bytes32 r, bytes32 s
) external returns (uint amountETH);
```

The `removeLiquidityETHWithPermitSupportingFeeOnTransferTokens`function is similar to the `removeLiquidityETHWithPermit`function. This function removes AVAX as well as the corresponding paired token in the liquidity pool. In other words, this function is used when the pool consists of WVAX and a ERC-20 token. This function operates similarly to the `removeLiquidityETHfunction` with the added benefit of not requiring pre-approvals using [permit function](https://docs.unifiprotocol.com/utrade-v2/avalanche/unifierc20.sol) from the ERC-20 contract. In addition, this function allows for fee on transfer tokens, such as PAXG, to be used on uTrade.&#x20;

#### Function Parameter Breakdown

| Parameter        | Type    | Description                                                                                                                                                                                                             |
| ---------------- | ------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| *token*          | address | Token address of the ERC-20 asset in the pair.                                                                                                                                                                          |
| *liquidity*      | uint    | The amount of liquidity tokens to be redeemed and removed.                                                                                                                                                              |
| *amountTokenMin* | uint    | Sets the minimum amount of *token* to be removed from the the pool. This acts as a safeguard against removing liquidity during a spike in value. If the removed amount falls below this value, the transaction reverts. |
| *amountETHMin*   | uint    | Sets the minimum amount of AVAX to be removed from the the pool. This acts as a safeguard against removing liquidity during a spike in value. If the removed amount falls below this value, the transaction reverts.    |
| *to*             | address | The address to where AVAX and token will be sent.                                                                                                                                                                       |
| *deadline*       | uint    | The UNIX timestamp for which this transaction must be completed. If the transaction is mined after this deadline, the transaction will revert.                                                                          |
| *v*              | uint8   | The v value of the permit. This is one of the three values that makes up the approval signature.                                                                                                                        |
| *r*              | bytes32 | The r value of the permit. This is one of the three values that makes up the approval signature.                                                                                                                        |
| *s*              | bytes32 | The s value of the permit. This is one of the three values that makes up the approval signature.                                                                                                                        |

#### Function Return Parameter Breakdown

| Parameter   | Value | Description                                                                                                                                                                                                                    |
| ----------- | ----- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| *amountETH* | uint  | The exact amount of AVAX sent to the address provided in the *to* parameter. Note that the *amountToken* parameter is not returned. The amount of fee on transfer that a token may have is not available prior to transaction. |

## State-Changing Functions - Swap

### swapExactTokensForTokens

```
function swapExactTokensForTokens(
        uint amountIn,
        uint amountOutMin,
        address[] calldata path,
        address to,
        uint deadline
) external returns (uint[] memory amounts);
```

The `swapExactTokensForTokens` function sends an exact amount of tokens for the maximum amount of another token.&#x20;

#### Function Parameter Breakdown

| Parameter      | Type                | Description                                                                                                                                                                                                                                                                                                                                                                                                                            |
| -------------- | ------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| *amountIn*     | uint                | The amount of tokens being sent to swap into another token                                                                                                                                                                                                                                                                                                                                                                             |
| *amountOutMin* | uint                | Sets the minimum amount of the desired token to receive. This acts as a safeguard against removing liquidity during a spike in value. If the amount to be received falls below this value, the transaction reverts.                                                                                                                                                                                                                    |
| *path*         | address\[] calldata | <p>The pathway to change one token to another, consisting of an array of addresses. Each token must have an existing liquidity pool, as well as have liquidity.<br></p><p>The <em>path</em> represents the pathway from one token to another. If a pair exists for the two tokens you wish to exchange, this will contain two values inside of an array. However, if there is no direct pair, multiple addresses may be required. </p> |
| *to*           | address             | The address to where the desired token will be sent.                                                                                                                                                                                                                                                                                                                                                                                   |
| *deadline*     | uint                | The UNIX timestamp for which this transaction must be completed. If the transaction is mined after this deadline, the transaction will revert.                                                                                                                                                                                                                                                                                         |

#### Function Return Parameter Breakdown

| Parameter | Type           | Description                                                                                                |
| --------- | -------------- | ---------------------------------------------------------------------------------------------------------- |
| *amounts* | uint\[] memory | The exact amount of tokens sent into the swap, as well as the exact return amount of all subsequent swaps. |

### swapTokensForExactTokens

```
function swapTokensForExactTokens(
        uint amountOut,
        uint amountInMax,
        address[] calldata path,
        address to,
        uint deadline
) external returns (uint[] memory amounts);
```

The `swapTokensForExactTokens` function sends the minimum amount of tokens for the exact amount of another token.&#x20;

#### Function Parameter Breakdown

| Parameter     | Type                | Description                                                                                                                                                                                                                                                                                                                                                                                                                            |
| ------------- | ------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| *amountOut*   | uint                | The exact amount of the desired tokens to be received.                                                                                                                                                                                                                                                                                                                                                                                 |
| *amountInMax* | uint                | Sets the maximum amount of token to be sent in. This acts as a safeguard against removing liquidity during a spike in value. If the amount to be sent rises above this value, the transaction reverts.                                                                                                                                                                                                                                 |
| *path*        | address\[] calldata | <p>The pathway to change one token to another, consisting of an array of addresses. Each token must have an existing liquidity pool, as well as have liquidity.<br></p><p>The <em>path</em> represents the pathway from one token to another. If a pair exists for the two tokens you wish to exchange, this will contain two values inside of an array. However, if there is no direct pair, multiple addresses may be required. </p> |
| *to*          | address             | The address to where the desired token will be sent.                                                                                                                                                                                                                                                                                                                                                                                   |
| *deadline*    | uint                | The UNIX timestamp for which this transaction must be completed. If the transaction is mined after this deadline, the transaction will revert.                                                                                                                                                                                                                                                                                         |

#### Function Return Parameter Breakdown

| Parameter | Type           | Description                                                                                                |
| --------- | -------------- | ---------------------------------------------------------------------------------------------------------- |
| *amounts* | uint\[] memory | The exact amount of tokens sent into the swap, as well as the exact return amount of all subsequent swaps. |

### swapExactETHForTokens

```
function swapExactETHForTokens(
        uint amountOutMin, 
        address[] calldata path, 
        address to, 
        uint deadline)
        external
        payable
returns (uint[] memory amounts);
```

The `swapExactETHForTokens` function sends an exact amount of AVAX for a desired token.

#### Function Parameter Breakdown

| Parameter                                           | Type                | Description                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       |
| --------------------------------------------------- | ------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| <p><em>(amountIn)</em></p><p><em>msg.value</em></p> | uint                | Sent as the msg.value, the amount of AVAX to be swapped.                                                                                                                                                                                                                                                                                                                                                                                                                                                                          |
| *amountOutMin*                                      | uint                | Sets the minimum amount of the desired token to receive. This acts as a safeguard against removing liquidity during a spike in value. If the amount to be received falls below this value, the transaction reverts.                                                                                                                                                                                                                                                                                                               |
| *path*                                              | address\[] calldata | <p>The pathway to change one token to another, consisting of an array of addresses. Each token must have an existing liquidity pool, as well as have liquidity.<br></p><p>The <em>path</em> represents the pathway from one token to another. If a pair exists for the two tokens you wish to exchange, this will contain two values inside of an array. However, if there is no direct pair, multiple addresses may be required. </p><p></p><p>As the first swap is swapping AVAX to WAVAX, the first address must be WAVAX.</p> |
| *to*                                                | address             | The address to where the desired token will be sent.                                                                                                                                                                                                                                                                                                                                                                                                                                                                              |
| *deadline*                                          | uint                | The UNIX timestamp for which this transaction must be completed. If the transaction is mined after this deadline, the transaction will revert.                                                                                                                                                                                                                                                                                                                                                                                    |

#### Function Return Parameter Breakdown

| Parameter | Type           | Description                                                                                              |
| --------- | -------------- | -------------------------------------------------------------------------------------------------------- |
| *amounts* | uint\[] memory | The exact amount of AVAX sent into the swap, as well as the exact return amount of all subsequent swaps. |

### swapTokensForExactETH

```
function swapTokensForExactETH(
        uint amountOut, 
        uint amountInMax, 
        address[] calldata path, 
        address to, 
        uint deadline)
        external
        returns (uint[] memory amounts);
```

The `swapTokensForExactETH` function sends an amount of tokens for an exact amount of AVAX.

#### Function Parameter Breakdown

| Parameter     | Type                | Description                                                                                                                                                                                                                                                                                                                                                                                                                            |
| ------------- | ------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| *amountOut*   | uint                | The exact amount of the AVAX to be received.                                                                                                                                                                                                                                                                                                                                                                                           |
| *amountInMax* | uint                | Sets the maximum amount of token to be sent in. This acts as a safeguard against removing liquidity during a spike in value. If the amount to be sent rises above this value, the transaction reverts.                                                                                                                                                                                                                                 |
| *path*        | address\[] calldata | <p>The pathway to change one token to another, consisting of an array of addresses. Each token must have an existing liquidity pool, as well as have liquidity.<br></p><p>The <em>path</em> represents the pathway from one token to another. If a pair exists for the two tokens you wish to exchange, this will contain two values inside of an array. However, if there is no direct pair, multiple addresses may be required. </p> |
| *to*          | address             | The address to where the desired token will be sent.                                                                                                                                                                                                                                                                                                                                                                                   |
| *deadline*    | uint                | The UNIX timestamp for which this transaction must be completed. If the transaction is mined after this deadline, the transaction will revert.                                                                                                                                                                                                                                                                                         |

#### Function Return Parameter Breakdown

| Parameter | Type           | Description                                                                                         |
| --------- | -------------- | --------------------------------------------------------------------------------------------------- |
| *amounts* | uint\[] memory | The exact amount of tokens sent into the swap, as well as the exact amount of all subsequent swaps. |

### swapExactTokensForETH

```
function swapExactTokensForETH(
        uint amountIn, 
        uint amountOutMin, 
        address[] calldata path, 
        address to, 
        uint deadline)
        external
        returns (uint[] memory amounts);
```

The `swapExactTokensForETH` function sends an exact amount of tokens for AVAX.

#### Function Parameter Breakdown

| Parameter      | Type                | Description                                                                                                                                                                                                                                                                                                                                                                                                                            |
| -------------- | ------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| *amountIn*     | uint                | The amount of tokens being sent to swap into AVAX.                                                                                                                                                                                                                                                                                                                                                                                     |
| *amountOutMin* | uint                | Sets the minimum amount of the AVAX to receive. This acts as a safeguard against removing liquidity during a spike in value. If the amount to be received falls below this value, the transaction reverts.                                                                                                                                                                                                                             |
| *path*         | address\[] calldata | <p>The pathway to change one token to another, consisting of an array of addresses. Each token must have an existing liquidity pool, as well as have liquidity.<br></p><p>The <em>path</em> represents the pathway from one token to another. If a pair exists for the two tokens you wish to exchange, this will contain two values inside of an array. However, if there is no direct pair, multiple addresses may be required. </p> |
| *to*           | address             | The address to where the desired token will be sent.                                                                                                                                                                                                                                                                                                                                                                                   |
| *deadline*     | uint                | The UNIX timestamp for which this transaction must be completed. If the transaction is mined after this deadline, the transaction will revert.                                                                                                                                                                                                                                                                                         |

#### Function Parameter Return Breakdown

| Parameter | Type           | Description                                                                                         |
| --------- | -------------- | --------------------------------------------------------------------------------------------------- |
| *amounts* | uint\[] memory | The exact amount of tokens sent into the swap, as well as the exact amount of all subsequent swaps. |

### swapETHForExactTokens

```
function swapETHForExactTokens(
        uint amountOut, 
        address[] calldata path, 
        address to, 
        uint deadline)
        external
        payable
        returns (uint[] memory amounts);
```

The `swapETHForExactTokens` function swaps an exact amount of AVAX for an amount of the desired token.

#### Function Parameter Breakdown

| Parameter                                           | Type                | Description                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      |
| --------------------------------------------------- | ------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| <p><em>(amountIn)</em></p><p><em>msg.value</em></p> | uint                | Sent as the msg.value, the amount of AVAX to be swapped.                                                                                                                                                                                                                                                                                                                                                                                                                                                                         |
| *amountOutMin*                                      | uint                | Sets the minimum amount of the desired token to receive. This acts as a safeguard against removing liquidity during a spike in value. If the amount to be received falls below this value, the transaction reverts.                                                                                                                                                                                                                                                                                                              |
| *path*                                              | address\[] calldata | <p>The pathway to change one token to another, consisting of an array of addresses. Each token must have an existing liquidity pool, as well as have liquidity.<br></p><p>The <em>path</em> represents the pathway from one token to another. If a pair exists for the two tokens you wish to exchange, this will contain two values inside of an array. However, if there is no direct pair, multiple addresses may be required. </p><p></p><p>As the first swap is swapping AVAX to WAVAX, the first address must be WAVX.</p> |
| *to*                                                | address             | The address to where the desired token will be sent.                                                                                                                                                                                                                                                                                                                                                                                                                                                                             |
| *deadline*                                          | uint                | The UNIX timestamp for which this transaction must be completed. If the transaction is mined after this deadline, the transaction will revert.                                                                                                                                                                                                                                                                                                                                                                                   |

#### Function Return Parameter Breakdown

| Parameter | Type           | Description                                                                                              |
| --------- | -------------- | -------------------------------------------------------------------------------------------------------- |
| *amounts* | uint\[] memory | The exact amount of AVAX sent into the swap, as well as the exact return amount of all subsequent swaps. |

### swapExactTokensForTokensSupportingFeeOnTransferTokens

```
function swapExactTokensForTokensSupportingFeeOnTransferTokens(
        uint amountIn,
        uint amountOutMin,
        address[] calldata path,
        address to,
        uint deadline
) external;
```

The `swapExactTokensForTokensSupportingFeeOnTransferTokens` function is similar to `swapExactTokensForTokens` as it swaps one ERC-20 token for another ERC-20 token. In addition, this function allows for fee on transfer tokens, such as PAXG, to be used on uTrade.

#### Function Parameter Breakdown

| Name           | Type                |                                                                                                                                                                                                                                                                                                                                                                                                                              |
| -------------- | ------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| *amountIn*     | uint                | The amount of tokens being sent to swap into AVAX.                                                                                                                                                                                                                                                                                                                                                                           |
| *amountOutMin* | uint                | Sets the minimum amount of the desired token to receive. This acts as a safeguard against removing liquidity during a spike in value. If the amount to be received falls below this value, the transaction reverts.                                                                                                                                                                                                          |
| *path*         | address\[] calldata | <p>The pathway to change one token to another, consisting of an array of addresses. Each token must have an existing liquidity pool, as well as have liquidity.<br></p><p>The path represents the pathway from one token to another. If a pair exists for the two tokens you wish to exchange, this will contain two values inside of an array. However, if there is no direct pair, multiple addresses may be required.</p> |
| *to*           | address             | The address to where the desired token will be sent.                                                                                                                                                                                                                                                                                                                                                                         |
| *deadline*     | uint                | The UNIX timestamp for which this transaction must be completed. If the transaction is mined after this deadline, the transaction will revert.                                                                                                                                                                                                                                                                               |

### swapExactETHForTokensSupportingFeeOnTransferTokens

```
function swapExactETHForTokensSupportingFeeOnTransferTokens(
        uint amountOutMin,
        address[] calldata path,
        address to,
        uint deadline
 ) external payable;
```

The `swapExactETHForTokensSupportingFeeOnTransferTokens`function  is similar to `swapExactETHForTokens` function as it swaps an exact amount of AVAX for ERC-20 tokens. In addition, this function allows for fee on transfer tokens, such as PAXG, to be used on uTrade.&#x20;

#### Function Parameter Breakdown

| Parameter                                           | Type                | Description                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       |
| --------------------------------------------------- | ------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| <p><em>(amountIn)</em></p><p><em>msg.value</em></p> | uint                | Sent as the msg.value, the exact amount of AVAX to be swapped.                                                                                                                                                                                                                                                                                                                                                                                                                                                                    |
| *amountOutMin*                                      | uint                | Sets the minimum amount of the desired token to receive. This acts as a safeguard against removing liquidity during a spike in value. If the amount to be received falls below this value, the transaction reverts.                                                                                                                                                                                                                                                                                                               |
| *path*                                              | address\[] calldata | <p>The pathway to change one token to another, consisting of an array of addresses. Each token must have an existing liquidity pool, as well as have liquidity.<br></p><p>The <em>path</em> represents the pathway from one token to another. If a pair exists for the two tokens you wish to exchange, this will contain two values inside of an array. However, if there is no direct pair, multiple addresses may be required. </p><p></p><p>As the first swap is swapping AVAX to WAVAX, the first address must be WAVAX.</p> |
| *to*                                                | address             | The address to where the desired token will be sent.                                                                                                                                                                                                                                                                                                                                                                                                                                                                              |
| *deadline*                                          | uint                | The UNIX timestamp for which this transaction must be completed. If the transaction is mined after this deadline, the transaction will revert.                                                                                                                                                                                                                                                                                                                                                                                    |

### swapExactTokensForETHSupportingFeeOnTransferTokens <a href="#swapexacttokensforethsupportingfeeontransfertokens" id="swapexacttokensforethsupportingfeeontransfertokens"></a>

```
function swapExactTokensForETHSupportingFeeOnTransferTokens(
        uint amountIn,
        uint amountOutMin,
        address[] calldata path,
        address to,
        uint deadline
) external;
```

The function `swapExactTokensForETHSupportingFeeOnTransferTokens`is similar to the `swapExactTokensForETH`function, as it swaps an exact amount of ERC-20 tokens for AVAX. In addition, this function allows for fee on transfer tokens, such as PAXG, to be used on uTrade.

#### Function Parameter Breakdown

| Parameter      | Type                | Description                                                                                                                                                                                                                                                                                                                                                                                                                            |
| -------------- | ------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| *amountIn*     | uint                | The amount of tokens being sent to swap into AVAX.                                                                                                                                                                                                                                                                                                                                                                                     |
| *amountOutMin* | uint                | Sets the minimum amount of the AVAX to receive. This acts as a safeguard against removing liquidity during a spike in value. If the amount to be received falls below this value, the transaction reverts.                                                                                                                                                                                                                             |
| *path*         | address\[] calldata | <p>The pathway to change one token to another, consisting of an array of addresses. Each token must have an existing liquidity pool, as well as have liquidity.<br></p><p>The <em>path</em> represents the pathway from one token to another. If a pair exists for the two tokens you wish to exchange, this will contain two values inside of an array. However, if there is no direct pair, multiple addresses may be required. </p> |
| *to*           | address             | The address to where the desired token will be sent.                                                                                                                                                                                                                                                                                                                                                                                   |
| *deadline*     | uint                | The UNIX timestamp for which this transaction must be completed. If the transaction is mined after this deadline, the transaction will revert.                                                                                                                                                                                                                                                                                         |

## Interface Code

```
interface IUnifiRouter01 {
    function factory() external pure returns (address);
    function WETH() external pure returns (address);

    function addLiquidity(
        address tokenA,
        address tokenB,
        uint amountADesired,
        uint amountBDesired,
        uint amountAMin,
        uint amountBMin,
        address to,
        uint deadline
    ) external returns (uint amountA, uint amountB, uint liquidity);
    function addLiquidityETH(
        address token,
        uint amountTokenDesired,
        uint amountTokenMin,
        uint amountETHMin,
        address to,
        uint deadline
    ) external payable returns (uint amountToken, uint amountETH, uint liquidity);
    function removeLiquidity(
        address tokenA,
        address tokenB,
        uint liquidity,
        uint amountAMin,
        uint amountBMin,
        address to,
        uint deadline
    ) external returns (uint amountA, uint amountB);
    function removeLiquidityETH(
        address token,
        uint liquidity,
        uint amountTokenMin,
        uint amountETHMin,
        address to,
        uint deadline
    ) external returns (uint amountToken, uint amountETH);
    function removeLiquidityWithPermit(
        address tokenA,
        address tokenB,
        uint liquidity,
        uint amountAMin,
        uint amountBMin,
        address to,
        uint deadline,
        bool approveMax, uint8 v, bytes32 r, bytes32 s
    ) external returns (uint amountA, uint amountB);
    function removeLiquidityETHWithPermit(
        address token,
        uint liquidity,
        uint amountTokenMin,
        uint amountETHMin,
        address to,
        uint deadline,
        bool approveMax, uint8 v, bytes32 r, bytes32 s
    ) external returns (uint amountToken, uint amountETH);
    function swapExactTokensForTokens(
        uint amountIn,
        uint amountOutMin,
        address[] calldata path,
        address to,
        uint deadline
    ) external returns (uint[] memory amounts);
    function swapTokensForExactTokens(
        uint amountOut,
        uint amountInMax,
        address[] calldata path,
        address to,
        uint deadline
    ) external returns (uint[] memory amounts);
    function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline)
        external
        payable
        returns (uint[] memory amounts);
    function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline)
        external
        returns (uint[] memory amounts);
    function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline)
        external
        returns (uint[] memory amounts);
    function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline)
        external
        payable
        returns (uint[] memory amounts);

    function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB);
    function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut, uint fee) external pure returns (uint amountOut);
    function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut, uint fee) external pure returns (uint amountIn);
    function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts);
    function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts);
}

interface IUnifiRouter02 is IUnifiRouter01 {
    function removeLiquidityETHSupportingFeeOnTransferTokens(
        address token,
        uint liquidity,
        uint amountTokenMin,
        uint amountETHMin,
        address to,
        uint deadline
    ) external returns (uint amountETH);
    function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens(
        address token,
        uint liquidity,
        uint amountTokenMin,
        uint amountETHMin,
        address to,
        uint deadline,
        bool approveMax, uint8 v, bytes32 r, bytes32 s
    ) external returns (uint amountETH);

    function swapExactTokensForTokensSupportingFeeOnTransferTokens(
        uint amountIn,
        uint amountOutMin,
        address[] calldata path,
        address to,
        uint deadline
    ) external;
    function swapExactETHForTokensSupportingFeeOnTransferTokens(
        uint amountOutMin,
        address[] calldata path,
        address to,
        uint deadline
    ) external payable;
    function swapExactTokensForETHSupportingFeeOnTransferTokens(
        uint amountIn,
        uint amountOutMin,
        address[] calldata path,
        address to,
        uint deadline
    ) external;
}
```


# Binance Smart Chain

Here you will find in-depth detail of the contracts that make up uTrade V2 on Binance Smart Chain. Each contract includes JSONs as well as Typescript files for integration into your project. Every effort is made to open-source all aspects of uTrade V2, but some do remain private.  When a contract is available, you will find a link to the Github source code.&#x20;


# singleLiquidityWrapper.sol

**Primary Uses -** Unique to uTrade, the Single Liquidity Wrapper allows BNB or any BEP-20 token to converted into a LP pool. For example, USDT can be added using the wrapper to supply liquidity for a BUSD / WBNB 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

| Type                                                 | Link                                                                                                                                              |
| ---------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------- |
| uTrade V2 Single Liquidity Wrapper (Solidity)        | [BscScan Verified](https://bscscan.com/address/0x9fa035D76636d3D2E4d029406492E6A5E0898e81#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                                                                                                                               |
| ------------ | ------------------------------------------------------------------------------------------------------------------------------------- |
| BSC Main Net | `0x9fa035D76636d3D2E4d029406492E6A5E0898e81` ([Link](https://bscscan.com/address/0x9fa035D76636d3D2E4d029406492E6A5E0898e81))         |
| BSC Test Net | `0xF68Dbc70C086e20063144a2153c0172Aa318F468` ([Link](https://testnet.bscscan.com/address/0xF68Dbc70C086e20063144a2153c0172Aa318F468)) |

### 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 BNB into a LP token. It does so by first converting the provided BNB 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 BNB value is sent as a msg.value parameter. One of the two assets can be WBNB.

#### Parameter Breakdown

| Parameter                                        | Type    | Description                                                                                                                                       |
| ------------------------------------------------ | ------- | ------------------------------------------------------------------------------------------------------------------------------------------------- |
| <p><em>amountIn</em><br><em>(msg.value)</em></p> | uint    | The amount of BNB 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 BEP-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 BNB  to an uTrade V2 LP token made up of two different tokens. In other words, BNB 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 BNB 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 BNB 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 WBNB'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 BNB must be converted to WBNB, 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 BNB 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 WBNB'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 BNB must be converted to WBNB, 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 WBNB and send BNB. |
| *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 BNB or any BEP-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 BNB. If true, the *receiveToken* address should be WBNB, as it will unwrap WBNB and send BNB.                                                                                                                                                                                                                                                                                                                              |
| *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 ;
}
```


# UnifiController.sol

The Unifi Controller is a work in progress with minor tweaks here and there. Full documentation will be available once it is optimized!

**Primary Uses -** The Unifi Controller is responsible for the setting the variables of UP minting on individual pairs as well as updating the redeem value of UP tokens globally.&#x20;

## uTrade V2 Controller Code / Interfaces

|                                             |           |
| ------------------------------------------- | --------- |
| uTrade V2 Controller (Solidity)             | Link Here |
| uTrade V2 Controller Interface as JSON      | Link Here |
| uTrade V2 Controller as Typescript          | Link Here |
| Import statement codeblock (when available) |           |

## uTrade V2 Controller Contract Addresses

| Network      | Address                                                                                                                               |
| ------------ | ------------------------------------------------------------------------------------------------------------------------------------- |
| BSC Main Net | `0x5b80021bec729DF06438EcAD5edfC48C39F03e89` ([Link](https://bscscan.com/address/0x5b80021bec729DF06438EcAD5edfC48C39F03e89))         |
| BSC Test Net | `0xac057d3A6d17F9819BAC2583445a2016E0442532` ([Link](https://testnet.bscscan.com/address/0xac057d3A6d17F9819BAC2583445a2016E0442532)) |

### SwapFeesUPminted

```
event SwapFeesUpminted(address indexed pool, uint amountUPMinted, address defaultPoolAddress, uint platforUPFees);
```

The `SwapFeeUpminted` event is emitted whenever UP is minted. In the majority of cases, this will occur any time a trade occurs.&#x20;

#### Parameter Breakdown

| Parameter            | Type    | Description                                                                                     |
| -------------------- | ------- | ----------------------------------------------------------------------------------------------- |
| *pool*               | address | The liquidity pool where the UP was minted.                                                     |
| *amountUPMinted*     | uint    | The amount of UP minted during this event.                                                      |
| *defaultPoolAddress* | address | The pool representing the 'Super Pair' reward for UNIFI holders.                                |
| *platforUPFees*      | uint    | The amount of UP collected by the platform for increasing the redeem value and for Super Pairs. |

### UpdatePoolRewards

```
event UpdatePoolRewards(address indexed pool, uint rewards);    
```

The UpdatePoolRewards event is emitted when the amount of UP claimable by the liquidity providers in the liquidity pool is updated. This event occurs when a trade occurs and results in UP being minted for liquidity providers, or a liquidity provider performs a claim UP transaction.

#### Parameter Breakdown

| Parameter | Type    | Description                                                                      |
| --------- | ------- | -------------------------------------------------------------------------------- |
| *pool*    | address | The liquidity pool where the UP was minted.                                      |
| *rewards* | uint    | The amount of UP available to be claimed by all liquidity providers in the pool. |

## Read-Only Functions

#### feeSetter

```
function feeSetter() external view returns (address);
```

The `feeSetter` function returns the address of uTrade V2's Smart Contract which sets the fees for trading.

### WBNB

```
function WBNB() external view returns (address);
```

The `WBNB` function will return the address of WBNB on BSC. As this does not change, it will always return `0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c`.

### UNIFIUPVault

```
function UNIFIUPVault() external view returns (address);
```

The `UNIFIUPVault` function returns the address of the UPBnb vault. This vault contains the BNB that is redeemable for UP.

### nativeFeeTo

```
function nativeFeeTo() external view returns (address);
```

The `nativeFeeTo` function returns the address where, in the case of Unifi Protocol collecting native token fees, the fees would be sent to.


# UnifiERC20.sol

**Primary Uses -** UnifiERC20.sol essentially ports the properties of BEP-20 tokens on to Unifi LP Tokens, or uTokens. An example of this in practice would be the 'approve' transaction.

## uTrade V2 UnifiERC20 Code / Interfaces

|                                             |                                                                                                                          |
| ------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------ |
| uTrade V2 UnifiERC20 (Solidity)             | [BscScan Verified Pair](https://bscscan.com/address/0x76AE2c33bcce5A45128eF2060C6280a452568396#code#F3#L1) (UNIFI / BNB) |
| uTrade V2 UnifiERC20 Interface as JSON      | Link Here                                                                                                                |
| uTrade V2 UnifiERC20 as Typescript          | Link Here                                                                                                                |
| Import statement codeblock (when available) |                                                                                                                          |

## uTrade V2 UnifiERC20 Contract Addresses

Each uTrade V2 Liquidity Pool uses the uTrade V2 ERC20 Interface in the contract. An example would be `0x76AE2c33bcce5A45128eF2060C6280a452568396` ([Link](https://bscscan.com/address/0x76AE2c33bcce5A45128eF2060C6280a452568396)) for the UNIFI / BNB pair.&#x20;

## Events

### Approval

```
event Approval(address indexed owner, address indexed spender, uint value);
```

The `Approval` event is emitted anytime an `approve` or `permit` function is called.

### Transfer

```
event Transfer(address indexed from, address indexed to, uint value);
```

The `Transfer` event is emitted anytime a transfer of LP tokens occurs, by the `transfer`, `transferFrom`, `mint`, or `burn` functions.

## Read-Only Functions

### name

```
function name() external pure returns (string memory);
```

The `name` function will return "Unifi LPs" for all liquidity pool contracts.

### symbol

```
function symbol() external pure returns (string memory);
```

The `symbol` function will return "Unifi-LP" for all liquidity pool contracts.

### decimals

```
function decimals() external pure returns (uint8);
```

The `decimals` function returns "18" as a uint8 value, which is the precision for each uToken on uTrade V2.

### totalSupply

```
function totalSupply() external view returns (uint);
```

The `totalSupply` function returns the total amount uTokens for a pair.

### balanceOf

```
function balanceOf(address owner) external view returns (uint);
```

The `balanceOf` function returns the balance of uTokens for the provided address.

### allowance

```
function allowance(address owner, address spender) external view returns (uint);
```

The `allowance` function returns the amount of tokens an address is approved to transfer when using the `transferFrom` function.

### DOMAIN\_SEPARATOR

```
function DOMAIN_SEPARATOR() external view returns (bytes32);
```

The `DOMAIN_SEPARATOR` function is used in the `permit` function, and is one of the components that allows transactions to get through without a prior approve transaction. Calling a read function returns the bytes32 data that is required for use in `permit` function.

### PERMIT\_TYPEHASH

```
function PERMIT_TYPEHASH() external view returns (bytes32);
```

The `PERMIT_TYPEHASH` function is used in the `permit` function, and is one of the components that allows transactions to get through without a prior approve transaction. Calling a read function returns the bytes32 data that is required for use in the `permit` function.

### nonces

```
function nonces(address owner) external view returns (uint);
```

The `nonces` function is used in the permit function. It returns the current nonce of the *address* provided.

## State-Changing Functions

### approve

```
function approve(address spender, uint value) external returns (bool);
```

The `approve` function sets a *value* for  the amount of LP tokens the *address* provided is allowed to transfer. Returns a boolean value and emits the `Approval` event.

### transfer

```
function transfer(address to, uint value) external returns (bool);
```

The `transfer` function lets an address send uTokens from one address to another, and returns a boolean value and emits a `Transfer` event.

### transferFrom

```
function transferFrom(address from, address to, uint value) external returns (bool);
```

The `transferFrom` function sends uTokens from one address to another. This requires the sending address to have approval to send uTokens. Returns a boolean value and emits a `Transfer`event.

### permit

```
function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external;
```

The permit function allows a sender to use a signature in lieu of an approval transaction, and sets the allowance for an address to send.

#### Function Parameter Breakdown

| Parameter  | Type    | Description                                                                                                                                    |
| ---------- | ------- | ---------------------------------------------------------------------------------------------------------------------------------------------- |
| *owner*    | address | The owner of the address.                                                                                                                      |
| *spender*  | address | The spender of the uTokens.                                                                                                                    |
| *value*    | uint    | The amount of uTokens to be transferred.                                                                                                       |
| *deadline* | uint    | The UNIX timestamp for which this transaction must be completed. If the transaction is mined after this deadline, the transaction will revert. |
| *v*        | uint8   | The v value of the permit. This is one of the three values that makes up the approval signature.                                               |
| *r*        | bytes32 | The r value of the permit. This is one of the three values that makes up the approval signature.                                               |
| *s*        | bytes32 | The s value of the permit. This is one of the three values that makes up the approval signature.                                               |

## Interface Code

```
interface IUnifiERC20 {
    event Approval(address indexed owner, address indexed spender, uint value);
    event Transfer(address indexed from, address indexed to, uint value);

    function name() external pure returns (string memory);
    function symbol() external pure returns (string memory);
    function decimals() external pure returns (uint8);
    function totalSupply() external view returns (uint);
    function balanceOf(address owner) external view returns (uint);
    function allowance(address owner, address spender) external view returns (uint);

    function approve(address spender, uint value) external returns (bool);
    function transfer(address to, uint value) external returns (bool);
    function transferFrom(address from, address to, uint value) external returns (bool);

    function DOMAIN_SEPARATOR() external view returns (bytes32);
    function PERMIT_TYPEHASH() external pure returns (bytes32);
    function nonces(address owner) external view returns (uint);

    function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external;
}
```


# UnifiFactory.sol

**Primary Uses** - The uTrade V2 Factory contract creates an LP token for any pairs listed on uTrade V2, and indexes them for easy retrieval. In addition, it can return the address of the LP token based on a call of the addresses of the two tokens that make up the liquidity pool.

## uTrade V2 Factory Code / Interfaces

|                                             |                                                                                                                                    |
| ------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------- |
| uTrade V2 Factory (Solidity)                | [BscScan Verified](https://bscscan.com/address/0xA5Ba037Ec16c45f8ae09e013C1849554C01385f5#code)                                    |
| uTrade V2 Factory Interface as JSON         | [GitHub](https://github.com/unifiprotocol/uTradeV2-core/blob/52d66be2a472b9697a577757a0446076b6c32001/ABI/JSON/IUnifiFactory.json) |
| uTrade V2 Factory Interface as Typescript   | [GitHub](https://github.com/unifiprotocol/uTradeV2-core/blob/52d66be2a472b9697a577757a0446076b6c32001/ABI/TS/IUnifiFactory.ts)     |
| Import statement codeblock (when available) |                                                                                                                                    |

## uTrade V2 Factory Contract Addresses

| Network      | Address                                                                                                                               |
| ------------ | ------------------------------------------------------------------------------------------------------------------------------------- |
| BSC Main Net | `0xA5Ba037Ec16c45f8ae09e013C1849554C01385f5` ([Link](https://bscscan.com/address/0xA5Ba037Ec16c45f8ae09e013C1849554C01385f5))         |
| BSC Test Net | `0xcAF0DFf51989Cee8f6437A7152001A42116170d5` ([Link](https://testnet.bscscan.com/address/0xac057d3A6d17F9819BAC2583445a2016E0442532)) |

### PairCreated

```
event PairCreated(address indexed token0, address indexed token1, address pair, uint);
```

Anytime a pair is created on uTrade V2 using the `createPair` function, a `PairCreated` event is emitted. Contracts can be deployed to listen for new pairs on the uTrade V2 BSC Factory address.&#x20;

* *token0* is the token address of the first asset in the token pair.
* *token1* is the token address of the second asset in the token pair.
* *pair* is the address of the newly created uTrade V2 liquidity pool.
* *uint* refers to the index of this uTrade V2 Factor&#x79;*.* For example, the first liquidity pool created on uTrade V2 is 1, the second liquidity pool is 2, and so on. This number can used with the `allPairs(uint)` to return the address. The current number, and therefore the total number of LP pools on uTrade V2 BSC, can be accessed using the `allPairsLength` function.

## Read-Only Functions <a href="#read-only-functions" id="read-only-functions"></a>

### getPair

```
function getPair(address tokenA, address tokenB) external view returns (address pair);
```

A call to the `getPair` function returns the address of the pair for *tokenA* and *tokenB*.

* If the pair does not exist, the call will return *address(0)*.&#x20;
* The order of the tokens is irrelevant in this call. For example, a call for BNB, UNIFI will return the same pair address as UNIFI, BNB.&#x20;

### allPairs

```
function allPairs(uint) external view returns (address pair);
```

A call to the `allPairs` function returns the address of a pair based on the indexed *uint* value assigned upon creation of the LP.

* For example, `allPairs(0)` will return the first pair created on uTrade V2 BSC.
* &#x20;If the index number is too high, as in, there aren't enough pairs created yet, the function will return *address(0)*.

### allPairsLength

```
function allPairsLength() external view returns (uint);
```

A call to the `allPairsLength` function returns the current number of pairs.&#x20;

* For example, if there are 201 total liquidity pool pairs on uTrade V2 BSC, this call will return *200* as an uint value.

### feeTo

```
function feeTo() external view returns (address);
```

A call to the `feeTo` function returns the percentage of trading fees that Unifi Protocol receives.&#x20;

* Due to the nature of UP Token economics, this is set to zero, but is preserved for flexibility in the future.

### feeToSetter

```
function feeToSetter() external view returns (address);
```

A call to the `feeToSetter` function returns the address to which the `feeTo` would send trading fees, if trading fees were collected.

## State-Changing Functions <a href="#state-changing-functions" id="state-changing-functions"></a>

### createPair

```
function createPair(address tokenA, address tokenB) external returns (address pair);
```

Creates a liquidity pool pair for *tokenA* and *tokenB* if one does not currently exist. After the function is confirmed on chain, a `PairCreated` event is emitted.

## Interface Code

```
interface UnifiFactory {  
  event PairCreated(address indexed token0, address indexed token1, address pair, uint);
  function getPair(address tokenA, address tokenB) external view returns (address pair);  
  function allPairs(uint) external view returns (address pair);  
  function allPairsLength() external view returns (uint);
  function feeTo() external view returns (address);  function feeToSetter() external view returns (address);
  function createPair(address tokenA, address tokenB) external returns (address pair);
  }
```

###

###


# UnifiPair.sol

**Primary Uses -** UnifiPair.sol is responsible for many of the functionalities of liquidity pool tokens and UP tokens. First, it is responsible for the issuing and burning of Liquidity Pool Tokens (uTokens). In addition, it allows for direct reads of the reserves and ratio of the liquidity pool, as well as swaps. Lastly, it is where UP claims are processed.&#x20;

## uTrade V2 Pair Code / Interfaces

|                                             |                                                                                                                          |
| ------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------ |
| uTrade V2 Pair (Solidity)                   | [BscScan Verified Pair](https://bscscan.com/address/0x76AE2c33bcce5A45128eF2060C6280a452568396#code#F1#L1) (UNIFI / BNB) |
| uTrade V2 Pair Interface as JSON            | Link Here                                                                                                                |
| uTrade V2 Pair as Typescript                | Link Here                                                                                                                |
| Import statement codeblock (when available) |                                                                                                                          |

## uTrade V2 Pair Contract Addresses

Each uTrade V2 Liquidity Pool uses uTrade V2 Pair Solidity Contract. For instance, `0x76AE2c33bcce5A45128eF2060C6280a452568396` ([Link](https://bscscan.com/address/0x76AE2c33bcce5A45128eF2060C6280a452568396)) is the address for the UNIFI / BNB pair on Binance Smart Chain - Main Net.

## Events

### Mint

```
event Mint(address indexed sender, uint amount0, uint amount1);
```

The `Mint` event is emitted any time liquidity tokens are created via the `mint` function. In other words, when a user adds liquidity to a pair, then they will receive LP tokens, therefore the `Mint` event will be emitted.

### Burn

```
event Burn(address indexed sender, uint amount0, uint amount1, address indexed to);
```

The `Burn` event is emitted any time liquidity tokens are burned via the `burn` function. In other words, when a user removes liquidity from a pair,  their LP tokens will be burned, therefore the `Burn` event will be emitted.

### Swap

```
event Swap(
        address indexed sender,
        uint amount0In,
        uint amount1In,
        uint amount0Out,
        uint amount1Out,
        address indexed to
 );
```

The `Swap` event is emitted any time the `swap` function is used. Under the hood, all trades on uTrade V2 are swaps. Therefore, any time somebody trades on the pair, the uTrade contract for that pair will emit a `Swap` event.

### Sync

```
event Sync(uint112 reserve0, uint112 reserve1);
```

The `Sync` event is emitted anytime a function occurs that may change the reserves of a token pair. In other words, anytime the amount of the two tokens within a liquidity pool may change. Therefore, whenever a`mint`, `burn`, `swap`, or `sync` function is called, the `Sync` event will be emitted.

## Read-Only Functions

### MINIMUM\_LIQUIDITY <a href="#minimum_liquidity" id="minimum_liquidity"></a>

```
function MINIMUM_LIQUIDITY() external pure returns (uint);
```

The `MINIMUM_LIQUIDITY`function will always return 1000. The function itself refers to the burning of initial LP tokens that occurs once when a pool is created. This burn of a tiny amount allows for cleaner LP token numbers therefore avoiding LP tokens being represented as very small decimals value. This allows the tick size to be more precise and prevents rounding errors.

### factory

```
function factory() external view returns (address);
```

The `factory` function will return the current factory address for uTrade V2.

### WBNB

```
function WBNB() external view returns (address);
```

The WBNB function will return the address of WBNB on BSC. As this does not change, it will always return `0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c`.

### token0

```
function token0() external view returns (address);
```

The `token0` function will return the contract address of the first token that makes up the liquidity pair. In other words, if the liquidity pool is made up of USDT / USDC, it will return the contract address of USDT.

### token1

```
function token1() external view returns (address);
```

The `token1` function will return the contract address of the first token that makes up the liquidity pair. In other words, if the liquidity pool is made up of USDT / USDC, it will return the contract address of USDC.

### getReserves

```
function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast);
```

The `getReserves` function returns the reserves of the two tokens that make up the liquidity pool as *reserve0* and *reserve1*. These two values can be helpful in determining the current price of each asset. The function also returns a timestamp with the block number.

### price0CumulativeLast

```
function price0CumulativeLast() external view returns (uint);
```

The `price0CumulativeLast` function is for Oracle usage on uTrade V2. The value of *token0* is captured at the end of each block, and can be called using this function to feed into an Oracle to determine a more time-weighted 'average' price.&#x20;

### price1CumulativeLast

```
function price1CumulativeLast() external view returns (uint);
```

The `price1CumulativeLast` function is for Oracle usage on uTrade V2. The value of *token1* is captured at the end of each block, and can be called using this function to feed into an Oracle to determine a more time-weighted 'average' price.&#x20;

### kLast

```
function kLast() external view returns (uint);
```

The `kLast` function returns the value of *reserve0* \* *reserve1*, after any event that may have triggered a change in the liquidity. For example, the execution of a *swap* function or a *mint* function.

## State-Changing Functions

### mint

```
function mint(address to) external returns (uint liquidity);
```

The `mint` function creates the LP tokens that represent a user's tokens in a liquidity pool. For example, if a user provides 1 BNB and 300 USDT liquidity to a pool, the Unifi Pair Smart Contract will mint an amount of uBNBUSDT tokens. Will emit the `Mint`, `Sync`, and `Transfer` events.

### burn

```
function burn(address to) external returns (uint amount0, uint amount1);
```

The `burn` function destroys the LP tokens that represent a user's token in a liquidity pool. For example, if a user removes 1 BNB and 300 USDT liquidity to a pool, the Unifi Pair Smart Contract will burn an amount of uBNBUSDT tokens. Will emit the `Burn`, `Sync`, and `Transfer` events.

### claimUP

```
function claimUP(address to) external lock returns(uint) {
```

The `claimUP` function claims any UP earned from providing liquidity if any exists, and sends the UP to the address provided.

### swap

```
function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external;
```

The `swap` function exchanges one token for another. Under the hood, all trades on uTrade V2 use this function. The *calldata* must be 0 during a normal swap, but must contain data if executing a flash loan. Emits the `Swap` and `Sync` events.

### skim

```
function skim(address to) external;
```

The `skim` function operates as a safeguard if the amount of tokens causes a data error due to too large of a number in the reserves pools. In this unusual circumstance, this will trigger failures in trades. The `skim` function can be called to return the overflowed tokens to the caller.

### sync

```
function sync() external;
```

The `sync` function operates as a safeguard in certain events where the token balance changes outside of normal trading. An example would be an algorithmic stablecoin re-balancing, therefore lowering or raising the amount of the algorithmic stablecoin in the pool. The `sync` function may be called to reset the price ratio to the new reserves. Emits the `Sync`event.

## Interface Code

```
interface IUnifiPair {
    event Mint(address indexed sender, uint amount0, uint amount1);
    event Burn(address indexed sender, uint amount0, uint amount1, address indexed to);
    event Swap(
        address indexed sender,
        uint amount0In,
        uint amount1In,
        uint amount0Out,
        uint amount1Out,
        address indexed to
    );
    event Sync(uint112 reserve0, uint112 reserve1);

    function MINIMUM_LIQUIDITY() external pure returns (uint);
    function factory() external view returns (address);
    function token0() external view returns (address);
    function token1() external view returns (address);
    function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast);
    function price0CumulativeLast() external view returns (uint);
    function price1CumulativeLast() external view returns (uint);
    function kLast() external view returns (uint);

    function mint(address to) external returns (uint liquidity);
    function burn(address to) external returns (uint amount0, uint amount1);
    function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external;
    function skim(address to) external;
    function sync() external;

    function initialize(address, address) external;
}
```


# UnifiRouter.sol

**Primary Uses** - The uTrade V2 Router is the 'brain' of uTrade. The router finds the optimal path for exchanging one token for another. Whenever a trade is made, your wallet sends funds to the router address. The router will then carry out as many transactions as necessary to acquire the desired token. The router also handles adding liquidity to liquidity pools, and sending the corresponding LP tokens to liquidity providers.

## uTrade V2 Router Code / Interfaces

|                                             |                                                                                                                                   |
| ------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------- |
| uTrade V2 Router (Solidity)                 | [BscScan Verified](https://bscscan.com/address/0xBE930734eDAfc41676A76d2240f206Ed36dafbA2#code)                                   |
| uTrade V2 Router Interface as JSON          | [GitHub](https://github.com/unifiprotocol/uTradeV2-core/blob/52d66be2a472b9697a577757a0446076b6c32001/ABI/JSON/IUnifiRouter.json) |
| uTrade V2 Router Interface as Typescript    | [GitHub](https://github.com/unifiprotocol/uTradeV2-core/blob/52d66be2a472b9697a577757a0446076b6c32001/ABI/TS/IUnifiRouter.ts)     |
| Import statement codeblock (when available) |                                                                                                                                   |

## uTrade V2 Router Contract Addresses

| Network      | Address                                                                                                                               |
| ------------ | ------------------------------------------------------------------------------------------------------------------------------------- |
| BSC Main Net | `0xBE930734eDAfc41676A76d2240f206Ed36dafbA2`([Link](https://bscscan.com/address/0xBE930734eDAfc41676A76d2240f206Ed36dafbA2))          |
| BSC Test Net | `0x8E07E90f7F5AD5EBaCCE04f020BD08D7572BB36E` ([Link](https://testnet.bscscan.com/address/0xac057d3A6d17F9819BAC2583445a2016E0442532)) |

### factory

```
function factory() external pure returns (address);
```

A call to the `factory` function returns the address of the current Factory used by uTrade v2. The current factory address for uTrade V2 on Binance Smart Chain is `0xA5Ba037Ec16c45f8ae09e013C1849554C01385f5` .

### WETH

```
function WETH() external pure returns (address);
```

A call to the `WETH` function returns the address of Wrapped BNB (WBNB) on Binance Smart Chain. As this address does not change, it will always return `0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c`.

### quote

```
function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB);
```

A call to the `quote` function returns the amount of *tokenB* that will be received for an amount of *tokenA*. This can be used to calculate the exchange rate between two tokens without factoring in slippage or fees. By entering the amount of *tokenA,* the total amount of reserves of *tokenA* as *reserveA,* and the total amount of reserves of *tokenB* as *reserveB*, the call will return the equivalent amount of *tokenB*.

### getAmountOut

```
function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut, uint fee) external pure returns (uint amountOut);
```

A call to the `getAmountOut`function with the amount of the token being sent will return the maximum amount of a token to be received, accounting for fees and the total amount of reserves.

### getAmountIn

```
function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut, uint fee) external pure returns (uint amountIn);
```

A call to the `getAmountIn` function with the amount of the token you wish to receive will return the minimum amount required of the token you wish to send, accounting for fees and the total amount of reserves.

### getAmountsOut

```
function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts);
```

A call to the `getAmountsOut` function with the amount of the token being sent will return the maximum amount to be received of multiple different tokens. By entering multiple LP addresses in the *address* array, the function will return the maximum amount of each token that will be received. A call to this function uses the `getReserves` function from [UnifiPair.sol](https://docs.unifiprotocol.com/utrade-v2/binance-smart-chain/unifipair.sol) to determine the reserves of the liquidity pool. Then, it calls the `getAmountOut` function to determine the amount of each token in the array that will be received for the *amountIn* value of a token.

### getAmountsIn <a href="#getamountsin" id="getamountsin"></a>

```
function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts);
```

A call to the `getAmountsIn` function with the desired amount of the token to be received will return the minimum amount required to be sent of multiple tokens. By entering multiple LP addresses in the *address* array, the function will return the minimum amount of each token that will need to be sent to receive the desired amount of a token. A call to this function uses the `getReserves` function from [UnifiPair.sol](https://docs.unifiprotocol.com/utrade-v2/binance-smart-chain/unifipair.sol) to determine the reserves of the liquidity pool. Then, it calls the `getAmountIn` function to determine the amount of each token in the array that will need to be sent for the *amountOut* value of a token.&#x20;

## State-Changing Functions - Liquidity <a href="#state-changing-functions" id="state-changing-functions"></a>

### addLiquidity

```
function addLiquidity(
        address tokenA,
        address tokenB,
        uint amountADesired,
        uint amountBDesired,
        uint amountAMin,
        uint amountBMin,
        address to,
        uint deadline
) external returns (uint amountA, uint amountB, uint liquidity);
```

The `addLiquidity` function adds the two tokens that make up the liquidity pool - *tokenA* and *tokenB* - at the proper ratio based on the reserves of the pool. For example, if the pool contains 500 USDT / 2 BNB, a user's liquidity will be added at the ratio of 250 USDT to 1 BNB, provided there is no price movements in the pair between when the user broadcasts the transaction to when it is mined. In the event of a price movement, the *amountADesired*, *amountBDesired*, *amountAMin*, and *amountBMin* act as a security measure against an adverse price movement. After the liquidity is added, the function sends the corresponding LP tokens to the sender.

In the case of a pool not existing for the two assets, one will be created using [UnifiFactory.sol](https://app.gitbook.com/@unifi-protocol/s/unifi-protocol/utrade-v2/binance-smart-chain/utrade-v2-factory) at the ratio of the assets supplied.

#### Function Parameters Breakdown

| Parameter        | Type    | Description                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          |
| ---------------- | ------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| *tokenA*         | address | Token address of the first asset in the token pair.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  |
| *tokenB*         | address | Token address of the second asset in the token pair.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 |
| *amountADesired* | uint    | The amount of *tokenA* to be added to liquidity if the value of *tokenA* goes down in comparison to *tokenB*.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        |
| *amountBDesired* | uint    | The amount of *tokenB* to be added to liquidity if the value of *tokenB* goes down in comparison to *tokenA.*                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        |
| *amountAMin*     | uint    | <p>Sets the minimum amount of <em>tokenA</em> that can added to the pool before the transaction reverts. This acts as a safeguard. <br></p><ul><li>If the value of <em>tokenA</em> rapidly increases in comparison to <em>tokenB</em>, the user will require less of <em>tokenA</em> to be added to the pool to maintain the original value of the submitted liquidity.</li><li>A user could potentially be adding liquidity during an outlier spike in value. If the amount of <em>tokenA</em> required falls below this value, the transaction will revert.</li><li>This value must be less than or equal to <em>amountADesired</em>.</li></ul>    |
| *amountBMin*     | uint    | <p>Sets the minimum amount of <em>tokenB</em> that can added to the pool before the transaction reverts. This acts as a safeguard.</p><p></p><ul><li>If the value of <em>tokenB</em> rapidly increases in comparison to <em>tokenA</em>, the user will require less of <em>tokenB</em> to be added to the pool to maintain the original value of the submitted liquidity.</li><li> A user could potentially be adding liquidity during an outlier spike in value. If the amount of <em>tokenB</em> required falls below this value, the transaction will revert.</li><li>This value must be less than or equal to <em>amountBDesired</em>.</li></ul> |
| *to*             | address | The address to which the LP tokens for the uTrade V2 pool will be sent.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              |
| *deadline*       | uint    | The UNIX timestamp for which this transaction must be completed. If the transaction is mined after this deadline, the transaction will revert.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       |

#### Function Return Parameter Breakdown

| Parameter   | Type | Description                                                                                                |
| ----------- | ---- | ---------------------------------------------------------------------------------------------------------- |
| *amountA*   | uint | The exact amount of *tokenA* that was sent to the pool.                                                    |
| *amountB*   | uint | The exact amount of *tokenB* that was sent to the pool.                                                    |
| *liquidity* | uint | The exact amount of liquidity tokens minted and sent to the address provided in the *to* paramete&#x72;*.* |

### addLiquidityETH

```
function addLiquidityETH(
        address token,
        uint amountTokenDesired,
        uint amountTokenMin,
        uint amountETHMin,
        address to,
        uint deadline
    ) external payable returns (uint amountToken, uint amountETH, uint liquidity);
```

The `addLiquidityEth` function is similar to the `addLiquidity` function except it accounts for one token being a native asset. In the case of Binance Smart Chain, this native asset would be BNB. This function will convert BNB to WBNB, will pair that WBNB with the supplied other token, and add the liquidity to the pool. This function will add at the ideal ratio based on when the transaction is mined.\
\
In the case of a pool not existing for WBNB and the token provided, one will be created using [UnifiFactory.sol](https://docs.unifiprotocol.com/utrade-v2/binance-smart-chain/utrade-v2-factory) at the ratio of the assets supplied.

* This function requires a *msg.value* with the amount of BNB to be added.&#x20;
  * The *msg.value* acts as the amountETHDesired. As in, if the ratio between BNB and the token being paired with it change, this is the number of BNB that will be added to the pool.
  * Any leftover BNB is returned to the *msg.sender* address.

#### Function Parameter Breakdown

| Parameter                      | Type    | Description                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 |
| ------------------------------ | ------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| *token*                        | address | The address of the supplied token for the liquidity pool. In other words, the asset that BNB is paired with.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                |
| *amountTokenDesired*           | uint    | The amount of the supplied token to be added to liquidity if the value of token goes down in comparison to BNB.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             |
| (*amountETHDesired*) msg.value | uint    | Sent as the msg.value, the amount of BNB to be added to liquidity if the value of BNB goes down in comparison to token.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     |
| *amountTokenMin*               | uint    | <p>Sets the minimum amount of the supplied token that can added to the pool before the transaction reverts. This acts as a safeguard. </p><p></p><ul><li>If the value of supplied token rapidly increases in comparison to BNB, the user will require less of the token to be added to the pool to maintain the original value of the submitted liquidity.</li><li>A user could potentially be adding liquidity during an outlier spike in value. If the amount of the supplied token required falls below this value, the transaction will revert.</li><li>This value must be less than or equal to <em>amountTokenDesired</em>.</li></ul> |
| *amountETHMin*                 | uint    | <p></p><p>Sets the minimum amount of BNB that can added to the pool before the transaction reverts. This acts as a safeguard. </p><p></p><ul><li>If the value of BNB increases in comparison to the supplied token, the user will require less BNB to be added to the pool to maintain the original value of the submitted liquidity.</li><li>A user could potentially be adding liquidity during an outlier spike in value. If the amount of BNB required falls below this value, the transaction will revert.</li><li>This value must be less than or equal to <em>amountETHDesired</em>.</li></ul>                                       |
| *to*                           | address | The address to which the LP tokens for the uTrade V2 pool will be sent.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     |
| *deadline*                     | uint    | The UNIX timestamp for which this transaction must be completed. If the transaction is mined after this deadline, the transaction will revert.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              |

#### Function Return Parameter Breakdown

| Parameter     | Type | Description                                                                                                |
| ------------- | ---- | ---------------------------------------------------------------------------------------------------------- |
| *amountToken* | uint | The exact amount of the supplied token sent to the pool.                                                   |
| *amountETH*   | uint | The exact amount of BNB converted to WBNB, and then added to the pool.                                     |
| *liquidity*   | uint | The exact amount of liquidity tokens minted and sent to the address provided in the *to* paramete&#x72;*.* |

### removeLiquidity

```
function removeLiquidity(
        address tokenA,
        address tokenB,
        uint liquidity,
        uint amountAMin,
        uint amountBMin,
        address to,
        uint deadline
) external returns (uint amountA, uint amountB);
```

The `removeLiquidity` function removes the two tokens that make up liquidity from a pool. In other words, this function is used when the pool consists of two BEP-20 tokens.

* In the event one of the assets is paired with BNB, BNB will have been wrapped and paired with WBNB (Wrapped BNB). If the user wishes to withdraw WBNB instead of withdrawing as BNB, this function should be used instead of `removeLiquidityETH` .

#### Function Parameter Breakdown

| Parameter    | Type    | Description                                                                                                                                                                                                              |
| ------------ | ------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| *tokenA*     | address | Token address of the first asset in the pair.                                                                                                                                                                            |
| *tokenB*     | address | Token address of the second asset in the pair.                                                                                                                                                                           |
| *liquidity*  | uint    | The amount of liquidity tokens to be redeemed and removed.                                                                                                                                                               |
| *amountAMin* | uint    | Sets the minimum amount of *tokenA* to be removed from the the pool. This acts as a safeguard against removing liquidity during a spike in value. If the removed amount falls below this value, the transaction reverts. |
| *amountBMin* | uint    | Sets the minimum amount of *tokenB* to be removed from the the pool. This acts as a safeguard against removing liquidity during a spike in value. If the removed amount falls below this value, the transaction reverts. |
| *to*         | address | The address to where the redeemed tokens will be sent.                                                                                                                                                                   |
| *deadline*   | uint    | The UNIX timestamp for which this transaction must be completed. If the transaction is mined after this deadline, the transaction will revert.                                                                           |

#### Function Return Parameter Breakdown

| Parameter | Title | Description                                                                      |
| --------- | ----- | -------------------------------------------------------------------------------- |
| *amountA* | uint  | The exact amount of *tokenA* sent to the address provided in the *to* parameter. |
| *amountB* | uint  | The exact amount of *tokenB* sent to the address provided in the *to* parameter. |

### removeLiquidityETH

```
function removeLiquidityETH(
        address token,
        uint liquidity,
        uint amountTokenMin,
        uint amountETHMin,
        address to,
        uint deadline
) external returns (uint amountToken, uint amountETH);
```

The `removeLiquidityETH` function removes BNB as well as the corresponding paired token in the liquidity pool. In other words, this function is used when the pool consists of WBNB and a BEP-20 token.

* In the event one of the assets is paired with BNB, BNB has been wrapped into WBNB (Wrapped BNB). This function will unwrap the WBNB as the liquidity removed. If the user wishes to withdraw WBNB instead of withdrawing as BNB, the `removeLiquidity` function should be used.

#### Function Parameter Breakdown

| Parameter        | Type    | Description                                                                                                                                                                                                             |
| ---------------- | ------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| *token*          | address | Token address of the BEP-20 asset in the pair.                                                                                                                                                                          |
| *liquidity*      | uint    | The amount of liquidity tokens to be redeemed and removed.                                                                                                                                                              |
| *amountTokenMin* | uint    | Sets the minimum amount of *token* to be removed from the the pool. This acts as a safeguard against removing liquidity during a spike in value. If the removed amount falls below this value, the transaction reverts. |
| *amountETHMin*   | uint    | Sets the minimum amount of BNB to be removed from the the pool. This acts as a safeguard against removing liquidity during a spike in value. If the removed amount falls below this value, the transaction reverts.     |
| *to*             | address | The address to where BNB and token will be sent.                                                                                                                                                                        |
| *deadline*       | uint    | The UNIX timestamp for which this transaction must be completed. If the transaction is mined after this deadline, the transaction will revert.                                                                          |

#### Function Return Parameter Breakdown

| Parameter     | Value | Description                                                                     |
| ------------- | ----- | ------------------------------------------------------------------------------- |
| *amountToken* | uint  | The exact amount of *token* sent to the address provided in the *to* parameter. |
| *amountETH*   | uint  | The exact amount of BNB sent to the address provided in the *to* parameter.     |

### removeLiquidityWithPermit

```
function removeLiquidityWithPermit(
        address tokenA,
        address tokenB,
        uint liquidity,
        uint amountAMin,
        uint amountBMin,
        address to,
        uint deadline,
        bool approveMax, uint8 v, bytes32 r, bytes32 s
) external returns (uint amountA, uint amountB);
```

The `removeLiquidityWithPermit` functions removes the two tokens that make up liquidity from a pool. In other words, this function is used when the pool consists of two BEP-20 tokens. This function operates similarly to the `removeLiquidity` function with the added benefit of not requiring pre-approvals using [permit function](https://docs.unifiprotocol.com/utrade-v2/binance-smart-chain/unifierc20.sol#permit) from the BEP-20 contract.

* In the event one of the assets is paired with BNB, BNB will have been wrapped and paired with WBNB (Wrapped BNB). If the user wishes to withdraw WBNB instead of withdrawing as BNB, this function should be used instead of `removeLiquidityETHWithPermit` .

#### Function Parameter Breakdown

| Parameter    | Type    | Description                                                                                                                                                                                                              |
| ------------ | ------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| *tokenA*     | address | Token address of the first asset in the pair.                                                                                                                                                                            |
| *tokenB*     | address | Token address of the second asset in the pair.                                                                                                                                                                           |
| *liquidity*  | uint    | The amount of liquidity tokens to be redeemed and removed.                                                                                                                                                               |
| *amountAMin* | uint    | Sets the minimum amount of *tokenA* to be removed from the the pool. This acts as a safeguard against removing liquidity during a spike in value. If the removed amount falls below this value, the transaction reverts. |
| *amountBMin* | uint    | Sets the minimum amount of *tokenB* to be removed from the the pool. This acts as a safeguard against removing liquidity during a spike in value. If the removed amount falls below this value, the transaction reverts. |
| *to*         | address | The address to where the redeemed tokens will be sent.                                                                                                                                                                   |
| *deadline*   | uint    | The UNIX timestamp for which this transaction must be completed. If the transaction is mined after this deadline, the transaction will revert.                                                                           |
| *approveMax* | bool    | Sets a true or false value on if approval amount in the signature is for liquidity or for uint(-1).                                                                                                                      |
| *v*          | uint8   | The v value of the permit. This is one of the three values that makes up the approval signature.                                                                                                                         |
| *r*          | bytes32 | The r value of the permit. This is one of the three values that makes up the approval signature.                                                                                                                         |
| *s*          | bytes32 | The s value of the permit. This is one of the three values that makes up the approval signature.                                                                                                                         |

#### Function Return Parameter Breakdown

| Parameter | Title | Description                                                                      |
| --------- | ----- | -------------------------------------------------------------------------------- |
| *amountA* | uint  | The exact amount of *tokenA* sent to the address provided in the *to* parameter. |
| *amountB* | uint  | The exact amount of *tokenB* sent to the address provided in the *to* parameter. |

### removeLiquidityETHWithPermit

```
function removeLiquidityETHWithPermit(
        address token,
        uint liquidity,
        uint amountTokenMin,
        uint amountETHMin,
        address to,
        uint deadline,
        bool approveMax, uint8 v, bytes32 r, bytes32 s
) external returns (uint amountToken, uint amountETH);
    
```

The `removeLiquidityETHWithPermit` function removes BNB as well as the corresponding paired token in the liquidity pool. In other words, this function is used when the pool consists of WBNB and a BEP-20 token. This function operates similarly to the `removeLiquidityETH`function with the added benefit of not requiring pre-approvals using [permit function](https://docs.unifiprotocol.com/utrade-v2/binance-smart-chain/unifierc20.sol#permit) from the BEP-20 contract.

* In the event one of the assets is paired with BNB, BNB has been wrapped into WBNB (Wrapped BNB). This function will unwrap the WBNB as the liquidity removed. If the user wishes to withdraw WBNB instead of withdrawing as BNB, the `removeLiquidityWithPermit` function should be used.

#### Function Parameter Breakdown

| Parameter        | Type    | Description                                                                                                                                                                                                             |
| ---------------- | ------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| *token*          | address | Token address of the BEP-20 asset in the pair.                                                                                                                                                                          |
| *liquidity*      | uint    | The amount of liquidity tokens to be redeemed and removed.                                                                                                                                                              |
| *amountTokenMin* | uint    | Sets the minimum amount of *token* to be removed from the the pool. This acts as a safeguard against removing liquidity during a spike in value. If the removed amount falls below this value, the transaction reverts. |
| *amountETHMin*   | uint    | Sets the minimum amount of BNB to be removed from the the pool. This acts as a safeguard against removing liquidity during a spike in value. If the removed amount falls below this value, the transaction reverts.     |
| *to*             | address | The address to where BNB and token will be sent.                                                                                                                                                                        |
| *deadline*       | uint    | The UNIX timestamp for which this transaction must be completed. If the transaction is mined after this deadline, the transaction will revert.                                                                          |
| *v*              | uint8   | The v value of the permit. This is one of the three values that makes up the approval signature.                                                                                                                        |
| *r*              | bytes32 | The r value of the permit. This is one of the three values that makes up the approval signature.                                                                                                                        |
| *s*              | bytes32 | The s value of the permit. This is one of the three values that makes up the approval signature.                                                                                                                        |

#### Function Return Parameter Breakdown

| Parameter     | Value | Description                                                                     |
| ------------- | ----- | ------------------------------------------------------------------------------- |
| *amountToken* | uint  | The exact amount of *token* sent to the address provided in the *to* parameter. |
| *amountETH*   | uint  | The exact amount of BNB sent to the address provided in the *to* parameter.     |

### removeLiquidityETHSupportingFeeOnTransferTokens

```
function removeLiquidityETHSupportingFeeOnTransferTokens(
        address token,
        uint liquidity,
        uint amountTokenMin,
        uint amountETHMin,
        address to,
        uint deadline
) external returns (uint amountETH);
```

The `removeLiquidityETHSupportingFeeOnTransferTokens`function is similar to the `removeLiquidityETH` function, and contains the same call parameters. This function removes BNB as well as the corresponding paired token in the liquidity pool. In other words, this function is used when the pool consists of WBNB and a BEP-20 token.&#x20;

However, this function allows for fee on transfer tokens, such as PAXG, to be used on uTrade.&#x20;

#### Function Parameter Breakdown

| Parameter        | Type    | Description                                                                                                                                                                                                             |
| ---------------- | ------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| *token*          | address | Token address of the BEP-20 asset in the pair.                                                                                                                                                                          |
| *liquidity*      | uint    | The amount of liquidity tokens to be redeemed and removed.                                                                                                                                                              |
| *amountTokenMin* | uint    | Sets the minimum amount of *token* to be removed from the the pool. This acts as a safeguard against removing liquidity during a spike in value. If the removed amount falls below this value, the transaction reverts. |
| *amountETHMin*   | uint    | Sets the minimum amount of BNB to be removed from the the pool. This acts as a safeguard against removing liquidity during a spike in value. If the removed amount falls below this value, the transaction reverts.     |
| *to*             | address | The address to where BNB and the paired token will be sent.                                                                                                                                                             |
| *deadline*       | uint    | The UNIX timestamp for which this transaction must be completed. If the transaction is mined after this deadline, the transaction will revert.                                                                          |

#### Function Return Parameter Breakdown

| Parameter   | Value | Description                                                                                                                                                                                                                   |
| ----------- | ----- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| *amountETH* | uint  | The exact amount of BNB sent to the address provided in the *to* parameter. Note that the *amountToken* parameter is not returned. The amount of fee on transfer that a token may have is not available prior to transaction. |

### removeLiquidityETHWithPermitSupportingFeeOnTransferTokens

```
function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens(
        address token,
        uint liquidity,
        uint amountTokenMin,
        uint amountETHMin,
        address to,
        uint deadline,
        bool approveMax, uint8 v, bytes32 r, bytes32 s
) external returns (uint amountETH);
```

The `removeLiquidityETHWithPermitSupportingFeeOnTransferTokens`function is similar to the `removeLiquidityETHWithPermit`function. This function removes BNB as well as the corresponding paired token in the liquidity pool. In other words, this function is used when the pool consists of WBNB and a BEP-20 token. This function operates similarly to the `removeLiquidityETHfunction` with the added benefit of not requiring pre-approvals using [permit function](https://docs.unifiprotocol.com/utrade-v2/binance-smart-chain/unifierc20.sol#permit) from the BEP-20 contract. In addition, this function allows for fee on transfer tokens, such as PAXG, to be used on uTrade.&#x20;

#### Function Parameter Breakdown

| Parameter        | Type    | Description                                                                                                                                                                                                             |
| ---------------- | ------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| *token*          | address | Token address of the BEP-20 asset in the pair.                                                                                                                                                                          |
| *liquidity*      | uint    | The amount of liquidity tokens to be redeemed and removed.                                                                                                                                                              |
| *amountTokenMin* | uint    | Sets the minimum amount of *token* to be removed from the the pool. This acts as a safeguard against removing liquidity during a spike in value. If the removed amount falls below this value, the transaction reverts. |
| *amountETHMin*   | uint    | Sets the minimum amount of BNB to be removed from the the pool. This acts as a safeguard against removing liquidity during a spike in value. If the removed amount falls below this value, the transaction reverts.     |
| *to*             | address | The address to where BNB and token will be sent.                                                                                                                                                                        |
| *deadline*       | uint    | The UNIX timestamp for which this transaction must be completed. If the transaction is mined after this deadline, the transaction will revert.                                                                          |
| *v*              | uint8   | The v value of the permit. This is one of the three values that makes up the approval signature.                                                                                                                        |
| *r*              | bytes32 | The r value of the permit. This is one of the three values that makes up the approval signature.                                                                                                                        |
| *s*              | bytes32 | The s value of the permit. This is one of the three values that makes up the approval signature.                                                                                                                        |

#### Function Return Parameter Breakdown

| Parameter   | Value | Description                                                                                                                                                                                                                   |
| ----------- | ----- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| *amountETH* | uint  | The exact amount of BNB sent to the address provided in the *to* parameter. Note that the *amountToken* parameter is not returned. The amount of fee on transfer that a token may have is not available prior to transaction. |

## State-Changing Functions - Swap

### swapExactTokensForTokens

```
function swapExactTokensForTokens(
        uint amountIn,
        uint amountOutMin,
        address[] calldata path,
        address to,
        uint deadline
) external returns (uint[] memory amounts);
```

The `swapExactTokensForTokens` function sends an exact amount of tokens for the maximum amount of another token.&#x20;

#### Function Parameter Breakdown

| Parameter      | Type                | Description                                                                                                                                                                                                                                                                                                                                                                                                                            |
| -------------- | ------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| *amountIn*     | uint                | The amount of tokens being sent to swap into another token                                                                                                                                                                                                                                                                                                                                                                             |
| *amountOutMin* | uint                | Sets the minimum amount of the desired token to receive. This acts as a safeguard against removing liquidity during a spike in value. If the amount to be received falls below this value, the transaction reverts.                                                                                                                                                                                                                    |
| *path*         | address\[] calldata | <p>The pathway to change one token to another, consisting of an array of addresses. Each token must have an existing liquidity pool, as well as have liquidity.<br></p><p>The <em>path</em> represents the pathway from one token to another. If a pair exists for the two tokens you wish to exchange, this will contain two values inside of an array. However, if there is no direct pair, multiple addresses may be required. </p> |
| *to*           | address             | The address to where the desired token will be sent.                                                                                                                                                                                                                                                                                                                                                                                   |
| *deadline*     | uint                | The UNIX timestamp for which this transaction must be completed. If the transaction is mined after this deadline, the transaction will revert.                                                                                                                                                                                                                                                                                         |

#### Function Return Parameter Breakdown

| Parameter | Type           | Description                                                                                                |
| --------- | -------------- | ---------------------------------------------------------------------------------------------------------- |
| *amounts* | uint\[] memory | The exact amount of tokens sent into the swap, as well as the exact return amount of all subsequent swaps. |

### swapTokensForExactTokens

```
function swapTokensForExactTokens(
        uint amountOut,
        uint amountInMax,
        address[] calldata path,
        address to,
        uint deadline
) external returns (uint[] memory amounts);
```

The `swapTokensForExactTokens` function sends the minimum amount of tokens for the exact amount of another token.&#x20;

#### Function Parameter Breakdown

| Parameter     | Type                | Description                                                                                                                                                                                                                                                                                                                                                                                                                            |
| ------------- | ------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| *amountOut*   | uint                | The exact amount of the desired tokens to be received.                                                                                                                                                                                                                                                                                                                                                                                 |
| *amountInMax* | uint                | Sets the maximum amount of token to be sent in. This acts as a safeguard against removing liquidity during a spike in value. If the amount to be sent rises above this value, the transaction reverts.                                                                                                                                                                                                                                 |
| *path*        | address\[] calldata | <p>The pathway to change one token to another, consisting of an array of addresses. Each token must have an existing liquidity pool, as well as have liquidity.<br></p><p>The <em>path</em> represents the pathway from one token to another. If a pair exists for the two tokens you wish to exchange, this will contain two values inside of an array. However, if there is no direct pair, multiple addresses may be required. </p> |
| *to*          | address             | The address to where the desired token will be sent.                                                                                                                                                                                                                                                                                                                                                                                   |
| *deadline*    | uint                | The UNIX timestamp for which this transaction must be completed. If the transaction is mined after this deadline, the transaction will revert.                                                                                                                                                                                                                                                                                         |

#### Function Return Parameter Breakdown

| Parameter | Type           | Description                                                                                                |
| --------- | -------------- | ---------------------------------------------------------------------------------------------------------- |
| *amounts* | uint\[] memory | The exact amount of tokens sent into the swap, as well as the exact return amount of all subsequent swaps. |

### swapExactETHForTokens

```
function swapExactETHForTokens(
        uint amountOutMin, 
        address[] calldata path, 
        address to, 
        uint deadline)
        external
        payable
returns (uint[] memory amounts);
```

The `swapExactETHForTokens` function sends an exact amount of BNB for a desired token.

#### Function Parameter Breakdown

| Parameter                                           | Type                | Description                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    |
| --------------------------------------------------- | ------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| <p><em>(amountIn)</em></p><p><em>msg.value</em></p> | uint                | Sent as the msg.value, the amount of BNB to be swapped.                                                                                                                                                                                                                                                                                                                                                                                                                                                                        |
| *amountOutMin*                                      | uint                | Sets the minimum amount of the desired token to receive. This acts as a safeguard against removing liquidity during a spike in value. If the amount to be received falls below this value, the transaction reverts.                                                                                                                                                                                                                                                                                                            |
| *path*                                              | address\[] calldata | <p>The pathway to change one token to another, consisting of an array of addresses. Each token must have an existing liquidity pool, as well as have liquidity.<br></p><p>The <em>path</em> represents the pathway from one token to another. If a pair exists for the two tokens you wish to exchange, this will contain two values inside of an array. However, if there is no direct pair, multiple addresses may be required. </p><p></p><p>As the first swap is swapping BNB to WBNB, the first address must be WBNB.</p> |
| *to*                                                | address             | The address to where the desired token will be sent.                                                                                                                                                                                                                                                                                                                                                                                                                                                                           |
| *deadline*                                          | uint                | The UNIX timestamp for which this transaction must be completed. If the transaction is mined after this deadline, the transaction will revert.                                                                                                                                                                                                                                                                                                                                                                                 |

#### Function Return Parameter Breakdown

| Parameter | Type           | Description                                                                                             |
| --------- | -------------- | ------------------------------------------------------------------------------------------------------- |
| *amounts* | uint\[] memory | The exact amount of BNB sent into the swap, as well as the exact return amount of all subsequent swaps. |

### swapTokensForExactETH

```
function swapTokensForExactETH(
        uint amountOut, 
        uint amountInMax, 
        address[] calldata path, 
        address to, 
        uint deadline)
        external
        returns (uint[] memory amounts);
```

The `swapTokensForExactETH` function sends an amount of tokens for an exact amount of BNB.

#### Function Parameter Breakdown

| Parameter     | Type                | Description                                                                                                                                                                                                                                                                                                                                                                                                                            |
| ------------- | ------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| *amountOut*   | uint                | The exact amount of the BNB to be received.                                                                                                                                                                                                                                                                                                                                                                                            |
| *amountInMax* | uint                | Sets the maximum amount of token to be sent in. This acts as a safeguard against removing liquidity during a spike in value. If the amount to be sent rises above this value, the transaction reverts.                                                                                                                                                                                                                                 |
| *path*        | address\[] calldata | <p>The pathway to change one token to another, consisting of an array of addresses. Each token must have an existing liquidity pool, as well as have liquidity.<br></p><p>The <em>path</em> represents the pathway from one token to another. If a pair exists for the two tokens you wish to exchange, this will contain two values inside of an array. However, if there is no direct pair, multiple addresses may be required. </p> |
| *to*          | address             | The address to where the desired token will be sent.                                                                                                                                                                                                                                                                                                                                                                                   |
| *deadline*    | uint                | The UNIX timestamp for which this transaction must be completed. If the transaction is mined after this deadline, the transaction will revert.                                                                                                                                                                                                                                                                                         |

#### Function Return Parameter Breakdown

| Parameter | Type           | Description                                                                                         |
| --------- | -------------- | --------------------------------------------------------------------------------------------------- |
| *amounts* | uint\[] memory | The exact amount of tokens sent into the swap, as well as the exact amount of all subsequent swaps. |

### swapExactTokensForETH

```
function swapExactTokensForETH(
        uint amountIn, 
        uint amountOutMin, 
        address[] calldata path, 
        address to, 
        uint deadline)
        external
        returns (uint[] memory amounts);
```

The `swapExactTokensForETH` function sends an exact amount of tokens for BNB.

#### Function Parameter Breakdown

| Parameter      | Type                | Description                                                                                                                                                                                                                                                                                                                                                                                                                            |
| -------------- | ------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| *amountIn*     | uint                | The amount of tokens being sent to swap into BNB.                                                                                                                                                                                                                                                                                                                                                                                      |
| *amountOutMin* | uint                | Sets the minimum amount of the BNB to receive. This acts as a safeguard against removing liquidity during a spike in value. If the amount to be received falls below this value, the transaction reverts.                                                                                                                                                                                                                              |
| *path*         | address\[] calldata | <p>The pathway to change one token to another, consisting of an array of addresses. Each token must have an existing liquidity pool, as well as have liquidity.<br></p><p>The <em>path</em> represents the pathway from one token to another. If a pair exists for the two tokens you wish to exchange, this will contain two values inside of an array. However, if there is no direct pair, multiple addresses may be required. </p> |
| *to*           | address             | The address to where the desired token will be sent.                                                                                                                                                                                                                                                                                                                                                                                   |
| *deadline*     | uint                | The UNIX timestamp for which this transaction must be completed. If the transaction is mined after this deadline, the transaction will revert.                                                                                                                                                                                                                                                                                         |

#### Function Parameter Return Breakdown

| Parameter | Type           | Description                                                                                         |
| --------- | -------------- | --------------------------------------------------------------------------------------------------- |
| *amounts* | uint\[] memory | The exact amount of tokens sent into the swap, as well as the exact amount of all subsequent swaps. |

### swapETHForExactTokens

```
function swapETHForExactTokens(
        uint amountOut, 
        address[] calldata path, 
        address to, 
        uint deadline)
        external
        payable
        returns (uint[] memory amounts);
```

The `swapETHForExactTokens` function swaps an exact amount of BNB for an amount of the desired token.

#### Function Parameter Breakdown

| Parameter                                           | Type                | Description                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    |
| --------------------------------------------------- | ------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| <p><em>(amountIn)</em></p><p><em>msg.value</em></p> | uint                | Sent as the msg.value, the amount of BNB to be swapped.                                                                                                                                                                                                                                                                                                                                                                                                                                                                        |
| *amountOutMin*                                      | uint                | Sets the minimum amount of the desired token to receive. This acts as a safeguard against removing liquidity during a spike in value. If the amount to be received falls below this value, the transaction reverts.                                                                                                                                                                                                                                                                                                            |
| *path*                                              | address\[] calldata | <p>The pathway to change one token to another, consisting of an array of addresses. Each token must have an existing liquidity pool, as well as have liquidity.<br></p><p>The <em>path</em> represents the pathway from one token to another. If a pair exists for the two tokens you wish to exchange, this will contain two values inside of an array. However, if there is no direct pair, multiple addresses may be required. </p><p></p><p>As the first swap is swapping BNB to WBNB, the first address must be WBNB.</p> |
| *to*                                                | address             | The address to where the desired token will be sent.                                                                                                                                                                                                                                                                                                                                                                                                                                                                           |
| *deadline*                                          | uint                | The UNIX timestamp for which this transaction must be completed. If the transaction is mined after this deadline, the transaction will revert.                                                                                                                                                                                                                                                                                                                                                                                 |

#### Function Return Parameter Breakdown

| Parameter | Type           | Description                                                                                             |
| --------- | -------------- | ------------------------------------------------------------------------------------------------------- |
| *amounts* | uint\[] memory | The exact amount of BNB sent into the swap, as well as the exact return amount of all subsequent swaps. |

### swapExactTokensForTokensSupportingFeeOnTransferTokens

```
function swapExactTokensForTokensSupportingFeeOnTransferTokens(
        uint amountIn,
        uint amountOutMin,
        address[] calldata path,
        address to,
        uint deadline
) external;
```

The `swapExactTokensForTokensSupportingFeeOnTransferTokens` function is similar to `swapExactTokensForTokens` as it swaps one BEP-20 token for another BEP-20 token. In addition, this function allows for fee on transfer tokens, such as PAXG, to be used on uTrade.

#### Function Parameter Breakdown

| Name           | Type                |                                                                                                                                                                                                                                                                                                                                                                                                                              |
| -------------- | ------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| *amountIn*     | uint                | The amount of tokens being sent to swap into BNB.                                                                                                                                                                                                                                                                                                                                                                            |
| *amountOutMin* | uint                | Sets the minimum amount of the desired token to receive. This acts as a safeguard against removing liquidity during a spike in value. If the amount to be received falls below this value, the transaction reverts.                                                                                                                                                                                                          |
| *path*         | address\[] calldata | <p>The pathway to change one token to another, consisting of an array of addresses. Each token must have an existing liquidity pool, as well as have liquidity.<br></p><p>The path represents the pathway from one token to another. If a pair exists for the two tokens you wish to exchange, this will contain two values inside of an array. However, if there is no direct pair, multiple addresses may be required.</p> |
| *to*           | address             | The address to where the desired token will be sent.                                                                                                                                                                                                                                                                                                                                                                         |
| *deadline*     | uint                | The UNIX timestamp for which this transaction must be completed. If the transaction is mined after this deadline, the transaction will revert.                                                                                                                                                                                                                                                                               |

### swapExactETHForTokensSupportingFeeOnTransferTokens

```
function swapExactETHForTokensSupportingFeeOnTransferTokens(
        uint amountOutMin,
        address[] calldata path,
        address to,
        uint deadline
 ) external payable;
```

The `swapExactETHForTokensSupportingFeeOnTransferTokens`function  is similar to `swapExactETHForTokens` function as it swaps an exact amount of BNB for BEP-20 tokens. In addition, this function allows for fee on transfer tokens, such as PAXG, to be used on uTrade.&#x20;

#### Function Parameter Breakdown

| Parameter                                           | Type                | Description                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    |
| --------------------------------------------------- | ------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| <p><em>(amountIn)</em></p><p><em>msg.value</em></p> | uint                | Sent as the msg.value, the exact amount of BNB to be swapped.                                                                                                                                                                                                                                                                                                                                                                                                                                                                  |
| *amountOutMin*                                      | uint                | Sets the minimum amount of the desired token to receive. This acts as a safeguard against removing liquidity during a spike in value. If the amount to be received falls below this value, the transaction reverts.                                                                                                                                                                                                                                                                                                            |
| *path*                                              | address\[] calldata | <p>The pathway to change one token to another, consisting of an array of addresses. Each token must have an existing liquidity pool, as well as have liquidity.<br></p><p>The <em>path</em> represents the pathway from one token to another. If a pair exists for the two tokens you wish to exchange, this will contain two values inside of an array. However, if there is no direct pair, multiple addresses may be required. </p><p></p><p>As the first swap is swapping BNB to WBNB, the first address must be WBNB.</p> |
| *to*                                                | address             | The address to where the desired token will be sent.                                                                                                                                                                                                                                                                                                                                                                                                                                                                           |
| *deadline*                                          | uint                | The UNIX timestamp for which this transaction must be completed. If the transaction is mined after this deadline, the transaction will revert.                                                                                                                                                                                                                                                                                                                                                                                 |

### swapExactTokensForETHSupportingFeeOnTransferTokens <a href="#swapexacttokensforethsupportingfeeontransfertokens" id="swapexacttokensforethsupportingfeeontransfertokens"></a>

```
function swapExactTokensForETHSupportingFeeOnTransferTokens(
        uint amountIn,
        uint amountOutMin,
        address[] calldata path,
        address to,
        uint deadline
) external;
```

The function `swapExactTokensForETHSupportingFeeOnTransferTokens`is similar to the `swapExactTokensForETH`function, as it swaps an exact amount of BEP-20 tokens for BNB. In addition, this function allows for fee on transfer tokens, such as PAXG, to be used on uTrade.

#### Function Parameter Breakdown

| Parameter      | Type                | Description                                                                                                                                                                                                                                                                                                                                                                                                                            |
| -------------- | ------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| *amountIn*     | uint                | The amount of tokens being sent to swap into BNB.                                                                                                                                                                                                                                                                                                                                                                                      |
| *amountOutMin* | uint                | Sets the minimum amount of the BNB to receive. This acts as a safeguard against removing liquidity during a spike in value. If the amount to be received falls below this value, the transaction reverts.                                                                                                                                                                                                                              |
| *path*         | address\[] calldata | <p>The pathway to change one token to another, consisting of an array of addresses. Each token must have an existing liquidity pool, as well as have liquidity.<br></p><p>The <em>path</em> represents the pathway from one token to another. If a pair exists for the two tokens you wish to exchange, this will contain two values inside of an array. However, if there is no direct pair, multiple addresses may be required. </p> |
| *to*           | address             | The address to where the desired token will be sent.                                                                                                                                                                                                                                                                                                                                                                                   |
| *deadline*     | uint                | The UNIX timestamp for which this transaction must be completed. If the transaction is mined after this deadline, the transaction will revert.                                                                                                                                                                                                                                                                                         |

## Interface Code

```
interface IUnifiRouter01 {
    function factory() external pure returns (address);
    function WETH() external pure returns (address);

    function addLiquidity(
        address tokenA,
        address tokenB,
        uint amountADesired,
        uint amountBDesired,
        uint amountAMin,
        uint amountBMin,
        address to,
        uint deadline
    ) external returns (uint amountA, uint amountB, uint liquidity);
    function addLiquidityETH(
        address token,
        uint amountTokenDesired,
        uint amountTokenMin,
        uint amountETHMin,
        address to,
        uint deadline
    ) external payable returns (uint amountToken, uint amountETH, uint liquidity);
    function removeLiquidity(
        address tokenA,
        address tokenB,
        uint liquidity,
        uint amountAMin,
        uint amountBMin,
        address to,
        uint deadline
    ) external returns (uint amountA, uint amountB);
    function removeLiquidityETH(
        address token,
        uint liquidity,
        uint amountTokenMin,
        uint amountETHMin,
        address to,
        uint deadline
    ) external returns (uint amountToken, uint amountETH);
    function removeLiquidityWithPermit(
        address tokenA,
        address tokenB,
        uint liquidity,
        uint amountAMin,
        uint amountBMin,
        address to,
        uint deadline,
        bool approveMax, uint8 v, bytes32 r, bytes32 s
    ) external returns (uint amountA, uint amountB);
    function removeLiquidityETHWithPermit(
        address token,
        uint liquidity,
        uint amountTokenMin,
        uint amountETHMin,
        address to,
        uint deadline,
        bool approveMax, uint8 v, bytes32 r, bytes32 s
    ) external returns (uint amountToken, uint amountETH);
    function swapExactTokensForTokens(
        uint amountIn,
        uint amountOutMin,
        address[] calldata path,
        address to,
        uint deadline
    ) external returns (uint[] memory amounts);
    function swapTokensForExactTokens(
        uint amountOut,
        uint amountInMax,
        address[] calldata path,
        address to,
        uint deadline
    ) external returns (uint[] memory amounts);
    function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline)
        external
        payable
        returns (uint[] memory amounts);
    function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline)
        external
        returns (uint[] memory amounts);
    function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline)
        external
        returns (uint[] memory amounts);
    function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline)
        external
        payable
        returns (uint[] memory amounts);

    function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB);
    function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut, uint fee) external pure returns (uint amountOut);
    function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut, uint fee) external pure returns (uint amountIn);
    function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts);
    function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts);
}

interface IUnifiRouter02 is IUnifiRouter01 {
    function removeLiquidityETHSupportingFeeOnTransferTokens(
        address token,
        uint liquidity,
        uint amountTokenMin,
        uint amountETHMin,
        address to,
        uint deadline
    ) external returns (uint amountETH);
    function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens(
        address token,
        uint liquidity,
        uint amountTokenMin,
        uint amountETHMin,
        address to,
        uint deadline,
        bool approveMax, uint8 v, bytes32 r, bytes32 s
    ) external returns (uint amountETH);

    function swapExactTokensForTokensSupportingFeeOnTransferTokens(
        uint amountIn,
        uint amountOutMin,
        address[] calldata path,
        address to,
        uint deadline
    ) external;
    function swapExactETHForTokensSupportingFeeOnTransferTokens(
        uint amountOutMin,
        address[] calldata path,
        address to,
        uint deadline
    ) external payable;
    function swapExactTokensForETHSupportingFeeOnTransferTokens(
        uint amountIn,
        uint amountOutMin,
        address[] calldata path,
        address to,
        uint deadline
    ) external;
}
```


# BitTorrent Chain

Here you will find in-depth detail of the contracts that make up uTrade V2 on BitTorrent Chain. Each contract includes JSONs as well as Typescript files for integration into your project. Every effort is made to open-source all aspects of uTrade V2, but some do remain private.  When a contract is available, you will find a link to the Github source code.


# singleLiquidityWrapper.sol

**Primary Uses -** Unique to uTrade, the Single Liquidity Wrapper allows BTT or any BRC-20 token on BTT to converted into a LP pool. For example, USDT can be added using the wrapper to supply liquidity for a USDT.t / WBTT 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)        | [GitHub](https://github.com/unifiprotocol/utrade-contracts/blob/main/BTT/SingleLiquidity/singleLiquidityWrapper.sol)                              |
| 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                                                                                                                         |
| ---------------- | ------------------------------------------------------------------------------------------------------------------------------- |
| BitTorrent Chain | `0xb986284c89cc9ca5427582222f5e1af4ea0ef99c` ([Link](https://scan.bt.io/#/contract/0xb986284c89cc9ca5427582222f5e1af4ea0ef99c)) |

###

### 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;

<table data-header-hidden><thead><tr><th>Parameter</th><th width="150">Type</th><th>Description</th></tr></thead><tbody><tr><td>Parameter</td><td>Type</td><td>Description</td></tr><tr><td><em>tokenA</em></td><td>address</td><td>The contract address of the provided token to be converted into the LP token.</td></tr><tr><td><em>requireToken</em></td><td>address</td><td>The contract address of the other token in the liquidity pool. In other words, the asset that half of <em>tokenA</em> will be converted to that will be added to the liquidity pool.</td></tr><tr><td><em>amount</em></td><td>uint</td><td>The amount of <em>tokenA</em> to be sent to the liquidity pool.</td></tr><tr><td><em>to</em></td><td>address</td><td>The recipient of the LP tokens.</td></tr><tr><td><em>minOut</em></td><td>uint</td><td>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.</td></tr></tbody></table>

### convertSingleAssetToLiquidityEth

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

The `convertSingleAssetToLiquidityETH`function converts BTT into a LP token. It does so by first converting the provided BTT 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 BTT value is sent as a msg.value parameter. One of the two assets can be WBTT.

#### Parameter Breakdown

<table data-header-hidden><thead><tr><th width="183.71006253553153">Parameter</th><th>Type</th><th>Description</th></tr></thead><tbody><tr><td>Parameter</td><td>Type</td><td>Description</td></tr><tr><td><em>amountIn</em><br><em>(msg.value)</em></td><td>uint</td><td>The amount of BTT to be converted to the two tokens that make up a liquidity pool. Sent as the message value.</td></tr><tr><td><em>requireToken</em></td><td>address</td><td>The address of the LP token token contract that is being supplied.</td></tr><tr><td><em>to</em></td><td>address</td><td>The recipient of the LP tokens.</td></tr><tr><td><em>minOut</em></td><td>uint</td><td>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.</td></tr></tbody></table>

### 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 BRC-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 BTT to an uTrade V2 LP token made up of two different tokens. In other words, BTT 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 BTT 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 AVAX 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 WBTT'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 AVAX must be converted to WBTT, 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 BTT 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 WBTT'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 BTT must be converted to WBTT, 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 BTT. If true, the *receiveToken* address should be WBTT, as it will unwrap WBTT and send BTT. |
| *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 BTT or any BRC-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 BTT. If true, the *receiveToken* address should be WBTT, as it will unwrap WBTT and send BTT.                                                                                                                                                                                                                                                                                                                              |
| *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 ;
}
```


# UnifiERC20.sol

**Primary Uses -** UnifiERC20.sol essentially ports the properties of BEP-20 tokens on to Unifi LP Tokens, or uTokens. An example of this in practice would be the 'approve' transaction.

## uTrade V2 UnifiERC20 Code / Interfaces

|                                             |                                                                                                   |
| ------------------------------------------- | ------------------------------------------------------------------------------------------------- |
| uTrade V2 UnifiERC20 (Solidity)             | [Github ](https://github.com/unifiprotocol/utrade-contracts/blob/main/BTT/Factory/UnifiERC20.sol) |
| uTrade V2 BTT Interfaces in Solidity        | [Github](https://github.com/unifiprotocol/utrade-contracts/blob/main/BTT/Factory/interfaces.sol)  |
| Import statement codeblock (when available) |                                                                                                   |

## uTrade V2 UnifiERC20 Contract Addresses

Each uTrade V2 Liquidity Pool uses the uTrade V2 ERC20 Interface in the contract.&#x20;

## Events

### Approval

```
event Approval(address indexed owner, address indexed spender, uint value);
```

The `Approval` event is emitted anytime an `approve` or `permit` function is called.

### Transfer

```
event Transfer(address indexed from, address indexed to, uint value);
```

The `Transfer` event is emitted anytime a transfer of LP tokens occurs, by the `transfer`, `transferFrom`, `mint`, or `burn` functions.

## Read-Only Functions

### name

```
function name() external pure returns (string memory);
```

The `name` function will return "Unifi LPs" for all liquidity pool contracts.

### symbol

```
function symbol() external pure returns (string memory);
```

The `symbol` function will return "Unifi-LP" for all liquidity pool contracts.

### decimals

```
function decimals() external pure returns (uint8);
```

The `decimals` function returns "18" as a uint8 value, which is the precision for each uToken on uTrade V2.

### totalSupply

```
function totalSupply() external view returns (uint);
```

The `totalSupply` function returns the total amount uTokens for a pair.

### balanceOf

```
function balanceOf(address owner) external view returns (uint);
```

The `balanceOf` function returns the balance of uTokens for the provided address.

### allowance

```
function allowance(address owner, address spender) external view returns (uint);
```

The `allowance` function returns the amount of tokens an address is approved to transfer when using the `transferFrom` function.

### DOMAIN\_SEPARATOR

```
function DOMAIN_SEPARATOR() external view returns (bytes32);
```

The `DOMAIN_SEPARATOR` function is used in the `permit` function, and is one of the components that allows transactions to get through without a prior approve transaction. Calling a read function returns the bytes32 data that is required for use in `permit` function.

### PERMIT\_TYPEHASH

```
function PERMIT_TYPEHASH() external view returns (bytes32);
```

The `PERMIT_TYPEHASH` function is used in the `permit` function, and is one of the components that allows transactions to get through without a prior approve transaction. Calling a read function returns the bytes32 data that is required for use in the `permit` function.

### nonces

```
function nonces(address owner) external view returns (uint);
```

The `nonces` function is used in the permit function. It returns the current nonce of the *address* provided.

## State-Changing Functions

### approve

```
function approve(address spender, uint value) external returns (bool);
```

The `approve` function sets a *value* for  the amount of LP tokens the *address* provided is allowed to transfer. Returns a boolean value and emits the `Approval` event.

### transfer

```
function transfer(address to, uint value) external returns (bool);
```

The `transfer` function lets an address send uTokens from one address to another, and returns a boolean value and emits a `Transfer` event.

### transferFrom

```
function transferFrom(address from, address to, uint value) external returns (bool);
```

The `transferFrom` function sends uTokens from one address to another. This requires the sending address to have approval to send uTokens. Returns a boolean value and emits a `Transfer`event.

### permit

```
function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external;
```

The permit function allows a sender to use a signature in lieu of an approval transaction, and sets the allowance for an address to send.

#### Function Parameter Breakdown

| Parameter  | Type    | Description                                                                                                                                    |
| ---------- | ------- | ---------------------------------------------------------------------------------------------------------------------------------------------- |
| *owner*    | address | The owner of the address.                                                                                                                      |
| *spender*  | address | The spender of the uTokens.                                                                                                                    |
| *value*    | uint    | The amount of uTokens to be transferred.                                                                                                       |
| *deadline* | uint    | The UNIX timestamp for which this transaction must be completed. If the transaction is mined after this deadline, the transaction will revert. |
| *v*        | uint8   | The v value of the permit. This is one of the three values that makes up the approval signature.                                               |
| *r*        | bytes32 | The r value of the permit. This is one of the three values that makes up the approval signature.                                               |
| *s*        | bytes32 | The s value of the permit. This is one of the three values that makes up the approval signature.                                               |

## Interface Code

```
interface IUnifiERC20 {
    event Approval(address indexed owner, address indexed spender, uint value);
    event Transfer(address indexed from, address indexed to, uint value);

    function name() external pure returns (string memory);
    function symbol() external pure returns (string memory);
    function decimals() external pure returns (uint8);
    function totalSupply() external view returns (uint);
    function balanceOf(address owner) external view returns (uint);
    function allowance(address owner, address spender) external view returns (uint);

    function approve(address spender, uint value) external returns (bool);
    function transfer(address to, uint value) external returns (bool);
    function transferFrom(address from, address to, uint value) external returns (bool);

    function DOMAIN_SEPARATOR() external view returns (bytes32);
    function PERMIT_TYPEHASH() external pure returns (bytes32);
    function nonces(address owner) external view returns (uint);

    function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external;
}
```


# UnifiFactory.sol

**Primary Uses** - The uTrade V2 Factory contract creates an LP token for any pairs listed on uTrade V2, and indexes them for easy retrieval. In addition, it can return the address of the LP token based on a call of the addresses of the two tokens that make up the liquidity pool.

## uTrade V2 Factory Code / Interfaces

<table data-header-hidden><thead><tr><th width="277"></th><th></th></tr></thead><tbody><tr><td></td><td></td></tr><tr><td>uTrade V2 Factory (Solidity)</td><td><a href="https://github.com/unifiprotocol/utrade-contracts/blob/main/BTT/Factory/UnifiFactory.sol">GitHub</a></td></tr><tr><td>uTrade V2 Factory Interface as JSON</td><td><a href="https://github.com/unifiprotocol/uTradeV2-core/blob/52d66be2a472b9697a577757a0446076b6c32001/ABI/JSON/IUnifiFactory.json">GitHub</a></td></tr><tr><td>uTrade V2 Factory Interface as Typescript</td><td><a href="https://github.com/unifiprotocol/uTradeV2-core/blob/52d66be2a472b9697a577757a0446076b6c32001/ABI/TS/IUnifiFactory.ts">GitHub</a></td></tr><tr><td>Import statement codeblock (when available)</td><td></td></tr></tbody></table>

## uTrade V2 Factory Contract Addresses

| Network          | Address                                                                                                                         |
| ---------------- | ------------------------------------------------------------------------------------------------------------------------------- |
| BitTorrent Chain | `0xCAaB36C77841647dC9955B3b1D03710E9B9F127f` ([Link](https://scan.bt.io/#/contract/0xcaab36c77841647dc9955b3b1d03710e9b9f127f)) |

## Events

### PairCreated

```
event PairCreated(address indexed token0, address indexed token1, address pair, uint);
```

Anytime a pair is created on uTrade V2 using the `createPair` function, a `PairCreated` event is emitted. Contracts can be deployed to listen for new pairs on the uTrade V2 BTTC Factory address.&#x20;

* *token0* is the token address of the first asset in the token pair.
* *token1* is the token address of the second asset in the token pair.
* *pair* is the address of the newly created uTrade V2 liquidity pool.
* *uint* refers to the index of this uTrade V2 Factor&#x79;*.* For example, the first liquidity pool created on uTrade V2 is 1, the second liquidity pool is 2, and so on. This number can used with the `allPairs(uint)` to return the address. The current number, and therefore the total number of LP pools on uTrade V2 AVAX, can be accessed using the `allPairsLength` function.

## Read-Only Functions <a href="#read-only-functions" id="read-only-functions"></a>

### getPair

```
function getPair(address tokenA, address tokenB) external view returns (address pair);
```

A call to the `getPair` function returns the address of the pair for *tokenA* and *tokenB*.

* If the pair does not exist, the call will return *address(0)*.&#x20;
* The order of the tokens is irrelevant in this call. For example, a call for USDT.t, WBTT will return the same pair address as WBTT, USDT.t&#x20;

### allPairs

```
function allPairs(uint) external view returns (address pair);
```

A call to the `allPairs` function returns the address of a pair based on the indexed *uint* value assigned upon creation of the LP.

* For example, `allPairs(0)` will return the first pair created on uTrade V2 BTTC.
* &#x20;If the index number is too high, as in, there aren't enough pairs created yet, the function will return *address(0)*.

### allPairsLength

```
function allPairsLength() external view returns (uint);
```

A call to the `allPairsLength` function returns the current number of pairs.&#x20;

* For example, if there are 201 total liquidity pool pairs on uTrade V2 BTTC, this call will return *200* as an uint value.

### feeTo

```
function feeTo() external view returns (address);
```

A call to the `feeTo` function returns the percentage of trading fees that Unifi Protocol receives.&#x20;

* Due to the nature of UP Token economics, this is set to zero, but is preserved for flexibility in the future.

### feeToSetter

```
function feeToSetter() external view returns (address);
```

A call to the `feeToSetter` function returns the address to which the `feeTo` would send trading fees, if trading fees were collected.

## State-Changing Functions <a href="#state-changing-functions" id="state-changing-functions"></a>

### createPair

```
function createPair(address tokenA, address tokenB) external returns (address pair);
```

Creates a liquidity pool pair for *tokenA* and *tokenB* if one does not currently exist. After the function is confirmed on chain, a `PairCreated` event is emitted.

## Interface Code

```
interface UnifiFactory {  
  event PairCreated(address indexed token0, address indexed token1, address pair, uint);
  function getPair(address tokenA, address tokenB) external view returns (address pair);  
  function allPairs(uint) external view returns (address pair);  
  function allPairsLength() external view returns (uint);
  function feeTo() external view returns (address);  function feeToSetter() external view returns (address);
  function createPair(address tokenA, address tokenB) external returns (address pair);
  }
```

###


# UnifiPair.sol

**Primary Uses -** UnifiPair.sol is responsible for many of the functionalities of liquidity pool tokens and UP tokens. First, it is responsible for the issuing and burning of Liquidity Pool Tokens (uTokens). In addition, it allows for direct reads of the reserves and ratio of the liquidity pool, as well as swaps. Lastly, it is where UP claims are processed.&#x20;

## uTrade V2 Pair Code / Interfaces

|                                             |                                                                                                       |
| ------------------------------------------- | ----------------------------------------------------------------------------------------------------- |
| uTrade V2 Pair (Solidity)                   | [Github](https://github.com/unifiprotocol/utrade-contracts/blob/main/Avalanche/Factory/UnifiPair.sol) |
| uTrade V2 Pair Interface as JSON            | Link Here                                                                                             |
| uTrade V2 Pair as Typescript                | Link Here                                                                                             |
| Import statement codeblock (when available) |                                                                                                       |

## uTrade V2 Pair Contract Addresses

Each uTrade V2 Liquidity Pool uses the uTrade V2 ERC20 Interface in the contract.&#x20;

## Events

### Mint

```
event Mint(address indexed sender, uint amount0, uint amount1);
```

The `Mint` event is emitted any time liquidity tokens are created via the `mint` function. In other words, when a user adds liquidity to a pair, then they will receive LP tokens, therefore the `Mint` event will be emitted.

### Burn

```
event Burn(address indexed sender, uint amount0, uint amount1, address indexed to);
```

The `Burn` event is emitted any time liquidity tokens are burned via the `burn` function. In other words, when a user removes liquidity from a pair,  their LP tokens will be burned, therefore the `Burn` event will be emitted.

### Swap

```
event Swap(
        address indexed sender,
        uint amount0In,
        uint amount1In,
        uint amount0Out,
        uint amount1Out,
        address indexed to
 );
```

The `Swap` event is emitted any time the `swap` function is used. Under the hood, all trades on uTrade V2 are swaps. Therefore, any time somebody trades on the pair, the uTrade contract for that pair will emit a `Swap` event.

### Sync

```
event Sync(uint112 reserve0, uint112 reserve1);
```

The `Sync` event is emitted anytime a function occurs that may change the reserves of a token pair. In other words, anytime the amount of the two tokens within a liquidity pool may change. Therefore, whenever a`mint`, `burn`, `swap`, or `sync` function is called, the `Sync` event will be emitted.

## Read-Only Functions

### MINIMUM\_LIQUIDITY <a href="#minimum_liquidity" id="minimum_liquidity"></a>

```
function MINIMUM_LIQUIDITY() external pure returns (uint);
```

The `MINIMUM_LIQUIDITY`function will always return 1000. The function itself refers to the burning of initial LP tokens that occurs once when a pool is created. This burn of a tiny amount allows for cleaner LP token numbers therefore avoiding LP tokens being represented as very small decimals value. This allows the tick size to be more precise and prevents rounding errors.

### factory

```
function factory() external view returns (address);
```

The `factory` function will return the current factory address for uTrade V2.

### WBNB

```
function WBNB() external view returns (address);
```

The WBNB function will return the address of WBTT on BTTC. As this does not change, it will always return `0x8D193c6efa90BCFf940A98785d1Ce9D093d3DC8A`.

### token0

```
function token0() external view returns (address);
```

The `token0` function will return the contract address of the first token that makes up the liquidity pair. In other words, if the liquidity pool is made up of USDT.t / WBTT, it will return the contract address of USDT.t.

### token1

```
function token1() external view returns (address);
```

The `token1` function will return the contract address of the first token that makes up the liquidity pair. In other words, if the liquidity pool is made up of USDT.t / WBTT, it will return the contract address of WBTT.

### getReserves

```
function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast);
```

The `getReserves` function returns the reserves of the two tokens that make up the liquidity pool as *reserve0* and *reserve1*. These two values can be helpful in determining the current price of each asset. The function also returns a timestamp with the block number.

### price0CumulativeLast

```
function price0CumulativeLast() external view returns (uint);
```

The `price0CumulativeLast` function is for Oracle usage on uTrade V2. The value of *token0* is captured at the end of each block, and can be called using this function to feed into an Oracle to determine a more time-weighted 'average' price.&#x20;

### price1CumulativeLast

```
function price1CumulativeLast() external view returns (uint);
```

The `price1CumulativeLast` function is for Oracle usage on uTrade V2. The value of *token1* is captured at the end of each block, and can be called using this function to feed into an Oracle to determine a more time-weighted 'average' price.&#x20;

### kLast

```
function kLast() external view returns (uint);
```

The `kLast` function returns the value of *reserve0* \* *reserve1*, after any event that may have triggered a change in the liquidity. For example, the execution of a *swap* function or a *mint* function.

## State-Changing Functions

### mint

```
function mint(address to) external returns (uint liquidity);
```

The `mint` function creates the LP tokens that represent a user's tokens in a liquidity pool. For example, if a user provides 1,000,000 BTT and 10 USDT.t liquidity to a pool, the Unifi Pair Smart Contract will mint an amount of uBTTUSDT.t tokens. Will emit the `Mint`, `Sync`, and `Transfer` events.

### burn

```
function burn(address to) external returns (uint amount0, uint amount1);
```

The `burn` function destroys the LP tokens that represent a user's token in a liquidity pool. For example, if a user removes 1,000,000 BTT and 10 USDT.t liquidity to a pool, the Unifi Pair Smart Contract will burn an amount of uBTTUSDT.t tokens. Will emit the `Burn`, `Sync`, and `Transfer` events.

### claimUP

```
function claimUP(address to) external lock returns(uint) {
```

The `claimUP` function claims any UP earned from providing liquidity if any exists, and sends the UP to the address provided.

### swap

```
function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external;
```

The `swap` function exchanges one token for another. Under the hood, all trades on uTrade V2 use this function. The *calldata* must be 0 during a normal swap, but must contain data if executing a flash loan. Emits the `Swap` and `Sync` events.

### skim

```
function skim(address to) external;
```

The `skim` function operates as a safeguard if the amount of tokens causes a data error due to too large of a number in the reserves pools. In this unusual circumstance, this will trigger failures in trades. The `skim` function can be called to return the overflowed tokens to the caller.

### sync

```
function sync() external;
```

The `sync` function operates as a safeguard in certain events where the token balance changes outside of normal trading. An example would be an algorithmic stablecoin re-balancing, therefore lowering or raising the amount of the algorithmic stablecoin in the pool. The `sync` function may be called to reset the price ratio to the new reserves. Emits the `Sync`event.

## Interface Code

```
interface IUnifiPair {
    event Mint(address indexed sender, uint amount0, uint amount1);
    event Burn(address indexed sender, uint amount0, uint amount1, address indexed to);
    event Swap(
        address indexed sender,
        uint amount0In,
        uint amount1In,
        uint amount0Out,
        uint amount1Out,
        address indexed to
    );
    event Sync(uint112 reserve0, uint112 reserve1);

    function MINIMUM_LIQUIDITY() external pure returns (uint);
    function factory() external view returns (address);
    function token0() external view returns (address);
    function token1() external view returns (address);
    function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast);
    function price0CumulativeLast() external view returns (uint);
    function price1CumulativeLast() external view returns (uint);
    function kLast() external view returns (uint);

    function mint(address to) external returns (uint liquidity);
    function burn(address to) external returns (uint amount0, uint amount1);
    function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external;
    function skim(address to) external;
    function sync() external;

    function initialize(address, address) external;
}
```


# UnifiRouter.sol

**Primary Uses** - The uTrade V2 Router is the 'brain' of uTrade. The router finds the optimal path for exchanging one token for another. Whenever a trade is made, your wallet sends funds to the router address. The router will then carry out as many transactions as necessary to acquire the desired token. The router also handles adding liquidity to liquidity pools, and sending the corresponding LP tokens to liquidity providers.

**Primary Uses** - The uTrade V2 Router is the 'brain' of uTrade. The router finds the optimal path for exchanging one token for another. Whenever a trade is made, your wallet sends funds to the router address. The router will then carry out as many transactions as necessary to acquire the desired token. The router also handles adding liquidity to liquidity pools, and sending the corresponding LP tokens to liquidity providers.

## uTrade V2 Router Code / Interfaces

|                                             |                                                                                                                                   |
| ------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------- |
| uTrade V2 Router (Solidity)                 | [Github](https://github.com/unifiprotocol/utrade-contracts/blob/main/Avalanche/Router/router.sol) (Note: The code is the same)    |
| uTrade V2 Router Interface as JSON          | [GitHub](https://github.com/unifiprotocol/uTradeV2-core/blob/52d66be2a472b9697a577757a0446076b6c32001/ABI/JSON/IUnifiRouter.json) |
| uTrade V2 Router Interface as Typescript    | [GitHub](https://github.com/unifiprotocol/uTradeV2-core/blob/52d66be2a472b9697a577757a0446076b6c32001/ABI/TS/IUnifiRouter.ts)     |
| Import statement codeblock (when available) |                                                                                                                                   |

## uTrade V2 Router Contract Addresses

| Network          | Address                                                                                                                         |
| ---------------- | ------------------------------------------------------------------------------------------------------------------------------- |
| BitTorrent Chain | `0xdae20ed99dc5da87727e75e4d1f27f1be6117095` ([Link](https://scan.bt.io/#/contract/0xdae20ed99dc5da87727e75e4d1f27f1be6117095)) |
|                  |                                                                                                                                 |

### factory

```
function factory() external pure returns (address);
```

A call to the `factory` function returns the address of the current Factory used by uTrade v2. The current factory address for uTrade V2 on BTTC is `0xCAaB36C77841647dC9955B3b1D03710E9B9F127f`.

### WETH

```
function WETH() external pure returns (address);
```

A call to the `WETH` function returns the address of Wrapped BTT (WBTT) on BitTorrent Chain. As this address does not change, it will always return `0x8D193c6efa90BCFf940A98785d1Ce9D093d3DC8A`.

### quote

```
function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB);
```

A call to the `quote` function returns the amount of *tokenB* that will be received for an amount of *tokenA*. This can be used to calculate the exchange rate between two tokens without factoring in slippage or fees. By entering the amount of *tokenA,* the total amount of reserves of *tokenA* as *reserveA,* and the total amount of reserves of *tokenB* as *reserveB*, the call will return the equivalent amount of *tokenB*.

### getAmountOut

```
function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut, uint fee) external pure returns (uint amountOut);
```

A call to the `getAmountOut`function with the amount of the token being sent will return the maximum amount of a token to be received, accounting for fees and the total amount of reserves.

### getAmountIn

```
function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut, uint fee) external pure returns (uint amountIn);
```

A call to the `getAmountIn` function with the amount of the token you wish to receive will return the minimum amount required of the token you wish to send, accounting for fees and the total amount of reserves.

### getAmountsOut

```
function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts);
```

A call to the `getAmountsOut` function with the amount of the token being sent will return the maximum amount to be received of multiple different tokens. By entering multiple LP addresses in the *address* array, the function will return the maximum amount of each token that will be received. A call to this function uses the `getReserves` function from [UnifiPair.sol](https://docs.unifiprotocol.com/utrade-v2/bittorrent-chain/unifipair.sol) to determine the reserves of the liquidity pool. Then, it calls the `getAmountOut` function to determine the amount of each token in the array that will be received for the *amountIn* value of a token.

### getAmountsIn <a href="#getamountsin" id="getamountsin"></a>

```
function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts);
```

A call to the `getAmountsIn` function with the desired amount of the token to be received will return the minimum amount required to be sent of multiple tokens. By entering multiple LP addresses in the *address* array, the function will return the minimum amount of each token that will need to be sent to receive the desired amount of a token. A call to this function uses the `getReserves` function from [UnifiPair.sol](https://docs.unifiprotocol.com/utrade-v2/bittorrent-chain/unifipair.sol) to determine the reserves of the liquidity pool. Then, it calls the `getAmountIn` function to determine the amount of each token in the array that will need to be sent for the *amountOut* value of a token.&#x20;

## State-Changing Functions - Liquidity <a href="#state-changing-functions" id="state-changing-functions"></a>

### addLiquidity

```
function addLiquidity(
        address tokenA,
        address tokenB,
        uint amountADesired,
        uint amountBDesired,
        uint amountAMin,
        uint amountBMin,
        address to,
        uint deadline
) external returns (uint amountA, uint amountB, uint liquidity);
```

The `addLiquidity` function adds the two tokens that make up the liquidity pool - *tokenA* and *tokenB* - at the proper ratio based on the reserves of the pool. For example, if the pool contains 100 USDT.t / 100,000 BTT, a user's liquidity will be added at the ratio of 1 USDT.t to 1000 BTT, provided there is no price movements in the pair between when the user broadcasts the transaction to when it is mined. In the event of a price movement, the *amountADesired*, *amountBDesired*, *amountAMin*, and *amountBMin* act as a security measure against an adverse price movement. After the liquidity is added, the function sends the corresponding LP tokens to the sender.

In the case of a pool not existing for the two assets, one will be created using [UnifiFactory.sol](https://docs.unifiprotocol.com/utrade-v2/bittorrent-chain/unififactory.sol) at the ratio of the assets supplied.

#### Function Parameters Breakdown

| Parameter        | Type    | Description                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          |
| ---------------- | ------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| *tokenA*         | address | Token address of the first asset in the token pair.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  |
| *tokenB*         | address | Token address of the second asset in the token pair.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 |
| *amountADesired* | uint    | The amount of *tokenA* to be added to liquidity if the value of *tokenA* goes down in comparison to *tokenB*.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        |
| *amountBDesired* | uint    | The amount of *tokenB* to be added to liquidity if the value of *tokenB* goes down in comparison to *tokenA.*                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        |
| *amountAMin*     | uint    | <p>Sets the minimum amount of <em>tokenA</em> that can added to the pool before the transaction reverts. This acts as a safeguard. <br></p><ul><li>If the value of <em>tokenA</em> rapidly increases in comparison to <em>tokenB</em>, the user will require less of <em>tokenA</em> to be added to the pool to maintain the original value of the submitted liquidity.</li><li>A user could potentially be adding liquidity during an outlier spike in value. If the amount of <em>tokenA</em> required falls below this value, the transaction will revert.</li><li>This value must be less than or equal to <em>amountADesired</em>.</li></ul>    |
| *amountBMin*     | uint    | <p>Sets the minimum amount of <em>tokenB</em> that can added to the pool before the transaction reverts. This acts as a safeguard.</p><p></p><ul><li>If the value of <em>tokenB</em> rapidly increases in comparison to <em>tokenA</em>, the user will require less of <em>tokenB</em> to be added to the pool to maintain the original value of the submitted liquidity.</li><li> A user could potentially be adding liquidity during an outlier spike in value. If the amount of <em>tokenB</em> required falls below this value, the transaction will revert.</li><li>This value must be less than or equal to <em>amountBDesired</em>.</li></ul> |
| *to*             | address | The address to which the LP tokens for the uTrade V2 pool will be sent.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              |
| *deadline*       | uint    | The UNIX timestamp for which this transaction must be completed. If the transaction is mined after this deadline, the transaction will revert.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       |

#### Function Return Parameter Breakdown

| Parameter   | Type | Description                                                                                                |
| ----------- | ---- | ---------------------------------------------------------------------------------------------------------- |
| *amountA*   | uint | The exact amount of *tokenA* that was sent to the pool.                                                    |
| *amountB*   | uint | The exact amount of *tokenB* that was sent to the pool.                                                    |
| *liquidity* | uint | The exact amount of liquidity tokens minted and sent to the address provided in the *to* paramete&#x72;*.* |

### addLiquidityETH

```
function addLiquidityETH(
        address token,
        uint amountTokenDesired,
        uint amountTokenMin,
        uint amountETHMin,
        address to,
        uint deadline
    ) external payable returns (uint amountToken, uint amountETH, uint liquidity);
```

The `addLiquidityEth` function is similar to the `addLiquidity` function except it accounts for one token being a native asset. In the case of BitTorrent Chain, this native asset would be BTT. This function will convert BTT to WBTT, will pair that WBTT with the supplied other token, and add the liquidity to the pool. This function will add at the ideal ratio based on when the transaction is mined.\
\
In the case of a pool not existing for BTT and the token provided, one will be created using [UnifiFactory.sol](https://docs.unifiprotocol.com/utrade-v2/bittorrent-chain/unififactory.sol) at the ratio of the assets supplied.

* This function requires a *msg.value* with the amount of BTT to be added.&#x20;
  * The *msg.value* acts as the amountETHDesired. As in, if the ratio between BTT and the token being paired with it change, this is the number of BTT that will be added to the pool.
  * Any leftover BTT is returned to the *msg.sender* address.

#### Function Parameter Breakdown

| Parameter                      | Type    | Description                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 |
| ------------------------------ | ------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| *token*                        | address | The address of the supplied token for the liquidity pool. In other words, the asset that BTT is paired with.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                |
| *amountTokenDesired*           | uint    | The amount of the supplied token to be added to liquidity if the value of token goes down in comparison to BTT.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             |
| (*amountETHDesired*) msg.value | uint    | Sent as the msg.value, the amount of BTT to be added to liquidity if the value of BTT goes down in comparison to token.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     |
| *amountTokenMin*               | uint    | <p>Sets the minimum amount of the supplied token that can added to the pool before the transaction reverts. This acts as a safeguard. </p><p></p><ul><li>If the value of supplied token rapidly increases in comparison to BTT, the user will require less of the token to be added to the pool to maintain the original value of the submitted liquidity.</li><li>A user could potentially be adding liquidity during an outlier spike in value. If the amount of the supplied token required falls below this value, the transaction will revert.</li><li>This value must be less than or equal to <em>amountTokenDesired</em>.</li></ul> |
| *amountETHMin*                 | uint    | <p></p><p>Sets the minimum amount of BTT that can added to the pool before the transaction reverts. This acts as a safeguard. </p><p></p><ul><li>If the value of BTT increases in comparison to the supplied token, the user will require less BTT to be added to the pool to maintain the original value of the submitted liquidity.</li><li>A user could potentially be adding liquidity during an outlier spike in value. If the amount of BTT required falls below this value, the transaction will revert.</li><li>This value must be less than or equal to <em>amountETHDesired</em>.</li></ul>                                       |
| *to*                           | address | The address to which the LP tokens for the uTrade V2 pool will be sent.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     |
| *deadline*                     | uint    | The UNIX timestamp for which this transaction must be completed. If the transaction is mined after this deadline, the transaction will revert.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              |

#### Function Return Parameter Breakdown

| Parameter     | Type | Description                                                                                                |
| ------------- | ---- | ---------------------------------------------------------------------------------------------------------- |
| *amountToken* | uint | The exact amount of the supplied token sent to the pool.                                                   |
| *amountETH*   | uint | The exact amount of BTT converted to WBTT, and then added to the pool.                                     |
| *liquidity*   | uint | The exact amount of liquidity tokens minted and sent to the address provided in the *to* paramete&#x72;*.* |

### removeLiquidity

```
function removeLiquidity(
        address tokenA,
        address tokenB,
        uint liquidity,
        uint amountAMin,
        uint amountBMin,
        address to,
        uint deadline
) external returns (uint amountA, uint amountB);
```

The `removeLiquidity` function removes the two tokens that make up liquidity from a pool. In other words, this function is used when the pool consists of two BRC-20 tokens.

* In the event one of the assets is paired with BTT, BTT will have been wrapped and paired with WBTT (Wrapped BTT). If the user wishes to withdraw WBTT instead of withdrawing as BTT, this function should be used instead of `removeLiquidityETH` .

#### Function Parameter Breakdown

| Parameter    | Type    | Description                                                                                                                                                                                                              |
| ------------ | ------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| *tokenA*     | address | Token address of the first asset in the pair.                                                                                                                                                                            |
| *tokenB*     | address | Token address of the second asset in the pair.                                                                                                                                                                           |
| *liquidity*  | uint    | The amount of liquidity tokens to be redeemed and removed.                                                                                                                                                               |
| *amountAMin* | uint    | Sets the minimum amount of *tokenA* to be removed from the the pool. This acts as a safeguard against removing liquidity during a spike in value. If the removed amount falls below this value, the transaction reverts. |
| *amountBMin* | uint    | Sets the minimum amount of *tokenB* to be removed from the the pool. This acts as a safeguard against removing liquidity during a spike in value. If the removed amount falls below this value, the transaction reverts. |
| *to*         | address | The address to where the redeemed tokens will be sent.                                                                                                                                                                   |
| *deadline*   | uint    | The UNIX timestamp for which this transaction must be completed. If the transaction is mined after this deadline, the transaction will revert.                                                                           |

#### Function Return Parameter Breakdown

| Parameter | Title | Description                                                                      |
| --------- | ----- | -------------------------------------------------------------------------------- |
| *amountA* | uint  | The exact amount of *tokenA* sent to the address provided in the *to* parameter. |
| *amountB* | uint  | The exact amount of *tokenB* sent to the address provided in the *to* parameter. |

### removeLiquidityETH

```
function removeLiquidityETH(
        address token,
        uint liquidity,
        uint amountTokenMin,
        uint amountETHMin,
        address to,
        uint deadline
) external returns (uint amountToken, uint amountETH);
```

The `removeLiquidityETH` function removes BTT as well as the corresponding paired token in the liquidity pool. In other words, this function is used when the pool consists of WBTT and a BRC-20 token.

* In the event one of the assets is paired with BTT, BTT has been wrapped into WBTT(Wrapped BTT). This function will unwrap the WBTT as the liquidity removed. If the user wishes to withdraw WBTT instead of withdrawing as BTT, the `removeLiquidity` function should be used.

#### Function Parameter Breakdown

| Parameter        | Type    | Description                                                                                                                                                                                                             |
| ---------------- | ------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| *token*          | address | Token address of the BRC-20 asset in the pair.                                                                                                                                                                          |
| *liquidity*      | uint    | The amount of liquidity tokens to be redeemed and removed.                                                                                                                                                              |
| *amountTokenMin* | uint    | Sets the minimum amount of *token* to be removed from the the pool. This acts as a safeguard against removing liquidity during a spike in value. If the removed amount falls below this value, the transaction reverts. |
| *amountETHMin*   | uint    | Sets the minimum amount of BTT to be removed from the the pool. This acts as a safeguard against removing liquidity during a spike in value. If the removed amount falls below this value, the transaction reverts.     |
| *to*             | address | The address to where BTT and token will be sent.                                                                                                                                                                        |
| *deadline*       | uint    | The UNIX timestamp for which this transaction must be completed. If the transaction is mined after this deadline, the transaction will revert.                                                                          |

#### Function Return Parameter Breakdown

| Parameter     | Value | Description                                                                     |
| ------------- | ----- | ------------------------------------------------------------------------------- |
| *amountToken* | uint  | The exact amount of *token* sent to the address provided in the *to* parameter. |
| *amountETH*   | uint  | The exact amount of BTT sent to the address provided in the *to* parameter.     |

### removeLiquidityWithPermit

```
function removeLiquidityWithPermit(
        address tokenA,
        address tokenB,
        uint liquidity,
        uint amountAMin,
        uint amountBMin,
        address to,
        uint deadline,
        bool approveMax, uint8 v, bytes32 r, bytes32 s
) external returns (uint amountA, uint amountB);
```

The `removeLiquidityWithPermit` functions removes the two tokens that make up liquidity from a pool. In other words, this function is used when the pool consists of two BRC-20 tokens. This function operates similarly to the `removeLiquidity` function with the added benefit of not requiring pre-approvals using [permit function](https://docs.unifiprotocol.com/utrade-v2/bittorrent-chain/unifierc20.sol) from the BRC-20 contract.

* In the event one of the assets is paired with BTT, BTT will have been wrapped and paired with WBTT (Wrapped BTT). If the user wishes to withdraw WBTT instead of withdrawing as BTT, this function should be used instead of `removeLiquidityETHWithPermit` .

#### Function Parameter Breakdown

| Parameter    | Type    | Description                                                                                                                                                                                                              |
| ------------ | ------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| *tokenA*     | address | Token address of the first asset in the pair.                                                                                                                                                                            |
| *tokenB*     | address | Token address of the second asset in the pair.                                                                                                                                                                           |
| *liquidity*  | uint    | The amount of liquidity tokens to be redeemed and removed.                                                                                                                                                               |
| *amountAMin* | uint    | Sets the minimum amount of *tokenA* to be removed from the the pool. This acts as a safeguard against removing liquidity during a spike in value. If the removed amount falls below this value, the transaction reverts. |
| *amountBMin* | uint    | Sets the minimum amount of *tokenB* to be removed from the the pool. This acts as a safeguard against removing liquidity during a spike in value. If the removed amount falls below this value, the transaction reverts. |
| *to*         | address | The address to where the redeemed tokens will be sent.                                                                                                                                                                   |
| *deadline*   | uint    | The UNIX timestamp for which this transaction must be completed. If the transaction is mined after this deadline, the transaction will revert.                                                                           |
| *approveMax* | bool    | Sets a true or false value on if approval amount in the signature is for liquidity or for uint(-1).                                                                                                                      |
| *v*          | uint8   | The v value of the permit. This is one of the three values that makes up the approval signature.                                                                                                                         |
| *r*          | bytes32 | The r value of the permit. This is one of the three values that makes up the approval signature.                                                                                                                         |
| *s*          | bytes32 | The s value of the permit. This is one of the three values that makes up the approval signature.                                                                                                                         |

#### Function Return Parameter Breakdown

| Parameter | Title | Description                                                                      |
| --------- | ----- | -------------------------------------------------------------------------------- |
| *amountA* | uint  | The exact amount of *tokenA* sent to the address provided in the *to* parameter. |
| *amountB* | uint  | The exact amount of *tokenB* sent to the address provided in the *to* parameter. |

### removeLiquidityETHWithPermit

```
function removeLiquidityETHWithPermit(
        address token,
        uint liquidity,
        uint amountTokenMin,
        uint amountETHMin,
        address to,
        uint deadline,
        bool approveMax, uint8 v, bytes32 r, bytes32 s
) external returns (uint amountToken, uint amountETH);
    
```

The `removeLiquidityETHWithPermit` function removes BTT as well as the corresponding paired token in the liquidity pool. In other words, this function is used when the pool consists of WBTT and a BRC-20 token. This function operates similarly to the `removeLiquidityETH`function with the added benefit of not requiring pre-approvals using [permit function](https://docs.unifiprotocol.com/utrade-v2/bittorrent-chain/unifierc20.sol) from the BRC-20 contract.

* In the event one of the assets is paired with BTT, BTT has been wrapped into WBTT(Wrapped BTT). This function will unwrap the WBTT as the liquidity removed. If the user wishes to withdraw WBTT instead of withdrawing as BTT, the `removeLiquidityWithPermit` function should be used.

#### Function Parameter Breakdown

| Parameter        | Type    | Description                                                                                                                                                                                                             |
| ---------------- | ------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| *token*          | address | Token address of the BRC-20 asset in the pair.                                                                                                                                                                          |
| *liquidity*      | uint    | The amount of liquidity tokens to be redeemed and removed.                                                                                                                                                              |
| *amountTokenMin* | uint    | Sets the minimum amount of *token* to be removed from the the pool. This acts as a safeguard against removing liquidity during a spike in value. If the removed amount falls below this value, the transaction reverts. |
| *amountETHMin*   | uint    | Sets the minimum amount of BTT to be removed from the the pool. This acts as a safeguard against removing liquidity during a spike in value. If the removed amount falls below this value, the transaction reverts.     |
| *to*             | address | The address to where BTT and token will be sent.                                                                                                                                                                        |
| *deadline*       | uint    | The UNIX timestamp for which this transaction must be completed. If the transaction is mined after this deadline, the transaction will revert.                                                                          |
| *v*              | uint8   | The v value of the permit. This is one of the three values that makes up the approval signature.                                                                                                                        |
| *r*              | bytes32 | The r value of the permit. This is one of the three values that makes up the approval signature.                                                                                                                        |
| *s*              | bytes32 | The s value of the permit. This is one of the three values that makes up the approval signature.                                                                                                                        |

#### Function Return Parameter Breakdown

| Parameter     | Value | Description                                                                     |
| ------------- | ----- | ------------------------------------------------------------------------------- |
| *amountToken* | uint  | The exact amount of *token* sent to the address provided in the *to* parameter. |
| *amountETH*   | uint  | The exact amount of BTT sent to the address provided in the *to* parameter.     |

### removeLiquidityETHSupportingFeeOnTransferTokens

```
function removeLiquidityETHSupportingFeeOnTransferTokens(
        address token,
        uint liquidity,
        uint amountTokenMin,
        uint amountETHMin,
        address to,
        uint deadline
) external returns (uint amountETH);
```

The `removeLiquidityETHSupportingFeeOnTransferTokens`function is similar to the `removeLiquidityETH` function, and contains the same call parameters. This function removes BTT as well as the corresponding paired token in the liquidity pool. In other words, this function is used when the pool consists of WBTT and a BRC-20 token.&#x20;

However, this function allows for fee on transfer tokens, such as PAXG, to be used on uTrade.&#x20;

#### Function Parameter Breakdown

| Parameter        | Type    | Description                                                                                                                                                                                                             |
| ---------------- | ------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| *token*          | address | Token address of the BRC-20 asset in the pair.                                                                                                                                                                          |
| *liquidity*      | uint    | The amount of liquidity tokens to be redeemed and removed.                                                                                                                                                              |
| *amountTokenMin* | uint    | Sets the minimum amount of *token* to be removed from the the pool. This acts as a safeguard against removing liquidity during a spike in value. If the removed amount falls below this value, the transaction reverts. |
| *amountETHMin*   | uint    | Sets the minimum amount of BTT to be removed from the the pool. This acts as a safeguard against removing liquidity during a spike in value. If the removed amount falls below this value, the transaction reverts.     |
| *to*             | address | The address to where BTT and the paired token will be sent.                                                                                                                                                             |
| *deadline*       | uint    | The UNIX timestamp for which this transaction must be completed. If the transaction is mined after this deadline, the transaction will revert.                                                                          |

#### Function Return Parameter Breakdown

| Parameter   | Value | Description                                                                                                                                                                                                                   |
| ----------- | ----- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| *amountETH* | uint  | The exact amount of BTT sent to the address provided in the *to* parameter. Note that the *amountToken* parameter is not returned. The amount of fee on transfer that a token may have is not available prior to transaction. |

### removeLiquidityETHWithPermitSupportingFeeOnTransferTokens

```
function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens(
        address token,
        uint liquidity,
        uint amountTokenMin,
        uint amountETHMin,
        address to,
        uint deadline,
        bool approveMax, uint8 v, bytes32 r, bytes32 s
) external returns (uint amountETH);
```

The `removeLiquidityETHWithPermitSupportingFeeOnTransferTokens`function is similar to the `removeLiquidityETHWithPermit`function. This function removes BTT as well as the corresponding paired token in the liquidity pool. In other words, this function is used when the pool consists of WBTT and a BRC-20 token. This function operates similarly to the `removeLiquidityETHfunction` with the added benefit of not requiring pre-approvals using [permit function](https://docs.unifiprotocol.com/utrade-v2/avalanche/unifierc20.sol) from the BRC-20 contract. In addition, this function allows for fee on transfer tokens, such as PAXG, to be used on uTrade.&#x20;

#### Function Parameter Breakdown

| Parameter        | Type    | Description                                                                                                                                                                                                             |
| ---------------- | ------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| *token*          | address | Token address of the BRC-20 asset in the pair.                                                                                                                                                                          |
| *liquidity*      | uint    | The amount of liquidity tokens to be redeemed and removed.                                                                                                                                                              |
| *amountTokenMin* | uint    | Sets the minimum amount of *token* to be removed from the the pool. This acts as a safeguard against removing liquidity during a spike in value. If the removed amount falls below this value, the transaction reverts. |
| *amountETHMin*   | uint    | Sets the minimum amount of BTT to be removed from the the pool. This acts as a safeguard against removing liquidity during a spike in value. If the removed amount falls below this value, the transaction reverts.     |
| *to*             | address | The address to where BTT and token will be sent.                                                                                                                                                                        |
| *deadline*       | uint    | The UNIX timestamp for which this transaction must be completed. If the transaction is mined after this deadline, the transaction will revert.                                                                          |
| *v*              | uint8   | The v value of the permit. This is one of the three values that makes up the approval signature.                                                                                                                        |
| *r*              | bytes32 | The r value of the permit. This is one of the three values that makes up the approval signature.                                                                                                                        |
| *s*              | bytes32 | The s value of the permit. This is one of the three values that makes up the approval signature.                                                                                                                        |

#### Function Return Parameter Breakdown

| Parameter   | Value | Description                                                                                                                                                                                                                   |
| ----------- | ----- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| *amountETH* | uint  | The exact amount of BTT sent to the address provided in the *to* parameter. Note that the *amountToken* parameter is not returned. The amount of fee on transfer that a token may have is not available prior to transaction. |

## State-Changing Functions - Swap

### swapExactTokensForTokens

```
function swapExactTokensForTokens(
        uint amountIn,
        uint amountOutMin,
        address[] calldata path,
        address to,
        uint deadline
) external returns (uint[] memory amounts);
```

The `swapExactTokensForTokens` function sends an exact amount of tokens for the maximum amount of another token.&#x20;

#### Function Parameter Breakdown

| Parameter      | Type                | Description                                                                                                                                                                                                                                                                                                                                                                                                                            |
| -------------- | ------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| *amountIn*     | uint                | The amount of tokens being sent to swap into another token                                                                                                                                                                                                                                                                                                                                                                             |
| *amountOutMin* | uint                | Sets the minimum amount of the desired token to receive. This acts as a safeguard against removing liquidity during a spike in value. If the amount to be received falls below this value, the transaction reverts.                                                                                                                                                                                                                    |
| *path*         | address\[] calldata | <p>The pathway to change one token to another, consisting of an array of addresses. Each token must have an existing liquidity pool, as well as have liquidity.<br></p><p>The <em>path</em> represents the pathway from one token to another. If a pair exists for the two tokens you wish to exchange, this will contain two values inside of an array. However, if there is no direct pair, multiple addresses may be required. </p> |
| *to*           | address             | The address to where the desired token will be sent.                                                                                                                                                                                                                                                                                                                                                                                   |
| *deadline*     | uint                | The UNIX timestamp for which this transaction must be completed. If the transaction is mined after this deadline, the transaction will revert.                                                                                                                                                                                                                                                                                         |

#### Function Return Parameter Breakdown

| Parameter | Type           | Description                                                                                                |
| --------- | -------------- | ---------------------------------------------------------------------------------------------------------- |
| *amounts* | uint\[] memory | The exact amount of tokens sent into the swap, as well as the exact return amount of all subsequent swaps. |

### swapTokensForExactTokens

```
function swapTokensForExactTokens(
        uint amountOut,
        uint amountInMax,
        address[] calldata path,
        address to,
        uint deadline
) external returns (uint[] memory amounts);
```

The `swapTokensForExactTokens` function sends the minimum amount of tokens for the exact amount of another token.&#x20;

#### Function Parameter Breakdown

| Parameter     | Type                | Description                                                                                                                                                                                                                                                                                                                                                                                                                            |
| ------------- | ------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| *amountOut*   | uint                | The exact amount of the desired tokens to be received.                                                                                                                                                                                                                                                                                                                                                                                 |
| *amountInMax* | uint                | Sets the maximum amount of token to be sent in. This acts as a safeguard against removing liquidity during a spike in value. If the amount to be sent rises above this value, the transaction reverts.                                                                                                                                                                                                                                 |
| *path*        | address\[] calldata | <p>The pathway to change one token to another, consisting of an array of addresses. Each token must have an existing liquidity pool, as well as have liquidity.<br></p><p>The <em>path</em> represents the pathway from one token to another. If a pair exists for the two tokens you wish to exchange, this will contain two values inside of an array. However, if there is no direct pair, multiple addresses may be required. </p> |
| *to*          | address             | The address to where the desired token will be sent.                                                                                                                                                                                                                                                                                                                                                                                   |
| *deadline*    | uint                | The UNIX timestamp for which this transaction must be completed. If the transaction is mined after this deadline, the transaction will revert.                                                                                                                                                                                                                                                                                         |

#### Function Return Parameter Breakdown

| Parameter | Type           | Description                                                                                                |
| --------- | -------------- | ---------------------------------------------------------------------------------------------------------- |
| *amounts* | uint\[] memory | The exact amount of tokens sent into the swap, as well as the exact return amount of all subsequent swaps. |

### swapExactETHForTokens

```
function swapExactETHForTokens(
        uint amountOutMin, 
        address[] calldata path, 
        address to, 
        uint deadline)
        external
        payable
returns (uint[] memory amounts);
```

The `swapExactETHForTokens` function sends an exact amount of BTT for a desired token.

#### Function Parameter Breakdown

| Parameter                                           | Type                | Description                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    |
| --------------------------------------------------- | ------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| <p><em>(amountIn)</em></p><p><em>msg.value</em></p> | uint                | Sent as the msg.value, the amount of BTT to be swapped.                                                                                                                                                                                                                                                                                                                                                                                                                                                                        |
| *amountOutMin*                                      | uint                | Sets the minimum amount of the desired token to receive. This acts as a safeguard against removing liquidity during a spike in value. If the amount to be received falls below this value, the transaction reverts.                                                                                                                                                                                                                                                                                                            |
| *path*                                              | address\[] calldata | <p>The pathway to change one token to another, consisting of an array of addresses. Each token must have an existing liquidity pool, as well as have liquidity.<br></p><p>The <em>path</em> represents the pathway from one token to another. If a pair exists for the two tokens you wish to exchange, this will contain two values inside of an array. However, if there is no direct pair, multiple addresses may be required. </p><p></p><p>As the first swap is swapping BTT to WBTT, the first address must be WBTT.</p> |
| *to*                                                | address             | The address to where the desired token will be sent.                                                                                                                                                                                                                                                                                                                                                                                                                                                                           |
| *deadline*                                          | uint                | The UNIX timestamp for which this transaction must be completed. If the transaction is mined after this deadline, the transaction will revert.                                                                                                                                                                                                                                                                                                                                                                                 |

#### Function Return Parameter Breakdown

| Parameter | Type           | Description                                                                                             |
| --------- | -------------- | ------------------------------------------------------------------------------------------------------- |
| *amounts* | uint\[] memory | The exact amount of BTT sent into the swap, as well as the exact return amount of all subsequent swaps. |

### swapTokensForExactETH

```
function swapTokensForExactETH(
        uint amountOut, 
        uint amountInMax, 
        address[] calldata path, 
        address to, 
        uint deadline)
        external
        returns (uint[] memory amounts);
```

The `swapTokensForExactETH` function sends an amount of tokens for an exact amount of BTT.

#### Function Parameter Breakdown

| Parameter     | Type                | Description                                                                                                                                                                                                                                                                                                                                                                                                                            |
| ------------- | ------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| *amountOut*   | uint                | The exact amount of the BTT to be received.                                                                                                                                                                                                                                                                                                                                                                                            |
| *amountInMax* | uint                | Sets the maximum amount of token to be sent in. This acts as a safeguard against removing liquidity during a spike in value. If the amount to be sent rises above this value, the transaction reverts.                                                                                                                                                                                                                                 |
| *path*        | address\[] calldata | <p>The pathway to change one token to another, consisting of an array of addresses. Each token must have an existing liquidity pool, as well as have liquidity.<br></p><p>The <em>path</em> represents the pathway from one token to another. If a pair exists for the two tokens you wish to exchange, this will contain two values inside of an array. However, if there is no direct pair, multiple addresses may be required. </p> |
| *to*          | address             | The address to where the desired token will be sent.                                                                                                                                                                                                                                                                                                                                                                                   |
| *deadline*    | uint                | The UNIX timestamp for which this transaction must be completed. If the transaction is mined after this deadline, the transaction will revert.                                                                                                                                                                                                                                                                                         |

#### Function Return Parameter Breakdown

| Parameter | Type           | Description                                                                                         |
| --------- | -------------- | --------------------------------------------------------------------------------------------------- |
| *amounts* | uint\[] memory | The exact amount of tokens sent into the swap, as well as the exact amount of all subsequent swaps. |

### swapExactTokensForETH

```
function swapExactTokensForETH(
        uint amountIn, 
        uint amountOutMin, 
        address[] calldata path, 
        address to, 
        uint deadline)
        external
        returns (uint[] memory amounts);
```

The `swapExactTokensForETH` function sends an exact amount of tokens for BTT.

#### Function Parameter Breakdown

| Parameter      | Type                | Description                                                                                                                                                                                                                                                                                                                                                                                                                            |
| -------------- | ------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| *amountIn*     | uint                | The amount of tokens being sent to swap into BTT.                                                                                                                                                                                                                                                                                                                                                                                      |
| *amountOutMin* | uint                | Sets the minimum amount of the BTT to receive. This acts as a safeguard against removing liquidity during a spike in value. If the amount to be received falls below this value, the transaction reverts.                                                                                                                                                                                                                              |
| *path*         | address\[] calldata | <p>The pathway to change one token to another, consisting of an array of addresses. Each token must have an existing liquidity pool, as well as have liquidity.<br></p><p>The <em>path</em> represents the pathway from one token to another. If a pair exists for the two tokens you wish to exchange, this will contain two values inside of an array. However, if there is no direct pair, multiple addresses may be required. </p> |
| *to*           | address             | The address to where the desired token will be sent.                                                                                                                                                                                                                                                                                                                                                                                   |
| *deadline*     | uint                | The UNIX timestamp for which this transaction must be completed. If the transaction is mined after this deadline, the transaction will revert.                                                                                                                                                                                                                                                                                         |

#### Function Parameter Return Breakdown

| Parameter | Type           | Description                                                                                         |
| --------- | -------------- | --------------------------------------------------------------------------------------------------- |
| *amounts* | uint\[] memory | The exact amount of tokens sent into the swap, as well as the exact amount of all subsequent swaps. |

### swapETHForExactTokens

```
function swapETHForExactTokens(
        uint amountOut, 
        address[] calldata path, 
        address to, 
        uint deadline)
        external
        payable
        returns (uint[] memory amounts);
```

The `swapETHForExactTokens` function swaps an exact amount of BTT for an amount of the desired token.

#### Function Parameter Breakdown

| Parameter                                           | Type                | Description                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    |
| --------------------------------------------------- | ------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| <p><em>(amountIn)</em></p><p><em>msg.value</em></p> | uint                | Sent as the msg.value, the amount of BTT to be swapped.                                                                                                                                                                                                                                                                                                                                                                                                                                                                        |
| *amountOutMin*                                      | uint                | Sets the minimum amount of the desired token to receive. This acts as a safeguard against removing liquidity during a spike in value. If the amount to be received falls below this value, the transaction reverts.                                                                                                                                                                                                                                                                                                            |
| *path*                                              | address\[] calldata | <p>The pathway to change one token to another, consisting of an array of addresses. Each token must have an existing liquidity pool, as well as have liquidity.<br></p><p>The <em>path</em> represents the pathway from one token to another. If a pair exists for the two tokens you wish to exchange, this will contain two values inside of an array. However, if there is no direct pair, multiple addresses may be required. </p><p></p><p>As the first swap is swapping BTT to WBTT, the first address must be WBTT.</p> |
| *to*                                                | address             | The address to where the desired token will be sent.                                                                                                                                                                                                                                                                                                                                                                                                                                                                           |
| *deadline*                                          | uint                | The UNIX timestamp for which this transaction must be completed. If the transaction is mined after this deadline, the transaction will revert.                                                                                                                                                                                                                                                                                                                                                                                 |

#### Function Return Parameter Breakdown

| Parameter | Type           | Description                                                                                             |
| --------- | -------------- | ------------------------------------------------------------------------------------------------------- |
| *amounts* | uint\[] memory | The exact amount of BTT sent into the swap, as well as the exact return amount of all subsequent swaps. |

### swapExactTokensForTokensSupportingFeeOnTransferTokens

```
function swapExactTokensForTokensSupportingFeeOnTransferTokens(
        uint amountIn,
        uint amountOutMin,
        address[] calldata path,
        address to,
        uint deadline
) external;
```

The `swapExactTokensForTokensSupportingFeeOnTransferTokens` function is similar to `swapExactTokensForTokens` as it swaps one BRC-20 token for another BRC-20 token. In addition, this function allows for fee on transfer tokens, such as PAXG, to be used on uTrade.

#### Function Parameter Breakdown

| Name           | Type                |                                                                                                                                                                                                                                                                                                                                                                                                                              |
| -------------- | ------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| *amountIn*     | uint                | The amount of tokens being sent to swap into BTT.                                                                                                                                                                                                                                                                                                                                                                            |
| *amountOutMin* | uint                | Sets the minimum amount of the desired token to receive. This acts as a safeguard against removing liquidity during a spike in value. If the amount to be received falls below this value, the transaction reverts.                                                                                                                                                                                                          |
| *path*         | address\[] calldata | <p>The pathway to change one token to another, consisting of an array of addresses. Each token must have an existing liquidity pool, as well as have liquidity.<br></p><p>The path represents the pathway from one token to another. If a pair exists for the two tokens you wish to exchange, this will contain two values inside of an array. However, if there is no direct pair, multiple addresses may be required.</p> |
| *to*           | address             | The address to where the desired token will be sent.                                                                                                                                                                                                                                                                                                                                                                         |
| *deadline*     | uint                | The UNIX timestamp for which this transaction must be completed. If the transaction is mined after this deadline, the transaction will revert.                                                                                                                                                                                                                                                                               |

### swapExactETHForTokensSupportingFeeOnTransferTokens

```
function swapExactETHForTokensSupportingFeeOnTransferTokens(
        uint amountOutMin,
        address[] calldata path,
        address to,
        uint deadline
 ) external payable;
```

The `swapExactETHForTokensSupportingFeeOnTransferTokens`function  is similar to `swapExactETHForTokens` function as it swaps an exact amount of BTT for BRC-20 tokens. In addition, this function allows for fee on transfer tokens, such as PAXG, to be used on uTrade.&#x20;

#### Function Parameter Breakdown

| Parameter                                           | Type                | Description                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    |
| --------------------------------------------------- | ------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| <p><em>(amountIn)</em></p><p><em>msg.value</em></p> | uint                | Sent as the msg.value, the exact amount of BTT to be swapped.                                                                                                                                                                                                                                                                                                                                                                                                                                                                  |
| *amountOutMin*                                      | uint                | Sets the minimum amount of the desired token to receive. This acts as a safeguard against removing liquidity during a spike in value. If the amount to be received falls below this value, the transaction reverts.                                                                                                                                                                                                                                                                                                            |
| *path*                                              | address\[] calldata | <p>The pathway to change one token to another, consisting of an array of addresses. Each token must have an existing liquidity pool, as well as have liquidity.<br></p><p>The <em>path</em> represents the pathway from one token to another. If a pair exists for the two tokens you wish to exchange, this will contain two values inside of an array. However, if there is no direct pair, multiple addresses may be required. </p><p></p><p>As the first swap is swapping BTT to WBTT, the first address must be WBTT.</p> |
| *to*                                                | address             | The address to where the desired token will be sent.                                                                                                                                                                                                                                                                                                                                                                                                                                                                           |
| *deadline*                                          | uint                | The UNIX timestamp for which this transaction must be completed. If the transaction is mined after this deadline, the transaction will revert.                                                                                                                                                                                                                                                                                                                                                                                 |

### swapExactTokensForETHSupportingFeeOnTransferTokens <a href="#swapexacttokensforethsupportingfeeontransfertokens" id="swapexacttokensforethsupportingfeeontransfertokens"></a>

```
function swapExactTokensForETHSupportingFeeOnTransferTokens(
        uint amountIn,
        uint amountOutMin,
        address[] calldata path,
        address to,
        uint deadline
) external;
```

The function `swapExactTokensForETHSupportingFeeOnTransferTokens`is similar to the `swapExactTokensForETH`function, as it swaps an exact amount of BRC-20 tokens for BTT. In addition, this function allows for fee on transfer tokens, such as PAXG, to be used on uTrade.

#### Function Parameter Breakdown

| Parameter      | Type                | Description                                                                                                                                                                                                                                                                                                                                                                                                                            |
| -------------- | ------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| *amountIn*     | uint                | The amount of tokens being sent to swap into BTT.                                                                                                                                                                                                                                                                                                                                                                                      |
| *amountOutMin* | uint                | Sets the minimum amount of the BTT to receive. This acts as a safeguard against removing liquidity during a spike in value. If the amount to be received falls below this value, the transaction reverts.                                                                                                                                                                                                                              |
| *path*         | address\[] calldata | <p>The pathway to change one token to another, consisting of an array of addresses. Each token must have an existing liquidity pool, as well as have liquidity.<br></p><p>The <em>path</em> represents the pathway from one token to another. If a pair exists for the two tokens you wish to exchange, this will contain two values inside of an array. However, if there is no direct pair, multiple addresses may be required. </p> |
| *to*           | address             | The address to where the desired token will be sent.                                                                                                                                                                                                                                                                                                                                                                                   |
| *deadline*     | uint                | The UNIX timestamp for which this transaction must be completed. If the transaction is mined after this deadline, the transaction will revert.                                                                                                                                                                                                                                                                                         |

## Interface Code

```
interface IUnifiRouter01 {
    function factory() external pure returns (address);
    function WETH() external pure returns (address);

    function addLiquidity(
        address tokenA,
        address tokenB,
        uint amountADesired,
        uint amountBDesired,
        uint amountAMin,
        uint amountBMin,
        address to,
        uint deadline
    ) external returns (uint amountA, uint amountB, uint liquidity);
    function addLiquidityETH(
        address token,
        uint amountTokenDesired,
        uint amountTokenMin,
        uint amountETHMin,
        address to,
        uint deadline
    ) external payable returns (uint amountToken, uint amountETH, uint liquidity);
    function removeLiquidity(
        address tokenA,
        address tokenB,
        uint liquidity,
        uint amountAMin,
        uint amountBMin,
        address to,
        uint deadline
    ) external returns (uint amountA, uint amountB);
    function removeLiquidityETH(
        address token,
        uint liquidity,
        uint amountTokenMin,
        uint amountETHMin,
        address to,
        uint deadline
    ) external returns (uint amountToken, uint amountETH);
    function removeLiquidityWithPermit(
        address tokenA,
        address tokenB,
        uint liquidity,
        uint amountAMin,
        uint amountBMin,
        address to,
        uint deadline,
        bool approveMax, uint8 v, bytes32 r, bytes32 s
    ) external returns (uint amountA, uint amountB);
    function removeLiquidityETHWithPermit(
        address token,
        uint liquidity,
        uint amountTokenMin,
        uint amountETHMin,
        address to,
        uint deadline,
        bool approveMax, uint8 v, bytes32 r, bytes32 s
    ) external returns (uint amountToken, uint amountETH);
    function swapExactTokensForTokens(
        uint amountIn,
        uint amountOutMin,
        address[] calldata path,
        address to,
        uint deadline
    ) external returns (uint[] memory amounts);
    function swapTokensForExactTokens(
        uint amountOut,
        uint amountInMax,
        address[] calldata path,
        address to,
        uint deadline
    ) external returns (uint[] memory amounts);
    function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline)
        external
        payable
        returns (uint[] memory amounts);
    function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline)
        external
        returns (uint[] memory amounts);
    function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline)
        external
        returns (uint[] memory amounts);
    function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline)
        external
        payable
        returns (uint[] memory amounts);

    function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB);
    function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut, uint fee) external pure returns (uint amountOut);
    function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut, uint fee) external pure returns (uint amountIn);
    function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts);
    function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts);
}

interface IUnifiRouter02 is IUnifiRouter01 {
    function removeLiquidityETHSupportingFeeOnTransferTokens(
        address token,
        uint liquidity,
        uint amountTokenMin,
        uint amountETHMin,
        address to,
        uint deadline
    ) external returns (uint amountETH);
    function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens(
        address token,
        uint liquidity,
        uint amountTokenMin,
        uint amountETHMin,
        address to,
        uint deadline,
        bool approveMax, uint8 v, bytes32 r, bytes32 s
    ) external returns (uint amountETH);

    function swapExactTokensForTokensSupportingFeeOnTransferTokens(
        uint amountIn,
        uint amountOutMin,
        address[] calldata path,
        address to,
        uint deadline
    ) external;
    function swapExactETHForTokensSupportingFeeOnTransferTokens(
        uint amountOutMin,
        address[] calldata path,
        address to,
        uint deadline
    ) external payable;
    function swapExactTokensForETHSupportingFeeOnTransferTokens(
        uint amountIn,
        uint amountOutMin,
        address[] calldata path,
        address to,
        uint deadline
    ) external;
}
```


# Ethereum

Here you will find in-depth detail of the contracts that make up uTrade V2 on Ethereum. Each contract includes JSONs as well as Typescript files for integration into your project. Every effort is made to open-source all aspects of uTrade V2, but some do remain private.  When a contract is available, you will find a link to the Github source code.&#x20;


# singleLiquidityWrapper.sol

**Primary Uses -** Unique to uTrade, the Single Liquidity Wrapper allows ETH or any ERC-20 token to converted into a LP pool. For example, USDT can be added using the wrapper to supply liquidity for a BUSD / WETH 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)        | [Etherscan Verified](https://etherscan.io/address/0x791ca4e3b1ddf69bb7635684e1fb50f0bc0fc917#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                                                                                                                                |
| -------------------- | -------------------------------------------------------------------------------------------------------------------------------------- |
| ETH Main Net         | `0x791CA4e3B1DDf69bB7635684E1FB50F0Bc0fc917`([Link](https://etherscan.io/address/0x791ca4e3b1ddf69bb7635684e1fb50f0bc0fc917))          |
| ETH Ropsten Test Net | `0xD1bb0bb882Eb112b82D625c4b2c3BF943CC2bF67` ([Link](https://ropsten.etherscan.io/address/0xD1bb0bb882Eb112b82D625c4b2c3BF943CC2bF67)) |

### 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 ETH into a LP token. It does so by first converting the provided ETH 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 ETH value is sent as a msg.value parameter. One of the two assets can be WETH.

#### Parameter Breakdown

| Parameter                                        | Type    | Description                                                                                                                                       |
| ------------------------------------------------ | ------- | ------------------------------------------------------------------------------------------------------------------------------------------------- |
| <p><em>amountIn</em><br><em>(msg.value)</em></p> | uint    | The amount of ETH 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 ETH to an uTrade V2 LP token made up of two different tokens. In other words, ETH 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 ETH 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 ETH 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 WETH'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 ETH must be converted to WETH, 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 ETH 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 WETH'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 ETH must be converted to WETH, 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 ETH. If true, the *receiveToken* address should be WETH, as it will unwrap WETH and send ETH. |
| *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 ETH 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 ETH. If true, the *receiveToken* address should be WETH, as it will unwrap WETH and send ETH.                                                                                                                                                                                                                                                                                                                              |
| *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 ;
}
```


# UnifiController.sol

The Unifi Controller is a work in progress with minor tweaks here and there. Full documentation will be available once it is optimized!

**Primary Uses -** The Unifi Controller is responsible for the setting the variables of UP minting on individual pairs as well as updating the redeem value of UP tokens globally.&#x20;

## uTrade V2 Controller Code / Interfaces

|                                             |           |
| ------------------------------------------- | --------- |
| uTrade V2 Controller (Solidity)             | Link Here |
| uTrade V2 Controller Interface as JSON      | Link Here |
| uTrade V2 Controller as Typescript          | Link Here |
| Import statement codeblock (when available) |           |

## uTrade V2 Controller Contract Addresses

| Network              | Address                                                                                                                                |
| -------------------- | -------------------------------------------------------------------------------------------------------------------------------------- |
| ETH Main Net         | `0xCE17B79C9Ccf709528F120f66Fd3498B33D4F72F` ([Link](https://etherscan.io/address/0xCE17B79C9Ccf709528F120f66Fd3498B33D4F72F))         |
| ETH Ropsten Test Net | `0x4F916649463F4A74c536F3B6C599f66BBB94e4fc` ([Link](https://ropsten.etherscan.io/address/0x4F916649463F4A74c536F3B6C599f66BBB94e4fc)) |

## Events

### SwapFeesUPminted

```
event SwapFeesUpminted(address indexed pool, uint amountUPMinted, address defaultPoolAddress, uint platforUPFees);
```

The `SwapFeeUpminted` event is emitted whenever UP is minted. In the majority of cases, this will occur any time a trade occurs.&#x20;

#### Parameter Breakdown

| Parameter            | Type    | Description                                                                                     |
| -------------------- | ------- | ----------------------------------------------------------------------------------------------- |
| *pool*               | address | The liquidity pool where the UP was minted.                                                     |
| *amountUPMinted*     | uint    | The amount of UP minted during this event.                                                      |
| *defaultPoolAddress* | address | The pool representing the 'Super Pair' reward for UNIFI holders.                                |
| *platforUPFees*      | uint    | The amount of UP collected by the platform for increasing the redeem value and for Super Pairs. |

### UpdatePoolRewards

```
event UpdatePoolRewards(address indexed pool, uint rewards);    
```

The `UpdatePoolRewards` event is emitted when the amount of UP claimable by the liquidity providers in the liquidity pool is updated. This event occurs when a trade occurs and results in UP being minted for liquidity providers, or a liquidity provider performs a claim UP transaction.

#### Parameter Breakdown

| Parameter | Type    | Description                                                                      |
| --------- | ------- | -------------------------------------------------------------------------------- |
| *pool*    | address | The liquidity pool where the UP was minted.                                      |
| *rewards* | uint    | The amount of UP available to be claimed by all liquidity providers in the pool. |

## Read-Only Functions

#### feeSetter

```
function feeSetter() external view returns (address);
```

The `feeSetter` function returns the address of uTrade V2's Smart Contract which sets the fees for trading.

### WBNB

```
function WETH() external view returns (address);
```

The `WETH` function will return the address of WETH on Ethereum. As this does not change, it will always return `0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2`.

### UNIFIUPVault

```
function UNIFIUPVault() external view returns (address);
```

The `UNIFIUPVault` function returns the address of the UPEth vault. This vault contains the ETH that is redeemable for UP.

### nativeFeeTo

```
function nativeFeeTo() external view returns (address);
```

The `nativeFeeTo` function returns the address where, in the case of Unifi Protocol collecting native token fees, the fees would be sent to.


# UnifiERC20.sol

**Primary Uses -** UnifiERC20.sol essentially ports the properties of ERC-20 tokens on to Unifi LP Tokens, or uTokens. An example of this in practice would be the 'approve' transaction.

## uTrade V2 UnifiERC20 Code / Interfaces

|                                             |                                                                                                                             |
| ------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------- |
| uTrade V2 UnifiERC20 (Solidity)             | [Etherscan Verified Pair (UNIFI / ETH)](https://etherscan.io/address/0x96351b805fb389b761c1318b43a7dc0c679bed5e#code#F2#L1) |
| uTrade V2 UnifiERC20 Interface as JSON      | Link Here                                                                                                                   |
| uTrade V2 UnifiERC20 as Typescript          | Link Here                                                                                                                   |
| Import statement codeblock (when available) |                                                                                                                             |

## uTrade V2 UnifiERC20 Contract Addresses

Each uTrade V2 Liquidity Pool uses the uTrade V2 ERC20 Interface in the contract. An example would be `0x96351b805FB389B761c1318B43a7dC0C679BEd5E` ([Link](https://etherscan.io/address/0x96351b805fb389b761c1318b43a7dc0c679bed5e)) for the UNIFI / ETH pair.&#x20;

## Events

### Approval

```
event Approval(address indexed owner, address indexed spender, uint value);
```

The `Approval` event is emitted anytime an `approve` or `permit` function is called.

### Transfer

```
event Transfer(address indexed from, address indexed to, uint value);
```

The `Transfer` event is emitted anytime a transfer of LP tokens occurs, by the `transfer`, `transferFrom`, `mint`, or `burn` functions.

## Read-Only Functions

### name

```
function name() external pure returns (string memory);
```

The `name` function will return "Unifi LPs" for all liquidity pool contracts.

### symbol

```
function symbol() external pure returns (string memory);
```

The `symbol` function will return "Unifi-LP" for all liquidity pool contracts.

### decimals

```
function decimals() external pure returns (uint8);
```

The `decimals` function returns "18" as a uint8 value, which is the precision for each uToken on uTrade V2.

### totalSupply

```
function totalSupply() external view returns (uint);
```

The `totalSupply` function returns the total amount uTokens for a pair.

### balanceOf

```
function balanceOf(address owner) external view returns (uint);
```

The `balanceOf` function returns the balance of uTokens for the provided address.

### allowance

```
function allowance(address owner, address spender) external view returns (uint);
```

The `allowance` function returns the amount of tokens an address is approved to transfer when using the `transferFrom` function.

### DOMAIN\_SEPARATOR

```
function DOMAIN_SEPARATOR() external view returns (bytes32);
```

The `DOMAIN_SEPARATOR` function is used in the `permit` function, and is one of the components that allows transactions to get through without a prior approve transaction. Calling a read function returns the bytes32 data that is required for use in `permit` function.

### PERMIT\_TYPEHASH

```
function PERMIT_TYPEHASH() external view returns (bytes32);
```

The `PERMIT_TYPEHASH` function is used in the `permit` function, and is one of the components that allows transactions to get through without a prior approve transaction. Calling a read function returns the bytes32 data that is required for use in the `permit` function.

### nonces

```
function nonces(address owner) external view returns (uint);
```

The `nonces` function is used in the permit function. It returns the current nonce of the *address* provided.

## State-Changing Functions

### approve

```
function approve(address spender, uint value) external returns (bool);
```

The `approve` function sets a *value* for  the amount of LP tokens the *address* provided is allowed to transfer. Returns a boolean value and emits the `Approval` event.

### transfer

```
function transfer(address to, uint value) external returns (bool);
```

The `transfer` function lets an address send uTokens from one address to another, and returns a boolean value and emits a `Transfer` event.

### transferFrom

```
function transferFrom(address from, address to, uint value) external returns (bool);
```

The `transferFrom` function sends uTokens from one address to another. This requires the sending address to have approval to send uTokens. Returns a boolean value and emits a `Transfer`event.

### permit

```
function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external;
```

The permit function allows a sender to use a signature in lieu of an approval transaction, and sets the allowance for an address to send.

#### Function Parameter Breakdown

| Parameter  | Type    | Description                                                                                                                                    |
| ---------- | ------- | ---------------------------------------------------------------------------------------------------------------------------------------------- |
| *owner*    | address | The owner of the address.                                                                                                                      |
| *spender*  | address | The spender of the uTokens.                                                                                                                    |
| *value*    | uint    | The amount of uTokens to be transferred.                                                                                                       |
| *deadline* | uint    | The UNIX timestamp for which this transaction must be completed. If the transaction is mined after this deadline, the transaction will revert. |
| *v*        | uint8   | The v value of the permit. This is one of the three values that makes up the approval signature.                                               |
| *r*        | bytes32 | The r value of the permit. This is one of the three values that makes up the approval signature.                                               |
| *s*        | bytes32 | The s value of the permit. This is one of the three values that makes up the approval signature.                                               |

## Interface Code

```
interface IUnifiERC20 {
    event Approval(address indexed owner, address indexed spender, uint value);
    event Transfer(address indexed from, address indexed to, uint value);

    function name() external pure returns (string memory);
    function symbol() external pure returns (string memory);
    function decimals() external pure returns (uint8);
    function totalSupply() external view returns (uint);
    function balanceOf(address owner) external view returns (uint);
    function allowance(address owner, address spender) external view returns (uint);

    function approve(address spender, uint value) external returns (bool);
    function transfer(address to, uint value) external returns (bool);
    function transferFrom(address from, address to, uint value) external returns (bool);

    function DOMAIN_SEPARATOR() external view returns (bytes32);
    function PERMIT_TYPEHASH() external pure returns (bytes32);
    function nonces(address owner) external view returns (uint);

    function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external;
}
```


# UnifiFactory.sol

**Primary Uses** - The uTrade V2 Factory contract creates an LP token for any pairs listed on uTrade V2, and indexes them for easy retrieval. In addition, it can return the address of the LP token based on a call of the addresses of the two tokens that make up the liquidity pool.

## uTrade V2 Factory Code / Interfaces

|                                             |                                                                                                                                    |
| ------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------- |
| uTrade V2 Factory (Solidity)                | Link Here                                                                                                                          |
| uTrade V2 Factory Interface as JSON         | [GitHub](https://github.com/unifiprotocol/uTradeV2-core/blob/52d66be2a472b9697a577757a0446076b6c32001/ABI/JSON/IUnifiFactory.json) |
| uTrade V2 Factory Interface as Typescript   | [GitHub](https://github.com/unifiprotocol/uTradeV2-core/blob/52d66be2a472b9697a577757a0446076b6c32001/ABI/TS/IUnifiFactory.ts)     |
| Import statement codeblock (when available) |                                                                                                                                    |

## uTrade V2 Factory Contract Addresses

| Network              | Address                                                                                                                                |
| -------------------- | -------------------------------------------------------------------------------------------------------------------------------------- |
| ETH Main Net         | `0x08e7974CacF66C5a92a37c221A15D3c30C7d97e0`([Link](https://etherscan.io/address/0x08e7974CacF66C5a92a37c221A15D3c30C7d97e0))          |
| ETH Ropsten Test Net | `0x4F916649463F4A74c536F3B6C599f66BBB94e4fc` ([Link](https://ropsten.etherscan.io/address/0x4F916649463F4A74c536F3B6C599f66BBB94e4fc)) |

## Events

### PairCreated

```
event PairCreated(address indexed token0, address indexed token1, address pair, uint);
```

Anytime a pair is created on uTrade V2 using the `createPair` function, a `PairCreated` event is emitted. Contracts can be deployed to listen for new pairs on the uTrade V2 ETH Factory address.&#x20;

* *token0* is the token address of the first asset in the token pair.
* *token1* is the token address of the second asset in the token pair.
* *pair* is the address of the newly created uTrade V2 liquidity pool.
* *uint* refers to the index of this uTrade V2 Factor&#x79;*.* For example, the first liquidity pool created on uTrade V2 is 1, the second liquidity pool is 2, and so on. This number can used with the `allPairs(uint)` to return the address. The current number, and therefore the total number of LP pools on uTrade V2 ETH, can be accessed using the `allPairsLength` function.

## Read-Only Functions <a href="#read-only-functions" id="read-only-functions"></a>

### getPair

```
function getPair(address tokenA, address tokenB) external view returns (address pair);
```

A call to the `getPair` function returns the address of the pair for *tokenA* and *tokenB*.

* If the pair does not exist, the call will return *address(0)*.&#x20;
* The order of the tokens is irrelevant in this call. For example, a call for ETH, UNIFI will return the same pair address as UNIFI, ETH.&#x20;

### allPairs

```
function allPairs(uint) external view returns (address pair);
```

A call to the `allPairs` function returns the address of a pair based on the indexed *uint* value assigned upon creation of the LP.

* For example, `allPairs(0)` will return the first pair created on uTrade V2 ETH.
* &#x20;If the index number is too high, as in, there aren't enough pairs created yet, the function will return *address(0)*.

### allPairsLength

```
function allPairsLength() external view returns (uint);
```

A call to the `allPairsLength` function returns the current number of pairs.&#x20;

* For example, if there are 201 total liquidity pool pairs on uTrade V2 ETH, this call will return *200* as an uint value.

### feeTo

```
function feeTo() external view returns (address);
```

A call to the `feeTo` function returns the percentage of trading fees that Unifi Protocol receives.&#x20;

* Due to the nature of UP Token economics, this is set to zero, but is preserved for flexibility in the future.

### feeToSetter

```
function feeToSetter() external view returns (address);
```

A call to the `feeToSetter` function returns the address to which the `feeTo` would send trading fees, if trading fees were collected.

## State-Changing Functions <a href="#state-changing-functions" id="state-changing-functions"></a>

### createPair

```
function createPair(address tokenA, address tokenB) external returns (address pair);
```

Creates a liquidity pool pair for *tokenA* and *tokenB* if one does not currently exist. After the function is confirmed on chain, a `PairCreated` event is emitted.

## Interface Code

```
interface UnifiFactory {  
  event PairCreated(address indexed token0, address indexed token1, address pair, uint);
  function getPair(address tokenA, address tokenB) external view returns (address pair);  
  function allPairs(uint) external view returns (address pair);  
  function allPairsLength() external view returns (uint);
  function feeTo() external view returns (address);  function feeToSetter() external view returns (address);
  function createPair(address tokenA, address tokenB) external returns (address pair);
  }
```

###

###


# UnifiPair.sol

**Primary Uses -** UnifiPair.sol is responsible for many of the functionalities of liquidity pool tokens and UP tokens. First, it is responsible for the issuing and burning of Liquidity Pool Tokens (uTokens). In addition, it allows for direct reads of the reserves and ratio of the liquidity pool, as well as swaps. Lastly, it is where UP claims are processed.&#x20;

## uTrade V2 Pair Code / Interfaces

|                                             |                                                                                                                              |
| ------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------- |
| uTrade V2 Pair (Solidity)                   | [Etherscan Verified Pair (UNIFI / ETH) ](https://etherscan.io/address/0x96351b805fb389b761c1318b43a7dc0c679bed5e#code#F3#L1) |
| uTrade V2 Pair Interface as JSON            | Link Here                                                                                                                    |
| uTrade V2 Pair as Typescript                | Link Here                                                                                                                    |
| Import statement codeblock (when available) |                                                                                                                              |

## uTrade V2 Pair Contract Addresses

Each uTrade V2 Liquidity Pool uses the uTrade V2 ERC20 Interface in the contract. An example would be `0x96351b805FB389B761c1318B43a7dC0C679BEd5E` ([Link](https://etherscan.io/address/0x96351b805fb389b761c1318b43a7dc0c679bed5e)) for the UNIFI / ETH pair on Ethereum Main Net.

## Events

### Mint

```
event Mint(address indexed sender, uint amount0, uint amount1);
```

The `Mint` event is emitted any time liquidity tokens are created via the `mint` function. In other words, when a user adds liquidity to a pair, then they will receive LP tokens, therefore the `Mint` event will be emitted.

### Burn

```
event Burn(address indexed sender, uint amount0, uint amount1, address indexed to);
```

The `Burn` event is emitted any time liquidity tokens are burned via the `burn` function. In other words, when a user removes liquidity from a pair,  their LP tokens will be burned, therefore the `Burn` event will be emitted.

### Swap

```
event Swap(
        address indexed sender,
        uint amount0In,
        uint amount1In,
        uint amount0Out,
        uint amount1Out,
        address indexed to
 );
```

The `Swap` event is emitted any time the `swap` function is used. Under the hood, all trades on uTrade V2 are swaps. Therefore, any time somebody trades on the pair, the uTrade contract for that pair will emit a `Swap` event.

### Sync

```
event Sync(uint112 reserve0, uint112 reserve1);
```

The `Sync` event is emitted anytime a function occurs that may change the reserves of a token pair. In other words, anytime the amount of the two tokens within a liquidity pool may change. Therefore, whenever a`mint`, `burn`, `swap`, or `sync` function is called, the `Sync` event will be emitted.

## Read-Only Functions

### MINIMUM\_LIQUIDITY <a href="#minimum_liquidity" id="minimum_liquidity"></a>

```
function MINIMUM_LIQUIDITY() external pure returns (uint);
```

The `MINIMUM_LIQUIDITY`function will always return 1000. The function itself refers to the burning of initial LP tokens that occurs once when a pool is created. This burn of a tiny amount allows for cleaner LP token numbers therefore avoiding LP tokens being represented as very small decimals value. This allows the tick size to be more precise and prevents rounding errors.

### factory

```
function factory() external view returns (address);
```

The `factory` function will return the current factory address for uTrade V2.

### WBNB

```
function WETH() external view returns (address);
```

The `WETH`function will return the address of WETH on Ethereum. As this does not change, it will always return `0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2`.

### token0

```
function token0() external view returns (address);
```

The `token0` function will return the contract address of the first token that makes up the liquidity pair. In other words, if the liquidity pool is made up of USDT / USDC, it will return the contract address of USDT.

### token1

```
function token1() external view returns (address);
```

The `token1` function will return the contract address of the first token that makes up the liquidity pair. In other words, if the liquidity pool is made up of USDT / USDC, it will return the contract address of USDC.

### getReserves

```
function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast);
```

The `getReserves` function returns the reserves of the two tokens that make up the liquidity pool as *reserve0* and *reserve1*. These two values can be helpful in determining the current price of each asset. The function also returns a timestamp with the block number.

### price0CumulativeLast

```
function price0CumulativeLast() external view returns (uint);
```

The `price0CumulativeLast` function is for Oracle usage on uTrade V2. The value of *token0* is captured at the end of each block, and can be called using this function to feed into an Oracle to determine a more time-weighted 'average' price.&#x20;

### price1CumulativeLast

```
function price1CumulativeLast() external view returns (uint);
```

The `price1CumulativeLast` function is for Oracle usage on uTrade V2. The value of *token1* is captured at the end of each block, and can be called using this function to feed into an Oracle to determine a more time-weighted 'average' price.&#x20;

### kLast

```
function kLast() external view returns (uint);
```

The `kLast` function returns the value of *reserve0* \* *reserve1*, after any event that may have triggered a change in the liquidity. For example, the execution of a *swap* function or a *mint* function.

## State-Changing Functions

### mint

```
function mint(address to) external returns (uint liquidity);
```

The `mint` function creates the LP tokens that represent a user's tokens in a liquidity pool. For example, if a user provides 1 ETH and 2000 USDT liquidity to a pool, the Unifi Pair Smart Contract will mint an amount of uUSDT tokens. Will emit the `Mint`, `Sync`, and `Transfer` events.

### burn

```
function burn(address to) external returns (uint amount0, uint amount1);
```

The `burn` function destroys the LP tokens that represent a user's token in a liquidity pool. For example, if a user removes 1 ETH and 2000 USDT liquidity to a pool, the Unifi Pair Smart Contract will burn an amount of uUSDT tokens. Will emit the `Burn`, `Sync`, and `Transfer` events.

### claimUP

```
function claimUP(address to) external lock returns(uint) {
```

The `claimUP` function claims any UP earned from providing liquidity if any exists, and sends the UP to the address provided.

### swap

```
function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external;
```

The `swap` function exchanges one token for another. Under the hood, all trades on uTrade V2 use this function. The *calldata* must be 0 during a normal swap, but must contain data if executing a flash loan. Emits the `Swap` and `Sync` events.

### skim

```
function skim(address to) external;
```

The `skim` function operates as a safeguard if the amount of tokens causes a data error due to too large of a number in the reserves pools. In this unusual circumstance, this will trigger failures in trades. The `skim` function can be called to return the overflowed tokens to the caller.

### sync

```
function sync() external;
```

The `sync` function operates as a safeguard in certain events where the token balance changes outside of normal trading. An example would be an algorithmic stablecoin re-balancing, therefore lowering or raising the amount of the algorithmic stablecoin in the pool. The `sync` function may be called to reset the price ratio to the new reserves. Emits the `Sync`event.

## Interface Code

```
interface IUnifiPair {
    event Mint(address indexed sender, uint amount0, uint amount1);
    event Burn(address indexed sender, uint amount0, uint amount1, address indexed to);
    event Swap(
        address indexed sender,
        uint amount0In,
        uint amount1In,
        uint amount0Out,
        uint amount1Out,
        address indexed to
    );
    event Sync(uint112 reserve0, uint112 reserve1);

    function MINIMUM_LIQUIDITY() external pure returns (uint);
    function factory() external view returns (address);
    function token0() external view returns (address);
    function token1() external view returns (address);
    function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast);
    function price0CumulativeLast() external view returns (uint);
    function price1CumulativeLast() external view returns (uint);
    function kLast() external view returns (uint);

    function mint(address to) external returns (uint liquidity);
    function burn(address to) external returns (uint amount0, uint amount1);
    function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external;
    function skim(address to) external;
    function sync() external;

    function initialize(address, address) external;
}
```


# UnifiRouter.sol

**Primary Uses** - The uTrade V2 Router is the 'brain' of uTrade. The router finds the optimal path for exchanging one token for another. Whenever a trade is made, your wallet sends funds to the router address. The router will then carry out as many transactions as necessary to acquire the desired token. The router also handles adding liquidity to liquidity pools, and sending the corresponding LP tokens to liquidity providers.

## uTrade V2 Router Code / Interfaces

|                                             |                                                                                                                                   |
| ------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------- |
| uTrade V2 Router (Solidity)                 | [Etherscan Verified](https://etherscan.io/address/0x79F12D68631eC6396aAB3CdF31F07C90D0023c9A#code)                                |
| uTrade V2 Router Interface as JSON          | [GitHub](https://github.com/unifiprotocol/uTradeV2-core/blob/52d66be2a472b9697a577757a0446076b6c32001/ABI/JSON/IUnifiRouter.json) |
| uTrade V2 Router Interface as Typescript    | [GitHub](https://github.com/unifiprotocol/uTradeV2-core/blob/52d66be2a472b9697a577757a0446076b6c32001/ABI/TS/IUnifiRouter.ts)     |
| Import statement codeblock (when available) |                                                                                                                                   |

## uTrade V2 Router Contract Addresses

| Network              | Address                                                                                                                                |
| -------------------- | -------------------------------------------------------------------------------------------------------------------------------------- |
| ETH Main Net         | `0x79F12D68631eC6396aAB3CdF31F07C90D0023c9A`([Link](https://etherscan.io/address/0x79F12D68631eC6396aAB3CdF31F07C90D0023c9A))          |
| ETH Ropsten Test Net | `0x2521aaB15347C4C0D7658B5e18e31955Cb496d3B` ([Link](https://ropsten.etherscan.io/address/0x2521aaB15347C4C0D7658B5e18e31955Cb496d3B)) |

## Read-Only Functions <a href="#read-only-functions" id="read-only-functions"></a>

### factory

```
function factory() external pure returns (address);
```

A call to the `factory` function returns the address of the current Factory used by uTrade v2. The current factory address for uTrade V2 on Ethereum is `0x08e7974CacF66C5a92a37c221A15D3c30C7d97e0`.

### WETH

```
function WETH() external pure returns (address);
```

A call to the `WETH` function returns the address of Wrapped ETH (WETH) on Ethereum. As this address does not change, it will always return `0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2`.

### quote

```
function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB);
```

A call to the `quote` function returns the amount of *tokenB* that will be received for an amount of *tokenA*. This can be used to calculate the exchange rate between two tokens without factoring in slippage or fees. By entering the amount of *tokenA,* the total amount of reserves of *tokenA* as *reserveA,* and the total amount of reserves of *tokenB* as *reserveB*, the call will return the equivalent amount of *tokenB*.

### getAmountOut

```
function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut, uint fee) external pure returns (uint amountOut);
```

A call to the `getAmountOut`function with the amount of the token being sent will return the maximum amount of a token to be received, accounting for fees and the total amount of reserves.

### getAmountIn

```
function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut, uint fee) external pure returns (uint amountIn);
```

A call to the `getAmountIn` function with the amount of the token you wish to receive will return the minimum amount required of the token you wish to send, accounting for fees and the total amount of reserves.

### getAmountsOut

```
function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts);
```

A call to the `getAmountsOut` function with the amount of the token being sent will return the maximum amount to be received of multiple different tokens. By entering multiple LP addresses in the *address* array, the function will return the maximum amount of each token that will be received. A call to this function uses the `getReserves` function from [UnifiPair.sol](https://docs.unifiprotocol.com/utrade-v2/ethereum/unifipair.sol) to determine the reserves of the liquidity pool. Then, it calls the `getAmountOut` function to determine the amount of each token in the array that will be received for the *amountIn* value of a token.

### getAmountsIn <a href="#getamountsin" id="getamountsin"></a>

```
function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts);
```

A call to the `getAmountsIn` function with the desired amount of the token to be received will return the minimum amount required to be sent of multiple tokens. By entering multiple LP addresses in the *address* array, the function will return the minimum amount of each token that will need to be sent to receive the desired amount of a token. A call to this function uses the `getReserves` function from [UnifiPair.sol](https://docs.unifiprotocol.com/utrade-v2/ethereum/unifipair.sol) to determine the reserves of the liquidity pool. Then, it calls the `getAmountIn` function to determine the amount of each token in the array that will need to be sent for the *amountOut* value of a token.&#x20;

## State-Changing Functions - Liquidity <a href="#state-changing-functions" id="state-changing-functions"></a>

### addLiquidity

```
function addLiquidity(
        address tokenA,
        address tokenB,
        uint amountADesired,
        uint amountBDesired,
        uint amountAMin,
        uint amountBMin,
        address to,
        uint deadline
) external returns (uint amountA, uint amountB, uint liquidity);
```

The `addLiquidity` function adds the two tokens that make up the liquidity pool - *tokenA* and *tokenB* - at the proper ratio based on the reserves of the pool. For example, if the pool contains 3000 USDT / 2 ETH, a user's liquidity will be added at the ratio of 1500 USDT to 1 ETH, provided there is no price movements in the pair between when the user broadcasts the transaction to when it is mined. In the event of a price movement, the *amountADesired*, *amountBDesired*, *amountAMin*, and *amountBMin* act as a security measure against an adverse price movement. After the liquidity is added, the function sends the corresponding LP tokens to the sender.

In the case of a pool not existing for the two assets, one will be created using [UnifiFactory.sol](https://docs.unifiprotocol.com/utrade-v2/ethereum/unififactory.sol) at the ratio of the assets supplied.

#### Function Parameters Breakdown

| Parameter        | Type    | Description                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          |
| ---------------- | ------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| *tokenA*         | address | Token address of the first asset in the token pair.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  |
| *tokenB*         | address | Token address of the second asset in the token pair.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 |
| *amountADesired* | uint    | The amount of *tokenA* to be added to liquidity if the value of *tokenA* goes down in comparison to *tokenB*.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        |
| *amountBDesired* | uint    | The amount of *tokenB* to be added to liquidity if the value of *tokenB* goes down in comparison to *tokenA.*                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        |
| *amountAMin*     | uint    | <p>Sets the minimum amount of <em>tokenA</em> that can added to the pool before the transaction reverts. This acts as a safeguard. <br></p><ul><li>If the value of <em>tokenA</em> rapidly increases in comparison to <em>tokenB</em>, the user will require less of <em>tokenA</em> to be added to the pool to maintain the original value of the submitted liquidity.</li><li>A user could potentially be adding liquidity during an outlier spike in value. If the amount of <em>tokenA</em> required falls below this value, the transaction will revert.</li><li>This value must be less than or equal to <em>amountADesired</em>.</li></ul>    |
| *amountBMin*     | uint    | <p>Sets the minimum amount of <em>tokenB</em> that can added to the pool before the transaction reverts. This acts as a safeguard.</p><p></p><ul><li>If the value of <em>tokenB</em> rapidly increases in comparison to <em>tokenA</em>, the user will require less of <em>tokenB</em> to be added to the pool to maintain the original value of the submitted liquidity.</li><li> A user could potentially be adding liquidity during an outlier spike in value. If the amount of <em>tokenB</em> required falls below this value, the transaction will revert.</li><li>This value must be less than or equal to <em>amountBDesired</em>.</li></ul> |
| *to*             | address | The address to which the LP tokens for the uTrade V2 pool will be sent.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              |
| *deadline*       | uint    | The UNIX timestamp for which this transaction must be completed. If the transaction is mined after this deadline, the transaction will revert.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       |

#### Function Return Parameter Breakdown

| Parameter   | Type | Description                                                                                                |
| ----------- | ---- | ---------------------------------------------------------------------------------------------------------- |
| *amountA*   | uint | The exact amount of *tokenA* that was sent to the pool.                                                    |
| *amountB*   | uint | The exact amount of *tokenB* that was sent to the pool.                                                    |
| *liquidity* | uint | The exact amount of liquidity tokens minted and sent to the address provided in the *to* paramete&#x72;*.* |

### addLiquidityETH

```
function addLiquidityETH(
        address token,
        uint amountTokenDesired,
        uint amountTokenMin,
        uint amountETHMin,
        address to,
        uint deadline
    ) external payable returns (uint amountToken, uint amountETH, uint liquidity);
```

The `addLiquidityEth` function is similar to the `addLiquidity` function except it accounts for one token being a native asset. In the case of Ethereum, this native asset would be ETH. This function will convert ETH to WETH, will pair that WETH with the supplied other token, and add the liquidity to the pool. This function will add at the ideal ratio based on when the transaction is mined.\
\
In the case of a pool not existing for WETH and the token provided, one will be created using [UnifiFactory.sol](https://docs.unifiprotocol.com/utrade-v2/ethereum/unififactory.sol) at the ratio of the assets supplied.

* This function requires a *msg.value* with the amount of ETH to be added.&#x20;
  * The *msg.value* acts as the amountETHDesired. As in, if the ratio between ETH and the token being paired with it change, this is the number of ETH that will be added to the pool.
  * Any leftover ETH is returned to the *msg.sender* address.

#### Function Parameter Breakdown

| Parameter                      | Type    | Description                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 |
| ------------------------------ | ------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| *token*                        | address | The address of the supplied token for the liquidity pool. In other words, the asset that ETH is paired with.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                |
| *amountTokenDesired*           | uint    | The amount of the supplied token to be added to liquidity if the value of token goes down in comparison to ETH.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             |
| (*amountETHDesired*) msg.value | uint    | Sent as the msg.value, the amount of ETH to be added to liquidity if the value of ETH goes down in comparison to token.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     |
| *amountTokenMin*               | uint    | <p>Sets the minimum amount of the supplied token that can added to the pool before the transaction reverts. This acts as a safeguard. </p><p></p><ul><li>If the value of supplied token rapidly increases in comparison to ETH, the user will require less of the token to be added to the pool to maintain the original value of the submitted liquidity.</li><li>A user could potentially be adding liquidity during an outlier spike in value. If the amount of the supplied token required falls below this value, the transaction will revert.</li><li>This value must be less than or equal to <em>amountTokenDesired</em>.</li></ul> |
| *amountETHMin*                 | uint    | <p></p><p>Sets the minimum amount of ETH that can added to the pool before the transaction reverts. This acts as a safeguard. </p><p></p><ul><li>If the value of ETH increases in comparison to the supplied token, the user will require less ETH to be added to the pool to maintain the original value of the submitted liquidity.</li><li>A user could potentially be adding liquidity during an outlier spike in value. If the amount of ETH required falls below this value, the transaction will revert.</li><li>This value must be less than or equal to <em>amountETHDesired</em>.</li></ul>                                       |
| *to*                           | address | The address to which the LP tokens for the uTrade V2 pool will be sent.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     |
| *deadline*                     | uint    | The UNIX timestamp for which this transaction must be completed. If the transaction is mined after this deadline, the transaction will revert.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              |

#### Function Return Parameter Breakdown

| Parameter     | Type | Description                                                                                                |
| ------------- | ---- | ---------------------------------------------------------------------------------------------------------- |
| *amountToken* | uint | The exact amount of the supplied token sent to the pool.                                                   |
| *amountETH*   | uint | The exact amount of ETH converted to WETH, and then added to the pool.                                     |
| *liquidity*   | uint | The exact amount of liquidity tokens minted and sent to the address provided in the *to* paramete&#x72;*.* |

### removeLiquidity

```
function removeLiquidity(
        address tokenA,
        address tokenB,
        uint liquidity,
        uint amountAMin,
        uint amountBMin,
        address to,
        uint deadline
) external returns (uint amountA, uint amountB);
```

The `removeLiquidity` function removes the two tokens that make up liquidity from a pool. In other words, this function is used when the pool consists of two ERC-20 tokens.

* In the event one of the assets is paired with ETH, ETH will have been wrapped and paired with WETH (Wrapped Ether). If the user wishes to withdraw WETH instead of withdrawing as ETH, this function should be used instead of `removeLiquidityETH` .

#### Function Parameter Breakdown

| Parameter    | Type    | Description                                                                                                                                                                                                              |
| ------------ | ------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| *tokenA*     | address | Token address of the first asset in the pair.                                                                                                                                                                            |
| *tokenB*     | address | Token address of the second asset in the pair.                                                                                                                                                                           |
| *liquidity*  | uint    | The amount of liquidity tokens to be redeemed and removed.                                                                                                                                                               |
| *amountAMin* | uint    | Sets the minimum amount of *tokenA* to be removed from the the pool. This acts as a safeguard against removing liquidity during a spike in value. If the removed amount falls below this value, the transaction reverts. |
| *amountBMin* | uint    | Sets the minimum amount of *tokenB* to be removed from the the pool. This acts as a safeguard against removing liquidity during a spike in value. If the removed amount falls below this value, the transaction reverts. |
| *to*         | address | The address to where the redeemed tokens will be sent.                                                                                                                                                                   |
| *deadline*   | uint    | The UNIX timestamp for which this transaction must be completed. If the transaction is mined after this deadline, the transaction will revert.                                                                           |

#### Function Return Parameter Breakdown

| Parameter | Title | Description                                                                      |
| --------- | ----- | -------------------------------------------------------------------------------- |
| *amountA* | uint  | The exact amount of *tokenA* sent to the address provided in the *to* parameter. |
| *amountB* | uint  | The exact amount of *tokenB* sent to the address provided in the *to* parameter. |

### removeLiquidityETH

```
function removeLiquidityETH(
        address token,
        uint liquidity,
        uint amountTokenMin,
        uint amountETHMin,
        address to,
        uint deadline
) external returns (uint amountToken, uint amountETH);
```

The `removeLiquidityETH` function removes ETH as well as the corresponding paired token in the liquidity pool. In other words, this function is used when the pool consists of WETH and an ERC-20 token.

* In the event one of the assets is paired with ETH, ETH has been wrapped into WETH (Wrapped Ether). This function will unwrap the WETH as the liquidity removed. If the user wishes to withdraw WETH instead of withdrawing as ETH, the `removeLiquidity` function should be used.

#### Function Parameter Breakdown

| Parameter        | Type    | Description                                                                                                                                                                                                             |
| ---------------- | ------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| *token*          | address | Token address of the ERC-20 asset in the pair.                                                                                                                                                                          |
| *liquidity*      | uint    | The amount of liquidity tokens to be redeemed and removed.                                                                                                                                                              |
| *amountTokenMin* | uint    | Sets the minimum amount of *token* to be removed from the the pool. This acts as a safeguard against removing liquidity during a spike in value. If the removed amount falls below this value, the transaction reverts. |
| *amountETHMin*   | uint    | Sets the minimum amount of ETH to be removed from the pool. This acts as a safeguard against removing liquidity during a spike in value. If the removed amount falls below this value, the transaction reverts.         |
| *to*             | address | The address to where ETH and token will be sent.                                                                                                                                                                        |
| *deadline*       | uint    | The UNIX timestamp for which this transaction must be completed. If the transaction is mined after this deadline, the transaction will revert.                                                                          |

#### Function Return Parameter Breakdown

| Parameter     | Value | Description                                                                     |
| ------------- | ----- | ------------------------------------------------------------------------------- |
| *amountToken* | uint  | The exact amount of *token* sent to the address provided in the *to* parameter. |
| *amountETH*   | uint  | The exact amount of ETH sent to the address provided in the *to* parameter.     |

### removeLiquidityWithPermit

```
function removeLiquidityWithPermit(
        address tokenA,
        address tokenB,
        uint liquidity,
        uint amountAMin,
        uint amountBMin,
        address to,
        uint deadline,
        bool approveMax, uint8 v, bytes32 r, bytes32 s
) external returns (uint amountA, uint amountB);
```

The `removeLiquidityWithPermit` functions removes the two tokens that make up liquidity from a pool. In other words, this function is used when the pool consists of two ERC-20 tokens. This function operates similarly to the `removeLiquidity` function with the added benefit of not requiring pre-approvals using permit.

* In the event one of the assets is paired with ETH, ETH will have been wrapped and paired with WETH (Wrapped ETH). If the user wishes to withdraw WETH instead of withdrawing as ETH, this function should be used instead of `removeLiquidityETHWithPermit` .

#### Function Parameter Breakdown

| Parameter    | Type    | Description                                                                                                                                                                                                              |
| ------------ | ------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| *tokenA*     | address | Token address of the first asset in the pair.                                                                                                                                                                            |
| *tokenB*     | address | Token address of the second asset in the pair.                                                                                                                                                                           |
| *liquidity*  | uint    | The amount of liquidity tokens to be redeemed and removed.                                                                                                                                                               |
| *amountAMin* | uint    | Sets the minimum amount of *tokenA* to be removed from the the pool. This acts as a safeguard against removing liquidity during a spike in value. If the removed amount falls below this value, the transaction reverts. |
| *amountBMin* | uint    | Sets the minimum amount of *tokenB* to be removed from the the pool. This acts as a safeguard against removing liquidity during a spike in value. If the removed amount falls below this value, the transaction reverts. |
| *to*         | address | The address to where the redeemed tokens will be sent.                                                                                                                                                                   |
| *deadline*   | uint    | The UNIX timestamp for which this transaction must be completed. If the transaction is mined after this deadline, the transaction will revert.                                                                           |
| *approveMax* | bool    | Sets a true or false value on if approval amount in the signature is for liquidity or for uint(-1).                                                                                                                      |
| *v*          | uint8   | The v value of the permit. This is one of the three values that makes up the approval signature.                                                                                                                         |
| *r*          | bytes32 | The r value of the permit. This is one of the three values that makes up the approval signature.                                                                                                                         |
| *s*          | bytes32 | The s value of the permit. This is one of the three values that makes up the approval signature.                                                                                                                         |

#### Function Return Parameter Breakdown

| Parameter | Title | Description                                                                      |
| --------- | ----- | -------------------------------------------------------------------------------- |
| *amountA* | uint  | The exact amount of *tokenA* sent to the address provided in the *to* parameter. |
| *amountB* | uint  | The exact amount of *tokenB* sent to the address provided in the *to* parameter. |

### removeLiquidityETHWithPermit

```
function removeLiquidityETHWithPermit(
        address token,
        uint liquidity,
        uint amountTokenMin,
        uint amountETHMin,
        address to,
        uint deadline,
        bool approveMax, uint8 v, bytes32 r, bytes32 s
) external returns (uint amountToken, uint amountETH);
    
```

The `removeLiquidityETHWithPermit` function removes ETH as well as the corresponding paired token in the liquidity pool. In other words, this function is used when the pool consists of WETH and a ERC-20 token. This function operates similarly to the `removeLiquidityETH`function with the added benefit of not requiring pre-approvals using permit.

* In the event one of the assets is paired with ETH, ETH has been wrapped into WETH (Wrapped Ether). This function will unwrap the WETH as the liquidity removed. If the user wishes to withdraw WETH instead of withdrawing as ETH, the `removeLiquidityWithPermit` function should be used.

#### Function Parameter Breakdown

| Parameter        | Type    | Description                                                                                                                                                                                                             |
| ---------------- | ------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| *token*          | address | Token address of the ERC-20 asset in the pair.                                                                                                                                                                          |
| *liquidity*      | uint    | The amount of liquidity tokens to be redeemed and removed.                                                                                                                                                              |
| *amountTokenMin* | uint    | Sets the minimum amount of *token* to be removed from the the pool. This acts as a safeguard against removing liquidity during a spike in value. If the removed amount falls below this value, the transaction reverts. |
| *amountETHMin*   | uint    | Sets the minimum amount of ETH to be removed from the the pool. This acts as a safeguard against removing liquidity during a spike in value. If the removed amount falls below this value, the transaction reverts.     |
| *to*             | address | The address to where ETH and token will be sent.                                                                                                                                                                        |
| *deadline*       | uint    | The UNIX timestamp for which this transaction must be completed. If the transaction is mined after this deadline, the transaction will revert.                                                                          |
| *v*              | uint8   | The v value of the permit. This is one of the three values that makes up the approval signature.                                                                                                                        |
| *r*              | bytes32 | The r value of the permit. This is one of the three values that makes up the approval signature.                                                                                                                        |
| *s*              | bytes32 | The s value of the permit. This is one of the three values that makes up the approval signature.                                                                                                                        |

#### Function Return Parameter Breakdown

| Parameter     | Value | Description                                                                     |
| ------------- | ----- | ------------------------------------------------------------------------------- |
| *amountToken* | uint  | The exact amount of *token* sent to the address provided in the *to* parameter. |
| *amountETH*   | uint  | The exact amount of ETH sent to the address provided in the *to* parameter.     |

### removeLiquidityETHSupportingFeeOnTransferTokens

```
function removeLiquidityETHSupportingFeeOnTransferTokens(
        address token,
        uint liquidity,
        uint amountTokenMin,
        uint amountETHMin,
        address to,
        uint deadline
) external returns (uint amountETH);
```

The `removeLiquidityETHSupportingFeeOnTransferTokens`function is similar to the `removeLiquidityETH` function, and contains the same call parameters. This function removes ETH as well as the corresponding paired token in the liquidity pool. In other words, this function is used when the pool consists of WETH and a ERC-20 token.&#x20;

However, this function allows for fee on transfer tokens, such as PAXG, to be used on uTrade.&#x20;

#### Function Parameter Breakdown

| Parameter        | Type    | Description                                                                                                                                                                                                             |
| ---------------- | ------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| *token*          | address | Token address of the ERC-20 asset in the pair.                                                                                                                                                                          |
| *liquidity*      | uint    | The amount of liquidity tokens to be redeemed and removed.                                                                                                                                                              |
| *amountTokenMin* | uint    | Sets the minimum amount of *token* to be removed from the the pool. This acts as a safeguard against removing liquidity during a spike in value. If the removed amount falls below this value, the transaction reverts. |
| *amountETHMin*   | uint    | Sets the minimum amount of ETH to be removed from the the pool. This acts as a safeguard against removing liquidity during a spike in value. If the removed amount falls below this value, the transaction reverts.     |
| *to*             | address | The address to where ETH and the paired token will be sent.                                                                                                                                                             |
| *deadline*       | uint    | The UNIX timestamp for which this transaction must be completed. If the transaction is mined after this deadline, the transaction will revert.                                                                          |

#### Function Return Parameter Breakdown

| Parameter   | Value | Description                                                                                                                                                                                                                   |
| ----------- | ----- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| *amountETH* | uint  | The exact amount of ETH sent to the address provided in the *to* parameter. Note that the *amountToken* parameter is not returned. The amount of fee on transfer that a token may have is not available prior to transaction. |

### removeLiquidityETHWithPermitSupportingFeeOnTransferTokens

```
function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens(
        address token,
        uint liquidity,
        uint amountTokenMin,
        uint amountETHMin,
        address to,
        uint deadline,
        bool approveMax, uint8 v, bytes32 r, bytes32 s
) external returns (uint amountETH);
```

The `removeLiquidityETHWithPermitSupportingFeeOnTransferTokens`function is similar to the `removeLiquidityETHWithPermit`function. This function removes ETH as well as the corresponding paired token in the liquidity pool. In other words, this function is used when the pool consists of WETH and an ERC-20 token. This function operates similarly to the `removeLiquidityETHfunction` with the added benefit of not requiring pre-approvals using permit. In addition, this function allows for fee on transfer tokens, such as PAXG, to be used on uTrade.&#x20;

#### Function Parameter Breakdown

| Parameter        | Type    | Description                                                                                                                                                                                                             |
| ---------------- | ------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| *token*          | address | Token address of the ERC-20 asset in the pair.                                                                                                                                                                          |
| *liquidity*      | uint    | The amount of liquidity tokens to be redeemed and removed.                                                                                                                                                              |
| *amountTokenMin* | uint    | Sets the minimum amount of *token* to be removed from the the pool. This acts as a safeguard against removing liquidity during a spike in value. If the removed amount falls below this value, the transaction reverts. |
| *amountETHMin*   | uint    | Sets the minimum amount of ETH to be removed from the the pool. This acts as a safeguard against removing liquidity during a spike in value. If the removed amount falls below this value, the transaction reverts.     |
| *to*             | address | The address to where ETH and token will be sent.                                                                                                                                                                        |
| *deadline*       | uint    | The UNIX timestamp for which this transaction must be completed. If the transaction is mined after this deadline, the transaction will revert.                                                                          |
| *v*              | uint8   | The v value of the permit. This is one of the three values that makes up the approval signature.                                                                                                                        |
| *r*              | bytes32 | The r value of the permit. This is one of the three values that makes up the approval signature.                                                                                                                        |
| *s*              | bytes32 | The s value of the permit. This is one of the three values that makes up the approval signature.                                                                                                                        |

#### Function Return Parameter Breakdown

| Parameter   | Value | Description                                                                                                                                                                                                                   |
| ----------- | ----- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| *amountETH* | uint  | The exact amount of ETH sent to the address provided in the *to* parameter. Note that the *amountToken* parameter is not returned. The amount of fee on transfer that a token may have is not available prior to transaction. |

## State-Changing Functions - Swap

### swapExactTokensForTokens

```
function swapExactTokensForTokens(
        uint amountIn,
        uint amountOutMin,
        address[] calldata path,
        address to,
        uint deadline
) external returns (uint[] memory amounts);
```

The `swapExactTokensForTokens` function sends an exact amount of tokens for the maximum amount of another token.&#x20;

#### Function Parameter Breakdown

| Parameter      | Type                | Description                                                                                                                                                                                                                                                                                                                                                                                                                            |
| -------------- | ------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| *amountIn*     | uint                | The amount of tokens being sent to swap into another token                                                                                                                                                                                                                                                                                                                                                                             |
| *amountOutMin* | uint                | Sets the minimum amount of the desired token to receive. This acts as a safeguard against removing liquidity during a spike in value. If the amount to be received falls below this value, the transaction reverts.                                                                                                                                                                                                                    |
| *path*         | address\[] calldata | <p>The pathway to change one token to another, consisting of an array of addresses. Each token must have an existing liquidity pool, as well as have liquidity.<br></p><p>The <em>path</em> represents the pathway from one token to another. If a pair exists for the two tokens you wish to exchange, this will contain two values inside of an array. However, if there is no direct pair, multiple addresses may be required. </p> |
| *to*           | address             | The address to where the desired token will be sent.                                                                                                                                                                                                                                                                                                                                                                                   |
| *deadline*     | uint                | The UNIX timestamp for which this transaction must be completed. If the transaction is mined after this deadline, the transaction will revert.                                                                                                                                                                                                                                                                                         |

#### Function Return Parameter Breakdown

| Parameter | Type           | Description                                                                                                |
| --------- | -------------- | ---------------------------------------------------------------------------------------------------------- |
| *amounts* | uint\[] memory | The exact amount of tokens sent into the swap, as well as the exact return amount of all subsequent swaps. |

### swapTokensForExactTokens

```
function swapTokensForExactTokens(
        uint amountOut,
        uint amountInMax,
        address[] calldata path,
        address to,
        uint deadline
) external returns (uint[] memory amounts);
```

The `swapTokensForExactTokens` function sends the minimum amount of tokens for the exact amount of another token.&#x20;

#### Function Parameter Breakdown

| Parameter     | Type                | Description                                                                                                                                                                                                                                                                                                                                                                                                                            |
| ------------- | ------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| *amountOut*   | uint                | The exact amount of the desired tokens to be received.                                                                                                                                                                                                                                                                                                                                                                                 |
| *amountInMax* | uint                | Sets the maximum amount of token to be sent in. This acts as a safeguard against removing liquidity during a spike in value. If the amount to be sent rises above this value, the transaction reverts.                                                                                                                                                                                                                                 |
| *path*        | address\[] calldata | <p>The pathway to change one token to another, consisting of an array of addresses. Each token must have an existing liquidity pool, as well as have liquidity.<br></p><p>The <em>path</em> represents the pathway from one token to another. If a pair exists for the two tokens you wish to exchange, this will contain two values inside of an array. However, if there is no direct pair, multiple addresses may be required. </p> |
| *to*          | address             | The address to where the desired token will be sent.                                                                                                                                                                                                                                                                                                                                                                                   |
| *deadline*    | uint                | The UNIX timestamp for which this transaction must be completed. If the transaction is mined after this deadline, the transaction will revert.                                                                                                                                                                                                                                                                                         |

#### Function Return Parameter Breakdown

| Parameter | Type           | Description                                                                                                |
| --------- | -------------- | ---------------------------------------------------------------------------------------------------------- |
| *amounts* | uint\[] memory | The exact amount of tokens sent into the swap, as well as the exact return amount of all subsequent swaps. |

### swapExactETHForTokens

```
function swapExactETHForTokens(
        uint amountOutMin, 
        address[] calldata path, 
        address to, 
        uint deadline)
        external
        payable
returns (uint[] memory amounts);
```

The `swapExactETHForTokens` function sends an exact amount of ETH for a desired token.

#### Function Parameter Breakdown

| Parameter                                           | Type                | Description                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    |
| --------------------------------------------------- | ------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| <p><em>(amountIn)</em></p><p><em>msg.value</em></p> | uint                | Sent as the msg.value, the amount of ETH to be swapped.                                                                                                                                                                                                                                                                                                                                                                                                                                                                        |
| *amountOutMin*                                      | uint                | Sets the minimum amount of the desired token to receive. This acts as a safeguard against removing liquidity during a spike in value. If the amount to be received falls below this value, the transaction reverts.                                                                                                                                                                                                                                                                                                            |
| *path*                                              | address\[] calldata | <p>The pathway to change one token to another, consisting of an array of addresses. Each token must have an existing liquidity pool, as well as have liquidity.<br></p><p>The <em>path</em> represents the pathway from one token to another. If a pair exists for the two tokens you wish to exchange, this will contain two values inside of an array. However, if there is no direct pair, multiple addresses may be required. </p><p></p><p>As the first swap is swapping ETH to WETH, the first address must be WETH.</p> |
| *to*                                                | address             | The address to where the desired token will be sent.                                                                                                                                                                                                                                                                                                                                                                                                                                                                           |
| *deadline*                                          | uint                | The UNIX timestamp for which this transaction must be completed. If the transaction is mined after this deadline, the transaction will revert.                                                                                                                                                                                                                                                                                                                                                                                 |

#### Function Return Parameter Breakdown

| Parameter | Type           | Description                                                                                             |
| --------- | -------------- | ------------------------------------------------------------------------------------------------------- |
| *amounts* | uint\[] memory | The exact amount of ETH sent into the swap, as well as the exact return amount of all subsequent swaps. |

### swapTokensForExactETH

```
function swapTokensForExactETH(
        uint amountOut, 
        uint amountInMax, 
        address[] calldata path, 
        address to, 
        uint deadline)
        external
        returns (uint[] memory amounts);
```

The `swapTokensForExactETH` function sends an amount of tokens for an exact amount of ETH.

#### Function Parameter Breakdown

| Parameter     | Type                | Description                                                                                                                                                                                                                                                                                                                                                                                                                            |
| ------------- | ------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| *amountOut*   | uint                | The exact amount of the ETH to be received.                                                                                                                                                                                                                                                                                                                                                                                            |
| *amountInMax* | uint                | Sets the maximum amount of token to be sent in. This acts as a safeguard against removing liquidity during a spike in value. If the amount to be sent rises above this value, the transaction reverts.                                                                                                                                                                                                                                 |
| *path*        | address\[] calldata | <p>The pathway to change one token to another, consisting of an array of addresses. Each token must have an existing liquidity pool, as well as have liquidity.<br></p><p>The <em>path</em> represents the pathway from one token to another. If a pair exists for the two tokens you wish to exchange, this will contain two values inside of an array. However, if there is no direct pair, multiple addresses may be required. </p> |
| *to*          | address             | The address to where the desired token will be sent.                                                                                                                                                                                                                                                                                                                                                                                   |
| *deadline*    | uint                | The UNIX timestamp for which this transaction must be completed. If the transaction is mined after this deadline, the transaction will revert.                                                                                                                                                                                                                                                                                         |

#### Function Return Parameter Breakdown

| Parameter | Type           | Description                                                                                         |
| --------- | -------------- | --------------------------------------------------------------------------------------------------- |
| *amounts* | uint\[] memory | The exact amount of tokens sent into the swap, as well as the exact amount of all subsequent swaps. |

### swapExactTokensForETH

```
function swapExactTokensForETH(
        uint amountIn, 
        uint amountOutMin, 
        address[] calldata path, 
        address to, 
        uint deadline)
        external
        returns (uint[] memory amounts);
```

The `swapExactTokensForETH` function sends an exact amount of tokens for ETH.

#### Function Parameter Breakdown

| Parameter      | Type                | Description                                                                                                                                                                                                                                                                                                                                                                                                                            |
| -------------- | ------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| *amountIn*     | uint                | The amount of tokens being sent to swap into ETH.                                                                                                                                                                                                                                                                                                                                                                                      |
| *amountOutMin* | uint                | Sets the minimum amount of the ETH to receive. This acts as a safeguard against removing liquidity during a spike in value. If the amount to be received falls below this value, the transaction reverts.                                                                                                                                                                                                                              |
| *path*         | address\[] calldata | <p>The pathway to change one token to another, consisting of an array of addresses. Each token must have an existing liquidity pool, as well as have liquidity.<br></p><p>The <em>path</em> represents the pathway from one token to another. If a pair exists for the two tokens you wish to exchange, this will contain two values inside of an array. However, if there is no direct pair, multiple addresses may be required. </p> |
| *to*           | address             | The address to where the desired token will be sent.                                                                                                                                                                                                                                                                                                                                                                                   |
| *deadline*     | uint                | The UNIX timestamp for which this transaction must be completed. If the transaction is mined after this deadline, the transaction will revert.                                                                                                                                                                                                                                                                                         |

#### Function Parameter Return Breakdown

| Parameter | Type           | Description                                                                                         |
| --------- | -------------- | --------------------------------------------------------------------------------------------------- |
| *amounts* | uint\[] memory | The exact amount of tokens sent into the swap, as well as the exact amount of all subsequent swaps. |

### swapETHForExactTokens

```
function swapETHForExactTokens(
        uint amountOut, 
        address[] calldata path, 
        address to, 
        uint deadline)
        external
        payable
        returns (uint[] memory amounts);
```

The `swapETHForExactTokens` function swaps an exact amount of ETH for an amount of the desired token.

#### Function Parameter Breakdown

| Parameter                                           | Type                | Description                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    |
| --------------------------------------------------- | ------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| <p><em>(amountIn)</em></p><p><em>msg.value</em></p> | uint                | Sent as the msg.value, the amount of ETH to be swapped.                                                                                                                                                                                                                                                                                                                                                                                                                                                                        |
| *amountOutMin*                                      | uint                | Sets the minimum amount of the desired token to receive. This acts as a safeguard against removing liquidity during a spike in value. If the amount to be received falls below this value, the transaction reverts.                                                                                                                                                                                                                                                                                                            |
| *path*                                              | address\[] calldata | <p>The pathway to change one token to another, consisting of an array of addresses. Each token must have an existing liquidity pool, as well as have liquidity.<br></p><p>The <em>path</em> represents the pathway from one token to another. If a pair exists for the two tokens you wish to exchange, this will contain two values inside of an array. However, if there is no direct pair, multiple addresses may be required. </p><p></p><p>As the first swap is swapping ETH to WETH, the first address must be WETH.</p> |
| *to*                                                | address             | The address to where the desired token will be sent.                                                                                                                                                                                                                                                                                                                                                                                                                                                                           |
| *deadline*                                          | uint                | The UNIX timestamp for which this transaction must be completed. If the transaction is mined after this deadline, the transaction will revert.                                                                                                                                                                                                                                                                                                                                                                                 |

#### Function Return Parameter Breakdown

| Parameter | Type           | Description                                                                                             |
| --------- | -------------- | ------------------------------------------------------------------------------------------------------- |
| *amounts* | uint\[] memory | The exact amount of ETH sent into the swap, as well as the exact return amount of all subsequent swaps. |

### swapExactTokensForTokensSupportingFeeOnTransferTokens

```
function swapExactTokensForTokensSupportingFeeOnTransferTokens(
        uint amountIn,
        uint amountOutMin,
        address[] calldata path,
        address to,
        uint deadline
) external;
```

The `swapExactTokensForTokensSupportingFeeOnTransferTokens` function is similar to `swapExactTokensForTokens` as it swaps one ERC-20 token for another ERC-20 token. In addition, this function allows for fee on transfer tokens, such as PAXG, to be used on uTrade.

#### Function Parameter Breakdown

| Name           | Type                |                                                                                                                                                                                                                                                                                                                                                                                                                              |
| -------------- | ------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| *amountIn*     | uint                | The amount of tokens being sent to swap into another token.                                                                                                                                                                                                                                                                                                                                                                  |
| *amountOutMin* | uint                | Sets the minimum amount of the desired token to receive. This acts as a safeguard against removing liquidity during a spike in value. If the amount to be received falls below this value, the transaction reverts.                                                                                                                                                                                                          |
| *path*         | address\[] calldata | <p>The pathway to change one token to another, consisting of an array of addresses. Each token must have an existing liquidity pool, as well as have liquidity.<br></p><p>The path represents the pathway from one token to another. If a pair exists for the two tokens you wish to exchange, this will contain two values inside of an array. However, if there is no direct pair, multiple addresses may be required.</p> |
| *to*           | address             | The address to where the desired token will be sent.                                                                                                                                                                                                                                                                                                                                                                         |
| *deadline*     | uint                | The UNIX timestamp for which this transaction must be completed. If the transaction is mined after this deadline, the transaction will revert.                                                                                                                                                                                                                                                                               |

### swapExactETHForTokensSupportingFeeOnTransferTokens

```
function swapExactETHForTokensSupportingFeeOnTransferTokens(
        uint amountOutMin,
        address[] calldata path,
        address to,
        uint deadline
 ) external payable;
```

The `swapExactETHForTokensSupportingFeeOnTransferTokens`function  is similar to `swapExactETHForTokens` function as it swaps an exact amount of ETH for ERC-20 tokens. In addition, this function allows for fee on transfer tokens, such as PAXG, to be used on uTrade.&#x20;

#### Function Parameter Breakdown

| Parameter                                           | Type                | Description                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    |
| --------------------------------------------------- | ------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| <p><em>(amountIn)</em></p><p><em>msg.value</em></p> | uint                | Sent as the msg.value, the exact amount of ETH to be swapped.                                                                                                                                                                                                                                                                                                                                                                                                                                                                  |
| *amountOutMin*                                      | uint                | Sets the minimum amount of the desired token to receive. This acts as a safeguard against removing liquidity during a spike in value. If the amount to be received falls below this value, the transaction reverts.                                                                                                                                                                                                                                                                                                            |
| *path*                                              | address\[] calldata | <p>The pathway to change one token to another, consisting of an array of addresses. Each token must have an existing liquidity pool, as well as have liquidity.<br></p><p>The <em>path</em> represents the pathway from one token to another. If a pair exists for the two tokens you wish to exchange, this will contain two values inside of an array. However, if there is no direct pair, multiple addresses may be required. </p><p></p><p>As the first swap is swapping ETH to WETH, the first address must be WETH.</p> |
| *to*                                                | address             | The address to where the desired token will be sent.                                                                                                                                                                                                                                                                                                                                                                                                                                                                           |
| *deadline*                                          | uint                | The UNIX timestamp for which this transaction must be completed. If the transaction is mined after this deadline, the transaction will revert.                                                                                                                                                                                                                                                                                                                                                                                 |

### swapExactTokensForETHSupportingFeeOnTransferTokens <a href="#swapexacttokensforethsupportingfeeontransfertokens" id="swapexacttokensforethsupportingfeeontransfertokens"></a>

```
function swapExactTokensForETHSupportingFeeOnTransferTokens(
        uint amountIn,
        uint amountOutMin,
        address[] calldata path,
        address to,
        uint deadline
) external;
```

The function `swapExactTokensForETHSupportingFeeOnTransferTokens`is similar to the `swapExactTokensForETH`function, as it swaps an exact amount of ERC-20 tokens for ETH. In addition, this function allows for fee on transfer tokens, such as PAXG, to be used on uTrade.

#### Function Parameter Breakdown

| Parameter      | Type                | Description                                                                                                                                                                                                                                                                                                                                                                                                                            |
| -------------- | ------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| *amountIn*     | uint                | The amount of tokens being sent to swap into ETH.                                                                                                                                                                                                                                                                                                                                                                                      |
| *amountOutMin* | uint                | Sets the minimum amount of the ETH to receive. This acts as a safeguard against removing liquidity during a spike in value. If the amount to be received falls below this value, the transaction reverts.                                                                                                                                                                                                                              |
| *path*         | address\[] calldata | <p>The pathway to change one token to another, consisting of an array of addresses. Each token must have an existing liquidity pool, as well as have liquidity.<br></p><p>The <em>path</em> represents the pathway from one token to another. If a pair exists for the two tokens you wish to exchange, this will contain two values inside of an array. However, if there is no direct pair, multiple addresses may be required. </p> |
| *to*           | address             | The address to where the desired token will be sent.                                                                                                                                                                                                                                                                                                                                                                                   |
| *deadline*     | uint                | The UNIX timestamp for which this transaction must be completed. If the transaction is mined after this deadline, the transaction will revert.                                                                                                                                                                                                                                                                                         |

## Interface Code

```
interface IUnifiRouter01 {
    function factory() external pure returns (address);
    function WETH() external pure returns (address);

    function addLiquidity(
        address tokenA,
        address tokenB,
        uint amountADesired,
        uint amountBDesired,
        uint amountAMin,
        uint amountBMin,
        address to,
        uint deadline
    ) external returns (uint amountA, uint amountB, uint liquidity);
    function addLiquidityETH(
        address token,
        uint amountTokenDesired,
        uint amountTokenMin,
        uint amountETHMin,
        address to,
        uint deadline
    ) external payable returns (uint amountToken, uint amountETH, uint liquidity);
    function removeLiquidity(
        address tokenA,
        address tokenB,
        uint liquidity,
        uint amountAMin,
        uint amountBMin,
        address to,
        uint deadline
    ) external returns (uint amountA, uint amountB);
    function removeLiquidityETH(
        address token,
        uint liquidity,
        uint amountTokenMin,
        uint amountETHMin,
        address to,
        uint deadline
    ) external returns (uint amountToken, uint amountETH);
    function removeLiquidityWithPermit(
        address tokenA,
        address tokenB,
        uint liquidity,
        uint amountAMin,
        uint amountBMin,
        address to,
        uint deadline,
        bool approveMax, uint8 v, bytes32 r, bytes32 s
    ) external returns (uint amountA, uint amountB);
    function removeLiquidityETHWithPermit(
        address token,
        uint liquidity,
        uint amountTokenMin,
        uint amountETHMin,
        address to,
        uint deadline,
        bool approveMax, uint8 v, bytes32 r, bytes32 s
    ) external returns (uint amountToken, uint amountETH);
    function swapExactTokensForTokens(
        uint amountIn,
        uint amountOutMin,
        address[] calldata path,
        address to,
        uint deadline
    ) external returns (uint[] memory amounts);
    function swapTokensForExactTokens(
        uint amountOut,
        uint amountInMax,
        address[] calldata path,
        address to,
        uint deadline
    ) external returns (uint[] memory amounts);
    function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline)
        external
        payable
        returns (uint[] memory amounts);
    function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline)
        external
        returns (uint[] memory amounts);
    function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline)
        external
        returns (uint[] memory amounts);
    function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline)
        external
        payable
        returns (uint[] memory amounts);

    function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB);
    function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut, uint fee) external pure returns (uint amountOut);
    function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut, uint fee) external pure returns (uint amountIn);
    function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts);
    function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts);
}

interface IUnifiRouter02 is IUnifiRouter01 {
    function removeLiquidityETHSupportingFeeOnTransferTokens(
        address token,
        uint liquidity,
        uint amountTokenMin,
        uint amountETHMin,
        address to,
        uint deadline
    ) external returns (uint amountETH);
    function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens(
        address token,
        uint liquidity,
        uint amountTokenMin,
        uint amountETHMin,
        address to,
        uint deadline,
        bool approveMax, uint8 v, bytes32 r, bytes32 s
    ) external returns (uint amountETH);

    function swapExactTokensForTokensSupportingFeeOnTransferTokens(
        uint amountIn,
        uint amountOutMin,
        address[] calldata path,
        address to,
        uint deadline
    ) external;
    function swapExactETHForTokensSupportingFeeOnTransferTokens(
        uint amountOutMin,
        address[] calldata path,
        address to,
        uint deadline
    ) external payable;
    function swapExactTokensForETHSupportingFeeOnTransferTokens(
        uint amountIn,
        uint amountOutMin,
        address[] calldata path,
        address to,
        uint deadline
    ) external;
}
```


# Harmony

Here you will find in-depth detail of the contracts that make up uTrade V2 on Harmony. Each contract includes JSONs as well as Typescript files for integration into your project. Every effort is made to open-source all aspects of uTrade V2, but some do remain private.  When a contract is available, you will find a link to the Github source code.&#x20;


# singleLiquidityWrapper.sol

**Primary Uses -** Unique to uTrade, the Single Liquidity Wrapper allows ONE or any HRC-20 token to converted into a LP pool. For example, USDT can be added using the wrapper to supply liquidity for a BUSD / WONE 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)        | Link Here                                                                                                                                         |
| 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                                                                                                                                                                                                                                |
| ---------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Harmony Main Net | <p>0x: <code>0xa529de1949ddb797de0d7f2b3fcf8b17a94af51d</code><br>One:<code>one1555aux2fmkme0hsd0u4nlnutz7554agasnuyuf</code> (<a href="https://explorer.harmony.one/address/0xa529de1949ddb797de0d7f2b3fcf8b17a94af51d">Link</a>)</p> |

### 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 ONE into a LP token. It does so by first converting the provided ONE 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 ONE value is sent as a msg.value parameter. One of the two assets can be WONE.

#### Parameter Breakdown

| Parameter                                        | Type    | Description                                                                                                                                       |
| ------------------------------------------------ | ------- | ------------------------------------------------------------------------------------------------------------------------------------------------- |
| <p><em>amountIn</em><br><em>(msg.value)</em></p> | uint    | The amount of ONE 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 HRC-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 ONE to an uTrade V2 LP token made up of two different tokens. In other words, ONE 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 ONE 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 ONE 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 WONE'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 ONE must be converted to WONE 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 ONE 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 WONE'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 ONE must be converted to WONE, 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 ONE. If true, the *receiveToken* address should be WONE, as it will unwrap WONE and send ONE. |
| *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 ONE or any HRC-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 ONE. If true, the *receiveToken* address should be WONE, as it will unwrap WONE and send ONE.                                                                                                                                                                                                                                                                                                                              |
| *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 ;
}
```


# UnifiERC20.sol

**Primary Uses -** UnifiERC20.sol essentially ports the properties of HRC-20 tokens on to Unifi LP Tokens, or uTokens. An example of this in practice would be the 'approve' transaction.

## uTrade V2 UnifiERC20 Code / Interfaces

|                                             |           |
| ------------------------------------------- | --------- |
| uTrade V2 UnifiERC20 (Solidity)             | Link Here |
| uTrade V2 UnifiERC20 Interface as JSON      | Link Here |
| uTrade V2 UnifiERC20 as Typescript          | Link Here |
| Import statement codeblock (when available) |           |

## uTrade V2 UnifiERC20 Contract Addresses

Each uTrade V2 Liquidity Pool uses the uTrade V2 ERC20 Interface in the contract. An example would be `one1suatku23s9ll76a683lmzffqn8ppp29sdtn6xj` or `0x873abb7151817fff6bba3c7fb1252099c210a8b0` ([Link](https://explorer.harmony.one/address/0x873aBB7151817fFf6bBA3C7Fb1252099C210a8b0)) for the UP / WONE pair.&#x20;

## Events

### Approval

```
event Approval(address indexed owner, address indexed spender, uint value);
```

The `Approval` event is emitted anytime an `approve` or `permit` function is called.

### Transfer

```
event Transfer(address indexed from, address indexed to, uint value);
```

The `Transfer` event is emitted anytime a transfer of LP tokens occurs, by the `transfer`, `transferFrom`, `mint`, or `burn` functions.

## Read-Only Functions

### name

```
function name() external pure returns (string memory);
```

The `name` function will return "Unifi LPs" for all liquidity pool contracts.

### symbol

```
function symbol() external pure returns (string memory);
```

The `symbol` function will return "Unifi-LP" for all liquidity pool contracts.

### decimals

```
function decimals() external pure returns (uint8);
```

The `decimals` function returns "18" as a uint8 value, which is the precision for each uToken on uTrade V2.

### totalSupply

```
function totalSupply() external view returns (uint);
```

The `totalSupply` function returns the total amount uTokens for a pair.

### balanceOf

```
function balanceOf(address owner) external view returns (uint);
```

The `balanceOf` function returns the balance of uTokens for the provided address.

### allowance

```
function allowance(address owner, address spender) external view returns (uint);
```

The `allowance` function returns the amount of tokens an address is approved to transfer when using the `transferFrom` function.

### DOMAIN\_SEPARATOR

```
function DOMAIN_SEPARATOR() external view returns (bytes32);
```

The `DOMAIN_SEPARATOR` function is used in the `permit` function, and is one of the components that allows transactions to get through without a prior approve transaction. Calling a read function returns the bytes32 data that is required for use in `permit` function.

### PERMIT\_TYPEHASH

```
function PERMIT_TYPEHASH() external view returns (bytes32);
```

The `PERMIT_TYPEHASH` function is used in the `permit` function, and is one of the components that allows transactions to get through without a prior approve transaction. Calling a read function returns the bytes32 data that is required for use in the `permit` function.

### nonces

```
function nonces(address owner) external view returns (uint);
```

The `nonces` function is used in the permit function. It returns the current nonce of the *address* provided.

## State-Changing Functions

### approve

```
function approve(address spender, uint value) external returns (bool);
```

The `approve` function sets a *value* for  the amount of LP tokens the *address* provided is allowed to transfer. Returns a boolean value and emits the `Approval` event.

### transfer

```
function transfer(address to, uint value) external returns (bool);
```

The `transfer` function lets an address send uTokens from one address to another, and returns a boolean value and emits a `Transfer` event.

### transferFrom

```
function transferFrom(address from, address to, uint value) external returns (bool);
```

The `transferFrom` function sends uTokens from one address to another. This requires the sending address to have approval to send uTokens. Returns a boolean value and emits a `Transfer`event.

### permit

```
function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external;
```

The permit function allows a sender to use a signature in lieu of an approval transaction, and sets the allowance for an address to send.

#### Function Parameter Breakdown

| Parameter  | Type    | Description                                                                                                                                    |
| ---------- | ------- | ---------------------------------------------------------------------------------------------------------------------------------------------- |
| *owner*    | address | The owner of the address.                                                                                                                      |
| *spender*  | address | The spender of the uTokens.                                                                                                                    |
| *value*    | uint    | The amount of uTokens to be transferred.                                                                                                       |
| *deadline* | uint    | The UNIX timestamp for which this transaction must be completed. If the transaction is mined after this deadline, the transaction will revert. |
| *v*        | uint8   | The v value of the permit. This is one of the three values that makes up the approval signature.                                               |
| *r*        | bytes32 | The r value of the permit. This is one of the three values that makes up the approval signature.                                               |
| *s*        | bytes32 | The s value of the permit. This is one of the three values that makes up the approval signature.                                               |

## Interface Code

```
interface IUnifiERC20 {
    event Approval(address indexed owner, address indexed spender, uint value);
    event Transfer(address indexed from, address indexed to, uint value);

    function name() external pure returns (string memory);
    function symbol() external pure returns (string memory);
    function decimals() external pure returns (uint8);
    function totalSupply() external view returns (uint);
    function balanceOf(address owner) external view returns (uint);
    function allowance(address owner, address spender) external view returns (uint);

    function approve(address spender, uint value) external returns (bool);
    function transfer(address to, uint value) external returns (bool);
    function transferFrom(address from, address to, uint value) external returns (bool);

    function DOMAIN_SEPARATOR() external view returns (bytes32);
    function PERMIT_TYPEHASH() external pure returns (bytes32);
    function nonces(address owner) external view returns (uint);

    function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external;
}
```


# UnifiFactory.sol

**Primary Uses** - The uTrade V2 Factory contract creates an LP token for any pairs listed on uTrade V2, and indexes them for easy retrieval. In addition, it can return the address of the LP token based on a call of the addresses of the two tokens that make up the liquidity pool.

## uTrade V2 Factory Code / Interfaces

|                                             |                                                                                                                                    |
| ------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------- |
| uTrade V2 Factory (Solidity)                | Link Here                                                                                                                          |
| uTrade V2 Factory Interface as JSON         | [GitHub](https://github.com/unifiprotocol/uTradeV2-core/blob/52d66be2a472b9697a577757a0446076b6c32001/ABI/JSON/IUnifiFactory.json) |
| uTrade V2 Factory Interface as Typescript   | [GitHub](https://github.com/unifiprotocol/uTradeV2-core/blob/52d66be2a472b9697a577757a0446076b6c32001/ABI/TS/IUnifiFactory.ts)     |
| Import statement codeblock (when available) |                                                                                                                                    |

## uTrade V2 Factory Contract Addresses

| Network | Address                                                                                                                                                                                                                                  |
| ------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Harmony | <p>0x: <code>0x7aB6ef0cE51a2aDc5B673Bad7218C01AE9B04695</code> <br>one: <code>one1suatku23s9ll76a683lmzffqn8ppp29sdtn6xj</code> (<a href="https://explorer.harmony.one/address/0x7ab6ef0ce51a2adc5b673bad7218c01ae9b04695">Link</a>)</p> |

### PairCreated

```
event PairCreated(address indexed token0, address indexed token1, address pair, uint);
```

Anytime a pair is created on uTrade V2 using the `createPair` function, a `PairCreated` event is emitted. Contracts can be deployed to listen for new pairs on the uTrade V2 Harmony Factory address.&#x20;

* *token0* is the token address of the first asset in the token pair.
* *token1* is the token address of the second asset in the token pair.
* *pair* is the address of the newly created uTrade V2 liquidity pool.
* *uint* refers to the index of this uTrade V2 Factor&#x79;*.* For example, the first liquidity pool created on uTrade V2 is 1, the second liquidity pool is 2, and so on. This number can used with the `allPairs(uint)` to return the address. The current number, and therefore the total number of LP pools on uTrade V2 Harmony, can be accessed using the `allPairsLength` function.

## Read-Only Functions <a href="#read-only-functions" id="read-only-functions"></a>

### getPair

```
function getPair(address tokenA, address tokenB) external view returns (address pair);
```

A call to the `getPair` function returns the address of the pair for *tokenA* and *tokenB*.

* If the pair does not exist, the call will return *address(0)*.&#x20;
* The order of the tokens is irrelevant in this call. For example, a call for ONE, UNIFI will return the same pair address as UNIFI, ONE.&#x20;

### allPairs

```
function allPairs(uint) external view returns (address pair);
```

A call to the `allPairs` function returns the address of a pair based on the indexed *uint* value assigned upon creation of the LP.

* For example, `allPairs(0)` will return the first pair created on uTrade V2 Harmony.
* &#x20;If the index number is too high, as in, there aren't enough pairs created yet, the function will return *address(0)*.

### allPairsLength

```
function allPairsLength() external view returns (uint);
```

A call to the `allPairsLength` function returns the current number of pairs.&#x20;

* For example, if there are 201 total liquidity pool pairs on uTrade V2 Harmony, this call will return *200* as an uint value.

### feeTo

```
function feeTo() external view returns (address);
```

A call to the `feeTo` function returns the percentage of trading fees that Unifi Protocol receives.&#x20;

* Due to the nature of UP Token economics, this is set to zero, but is preserved for flexibility in the future.

### feeToSetter

```
function feeToSetter() external view returns (address);
```

A call to the `feeToSetter` function returns the address to which the `feeTo` would send trading fees, if trading fees were collected.

## State-Changing Functions <a href="#state-changing-functions" id="state-changing-functions"></a>

### createPair

```
function createPair(address tokenA, address tokenB) external returns (address pair);
```

Creates a liquidity pool pair for *tokenA* and *tokenB* if one does not currently exist. After the function is confirmed on chain, a `PairCreated` event is emitted.

## Interface Code

```
interface UnifiFactory {  
  event PairCreated(address indexed token0, address indexed token1, address pair, uint);
  function getPair(address tokenA, address tokenB) external view returns (address pair);  
  function allPairs(uint) external view returns (address pair);  
  function allPairsLength() external view returns (uint);
  function feeTo() external view returns (address);  function feeToSetter() external view returns (address);
  function createPair(address tokenA, address tokenB) external returns (address pair);
  }
```

###


# UnifiPair.sol

**Primary Uses -** UnifiPair.sol is responsible for many of the functionalities of liquidity pool tokens and UP tokens. First, it is responsible for the issuing and burning of Liquidity Pool Tokens (uTokens). In addition, it allows for direct reads of the reserves and ratio of the liquidity pool, as well as swaps. Lastly, it is where UP claims are processed.&#x20;

## uTrade V2 Pair Code / Interfaces

|                                             |           |
| ------------------------------------------- | --------- |
| uTrade V2 Pair (Solidity)                   | Link Here |
| uTrade V2 Pair Interface as JSON            | Link Here |
| uTrade V2 Pair as Typescript                | Link Here |
| Import statement codeblock (when available) |           |

## uTrade V2 UnifiERC20 Contract Addresses

Each uTrade V2 Liquidity Pool uses the uTrade V2 ERC20 Interface in the contract. An example would be `one1suatku23s9ll76a683lmzffqn8ppp29sdtn6xj` or `0x873abb7151817fff6bba3c7fb1252099c210a8b0` ([Link](https://explorer.harmony.one/address/0x873aBB7151817fFf6bBA3C7Fb1252099C210a8b0)) for the UP / WONE pair.&#x20;

## Events

### Mint

```
event Mint(address indexed sender, uint amount0, uint amount1);
```

The `Mint` event is emitted any time liquidity tokens are created via the `mint` function. In other words, when a user adds liquidity to a pair, then they will receive LP tokens, therefore the `Mint` event will be emitted.

### Burn

```
event Burn(address indexed sender, uint amount0, uint amount1, address indexed to);
```

The `Burn` event is emitted any time liquidity tokens are burned via the `burn` function. In other words, when a user removes liquidity from a pair,  their LP tokens will be burned, therefore the `Burn` event will be emitted.

### Swap

```
event Swap(
        address indexed sender,
        uint amount0In,
        uint amount1In,
        uint amount0Out,
        uint amount1Out,
        address indexed to
 );
```

The `Swap` event is emitted any time the `swap` function is used. Under the hood, all trades on uTrade V2 are swaps. Therefore, any time somebody trades on the pair, the uTrade contract for that pair will emit a `Swap` event.

### Sync

```
event Sync(uint112 reserve0, uint112 reserve1);
```

The `Sync` event is emitted anytime a function occurs that may change the reserves of a token pair. In other words, anytime the amount of the two tokens within a liquidity pool may change. Therefore, whenever a`mint`, `burn`, `swap`, or `sync` function is called, the `Sync` event will be emitted.

## Read-Only Functions

### MINIMUM\_LIQUIDITY <a href="#minimum_liquidity" id="minimum_liquidity"></a>

```
function MINIMUM_LIQUIDITY() external pure returns (uint);
```

The `MINIMUM_LIQUIDITY`function will always return 1000. The function itself refers to the burning of initial LP tokens that occurs once when a pool is created. This burn of a tiny amount allows for cleaner LP token numbers therefore avoiding LP tokens being represented as very small decimals value. This allows the tick size to be more precise and prevents rounding errors.

### factory

```
function factory() external view returns (address);
```

The `factory` function will return the current factory address for uTrade V2.

### WBNB

```
function WETH() external view returns (address);
```

A call to the `WETH` function returns the address of Wrapped ONE (WONE) on Harmony in 0x format. As this address does not change, it will always return `0xcf664087a5bb0237a0bad6742852ec6c8d69a27a`.

### token0

```
function token0() external view returns (address);
```

The `token0` function will return the contract address of the first token that makes up the liquidity pair. In other words, if the liquidity pool is made up of USDT / USDC, it will return the contract address of USDT.

### token1

```
function token1() external view returns (address);
```

The `token1` function will return the contract address of the first token that makes up the liquidity pair. In other words, if the liquidity pool is made up of USDT / USDC, it will return the contract address of USDC.

### getReserves

```
function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast);
```

The `getReserves` function returns the reserves of the two tokens that make up the liquidity pool as *reserve0* and *reserve1*. These two values can be helpful in determining the current price of each asset. The function also returns a timestamp with the block number.

### price0CumulativeLast

```
function price0CumulativeLast() external view returns (uint);
```

The `price0CumulativeLast` function is for Oracle usage on uTrade V2. The value of *token0* is captured at the end of each block, and can be called using this function to feed into an Oracle to determine a more time-weighted 'average' price.&#x20;

### price1CumulativeLast

```
function price1CumulativeLast() external view returns (uint);
```

The `price1CumulativeLast` function is for Oracle usage on uTrade V2. The value of *token1* is captured at the end of each block, and can be called using this function to feed into an Oracle to determine a more time-weighted 'average' price.&#x20;

### kLast

```
function kLast() external view returns (uint);
```

The `kLast` function returns the value of *reserve0* \* *reserve1*, after any event that may have triggered a change in the liquidity. For example, the execution of a *swap* function or a *mint* function.

## State-Changing Functions

### mint

```
function mint(address to) external returns (uint liquidity);
```

The `mint` function creates the LP tokens that represent a user's tokens in a liquidity pool. For example, if a user provides 15000 ONE and 300 USDT liquidity to a pool, the Unifi Pair Smart Contract will mint an amount of uWONEUSDT tokens. Will emit the `Mint`, `Sync`, and `Transfer` events.

### burn

```
function burn(address to) external returns (uint amount0, uint amount1);
```

The `burn` function destroys the LP tokens that represent a user's token in a liquidity pool. For example, if a user removes 15000 ONE and 300 USDT liquidity to a pool, the Unifi Pair Smart Contract will burn an amount of uWONEUSDT tokens. Will emit the `Burn`, `Sync`, and `Transfer` events.

### claimUP

```
function claimUP(address to) external lock returns(uint) {
```

The `claimUP` function claims any UP earned from providing liquidity if any exists, and sends the UP to the address provided.

### swap

```
function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external;
```

The `swap` function exchanges one token for another. Under the hood, all trades on uTrade V2 use this function. The *calldata* must be 0 during a normal swap, but must contain data if executing a flash loan. Emits the `Swap` and `Sync` events.

### skim

```
function skim(address to) external;
```

The `skim` function operates as a safeguard if the amount of tokens causes a data error due to too large of a number in the reserves pools. In this unusual circumstance, this will trigger failures in trades. The `skim` function can be called to return the overflowed tokens to the caller.

### sync

```
function sync() external;
```

The `sync` function operates as a safeguard in certain events where the token balance changes outside of normal trading. An example would be an algorithmic stablecoin re-balancing, therefore lowering or raising the amount of the algorithmic stablecoin in the pool. The `sync` function may be called to reset the price ratio to the new reserves. Emits the `Sync`event.

## Interface Code

```
interface IUnifiPair {
    event Mint(address indexed sender, uint amount0, uint amount1);
    event Burn(address indexed sender, uint amount0, uint amount1, address indexed to);
    event Swap(
        address indexed sender,
        uint amount0In,
        uint amount1In,
        uint amount0Out,
        uint amount1Out,
        address indexed to
    );
    event Sync(uint112 reserve0, uint112 reserve1);

    function MINIMUM_LIQUIDITY() external pure returns (uint);
    function factory() external view returns (address);
    function token0() external view returns (address);
    function token1() external view returns (address);
    function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast);
    function price0CumulativeLast() external view returns (uint);
    function price1CumulativeLast() external view returns (uint);
    function kLast() external view returns (uint);

    function mint(address to) external returns (uint liquidity);
    function burn(address to) external returns (uint amount0, uint amount1);
    function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external;
    function skim(address to) external;
    function sync() external;

    function initialize(address, address) external;
}
```


# UnifiRouter.sol

**Primary Uses** - The uTrade V2 Router is the 'brain' of uTrade. The router finds the optimal path for exchanging one token for another. Whenever a trade is made, your wallet sends funds to the router address. The router will then carry out as many transactions as necessary to acquire the desired token. The router also handles adding liquidity to liquidity pools, and sending the corresponding LP tokens to liquidity providers.

## uTrade V2 Router Code / Interfaces

|                                             |                                                                                                                                   |
| ------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------- |
| uTrade V2 Router (Solidity)                 | Link Here                                                                                                                         |
| uTrade V2 Router Interface as JSON          | [GitHub](https://github.com/unifiprotocol/uTradeV2-core/blob/52d66be2a472b9697a577757a0446076b6c32001/ABI/JSON/IUnifiRouter.json) |
| uTrade V2 Router Interface as Typescript    | [GitHub](https://github.com/unifiprotocol/uTradeV2-core/blob/52d66be2a472b9697a577757a0446076b6c32001/ABI/TS/IUnifiRouter.ts)     |
| Import statement codeblock (when available) |                                                                                                                                   |

## uTrade V2 Router Contract Addresses

| Network | Address                                                                                                                                                                                                                                 |
| ------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Harmony | <p>0x: <code>0xbfd48577e368322966cfda94c0a63078ce2f0402</code><br>one: <code>0xbfd48577e368322966cfda94c0a63078ce2f0402</code> (<a href="https://explorer.harmony.one/address/0xbfd48577e368322966cfda94c0a63078ce2f0402">Link</a>)</p> |

### factory

```
function factory() external pure returns (address);
```

A call to the `factory` function returns the address of the current Factory used by uTrade v2. The current factory address for uTrade V2 on Harmony is `0x7aB6ef0cE51a2aDc5B673Bad7218C01AE9B04695`.

### WETH

```
function WETH() external pure returns (address);
```

A call to the `WETH` function returns the address of Wrapped ONE (WONE) on Harmony in 0x format. As this address does not change, it will always return `0xcf664087a5bb0237a0bad6742852ec6c8d69a27a`.

### quote

```
function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB);
```

A call to the `quote` function returns the amount of *tokenB* that will be received for an amount of *tokenA*. This can be used to calculate the exchange rate between two tokens without factoring in slippage or fees. By entering the amount of *tokenA,* the total amount of reserves of *tokenA* as *reserveA,* and the total amount of reserves of *tokenB* as *reserveB*, the call will return the equivalent amount of *tokenB*.

### getAmountOut

```
function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut, uint fee) external pure returns (uint amountOut);
```

A call to the `getAmountOut`function with the amount of the token being sent will return the maximum amount of a token to be received, accounting for fees and the total amount of reserves.

### getAmountIn

```
function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut, uint fee) external pure returns (uint amountIn);
```

A call to the `getAmountIn` function with the amount of the token you wish to receive will return the minimum amount required of the token you wish to send, accounting for fees and the total amount of reserves.

### getAmountsOut

```
function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts);
```

A call to the `getAmountsOut` function with the amount of the token being sent will return the maximum amount to be received of multiple different tokens. By entering multiple LP addresses in the *address* array, the function will return the maximum amount of each token that will be received. A call to this function uses the `getReserves` function from[ UnifiPair.sol ](https://docs.unifiprotocol.com/utrade-v2/harmony/unifipair.sol)to determine the reserves of the liquidity pool. Then, it calls the `getAmountOut` function to determine the amount of each token in the array that will be received for the *amountIn* value of a token.

### getAmountsIn <a href="#getamountsin" id="getamountsin"></a>

```
function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts);
```

A call to the `getAmountsIn` function with the desired amount of the token to be received will return the minimum amount required to be sent of multiple tokens. By entering multiple LP addresses in the *address* array, the function will return the minimum amount of each token that will need to be sent to receive the desired amount of a token. A call to this function uses the `getReserves` function from [UnifiPair.sol](https://docs.unifiprotocol.com/utrade-v2/harmony/unifipair.sol) to determine the reserves of the liquidity pool. Then, it calls the `getAmountIn` function to determine the amount of each token in the array that will need to be sent for the *amountOut* value of a token.&#x20;

## State-Changing Functions - Liquidity <a href="#state-changing-functions" id="state-changing-functions"></a>

### addLiquidity

```
function addLiquidity(
        address tokenA,
        address tokenB,
        uint amountADesired,
        uint amountBDesired,
        uint amountAMin,
        uint amountBMin,
        address to,
        uint deadline
) external returns (uint amountA, uint amountB, uint liquidity);
```

The `addLiquidity` function adds the two tokens that make up the liquidity pool - *tokenA* and *tokenB* - at the proper ratio based on the reserves of the pool. For example, if the pool contains 50 USDT / 1000 ONE, a user's liquidity will be added at the ratio of 1 USDT to 5 ONE provided there is no price movements in the pair between when the user broadcasts the transaction to when it is mined. In the event of a price movement, the *amountADesired*, *amountBDesired*, *amountAMin*, and *amountBMin* act as a security measure against an adverse price movement. After the liquidity is added, the function sends the corresponding LP tokens to the sender.

In the case of a pool not existing for the two assets, one will be created using [UnifiFactory.sol](https://docs.unifiprotocol.com/utrade-v2/harmony/unififactory.sol) at the ratio of the assets supplied.

#### Function Parameters Breakdown

| Parameter        | Type    | Description                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          |
| ---------------- | ------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| *tokenA*         | address | Token address of the first asset in the token pair.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  |
| *tokenB*         | address | Token address of the second asset in the token pair.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 |
| *amountADesired* | uint    | The amount of *tokenA* to be added to liquidity if the value of *tokenA* goes down in comparison to *tokenB*.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        |
| *amountBDesired* | uint    | The amount of *tokenB* to be added to liquidity if the value of *tokenB* goes down in comparison to *tokenA.*                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        |
| *amountAMin*     | uint    | <p>Sets the minimum amount of <em>tokenA</em> that can added to the pool before the transaction reverts. This acts as a safeguard. <br></p><ul><li>If the value of <em>tokenA</em> rapidly increases in comparison to <em>tokenB</em>, the user will require less of <em>tokenA</em> to be added to the pool to maintain the original value of the submitted liquidity.</li><li>A user could potentially be adding liquidity during an outlier spike in value. If the amount of <em>tokenA</em> required falls below this value, the transaction will revert.</li><li>This value must be less than or equal to <em>amountADesired</em>.</li></ul>    |
| *amountBMin*     | uint    | <p>Sets the minimum amount of <em>tokenB</em> that can added to the pool before the transaction reverts. This acts as a safeguard.</p><p></p><ul><li>If the value of <em>tokenB</em> rapidly increases in comparison to <em>tokenA</em>, the user will require less of <em>tokenB</em> to be added to the pool to maintain the original value of the submitted liquidity.</li><li> A user could potentially be adding liquidity during an outlier spike in value. If the amount of <em>tokenB</em> required falls below this value, the transaction will revert.</li><li>This value must be less than or equal to <em>amountBDesired</em>.</li></ul> |
| *to*             | address | The address to which the LP tokens for the uTrade V2 pool will be sent.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              |
| *deadline*       | uint    | The UNIX timestamp for which this transaction must be completed. If the transaction is mined after this deadline, the transaction will revert.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       |

#### Function Return Parameter Breakdown

| Parameter   | Type | Description                                                                                                |
| ----------- | ---- | ---------------------------------------------------------------------------------------------------------- |
| *amountA*   | uint | The exact amount of *tokenA* that was sent to the pool.                                                    |
| *amountB*   | uint | The exact amount of *tokenB* that was sent to the pool.                                                    |
| *liquidity* | uint | The exact amount of liquidity tokens minted and sent to the address provided in the *to* paramete&#x72;*.* |

### addLiquidityETH

```
function addLiquidityETH(
        address token,
        uint amountTokenDesired,
        uint amountTokenMin,
        uint amountETHMin,
        address to,
        uint deadline
    ) external payable returns (uint amountToken, uint amountETH, uint liquidity);
```

The `addLiquidityEth` function is similar to the `addLiquidity` function except it accounts for one token being a native asset. In the case of Harmony, this native asset would be ONE. This function will convert ONE to WONE, will pair that WONE with the supplied other token, and add the liquidity to the pool. This function will add at the ideal ratio based on when the transaction is mined.\
\
In the case of a pool not existing for WONE and the token provided, one will be created using [UnifiFactory.sol](https://app.gitbook.com/@unifi-protocol/s/unifi-protocol/utrade-v2/harmony/unififactory.sol) at the ratio of the assets supplied.

* This function requires a *msg.value* with the amount of ONE to be added.&#x20;
  * The *msg.value* acts as the amountETHDesired. As in, if the ratio between ONE and the token being paired with it change, this is the number of ONE that will be added to the pool.
  * Any leftover ONE is returned to the *msg.sender* address.

#### Function Parameter Breakdown

| Parameter                      | Type    | Description                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 |
| ------------------------------ | ------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| *token*                        | address | The address of the supplied token for the liquidity pool. In other words, the asset that ONE is paired with.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                |
| *amountTokenDesired*           | uint    | The amount of the supplied token to be added to liquidity if the value of token goes down in comparison to ONE.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             |
| (*amountETHDesired*) msg.value | uint    | Sent as the msg.value, the amount of ONE to be added to liquidity if the value of ONE goes down in comparison to token.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     |
| *amountTokenMin*               | uint    | <p>Sets the minimum amount of the supplied token that can added to the pool before the transaction reverts. This acts as a safeguard. </p><p></p><ul><li>If the value of supplied token rapidly increases in comparison to ONE, the user will require less of the token to be added to the pool to maintain the original value of the submitted liquidity.</li><li>A user could potentially be adding liquidity during an outlier spike in value. If the amount of the supplied token required falls below this value, the transaction will revert.</li><li>This value must be less than or equal to <em>amountTokenDesired</em>.</li></ul> |
| *amountETHMin*                 | uint    | <p></p><p>Sets the minimum amount of ONE that can added to the pool before the transaction reverts. This acts as a safeguard. </p><p></p><ul><li>If the value of ONE increases in comparison to the supplied token, the user will require less ONE to be added to the pool to maintain the original value of the submitted liquidity.</li><li>A user could potentially be adding liquidity during an outlier spike in value. If the amount of ONE required falls below this value, the transaction will revert.</li><li>This value must be less than or equal to <em>amountETHDesired</em>.</li></ul>                                       |
| *to*                           | address | The address to which the LP tokens for the uTrade V2 pool will be sent.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     |
| *deadline*                     | uint    | The UNIX timestamp for which this transaction must be completed. If the transaction is mined after this deadline, the transaction will revert.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              |

#### Function Return Parameter Breakdown

| Parameter     | Type | Description                                                                                                |
| ------------- | ---- | ---------------------------------------------------------------------------------------------------------- |
| *amountToken* | uint | The exact amount of the supplied token sent to the pool.                                                   |
| *amountETH*   | uint | The exact amount of ONE converted to WONE, and then added to the pool.                                     |
| *liquidity*   | uint | The exact amount of liquidity tokens minted and sent to the address provided in the *to* paramete&#x72;*.* |

### removeLiquidity

```
function removeLiquidity(
        address tokenA,
        address tokenB,
        uint liquidity,
        uint amountAMin,
        uint amountBMin,
        address to,
        uint deadline
) external returns (uint amountA, uint amountB);
```

The `removeLiquidity` function removes the two tokens that make up liquidity from a pool. In other words, this function is used when the pool consists of two HRC-20 tokens.

* In the event one of the assets is paired with ONE, ONE will have been wrapped and paired with WONE (Wrapped ONE). If the user wishes to withdraw WONE instead of withdrawing as ONE, this function should be used instead of `removeLiquidityETH` .

#### Function Parameter Breakdown

| Parameter    | Type    | Description                                                                                                                                                                                                              |
| ------------ | ------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| *tokenA*     | address | Token address of the first asset in the pair.                                                                                                                                                                            |
| *tokenB*     | address | Token address of the second asset in the pair.                                                                                                                                                                           |
| *liquidity*  | uint    | The amount of liquidity tokens to be redeemed and removed.                                                                                                                                                               |
| *amountAMin* | uint    | Sets the minimum amount of *tokenA* to be removed from the the pool. This acts as a safeguard against removing liquidity during a spike in value. If the removed amount falls below this value, the transaction reverts. |
| *amountBMin* | uint    | Sets the minimum amount of *tokenB* to be removed from the the pool. This acts as a safeguard against removing liquidity during a spike in value. If the removed amount falls below this value, the transaction reverts. |
| *to*         | address | The address to where the redeemed tokens will be sent.                                                                                                                                                                   |
| *deadline*   | uint    | The UNIX timestamp for which this transaction must be completed. If the transaction is mined after this deadline, the transaction will revert.                                                                           |

#### Function Return Parameter Breakdown

| Parameter | Title | Description                                                                      |
| --------- | ----- | -------------------------------------------------------------------------------- |
| *amountA* | uint  | The exact amount of *tokenA* sent to the address provided in the *to* parameter. |
| *amountB* | uint  | The exact amount of *tokenB* sent to the address provided in the *to* parameter. |

### removeLiquidityETH

```
function removeLiquidityETH(
        address token,
        uint liquidity,
        uint amountTokenMin,
        uint amountETHMin,
        address to,
        uint deadline
) external returns (uint amountToken, uint amountETH);
```

The `removeLiquidityETH` function removes ONE as well as the corresponding paired token in the liquidity pool. In other words, this function is used when the pool consists of WONE and a HRC-20 token.

* In the event one of the assets is paired with ONE, ONE has been wrapped into WONE (Wrapped ONE). This function will unwrap the WONE as the liquidity removed. If the user wishes to withdraw WONE instead of withdrawing as ONE, the `removeLiquidity` function should be used.

#### Function Parameter Breakdown

| Parameter        | Type    | Description                                                                                                                                                                                                             |
| ---------------- | ------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| *token*          | address | Token address of the HRC-20 asset in the pair.                                                                                                                                                                          |
| *liquidity*      | uint    | The amount of liquidity tokens to be redeemed and removed.                                                                                                                                                              |
| *amountTokenMin* | uint    | Sets the minimum amount of *token* to be removed from the the pool. This acts as a safeguard against removing liquidity during a spike in value. If the removed amount falls below this value, the transaction reverts. |
| *amountETHMin*   | uint    | Sets the minimum amount of ONE to be removed from the the pool. This acts as a safeguard against removing liquidity during a spike in value. If the removed amount falls below this value, the transaction reverts.     |
| *to*             | address | The address to where ONE and token will be sent.                                                                                                                                                                        |
| *deadline*       | uint    | The UNIX timestamp for which this transaction must be completed. If the transaction is mined after this deadline, the transaction will revert.                                                                          |

#### Function Return Parameter Breakdown

| Parameter     | Value | Description                                                                     |
| ------------- | ----- | ------------------------------------------------------------------------------- |
| *amountToken* | uint  | The exact amount of *token* sent to the address provided in the *to* parameter. |
| *amountETH*   | uint  | The exact amount of ONE sent to the address provided in the *to* parameter.     |

### removeLiquidityWithPermit

```
function removeLiquidityWithPermit(
        address tokenA,
        address tokenB,
        uint liquidity,
        uint amountAMin,
        uint amountBMin,
        address to,
        uint deadline,
        bool approveMax, uint8 v, bytes32 r, bytes32 s
) external returns (uint amountA, uint amountB);
```

The `removeLiquidityWithPermit` functions removes the two tokens that make up liquidity from a pool. In other words, this function is used when the pool consists of two HRC-20 tokens. This function operates similarly to the `removeLiquidity` function with the added benefit of not requiring pre-approvals using [permit function](https://docs.unifiprotocol.com/utrade-v2/harmony/unifierc20.sol) from the HRC-20 contract.

* In the event one of the assets is paired with ONE, ONE will have been wrapped and paired with WONE (Wrapped ONE). If the user wishes to withdraw WONE instead of withdrawing as ONE, this function should be used instead of `removeLiquidityETHWithPermit` .

#### Function Parameter Breakdown

| Parameter    | Type    | Description                                                                                                                                                                                                              |
| ------------ | ------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| *tokenA*     | address | Token address of the first asset in the pair.                                                                                                                                                                            |
| *tokenB*     | address | Token address of the second asset in the pair.                                                                                                                                                                           |
| *liquidity*  | uint    | The amount of liquidity tokens to be redeemed and removed.                                                                                                                                                               |
| *amountAMin* | uint    | Sets the minimum amount of *tokenA* to be removed from the the pool. This acts as a safeguard against removing liquidity during a spike in value. If the removed amount falls below this value, the transaction reverts. |
| *amountBMin* | uint    | Sets the minimum amount of *tokenB* to be removed from the the pool. This acts as a safeguard against removing liquidity during a spike in value. If the removed amount falls below this value, the transaction reverts. |
| *to*         | address | The address to where the redeemed tokens will be sent.                                                                                                                                                                   |
| *deadline*   | uint    | The UNIX timestamp for which this transaction must be completed. If the transaction is mined after this deadline, the transaction will revert.                                                                           |
| *approveMax* | bool    | Sets a true or false value on if approval amount in the signature is for liquidity or for uint(-1).                                                                                                                      |
| *v*          | uint8   | The v value of the permit. This is one of the three values that makes up the approval signature.                                                                                                                         |
| *r*          | bytes32 | The r value of the permit. This is one of the three values that makes up the approval signature.                                                                                                                         |
| *s*          | bytes32 | The s value of the permit. This is one of the three values that makes up the approval signature.                                                                                                                         |

#### Function Return Parameter Breakdown

| Parameter | Title | Description                                                                      |
| --------- | ----- | -------------------------------------------------------------------------------- |
| *amountA* | uint  | The exact amount of *tokenA* sent to the address provided in the *to* parameter. |
| *amountB* | uint  | The exact amount of *tokenB* sent to the address provided in the *to* parameter. |

### removeLiquidityETHWithPermit

```
function removeLiquidityETHWithPermit(
        address token,
        uint liquidity,
        uint amountTokenMin,
        uint amountETHMin,
        address to,
        uint deadline,
        bool approveMax, uint8 v, bytes32 r, bytes32 s
) external returns (uint amountToken, uint amountETH);
    
```

The `removeLiquidityETHWithPermit` function removes ONE as well as the corresponding paired token in the liquidity pool. In other words, this function is used when the pool consists of WONE and a HRC-20 token. This function operates similarly to the `removeLiquidityETH`function with the added benefit of not requiring pre-approvals using [permit function](https://docs.unifiprotocol.com/utrade-v2/harmony/unifierc20.sol) from the HRC-20 contract.

* In the event one of the assets is paired with ONE, ONE has been wrapped into WONE (Wrapped ONE). This function will unwrap the WONE as the liquidity removed. If the user wishes to withdraw WONE instead of withdrawing as ONE, the `removeLiquidityWithPermit` function should be used.

#### Function Parameter Breakdown

| Parameter        | Type    | Description                                                                                                                                                                                                             |
| ---------------- | ------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| *token*          | address | Token address of the HRC-20 asset in the pair.                                                                                                                                                                          |
| *liquidity*      | uint    | The amount of liquidity tokens to be redeemed and removed.                                                                                                                                                              |
| *amountTokenMin* | uint    | Sets the minimum amount of *token* to be removed from the the pool. This acts as a safeguard against removing liquidity during a spike in value. If the removed amount falls below this value, the transaction reverts. |
| *amountETHMin*   | uint    | Sets the minimum amount of ONE to be removed from the the pool. This acts as a safeguard against removing liquidity during a spike in value. If the removed amount falls below this value, the transaction reverts.     |
| *to*             | address | The address to where ONE and token will be sent.                                                                                                                                                                        |
| *deadline*       | uint    | The UNIX timestamp for which this transaction must be completed. If the transaction is mined after this deadline, the transaction will revert.                                                                          |
| *v*              | uint8   | The v value of the permit. This is one of the three values that makes up the approval signature.                                                                                                                        |
| *r*              | bytes32 | The r value of the permit. This is one of the three values that makes up the approval signature.                                                                                                                        |
| *s*              | bytes32 | The s value of the permit. This is one of the three values that makes up the approval signature.                                                                                                                        |

#### Function Return Parameter Breakdown

| Parameter     | Value | Description                                                                     |
| ------------- | ----- | ------------------------------------------------------------------------------- |
| *amountToken* | uint  | The exact amount of *token* sent to the address provided in the *to* parameter. |
| *amountETH*   | uint  | The exact amount of ONE sent to the address provided in the *to* parameter.     |

### removeLiquidityETHSupportingFeeOnTransferTokens

```
function removeLiquidityETHSupportingFeeOnTransferTokens(
        address token,
        uint liquidity,
        uint amountTokenMin,
        uint amountETHMin,
        address to,
        uint deadline
) external returns (uint amountETH);
```

The `removeLiquidityETHSupportingFeeOnTransferTokens`function is similar to the `removeLiquidityETH` function, and contains the same call parameters. This function removes ONE as well as the corresponding paired token in the liquidity pool. In other words, this function is used when the pool consists of WONE and a HRC-20 token.&#x20;

However, this function allows for fee on transfer tokens, such as PAXG, to be used on uTrade.&#x20;

#### Function Parameter Breakdown

| Parameter        | Type    | Description                                                                                                                                                                                                             |
| ---------------- | ------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| *token*          | address | Token address of the HRC-20 asset in the pair.                                                                                                                                                                          |
| *liquidity*      | uint    | The amount of liquidity tokens to be redeemed and removed.                                                                                                                                                              |
| *amountTokenMin* | uint    | Sets the minimum amount of *token* to be removed from the the pool. This acts as a safeguard against removing liquidity during a spike in value. If the removed amount falls below this value, the transaction reverts. |
| *amountETHMin*   | uint    | Sets the minimum amount of BNB to be removed from the the pool. This acts as a safeguard against removing liquidity during a spike in value. If the removed amount falls below this value, the transaction reverts.     |
| *to*             | address | The address to where ONE and the paired token will be sent.                                                                                                                                                             |
| *deadline*       | uint    | The UNIX timestamp for which this transaction must be completed. If the transaction is mined after this deadline, the transaction will revert.                                                                          |

#### Function Return Parameter Breakdown

| Parameter   | Value | Description                                                                                                                                                                                                                   |
| ----------- | ----- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| *amountETH* | uint  | The exact amount of ONE sent to the address provided in the *to* parameter. Note that the *amountToken* parameter is not returned. The amount of fee on transfer that a token may have is not available prior to transaction. |

### removeLiquidityETHWithPermitSupportingFeeOnTransferTokens

```
function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens(
        address token,
        uint liquidity,
        uint amountTokenMin,
        uint amountETHMin,
        address to,
        uint deadline,
        bool approveMax, uint8 v, bytes32 r, bytes32 s
) external returns (uint amountETH);
```

The `removeLiquidityETHWithPermitSupportingFeeOnTransferTokens`function is similar to the `removeLiquidityETHWithPermit`function. This function removes ONE as well as the corresponding paired token in the liquidity pool. In other words, this function is used when the pool consists of WONE and a HRC-20 token. This function operates similarly to the `removeLiquidityETHfunction` with the added benefit of not requiring pre-approvals using [permit function](https://docs.unifiprotocol.com/utrade-v2/harmony/unifierc20.sol) from the HRC-20 contract. In addition, this function allows for fee on transfer tokens, such as PAXG, to be used on uTrade.&#x20;

#### Function Parameter Breakdown

| Parameter        | Type    | Description                                                                                                                                                                                                             |
| ---------------- | ------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| *token*          | address | Token address of the HRC-20 asset in the pair.                                                                                                                                                                          |
| *liquidity*      | uint    | The amount of liquidity tokens to be redeemed and removed.                                                                                                                                                              |
| *amountTokenMin* | uint    | Sets the minimum amount of *token* to be removed from the the pool. This acts as a safeguard against removing liquidity during a spike in value. If the removed amount falls below this value, the transaction reverts. |
| *amountETHMin*   | uint    | Sets the minimum amount of ONE to be removed from the the pool. This acts as a safeguard against removing liquidity during a spike in value. If the removed amount falls below this value, the transaction reverts.     |
| *to*             | address | The address to where ONE and token will be sent.                                                                                                                                                                        |
| *deadline*       | uint    | The UNIX timestamp for which this transaction must be completed. If the transaction is mined after this deadline, the transaction will revert.                                                                          |
| *v*              | uint8   | The v value of the permit. This is one of the three values that makes up the approval signature.                                                                                                                        |
| *r*              | bytes32 | The r value of the permit. This is one of the three values that makes up the approval signature.                                                                                                                        |
| *s*              | bytes32 | The s value of the permit. This is one of the three values that makes up the approval signature.                                                                                                                        |

#### Function Return Parameter Breakdown

| Parameter   | Value | Description                                                                                                                                                                                                                   |
| ----------- | ----- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| *amountETH* | uint  | The exact amount of ONE sent to the address provided in the *to* parameter. Note that the *amountToken* parameter is not returned. The amount of fee on transfer that a token may have is not available prior to transaction. |

## State-Changing Functions - Swap

### swapExactTokensForTokens

```
function swapExactTokensForTokens(
        uint amountIn,
        uint amountOutMin,
        address[] calldata path,
        address to,
        uint deadline
) external returns (uint[] memory amounts);
```

The `swapExactTokensForTokens` function sends an exact amount of tokens for the maximum amount of another token.&#x20;

#### Function Parameter Breakdown

| Parameter      | Type                | Description                                                                                                                                                                                                                                                                                                                                                                                                                            |
| -------------- | ------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| *amountIn*     | uint                | The amount of tokens being sent to swap into another token                                                                                                                                                                                                                                                                                                                                                                             |
| *amountOutMin* | uint                | Sets the minimum amount of the desired token to receive. This acts as a safeguard against removing liquidity during a spike in value. If the amount to be received falls below this value, the transaction reverts.                                                                                                                                                                                                                    |
| *path*         | address\[] calldata | <p>The pathway to change one token to another, consisting of an array of addresses. Each token must have an existing liquidity pool, as well as have liquidity.<br></p><p>The <em>path</em> represents the pathway from one token to another. If a pair exists for the two tokens you wish to exchange, this will contain two values inside of an array. However, if there is no direct pair, multiple addresses may be required. </p> |
| *to*           | address             | The address to where the desired token will be sent.                                                                                                                                                                                                                                                                                                                                                                                   |
| *deadline*     | uint                | The UNIX timestamp for which this transaction must be completed. If the transaction is mined after this deadline, the transaction will revert.                                                                                                                                                                                                                                                                                         |

#### Function Return Parameter Breakdown

| Parameter | Type           | Description                                                                                                |
| --------- | -------------- | ---------------------------------------------------------------------------------------------------------- |
| *amounts* | uint\[] memory | The exact amount of tokens sent into the swap, as well as the exact return amount of all subsequent swaps. |

### swapTokensForExactTokens

```
function swapTokensForExactTokens(
        uint amountOut,
        uint amountInMax,
        address[] calldata path,
        address to,
        uint deadline
) external returns (uint[] memory amounts);
```

The `swapTokensForExactTokens` function sends the minimum amount of tokens for the exact amount of another token.&#x20;

#### Function Parameter Breakdown

| Parameter     | Type                | Description                                                                                                                                                                                                                                                                                                                                                                                                                            |
| ------------- | ------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| *amountOut*   | uint                | The exact amount of the desired tokens to be received.                                                                                                                                                                                                                                                                                                                                                                                 |
| *amountInMax* | uint                | Sets the maximum amount of token to be sent in. This acts as a safeguard against removing liquidity during a spike in value. If the amount to be sent rises above this value, the transaction reverts.                                                                                                                                                                                                                                 |
| *path*        | address\[] calldata | <p>The pathway to change one token to another, consisting of an array of addresses. Each token must have an existing liquidity pool, as well as have liquidity.<br></p><p>The <em>path</em> represents the pathway from one token to another. If a pair exists for the two tokens you wish to exchange, this will contain two values inside of an array. However, if there is no direct pair, multiple addresses may be required. </p> |
| *to*          | address             | The address to where the desired token will be sent.                                                                                                                                                                                                                                                                                                                                                                                   |
| *deadline*    | uint                | The UNIX timestamp for which this transaction must be completed. If the transaction is mined after this deadline, the transaction will revert.                                                                                                                                                                                                                                                                                         |

#### Function Return Parameter Breakdown

| Parameter | Type           | Description                                                                                                |
| --------- | -------------- | ---------------------------------------------------------------------------------------------------------- |
| *amounts* | uint\[] memory | The exact amount of tokens sent into the swap, as well as the exact return amount of all subsequent swaps. |

### swapExactETHForTokens

```
function swapExactETHForTokens(
        uint amountOutMin, 
        address[] calldata path, 
        address to, 
        uint deadline)
        external
        payable
returns (uint[] memory amounts);
```

The `swapExactETHForTokens` function sends an exact amount of ONE for a desired token.

#### Function Parameter Breakdown

| Parameter                                           | Type                | Description                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    |
| --------------------------------------------------- | ------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| <p><em>(amountIn)</em></p><p><em>msg.value</em></p> | uint                | Sent as the msg.value, the amount of ONE to be swapped.                                                                                                                                                                                                                                                                                                                                                                                                                                                                        |
| *amountOutMin*                                      | uint                | Sets the minimum amount of the desired token to receive. This acts as a safeguard against removing liquidity during a spike in value. If the amount to be received falls below this value, the transaction reverts.                                                                                                                                                                                                                                                                                                            |
| *path*                                              | address\[] calldata | <p>The pathway to change one token to another, consisting of an array of addresses. Each token must have an existing liquidity pool, as well as have liquidity.<br></p><p>The <em>path</em> represents the pathway from one token to another. If a pair exists for the two tokens you wish to exchange, this will contain two values inside of an array. However, if there is no direct pair, multiple addresses may be required. </p><p></p><p>As the first swap is swapping ONE to WONE, the first address must be WONE.</p> |
| *to*                                                | address             | The address to where the desired token will be sent.                                                                                                                                                                                                                                                                                                                                                                                                                                                                           |
| *deadline*                                          | uint                | The UNIX timestamp for which this transaction must be completed. If the transaction is mined after this deadline, the transaction will revert.                                                                                                                                                                                                                                                                                                                                                                                 |

#### Function Return Parameter Breakdown

| Parameter | Type           | Description                                                                                             |
| --------- | -------------- | ------------------------------------------------------------------------------------------------------- |
| *amounts* | uint\[] memory | The exact amount of ONE sent into the swap, as well as the exact return amount of all subsequent swaps. |

### swapTokensForExactETH

```
function swapTokensForExactETH(
        uint amountOut, 
        uint amountInMax, 
        address[] calldata path, 
        address to, 
        uint deadline)
        external
        returns (uint[] memory amounts);
```

The `swapTokensForExactETH` function sends an amount of tokens for an exact amount of ONE.

#### Function Parameter Breakdown

| Parameter     | Type                | Description                                                                                                                                                                                                                                                                                                                                                                                                                            |
| ------------- | ------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| *amountOut*   | uint                | The exact amount of the ONE to be received.                                                                                                                                                                                                                                                                                                                                                                                            |
| *amountInMax* | uint                | Sets the maximum amount of token to be sent in. This acts as a safeguard against removing liquidity during a spike in value. If the amount to be sent rises above this value, the transaction reverts.                                                                                                                                                                                                                                 |
| *path*        | address\[] calldata | <p>The pathway to change one token to another, consisting of an array of addresses. Each token must have an existing liquidity pool, as well as have liquidity.<br></p><p>The <em>path</em> represents the pathway from one token to another. If a pair exists for the two tokens you wish to exchange, this will contain two values inside of an array. However, if there is no direct pair, multiple addresses may be required. </p> |
| *to*          | address             | The address to where the desired token will be sent.                                                                                                                                                                                                                                                                                                                                                                                   |
| *deadline*    | uint                | The UNIX timestamp for which this transaction must be completed. If the transaction is mined after this deadline, the transaction will revert.                                                                                                                                                                                                                                                                                         |

#### Function Return Parameter Breakdown

| Parameter | Type           | Description                                                                                         |
| --------- | -------------- | --------------------------------------------------------------------------------------------------- |
| *amounts* | uint\[] memory | The exact amount of tokens sent into the swap, as well as the exact amount of all subsequent swaps. |

### swapExactTokensForETH

```
function swapExactTokensForETH(
        uint amountIn, 
        uint amountOutMin, 
        address[] calldata path, 
        address to, 
        uint deadline)
        external
        returns (uint[] memory amounts);
```

The `swapExactTokensForETH` function sends an exact amount of tokens for ONE.

#### Function Parameter Breakdown

| Parameter      | Type                | Description                                                                                                                                                                                                                                                                                                                                                                                                                            |
| -------------- | ------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| *amountIn*     | uint                | The amount of tokens being sent to swap into ONE.                                                                                                                                                                                                                                                                                                                                                                                      |
| *amountOutMin* | uint                | Sets the minimum amount of the ONE to receive. This acts as a safeguard against removing liquidity during a spike in value. If the amount to be received falls below this value, the transaction reverts.                                                                                                                                                                                                                              |
| *path*         | address\[] calldata | <p>The pathway to change one token to another, consisting of an array of addresses. Each token must have an existing liquidity pool, as well as have liquidity.<br></p><p>The <em>path</em> represents the pathway from one token to another. If a pair exists for the two tokens you wish to exchange, this will contain two values inside of an array. However, if there is no direct pair, multiple addresses may be required. </p> |
| *to*           | address             | The address to where the desired token will be sent.                                                                                                                                                                                                                                                                                                                                                                                   |
| *deadline*     | uint                | The UNIX timestamp for which this transaction must be completed. If the transaction is mined after this deadline, the transaction will revert.                                                                                                                                                                                                                                                                                         |

#### Function Parameter Return Breakdown

| Parameter | Type           | Description                                                                                         |
| --------- | -------------- | --------------------------------------------------------------------------------------------------- |
| *amounts* | uint\[] memory | The exact amount of tokens sent into the swap, as well as the exact amount of all subsequent swaps. |

### swapETHForExactTokens

```
function swapETHForExactTokens(
        uint amountOut, 
        address[] calldata path, 
        address to, 
        uint deadline)
        external
        payable
        returns (uint[] memory amounts);
```

The `swapETHForExactTokens` function swaps an exact amount of ONE for an amount of the desired token.

#### Function Parameter Breakdown

| Parameter                                           | Type                | Description                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    |
| --------------------------------------------------- | ------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| <p><em>(amountIn)</em></p><p><em>msg.value</em></p> | uint                | Sent as the msg.value, the amount of ONE to be swapped.                                                                                                                                                                                                                                                                                                                                                                                                                                                                        |
| *amountOutMin*                                      | uint                | Sets the minimum amount of the desired token to receive. This acts as a safeguard against removing liquidity during a spike in value. If the amount to be received falls below this value, the transaction reverts.                                                                                                                                                                                                                                                                                                            |
| *path*                                              | address\[] calldata | <p>The pathway to change one token to another, consisting of an array of addresses. Each token must have an existing liquidity pool, as well as have liquidity.<br></p><p>The <em>path</em> represents the pathway from one token to another. If a pair exists for the two tokens you wish to exchange, this will contain two values inside of an array. However, if there is no direct pair, multiple addresses may be required. </p><p></p><p>As the first swap is swapping ONE to WONE, the first address must be WONE.</p> |
| *to*                                                | address             | The address to where the desired token will be sent.                                                                                                                                                                                                                                                                                                                                                                                                                                                                           |
| *deadline*                                          | uint                | The UNIX timestamp for which this transaction must be completed. If the transaction is mined after this deadline, the transaction will revert.                                                                                                                                                                                                                                                                                                                                                                                 |

#### Function Return Parameter Breakdown

| Parameter | Type           | Description                                                                                             |
| --------- | -------------- | ------------------------------------------------------------------------------------------------------- |
| *amounts* | uint\[] memory | The exact amount of ONE sent into the swap, as well as the exact return amount of all subsequent swaps. |

### swapExactTokensForTokensSupportingFeeOnTransferTokens

```
function swapExactTokensForTokensSupportingFeeOnTransferTokens(
        uint amountIn,
        uint amountOutMin,
        address[] calldata path,
        address to,
        uint deadline
) external;
```

The `swapExactTokensForTokensSupportingFeeOnTransferTokens` function is similar to `swapExactTokensForTokens` as it swaps one HRC-20 token for another HRC-20 token. In addition, this function allows for fee on transfer tokens, such as PAXG, to be used on uTrade.

#### Function Parameter Breakdown

| Name           | Type                |                                                                                                                                                                                                                                                                                                                                                                                                                              |
| -------------- | ------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| *amountIn*     | uint                | The amount of tokens being sent to swap into ONE.                                                                                                                                                                                                                                                                                                                                                                            |
| *amountOutMin* | uint                | Sets the minimum amount of the desired token to receive. This acts as a safeguard against removing liquidity during a spike in value. If the amount to be received falls below this value, the transaction reverts.                                                                                                                                                                                                          |
| *path*         | address\[] calldata | <p>The pathway to change one token to another, consisting of an array of addresses. Each token must have an existing liquidity pool, as well as have liquidity.<br></p><p>The path represents the pathway from one token to another. If a pair exists for the two tokens you wish to exchange, this will contain two values inside of an array. However, if there is no direct pair, multiple addresses may be required.</p> |
| *to*           | address             | The address to where the desired token will be sent.                                                                                                                                                                                                                                                                                                                                                                         |
| *deadline*     | uint                | The UNIX timestamp for which this transaction must be completed. If the transaction is mined after this deadline, the transaction will revert.                                                                                                                                                                                                                                                                               |

### swapExactETHForTokensSupportingFeeOnTransferTokens

```
function swapExactETHForTokensSupportingFeeOnTransferTokens(
        uint amountOutMin,
        address[] calldata path,
        address to,
        uint deadline
 ) external payable;
```

The `swapExactETHForTokensSupportingFeeOnTransferTokens`function  is similar to `swapExactETHForTokens` function as it swaps an exact amount of ONE for HRC-20 tokens. In addition, this function allows for fee on transfer tokens, such as PAXG, to be used on uTrade.&#x20;

#### Function Parameter Breakdown

| Parameter                                           | Type                | Description                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    |
| --------------------------------------------------- | ------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| <p><em>(amountIn)</em></p><p><em>msg.value</em></p> | uint                | Sent as the msg.value, the exact amount of ONE to be swapped.                                                                                                                                                                                                                                                                                                                                                                                                                                                                  |
| *amountOutMin*                                      | uint                | Sets the minimum amount of the desired token to receive. This acts as a safeguard against removing liquidity during a spike in value. If the amount to be received falls below this value, the transaction reverts.                                                                                                                                                                                                                                                                                                            |
| *path*                                              | address\[] calldata | <p>The pathway to change one token to another, consisting of an array of addresses. Each token must have an existing liquidity pool, as well as have liquidity.<br></p><p>The <em>path</em> represents the pathway from one token to another. If a pair exists for the two tokens you wish to exchange, this will contain two values inside of an array. However, if there is no direct pair, multiple addresses may be required. </p><p></p><p>As the first swap is swapping ONE to WONE, the first address must be WONE.</p> |
| *to*                                                | address             | The address to where the desired token will be sent.                                                                                                                                                                                                                                                                                                                                                                                                                                                                           |
| *deadline*                                          | uint                | The UNIX timestamp for which this transaction must be completed. If the transaction is mined after this deadline, the transaction will revert.                                                                                                                                                                                                                                                                                                                                                                                 |

### swapExactTokensForETHSupportingFeeOnTransferTokens <a href="#swapexacttokensforethsupportingfeeontransfertokens" id="swapexacttokensforethsupportingfeeontransfertokens"></a>

```
function swapExactTokensForETHSupportingFeeOnTransferTokens(
        uint amountIn,
        uint amountOutMin,
        address[] calldata path,
        address to,
        uint deadline
) external;
```

The function `swapExactTokensForETHSupportingFeeOnTransferTokens`is similar to the `swapExactTokensForETH`function, as it swaps an exact amount of HRC-20 tokens for ONE. In addition, this function allows for fee on transfer tokens, such as PAXG, to be used on uTrade.

#### Function Parameter Breakdown

| Parameter      | Type                | Description                                                                                                                                                                                                                                                                                                                                                                                                                            |
| -------------- | ------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| *amountIn*     | uint                | The amount of tokens being sent to swap into ONE.                                                                                                                                                                                                                                                                                                                                                                                      |
| *amountOutMin* | uint                | Sets the minimum amount of the ONE to receive. This acts as a safeguard against removing liquidity during a spike in value. If the amount to be received falls below this value, the transaction reverts.                                                                                                                                                                                                                              |
| *path*         | address\[] calldata | <p>The pathway to change one token to another, consisting of an array of addresses. Each token must have an existing liquidity pool, as well as have liquidity.<br></p><p>The <em>path</em> represents the pathway from one token to another. If a pair exists for the two tokens you wish to exchange, this will contain two values inside of an array. However, if there is no direct pair, multiple addresses may be required. </p> |
| *to*           | address             | The address to where the desired token will be sent.                                                                                                                                                                                                                                                                                                                                                                                   |
| *deadline*     | uint                | The UNIX timestamp for which this transaction must be completed. If the transaction is mined after this deadline, the transaction will revert.                                                                                                                                                                                                                                                                                         |

## Interface Code

```
interface IUnifiRouter01 {
    function factory() external pure returns (address);
    function WETH() external pure returns (address);

    function addLiquidity(
        address tokenA,
        address tokenB,
        uint amountADesired,
        uint amountBDesired,
        uint amountAMin,
        uint amountBMin,
        address to,
        uint deadline
    ) external returns (uint amountA, uint amountB, uint liquidity);
    function addLiquidityETH(
        address token,
        uint amountTokenDesired,
        uint amountTokenMin,
        uint amountETHMin,
        address to,
        uint deadline
    ) external payable returns (uint amountToken, uint amountETH, uint liquidity);
    function removeLiquidity(
        address tokenA,
        address tokenB,
        uint liquidity,
        uint amountAMin,
        uint amountBMin,
        address to,
        uint deadline
    ) external returns (uint amountA, uint amountB);
    function removeLiquidityETH(
        address token,
        uint liquidity,
        uint amountTokenMin,
        uint amountETHMin,
        address to,
        uint deadline
    ) external returns (uint amountToken, uint amountETH);
    function removeLiquidityWithPermit(
        address tokenA,
        address tokenB,
        uint liquidity,
        uint amountAMin,
        uint amountBMin,
        address to,
        uint deadline,
        bool approveMax, uint8 v, bytes32 r, bytes32 s
    ) external returns (uint amountA, uint amountB);
    function removeLiquidityETHWithPermit(
        address token,
        uint liquidity,
        uint amountTokenMin,
        uint amountETHMin,
        address to,
        uint deadline,
        bool approveMax, uint8 v, bytes32 r, bytes32 s
    ) external returns (uint amountToken, uint amountETH);
    function swapExactTokensForTokens(
        uint amountIn,
        uint amountOutMin,
        address[] calldata path,
        address to,
        uint deadline
    ) external returns (uint[] memory amounts);
    function swapTokensForExactTokens(
        uint amountOut,
        uint amountInMax,
        address[] calldata path,
        address to,
        uint deadline
    ) external returns (uint[] memory amounts);
    function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline)
        external
        payable
        returns (uint[] memory amounts);
    function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline)
        external
        returns (uint[] memory amounts);
    function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline)
        external
        returns (uint[] memory amounts);
    function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline)
        external
        payable
        returns (uint[] memory amounts);

    function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB);
    function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut, uint fee) external pure returns (uint amountOut);
    function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut, uint fee) external pure returns (uint amountIn);
    function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts);
    function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts);
}

interface IUnifiRouter02 is IUnifiRouter01 {
    function removeLiquidityETHSupportingFeeOnTransferTokens(
        address token,
        uint liquidity,
        uint amountTokenMin,
        uint amountETHMin,
        address to,
        uint deadline
    ) external returns (uint amountETH);
    function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens(
        address token,
        uint liquidity,
        uint amountTokenMin,
        uint amountETHMin,
        address to,
        uint deadline,
        bool approveMax, uint8 v, bytes32 r, bytes32 s
    ) external returns (uint amountETH);

    function swapExactTokensForTokensSupportingFeeOnTransferTokens(
        uint amountIn,
        uint amountOutMin,
        address[] calldata path,
        address to,
        uint deadline
    ) external;
    function swapExactETHForTokensSupportingFeeOnTransferTokens(
        uint amountOutMin,
        address[] calldata path,
        address to,
        uint deadline
    ) external payable;
    function swapExactTokensForETHSupportingFeeOnTransferTokens(
        uint amountIn,
        uint amountOutMin,
        address[] calldata path,
        address to,
        uint deadline
    ) external;
}
```


# IoTeX

Here you will find in-depth detail of the contracts that make up uTrade V2 on IoTeX. Each contract includes JSONs as well as Typescript files for integration into your project. Every effort is made to open-source all aspects of uTrade V2, but some do remain private.  When a contract is available, you will find a link to the Github source code.&#x20;


# UnifiERC20.sol

**Primary Uses -** UnifiERC20.sol essentially ports the properties of XRC-20 tokens on to Unifi LP Tokens, or uTokens. An example of this in practice would be the 'approve' transaction.

## uTrade V2 UnifiERC20 Code / Interfaces

|                                             |           |
| ------------------------------------------- | --------- |
| uTrade V2 UnifiERC20 (Solidity)             | Link Here |
| uTrade V2 UnifiERC20 Interface as JSON      | Link Here |
| uTrade V2 UnifiERC20 as Typescript          | Link Here |
| Import statement codeblock (when available) |           |

## uTrade V2 UnifiERC20 Contract Addresses

Each uTrade V2 Liquidity Pool uses the uTrade V2 XRC20 Interface in the contract. An example would be `0xBd99494A8EEa8425F5B83D7608b1b198763a97F8` ([Link](https://iotexscan.io/address/0xBd99494A8EEa8425F5B83D7608b1b198763a97F8)) for the WIOTX / UPIotx pair.&#x20;

## Events

### Approval

```
event Approval(address indexed owner, address indexed spender, uint value);
```

The `Approval` event is emitted anytime an `approve` or `permit` function is called.

### Transfer

```
event Transfer(address indexed from, address indexed to, uint value);
```

The `Transfer` event is emitted anytime a transfer of LP tokens occurs, by the `transfer`, `transferFrom`, `mint`, or `burn` functions.

## Read-Only Functions

### name

```
function name() external pure returns (string memory);
```

The `name` function will return "Unifi LPs" for all liquidity pool contracts.

### symbol

```
function symbol() external pure returns (string memory);
```

The `symbol` function will return "Unifi-LP" for all liquidity pool contracts.

### decimals

```
function decimals() external pure returns (uint8);
```

The `decimals` function returns "18" as a uint8 value, which is the precision for each uToken on uTrade V2.

### totalSupply

```
function totalSupply() external view returns (uint);
```

The `totalSupply` function returns the total amount uTokens for a pair.

### balanceOf

```
function balanceOf(address owner) external view returns (uint);
```

The `balanceOf` function returns the balance of uTokens for the provided address.

### allowance

```
function allowance(address owner, address spender) external view returns (uint);
```

The `allowance` function returns the amount of tokens an address is approved to transfer when using the `transferFrom` function.

### DOMAIN\_SEPARATOR

```
function DOMAIN_SEPARATOR() external view returns (bytes32);
```

The `DOMAIN_SEPARATOR` function is used in the `permit` function, and is one of the components that allows transactions to get through without a prior approve transaction. Calling a read function returns the bytes32 data that is required for use in `permit` function.

### PERMIT\_TYPEHASH

```
function PERMIT_TYPEHASH() external view returns (bytes32);
```

The `PERMIT_TYPEHASH` function is used in the `permit` function, and is one of the components that allows transactions to get through without a prior approve transaction. Calling a read function returns the bytes32 data that is required for use in the `permit` function.

### nonces

```
function nonces(address owner) external view returns (uint);
```

The `nonces` function is used in the permit function. It returns the current nonce of the *address* provided.

## State-Changing Functions

### approve

```
function approve(address spender, uint value) external returns (bool);
```

The `approve` function sets a *value* for  the amount of LP tokens the *address* provided is allowed to transfer. Returns a boolean value and emits the `Approval` event.

### transfer

```
function transfer(address to, uint value) external returns (bool);
```

The `transfer` function lets an address send uTokens from one address to another, and returns a boolean value and emits a `Transfer` event.

### transferFrom

```
function transferFrom(address from, address to, uint value) external returns (bool);
```

The `transferFrom` function sends uTokens from one address to another. This requires the sending address to have approval to send uTokens. Returns a boolean value and emits a `Transfer`event.

### permit

```
function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external;
```

The permit function allows a sender to use a signature in lieu of an approval transaction, and sets the allowance for an address to send.

#### Function Parameter Breakdown

| Parameter  | Type    | Description                                                                                                                                    |
| ---------- | ------- | ---------------------------------------------------------------------------------------------------------------------------------------------- |
| *owner*    | address | The owner of the address.                                                                                                                      |
| *spender*  | address | The spender of the uTokens.                                                                                                                    |
| *value*    | uint    | The amount of uTokens to be transferred.                                                                                                       |
| *deadline* | uint    | The UNIX timestamp for which this transaction must be completed. If the transaction is mined after this deadline, the transaction will revert. |
| *v*        | uint8   | The v value of the permit. This is one of the three values that makes up the approval signature.                                               |
| *r*        | bytes32 | The r value of the permit. This is one of the three values that makes up the approval signature.                                               |
| *s*        | bytes32 | The s value of the permit. This is one of the three values that makes up the approval signature.                                               |

## Interface Code

```
interface IUnifiERC20 {
    event Approval(address indexed owner, address indexed spender, uint value);
    event Transfer(address indexed from, address indexed to, uint value);

    function name() external pure returns (string memory);
    function symbol() external pure returns (string memory);
    function decimals() external pure returns (uint8);
    function totalSupply() external view returns (uint);
    function balanceOf(address owner) external view returns (uint);
    function allowance(address owner, address spender) external view returns (uint);

    function approve(address spender, uint value) external returns (bool);
    function transfer(address to, uint value) external returns (bool);
    function transferFrom(address from, address to, uint value) external returns (bool);

    function DOMAIN_SEPARATOR() external view returns (bytes32);
    function PERMIT_TYPEHASH() external pure returns (bytes32);
    function nonces(address owner) external view returns (uint);

    function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external;
}
```


# UnifiFactory.sol

**Primary Uses** - The uTrade V2 Factory contract creates an LP token for any pairs listed on uTrade V2, and indexes them for easy retrieval. In addition, it can return the address of the LP token based on a call of the addresses of the two tokens that make up the liquidity pool.

## uTrade V2 Factory Code / Interfaces

|                                             |                                                                                                                                    |
| ------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------- |
| uTrade V2 Factory (Solidity)                |                                                                                                                                    |
| uTrade V2 Factory Interface as JSON         | [GitHub](https://github.com/unifiprotocol/uTradeV2-core/blob/52d66be2a472b9697a577757a0446076b6c32001/ABI/JSON/IUnifiFactory.json) |
| uTrade V2 Factory Interface as Typescript   | [GitHub](https://github.com/unifiprotocol/uTradeV2-core/blob/52d66be2a472b9697a577757a0446076b6c32001/ABI/TS/IUnifiFactory.ts)     |
| Import statement codeblock (when available) |                                                                                                                                    |

## uTrade V2 Factory Contract Addresses

| Network        | Address                                                                                                                        |
| -------------- | ------------------------------------------------------------------------------------------------------------------------------ |
| IoTeX Main Net | `0x839547067bc885db205F5fA42dcFeEcDFf5A8530` ([Link](https://iotexscan.io/address/0x839547067bc885db205F5fA42dcFeEcDFf5A8530)) |

## Events

### PairCreated

```
event PairCreated(address indexed token0, address indexed token1, address pair, uint);
```

Anytime a pair is created on uTrade V2 using the `createPair` function, a `PairCreated`event is emitted. Contracts can be deployed to listen for new pairs on the uTrade V2 IoTeX Factory address.&#x20;

* *token0* is the token address of the first asset in the token pair.
* *token1* is the token address of the second asset in the token pair.
* *pair* is the address of the newly created uTrade V2 liquidity pool.
* *uint* refers to the index of this uTrade V2 Factor&#x79;*.* For example, the first liquidity pool created on uTrade V2 is 1, the second liquidity pool is 2, and so on. This number can used with the `allPairs(uint)` to return the address. The current number, and therefore the total number of LP pools on uTrade V2 ETH, can be accessed using the `allPairsLength` function.

## Read-Only Functions <a href="#read-only-functions" id="read-only-functions"></a>

### getPair

```
function getPair(address tokenA, address tokenB) external view returns (address pair);
```

A call to the `getPair` function returns the address of the pair for *tokenA* and *tokenB*.

* If the pair does not exist, the call will return *address(0)*.&#x20;
* The order of the tokens is irrelevant in this call. For example, a call for IOTX, UP will return the same pair address as UP, IOTX.&#x20;

### allPairs

```
function allPairs(uint) external view returns (address pair);
```

A call to the `allPairs` function returns the address of a pair based on the indexed *uint* value assigned upon creation of the LP.

* For example, `allPairs(0)` will return the first pair created on uTrade V2 IoTeX.
* &#x20;If the index number is too high, as in, there aren't enough pairs created yet, the function will return *address(0)*.

### allPairsLength

```
function allPairsLength() external view returns (uint);
```

A call to the `allPairsLength` function returns the current number of pairs.&#x20;

* For example, if there are 201 total liquidity pool pairs on uTrade V2 IoTeX, this call will return *200* as an uint value.

### feeTo

```
function feeTo() external view returns (address);
```

A call to the `feeTo` function returns the percentage of trading fees that Unifi Protocol receives.&#x20;

* Due to the nature of UP Token economics, this is set to zero, but is preserved for flexibility in the future.

### feeToSetter

```
function feeToSetter() external view returns (address);
```

A call to the `feeToSetter` function returns the address to which the `feeTo` would send trading fees, if trading fees were collected.

## State-Changing Functions <a href="#state-changing-functions" id="state-changing-functions"></a>

### createPair

```
function createPair(address tokenA, address tokenB) external returns (address pair);
```

Creates a liquidity pool pair for *tokenA* and *tokenB* if one does not currently exist. After the function is confirmed on chain, a `PairCreated` event is emitted.

## Interface Code

```
interface UnifiFactory {  
  event PairCreated(address indexed token0, address indexed token1, address pair, uint);
  function getPair(address tokenA, address tokenB) external view returns (address pair);  
  function allPairs(uint) external view returns (address pair);  
  function allPairsLength() external view returns (uint);
  function feeTo() external view returns (address);  function feeToSetter() external view returns (address);
  function createPair(address tokenA, address tokenB) external returns (address pair);
  }
```

###

###


# UnifiRouter.sol

**Primary Uses** - The uTrade V2 Router is the 'brain' of uTrade. The router finds the optimal path for exchanging one token for another. Whenever a trade is made, your wallet sends funds to the router address. The router will then carry out as many transactions as necessary to acquire the desired token. The router also handles adding liquidity to liquidity pools, and sending the corresponding LP tokens to liquidity providers.

## uTrade V2 Router Code / Interfaces

|                                             |                                                                                                                                   |
| ------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------- |
| uTrade V2 Router (Solidity)                 |                                                                                                                                   |
| uTrade V2 Router Interface as JSON          | [GitHub](https://github.com/unifiprotocol/uTradeV2-core/blob/52d66be2a472b9697a577757a0446076b6c32001/ABI/JSON/IUnifiRouter.json) |
| uTrade V2 Router Interface as Typescript    | [GitHub](https://github.com/unifiprotocol/uTradeV2-core/blob/52d66be2a472b9697a577757a0446076b6c32001/ABI/TS/IUnifiRouter.ts)     |
| Import statement codeblock (when available) |                                                                                                                                   |

## uTrade V2 Router Contract Addresses

| Network        | Address                                                                                                                        |
| -------------- | ------------------------------------------------------------------------------------------------------------------------------ |
| IoTeX Main Net | `0xBd562d5cF2c62Da3143D862aF39eDb6dF59A4679` ([Link](https://iotexscan.io/address/0xBd562d5cF2c62Da3143D862aF39eDb6dF59A4679)) |

## Read-Only Functions <a href="#read-only-functions" id="read-only-functions"></a>

### factory

```
function factory() external pure returns (address);
```

A call to the `factory` function returns the address of the current Factory used by uTrade v2. The current factory address for uTrade V2 on IoTeX is `0x839547067bc885db205F5fA42dcFeEcDFf5A8530`.

### WETH

```
function WETH() external pure returns (address);
```

A call to the `WETH` function returns the address of Wrapped IoTeX (WIOTX) on IoTeX. As this address does not change, it will always return `0xa00744882684c3e4747faefd68d283ea44099d03`.

### quote

```
function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB);
```

A call to the `quote` function returns the amount of *tokenB* that will be received for an amount of *tokenA*. This can be used to calculate the exchange rate between two tokens without factoring in slippage or fees. By entering the amount of *tokenA,* the total amount of reserves of *tokenA* as *reserveA,* and the total amount of reserves of *tokenB* as *reserveB*, the call will return the equivalent amount of *tokenB*.

### getAmountOut

```
function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut, uint fee) external pure returns (uint amountOut);
```

A call to the `getAmountOut`function with the amount of the token being sent will return the maximum amount of a token to be received, accounting for fees and the total amount of reserves.

### getAmountIn

```
function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut, uint fee) external pure returns (uint amountIn);
```

A call to the `getAmountIn` function with the amount of the token you wish to receive will return the minimum amount required of the token you wish to send, accounting for fees and the total amount of reserves.

### getAmountsOut

```
function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts);
```

A call to the `getAmountsOut` function with the amount of the token being sent will return the maximum amount to be received of multiple different tokens. By entering multiple LP addresses in the *address* array, the function will return the maximum amount of each token that will be received. A call to this function uses the `getReserves` function from [UnifiPair.sol](https://docs.unifiprotocol.com/utrade-v2/iotex/unifipair.sol) to determine the reserves of the liquidity pool. Then, it calls the `getAmountOut` function to determine the amount of each token in the array that will be received for the *amountIn* value of a token.

### getAmountsIn <a href="#getamountsin" id="getamountsin"></a>

```
function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts);
```

A call to the `getAmountsIn` function with the desired amount of the token to be received will return the minimum amount required to be sent of multiple tokens. By entering multiple LP addresses in the *address* array, the function will return the minimum amount of each token that will need to be sent to receive the desired amount of a token. A call to this function uses the `getReserves` function from [UnifiPair.sol](https://docs.unifiprotocol.com/utrade-v2/iotex/unifipair.sol) to determine the reserves of the liquidity pool. Then, it calls the `getAmountIn` function to determine the amount of each token in the array that will need to be sent for the *amountOut* value of a token.&#x20;

## State-Changing Functions - Liquidity <a href="#state-changing-functions" id="state-changing-functions"></a>

### addLiquidity

```
function addLiquidity(
        address tokenA,
        address tokenB,
        uint amountADesired,
        uint amountBDesired,
        uint amountAMin,
        uint amountBMin,
        address to,
        uint deadline
) external returns (uint amountA, uint amountB, uint liquidity);
```

The `addLiquidity` function adds the two tokens that make up the liquidity pool - *tokenA* and *tokenB* - at the proper ratio based on the reserves of the pool. For example, if the pool contains 3000 USDT / 20000 IOTX, a user's liquidity will be added at the ratio of 0.15 USDT to 1 IOTX, provided there is no price movements in the pair between when the user broadcasts the transaction to when it is mined. In the event of a price movement, the *amountADesired*, *amountBDesired*, *amountAMin*, and *amountBMin* act as a security measure against an adverse price movement. After the liquidity is added, the function sends the corresponding LP tokens to the sender.

In the case of a pool not existing for the two assets, one will be created using [UnifiFactory.sol](https://docs.unifiprotocol.com/utrade-v2/iotex/unififactory.sol) at the ratio of the assets supplied.

#### Function Parameters Breakdown

| Parameter        | Type    | Description                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          |
| ---------------- | ------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| *tokenA*         | address | Token address of the first asset in the token pair.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  |
| *tokenB*         | address | Token address of the second asset in the token pair.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 |
| *amountADesired* | uint    | The amount of *tokenA* to be added to liquidity if the value of *tokenA* goes down in comparison to *tokenB*.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        |
| *amountBDesired* | uint    | The amount of *tokenB* to be added to liquidity if the value of *tokenB* goes down in comparison to *tokenA.*                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        |
| *amountAMin*     | uint    | <p>Sets the minimum amount of <em>tokenA</em> that can added to the pool before the transaction reverts. This acts as a safeguard. <br></p><ul><li>If the value of <em>tokenA</em> rapidly increases in comparison to <em>tokenB</em>, the user will require less of <em>tokenA</em> to be added to the pool to maintain the original value of the submitted liquidity.</li><li>A user could potentially be adding liquidity during an outlier spike in value. If the amount of <em>tokenA</em> required falls below this value, the transaction will revert.</li><li>This value must be less than or equal to <em>amountADesired</em>.</li></ul>    |
| *amountBMin*     | uint    | <p>Sets the minimum amount of <em>tokenB</em> that can added to the pool before the transaction reverts. This acts as a safeguard.</p><p></p><ul><li>If the value of <em>tokenB</em> rapidly increases in comparison to <em>tokenA</em>, the user will require less of <em>tokenB</em> to be added to the pool to maintain the original value of the submitted liquidity.</li><li> A user could potentially be adding liquidity during an outlier spike in value. If the amount of <em>tokenB</em> required falls below this value, the transaction will revert.</li><li>This value must be less than or equal to <em>amountBDesired</em>.</li></ul> |
| *to*             | address | The address to which the LP tokens for the uTrade V2 pool will be sent.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              |
| *deadline*       | uint    | The UNIX timestamp for which this transaction must be completed. If the transaction is mined after this deadline, the transaction will revert.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       |

#### Function Return Parameter Breakdown

| Parameter   | Type | Description                                                                                                |
| ----------- | ---- | ---------------------------------------------------------------------------------------------------------- |
| *amountA*   | uint | The exact amount of *tokenA* that was sent to the pool.                                                    |
| *amountB*   | uint | The exact amount of *tokenB* that was sent to the pool.                                                    |
| *liquidity* | uint | The exact amount of liquidity tokens minted and sent to the address provided in the *to* paramete&#x72;*.* |

### addLiquidityETH

```
function addLiquidityETH(
        address token,
        uint amountTokenDesired,
        uint amountTokenMin,
        uint amountETHMin,
        address to,
        uint deadline
    ) external payable returns (uint amountToken, uint amountETH, uint liquidity);
```

The `addLiquidityEth` function is similar to the `addLiquidity` function except it accounts for one token being a native asset. In the case of IoTeX, this native asset would be IOTX. This function will convert IOTX to WIOTX, will pair that WIOTX with the supplied other token, and add the liquidity to the pool. This function will add at the ideal ratio based on when the transaction is mined.\
\
In the case of a pool not existing for WIOTX and the token provided, one will be created using [UnifiFactory.sol](https://docs.unifiprotocol.com/utrade-v2/iotex/unififactory.sol) at the ratio of the assets supplied.

* This function requires a *msg.value* with the amount of IOTX to be added.&#x20;
  * The *msg.value* acts as the amountETHDesired. As in, if the ratio between IOTX and the token being paired with it change, this is the number of IOTX that will be added to the pool.
  * Any leftover IOTX is returned to the *msg.sender* address.

#### Function Parameter Breakdown

| Parameter                      | Type    | Description                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  |
| ------------------------------ | ------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| *token*                        | address | The address of the supplied token for the liquidity pool. In other words, the asset that IOTX is paired with.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                |
| *amountTokenDesired*           | uint    | The amount of the supplied token to be added to liquidity if the value of token goes down in comparison to IOTX.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             |
| (*amountETHDesired*) msg.value | uint    | Sent as the msg.value, the amount of IOTX to be added to liquidity if the value of IOTX goes down in comparison to token.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    |
| *amountTokenMin*               | uint    | <p>Sets the minimum amount of the supplied token that can added to the pool before the transaction reverts. This acts as a safeguard. </p><p></p><ul><li>If the value of supplied token rapidly increases in comparison to IOTX, the user will require less of the token to be added to the pool to maintain the original value of the submitted liquidity.</li><li>A user could potentially be adding liquidity during an outlier spike in value. If the amount of the supplied token required falls below this value, the transaction will revert.</li><li>This value must be less than or equal to <em>amountTokenDesired</em>.</li></ul> |
| *amountETHMin*                 | uint    | <p></p><p>Sets the minimum amount of IOTX that can added to the pool before the transaction reverts. This acts as a safeguard. </p><p></p><ul><li>If the value of IOTX increases in comparison to the supplied token, the user will require less IOTX to be added to the pool to maintain the original value of the submitted liquidity.</li><li>A user could potentially be adding liquidity during an outlier spike in value. If the amount of IOTX required falls below this value, the transaction will revert.</li><li>This value must be less than or equal to <em>amountETHDesired</em>.</li></ul>                                    |
| *to*                           | address | The address to which the LP tokens for the uTrade V2 pool will be sent.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      |
| *deadline*                     | uint    | The UNIX timestamp for which this transaction must be completed. If the transaction is mined after this deadline, the transaction will revert.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               |

#### Function Return Parameter Breakdown

| Parameter     | Type | Description                                                                                                |
| ------------- | ---- | ---------------------------------------------------------------------------------------------------------- |
| *amountToken* | uint | The exact amount of the supplied token sent to the pool.                                                   |
| *amountETH*   | uint | The exact amount of IOTX converted to WIOTX, and then added to the pool.                                   |
| *liquidity*   | uint | The exact amount of liquidity tokens minted and sent to the address provided in the *to* paramete&#x72;*.* |

### removeLiquidity

```
function removeLiquidity(
        address tokenA,
        address tokenB,
        uint liquidity,
        uint amountAMin,
        uint amountBMin,
        address to,
        uint deadline
) external returns (uint amountA, uint amountB);
```

The `removeLiquidity` function removes the two tokens that make up liquidity from a pool. In other words, this function is used when the pool consists of two XRC-20 tokens.

* In the event one of the assets is paired with IOTX, IOTX will have been wrapped and paired with WIOTX (Wrapped IoTeX). If the user wishes to withdraw WETH instead of withdrawing as ETH, this function should be used instead of `removeLiquidityETH` .

#### Function Parameter Breakdown

| Parameter    | Type    | Description                                                                                                                                                                                                              |
| ------------ | ------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| *tokenA*     | address | Token address of the first asset in the pair.                                                                                                                                                                            |
| *tokenB*     | address | Token address of the second asset in the pair.                                                                                                                                                                           |
| *liquidity*  | uint    | The amount of liquidity tokens to be redeemed and removed.                                                                                                                                                               |
| *amountAMin* | uint    | Sets the minimum amount of *tokenA* to be removed from the the pool. This acts as a safeguard against removing liquidity during a spike in value. If the removed amount falls below this value, the transaction reverts. |
| *amountBMin* | uint    | Sets the minimum amount of *tokenB* to be removed from the the pool. This acts as a safeguard against removing liquidity during a spike in value. If the removed amount falls below this value, the transaction reverts. |
| *to*         | address | The address to where the redeemed tokens will be sent.                                                                                                                                                                   |
| *deadline*   | uint    | The UNIX timestamp for which this transaction must be completed. If the transaction is mined after this deadline, the transaction will revert.                                                                           |

#### Function Return Parameter Breakdown

| Parameter | Title | Description                                                                      |
| --------- | ----- | -------------------------------------------------------------------------------- |
| *amountA* | uint  | The exact amount of *tokenA* sent to the address provided in the *to* parameter. |
| *amountB* | uint  | The exact amount of *tokenB* sent to the address provided in the *to* parameter. |

### removeLiquidityETH

```
function removeLiquidityETH(
        address token,
        uint liquidity,
        uint amountTokenMin,
        uint amountETHMin,
        address to,
        uint deadline
) external returns (uint amountToken, uint amountETH);
```

The `removeLiquidityETH` function removes IOTX as well as the corresponding paired token in the liquidity pool. In other words, this function is used when the pool consists of WIOTX and an XRC-20 token.

* In the event one of the assets is paired with IOTX, IOTX has been wrapped into WIOTX (Wrapped IoTeX). This function will unwrap the WIOTX as the liquidity removed. If the user wishes to withdraw WIOTX instead of withdrawing as IOTX, the `removeLiquidity` function should be used.

#### Function Parameter Breakdown

| Parameter        | Type    | Description                                                                                                                                                                                                             |
| ---------------- | ------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| *token*          | address | Token address of the XRC-20 asset in the pair.                                                                                                                                                                          |
| *liquidity*      | uint    | The amount of liquidity tokens to be redeemed and removed.                                                                                                                                                              |
| *amountTokenMin* | uint    | Sets the minimum amount of *token* to be removed from the the pool. This acts as a safeguard against removing liquidity during a spike in value. If the removed amount falls below this value, the transaction reverts. |
| *amountETHMin*   | uint    | Sets the minimum amount of IOTX to be removed from the pool. This acts as a safeguard against removing liquidity during a spike in value. If the removed amount falls below this value, the transaction reverts.        |
| *to*             | address | The address to where IOTX and token will be sent.                                                                                                                                                                       |
| *deadline*       | uint    | The UNIX timestamp for which this transaction must be completed. If the transaction is mined after this deadline, the transaction will revert.                                                                          |

#### Function Return Parameter Breakdown

| Parameter     | Value | Description                                                                     |
| ------------- | ----- | ------------------------------------------------------------------------------- |
| *amountToken* | uint  | The exact amount of *token* sent to the address provided in the *to* parameter. |
| *amountETH*   | uint  | The exact amount of IOTX sent to the address provided in the *to* parameter.    |

### removeLiquidityWithPermit

```
function removeLiquidityWithPermit(
        address tokenA,
        address tokenB,
        uint liquidity,
        uint amountAMin,
        uint amountBMin,
        address to,
        uint deadline,
        bool approveMax, uint8 v, bytes32 r, bytes32 s
) external returns (uint amountA, uint amountB);
```

The `removeLiquidityWithPermit` functions removes the two tokens that make up liquidity from a pool. In other words, this function is used when the pool consists of two XRC-20 tokens. This function operates similarly to the `removeLiquidity` function with the added benefit of not requiring pre-approvals using permit.

* In the event one of the assets is paired with IOTX, IOTX will have been wrapped and paired with WIOTX (Wrapped IoTeX). If the user wishes to withdraw WIOTX instead of withdrawing as IOTX, this function should be used instead of `removeLiquidityETHWithPermit` .

#### Function Parameter Breakdown

| Parameter    | Type    | Description                                                                                                                                                                                                              |
| ------------ | ------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| *tokenA*     | address | Token address of the first asset in the pair.                                                                                                                                                                            |
| *tokenB*     | address | Token address of the second asset in the pair.                                                                                                                                                                           |
| *liquidity*  | uint    | The amount of liquidity tokens to be redeemed and removed.                                                                                                                                                               |
| *amountAMin* | uint    | Sets the minimum amount of *tokenA* to be removed from the the pool. This acts as a safeguard against removing liquidity during a spike in value. If the removed amount falls below this value, the transaction reverts. |
| *amountBMin* | uint    | Sets the minimum amount of *tokenB* to be removed from the the pool. This acts as a safeguard against removing liquidity during a spike in value. If the removed amount falls below this value, the transaction reverts. |
| *to*         | address | The address to where the redeemed tokens will be sent.                                                                                                                                                                   |
| *deadline*   | uint    | The UNIX timestamp for which this transaction must be completed. If the transaction is mined after this deadline, the transaction will revert.                                                                           |
| *approveMax* | bool    | Sets a true or false value on if approval amount in the signature is for liquidity or for uint(-1).                                                                                                                      |
| *v*          | uint8   | The v value of the permit. This is one of the three values that makes up the approval signature.                                                                                                                         |
| *r*          | bytes32 | The r value of the permit. This is one of the three values that makes up the approval signature.                                                                                                                         |
| *s*          | bytes32 | The s value of the permit. This is one of the three values that makes up the approval signature.                                                                                                                         |

#### Function Return Parameter Breakdown

| Parameter | Title | Description                                                                      |
| --------- | ----- | -------------------------------------------------------------------------------- |
| *amountA* | uint  | The exact amount of *tokenA* sent to the address provided in the *to* parameter. |
| *amountB* | uint  | The exact amount of *tokenB* sent to the address provided in the *to* parameter. |

### removeLiquidityETHWithPermit

```
function removeLiquidityETHWithPermit(
        address token,
        uint liquidity,
        uint amountTokenMin,
        uint amountETHMin,
        address to,
        uint deadline,
        bool approveMax, uint8 v, bytes32 r, bytes32 s
) external returns (uint amountToken, uint amountETH);
    
```

The `removeLiquidityETHWithPermit` function removes IOTX as well as the corresponding paired token in the liquidity pool. In other words, this function is used when the pool consists of WIOTX and a XRC-20 token. This function operates similarly to the `removeLiquidityETH`function with the added benefit of not requiring pre-approvals using permit.

* In the event one of the assets is paired with IOTX, IOTX has been wrapped into WIOTX (Wrapped IoTeX). This function will unwrap the WIOTX as the liquidity removed. If the user wishes to withdraw WIOTX instead of withdrawing as IOTX, the `removeLiquidityWithPermit` function should be used.

#### Function Parameter Breakdown

| Parameter        | Type    | Description                                                                                                                                                                                                             |
| ---------------- | ------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| *token*          | address | Token address of the XRC-20 asset in the pair.                                                                                                                                                                          |
| *liquidity*      | uint    | The amount of liquidity tokens to be redeemed and removed.                                                                                                                                                              |
| *amountTokenMin* | uint    | Sets the minimum amount of *token* to be removed from the the pool. This acts as a safeguard against removing liquidity during a spike in value. If the removed amount falls below this value, the transaction reverts. |
| *amountETHMin*   | uint    | Sets the minimum amount of IOTX to be removed from the the pool. This acts as a safeguard against removing liquidity during a spike in value. If the removed amount falls below this value, the transaction reverts.    |
| *to*             | address | The address to where IOTX and token will be sent.                                                                                                                                                                       |
| *deadline*       | uint    | The UNIX timestamp for which this transaction must be completed. If the transaction is mined after this deadline, the transaction will revert.                                                                          |
| *v*              | uint8   | The v value of the permit. This is one of the three values that makes up the approval signature.                                                                                                                        |
| *r*              | bytes32 | The r value of the permit. This is one of the three values that makes up the approval signature.                                                                                                                        |
| *s*              | bytes32 | The s value of the permit. This is one of the three values that makes up the approval signature.                                                                                                                        |

#### Function Return Parameter Breakdown

| Parameter     | Value | Description                                                                     |
| ------------- | ----- | ------------------------------------------------------------------------------- |
| *amountToken* | uint  | The exact amount of *token* sent to the address provided in the *to* parameter. |
| *amountETH*   | uint  | The exact amount of IOTX sent to the address provided in the *to* parameter.    |

### removeLiquidityETHSupportingFeeOnTransferTokens

```
function removeLiquidityETHSupportingFeeOnTransferTokens(
        address token,
        uint liquidity,
        uint amountTokenMin,
        uint amountETHMin,
        address to,
        uint deadline
) external returns (uint amountETH);
```

The `removeLiquidityETHSupportingFeeOnTransferTokens`function is similar to the `removeLiquidityETH` function, and contains the same call parameters. This function removes IOTX as well as the corresponding paired token in the liquidity pool. In other words, this function is used when the pool consists of WIOTX and a XRC-20 token.&#x20;

However, this function allows for fee on transfer tokens, such as PAXG, to be used on uTrade.&#x20;

#### Function Parameter Breakdown

| Parameter        | Type    | Description                                                                                                                                                                                                             |
| ---------------- | ------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| *token*          | address | Token address of the XRC-20 asset in the pair.                                                                                                                                                                          |
| *liquidity*      | uint    | The amount of liquidity tokens to be redeemed and removed.                                                                                                                                                              |
| *amountTokenMin* | uint    | Sets the minimum amount of *token* to be removed from the the pool. This acts as a safeguard against removing liquidity during a spike in value. If the removed amount falls below this value, the transaction reverts. |
| *amountETHMin*   | uint    | Sets the minimum amount of IOTX to be removed from the the pool. This acts as a safeguard against removing liquidity during a spike in value. If the removed amount falls below this value, the transaction reverts.    |
| *to*             | address | The address to where IOTX and the paired token will be sent.                                                                                                                                                            |
| *deadline*       | uint    | The UNIX timestamp for which this transaction must be completed. If the transaction is mined after this deadline, the transaction will revert.                                                                          |

#### Function Return Parameter Breakdown

| Parameter   | Value | Description                                                                                                                                                                                                                    |
| ----------- | ----- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| *amountETH* | uint  | The exact amount of IOTX sent to the address provided in the *to* parameter. Note that the *amountToken* parameter is not returned. The amount of fee on transfer that a token may have is not available prior to transaction. |

### removeLiquidityETHWithPermitSupportingFeeOnTransferTokens

```
function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens(
        address token,
        uint liquidity,
        uint amountTokenMin,
        uint amountETHMin,
        address to,
        uint deadline,
        bool approveMax, uint8 v, bytes32 r, bytes32 s
) external returns (uint amountETH);
```

The `removeLiquidityETHWithPermitSupportingFeeOnTransferTokens`function is similar to the `removeLiquidityETHWithPermit`function. This function removes IOTX as well as the corresponding paired token in the liquidity pool. In other words, this function is used when the pool consists of WIOTX and an XRC-20 token. This function operates similarly to the `removeLiquidityETHfunction` with the added benefit of not requiring pre-approvals using permit. In addition, this function allows for fee on transfer tokens, such as PAXG, to be used on uTrade.&#x20;

#### Function Parameter Breakdown

| Parameter        | Type    | Description                                                                                                                                                                                                             |
| ---------------- | ------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| *token*          | address | Token address of the XRC-20 asset in the pair.                                                                                                                                                                          |
| *liquidity*      | uint    | The amount of liquidity tokens to be redeemed and removed.                                                                                                                                                              |
| *amountTokenMin* | uint    | Sets the minimum amount of *token* to be removed from the the pool. This acts as a safeguard against removing liquidity during a spike in value. If the removed amount falls below this value, the transaction reverts. |
| *amountETHMin*   | uint    | Sets the minimum amount of IOTX to be removed from the the pool. This acts as a safeguard against removing liquidity during a spike in value. If the removed amount falls below this value, the transaction reverts.    |
| *to*             | address | The address to where IOTX and token will be sent.                                                                                                                                                                       |
| *deadline*       | uint    | The UNIX timestamp for which this transaction must be completed. If the transaction is mined after this deadline, the transaction will revert.                                                                          |
| *v*              | uint8   | The v value of the permit. This is one of the three values that makes up the approval signature.                                                                                                                        |
| *r*              | bytes32 | The r value of the permit. This is one of the three values that makes up the approval signature.                                                                                                                        |
| *s*              | bytes32 | The s value of the permit. This is one of the three values that makes up the approval signature.                                                                                                                        |

#### Function Return Parameter Breakdown

| Parameter   | Value | Description                                                                                                                                                                                                                    |
| ----------- | ----- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| *amountETH* | uint  | The exact amount of IOTX sent to the address provided in the *to* parameter. Note that the *amountToken* parameter is not returned. The amount of fee on transfer that a token may have is not available prior to transaction. |

## State-Changing Functions - Swap

### swapExactTokensForTokens

```
function swapExactTokensForTokens(
        uint amountIn,
        uint amountOutMin,
        address[] calldata path,
        address to,
        uint deadline
) external returns (uint[] memory amounts);
```

The `swapExactTokensForTokens` function sends an exact amount of tokens for the maximum amount of another token.&#x20;

#### Function Parameter Breakdown

| Parameter      | Type                | Description                                                                                                                                                                                                                                                                                                                                                                                                                            |
| -------------- | ------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| *amountIn*     | uint                | The amount of tokens being sent to swap into another token                                                                                                                                                                                                                                                                                                                                                                             |
| *amountOutMin* | uint                | Sets the minimum amount of the desired token to receive. This acts as a safeguard against removing liquidity during a spike in value. If the amount to be received falls below this value, the transaction reverts.                                                                                                                                                                                                                    |
| *path*         | address\[] calldata | <p>The pathway to change one token to another, consisting of an array of addresses. Each token must have an existing liquidity pool, as well as have liquidity.<br></p><p>The <em>path</em> represents the pathway from one token to another. If a pair exists for the two tokens you wish to exchange, this will contain two values inside of an array. However, if there is no direct pair, multiple addresses may be required. </p> |
| *to*           | address             | The address to where the desired token will be sent.                                                                                                                                                                                                                                                                                                                                                                                   |
| *deadline*     | uint                | The UNIX timestamp for which this transaction must be completed. If the transaction is mined after this deadline, the transaction will revert.                                                                                                                                                                                                                                                                                         |

#### Function Return Parameter Breakdown

| Parameter | Type           | Description                                                                                                |
| --------- | -------------- | ---------------------------------------------------------------------------------------------------------- |
| *amounts* | uint\[] memory | The exact amount of tokens sent into the swap, as well as the exact return amount of all subsequent swaps. |

### swapTokensForExactTokens

```
function swapTokensForExactTokens(
        uint amountOut,
        uint amountInMax,
        address[] calldata path,
        address to,
        uint deadline
) external returns (uint[] memory amounts);
```

The `swapTokensForExactTokens` function sends the minimum amount of tokens for the exact amount of another token.&#x20;

#### Function Parameter Breakdown

| Parameter     | Type                | Description                                                                                                                                                                                                                                                                                                                                                                                                                            |
| ------------- | ------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| *amountOut*   | uint                | The exact amount of the desired tokens to be received.                                                                                                                                                                                                                                                                                                                                                                                 |
| *amountInMax* | uint                | Sets the maximum amount of token to be sent in. This acts as a safeguard against removing liquidity during a spike in value. If the amount to be sent rises above this value, the transaction reverts.                                                                                                                                                                                                                                 |
| *path*        | address\[] calldata | <p>The pathway to change one token to another, consisting of an array of addresses. Each token must have an existing liquidity pool, as well as have liquidity.<br></p><p>The <em>path</em> represents the pathway from one token to another. If a pair exists for the two tokens you wish to exchange, this will contain two values inside of an array. However, if there is no direct pair, multiple addresses may be required. </p> |
| *to*          | address             | The address to where the desired token will be sent.                                                                                                                                                                                                                                                                                                                                                                                   |
| *deadline*    | uint                | The UNIX timestamp for which this transaction must be completed. If the transaction is mined after this deadline, the transaction will revert.                                                                                                                                                                                                                                                                                         |

#### Function Return Parameter Breakdown

| Parameter | Type           | Description                                                                                                |
| --------- | -------------- | ---------------------------------------------------------------------------------------------------------- |
| *amounts* | uint\[] memory | The exact amount of tokens sent into the swap, as well as the exact return amount of all subsequent swaps. |

### swapExactETHForTokens

```
function swapExactETHForTokens(
        uint amountOutMin, 
        address[] calldata path, 
        address to, 
        uint deadline)
        external
        payable
returns (uint[] memory amounts);
```

The `swapExactETHForTokens` function sends an exact amount of IOTX for a desired token.

#### Function Parameter Breakdown

| Parameter                                           | Type                | Description                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      |
| --------------------------------------------------- | ------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| <p><em>(amountIn)</em></p><p><em>msg.value</em></p> | uint                | Sent as the msg.value, the amount of IOTX to be swapped.                                                                                                                                                                                                                                                                                                                                                                                                                                                                         |
| *amountOutMin*                                      | uint                | Sets the minimum amount of the desired token to receive. This acts as a safeguard against removing liquidity during a spike in value. If the amount to be received falls below this value, the transaction reverts.                                                                                                                                                                                                                                                                                                              |
| *path*                                              | address\[] calldata | <p>The pathway to change one token to another, consisting of an array of addresses. Each token must have an existing liquidity pool, as well as have liquidity.<br></p><p>The <em>path</em> represents the pathway from one token to another. If a pair exists for the two tokens you wish to exchange, this will contain two values inside of an array. However, if there is no direct pair, multiple addresses may be required. </p><p></p><p>As the first swap is swapping IOTX to WIOTX, the first address must be WETH.</p> |
| *to*                                                | address             | The address to where the desired token will be sent.                                                                                                                                                                                                                                                                                                                                                                                                                                                                             |
| *deadline*                                          | uint                | The UNIX timestamp for which this transaction must be completed. If the transaction is mined after this deadline, the transaction will revert.                                                                                                                                                                                                                                                                                                                                                                                   |

#### Function Return Parameter Breakdown

| Parameter | Type           | Description                                                                                              |
| --------- | -------------- | -------------------------------------------------------------------------------------------------------- |
| *amounts* | uint\[] memory | The exact amount of IOTX sent into the swap, as well as the exact return amount of all subsequent swaps. |

### swapTokensForExactETH

```
function swapTokensForExactETH(
        uint amountOut, 
        uint amountInMax, 
        address[] calldata path, 
        address to, 
        uint deadline)
        external
        returns (uint[] memory amounts);
```

The `swapTokensForExactETH` function sends an amount of tokens for an exact amount of IOTX.

#### Function Parameter Breakdown

| Parameter     | Type                | Description                                                                                                                                                                                                                                                                                                                                                                                                                            |
| ------------- | ------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| *amountOut*   | uint                | The exact amount of the IOTX to be received.                                                                                                                                                                                                                                                                                                                                                                                           |
| *amountInMax* | uint                | Sets the maximum amount of token to be sent in. This acts as a safeguard against removing liquidity during a spike in value. If the amount to be sent rises above this value, the transaction reverts.                                                                                                                                                                                                                                 |
| *path*        | address\[] calldata | <p>The pathway to change one token to another, consisting of an array of addresses. Each token must have an existing liquidity pool, as well as have liquidity.<br></p><p>The <em>path</em> represents the pathway from one token to another. If a pair exists for the two tokens you wish to exchange, this will contain two values inside of an array. However, if there is no direct pair, multiple addresses may be required. </p> |
| *to*          | address             | The address to where the desired token will be sent.                                                                                                                                                                                                                                                                                                                                                                                   |
| *deadline*    | uint                | The UNIX timestamp for which this transaction must be completed. If the transaction is mined after this deadline, the transaction will revert.                                                                                                                                                                                                                                                                                         |

#### Function Return Parameter Breakdown

| Parameter | Type           | Description                                                                                         |
| --------- | -------------- | --------------------------------------------------------------------------------------------------- |
| *amounts* | uint\[] memory | The exact amount of tokens sent into the swap, as well as the exact amount of all subsequent swaps. |

### swapExactTokensForETH

```
function swapExactTokensForETH(
        uint amountIn, 
        uint amountOutMin, 
        address[] calldata path, 
        address to, 
        uint deadline)
        external
        returns (uint[] memory amounts);
```

The `swapExactTokensForETH` function sends an exact amount of tokens for IOTX.

#### Function Parameter Breakdown

| Parameter      | Type                | Description                                                                                                                                                                                                                                                                                                                                                                                                                            |
| -------------- | ------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| *amountIn*     | uint                | The amount of tokens being sent to swap into IOTX.                                                                                                                                                                                                                                                                                                                                                                                     |
| *amountOutMin* | uint                | Sets the minimum amount of the IOTX to receive. This acts as a safeguard against removing liquidity during a spike in value. If the amount to be received falls below this value, the transaction reverts.                                                                                                                                                                                                                             |
| *path*         | address\[] calldata | <p>The pathway to change one token to another, consisting of an array of addresses. Each token must have an existing liquidity pool, as well as have liquidity.<br></p><p>The <em>path</em> represents the pathway from one token to another. If a pair exists for the two tokens you wish to exchange, this will contain two values inside of an array. However, if there is no direct pair, multiple addresses may be required. </p> |
| *to*           | address             | The address to where the desired token will be sent.                                                                                                                                                                                                                                                                                                                                                                                   |
| *deadline*     | uint                | The UNIX timestamp for which this transaction must be completed. If the transaction is mined after this deadline, the transaction will revert.                                                                                                                                                                                                                                                                                         |

#### Function Parameter Return Breakdown

| Parameter | Type           | Description                                                                                         |
| --------- | -------------- | --------------------------------------------------------------------------------------------------- |
| *amounts* | uint\[] memory | The exact amount of tokens sent into the swap, as well as the exact amount of all subsequent swaps. |

### swapETHForExactTokens

```
function swapETHForExactTokens(
        uint amountOut, 
        address[] calldata path, 
        address to, 
        uint deadline)
        external
        payable
        returns (uint[] memory amounts);
```

The `swapETHForExactTokens` function swaps an exact amount of IOTX for an amount of the desired token.

#### Function Parameter Breakdown

| Parameter                                           | Type                | Description                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       |
| --------------------------------------------------- | ------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| <p><em>(amountIn)</em></p><p><em>msg.value</em></p> | uint                | Sent as the msg.value, the amount of IOTX to be swapped.                                                                                                                                                                                                                                                                                                                                                                                                                                                                          |
| *amountOutMin*                                      | uint                | Sets the minimum amount of the desired token to receive. This acts as a safeguard against removing liquidity during a spike in value. If the amount to be received falls below this value, the transaction reverts.                                                                                                                                                                                                                                                                                                               |
| *path*                                              | address\[] calldata | <p>The pathway to change one token to another, consisting of an array of addresses. Each token must have an existing liquidity pool, as well as have liquidity.<br></p><p>The <em>path</em> represents the pathway from one token to another. If a pair exists for the two tokens you wish to exchange, this will contain two values inside of an array. However, if there is no direct pair, multiple addresses may be required. </p><p></p><p>As the first swap is swapping IOTX to WIOTX, the first address must be WIOTX.</p> |
| *to*                                                | address             | The address to where the desired token will be sent.                                                                                                                                                                                                                                                                                                                                                                                                                                                                              |
| *deadline*                                          | uint                | The UNIX timestamp for which this transaction must be completed. If the transaction is mined after this deadline, the transaction will revert.                                                                                                                                                                                                                                                                                                                                                                                    |

#### Function Return Parameter Breakdown

| Parameter | Type           | Description                                                                                             |
| --------- | -------------- | ------------------------------------------------------------------------------------------------------- |
| *amounts* | uint\[] memory | The exact amount of ETH sent into the swap, as well as the exact return amount of all subsequent swaps. |

### swapExactTokensForTokensSupportingFeeOnTransferTokens

```
function swapExactTokensForTokensSupportingFeeOnTransferTokens(
        uint amountIn,
        uint amountOutMin,
        address[] calldata path,
        address to,
        uint deadline
) external;
```

The `swapExactTokensForTokensSupportingFeeOnTransferTokens` function is similar to `swapExactTokensForTokens` as it swaps one XRC-20 token for another XRC-20 token. In addition, this function allows for fee on transfer tokens, such as PAXG, to be used on uTrade.

#### Function Parameter Breakdown

| Name           | Type                |                                                                                                                                                                                                                                                                                                                                                                                                                              |
| -------------- | ------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| *amountIn*     | uint                | The amount of tokens being sent to swap into another token.                                                                                                                                                                                                                                                                                                                                                                  |
| *amountOutMin* | uint                | Sets the minimum amount of the desired token to receive. This acts as a safeguard against removing liquidity during a spike in value. If the amount to be received falls below this value, the transaction reverts.                                                                                                                                                                                                          |
| *path*         | address\[] calldata | <p>The pathway to change one token to another, consisting of an array of addresses. Each token must have an existing liquidity pool, as well as have liquidity.<br></p><p>The path represents the pathway from one token to another. If a pair exists for the two tokens you wish to exchange, this will contain two values inside of an array. However, if there is no direct pair, multiple addresses may be required.</p> |
| *to*           | address             | The address to where the desired token will be sent.                                                                                                                                                                                                                                                                                                                                                                         |
| *deadline*     | uint                | The UNIX timestamp for which this transaction must be completed. If the transaction is mined after this deadline, the transaction will revert.                                                                                                                                                                                                                                                                               |

### swapExactETHForTokensSupportingFeeOnTransferTokens

```
function swapExactETHForTokensSupportingFeeOnTransferTokens(
        uint amountOutMin,
        address[] calldata path,
        address to,
        uint deadline
 ) external payable;
```

The `swapExactETHForTokensSupportingFeeOnTransferTokens`function  is similar to `swapExactETHForTokens` function as it swaps an exact amount of IOTX for XRC-20 tokens. In addition, this function allows for fee on transfer tokens, such as PAXG, to be used on uTrade.&#x20;

#### Function Parameter Breakdown

| Parameter                                           | Type                | Description                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       |
| --------------------------------------------------- | ------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| <p><em>(amountIn)</em></p><p><em>msg.value</em></p> | uint                | Sent as the msg.value, the exact amount of IOTX to be swapped.                                                                                                                                                                                                                                                                                                                                                                                                                                                                    |
| *amountOutMin*                                      | uint                | Sets the minimum amount of the desired token to receive. This acts as a safeguard against removing liquidity during a spike in value. If the amount to be received falls below this value, the transaction reverts.                                                                                                                                                                                                                                                                                                               |
| *path*                                              | address\[] calldata | <p>The pathway to change one token to another, consisting of an array of addresses. Each token must have an existing liquidity pool, as well as have liquidity.<br></p><p>The <em>path</em> represents the pathway from one token to another. If a pair exists for the two tokens you wish to exchange, this will contain two values inside of an array. However, if there is no direct pair, multiple addresses may be required. </p><p></p><p>As the first swap is swapping IOTX to WIOTX, the first address must be WIOTX.</p> |
| *to*                                                | address             | The address to where the desired token will be sent.                                                                                                                                                                                                                                                                                                                                                                                                                                                                              |
| *deadline*                                          | uint                | The UNIX timestamp for which this transaction must be completed. If the transaction is mined after this deadline, the transaction will revert.                                                                                                                                                                                                                                                                                                                                                                                    |

### swapExactTokensForETHSupportingFeeOnTransferTokens <a href="#swapexacttokensforethsupportingfeeontransfertokens" id="swapexacttokensforethsupportingfeeontransfertokens"></a>

```
function swapExactTokensForETHSupportingFeeOnTransferTokens(
        uint amountIn,
        uint amountOutMin,
        address[] calldata path,
        address to,
        uint deadline
) external;
```

The function `swapExactTokensForETHSupportingFeeOnTransferTokens`is similar to the `swapExactTokensForETH`function, as it swaps an exact amount of XRC-20 tokens for IOTX. In addition, this function allows for fee on transfer tokens, such as PAXG, to be used on uTrade.

#### Function Parameter Breakdown

| Parameter      | Type                | Description                                                                                                                                                                                                                                                                                                                                                                                                                            |
| -------------- | ------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| *amountIn*     | uint                | The amount of tokens being sent to swap into IOTX.                                                                                                                                                                                                                                                                                                                                                                                     |
| *amountOutMin* | uint                | Sets the minimum amount of the IOTX to receive. This acts as a safeguard against removing liquidity during a spike in value. If the amount to be received falls below this value, the transaction reverts.                                                                                                                                                                                                                             |
| *path*         | address\[] calldata | <p>The pathway to change one token to another, consisting of an array of addresses. Each token must have an existing liquidity pool, as well as have liquidity.<br></p><p>The <em>path</em> represents the pathway from one token to another. If a pair exists for the two tokens you wish to exchange, this will contain two values inside of an array. However, if there is no direct pair, multiple addresses may be required. </p> |
| *to*           | address             | The address to where the desired token will be sent.                                                                                                                                                                                                                                                                                                                                                                                   |
| *deadline*     | uint                | The UNIX timestamp for which this transaction must be completed. If the transaction is mined after this deadline, the transaction will revert.                                                                                                                                                                                                                                                                                         |

## Interface Code

```
interface IUnifiRouter01 {
    function factory() external pure returns (address);
    function WETH() external pure returns (address);

    function addLiquidity(
        address tokenA,
        address tokenB,
        uint amountADesired,
        uint amountBDesired,
        uint amountAMin,
        uint amountBMin,
        address to,
        uint deadline
    ) external returns (uint amountA, uint amountB, uint liquidity);
    function addLiquidityETH(
        address token,
        uint amountTokenDesired,
        uint amountTokenMin,
        uint amountETHMin,
        address to,
        uint deadline
    ) external payable returns (uint amountToken, uint amountETH, uint liquidity);
    function removeLiquidity(
        address tokenA,
        address tokenB,
        uint liquidity,
        uint amountAMin,
        uint amountBMin,
        address to,
        uint deadline
    ) external returns (uint amountA, uint amountB);
    function removeLiquidityETH(
        address token,
        uint liquidity,
        uint amountTokenMin,
        uint amountETHMin,
        address to,
        uint deadline
    ) external returns (uint amountToken, uint amountETH);
    function removeLiquidityWithPermit(
        address tokenA,
        address tokenB,
        uint liquidity,
        uint amountAMin,
        uint amountBMin,
        address to,
        uint deadline,
        bool approveMax, uint8 v, bytes32 r, bytes32 s
    ) external returns (uint amountA, uint amountB);
    function removeLiquidityETHWithPermit(
        address token,
        uint liquidity,
        uint amountTokenMin,
        uint amountETHMin,
        address to,
        uint deadline,
        bool approveMax, uint8 v, bytes32 r, bytes32 s
    ) external returns (uint amountToken, uint amountETH);
    function swapExactTokensForTokens(
        uint amountIn,
        uint amountOutMin,
        address[] calldata path,
        address to,
        uint deadline
    ) external returns (uint[] memory amounts);
    function swapTokensForExactTokens(
        uint amountOut,
        uint amountInMax,
        address[] calldata path,
        address to,
        uint deadline
    ) external returns (uint[] memory amounts);
    function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline)
        external
        payable
        returns (uint[] memory amounts);
    function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline)
        external
        returns (uint[] memory amounts);
    function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline)
        external
        returns (uint[] memory amounts);
    function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline)
        external
        payable
        returns (uint[] memory amounts);

    function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB);
    function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut, uint fee) external pure returns (uint amountOut);
    function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut, uint fee) external pure returns (uint amountIn);
    function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts);
    function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts);
}

interface IUnifiRouter02 is IUnifiRouter01 {
    function removeLiquidityETHSupportingFeeOnTransferTokens(
        address token,
        uint liquidity,
        uint amountTokenMin,
        uint amountETHMin,
        address to,
        uint deadline
    ) external returns (uint amountETH);
    function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens(
        address token,
        uint liquidity,
        uint amountTokenMin,
        uint amountETHMin,
        address to,
        uint deadline,
        bool approveMax, uint8 v, bytes32 r, bytes32 s
    ) external returns (uint amountETH);

    function swapExactTokensForTokensSupportingFeeOnTransferTokens(
        uint amountIn,
        uint amountOutMin,
        address[] calldata path,
        address to,
        uint deadline
    ) external;
    function swapExactETHForTokensSupportingFeeOnTransferTokens(
        uint amountOutMin,
        address[] calldata path,
        address to,
        uint deadline
    ) external payable;
    function swapExactTokensForETHSupportingFeeOnTransferTokens(
        uint amountIn,
        uint amountOutMin,
        address[] calldata path,
        address to,
        uint deadline
    ) external;
}
```


# UnifiPair.sol

**Primary Uses -** UnifiPair.sol is responsible for many of the functionalities of liquidity pool tokens and UP tokens. First, it is responsible for the issuing and burning of Liquidity Pool Tokens (uTokens). In addition, it allows for direct reads of the reserves and ratio of the liquidity pool, as well as swaps. Lastly, it is where UP claims are processed.&#x20;

## uTrade V2 Pair Code / Interfaces

|                                             |           |
| ------------------------------------------- | --------- |
| uTrade V2 Pair (Solidity)                   |           |
| uTrade V2 Pair Interface as JSON            | Link Here |
| uTrade V2 Pair as Typescript                | Link Here |
| Import statement codeblock (when available) |           |

## uTrade V2 Pair Contract Addresses

Each uTrade V2 Liquidity Pool uses the uTrade V2 XRC20 Interface in the contract. An example would be `0xBd99494A8EEa8425F5B83D7608b1b198763a97F8` ([Link](https://iotexscan.io/address/0xBd99494A8EEa8425F5B83D7608b1b198763a97F8)) for the WIOTX / UPIotx pair on the IoTeX Main Net.

## Events

### Mint

```
event Mint(address indexed sender, uint amount0, uint amount1);
```

The `Mint` event is emitted any time liquidity tokens are created via the `mint` function. In other words, when a user adds liquidity to a pair, then they will receive LP tokens, therefore the `Mint` event will be emitted.

### Burn

```
event Burn(address indexed sender, uint amount0, uint amount1, address indexed to);
```

The `Burn` event is emitted any time liquidity tokens are burned via the `burn` function. In other words, when a user removes liquidity from a pair,  their LP tokens will be burned, therefore the `Burn` event will be emitted.

### Swap

```
event Swap(
        address indexed sender,
        uint amount0In,
        uint amount1In,
        uint amount0Out,
        uint amount1Out,
        address indexed to
 );
```

The `Swap` event is emitted any time the `swap` function is used. Under the hood, all trades on uTrade V2 are swaps. Therefore, any time somebody trades on the pair, the uTrade contract for that pair will emit a `Swap` event.

### Sync

```
event Sync(uint112 reserve0, uint112 reserve1);
```

The `Sync` event is emitted anytime a function occurs that may change the reserves of a token pair. In other words, anytime the amount of the two tokens within a liquidity pool may change. Therefore, whenever a`mint`, `burn`, `swap`, or `sync` function is called, the `Sync` event will be emitted.

## Read-Only Functions

### MINIMUM\_LIQUIDITY <a href="#minimum_liquidity" id="minimum_liquidity"></a>

```
function MINIMUM_LIQUIDITY() external pure returns (uint);
```

The `MINIMUM_LIQUIDITY`function will always return 1000. The function itself refers to the burning of initial LP tokens that occurs once when a pool is created. This burn of a tiny amount allows for cleaner LP token numbers therefore avoiding LP tokens being represented as very small decimals value. This allows the tick size to be more precise and prevents rounding errors.

### factory

```
function factory() external view returns (address);
```

The `factory` function will return the current factory address for uTrade V2.

### WBNB

```
function WETH() external view returns (address);
```

The `WETH`function will return the address of WIOTX on IoTeX. As this does not change, it will always return `0xa00744882684c3e4747faefd68d283ea44099d03`.

### token0

```
function token0() external view returns (address);
```

The `token0` function will return the contract address of the first token that makes up the liquidity pair. In other words, if the liquidity pool is made up of USDT / USDC, it will return the contract address of USDT.

### token1

```
function token1() external view returns (address);
```

The `token1` function will return the contract address of the first token that makes up the liquidity pair. In other words, if the liquidity pool is made up of USDT / USDC, it will return the contract address of USDC.

### getReserves

```
function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast);
```

The `getReserves` function returns the reserves of the two tokens that make up the liquidity pool as *reserve0* and *reserve1*. These two values can be helpful in determining the current price of each asset. The function also returns a timestamp with the block number.

### price0CumulativeLast

```
function price0CumulativeLast() external view returns (uint);
```

The `price0CumulativeLast`function is for Oracle usage on uTrade V2. The value of *token0* is captured at the end of each block, and can be called using this function to feed into an Oracle to determine a more time-weighted 'average' price.&#x20;

### price1CumulativeLast

```
function price1CumulativeLast() external view returns (uint);
```

The `price1CumulativeLast` function is for Oracle usage on uTrade V2. The value of *token1* is captured at the end of each block, and can be called using this function to feed into an Oracle to determine a more time-weighted 'average' price.&#x20;

### kLast

```
function kLast() external view returns (uint);
```

The `kLast` function returns the value of *reserve0* \* *reserve1*, after any event that may have triggered a change in the liquidity. For example, the execution of a *swap* function or a *mint* function.

## State-Changing Functions

### mint

```
function mint(address to) external returns (uint liquidity);
```

The `mint` function creates the LP tokens that represent a user's tokens in a liquidity pool. For example, if a user provides 20,000 IOTX and 2000 USDT liquidity to a pool, the Unifi Pair Smart Contract will mint an amount of uUSDT tokens. Will emit the `Mint`, `Sync`, and `Transfer` events.

### burn

```
function burn(address to) external returns (uint amount0, uint amount1);
```

The `burn` function destroys the LP tokens that represent a user's token in a liquidity pool. For example, if a user removes 20,000 IOTX and 2000 USDT liquidity to a pool, the Unifi Pair Smart Contract will burn an amount of uUSDT tokens. Will emit the `Burn`, `Sync`, and `Transfer` events.

### claimUP

```
function claimUP(address to) external lock returns(uint) {
```

The `claimUP` function claims any UP earned from providing liquidity if any exists, and sends the UP to the address provided.

### swap

```
function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external;
```

The `swap` function exchanges one token for another. Under the hood, all trades on uTrade V2 use this function. The *calldata* must be 0 during a normal swap, but must contain data if executing a flash loan. Emits the `Swap` and `Sync` events.

### skim

```
function skim(address to) external;
```

The `skim` function operates as a safeguard if the amount of tokens causes a data error due to too large of a number in the reserves pools. In this unusual circumstance, this will trigger failures in trades. The `skim` function can be called to return the overflowed tokens to the caller.

### sync

```
function sync() external;
```

The `sync` function operates as a safeguard in certain events where the token balance changes outside of normal trading. An example would be an algorithmic stablecoin re-balancing, therefore lowering or raising the amount of the algorithmic stablecoin in the pool. The `sync` function may be called to reset the price ratio to the new reserves. Emits the `Sync`event.

## Interface Code

```
interface IUnifiPair {
    event Mint(address indexed sender, uint amount0, uint amount1);
    event Burn(address indexed sender, uint amount0, uint amount1, address indexed to);
    event Swap(
        address indexed sender,
        uint amount0In,
        uint amount1In,
        uint amount0Out,
        uint amount1Out,
        address indexed to
    );
    event Sync(uint112 reserve0, uint112 reserve1);

    function MINIMUM_LIQUIDITY() external pure returns (uint);
    function factory() external view returns (address);
    function token0() external view returns (address);
    function token1() external view returns (address);
    function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast);
    function price0CumulativeLast() external view returns (uint);
    function price1CumulativeLast() external view returns (uint);
    function kLast() external view returns (uint);

    function mint(address to) external returns (uint liquidity);
    function burn(address to) external returns (uint amount0, uint amount1);
    function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external;
    function skim(address to) external;
    function sync() external;

    function initialize(address, address) external;
}
```


# Polygon

Here you will find in-depth detail of the contracts that make up uTrade V2 on Polygon. Each contract includes JSONs as well as Typescript files for integration into your project. Every effort is made to open-source all aspects of uTrade V2, but some do remain private.  When a contract is available, you will find a link to the Github source code.&#x20;


# 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 ;
}
```


# UnifiController.sol

The Unifi Controller is a work in progress with minor tweaks here and there. Full documentation will be available once it is optimized!

**Primary Uses -** The Unifi Controller is responsible for the setting the variables of UP minting on individual pairs as well as updating the redeem value of UP tokens globally.&#x20;

## uTrade V2 Controller Code / Interfaces

|                                             |           |
| ------------------------------------------- | --------- |
| uTrade V2 Controller (Solidity)             | Link Here |
| uTrade V2 Controller Interface as JSON      | Link Here |
| uTrade V2 Controller as Typescript          | Link Here |
| Import statement codeblock (when available) |           |

## uTrade V2 Controller Contract Addresses

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

## Events

### SwapFeesUPminted

```
event SwapFeesUpminted(address indexed pool, uint amountUPMinted, address defaultPoolAddress, uint platforUPFees);
```

The `SwapFeeUpminted` event is emitted whenever UP is minted. In the majority of cases, this will occur any time a trade occurs.&#x20;

#### Parameter Breakdown

| Parameter            | Type    | Description                                                                                     |
| -------------------- | ------- | ----------------------------------------------------------------------------------------------- |
| *pool*               | address | The liquidity pool where the UP was minted.                                                     |
| *amountUPMinted*     | uint    | The amount of UP minted during this event.                                                      |
| *defaultPoolAddress* | address | The pool representing the 'Super Pair' reward for UNIFI holders.                                |
| *platforUPFees*      | uint    | The amount of UP collected by the platform for increasing the redeem value and for Super Pairs. |

### UpdatePoolRewards

```
event UpdatePoolRewards(address indexed pool, uint rewards);    
```

The `UpdatePoolRewards` event is emitted when the amount of UP claimable by the liquidity providers in the liquidity pool is updated. This event occurs when a trade occurs and results in UP being minted for liquidity providers, or a liquidity provider performs a claim UP transaction.

#### Parameter Breakdown

| Parameter | Type    | Description                                                                      |
| --------- | ------- | -------------------------------------------------------------------------------- |
| *pool*    | address | The liquidity pool where the UP was minted.                                      |
| *rewards* | uint    | The amount of UP available to be claimed by all liquidity providers in the pool. |

## Read-Only Functions

#### feeSetter

```
function feeSetter() external view returns (address);
```

The `feeSetter` function returns the address of uTrade V2's Smart Contract which sets the fees for trading.

### WETH

```
function WETH() external view returns (address);
```

The `WETH` function will return the address of WMATIC on Polygon. As this does not change, it will always return `0x0d500b1d8e8ef31e21c99d1db9a6444d3adf1270`.

### UNIFIUPVault

```
function UNIFIUPVault() external view returns (address);
```

The `UNIFIUPVault` function returns the address of the UPMatic vault. This vault contains the MATIC that is redeemable for UP.

### nativeFeeTo

```
function nativeFeeTo() external view returns (address);
```

The `nativeFeeTo` function returns the address where, in the case of Unifi Protocol collecting native token fees, the fees would be sent to.


# UnifiERC20.sol

**Primary Uses -** UnifiERC20.sol essentially ports the properties of ERC-20 tokens on to Unifi LP Tokens, or uTokens. An example of this in practice would be the 'approve' transaction.

## uTrade V2 UnifiERC20 Code / Interfaces

|                                             |                                                                                                                                 |
| ------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------- |
| uTrade V2 UnifiERC20 (Solidity)             | [PolygonScan Verified Pair (WMATIC / UPMatic)](https://polygonscan.com/address/0x2c3f16c99cb288c79200bc380831018ee1d65c5e#code) |
| uTrade V2 UnifiERC20 Interface as JSON      | Link Here                                                                                                                       |
| uTrade V2 UnifiERC20 as Typescript          | Link Here                                                                                                                       |
| Import statement codeblock (when available) |                                                                                                                                 |

## uTrade V2 UnifiERC20 Contract Addresses

Each uTrade V2 Liquidity Pool uses the uTrade V2 ERC20 Interface in the contract. An example would be `0x2C3F16C99CB288C79200BC380831018ee1d65C5E` ([Link](https://polygonscan.com/address/0x2c3f16c99cb288c79200bc380831018ee1d65c5e)) for the WMATIC / UPMatic pair.&#x20;

## Events

### Approval

```
event Approval(address indexed owner, address indexed spender, uint value);
```

The `Approval` event is emitted anytime an `approve` or `permit` function is called.

### Transfer

```
event Transfer(address indexed from, address indexed to, uint value);
```

The `Transfer` event is emitted anytime a transfer of LP tokens occurs, by the `transfer`, `transferFrom`, `mint`, or `burn` functions.

## Read-Only Functions

### name

```
function name() external pure returns (string memory);
```

The `name` function will return "Unifi LPs" for all liquidity pool contracts.

### symbol

```
function symbol() external pure returns (string memory);
```

The `symbol` function will return "Unifi-LP" for all liquidity pool contracts.

### decimals

```
function decimals() external pure returns (uint8);
```

The `decimals` function returns "18" as a uint8 value, which is the precision for each uToken on uTrade V2.

### totalSupply

```
function totalSupply() external view returns (uint);
```

The `totalSupply` function returns the total amount uTokens for a pair.

### balanceOf

```
function balanceOf(address owner) external view returns (uint);
```

The `balanceOf` function returns the balance of uTokens for the provided address.

### allowance

```
function allowance(address owner, address spender) external view returns (uint);
```

The `allowance` function returns the amount of tokens an address is approved to transfer when using the `transferFrom` function.

### DOMAIN\_SEPARATOR

```
function DOMAIN_SEPARATOR() external view returns (bytes32);
```

The `DOMAIN_SEPARATOR` function is used in the `permit` function, and is one of the components that allows transactions to get through without a prior approve transaction. Calling a read function returns the bytes32 data that is required for use in `permit` function.

### PERMIT\_TYPEHASH

```
function PERMIT_TYPEHASH() external view returns (bytes32);
```

The `PERMIT_TYPEHASH` function is used in the `permit` function, and is one of the components that allows transactions to get through without a prior approve transaction. Calling a read function returns the bytes32 data that is required for use in the `permit` function.

### nonces

```
function nonces(address owner) external view returns (uint);
```

The `nonces` function is used in the permit function. It returns the current nonce of the *address* provided.

## State-Changing Functions

### approve

```
function approve(address spender, uint value) external returns (bool);
```

The `approve` function sets a *value* for  the amount of LP tokens the *address* provided is allowed to transfer. Returns a boolean value and emits the `Approval` event.

### transfer

```
function transfer(address to, uint value) external returns (bool);
```

The `transfer` function lets an address send uTokens from one address to another, and returns a boolean value and emits a `Transfer` event.

### transferFrom

```
function transferFrom(address from, address to, uint value) external returns (bool);
```

The `transferFrom` function sends uTokens from one address to another. This requires the sending address to have approval to send uTokens. Returns a boolean value and emits a `Transfer`event.

### permit

```
function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external;
```

The permit function allows a sender to use a signature in lieu of an approval transaction, and sets the allowance for an address to send.

#### Function Parameter Breakdown

| Parameter  | Type    | Description                                                                                                                                    |
| ---------- | ------- | ---------------------------------------------------------------------------------------------------------------------------------------------- |
| *owner*    | address | The owner of the address.                                                                                                                      |
| *spender*  | address | The spender of the uTokens.                                                                                                                    |
| *value*    | uint    | The amount of uTokens to be transferred.                                                                                                       |
| *deadline* | uint    | The UNIX timestamp for which this transaction must be completed. If the transaction is mined after this deadline, the transaction will revert. |
| *v*        | uint8   | The v value of the permit. This is one of the three values that makes up the approval signature.                                               |
| *r*        | bytes32 | The r value of the permit. This is one of the three values that makes up the approval signature.                                               |
| *s*        | bytes32 | The s value of the permit. This is one of the three values that makes up the approval signature.                                               |

## Interface Code

```
interface IUnifiERC20 {
    event Approval(address indexed owner, address indexed spender, uint value);
    event Transfer(address indexed from, address indexed to, uint value);

    function name() external pure returns (string memory);
    function symbol() external pure returns (string memory);
    function decimals() external pure returns (uint8);
    function totalSupply() external view returns (uint);
    function balanceOf(address owner) external view returns (uint);
    function allowance(address owner, address spender) external view returns (uint);

    function approve(address spender, uint value) external returns (bool);
    function transfer(address to, uint value) external returns (bool);
    function transferFrom(address from, address to, uint value) external returns (bool);

    function DOMAIN_SEPARATOR() external view returns (bytes32);
    function PERMIT_TYPEHASH() external pure returns (bytes32);
    function nonces(address owner) external view returns (uint);

    function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external;
}
```


# UnifiFactory.sol

**Primary Uses** - The uTrade V2 Factory contract creates an LP token for any pairs listed on uTrade V2, and indexes them for easy retrieval. In addition, it can return the address of the LP token based on a call of the addresses of the two tokens that make up the liquidity pool.

## uTrade V2 Factory Code / Interfaces

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

## uTrade V2 Factory Contract Addresses

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

## Events

### PairCreated

```
event PairCreated(address indexed token0, address indexed token1, address pair, uint);
```

Anytime a pair is created on uTrade V2 using the `createPair` function, a `PairCreated` event is emitted. Contracts can be deployed to listen for new pairs on the uTrade V2 Polygon Factory address.&#x20;

* *token0* is the token address of the first asset in the token pair.
* *token1* is the token address of the second asset in the token pair.
* *pair* is the address of the newly created uTrade V2 liquidity pool.
* *uint* refers to the index of this uTrade V2 Factor&#x79;*.* For example, the first liquidity pool created on uTrade V2 is 1, the second liquidity pool is 2, and so on. This number can used with the `allPairs(uint)` to return the address. The current number, and therefore the total number of LP pools on uTrade V2 Polygon, can be accessed using the `allPairsLength` function.

## Read-Only Functions <a href="#read-only-functions" id="read-only-functions"></a>

### getPair

```
function getPair(address tokenA, address tokenB) external view returns (address pair);
```

A call to the `getPair` function returns the address of the pair for *tokenA* and *tokenB*.

* If the pair does not exist, the call will return *address(0)*.&#x20;
* The order of the tokens is irrelevant in this call. For example, a call for WMATIC, UNIFI will return the same pair address as UNIFI, WMATIC.&#x20;

### allPairs

```
function allPairs(uint) external view returns (address pair);
```

A call to the `allPairs` function returns the address of a pair based on the indexed *uint* value assigned upon creation of the LP.

* For example, `allPairs(0)` will return the first pair created on uTrade V2 Polygon.
* &#x20;If the index number is too high, as in, there aren't enough pairs created yet, the function will return *address(0)*.

### allPairsLength

```
function allPairsLength() external view returns (uint);
```

A call to the `allPairsLength` function returns the current number of pairs.&#x20;

* For example, if there are 201 total liquidity pool pairs on uTrade V2 Polygon, this call will return *200* as an uint value.

### feeTo

```
function feeTo() external view returns (address);
```

A call to the `feeTo` function returns the percentage of trading fees that Unifi Protocol receives.&#x20;

* Due to the nature of UP Token economics, this is set to zero, but is preserved for flexibility in the future.

### feeToSetter

```
function feeToSetter() external view returns (address);
```

A call to the `feeToSetter` function returns the address to which the `feeTo` would send trading fees, if trading fees were collected.

## State-Changing Functions <a href="#state-changing-functions" id="state-changing-functions"></a>

### createPair

```
function createPair(address tokenA, address tokenB) external returns (address pair);
```

Creates a liquidity pool pair for *tokenA* and *tokenB* if one does not currently exist. After the function is confirmed on chain, a `PairCreated` event is emitted.

## Interface Code

```
interface UnifiFactory {  
  event PairCreated(address indexed token0, address indexed token1, address pair, uint);
  function getPair(address tokenA, address tokenB) external view returns (address pair);  
  function allPairs(uint) external view returns (address pair);  
  function allPairsLength() external view returns (uint);
  function feeTo() external view returns (address);  function feeToSetter() external view returns (address);
  function createPair(address tokenA, address tokenB) external returns (address pair);
  }
```

###

###


# UnifiPair.sol

**Primary Uses -** UnifiPair.sol is responsible for many of the functionalities of liquidity pool tokens and UP tokens. First, it is responsible for the issuing and burning of Liquidity Pool Tokens (uTokens). In addition, it allows for direct reads of the reserves and ratio of the liquidity pool, as well as swaps. Lastly, it is where UP claims are processed.&#x20;

## uTrade V2 Pair Code / Interfaces

|                                             |                                                                                                                                 |
| ------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------- |
| uTrade V2 Pair (Solidity)                   | [PolygonScan Verified Pair (WMATIC / UPMatic)](https://polygonscan.com/address/0x2c3f16c99cb288c79200bc380831018ee1d65c5e#code) |
| uTrade V2 Pair Interface as JSON            | Link Here                                                                                                                       |
| uTrade V2 Pair as Typescript                | Link Here                                                                                                                       |
| Import statement codeblock (when available) |                                                                                                                                 |

## uTrade V2 Pair Contract Addresses

Each uTrade V2 Liquidity Pool uses the uTrade V2 UnifiPair Interface in the contract. An example would be `0x2C3F16C99CB288C79200BC380831018ee1d65C5E` ([Link](https://polygonscan.com/address/0x2c3f16c99cb288c79200bc380831018ee1d65c5e)) for the WMATIC / UPMatic pair.&#x20;

## Events

### Mint

```
event Mint(address indexed sender, uint amount0, uint amount1);
```

The `Mint` event is emitted any time liquidity tokens are created via the `mint` function. In other words, when a user adds liquidity to a pair, then they will receive LP tokens, therefore the `Mint` event will be emitted.

### Burn

```
event Burn(address indexed sender, uint amount0, uint amount1, address indexed to);
```

The `Burn` event is emitted any time liquidity tokens are burned via the `burn` function. In other words, when a user removes liquidity from a pair,  their LP tokens will be burned, therefore the `Burn` event will be emitted.

### Swap

```
event Swap(
        address indexed sender,
        uint amount0In,
        uint amount1In,
        uint amount0Out,
        uint amount1Out,
        address indexed to
 );
```

The `Swap` event is emitted any time the `swap` function is used. Under the hood, all trades on uTrade V2 are swaps. Therefore, any time somebody trades on the pair, the uTrade contract for that pair will emit a `Swap` event.

### Sync

```
event Sync(uint112 reserve0, uint112 reserve1);
```

The `Sync` event is emitted anytime a function occurs that may change the reserves of a token pair. In other words, anytime the amount of the two tokens within a liquidity pool may change. Therefore, whenever a`mint`, `burn`, `swap`, or `sync` function is called, the `Sync` event will be emitted.

## Read-Only Functions

### MINIMUM\_LIQUIDITY <a href="#minimum_liquidity" id="minimum_liquidity"></a>

```
function MINIMUM_LIQUIDITY() external pure returns (uint);
```

The `MINIMUM_LIQUIDITY`function will always return 1000. The function itself refers to the burning of initial LP tokens that occurs once when a pool is created. This burn of a tiny amount allows for cleaner LP token numbers therefore avoiding LP tokens being represented as very small decimals value. This allows the tick size to be more precise and prevents rounding errors.

### factory

```
function factory() external view returns (address);
```

The `factory` function will return the current factory address for uTrade V2.

### WBNB

```
function WETH() external view returns (address);
```

The `WETH` function will return the address of WMATIC on Polygon. As this does not change, it will always return `0x0d500b1d8e8ef31e21c99d1db9a6444d3adf1270`.

### token0

```
function token0() external view returns (address);
```

The `token0` function will return the contract address of the first token that makes up the liquidity pair. In other words, if the liquidity pool is made up of USDT / USDC, it will return the contract address of USDT.

### token1

```
function token1() external view returns (address);
```

The `token1` function will return the contract address of the first token that makes up the liquidity pair. In other words, if the liquidity pool is made up of USDT / USDC, it will return the contract address of USDC.

### getReserves

```
function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast);
```

The `getReserves` function returns the reserves of the two tokens that make up the liquidity pool as *reserve0* and *reserve1*. These two values can be helpful in determining the current price of each asset. The function also returns a timestamp with the block number.

### price0CumulativeLast

```
function price0CumulativeLast() external view returns (uint);
```

The `price0CumulativeLast` function is for Oracle usage on uTrade V2. The value of *token0* is captured at the end of each block, and can be called using this function to feed into an Oracle to determine a more time-weighted 'average' price.&#x20;

### price1CumulativeLast

```
function price1CumulativeLast() external view returns (uint);
```

The `price1CumulativeLast` function is for Oracle usage on uTrade V2. The value of *token1* is captured at the end of each block, and can be called using this function to feed into an Oracle to determine a more time-weighted 'average' price.&#x20;

### kLast

```
function kLast() external view returns (uint);
```

The `kLast` function returns the value of *reserve0* \* *reserve1*, after any event that may have triggered a change in the liquidity. For example, the execution of a *swap* function or a *mint* function.

## State-Changing Functions

### mint

```
function mint(address to) external returns (uint liquidity);
```

The `mint` function creates the LP tokens that represent a user's tokens in a liquidity pool. For example, if a user provides 100 MATIC and 200 USDT liquidity to a pool, the Unifi Pair Smart Contract will mint an amount of uUSDT tokens. Will emit the `Mint`, `Sync`, and `Transfer` events.

### burn

```
function burn(address to) external returns (uint amount0, uint amount1);
```

The `burn` function destroys the LP tokens that represent a user's token in a liquidity pool. For example, if a user removes 100 MATIC and 200 USDT liquidity to a pool, the Unifi Pair Smart Contract will burn an amount of uUSDT tokens. Will emit the `Burn`, `Sync`, and `Transfer` events.

### claimUP

```
function claimUP(address to) external lock returns(uint) {
```

The `claimUP` function claims any UP earned from providing liquidity if any exists, and sends the UP to the address provided.

### swap

```
function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external;
```

The `swap` function exchanges one token for another. Under the hood, all trades on uTrade V2 use this function. The *calldata* must be 0 during a normal swap, but must contain data if executing a flash loan. Emits the `Swap` and `Sync` events.

### skim

```
function skim(address to) external;
```

The `skim` function operates as a safeguard if the amount of tokens causes a data error due to too large of a number in the reserves pools. In this unusual circumstance, this will trigger failures in trades. The `skim` function can be called to return the overflowed tokens to the caller.

### sync

```
function sync() external;
```

The `sync` function operates as a safeguard in certain events where the token balance changes outside of normal trading. An example would be an algorithmic stablecoin re-balancing, therefore lowering or raising the amount of the algorithmic stablecoin in the pool. The `sync` function may be called to reset the price ratio to the new reserves. Emits the `Sync`event.

## Interface Code

```
interface IUnifiPair {
    event Mint(address indexed sender, uint amount0, uint amount1);
    event Burn(address indexed sender, uint amount0, uint amount1, address indexed to);
    event Swap(
        address indexed sender,
        uint amount0In,
        uint amount1In,
        uint amount0Out,
        uint amount1Out,
        address indexed to
    );
    event Sync(uint112 reserve0, uint112 reserve1);

    function MINIMUM_LIQUIDITY() external pure returns (uint);
    function factory() external view returns (address);
    function token0() external view returns (address);
    function token1() external view returns (address);
    function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast);
    function price0CumulativeLast() external view returns (uint);
    function price1CumulativeLast() external view returns (uint);
    function kLast() external view returns (uint);

    function mint(address to) external returns (uint liquidity);
    function burn(address to) external returns (uint amount0, uint amount1);
    function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external;
    function skim(address to) external;
    function sync() external;

    function initialize(address, address) external;
}
```


# UnifiRouter.sol

**Primary Uses** - The uTrade V2 Router is the 'brain' of uTrade. The router finds the optimal path for exchanging one token for another. Whenever a trade is made, your wallet sends funds to the router address. The router will then carry out as many transactions as necessary to acquire the desired token. The router also handles adding liquidity to liquidity pools, and sending the corresponding LP tokens to liquidity providers.

## uTrade V2 Router Code / Interfaces

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

## uTrade V2 Router Contract Addresses

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

### factory

```
function factory() external pure returns (address);
```

A call to the `factory` function returns the address of the current Factory used by uTrade v2. The current factory address for uTrade V2 on Polygon is `0x4FEE52912f81B78C3CdcB723728926ED6a893D27`.

### WETH

```
function WETH() external pure returns (address);
```

A call to the `WETH` function returns the address of Wrapped Matic (WMATIC) on Polygon. As this address does not change, it will always return `0x0d500b1d8e8ef31e21c99d1db9a6444d3adf1270`.

### quote

```
function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB);
```

A call to the `quote` function returns the amount of *tokenB* that will be received for an amount of *tokenA*. This can be used to calculate the exchange rate between two tokens without factoring in slippage or fees. By entering the amount of *tokenA,* the total amount of reserves of *tokenA* as *reserveA,* and the total amount of reserves of *tokenB* as *reserveB*, the call will return the equivalent amount of *tokenB*.

### getAmountOut

```
function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut, uint fee) external pure returns (uint amountOut);
```

A call to the `getAmountOut`function with the amount of the token being sent will return the maximum amount of a token to be received, accounting for fees and the total amount of reserves.

### getAmountIn

```
function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut, uint fee) external pure returns (uint amountIn);
```

A call to the `getAmountIn` function with the amount of the token you wish to receive will return the minimum amount required of the token you wish to send, accounting for fees and the total amount of reserves.

### getAmountsOut

```
function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts);
```

A call to the `getAmountsOut` function with the amount of the token being sent will return the maximum amount to be received of multiple different tokens. By entering multiple LP addresses in the *address* array, the function will return the maximum amount of each token that will be received. A call to this function uses the `getReserves` function from [UnifiPair.sol](https://docs.unifiprotocol.com/utrade-v2/polygon/unifipair.sol) to determine the reserves of the liquidity pool. Then, it calls the `getAmountOut` function to determine the amount of each token in the array that will be received for the *amountIn* value of a token.

### getAmountsIn <a href="#getamountsin" id="getamountsin"></a>

```
function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts);
```

A call to the `getAmountsIn` function with the desired amount of the token to be received will return the minimum amount required to be sent of multiple tokens. By entering multiple LP addresses in the *address* array, the function will return the minimum amount of each token that will need to be sent to receive the desired amount of a token. A call to this function uses the `getReserves` function from [UnifiPair.sol](https://docs.unifiprotocol.com/utrade-v2/polygon/unifipair.sol) to determine the reserves of the liquidity pool. Then, it calls the `getAmountIn` function to determine the amount of each token in the array that will need to be sent for the *amountOut* value of a token.&#x20;

## State-Changing Functions - Liquidity <a href="#state-changing-functions" id="state-changing-functions"></a>

### addLiquidity

```
function addLiquidity(
        address tokenA,
        address tokenB,
        uint amountADesired,
        uint amountBDesired,
        uint amountAMin,
        uint amountBMin,
        address to,
        uint deadline
) external returns (uint amountA, uint amountB, uint liquidity);
```

The `addLiquidity` function adds the two tokens that make up the liquidity pool - *tokenA* and *tokenB* - at the proper ratio based on the reserves of the pool. For example, if the pool contains 200 USDT / 100 WMATIC, a user's liquidity will be added at the ratio of 2 USDT to 1 WMATIC, provided there is no price movements in the pair between when the user broadcasts the transaction to when it is mined. In the event of a price movement, the *amountADesired*, *amountBDesired*, *amountAMin*, and *amountBMin* act as a security measure against an adverse price movement. After the liquidity is added, the function sends the corresponding LP tokens to the sender.

In the case of a pool not existing for the two assets, one will be created using [UnifiFactory.sol](https://docs.unifiprotocol.com/utrade-v2/polygon/unififactory.sol) at the ratio of the assets supplied.

#### Function Parameters Breakdown

| Parameter        | Type    | Description                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          |
| ---------------- | ------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| *tokenA*         | address | Token address of the first asset in the token pair.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  |
| *tokenB*         | address | Token address of the second asset in the token pair.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 |
| *amountADesired* | uint    | The amount of *tokenA* to be added to liquidity if the value of *tokenA* goes down in comparison to *tokenB*.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        |
| *amountBDesired* | uint    | The amount of *tokenB* to be added to liquidity if the value of *tokenB* goes down in comparison to *tokenA.*                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        |
| *amountAMin*     | uint    | <p>Sets the minimum amount of <em>tokenA</em> that can added to the pool before the transaction reverts. This acts as a safeguard. <br></p><ul><li>If the value of <em>tokenA</em> rapidly increases in comparison to <em>tokenB</em>, the user will require less of <em>tokenA</em> to be added to the pool to maintain the original value of the submitted liquidity.</li><li>A user could potentially be adding liquidity during an outlier spike in value. If the amount of <em>tokenA</em> required falls below this value, the transaction will revert.</li><li>This value must be less than or equal to <em>amountADesired</em>.</li></ul>    |
| *amountBMin*     | uint    | <p>Sets the minimum amount of <em>tokenB</em> that can added to the pool before the transaction reverts. This acts as a safeguard.</p><p></p><ul><li>If the value of <em>tokenB</em> rapidly increases in comparison to <em>tokenA</em>, the user will require less of <em>tokenB</em> to be added to the pool to maintain the original value of the submitted liquidity.</li><li> A user could potentially be adding liquidity during an outlier spike in value. If the amount of <em>tokenB</em> required falls below this value, the transaction will revert.</li><li>This value must be less than or equal to <em>amountBDesired</em>.</li></ul> |
| *to*             | address | The address to which the LP tokens for the uTrade V2 pool will be sent.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              |
| *deadline*       | uint    | The UNIX timestamp for which this transaction must be completed. If the transaction is mined after this deadline, the transaction will revert.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       |

#### Function Return Parameter Breakdown

| Parameter   | Type | Description                                                                                                |
| ----------- | ---- | ---------------------------------------------------------------------------------------------------------- |
| *amountA*   | uint | The exact amount of *tokenA* that was sent to the pool.                                                    |
| *amountB*   | uint | The exact amount of *tokenB* that was sent to the pool.                                                    |
| *liquidity* | uint | The exact amount of liquidity tokens minted and sent to the address provided in the *to* paramete&#x72;*.* |

### addLiquidityETH

```
function addLiquidityETH(
        address token,
        uint amountTokenDesired,
        uint amountTokenMin,
        uint amountETHMin,
        address to,
        uint deadline
    ) external payable returns (uint amountToken, uint amountETH, uint liquidity);
```

The `addLiquidityEth` function is similar to the `addLiquidity` function except it accounts for one token being a native asset. In the case of Polygon, this native asset would be MATIC. This function will convert MATIC to WMATIC, will pair that WMATIC with the supplied other token, and add the liquidity to the pool. This function will add at the ideal ratio based on when the transaction is mined.\
\
In the case of a pool not existing for WMATIC and the token provided, one will be created using [UnifiFactory.sol](https://docs.unifiprotocol.com/utrade-v2/polygon/unififactory.sol) at the ratio of the assets supplied.

* This function requires a *msg.value* with the amount of MATIC to be added.&#x20;
  * The *msg.value* acts as the amountETHDesired. As in, if the ratio between MATIC and the token being paired with it change, this is the number of MATIC that will be added to the pool.
  * Any leftover MATIC is returned to the *msg.sender* address.

#### Function Parameter Breakdown

| Parameter                      | Type    | Description                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   |
| ------------------------------ | ------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| *token*                        | address | The address of the supplied token for the liquidity pool. In other words, the asset that MATIC is paired with.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                |
| *amountTokenDesired*           | uint    | The amount of the supplied token to be added to liquidity if the value of token goes down in comparison to MATIC.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             |
| (*amountETHDesired*) msg.value | uint    | Sent as the msg.value, the amount of MATIC to be added to liquidity if the value of MATIC goes down in comparison to token.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   |
| *amountTokenMin*               | uint    | <p>Sets the minimum amount of the supplied token that can added to the pool before the transaction reverts. This acts as a safeguard. </p><p></p><ul><li>If the value of supplied token rapidly increases in comparison to MATIC, the user will require less of the token to be added to the pool to maintain the original value of the submitted liquidity.</li><li>A user could potentially be adding liquidity during an outlier spike in value. If the amount of the supplied token required falls below this value, the transaction will revert.</li><li>This value must be less than or equal to <em>amountTokenDesired</em>.</li></ul> |
| *amountETHMin*                 | uint    | <p></p><p>Sets the minimum amount of MATIC that can added to the pool before the transaction reverts. This acts as a safeguard. </p><p></p><ul><li>If the value of MATIC increases in comparison to the supplied token, the user will require less MATIC to be added to the pool to maintain the original value of the submitted liquidity.</li><li>A user could potentially be adding liquidity during an outlier spike in value. If the amount of MATIC required falls below this value, the transaction will revert.</li><li>This value must be less than or equal to <em>amountETHDesired</em>.</li></ul>                                 |
| *to*                           | address | The address to which the LP tokens for the uTrade V2 pool will be sent.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       |
| *deadline*                     | uint    | The UNIX timestamp for which this transaction must be completed. If the transaction is mined after this deadline, the transaction will revert.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                |

#### Function Return Parameter Breakdown

| Parameter     | Type | Description                                                                                                |
| ------------- | ---- | ---------------------------------------------------------------------------------------------------------- |
| *amountToken* | uint | The exact amount of the supplied token sent to the pool.                                                   |
| *amountETH*   | uint | The exact amount of MATIC converted to WMATIC, and then added to the pool.                                 |
| *liquidity*   | uint | The exact amount of liquidity tokens minted and sent to the address provided in the *to* paramete&#x72;*.* |

### removeLiquidity

```
function removeLiquidity(
        address tokenA,
        address tokenB,
        uint liquidity,
        uint amountAMin,
        uint amountBMin,
        address to,
        uint deadline
) external returns (uint amountA, uint amountB);
```

The `removeLiquidity` function removes the two tokens that make up liquidity from a pool. In other words, this function is used when the pool consists of two ERC-20 tokens.

* In the event one of the assets is paired with MATIC, MATIC will have been wrapped and paired with WMATIC (Wrapped Matic). If the user wishes to withdraw WMATIC instead of withdrawing as MATIC, this function should be used instead of `removeLiquidityETH` .

#### Function Parameter Breakdown

| Parameter    | Type    | Description                                                                                                                                                                                                              |
| ------------ | ------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| *tokenA*     | address | Token address of the first asset in the pair.                                                                                                                                                                            |
| *tokenB*     | address | Token address of the second asset in the pair.                                                                                                                                                                           |
| *liquidity*  | uint    | The amount of liquidity tokens to be redeemed and removed.                                                                                                                                                               |
| *amountAMin* | uint    | Sets the minimum amount of *tokenA* to be removed from the the pool. This acts as a safeguard against removing liquidity during a spike in value. If the removed amount falls below this value, the transaction reverts. |
| *amountBMin* | uint    | Sets the minimum amount of *tokenB* to be removed from the the pool. This acts as a safeguard against removing liquidity during a spike in value. If the removed amount falls below this value, the transaction reverts. |
| *to*         | address | The address to where the redeemed tokens will be sent.                                                                                                                                                                   |
| *deadline*   | uint    | The UNIX timestamp for which this transaction must be completed. If the transaction is mined after this deadline, the transaction will revert.                                                                           |

#### Function Return Parameter Breakdown

| Parameter | Title | Description                                                                      |
| --------- | ----- | -------------------------------------------------------------------------------- |
| *amountA* | uint  | The exact amount of *tokenA* sent to the address provided in the *to* parameter. |
| *amountB* | uint  | The exact amount of *tokenB* sent to the address provided in the *to* parameter. |

### removeLiquidityETH

```
function removeLiquidityETH(
        address token,
        uint liquidity,
        uint amountTokenMin,
        uint amountETHMin,
        address to,
        uint deadline
) external returns (uint amountToken, uint amountETH);
```

The `removeLiquidityETH` function removes MATIC as well as the corresponding paired token in the liquidity pool. In other words, this function is used when the pool consists of WMATIC and an ERC-20 token.

* In the event one of the assets is paired with MATIC, MATIC has been wrapped into WMATIC (Wrapped MATIC). This function will unwrap the WMATIC as the liquidity removed. If the user wishes to withdraw WMATIC instead of withdrawing as MATIC, the `removeLiquidity` function should be used.

#### Function Parameter Breakdown

| Parameter        | Type    | Description                                                                                                                                                                                                             |
| ---------------- | ------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| *token*          | address | Token address of the ERC-20 asset in the pair.                                                                                                                                                                          |
| *liquidity*      | uint    | The amount of liquidity tokens to be redeemed and removed.                                                                                                                                                              |
| *amountTokenMin* | uint    | Sets the minimum amount of *token* to be removed from the the pool. This acts as a safeguard against removing liquidity during a spike in value. If the removed amount falls below this value, the transaction reverts. |
| *amountETHMin*   | uint    | Sets the minimum amount of MATIC to be removed from the pool. This acts as a safeguard against removing liquidity during a spike in value. If the removed amount falls below this value, the transaction reverts.       |
| *to*             | address | The address to where MATIC and token will be sent.                                                                                                                                                                      |
| *deadline*       | uint    | The UNIX timestamp for which this transaction must be completed. If the transaction is mined after this deadline, the transaction will revert.                                                                          |

#### Function Return Parameter Breakdown

| Parameter     | Value | Description                                                                     |
| ------------- | ----- | ------------------------------------------------------------------------------- |
| *amountToken* | uint  | The exact amount of *token* sent to the address provided in the *to* parameter. |
| *amountETH*   | uint  | The exact amount of MATIC sent to the address provided in the *to* parameter.   |

### removeLiquidityWithPermit

```
function removeLiquidityWithPermit(
        address tokenA,
        address tokenB,
        uint liquidity,
        uint amountAMin,
        uint amountBMin,
        address to,
        uint deadline,
        bool approveMax, uint8 v, bytes32 r, bytes32 s
) external returns (uint amountA, uint amountB);
```

The `removeLiquidityWithPermit` functions removes the two tokens that make up liquidity from a pool. In other words, this function is used when the pool consists of two ERC-20 tokens. This function operates similarly to the `removeLiquidity` function with the added benefit of not requiring pre-approvals using permit.

* In the event one of the assets is paired with MATIC, MATIC will have been wrapped and paired with WMATIC (Wrapped MATIC). If the user wishes to withdraw WMATIC instead of withdrawing as MATIC, this function should be used instead of `removeLiquidityETHWithPermit` .

#### Function Parameter Breakdown

| Parameter    | Type    | Description                                                                                                                                                                                                              |
| ------------ | ------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| *tokenA*     | address | Token address of the first asset in the pair.                                                                                                                                                                            |
| *tokenB*     | address | Token address of the second asset in the pair.                                                                                                                                                                           |
| *liquidity*  | uint    | The amount of liquidity tokens to be redeemed and removed.                                                                                                                                                               |
| *amountAMin* | uint    | Sets the minimum amount of *tokenA* to be removed from the the pool. This acts as a safeguard against removing liquidity during a spike in value. If the removed amount falls below this value, the transaction reverts. |
| *amountBMin* | uint    | Sets the minimum amount of *tokenB* to be removed from the the pool. This acts as a safeguard against removing liquidity during a spike in value. If the removed amount falls below this value, the transaction reverts. |
| *to*         | address | The address to where the redeemed tokens will be sent.                                                                                                                                                                   |
| *deadline*   | uint    | The UNIX timestamp for which this transaction must be completed. If the transaction is mined after this deadline, the transaction will revert.                                                                           |
| *approveMax* | bool    | Sets a true or false value on if approval amount in the signature is for liquidity or for uint(-1).                                                                                                                      |
| *v*          | uint8   | The v value of the permit. This is one of the three values that makes up the approval signature.                                                                                                                         |
| *r*          | bytes32 | The r value of the permit. This is one of the three values that makes up the approval signature.                                                                                                                         |
| *s*          | bytes32 | The s value of the permit. This is one of the three values that makes up the approval signature.                                                                                                                         |

#### Function Return Parameter Breakdown

| Parameter | Title | Description                                                                      |
| --------- | ----- | -------------------------------------------------------------------------------- |
| *amountA* | uint  | The exact amount of *tokenA* sent to the address provided in the *to* parameter. |
| *amountB* | uint  | The exact amount of *tokenB* sent to the address provided in the *to* parameter. |

### removeLiquidityETHWithPermit

```
function removeLiquidityETHWithPermit(
        address token,
        uint liquidity,
        uint amountTokenMin,
        uint amountETHMin,
        address to,
        uint deadline,
        bool approveMax, uint8 v, bytes32 r, bytes32 s
) external returns (uint amountToken, uint amountETH);
    
```

The `removeLiquidityETHWithPermit` function removes MATIC as well as the corresponding paired token in the liquidity pool. In other words, this function is used when the pool consists of WMATIC and a ERC-20 token. This function operates similarly to the `removeLiquidityETH`function with the added benefit of not requiring pre-approvals using permit.

* In the event one of the assets is paired with MATIC, MATIC has been wrapped into WMATIC (Wrapped Matic). This function will unwrap the WMATIC as the liquidity removed. If the user wishes to withdraw WMATIC instead of withdrawing as MATIC, the `removeLiquidityWithPermit` function should be used.

#### Function Parameter Breakdown

| Parameter        | Type    | Description                                                                                                                                                                                                             |
| ---------------- | ------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| *token*          | address | Token address of the ERC-20 asset in the pair.                                                                                                                                                                          |
| *liquidity*      | uint    | The amount of liquidity tokens to be redeemed and removed.                                                                                                                                                              |
| *amountTokenMin* | uint    | Sets the minimum amount of *token* to be removed from the the pool. This acts as a safeguard against removing liquidity during a spike in value. If the removed amount falls below this value, the transaction reverts. |
| *amountETHMin*   | uint    | Sets the minimum amount of MATIC to be removed from the the pool. This acts as a safeguard against removing liquidity during a spike in value. If the removed amount falls below this value, the transaction reverts.   |
| *to*             | address | The address to where MATIC and token will be sent.                                                                                                                                                                      |
| *deadline*       | uint    | The UNIX timestamp for which this transaction must be completed. If the transaction is mined after this deadline, the transaction will revert.                                                                          |
| *v*              | uint8   | The v value of the permit. This is one of the three values that makes up the approval signature.                                                                                                                        |
| *r*              | bytes32 | The r value of the permit. This is one of the three values that makes up the approval signature.                                                                                                                        |
| *s*              | bytes32 | The s value of the permit. This is one of the three values that makes up the approval signature.                                                                                                                        |

#### Function Return Parameter Breakdown

| Parameter     | Value | Description                                                                     |
| ------------- | ----- | ------------------------------------------------------------------------------- |
| *amountToken* | uint  | The exact amount of *token* sent to the address provided in the *to* parameter. |
| *amountETH*   | uint  | The exact amount of MATIC sent to the address provided in the *to* parameter.   |

### removeLiquidityETHSupportingFeeOnTransferTokens

```
function removeLiquidityETHSupportingFeeOnTransferTokens(
        address token,
        uint liquidity,
        uint amountTokenMin,
        uint amountETHMin,
        address to,
        uint deadline
) external returns (uint amountETH);
```

The `removeLiquidityETHSupportingFeeOnTransferTokens`function is similar to the `removeLiquidityETH` function, and contains the same call parameters. This function removes ETH as well as the corresponding paired token in the liquidity pool. In other words, this function is used when the pool consists of WMATIC and a ERC-20 token.&#x20;

However, this function allows for fee on transfer tokens, such as PAXG, to be used on uTrade.&#x20;

#### Function Parameter Breakdown

| Parameter        | Type    | Description                                                                                                                                                                                                             |
| ---------------- | ------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| *token*          | address | Token address of the ERC-20 asset in the pair.                                                                                                                                                                          |
| *liquidity*      | uint    | The amount of liquidity tokens to be redeemed and removed.                                                                                                                                                              |
| *amountTokenMin* | uint    | Sets the minimum amount of *token* to be removed from the the pool. This acts as a safeguard against removing liquidity during a spike in value. If the removed amount falls below this value, the transaction reverts. |
| *amountETHMin*   | uint    | Sets the minimum amount of MATIC to be removed from the the pool. This acts as a safeguard against removing liquidity during a spike in value. If the removed amount falls below this value, the transaction reverts.   |
| *to*             | address | The address to where MATIC and the paired token will be sent.                                                                                                                                                           |
| *deadline*       | uint    | The UNIX timestamp for which this transaction must be completed. If the transaction is mined after this deadline, the transaction will revert.                                                                          |

#### Function Return Parameter Breakdown

| Parameter   | Value | Description                                                                                                                                                                                                                     |
| ----------- | ----- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| *amountETH* | uint  | The exact amount of MATIC sent to the address provided in the *to* parameter. Note that the *amountToken* parameter is not returned. The amount of fee on transfer that a token may have is not available prior to transaction. |

### removeLiquidityETHWithPermitSupportingFeeOnTransferTokens

```
function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens(
        address token,
        uint liquidity,
        uint amountTokenMin,
        uint amountETHMin,
        address to,
        uint deadline,
        bool approveMax, uint8 v, bytes32 r, bytes32 s
) external returns (uint amountETH);
```

The `removeLiquidityETHWithPermitSupportingFeeOnTransferTokens`function is similar to the `removeLiquidityETHWithPermit`function. This function removes MATIC as well as the corresponding paired token in the liquidity pool. In other words, this function is used when the pool consists of WMATIC and an ERC-20 token. This function operates similarly to the `removeLiquidityETHfunction` with the added benefit of not requiring pre-approvals using permit In addition, this function allows for fee on transfer tokens, such as PAXG, to be used on uTrade.&#x20;

#### Function Parameter Breakdown

| Parameter        | Type    | Description                                                                                                                                                                                                             |
| ---------------- | ------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| *token*          | address | Token address of the ERC-20 asset in the pair.                                                                                                                                                                          |
| *liquidity*      | uint    | The amount of liquidity tokens to be redeemed and removed.                                                                                                                                                              |
| *amountTokenMin* | uint    | Sets the minimum amount of *token* to be removed from the the pool. This acts as a safeguard against removing liquidity during a spike in value. If the removed amount falls below this value, the transaction reverts. |
| *amountETHMin*   | uint    | Sets the minimum amount of MATIC to be removed from the the pool. This acts as a safeguard against removing liquidity during a spike in value. If the removed amount falls below this value, the transaction reverts.   |
| *to*             | address | The address to where MATIC and token will be sent.                                                                                                                                                                      |
| *deadline*       | uint    | The UNIX timestamp for which this transaction must be completed. If the transaction is mined after this deadline, the transaction will revert.                                                                          |
| *v*              | uint8   | The v value of the permit. This is one of the three values that makes up the approval signature.                                                                                                                        |
| *r*              | bytes32 | The r value of the permit. This is one of the three values that makes up the approval signature.                                                                                                                        |
| *s*              | bytes32 | The s value of the permit. This is one of the three values that makes up the approval signature.                                                                                                                        |

#### Function Return Parameter Breakdown

| Parameter   | Value | Description                                                                                                                                                                                                                     |
| ----------- | ----- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| *amountETH* | uint  | The exact amount of MATIC sent to the address provided in the *to* parameter. Note that the *amountToken* parameter is not returned. The amount of fee on transfer that a token may have is not available prior to transaction. |

## State-Changing Functions - Swap

### swapExactTokensForTokens

```
function swapExactTokensForTokens(
        uint amountIn,
        uint amountOutMin,
        address[] calldata path,
        address to,
        uint deadline
) external returns (uint[] memory amounts);
```

The `swapExactTokensForTokens` function sends an exact amount of tokens for the maximum amount of another token.&#x20;

#### Function Parameter Breakdown

| Parameter      | Type                | Description                                                                                                                                                                                                                                                                                                                                                                                                                            |
| -------------- | ------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| *amountIn*     | uint                | The amount of tokens being sent to swap into another token                                                                                                                                                                                                                                                                                                                                                                             |
| *amountOutMin* | uint                | Sets the minimum amount of the desired token to receive. This acts as a safeguard against removing liquidity during a spike in value. If the amount to be received falls below this value, the transaction reverts.                                                                                                                                                                                                                    |
| *path*         | address\[] calldata | <p>The pathway to change one token to another, consisting of an array of addresses. Each token must have an existing liquidity pool, as well as have liquidity.<br></p><p>The <em>path</em> represents the pathway from one token to another. If a pair exists for the two tokens you wish to exchange, this will contain two values inside of an array. However, if there is no direct pair, multiple addresses may be required. </p> |
| *to*           | address             | The address to where the desired token will be sent.                                                                                                                                                                                                                                                                                                                                                                                   |
| *deadline*     | uint                | The UNIX timestamp for which this transaction must be completed. If the transaction is mined after this deadline, the transaction will revert.                                                                                                                                                                                                                                                                                         |

#### Function Return Parameter Breakdown

| Parameter | Type           | Description                                                                                                |
| --------- | -------------- | ---------------------------------------------------------------------------------------------------------- |
| *amounts* | uint\[] memory | The exact amount of tokens sent into the swap, as well as the exact return amount of all subsequent swaps. |

### swapTokensForExactTokens

```
function swapTokensForExactTokens(
        uint amountOut,
        uint amountInMax,
        address[] calldata path,
        address to,
        uint deadline
) external returns (uint[] memory amounts);
```

The `swapTokensForExactTokens` function sends the minimum amount of tokens for the exact amount of another token.&#x20;

#### Function Parameter Breakdown

| Parameter     | Type                | Description                                                                                                                                                                                                                                                                                                                                                                                                                            |
| ------------- | ------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| *amountOut*   | uint                | The exact amount of the desired tokens to be received.                                                                                                                                                                                                                                                                                                                                                                                 |
| *amountInMax* | uint                | Sets the maximum amount of token to be sent in. This acts as a safeguard against removing liquidity during a spike in value. If the amount to be sent rises above this value, the transaction reverts.                                                                                                                                                                                                                                 |
| *path*        | address\[] calldata | <p>The pathway to change one token to another, consisting of an array of addresses. Each token must have an existing liquidity pool, as well as have liquidity.<br></p><p>The <em>path</em> represents the pathway from one token to another. If a pair exists for the two tokens you wish to exchange, this will contain two values inside of an array. However, if there is no direct pair, multiple addresses may be required. </p> |
| *to*          | address             | The address to where the desired token will be sent.                                                                                                                                                                                                                                                                                                                                                                                   |
| *deadline*    | uint                | The UNIX timestamp for which this transaction must be completed. If the transaction is mined after this deadline, the transaction will revert.                                                                                                                                                                                                                                                                                         |

#### Function Return Parameter Breakdown

| Parameter | Type           | Description                                                                                                |
| --------- | -------------- | ---------------------------------------------------------------------------------------------------------- |
| *amounts* | uint\[] memory | The exact amount of tokens sent into the swap, as well as the exact return amount of all subsequent swaps. |

### swapExactETHForTokens

```
function swapExactETHForTokens(
        uint amountOutMin, 
        address[] calldata path, 
        address to, 
        uint deadline)
        external
        payable
returns (uint[] memory amounts);
```

The `swapExactETHForTokens` function sends an exact amount of MATIC for a desired token.

#### Function Parameter Breakdown

| Parameter                                           | Type                | Description                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          |
| --------------------------------------------------- | ------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| <p><em>(amountIn)</em></p><p><em>msg.value</em></p> | uint                | Sent as the msg.value, the amount of MATIC to be swapped.                                                                                                                                                                                                                                                                                                                                                                                                                                                                            |
| *amountOutMin*                                      | uint                | Sets the minimum amount of the desired token to receive. This acts as a safeguard against removing liquidity during a spike in value. If the amount to be received falls below this value, the transaction reverts.                                                                                                                                                                                                                                                                                                                  |
| *path*                                              | address\[] calldata | <p>The pathway to change one token to another, consisting of an array of addresses. Each token must have an existing liquidity pool, as well as have liquidity.<br></p><p>The <em>path</em> represents the pathway from one token to another. If a pair exists for the two tokens you wish to exchange, this will contain two values inside of an array. However, if there is no direct pair, multiple addresses may be required. </p><p></p><p>As the first swap is swapping MATIC to WMATIC, the first address must be WMATIC.</p> |
| *to*                                                | address             | The address to where the desired token will be sent.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 |
| *deadline*                                          | uint                | The UNIX timestamp for which this transaction must be completed. If the transaction is mined after this deadline, the transaction will revert.                                                                                                                                                                                                                                                                                                                                                                                       |

#### Function Return Parameter Breakdown

| Parameter | Type           | Description                                                                                               |
| --------- | -------------- | --------------------------------------------------------------------------------------------------------- |
| *amounts* | uint\[] memory | The exact amount of MATIC sent into the swap, as well as the exact return amount of all subsequent swaps. |

### swapTokensForExactETH

```
function swapTokensForExactETH(
        uint amountOut, 
        uint amountInMax, 
        address[] calldata path, 
        address to, 
        uint deadline)
        external
        returns (uint[] memory amounts);
```

The `swapTokensForExactETH` function sends an amount of tokens for an exact amount of MATIC.

#### Function Parameter Breakdown

| Parameter     | Type                | Description                                                                                                                                                                                                                                                                                                                                                                                                                            |
| ------------- | ------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| *amountOut*   | uint                | The exact amount of the MATIC to be received.                                                                                                                                                                                                                                                                                                                                                                                          |
| *amountInMax* | uint                | Sets the maximum amount of token to be sent in. This acts as a safeguard against removing liquidity during a spike in value. If the amount to be sent rises above this value, the transaction reverts.                                                                                                                                                                                                                                 |
| *path*        | address\[] calldata | <p>The pathway to change one token to another, consisting of an array of addresses. Each token must have an existing liquidity pool, as well as have liquidity.<br></p><p>The <em>path</em> represents the pathway from one token to another. If a pair exists for the two tokens you wish to exchange, this will contain two values inside of an array. However, if there is no direct pair, multiple addresses may be required. </p> |
| *to*          | address             | The address to where the desired token will be sent.                                                                                                                                                                                                                                                                                                                                                                                   |
| *deadline*    | uint                | The UNIX timestamp for which this transaction must be completed. If the transaction is mined after this deadline, the transaction will revert.                                                                                                                                                                                                                                                                                         |

#### Function Return Parameter Breakdown

| Parameter | Type           | Description                                                                                         |
| --------- | -------------- | --------------------------------------------------------------------------------------------------- |
| *amounts* | uint\[] memory | The exact amount of tokens sent into the swap, as well as the exact amount of all subsequent swaps. |

### swapExactTokensForETH

```
function swapExactTokensForETH(
        uint amountIn, 
        uint amountOutMin, 
        address[] calldata path, 
        address to, 
        uint deadline)
        external
        returns (uint[] memory amounts);
```

The `swapExactTokensForETH` function sends an exact amount of tokens for MATIC.

#### Function Parameter Breakdown

| Parameter      | Type                | Description                                                                                                                                                                                                                                                                                                                                                                                                                            |
| -------------- | ------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| *amountIn*     | uint                | The amount of tokens being sent to swap into MATIC.                                                                                                                                                                                                                                                                                                                                                                                    |
| *amountOutMin* | uint                | Sets the minimum amount of the MATIC to receive. This acts as a safeguard against removing liquidity during a spike in value. If the amount to be received falls below this value, the transaction reverts.                                                                                                                                                                                                                            |
| *path*         | address\[] calldata | <p>The pathway to change one token to another, consisting of an array of addresses. Each token must have an existing liquidity pool, as well as have liquidity.<br></p><p>The <em>path</em> represents the pathway from one token to another. If a pair exists for the two tokens you wish to exchange, this will contain two values inside of an array. However, if there is no direct pair, multiple addresses may be required. </p> |
| *to*           | address             | The address to where the desired token will be sent.                                                                                                                                                                                                                                                                                                                                                                                   |
| *deadline*     | uint                | The UNIX timestamp for which this transaction must be completed. If the transaction is mined after this deadline, the transaction will revert.                                                                                                                                                                                                                                                                                         |

#### Function Parameter Return Breakdown

| Parameter | Type           | Description                                                                                         |
| --------- | -------------- | --------------------------------------------------------------------------------------------------- |
| *amounts* | uint\[] memory | The exact amount of tokens sent into the swap, as well as the exact amount of all subsequent swaps. |

### swapETHForExactTokens

```
function swapETHForExactTokens(
        uint amountOut, 
        address[] calldata path, 
        address to, 
        uint deadline)
        external
        payable
        returns (uint[] memory amounts);
```

The `swapETHForExactTokens` function swaps an exact amount of MATIC for an amount of the desired token.

#### Function Parameter Breakdown

| Parameter                                           | Type                | Description                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          |
| --------------------------------------------------- | ------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| <p><em>(amountIn)</em></p><p><em>msg.value</em></p> | uint                | Sent as the msg.value, the amount of MATIC to be swapped.                                                                                                                                                                                                                                                                                                                                                                                                                                                                            |
| *amountOutMin*                                      | uint                | Sets the minimum amount of the desired token to receive. This acts as a safeguard against removing liquidity during a spike in value. If the amount to be received falls below this value, the transaction reverts.                                                                                                                                                                                                                                                                                                                  |
| *path*                                              | address\[] calldata | <p>The pathway to change one token to another, consisting of an array of addresses. Each token must have an existing liquidity pool, as well as have liquidity.<br></p><p>The <em>path</em> represents the pathway from one token to another. If a pair exists for the two tokens you wish to exchange, this will contain two values inside of an array. However, if there is no direct pair, multiple addresses may be required. </p><p></p><p>As the first swap is swapping MATIC to WMATIC, the first address must be WMATIC.</p> |
| *to*                                                | address             | The address to where the desired token will be sent.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 |
| *deadline*                                          | uint                | The UNIX timestamp for which this transaction must be completed. If the transaction is mined after this deadline, the transaction will revert.                                                                                                                                                                                                                                                                                                                                                                                       |

#### Function Return Parameter Breakdown

| Parameter | Type           | Description                                                                                               |
| --------- | -------------- | --------------------------------------------------------------------------------------------------------- |
| *amounts* | uint\[] memory | The exact amount of MATIC sent into the swap, as well as the exact return amount of all subsequent swaps. |

### swapExactTokensForTokensSupportingFeeOnTransferTokens

```
function swapExactTokensForTokensSupportingFeeOnTransferTokens(
        uint amountIn,
        uint amountOutMin,
        address[] calldata path,
        address to,
        uint deadline
) external;
```

The `swapExactTokensForTokensSupportingFeeOnTransferTokens` function is similar to `swapExactTokensForTokens` as it swaps one ERC-20 token for another ERC-20 token. In addition, this function allows for fee on transfer tokens, such as PAXG, to be used on uTrade.

#### Function Parameter Breakdown

| Name           | Type                |                                                                                                                                                                                                                                                                                                                                                                                                                              |
| -------------- | ------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| *amountIn*     | uint                | The amount of tokens being sent to swap into another token.                                                                                                                                                                                                                                                                                                                                                                  |
| *amountOutMin* | uint                | Sets the minimum amount of the desired token to receive. This acts as a safeguard against removing liquidity during a spike in value. If the amount to be received falls below this value, the transaction reverts.                                                                                                                                                                                                          |
| *path*         | address\[] calldata | <p>The pathway to change one token to another, consisting of an array of addresses. Each token must have an existing liquidity pool, as well as have liquidity.<br></p><p>The path represents the pathway from one token to another. If a pair exists for the two tokens you wish to exchange, this will contain two values inside of an array. However, if there is no direct pair, multiple addresses may be required.</p> |
| *to*           | address             | The address to where the desired token will be sent.                                                                                                                                                                                                                                                                                                                                                                         |
| *deadline*     | uint                | The UNIX timestamp for which this transaction must be completed. If the transaction is mined after this deadline, the transaction will revert.                                                                                                                                                                                                                                                                               |

### swapExactETHForTokensSupportingFeeOnTransferTokens

```
function swapExactETHForTokensSupportingFeeOnTransferTokens(
        uint amountOutMin,
        address[] calldata path,
        address to,
        uint deadline
 ) external payable;
```

The `swapExactETHForTokensSupportingFeeOnTransferTokens`function  is similar to `swapExactETHForTokens` function as it swaps an exact amount of MATIC for ERC-20 tokens. In addition, this function allows for fee on transfer tokens, such as PAXG, to be used on uTrade.&#x20;

#### Function Parameter Breakdown

| Parameter                                           | Type                | Description                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          |
| --------------------------------------------------- | ------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| <p><em>(amountIn)</em></p><p><em>msg.value</em></p> | uint                | Sent as the msg.value, the exact amount of MATIC to be swapped.                                                                                                                                                                                                                                                                                                                                                                                                                                                                      |
| *amountOutMin*                                      | uint                | Sets the minimum amount of the desired token to receive. This acts as a safeguard against removing liquidity during a spike in value. If the amount to be received falls below this value, the transaction reverts.                                                                                                                                                                                                                                                                                                                  |
| *path*                                              | address\[] calldata | <p>The pathway to change one token to another, consisting of an array of addresses. Each token must have an existing liquidity pool, as well as have liquidity.<br></p><p>The <em>path</em> represents the pathway from one token to another. If a pair exists for the two tokens you wish to exchange, this will contain two values inside of an array. However, if there is no direct pair, multiple addresses may be required. </p><p></p><p>As the first swap is swapping MATIC to WMATIC, the first address must be WMATIC.</p> |
| *to*                                                | address             | The address to where the desired token will be sent.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 |
| *deadline*                                          | uint                | The UNIX timestamp for which this transaction must be completed. If the transaction is mined after this deadline, the transaction will revert.                                                                                                                                                                                                                                                                                                                                                                                       |

### swapExactTokensForETHSupportingFeeOnTransferTokens <a href="#swapexacttokensforethsupportingfeeontransfertokens" id="swapexacttokensforethsupportingfeeontransfertokens"></a>

```
function swapExactTokensForETHSupportingFeeOnTransferTokens(
        uint amountIn,
        uint amountOutMin,
        address[] calldata path,
        address to,
        uint deadline
) external;
```

The function `swapExactTokensForETHSupportingFeeOnTransferTokens`is similar to the `swapExactTokensForETH`function, as it swaps an exact amount of ERC-20 tokens for MATIC. In addition, this function allows for fee on transfer tokens, such as PAXG, to be used on uTrade.

#### Function Parameter Breakdown

| Parameter      | Type                | Description                                                                                                                                                                                                                                                                                                                                                                                                                            |
| -------------- | ------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| *amountIn*     | uint                | The amount of tokens being sent to swap into MATIC.                                                                                                                                                                                                                                                                                                                                                                                    |
| *amountOutMin* | uint                | Sets the minimum amount of the MATIC to receive. This acts as a safeguard against removing liquidity during a spike in value. If the amount to be received falls below this value, the transaction reverts.                                                                                                                                                                                                                            |
| *path*         | address\[] calldata | <p>The pathway to change one token to another, consisting of an array of addresses. Each token must have an existing liquidity pool, as well as have liquidity.<br></p><p>The <em>path</em> represents the pathway from one token to another. If a pair exists for the two tokens you wish to exchange, this will contain two values inside of an array. However, if there is no direct pair, multiple addresses may be required. </p> |
| *to*           | address             | The address to where the desired token will be sent.                                                                                                                                                                                                                                                                                                                                                                                   |
| *deadline*     | uint                | The UNIX timestamp for which this transaction must be completed. If the transaction is mined after this deadline, the transaction will revert.                                                                                                                                                                                                                                                                                         |

## Interface Code

```
interface IUnifiRouter01 {
    function factory() external pure returns (address);
    function WETH() external pure returns (address);

    function addLiquidity(
        address tokenA,
        address tokenB,
        uint amountADesired,
        uint amountBDesired,
        uint amountAMin,
        uint amountBMin,
        address to,
        uint deadline
    ) external returns (uint amountA, uint amountB, uint liquidity);
    function addLiquidityETH(
        address token,
        uint amountTokenDesired,
        uint amountTokenMin,
        uint amountETHMin,
        address to,
        uint deadline
    ) external payable returns (uint amountToken, uint amountETH, uint liquidity);
    function removeLiquidity(
        address tokenA,
        address tokenB,
        uint liquidity,
        uint amountAMin,
        uint amountBMin,
        address to,
        uint deadline
    ) external returns (uint amountA, uint amountB);
    function removeLiquidityETH(
        address token,
        uint liquidity,
        uint amountTokenMin,
        uint amountETHMin,
        address to,
        uint deadline
    ) external returns (uint amountToken, uint amountETH);
    function removeLiquidityWithPermit(
        address tokenA,
        address tokenB,
        uint liquidity,
        uint amountAMin,
        uint amountBMin,
        address to,
        uint deadline,
        bool approveMax, uint8 v, bytes32 r, bytes32 s
    ) external returns (uint amountA, uint amountB);
    function removeLiquidityETHWithPermit(
        address token,
        uint liquidity,
        uint amountTokenMin,
        uint amountETHMin,
        address to,
        uint deadline,
        bool approveMax, uint8 v, bytes32 r, bytes32 s
    ) external returns (uint amountToken, uint amountETH);
    function swapExactTokensForTokens(
        uint amountIn,
        uint amountOutMin,
        address[] calldata path,
        address to,
        uint deadline
    ) external returns (uint[] memory amounts);
    function swapTokensForExactTokens(
        uint amountOut,
        uint amountInMax,
        address[] calldata path,
        address to,
        uint deadline
    ) external returns (uint[] memory amounts);
    function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline)
        external
        payable
        returns (uint[] memory amounts);
    function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline)
        external
        returns (uint[] memory amounts);
    function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline)
        external
        returns (uint[] memory amounts);
    function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline)
        external
        payable
        returns (uint[] memory amounts);

    function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB);
    function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut, uint fee) external pure returns (uint amountOut);
    function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut, uint fee) external pure returns (uint amountIn);
    function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts);
    function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts);
}

interface IUnifiRouter02 is IUnifiRouter01 {
    function removeLiquidityETHSupportingFeeOnTransferTokens(
        address token,
        uint liquidity,
        uint amountTokenMin,
        uint amountETHMin,
        address to,
        uint deadline
    ) external returns (uint amountETH);
    function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens(
        address token,
        uint liquidity,
        uint amountTokenMin,
        uint amountETHMin,
        address to,
        uint deadline,
        bool approveMax, uint8 v, bytes32 r, bytes32 s
    ) external returns (uint amountETH);

    function swapExactTokensForTokensSupportingFeeOnTransferTokens(
        uint amountIn,
        uint amountOutMin,
        address[] calldata path,
        address to,
        uint deadline
    ) external;
    function swapExactETHForTokensSupportingFeeOnTransferTokens(
        uint amountOutMin,
        address[] calldata path,
        address to,
        uint deadline
    ) external payable;
    function swapExactTokensForETHSupportingFeeOnTransferTokens(
        uint amountIn,
        uint amountOutMin,
        address[] calldata path,
        address to,
        uint deadline
    ) external;
}
```


# Unifi.Report API Docs

Documentation for Unifi Report public API endpoints.

New API endpoints will be added here as they are developed. \
\
All Unifi Report API endpoints should be called using the url: `https://data.unifi.report`


# Graphs

API endpoints for the various charts and graphs displayed on Unifi Report.

##


# Account Page Graph data

The amount of unique and total accounts that have interacted with the Unifi Protocol over a given time period.

All Unifi Report API endpoints should be called using the url: `https://data.unifi.report`

Endpoint `GET /api/account-page-graph/`

| Parameter  | Description     |
| ---------- | --------------- |
| blockchain | Blockchain name |

Example API call: `curl -X GET -H 'Accept: application/json; indent=4' https://data.unifi.report/api/account-page-graph/?blockchain=Tron`\
&#x20;Response:

```
[
    {
        "date": "2021-01-04",
        "blockchain": "Tron",
        "blockchain_active_traders": "69",
        "blockchain_total_traders": "989"
    },
    {
        "date": "2021-01-05",
        "blockchain": "Tron",
        "blockchain_active_traders": "53",
        "blockchain_total_traders": "991"
    },
    {
        "date": "2021-01-06",
        "blockchain": "Tron",
        "blockchain_active_traders": "53",
        "blockchain_total_traders": "997"
    },
    {
        "date": "2021-01-07",
        "blockchain": "Tron",
        "blockchain_active_traders": "60",
        "blockchain_total_traders": "1005"
    },
    {
        "date": "2021-01-08",
        "blockchain": "Tron",
        "blockchain_active_traders": "67",
        "blockchain_total_traders": "1009"
    },
    {
        "date": "2021-01-09",
        "blockchain": "Tron",
        "blockchain_active_traders": "65",
        "blockchain_total_traders": "1013"
    },
    {
        "date": "2021-01-10",
        "blockchain": "Tron",
        "blockchain_active_traders": "53",
        "blockchain_total_traders": "1016"
    },
    {
        "date": "2021-01-11",
        "blockchain": "Tron",
        "blockchain_active_traders": "52",
        "blockchain_total_traders": "1020"
    },
    {
        "date": "2021-01-12",
        "blockchain": "Tron",
        "blockchain_active_traders": "56",
        "blockchain_total_traders": "1026"
    },
    {
        "date": "2021-01-13",
        "blockchain": "Tron",
        "blockchain_active_traders": "49",
        "blockchain_total_traders": "1027"
    },
    {
        "date": "2021-01-14",
        "blockchain": "Tron",
        "blockchain_active_traders": "43",
        "blockchain_total_traders": "1031"
    }
]
```


# Details Page Graphs

Details regarding specific uPairs on uTrade, including USD value of liquidity.

All Unifi Report API endpoints should be called using the url: `https://data.unifi.report`

Endpoint `GET /api/liquidity-graph-info/` <br>

| Parameter | Description      |
| --------- | ---------------- |
| contract  | Contract Address |

Example API call: `curl -X GET -H 'Accept: application/json; indent=4' https://data.unifi.report/api/liquidity-graph-info/?contract=TU2FCnCEaZChdVsifYQmL9WpNoCwDqXACJ`\
&#x20;Response:

```
[
    {
        "datetime": "2021-01-08",
        "smart_contract": "TS7NC6BKsFwbkJk7TZZS636YNJWuRvBDg9",
        "liquidity_a": "24195.306728",
        "liquidity_b": "41625.27274",
        "liquidity_a_usd": "1269.6763704750686",
        "liquidity_b_usd": "1269.6765467627597",
        "liquidity_total": "65820.579468",
        "liquidity_total_usd": "2539.3529172378285",
        "buy_volume_usd": "10.487277895695335",
        "sell_volume_usd": "0.0",
        "total_volume_usd": "10.487277895695335"
    },
    {
        "datetime": "2021-01-09",
        "smart_contract": "TS7NC6BKsFwbkJk7TZZS636YNJWuRvBDg9",
        "liquidity_a": "24195.306728",
        "liquidity_b": "41625.27274",
        "liquidity_a_usd": "1432.0190741479369",
        "liquidity_b_usd": "1432.0192729760336",
        "liquidity_total": "65820.579468",
        "liquidity_total_usd": "2864.0383471239707",
        "buy_volume_usd": "0.0",
        "sell_volume_usd": "0.0",
        "total_volume_usd": "0.0"
    },
    {
        "datetime": "2021-01-10",
        "smart_contract": "TS7NC6BKsFwbkJk7TZZS636YNJWuRvBDg9",
        "liquidity_a": "23803.606596",
        "liquidity_b": "42309.385843",
        "liquidity_a_usd": "1398.4031587593113",
        "liquidity_b_usd": "1398.403897568818",
        "liquidity_total": "66112.992439",
        "liquidity_total_usd": "2796.8070563281294",
        "buy_volume_usd": "51.61324514662071",
        "sell_volume_usd": "28.601828802372918",
        "total_volume_usd": "80.21507394899363"
    },
    {
        "datetime": "2021-01-11",
        "smart_contract": "TS7NC6BKsFwbkJk7TZZS636YNJWuRvBDg9",
        "liquidity_a": "23803.606596",
        "liquidity_b": "42309.385843",
        "liquidity_a_usd": "1214.6971717668039",
        "liquidity_b_usd": "1214.697813520087",
        "liquidity_total": "66112.992439",
        "liquidity_total_usd": "2429.394985286891",
        "buy_volume_usd": "0.0",
        "sell_volume_usd": "0.0",
        "total_volume_usd": "0.0"
    },
    {
        "datetime": "2021-01-12",
        "smart_contract": "TS7NC6BKsFwbkJk7TZZS636YNJWuRvBDg9",
        "liquidity_a": "24328.321023",
        "liquidity_b": "41395.636644",
        "liquidity_a_usd": "1183.899450157819",
        "liquidity_b_usd": "1183.8994776764753",
        "liquidity_total": "65723.957667",
        "liquidity_total_usd": "2367.7989278342943",
        "buy_volume_usd": "8.555469578081667",
        "sell_volume_usd": "34.08987127509495",
        "total_volume_usd": "42.64534085317662"
    },
    {
        "datetime": "2021-01-13",
        "smart_contract": "TS7NC6BKsFwbkJk7TZZS636YNJWuRvBDg9",
        "liquidity_a": "25033.818067",
        "liquidity_b": "40227.770154",
        "liquidity_a_usd": "1202.6843653281953",
        "liquidity_b_usd": "1202.6844146840178",
        "liquidity_total": "65261.588221",
        "liquidity_total_usd": "2405.3687800122134",
        "buy_volume_usd": "0.0",
        "sell_volume_usd": "36.65440658737242",
        "total_volume_usd": "36.65440658737242"
    },
    {
        "datetime": "2021-01-14",
        "smart_contract": "TS7NC6BKsFwbkJk7TZZS636YNJWuRvBDg9",
        "liquidity_a": "25911.152568",
        "liquidity_b": "38864.322359",
        "liquidity_a_usd": "1176.3595907651772",
        "liquidity_b_usd": "1176.3596889614848",
        "liquidity_total": "64775.474927",
        "liquidity_total_usd": "2352.719279726662",
        "buy_volume_usd": "0.0",
        "sell_volume_usd": "74.46893195151823",
        "total_volume_usd": "74.46893195151823"
    }
]
```


# Total Volume and Liquidity

Total volume and liquidity on a given blockchain on uTrade.

All Unifi Report API endpoints should be called using the url: `https://data.unifi.report`

Endpoint `GET /api/total-volume-liquidity/`

| Parameter  | Description     |
| ---------- | --------------- |
| blockchain | Blockchain name |

Example API call: `curl -X GET -H 'Accept: application/json; indent=4' https://data.unifi.report/api/total-volume-liquidity/?blockchain=Tron`\
&#x20;Response:

```
[
    {
        "datetime": "2021-01-08",
        "blockchain": "Tron",
        "liquidity": "477103.87080234004",
        "volume": "27357.84099199856"
    },
    {
        "datetime": "2021-01-09",
        "blockchain": "Tron",
        "liquidity": "534032.4774134799",
        "volume": "9893.330604148287"
    },
    {
        "datetime": "2021-01-10",
        "blockchain": "Tron",
        "liquidity": "504145.66731176997",
        "volume": "10063.582271850983"
    },
    {
        "datetime": "2021-01-11",
        "blockchain": "Tron",
        "liquidity": "447441.5838297001",
        "volume": "8924.637704482973"
    },
    {
        "datetime": "2021-01-12",
        "blockchain": "Tron",
        "liquidity": "446188.76798518",
        "volume": "3564.184480485333"
    },
    {
        "datetime": "2021-01-13",
        "blockchain": "Tron",
        "liquidity": "462752.1685596601",
        "volume": "8876.958822521816"
    },
    {
        "datetime": "2021-01-14",
        "blockchain": "Tron",
        "liquidity": "472199.0167375599",
        "volume": "1672.292931642252"
    }
]
```


# UP Token Stats

Historical data on UP token.

All Unifi Report API endpoints should be called using the url: `https://data.unifi.report`

Endpoint `GET /api/up-graph/` <br>

| Parameter  | Description     |
| ---------- | --------------- |
| blockchain | Blockchain name |

Example API call: `curl -X GET -H 'Accept: application/json; indent=4' https://data.unifi.report/api/up-graph/?blockchain=Tron`\
&#x20;Response:

```
[
    {
        "datetime": "2021-01-01",
        "unix_time": "1609542020",
        "redeem_value": "9.418377",
        "redeem_value_usd": "0.25380811870386",
        "market_price": "27.710213",
        "market_price_usd": "0.74673980776234",
        "total_supply": "682816.143402",
        "total_supply_usd": "18400.652339302906",
        "blockchain": "Tron"
    },
    {
        "datetime": "2021-01-02",
        "unix_time": "1609628407",
        "redeem_value": "9.419755",
        "redeem_value_usd": "0.2556922788563",
        "market_price": "26.175099",
        "market_price_usd": "0.71050369278174",
        "total_supply": "683045.244517",
        "total_supply_usd": "18540.757708933023",
        "blockchain": "Tron"
    },
    {
        "datetime": "2021-01-03",
        "unix_time": "1609714828",
        "redeem_value": "9.421512",
        "redeem_value_usd": "0.27779243338392",
        "market_price": "26.183596",
        "market_price_usd": "0.7720209715363601",
        "total_supply": "683342.648795",
        "total_supply_usd": "20148.296498882184",
        "blockchain": "Tron"
    },
    {
        "datetime": "2021-01-04",
        "unix_time": "1609801257",
        "redeem_value": "9.424321",
        "redeem_value_usd": "0.28812938896016005",
        "market_price": "26.163639",
        "market_price_usd": "0.79989988860144",
        "total_supply": "683314.190292",
        "total_supply_usd": "20890.937407229703",
        "blockchain": "Tron"
    },
    {
        "datetime": "2021-01-05",
        "unix_time": "1609887641",
        "redeem_value": "9.42711",
        "redeem_value_usd": "0.27307386984570003",
        "market_price": "26.051078",
        "market_price_usd": "0.7546181897858599",
        "total_supply": "683775.756046",
        "total_supply_usd": "19806.843434536197",
        "blockchain": "Tron"
    },
    {
        "datetime": "2021-01-06",
        "unix_time": "1609974055",
        "redeem_value": "10.37812",
        "redeem_value_usd": "0.31713687414639996",
        "market_price": "25.471929",
        "market_price_usd": "0.7783768102063799",
        "total_supply": "621425.741729",
        "total_supply_usd": "18989.66452941796",
        "blockchain": "Tron"
    },
    {
        "datetime": "2021-01-07",
        "unix_time": "1610060417",
        "redeem_value": "10.383127",
        "redeem_value_usd": "0.32853480569494",
        "market_price": "28.135407",
        "market_price_usd": "0.89023860267654",
        "total_supply": "621815.129259",
        "total_supply_usd": "19674.989304212453",
        "blockchain": "Tron"
    },
    {
        "datetime": "2021-01-08",
        "unix_time": "1610146820",
        "redeem_value": "10.392088",
        "redeem_value_usd": "0.3147664730364",
        "market_price": "28.184995",
        "market_price_usd": "0.8536967228047501",
        "total_supply": "623068.043147",
        "total_supply_usd": "18872.139112281642",
        "blockchain": "Tron"
    },
    {
        "datetime": "2021-01-09",
        "unix_time": "1610233234",
        "redeem_value": "10.39473",
        "redeem_value_usd": "0.355153621491",
        "market_price": "29.55051",
        "market_price_usd": "1.009643410017",
        "total_supply": "623382.367621",
        "total_supply_usd": "21298.918339796423",
        "blockchain": "Tron"
    },
    {
        "datetime": "2021-01-10",
        "unix_time": "1610319694",
        "redeem_value": "10.397785",
        "redeem_value_usd": "0.3413730066262",
        "market_price": "27.398566",
        "market_price_usd": "0.8995310878871199",
        "total_supply": "623809.953484",
        "total_supply_usd": "20480.504202018317",
        "blockchain": "Tron"
    },
    {
        "datetime": "2021-01-11",
        "unix_time": "1610406064",
        "redeem_value": "10.40057",
        "redeem_value_usd": "0.2959422910251",
        "market_price": "27.865776",
        "market_price_usd": "0.79290477258768",
        "total_supply": "624199.777717",
        "total_supply_usd": "17761.248881063937",
        "blockchain": "Tron"
    },
    {
        "datetime": "2021-01-12",
        "unix_time": "1610492424",
        "redeem_value": "10.401892",
        "redeem_value_usd": "0.29842549660968",
        "market_price": "27.668539",
        "market_price_usd": "0.79379765638206",
        "total_supply": "624385.047827",
        "total_supply_usd": "17913.31980503463",
        "blockchain": "Tron"
    },
    {
        "datetime": "2021-01-13",
        "unix_time": "1610578855",
        "redeem_value": "10.408137",
        "redeem_value_usd": "0.31038896366112",
        "market_price": "26.390877",
        "market_price_usd": "0.78702240008352",
        "total_supply": "625260.006027",
        "total_supply_usd": "18646.353837335748",
        "blockchain": "Tron"
    },
    {
        "datetime": "2021-01-14",
        "unix_time": "1610640017",
        "redeem_value": "10.41071",
        "redeem_value_usd": "0.3142518620624",
        "market_price": "26.383897",
        "market_price_usd": "0.7964095398596801",
        "total_supply": "625620.758645",
        "total_supply_usd": "18884.63787283313",
        "blockchain": "Tron"
    }
]
```


# Current UP Token Stats

Live data on UP token on each blockchain.

All Unifi Report API endpoints should be called using the url: `https://data.unifi.report`\
Endpoint `GET /api/up-graph/grouped` <br>

Response:

```
{
    "Harmony": [
        {
            "datetime": "2021-01-13",
            "unix_time": "1610578855",
            "redeem_value": "41.133235",
            "redeem_value_usd": "0.27302061331545",
            "market_price": "99.789328",
            "market_price_usd": "0.66234867092016",
            "total_supply": "24307.760471",
            "total_supply_usd": "161.3420308934484",
            "blockchain": "Harmony"
        },
    ]
    "Tron": [
        ...
    ]
    "Binance": [
        ...
    ]
}
```


# List Smart Contracts

For compiling a table of data from the Unifi Protocol.

All Unifi Report API endpoints should be called using the url: `https://data.unifi.report`

Endpoint `GET /api/smart-contract-balances/`

| Parameter  | Description                                    |
| ---------- | ---------------------------------------------- |
| blockchain | Blockchain name                                |
| contract   | Contract Address                               |
| pair       | Swap pair                                      |
| sort       | Sort by volume, liquidity, price or blockchain |

| sort parameter options | description                    |
| ---------------------- | ------------------------------ |
| volume                 | Sorts by volume                |
| volume\_desc           | Sorts by descending volume     |
| liquidity              | Sorts by liquidity             |
| liquidity\_desc        | Sorts by descending liquidity  |
| price                  | Sorts by price                 |
| price\_desc            | Sorts by descending price      |
| blockchain             | Sorts by blockchain            |
| blockchain\_desc       | Sorts by descending blockchain |

Example API call: `curl -X GET -H 'Accept: application/json; indent=4' https://data.unifi.report/api/smart-contract-balances/?contract=TUxqQp2qXUx7hT2F6Zx4hy85n8o9L9bzM9`\
&#x20;Response:

```
{
    "count": 1,
    "next": null,
    "previous": null,
    "results": [
         {
            "datetime": "2021-03-09",
            "icon": "https://icon-service.unifi.report/icon_trc20?token=TJ93jQZibdB3sriHYb5nNwjgkPPAcFR7ty",
            "nativeIcon": "https://icon-service.unifi.report/icon_trc20?token=trx",
            "token_a": "UP",
            "liquidity_a": "48112.22",
            "token_b": "TRX",
            "liquidity_b": "1376504.2",
            "total_liquidity": "151218.75",
            "price_native_token": "1.63626179",
            "token_address": "TJ93jQZibdB3sriHYb5nNwjgkPPAcFR7ty",
            "contract_address": "TUxqQp2qXUx7hT2F6Zx4hy85n8o9L9bzM9",
            "trading_pair": "UP-TRX",
            "blockchain": "Tron",
            "native_token_price_usd": "0.0526657",
            "volume": "4128.416407999999",
            "volume_usd": "6755.17",
            "link": "https://tronscan.org/#/contract/TUxqQp2qXUx7hT2F6Zx4hy85n8o9L9bzM9/code",
            "liquidity_change_percentage": "-4.75",
            "volume_change_percentage": "-2.1",
            "volume_usd_change_percentage": "-8.06",
            "price_change": "-6.09",
            "transaction_count": "51",
            "transaction_change_percentage": "24.39",
            "annual_percentage_yield": "38.19677309857802782744329306297004",
            "annual_percentage_bonus_yield": "0.00000000000000000000000000000000",
            "annual_percentage_plus_bonus_yield": "0.00000000000000000000000000000000",
            "variable_annual_percentage_rate": "0.10464869342076171809807760837430",
            "annual_percentage_bonus_rate": "0.00000000000000000000000000000000",
            "annual_percentage_plus_bonus_rate": "0.00000000000000000000000000000000",
            "bonus_status": "Inactive",
            "bonus_token_address": "None",
            "bonus_token_name": "None",
            "farm_contract": "None"
        }
    ]
}
```


# Transactions

Data regarding transactions occurring on uTrade.


# List of Transactions

The list of transactions that have occurred on uTrade.

All Unifi Report API endpoints should be called using the url: `https://data.unifi.report`

Endpoint `GET /api/transactions/`

| Parameter     | Description        |
| ------------- | ------------------ |
| page          | Page number        |
| page\_size    | Page size up to 50 |
| contract      | Contract Address   |
| user\_account | User Address       |
| blockchain    | Blockchain name    |
| hash          | Transaction Hash   |

Example API call: `curl -X GET -H 'Accept: application/json; indent=4' https://data.unifi.report/api/transactions/?blockchain=Tron` \
&#x20;Response:

```
{
    "count": 52976,
    "next": "/api/transactions/?blockchain=Tron&page=2&page_size=1",
    "previous": null,
    "results": [
        {
            "date": "2021-01-14",
            "unix_time": "1610626419",
            "blockchain": "Tron",
            "blockchain_short": "TRX",
            "symbol": "SOUL",
            "hash": "0fd953483cdd5735f33e95c3c7971394b66ff71e478c2c76bd7ef5f189a8b8ba",
            "address": "TU2FCnCEaZChdVsifYQmL9WpNoCwDqXACJ",
            "token_address": "THXm85dwyCSTNPq8h1JDPth2vuTcwtXyBb",
            "network_fee": "201186",
            "contract": "TS7NC6BKsFwbkJk7TZZS636YNJWuRvBDg9",
            "block": "26749248",
            "action": "Sell",
            "native_token_calculated": "1348.464853",
            "calculated_amount": "877.334501"
        },
    ]
}
```


# Details Page for Transactions

Details regarding transactions occurring on uTrade, such as which assets were traded.

All Unifi Report API endpoints should be called using the url: `https://data.unifi.report`

Endpoint `GET /api/transaction-detail/`

| Parameter | Description      | Required |
| --------- | ---------------- | :------: |
| hash      | Transaction hash |   Check  |

Example API call: `curl -X GET -H 'Accept: application/json; indent=4' https://data.unifi.report/api/transaction-detail/?hash=2f05f71b48cd50a94ace4f710962fd5b7a5f45e8d2d9585427413ce4b00b0cee` \
&#x20;Response:

```
[
    {
        "date": "2021-01-14",
        "unix_time": "1610626419",
        "blockchain": "Tron",
        "blockchain_short": "TRX",
        "symbol": "SEED",
        "hash": "0fd953483cdd5735f33e95c3c7971394b66ff71e478c2c76bd7ef5f189a8b8ba",
        "address": "TU2FCnCEaZChdVsifYQmL9WpNoCwDqXACJ",
        "token_address": "TBwoSTyywvLrgjSgaatxrBhxt3DGpVuENh",
        "network_fee": "201186",
        "contract": "TMFvnLMR1r1awHVGZsciwP4e3PVD7eiMWe",
        "block": "26749248",
        "action": "Sell",
        "native_token_calculated": "1.362085",
        "calculated_amount": "1.014331",
        "subtransactions": [
            {
                "from_address": "TMFvnLMR1r1awHVGZsciwP4e3PVD7eiMWe",
                "to_address": "TU2FCnCEaZChdVsifYQmL9WpNoCwDqXACJ",
                "contract_address": "TBwoSTyywvLrgjSgaatxrBhxt3DGpVuENh",
                "calculated_amount": "1.014331",
                "token": "SEED"
            },
            {
                "from_address": "T9yD14Nj9j7xAB4dbGeiX9h8unkKHxuWwb",
                "to_address": "TMFvnLMR1r1awHVGZsciwP4e3PVD7eiMWe",
                "contract_address": "TJ93jQZibdB3sriHYb5nNwjgkPPAcFR7ty",
                "calculated_amount": "0.000457",
                "token": "UP"
            },
            {
                "from_address": "T9yD14Nj9j7xAB4dbGeiX9h8unkKHxuWwb",
                "to_address": "TB5wAYNuMqM92aoRQbvNmDmJaNtq8wLy3v",
                "contract_address": "TJ93jQZibdB3sriHYb5nNwjgkPPAcFR7ty",
                "calculated_amount": "0.000457",
                "token": "UP"
            },
            {
                "from_address": "TU2FCnCEaZChdVsifYQmL9WpNoCwDqXACJ",
                "to_address": "TS7NC6BKsFwbkJk7TZZS636YNJWuRvBDg9",
                "contract_address": "THXm85dwyCSTNPq8h1JDPth2vuTcwtXyBb",
                "calculated_amount": "877.334501",
                "token": "SOUL"
            },
            {
                "from_address": "T9yD14Nj9j7xAB4dbGeiX9h8unkKHxuWwb",
                "to_address": "TS7NC6BKsFwbkJk7TZZS636YNJWuRvBDg9",
                "contract_address": "TJ93jQZibdB3sriHYb5nNwjgkPPAcFR7ty",
                "calculated_amount": "0.457926",
                "token": "UP"
            },
            {
                "from_address": "T9yD14Nj9j7xAB4dbGeiX9h8unkKHxuWwb",
                "to_address": "TB5wAYNuMqM92aoRQbvNmDmJaNtq8wLy3v",
                "contract_address": "TJ93jQZibdB3sriHYb5nNwjgkPPAcFR7ty",
                "calculated_amount": "0.457926",
                "token": "UP"
            }
        ]
    },
    {
        "date": "2021-01-14",
        "unix_time": "1610626419",
        "blockchain": "Tron",
        "blockchain_short": "TRX",
        "symbol": "SOUL",
        "hash": "0fd953483cdd5735f33e95c3c7971394b66ff71e478c2c76bd7ef5f189a8b8ba",
        "address": "TU2FCnCEaZChdVsifYQmL9WpNoCwDqXACJ",
        "token_address": "THXm85dwyCSTNPq8h1JDPth2vuTcwtXyBb",
        "network_fee": "201186",
        "contract": "TS7NC6BKsFwbkJk7TZZS636YNJWuRvBDg9",
        "block": "26749248",
        "action": "Sell",
        "native_token_calculated": "1348.464853",
        "calculated_amount": "877.334501",
        "subtransactions": [
            {
                "from_address": "TMFvnLMR1r1awHVGZsciwP4e3PVD7eiMWe",
                "to_address": "TU2FCnCEaZChdVsifYQmL9WpNoCwDqXACJ",
                "contract_address": "TBwoSTyywvLrgjSgaatxrBhxt3DGpVuENh",
                "calculated_amount": "1.014331",
                "token": "SEED"
            },
            {
                "from_address": "T9yD14Nj9j7xAB4dbGeiX9h8unkKHxuWwb",
                "to_address": "TMFvnLMR1r1awHVGZsciwP4e3PVD7eiMWe",
                "contract_address": "TJ93jQZibdB3sriHYb5nNwjgkPPAcFR7ty",
                "calculated_amount": "0.000457",
                "token": "UP"
            },
            {
                "from_address": "T9yD14Nj9j7xAB4dbGeiX9h8unkKHxuWwb",
                "to_address": "TB5wAYNuMqM92aoRQbvNmDmJaNtq8wLy3v",
                "contract_address": "TJ93jQZibdB3sriHYb5nNwjgkPPAcFR7ty",
                "calculated_amount": "0.000457",
                "token": "UP"
            },
            {
                "from_address": "TU2FCnCEaZChdVsifYQmL9WpNoCwDqXACJ",
                "to_address": "TS7NC6BKsFwbkJk7TZZS636YNJWuRvBDg9",
                "contract_address": "THXm85dwyCSTNPq8h1JDPth2vuTcwtXyBb",
                "calculated_amount": "877.334501",
                "token": "SOUL"
            },
            {
                "from_address": "T9yD14Nj9j7xAB4dbGeiX9h8unkKHxuWwb",
                "to_address": "TS7NC6BKsFwbkJk7TZZS636YNJWuRvBDg9",
                "contract_address": "TJ93jQZibdB3sriHYb5nNwjgkPPAcFR7ty",
                "calculated_amount": "0.457926",
                "token": "UP"
            },
            {
                "from_address": "T9yD14Nj9j7xAB4dbGeiX9h8unkKHxuWwb",
                "to_address": "TB5wAYNuMqM92aoRQbvNmDmJaNtq8wLy3v",
                "contract_address": "TJ93jQZibdB3sriHYb5nNwjgkPPAcFR7ty",
                "calculated_amount": "0.457926",
                "token": "UP"
            }
        ]
    }
]
```


# Accounts

Endpoint `GET /api/accounts`


# Binance Smart Chain

Contract API endpoints

**Please refer to the smart contract documentation for Binance Smart Chain for instructions on how to use these API endpoints with their smart contracts.**

## &#x20;BSC CONTRACT API

### &#x20;Call API

| Method name                                     | Param   | Return  | Description                                             | Trade related |
| ----------------------------------------------- | ------- | ------- | ------------------------------------------------------- | ------------- |
| `getPrice()`                                    | -       | uint256 | get the curent pool state                               | Yes           |
| `getMaxTransaction()`                           | -       | uint256 | get max amount per transaction                          | Yes           |
| `getMinTransaction()`                           | -       | uint256 | get min amount per transaction                          | Yes           |
| `getEstimatedBuyReceiveAmount(uint256 amount)`  | uint256 | uint256 | Returns the amount of trading token to receive          | Yes           |
| `getEstimatedSellReceiveAmount(uint256 amount)` | uint256 | uint256 | Returns the amount of base token to receive             | Yes           |
| `pendingFeeEarn()`                              | -       | uint256 | Return amount of UP token the user can claim            | No            |
| `getMaxRatio()`                                 | -       | uint256 | %Max amount per trade                                   | Yes           |
| `getSTATE()`                                    | -       | uint256 | If the pair is open for trading:\[0 - close , 1 - open] | Yes           |
| `getSeedBuyRate()`                              | -       | uint256 | Rebates %\[Out of 100000]                               | Yes           |
| `getFEE()`                                      | -       | uint256 | %FEE for the pair\[Out of 100000]                       | Yes           |
| `totalSupply()`                                 | -       | uint256 | Return Total Supply of liquidity token                  | No            |
| `balanceOf(address owner)`                      | address | uint256 | Return user liquidity balance                           | No            |
| `name()`                                        | -       | string  | Return Liquidity name Symbol                            | No            |
| `symbol()`                                      | -       | string  | Return Liquidity Token Symbol                           | No            |
| `decimals()`                                    | -       | uint28  | Return Liquidity Token Decimals                         | No            |

### &#x20;Send API

| Method name      | Param   | Return  | Payable | Description                                                                                                                                                                                                         |                                                                       |
| ---------------- | ------- | ------- | ------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------- |
| `Buy`            | address | uint256 | Yes     | When a user  buys a trading token.Example UP/BNB, a user would like to BUY UP using 1 BNB param would be user account address, call value would be 1 BNB                                                            |                                                                       |
| `Sell`           | uint256 | uint256 | No      | When a user sells a trading token.Example UP/BNB, a user would like to SELL 10 UP.The webapp \*must( send an approval before executing sell function. Param would be 1e19\[Up has 18 decimals we are selling 10 UP] |                                                                       |
| `DepositSupply`  | -       | uint256 | Yes     | For Liquidity Providers to deposit their tokens approval/allowance must be given before trigerring this function                                                                                                    |                                                                       |
| `WithdrawSupply` | uint256 | bool    | No      | False                                                                                                                                                                                                               | Liquidity providers to withdraw their liquidity                       |
| `ClaimFee`       | -       | uint256 | -       | No                                                                                                                                                                                                                  | Liquidity providers to claim the UP fees earn from the smart contract |


# Ethereum

Contract API endpoints

**Please refer to the smart contract documentation for Ethereum for instructions on how to use these API endpoints with their smart contracts.**

##

## &#x20;ETH CONTRACT API

### &#x20;Call API

| Method name                                     | Param   | Return  | Description                                             | Trade related |
| ----------------------------------------------- | ------- | ------- | ------------------------------------------------------- | ------------- |
| `getPrice()`                                    | -       | uint256 | get the curent pool state                               | Yes           |
| `getMaxTransaction()`                           | -       | uint256 | get max amount per transaction                          | Yes           |
| `getMinTransaction()`                           | -       | uint256 | get min amount per transaction                          | Yes           |
| `getEstimatedBuyReceiveAmount(uint256 amount)`  | uint256 | uint256 | Returns the amount of trading token to receive          | Yes           |
| `getEstimatedSellReceiveAmount(uint256 amount)` | uint256 | uint256 | Returns the amount of base token to receive             | Yes           |
| `pendingFeeEarn()`                              | -       | uint256 | Return amount of UP token the user can claim            | No            |
| `getMaxRatio()`                                 | -       | uint256 | %Max amount per trade                                   | Yes           |
| `getSTATE()`                                    | -       | uint256 | If the pair is open for trading:\[0 - close , 1 - open] | Yes           |
| `getSeedBuyRate()`                              | -       | uint256 | Rebates %\[Out of 100000]                               | Yes           |
| `getFEE()`                                      | -       | uint256 | %FEE for the pair\[Out of 100000]                       | Yes           |
| `totalSupply()`                                 | -       | uint256 | Return Total Supply of liquidity token                  | No            |
| `balanceOf(address owner)`                      | address | uint256 | Return user liquidity balance                           | No            |
| `name()`                                        | -       | string  | Return Liquidity name Symbol                            | No            |
| `symbol()`                                      | -       | string  | Return Liquidity Token Symbol                           | No            |
| `decimals()`                                    | -       | uint28  | Return Liquidity Token Decimals                         | No            |

### &#x20;Send API

| Method name      | Param   | Return  | Payable | Description                                                                                                                                                                                                         |                                                                       |
| ---------------- | ------- | ------- | ------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------- |
| `Buy`            | address | uint256 | Yes     | When a user  buys a trading token.Example UP/ETH, a user would like to BUY UP using 1 ETH param would be user account address, call value would be 1 ETH                                                            |                                                                       |
| `Sell`           | uint256 | uint256 | No      | When a user sells a trading token.Example UP/ETH, a user would like to SELL 10 UP.The webapp \*must( send an approval before executing sell function. Param would be 1e19\[Up has 18 decimals we are selling 10 UP] |                                                                       |
| `DepositSupply`  | -       | uint256 | Yes     | For Liquidity Providers to deposit their tokens approval/allowance must be given before trigerring this function                                                                                                    |                                                                       |
| `WithdrawSupply` | uint256 | bool    | No      | False                                                                                                                                                                                                               | Liquidity providers to withdraw their liquidity                       |
| `ClaimFee`       | -       | uint256 | -       | No                                                                                                                                                                                                                  | Liquidity providers to claim the UP fees earn from the smart contract |


# Harmony

Contract API endpoints

**Please refer to the smart contract documentation for Harmony for instructions on how to use these API endpoints with their smart contracts.**

## Harmony CONTRACT API

### &#x20;Call API

| Method name                                     | Param   | Return  | Description                                             | Trade related |
| ----------------------------------------------- | ------- | ------- | ------------------------------------------------------- | ------------- |
| `getPrice()`                                    | -       | uint256 | get the curent pool state                               | Yes           |
| `getMaxTransaction()`                           | -       | uint256 | get max amount per transaction                          | Yes           |
| `getMinTransaction()`                           | -       | uint256 | get min amount per transaction                          | Yes           |
| `getEstimatedBuyReceiveAmount(uint256 amount)`  | uint256 | uint256 | Returns the amount of trading token to receive          | Yes           |
| `getEstimatedSellReceiveAmount(uint256 amount)` | uint256 | uint256 | Returns the amount of base token to receive             | Yes           |
| `pendingFeeEarn()`                              | -       | uint256 | Return amount of UP token the user can claim            | No            |
| `getMaxRatio()`                                 | -       | uint256 | %Max amount per trade                                   | Yes           |
| `getSTATE()`                                    | -       | uint256 | If the pair is open for trading:\[0 - close , 1 - open] | Yes           |
| `getSeedBuyRate()`                              | -       | uint256 | Rebates %\[Out of 100000]                               | Yes           |
| `getFEE()`                                      | -       | uint256 | %FEE for the pair\[Out of 100000]                       | Yes           |
| `totalSupply()`                                 | -       | uint256 | Return Total Supply of liquidity token                  | No            |
| `balanceOf(address owner)`                      | address | uint256 | Return user liquidity balance                           | No            |
| `name()`                                        | -       | string  | Return Liquidity name Symbol                            | No            |
| `symbol()`                                      | -       | string  | Return Liquidity Token Symbol                           | No            |
| `decimals()`                                    | -       | uint28  | Return Liquidity Token Decimals                         | No            |

### &#x20;Send API

| Method name      | Param   | Return  | Payable | Description                                                                                                                                                                                                         |                                                                                                                                                          |                                                                                                                  |
| ---------------- | ------- | ------- | ------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------- |
| `Buy`            | address | uint256 | Yes     | True                                                                                                                                                                                                                | When a user  buys a trading token.Example UP/ONE, a user would like to BUY UP using 1 ONE param would be user account address, call value would be 1 ONE |                                                                                                                  |
| `Sell`           | uint256 | uint256 | No      | When a user sells a trading token.Example UP/ONE, a user would like to SELL 10 UP.The webapp \*must( send an approval before executing sell function. Param would be 1e19\[Up has 18 decimals we are selling 10 UP] |                                                                                                                                                          |                                                                                                                  |
| `DepositSupply`  | -       | uint256 | Yes     | No                                                                                                                                                                                                                  | True                                                                                                                                                     | For Liquidity Providers to deposit their tokens approval/allowance must be given before trigerring this function |
| `WithdrawSupply` | uint256 | bool    | -       | No                                                                                                                                                                                                                  | False                                                                                                                                                    | Liquidity providers to withdraw their liquidity                                                                  |
| `ClaimFee`       | -       | uint256 | -       | No                                                                                                                                                                                                                  | False                                                                                                                                                    | Liquidity providers to claim the UP fees earn from the smart contract                                            |


# Icon

Contract API endpoints

**Please refer to the smart contract documentation for ICON for instructions on how to use these API endpoints with their smart contracts.**

## &#x20;ICON CONTRACT API

### &#x20;Call API

| Method name                                  | Param   | Return  | Description                                              | Trade related |
| -------------------------------------------- | ------- | ------- | -------------------------------------------------------- | ------------- |
| `getPrice()`                                 | -       | int     | get the curent pool state                                | Yes           |
| `getMaxTransaction()`                        | -       | int     | get max amount per transaction                           | Yes           |
| `getEstimatedBuyReceiveAmount(int  amount)`  | int     | int     | Returns the amount of trading token to receive           | Yes           |
| `getEstimatedSellReceiveAmount(int  amount)` | int     | int     | Returns the amount of base token to receive              | Yes           |
| `pendingFeeEarn(address owner)`              | address | int     | Return amount of UP token the user can claim             | No            |
| `getMaxRatio()`                              | -       | int     | %Max amount per trade                                    | Yes           |
| `getSTATE()`                                 | -       | int     | If the pair is open for trading:\[0 - close , 1 - open]  | Yes           |
| `getSeedBuyRate()`                           | -       | uint256 | Rebates %\[Out of 100000]                                | Yes           |
| `getFEE()`                                   | -       | int     | %FEE for the pair\[Out of 100000]                        | Yes           |
| `totalSupply()`                              | -       | int     | Return Total Supply of liquidity token                   | No            |
| `balanceOf(address owner)`                   | address | int     | Return user liquidity balance                            | No            |
| `creditOf(address owner)`                    | address | int     | Return user ICX deposited into contract to add liquidity | No            |
| `name()`                                     | -       | string  | Return Liquidity name Symbol                             | No            |
| `symbol()`                                   | -       | string  | Return Liquidity Token Symbol                            | No            |
| `decimals()`                                 | -       | int     | Return Liquidity Token Decimals                          | No            |

### &#x20;Write API

| Method name      | Param   | Return | Payable | Description                                                                                                                                              |                                                                       |
| ---------------- | ------- | ------ | ------- | -------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------- |
| `Buy`            | address | int    | Yes     | When a user  buys a trading token.Example UP/ICX, a user would like to BUY UP using 1 ICX param would be user account address, call value would be 1 ICX |                                                                       |
| `addCredit`      | int     | -      | Yes     | Deposit ICX in order to add liquidity                                                                                                                    |                                                                       |
| `withdrawCredit` | -       | -      | No      | Contract will return users all of ICX user credit                                                                                                        |                                                                       |
| `WithdrawSupply` | int     | -      | No      | Liquidity providers to withdraw their liquidity                                                                                                          |                                                                       |
| `ClaimFee`       | -       | int    | -       | No                                                                                                                                                       | Liquidity providers to claim the UP fees earn from the smart contract |

Transfer trading token through token fall back function.Pack bytes in \_data field.

| \_data | Method name | Purpose                    | Param | Return | Payable | Description                                                                                                                                                                                                         |
| ------ | ----------- | -------------------------- | ----- | ------ | ------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| b'1'   | `transfer`  | `Trigger a sell`           | int   | -      | -       | When a user sells a trading token.Example UP/ICX, a user would like to SELL 10 UP.The webapp \*must( send an approval before executing sell function. Param would be 1e19\[Up has 18 decimals we are selling 10 UP] |
| b'4'   | `transfer`  | `Trigger a Deposit supply` | int   | -      | -       | For Liquidity Providers to deposit their tokens approval/allowance must be given before trigerring this function                                                                                                    |


# Ontology

Contract API endpoints

**Please refer to the smart contract documentation for Ontology for instructions on how to use these API endpoints with their smart contracts.**

### Contract function

## &#x20;ONT CONTRACT API

### &#x20;Call API

### &#x20;Send API

| Method name      | Param              | Return | Trade related | Description                                                                                                                                                                                                          |                                                                                                                  |
| ---------------- | ------------------ | ------ | ------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------- |
| `Buy`            | address,int amount | int    | Yes           | When a user  buys a trading token.Example UP/ONTd, a user would like to BUY UP using 1 ONTd param would be user account address, call value would be 1 ONTd                                                          |                                                                                                                  |
| `Sell`           | address,int amount | int    | Yes           | When a user sells a trading token.Example UP/ONTd, a user would like to SELL 10 UP.The webapp \*must( send an approval before executing sell function. Param would be 1e19\[Up has 18 decimals we are selling 10 UP] |                                                                                                                  |
| `DepositSupply`  | address,int amount | int    |               | No                                                                                                                                                                                                                   | For Liquidity Providers to deposit their tokens approval/allowance must be given before trigerring this function |
| `WithdrawSupply` | address,int amount | bool   | No            | Liquidity providers to withdraw their liquidity                                                                                                                                                                      |                                                                                                                  |
| `ClaimFee`       | address            | int    | No            | Liquidity providers to claim the UP fees earn from the smart contract                                                                                                                                                |                                                                                                                  |

| Method name                          | Param   | Return | Description                     | Trade related                                           |                                                |     |
| ------------------------------------ | ------- | ------ | ------------------------------- | ------------------------------------------------------- | ---------------------------------------------- | --- |
| `getPrice()`                         | -       | int    | get the curent pool state       | Yes                                                     |                                                |     |
| `getMaxTransaction()`                | -       | int    |                                 | get max amount per transaction                          | Yes                                            |     |
| `getMinTransaction()`                | -       | int    |                                 | get min amount per transaction                          | Yes                                            |     |
| `getEstimatedBuyReceiveAmount(int)`  | int     |        | int                             |                                                         | Returns the amount of trading token to receive | Yes |
| `getEstimatedSellReceiveAmount(int)` | int     |        | int                             |                                                         | Returns the amount of base token to receive    | Yes |
| `pendingFeeEarn()`                   | address | int    |                                 | Return amount of UP token the user can claim            | No                                             |     |
| `getMaxRatio()`                      | -       | int    |                                 | %Max amount per trade                                   | Yes                                            |     |
| `getSTATE()`                         | -       | int    |                                 | If the pair is open for trading:\[0 - close , 1 - open] | Yes                                            |     |
| `getSeedBuyRate()`                   | -       | int    |                                 | Rebates %\[Out of 100000]                               | Yes                                            |     |
| `getFEE()`                           | -       | int    |                                 | %FEE for the pair\[Out of 100000]                       | Yes                                            |     |
| `totalSupply()`                      | -       | int    |                                 | Return Total Supply of liquidity token                  | No                                             |     |
| `balanceOf(address owner)`           | address | int    |                                 | Return user liquidity balance                           | No                                             |     |
| `name()`                             | -       | string | Return Liquidity name Symbol    | No                                                      |                                                |     |
| `symbol()`                           | -       | string | Return Liquidity Token Symbol   | No                                                      |                                                |     |
| `decimals()`                         | -       | int    | Return Liquidity Token Decimals | No                                                      |                                                |     |


# TRON

Contract API endpoints

**Please refer to the smart contract documentation for TRON for instructions on how to use these API endpoints with their smart contracts.**

## &#x20;TRON CONTRACT API

### &#x20;Call API

| Method name                                     | Param   | Return  | Description                                             | Trade related |
| ----------------------------------------------- | ------- | ------- | ------------------------------------------------------- | ------------- |
| `getPrice()`                                    | -       | uint256 | get the curent pool state                               | Yes           |
| `getMaxTransaction()`                           | -       | uint256 | get max amount per transaction                          | Yes           |
| `getMinTransaction()`                           | -       | uint256 | get min amount per transaction                          | Yes           |
| `getEstimatedBuyReceiveAmount(uint256 amount)`  | uint256 | uint256 | Returns the amount of trading token to receive          | Yes           |
| `getEstimatedSellReceiveAmount(uint256 amount)` | uint256 | uint256 | Returns the amount of base token to receive             | Yes           |
| `pendingFeeEarn()`                              | -       | uint256 | Return amount of UP token the user can claim            | No            |
| `getMaxRatio()`                                 | -       | uint256 | %Max amount per trade                                   | Yes           |
| `getSTATE()`                                    | -       | uint256 | If the pair is open for trading:\[0 - close , 1 - open] | Yes           |
| `getSeedBuyRate()`                              | -       | uint256 | Rebates %\[Out of 100000]                               | Yes           |
| `getFEE()`                                      | -       | uint256 | %FEE for the pair\[Out of 100000]                       | Yes           |
| `totalSupply()`                                 | -       | uint256 | Return Total Supply of liquidity token                  | No            |
| `balanceOf(address owner)`                      | address | uint256 | Return user liquidity balance                           | No            |
| `name()`                                        | -       | string  | Return Liquidity name Symbol                            | No            |
| `symbol()`                                      | -       | string  | Return Liquidity Token Symbol                           | No            |
| `decimals()`                                    | -       | uint28  | Return Liquidity Token Decimals                         | No            |

### &#x20;Send API

| Method name      | Param   | Return  | Payable | Description                                                                                                                                                                                                         |                                                                       |
| ---------------- | ------- | ------- | ------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------- |
| `Buy`            | address | uint256 | Yes     | When a user  buys a trading token.Example UP/TRX, a user would like to BUY UP using 1 TRX param would be user account address, call value would be 1 TRX                                                            |                                                                       |
| `Sell`           | uint256 | uint256 | No      | When a user sells a trading token.Example UP/TRX, a user would like to SELL 10 UP.The webapp \*must( send an approval before executing sell function. Param would be 1e19\[Up has 18 decimals we are selling 10 UP] |                                                                       |
| `DepositSupply`  | -       | uint256 | Yes     | For Liquidity Providers to deposit their tokens approval/allowance must be given before trigerring this function                                                                                                    |                                                                       |
| `WithdrawSupply` | uint256 | bool    | No      | False                                                                                                                                                                                                               | Liquidity providers to withdraw their liquidity                       |
| `ClaimFee`       | -       | uint256 | -       | No                                                                                                                                                                                                                  | Liquidity providers to claim the UP fees earn from the smart contract |


