English
May 18, 2021

# Liquidity Pools on Minter

Liquidity pools have become one of the most significant innovations to arrive with Minter 2. They make it possible to:

• Swap any coins and tokens (backed and non-reserve, global and local alike)
• Earn from providing liquidity

In this article, we use testnet. The same rules apply to the main network.

## AMM

A liquidity pool is a trading pair of coins/tokens with locked-up funds of liquidity providers that guarantee swappability. Buying or selling through a liquidity pool, a trader uses funds that have been locked into it. Unlike centralized exchanges with limit orders and order books, liquidity pools don’t require you to place an order and wait for it to be filled. The process is carried out using Automated Market Maker (AMM).

AMM automatically determines the price of a token by balancing the quantities of both tokens in a given pair. There’s a constant that’s calculated using the following formula:

`x * y = k`,

where `x` is the quantity of the first coin; `y`, quantity of the second coin; and `k`, their product. This constant represents the size of a pool and is measured in units. Take the MNT/USDM pool:

X = 160388.49 MNT

Y = 99.19 USDM

K = X * Y = 160388.49 * 99.19 = 15908934.32

This constant can’t decrease when buy/sell deals are made within a pool. On the contrary, with each swap, it increases because of the 0.2-percent fee; the size of the pool itself increases as well. The bigger the pool gets due to the fees, the bigger earnings the liquidity providers make (we’ll talk about them a bit later).

At the moment, 1 MNT costs 0.00062 USDM (Y / X, 99.19 / 160388.49). Let’s try to buy 50 USDM for MNT and see how the price and the constant will change:

In the confirmation window, we can see how many USDMs we buy, how many MNTs we sell, the route, and the fee.

So we bought 50 USDM (meaning we took it from the pool) and spent 163369.6 MNT (meaning we added it to the pool). This amount includes the pool’s fee of 0.2%, or 326.73 MNT. Once the trade has been completed, the pool’s parameters changed:

The number of coins in the pool changed along with the price (new: 1 MNT = 0.00015 USDM). Let’s check the constant by multiplying quantities of both tokens:

X = 323758.09 MNT

Y = 49.19 USDM

K = X * Y = 323758.09 * 49.19 = 15925660.45

The constant rose due to fees -> the proportion of coins changed -> so did the price.

### Formulas

First, let’s define variables:

• `X` - quantity of the first coin in the pool before trade
• `Y` - quantity of the second coin in the pool before trade
• `K` - pool’s constant before trade
• `X_new` - quantity of the first coin in the pool after trade (X - Coin0)
• `Y_new `- quantity of the second coin in the pool after trade (Y - Coin1)
• `K_new` - pool’s constant after trade
• `Coin0` - quantity of the first coin needed for trade
• `Coin1` - quantity of the second coin needed for trade
• `Fee` - 0.2%

Old price of the first coin:

`Price = Y / X`

Price of the first coin after trade:

`Price_new = Y_new / X_new`

Quantity of the first coin in the pool after trade:

`X_new = X - Coin0`

How much of the second coin `Coin1` (plus `Fee`) we need to spend in order to buy a specific amount of the first coin `Coin0`:

`Coin1 = (K / (X - Coin0) - Y) / (1 - Fee / 100)`

Quantity of the second coin in the pool after trade:

`Y_new = Coin1 + Y`

Trade fee that goes into the pool:

`Coin1 / 100 * Fee`

## Liquidity Providers

For a trader to be able to buy and sell through a pool, that pool needs to be liquid. The liquidity is supplied by LPs. But why would they do that? To get their share of the 0.2% fee that traders pay for each transaction in the pool.

Adding liquidity means giving your own funds to the pool. Thanks to those funds, traders can make transactions and AMM can control the ratio of coins and regulate the price depending on direction (buy or sell).

You can add liquidity to the pool that already exists, for example, MNT/USDM. To begin with, let’s once again look at the pool’s current parameters:

Upon liquidity addition, the proportion should always be 50% / 50%. It’s a basic rule that allows to keep the ratio at the same level with no impact on price. This means that when an LP provides liquidity, they increase the size of the pool but don’t affect the price.

To supply liquidity, go to the corresponding section in Console (Pools -> Add Liquidity):

Assume we want to add 100 000 MNT. For that, we’ll need 15.19 USDM (at a price of ≈0.00015). Once liquidity has been added, the balances of tokens in the pool have risen by 100 000 MNT and 15.19 USDM.

#### Pool Tokens

For adding liquidity to the pool, we receive pool tokens in return. These tokens serve as our receipt allowing us to get back our liquidity plus share of fees at any time.

Technically, pool tokens are denoted as P-*,

where * is a numerical identifier of the pool. For example, MNT/USDM’s pool tokens are called P-1. To see all information about such a token, head to its page in Explorer:

From a tech standpoint, it’s a non-reserve token with a CRR of 0%, which is tied to a specific pool and has its own supply.

Hint. Pool tokens can be:

• Sent to any address (the receiver will be able to withdraw liquidity from the pool)
• Added to your own pool with any other coin or token (any pool token is freely tradable on the Minter network)
Why? It’s simple: now you can trade in liquidity shares. You can buy someone’s share in a specific pool or sell yours.

In the wallet, these pool tokens look like this:

Anyone who adds liquidity gets pool tokens, it’s their liquidity share. The sum of all pool tokens is displayed on the pool’s page:

That way, we can calculate our share of pool (your portion’s contribution toward total liquidity expressed in %). You can find all LPs and view their shares on this page as well:

You may find all pools to which you supply liquidity in Console:

The last pool on the screenshot is the one where we’ve just added liquidity with a share of 23.6%.

You can claim your liquidity back using the corresponding form:

Just specify how much of liquidity you want back (in %). Here you can see the numbers of both tokens you withdraw.

Important! Because one (or both) of the tokens may experience volatility, the USD worth of the liquidity provider’s funds may decrease upon liquidity removal. This situation is known as Impermanent Loss.

Impermanent loss occurs when the value of the assets you put into a liquidity pool has changed since you deposited them. The bigger the change, the more prone you are to impermanent loss. In this case, ‘loss’ means lower dollar price compared to that at the time of the deposit.

## Creating a Liquidity Pool

There’s no pool you want to add liquidity into? Not a problem, you can create it yourself—for example, with your own MYCOIN token and USDT stablecoin. In Minter 2, we can create not only backed coins, but also non-reserve tokens:

Let’s create a MYCOIN token with an initial supply of 1 million. They will not be backed by BIP and may be additionally issued (mintable) or burned (burnable).

Because the token has no reserve, for its exchange on the Minter network, you need to create a liquidity pool with it and, for example, the USDT stablecoin.

In the corresponding menu (Pools), select both coins and their proportions, remembering that the price of the first coin = the amount of the second coin / the amount of the first coin. If we want to set the price of 1 MYCOIN at 2 USDT, we need to add 2 times more USDT than MNT when creating a pool:

1 MYCOIN = 2000 USDT / 1000 MYCOIN = 2 USDT

After creating a pool, you can check it out in Explorer:

For adding liquidity to the pool (in our case, at the moment of creation), we received pool tokens called P-38. Now, any other member of the network can become a liquidity provider in our pool. For this, they need to:

1. Buy MYCOIN (because it can only be obtained from our pool)