Understanding Liquidity and Liquidity pools

Istari Vision
8 min readMay 19, 2021

--

In our previous article where we explained how AMMs work, we touched on the 3 major components of this system:

  • The body — limits of the liquidity pool
  • The rods — liquidity providers
  • The beads — liquidity

Today we will go more in-depth with respect to the Liquidity aspect and with special focus on the Liquidity pools.

Liquidity Pools — Open Finance

As you may recall liquidity pools are a shared pot of tokens locked in by the users and the price is determined by a mathematical formula. That formula is usually a very simple one, that was originally created by Uniswap: X * Y = K

This simple yet effective way of keeping track of moving liquidity within the actual pool was the backbone of the nascent DeFi industry we see today. In essence it allowed anyone to create a Token1/Token2 pair and set a starting price by supplying the respective tokens in equal values (not amounts).

The LPs and liquidity mechanics

Liquidity Providers (LPs) are the main driving forces behind an Automated Market Maker (AMM) DEX, as they are the ones that provide both tokens (and in some cases up to 8 different tokens) for the shared liquidity pool so that users can trade against them and get rewarded with the fees that users pay for trading.

Another innovation is in how the AMM keeps track of each individual LP tokens, by offering them a LP token that represents a share of the total liquidity in that pool. Because the liquidity is fungible (all the tokens in the pool are the same regardless of where they come from) the LPs can keep track and later withdraw their tokens along with the rewards from the pool.

So as we established that a LP locks tokens into the AMM DEX smart contract and receives LP tokens to keep track of those tokens, we can focus on how the actual liquidity moves within an AMM DEX and how the price mechanics work.

As the tokens are locked inside the AMM smart contract, they are usually split evenly on the trading pair, meaning a Token1/Token2 pair for example has 50/50 weights. This doesn’t translate necessarily into the fact that the respective tokens need to have the same exact supply number locked into the pair, but they need to have equal value or else the LPs can suffer from an arbitrage, where a third party can come with either Token1 or Token2 bought on other markets and adjust the imbalance in either tokens amounts.

When someone trades on an AMM, say they want to buy Token1 with Token2, they remove the respective quantity they wish to purchase of Token1 from the pool and they add the quantity of Token2 that needs to be added so that the overall value of the pool stays the same. Thus the ratio of the tokens within the liquidity pool dictates the price and in our example, the price of Token1 increases, while the price of Token2 decreases.

Visualization of a trade on an AMM

The dotted square in the graphic represents the price impact that the respective supply modification (adding Token2 and removing Token1) results in. That is known also as slippage, which is displayed frequently in % to determine how much the price in a respective pair of Token1/Token2 will be moved by the trade and thus supported by the trader.

A short example

If it sounds a bit confusing, don’t worry we will take a small example to showcase how a trade usually works on an AMM.

We have a LP that starts a pair with $10 worth of Token1 and 10$ worth of Token2 and thus the pool has a current constant value of $100 worth of liquidity.

Token1 price = $0.001 and Token2 price = $0.0001 thus the user adds 10,000 Token1 and 100,000 Token2 in the respective pair to match the $10 each value.

When a user wants to trade and buy 10 Token1 from the pool, they need to add in return 100 Token2 so that the pool’s overall value stays the same. When the user does that operation it alters the price of the tokens also, as the Price of Token1 = Amount of Token2 / Amount of Token1, which in our example is: 100,100 / 9990 = 10.02002 Token2 (the initial price of Token1 before the trade = 100,000 / 10,000 = 10 Token2).

Notice that here we are measuring the prices not in $ but in tokens, relative to each other as the respective pair only keeps track of the overall liquidity, not the $ price itself. To calculate the $ prices we simply take the initial values and multiply by them:

Price of Token1 before the trade = 10 Token2 = $0.001
Price of Token1 after the trade = 10.02002 Token2 = $0.001002002

A more in-depth view of price impact and slippage

The bigger the trade the larger the liquidity engaged, thus creating a bigger price impact for the user.

So as more tokens get added and removed at once, the price will move in a much more steeper direction, as such a general rule is that the price impact of an order is about twice the size of that respective order relative to the pool. In other words if you want to execute a trade to buy 1% of the supply of Token1 in the Token1/Token2 pool, you will have a price impact of 2% on the respective pair. This is the main reason why having deep liquidity (large quantities of tokens locked into that pair) is important to reduce price impact.

Slippage also correlates with the price impact, as a user can set how much deviation from the price that is currently being displayed, he wants to accept. This means that if the order that is being executed doesn’t fall within a certain % range of the current price, it gets canceled. In a simple example, if a user wants to buy Token1 at the max price of $0.00105 and the current price is $0.001, he sets a slippage of 5% for his order and if the price moves above $0.00105 while his trade is being executed, the order will be canceled.

The dangers of Impermanent Loss

Impermanent loss (IL) is something that affects virtually every AMM DEX Liquidity Provider (LP), but very few know how to gauge the impact of it for their LP positions.

As we presented above, the LP’s positions are being tracked by the LP tokens, that represent a proportional share of the total liquidity of that respective pool. When LPs provide liquidity, they do so at a certain price of that respective pair, so the total value of their respective position doesn’t fluctuate leading to instances where a certain token from that pair grows more than the other and due to that, the LP incurs an opportunity loss, also known as Impermanent Loss. The loss is translated in the fact that to balance the pool, the token that grows in value compared to the other token in the pair, is being sold one for another, to keep the overall value the same and hence the LP gets a worse deal by providing liquidity to the protocol compared to just holding the two tokens in the wallet.

To understand it, we provide a simple example and we refer back to the above numbers, with the Token1 and Token2 that are being locked into the pair, with 10,000 Token1 and 100,000 Token2 totally in that pool. The prices are just as before, Token1 price = $0.001 and Token2 price = $0.0001.

A user John locks has locked into that pair 100 Token1 with a market value of $0.1 and 1000 Token2 with a market value of $0.1 and thus has 0.1% of the total liquidity of the pool.

Now let’s take the scenario where Token2 increases in price by 2x to $0.0002, in this case as we know that the ratio of the pool doesn’t change, there still needs to be 1,000,000,000 liquidity in there (10,000 * 100,000), the amounts from each token have changed to reflect the price increase of Token2. So now we have 14,142.13562373 Token1 and 70,710.67811865 Token2, which amount to 1,000,000,000 total liquidity (14,142.13562373 * 70,710.67811865).

Possible evolution of the two token prices in this scenario

John decides to withdraw his liquidity from the AMM and from his action, he will receive, 141.421356 Token1 with a market value of $0.141421 and 707.106781 with a market value of $0.141421, totaling $0.282842 worth of tokens. If he would have just hold the tokens, he would have had 100 Token1 with a market value of $0.1 and 1000 Token2 with a market value of $0.2 (after the 2x price increase), thus having $0.3 worth of tokens, ending up much better than being a LP.

A small note here, we didn’t include any gas and AMM DEX fees, which change the calculations a bit, as especially for LPs the main reason why they provide liquidity is to get the trading fees rewards.

As a general rule to consider here when you think about Impermanent Loss, the scenario when a token grows and the other in the pair stagnates in value, we have the following breakdown of IL:

  • 1.25x price change = 0.6% loss
  • 1.50x price change = 2.0% loss
  • 1.75x price change = 3.8% loss
  • 2x price change = 5.7% loss
  • 3x price change = 13.4% loss
  • 4x price change = 20.0% loss
  • 5x price change = 25.5% loss

As such to put it shortly, the two scenarios for LPs are the following:

  1. The good one, where token prices fluctuate around the same price or increase/decrease at the same rate.
The situations favorable to LPs

2. The bad one, where token prices fluctuate and deviate from each other and the initial price or one fluctuates around the initial price level, while one deviates.

The situations unfavorable to LPs

Conclusion

The AMM concept introduced a whole new vertical for the decentralized financial world and opened the space to anyone to become a market maker on their own with the help of a clever Liquidity managing system. As such the new Liquidity providers can benefit from their holdings by locking their tokens into a pool to be used as liquidity for other participants to trade against.

While the concept in theory is simple, it comes with complex mathematical models behind and thus is subject to various risks, such as the one we highlighted about Impermanent Loss. As such most of the LPs are incentivized with other methods such the one we are seeing in the Maiar.exchange, with the MEX token.

By providing these carefully designed incentives, such as governance tokens, liquidity providing can further evolve into more novel concepts and can form new building blocks for the DeFi industry.

We at Istari are looking forward to the novel concepts that will be brought by the Maiar.exchange and we will be looking to lay a few of our own building blocks on top of it.

For more information, please visit us:

--

--