liquidity pools – Finematics https://finematics.com decentralized finance education Fri, 21 Aug 2020 16:39:34 +0000 en-GB hourly 1 https://wordpress.org/?v=5.8.1 https://finematics.com/wp-content/uploads/2017/09/cropped-favicon-32x32.png liquidity pools – Finematics https://finematics.com 32 32 What is Impermanent Loss? DEFI Explained https://finematics.com/impermanent-loss-explained/?utm_source=rss&utm_medium=rss&utm_campaign=impermanent-loss-explained&utm_source=rss&utm_medium=rss&utm_campaign=impermanent-loss-explained https://finematics.com/impermanent-loss-explained/#respond Fri, 21 Aug 2020 16:39:33 +0000 https://finematics.com/?p=896

Impermanent Loss

Have you ever provided liquidity to a liquidity pool just to realise that some of your coins have gone missing? In this article, we’ll learn what “impermanent loss” is and how it can affect liquidity providers’ profits.

In essence, impermanent loss is a temporary loss of funds occurring when providing liquidity. It’s very often explained as a difference between holding an asset versus providing liquidity in that asset. Impermanent loss is usually observed in standard liquidity pools where the liquidity provider (LP) has to provide both assets in a correct ratio, and one of the assets is volatile in relation to the other, for example, in a Uniswap DAI/ETH 50/50 liquidity pool.

If ETH goes up in value, the pool has to rely on arbitrageurs continually ensuring that the pool price reflects the real-world price to maintain the same value of both tokens in the pool. This basically leads to a situation where profit from the token that appreciated in value is taken away from the liquidity provider. At this point, if the LP decides to withdraw their liquidity, the impermanent loss becomes permanent.

Example

The easiest way to fully understand impermanent loss is to go through a quick example.

Let’s assume an LP provides liquidity to a DAI/ETH Uniswap 50/50 pool. To supply liquidity to a 50/50 pool, the LP has to provide an equal value of both tokens to the pool.

So far, so good, the value of both tokens is the same.

The price of ETH goes up on an external venue such as Coinbase. Now Coinbase’s ETH price is $550. This is where other market participants, called arbitrageurs, come into play. An arbitrageur notices the price difference between Coinbase and Uniswap and sees that as an opportunity for arbitrage that is basically an opportunity to make a profit.

Uniswap uses a constant product market maker to maintain a correct ratio of tokens in the pool. So as more ETH is being bought from the pool, the higher the price of ETH becomes. The arbitrageur buys cheaper ETH on Uniswap until there is no more price discrepancy between the exchanges. Let’s see how much ETH the arbitrageur has to buy to make this happen.

By plugging our external (Coinbase) price into a few formulas that can be derived from the constant product market maker formula, we can see that the point where the Uniswap ETH price will be at $550 is when there are 10,488.09 DAI and 19.07 ETH in the pool. So the arbitrageur is basically able to buy 0.93 ETH in order to achieve equilibrium between Uniswap’s and Coinbase’s ETH price, costing 488.09 DAI and achieving the average price of 524.83 DAI per ETH. Bought ETH can be instantly sold for DAI or any other USD based stable coin on an external venue for $550. The arbitrageur just earned ~25USD minus the fees.

Let’s see how this affected our liquidity provider.

As we can see the LP would’ve had $23.41 more if they just held their assets without providing liquidity. That $23.41 is basically the LPs impermanent loss.

Impermanent loss is called impermanent because at this point the LP lost $23.41 only on paper. If the LP doesn’t withdraw their liquidity and the price of ETH goes back to $500, the impermanent loss is cancelled back to 0. On the other hand, if the LP decided to withdraw their liquidity, they would realise their loss of $23.41, permanently.

LPs profit

Ok, now that we understand what impermanent loss is, let’s see how it can take away LPs profit as the value of one asset increases in relation to the other.

We can see that, for example, if the price of the asset in the pool goes up by 500% the LPs would experience a 25% impermanent loss. Here is the link to the article with the chart and other useful calculations.

So if impermanent loss can take away so much profit, what is the incentive for liquidity providers to provide liquidity in the first place? To understand that, let’s see how LPs can make money on their capital.

In the perfect world with no impermanent loss, the LPs would just be collecting money from trading fees. For example when it comes to Uniswap, each trade that goes through a liquidity pool pays a 0.3% fee that is proportionally distributed to the LPs of that pool. 

This basically means that the LP can still make money even when experiencing impermanent loss under the condition that impermanent loss < collected fees.

On top of that, a lot of liquidity pools provide additional incentives for LPs by offering liquidity mining programs. Liquidity mining, in essence, is a way of rewarding LPs with extra tokens for providing liquidity to certain pools or using a protocol. The value of the additional tokens in some cases can completely negate the value lost by impermanent loss, making providing liquidity highly lucrative. If you want to learn more about yield farming and liquidity mining you can check out this article.

Other Pools

So, how about providing liquidity to other pools outside of Uniswap? Would that also result in impermanent loss? Let’s see a few examples. 

Curve pools, for instance, only contain assets that should hold similar if not the same value. 

These could be different stable coins like USDC and DAI or different flavours of the same token such as sBTC, renBTC and wBTC. The risk of impermanent loss in such pools is greatly minimised as there is no asset in the pool whose value is volatile in relation to the other. This is also why Curve’s liquidity pools, or to be more generic, all the liquidity pools that hold stable assets usually attract way more capital than the pool with non-stable assets. 

Another example is Balancer that offers pools with arbitrary weights outside of the standard 50/50 weighted model. This means that, for example, if an LP wants to maintain a high exposure to a certain asset they can participate in a pool where one token has much higher weight than the other one such as 80/20 or even 98/2 pool. This can also reduce the impact of impermanent loss depending on the weights in the pool. The higher the weight of a token in the pool, the lesser the difference between holding the token and providing liquidity in the token becomes.

Another way of fighting with impermanent loss was recently introduced by Bancor. Bancor V2 pools can adjust their weights automatically based on the external prices coming from price oracles. This can completely mitigate impermanent loss even in the pools with volatile assets. You can learn more about Bancor V2 in this article

So have you ever been affected by impermanent loss? And what is your favourite strategy to deal with it? Comment down below.

If you enjoyed reading this article you can also check out Finematics on Youtube and Twitter.

]]>
https://finematics.com/impermanent-loss-explained/feed/ 0
How Do Liquidity Pools Work? DeFi Explained https://finematics.com/liquidity-pools-explained/?utm_source=rss&utm_medium=rss&utm_campaign=liquidity-pools-explained&utm_source=rss&utm_medium=rss&utm_campaign=liquidity-pools-explained https://finematics.com/liquidity-pools-explained/#respond Mon, 20 Jul 2020 11:41:54 +0000 https://finematics.com/?p=771

Intro

What are Liquidity Pools? How do they work? And why do we even need them in decentralized finance? Also, what are the differences between liquidity pools across different protocols such as Uniswap, Balancer or Curve? We’ll be going through all of this in this article.

Before we start, if you’re new to DeFi you may want to read my introduction to decentralized finance article first. Also, you may want to subscribe to Finematics on Youtube.

Liquidity Pools

Liquidity pools, in essence, are pools of tokens that are locked in a smart contract. They are used to facilitate trading by providing liquidity and are extensively used by some of the decentralized exchanges a.k.a DEXes.

One of the first projects that introduced liquidity pools was Bancor, but they became widely popularised by Uniswap.

Before we explain how liquidity pools work under the hood and what automated market making is, let’s try to understand why we even need them in the first place.

Why Do We Need Liquidity Pools?

If you’re familiar with any standard crypto exchanges like Coinbase or Binance you may have seen that their trading is based on the order book model. This is also the way traditional stock exchanges such as NYSE or Nasdaq work.

In this order book model buyers and sellers come together and place their orders. Buyers a.k.a. “bidders” try to buy a certain asset for the lowest price possible whereas sellers try to sell the same asset for as high as possible.

For trades to happen, both buyers and sellers have to converge on the price. This can happen by either a buyer bidding higher or a seller lowering their price.

But what if there is no one willing to place their orders at a fair price level? What if there are not enough coins that you want to buy? This is where market makers come to play.

In essence, market makers are entities that facilitate trading by always willing to buy or sell a particular asset. By doing that they provide liquidity, so the users can always trade and they don’t have to wait for another counterparty to show up.

Okay, so why can’t we just reproduce something like this in decentralized finance?

The answer is – we can! It would just be really slow, expensive and pretty much always result in poor user experience.

The main reason for this is the fact that the order book model relies heavily on having a market maker or multiple market makers willing to always “make the market” in a certain asset. Without market makers, an exchange becomes instantly illiquid and it’s pretty much unusable for normal users. On top of that, market makers usually track the current price of an asset by constantly changing their prices which results in a huge number of orders and order cancellations that are being sent to an exchange.

Ethereum with a current throughput of around 12-15 transactions per second and a block time between 10-19 seconds is not really a viable option for an order book exchange. On top of that, every interaction with a smart contract cost a gas fee, so market makers would go bankrupt by just updating their orders.

How about the 2nd layer scaling then? Some of the 2nd layer scaling projects like Loopring look promising, but even they are still dependant on market makers and they can face liquidity issues. On top of that, if a user wants to make only a single trade they would have to move their funds in and out of the 2nd layer which adds 2 extra steps to their process.

This is exactly why there was a need to invent something new that can work well in the decentralized world and this is where liquidity pools come to play.

How Do Liquidity Pools Work?

Ok, so now that we understand why we need liquidity pools in decentralized finance, let’s see how they actually work.

In its basic form, a single liquidity pool holds 2 tokens and each pool creates a new market for that particular pair of tokens. DAI/ETH can be a good example of a popular liquidity pool on Uniswap.

When a new pool is created, the first liquidity provider is the one that sets the initial price of the assets in the pool. The liquidity provider is incentivised to supply an equal value of both tokens to the pool. If the initial price of the tokens in the pool diverges from the current global market price, it creates an instant arbitrage opportunity that can result in lost capital for the liquidity provider. This concept of supplying tokens in a correct ratio remains the same for all the other liquidity providers that are willing to add more funds to the pool later.

When liquidity is supplied to a pool, the liquidity provider (LP) receives special tokens called LP tokens in proportion to how much liquidity they supplied to the pool. When a trade is facilitated by the pool a 0.3% fee is proportionally distributed amongst all the LP token holders. If the liquidity provider wants to get their underlying liquidity back, plus any accrued fees, they must burn their LP tokens.

Each token swap that a liquidity pool facilitates results in a price adjustment according to a deterministic pricing algorithm. This mechanism is also called an automated market maker (AMM) and liquidity pools across different protocols may use a slightly different algorithm.

Basic liquidity pools such as those used by Uniswap use a constant product market maker algorithm that makes sure that the product of the quantities of the 2 supplied tokens always remains the same. On top of that, because of the algorithm, a pool can always provide liquidity, no matter how large a trade is. The main reason for this is that the algorithm asymptotically increases the price of the token as the desired quantity increases. The math behind the constant product market maker is pretty interesting, but to make sure this article is not too long, I’ll save it for another time.

The main takeaway here is that the ratio of the tokens in the pool dictates the price, so if someone, let’s say, buys ETH from a DAI/ETH pool they reduce the supply of ETH and add the supply of DAI which results in an increase in the price of ETH and a decrease in the price of DAI. How much the price moves depends on the size of the trade, in proportion to the size of the pool. The bigger the pool is in comparison to a trade, the lesser the price impact a.k.a slippage occurs, so large pools can accommodate bigger trades without moving the price too much.

Because larger liquidity pools create less slippage and result in a better trading experience, some protocols like Balancer started incentivising liquidity providers with extra tokens for supplying liquidity to certain pools. This process is called liquidity mining and we talked about it in our Yield Farming article.

The concepts behind liquidity pools and automated market making are quite simple yet extremely powerful as we don’t have to have a centralized order book anymore and we don’t have to rely on external market makers to constantly keep providing liquidity to an exchange.

Different Types of Liquidity Pools

The liquidity pools that we just described are used by Uniswap and they are the most basic forms of liquidity pools. Other projects iterated on this concept and came up with a few interesting ideas.

Curve, for example, realised that the automated market making mechanism behind Uniswap doesn’t work very well for assets that should have a very similar price, such as stable coins or different flavours of the same coin, like wETH and sETH. Curve pools, by implementing a slightly different algorithm, are able to offer lower fees and lower slippage when exchanging these tokens.

The other idea for different liquidity pools came from Balancer that realised that we don’t have to limit ourselves to having only 2 assets in a pool and in fact Balancer allows for as many as 8 tokens in a single liquidity pool.

Risks

And of course, like with everything in DeFi we have to remember about potential risks. Besides our standard DeFi risks like smart contract bugs, admin keys and systemic risks, we have to add 2 new ones – impermanent loss and liquidity pool hacks – more on these in the next articles.

Summary

So what do you think about liquidity pools? And as always, don’t forget to subscribe to Finematics on Youtube for more DeFi content.

]]>
https://finematics.com/liquidity-pools-explained/feed/ 0