DeFi(Chain) Basics: Liquidity Mining

solros
Coinmonks
10 min readMay 3, 2022

--

In two previous posts, I have explained the basics of a DEX and some more details about the DeFiChain DEX. In particular, we have seen that is better for the ecosystem if there is more liquidity stored in a DEX pool since this makes the prices more stable. In this post, we are going to discuss where the liquidity in the pools is coming from and why you would want to provide liquidity yourself.

What is Liquidity Mining?

Liquidity Mining is one of the basic mechanisms of Decentralized Finance (DeFi). It ensures that liquidity pools contain enough liquidity by incentivizing market participants to provide liquidity. For those who provide liquidity it is also a good way to gain returns on their crypto assets.

Anyone can contribute and become a Liquidity Provider by adding liquidity to a pool. When you add liquidity, you always need to add both pool tokens at the current pool ratio. Hence adding liquidity does not shift the ratio. The same is true for withdrawing liquidity.

Let us once again consider a DEX pool where you can trade apples and oranges and assume that it contains 300 apples and 200 oranges; so the ratio of apples to oranges is 3:2. In order to add liquidity to this pool, you need to add both apples and oranges at that same ratio — for example, 60 apples and 40 oranges. After this addition, the pool contains 360 apples and 240 oranges, and you own 1/6 of the pool (or 16.67%).

What happens when the ratio shifts?

When the pool ratio shifts, so does the ratio in your share. For example, after some swaps the pooled reserves might have changed to 288 apples and 300 oranges. If you wanted to withdraw your funds now, you would get 48 apples and 50 oranges. So you would have 12 apples less and 10 oranges more than when you entered the pool. (Note that the product of your amounts remained constant: 60 · 40 = 2400 = 48 · 50)

In a sense, the liquidity providers always act as anti-cyclic buyers and sellers: They buy the token that goes down in price and sell the one that goes up.

What are liquidity tokens?

When you enter the pool, you give up your input tokens and instead receive so called liquidity tokens that certify your claim to your share of the pool.

As we have seen above, the pooled amounts change with every swap, but the product always stays constant. This fact is also reflected in the liquidity tokens: When you add A tokens on one side and B on the other, you will get

liquidity tokens. So the number of liquidity tokens depends on the product of the input amounts. (The square root is taken to adjust units and scale.)

In our example above, you would have received approximately 49 apple-orange liquidity tokens (since the square root of 60 · 40 is 48.99).
If you added 1 dBTC and 10,000 DFI to the BTC-DFI pool on DeFiChain, you would receive 100 BTC-DFI tokens.

Rewards and Commissions — What’s in it for the liquidity providers?

As we will see later, providing liquidity is not without risk. So the liquidity providers are rewarded for this service. On DeFiChain, they receive two different types of rewards:

  • The block rewards, paid in DFI:
    With every new block on the DeFiChain blockchain, a number of new DFI is minted. This number is decreasing by 1.658% every 32,690 blocks (approximately 11 days) and is distributed to different causes by fixed allocations. For example, one third of the new DFI goes to the masternode that mined the block as staking rewards, a smaller part goes into the community fund and another contingent of them is for rewarding liquidity providers. This last part is where the block rewards are coming from.
  • The commissions, paid in the two pool tokens:
    Every time someone uses the DEX pool to swap one token to the other, there is a fee of 0.2% of the input token, that is paid out to the liquidity providers. So whenever someone swaps apples to oranges, the commission for this swap will be paid out in apples. And when someone swaps oranges to apples, the commission will be paid in oranges.

The rewards and commissions are then distributed among the liquidity providers according to their share of the pool. In the above example, since you own 1/6 of the pool, you would receive 1/6 of all rewards and commissions from this pool.

At the time of writing, the block rewards make up the the bigger part by far (most of the time), but with the block rewards continuously going down and the usage of the DEX increasing, this might flip at some point in the future. From time to time this has already happened now. For example when new pools are created and do not yet get block rewards — or when there are huge moves in a pool, the commissions can already be substantial.

What are the risks?

There are a few risks associated with providing liquidity:

  • The platform risk: This is a kind of risk that have with every investment. In this case, it includes the risk of bugs or hacks and the project risk. (Crypto and the DeFiChain project in particular are still quite young. The whole ecosystem could go down for some unforeseeable reason and render your investment worthless.)
  • The price risk: If the tokens that you added to the pool loose value, of course the value of your portfolio also goes down.
    In the most extreme case, if one token goes to 0, you will loose everything: Remember that the two sides of the pool always have the same value, but if one token and hence the value on that one side goes to zero, so does the value on the other side. By the constant product formula, the product of the amounts of both sides stays constant. Thus, in this extreme case, you would have a gigantic number of (pretty much worthless) type A tokens on the one side and an infinitesimally small amount of type B tokens on the other. So if in our example, the price of apples goes to 0, you will also loose your oranges.
  • The risk of impermanent loss: The infamous impermanent loss (or IL) is a type of risk that is specific to liquidity mining. Impermanent loss means the following: When the pool ratio shifts (in any direction), the value of your funds after providing liquidity will always be less than if you had hodled.

What is Impermanent Loss?

Let us go back to our pool with 360 apples and 240 oranges. Assume that after a while the pool ratio has been shifted, so that there are now 300 apples and 288 oranges. So the price of an apple has increased from 2/3 oranges to 0.96 oranges. Likewise the price of an orange has gone down. If you now decide to withdraw your liquidity, you would get 1/6 of the pool: 50 apples and 48 oranges. (Note that the product of the two amounts is the same as when you added your tokens.) So you have lost 10 apples and gained 8 oranges. But what would this mean for the value of your investment?

Assume that when you entered the pool, the price of one apple was 40 Cents and the price of one orange 60 Cents. (Note that the value is 300 · 0.4 = 200 · 0.6 = 120 on both sides.) Also assume that when you leave the pool, the price of one apple has gone up to 96 Cents and hence the price of an orange has gone to 100 Cents.

So the value of your assets has increased from 60 · 0.4 + 40 · 0.6 = 24 + 24 = 48 to 50 · 0.96 + 48 · 1 = 48 + 48 = 96 — by a factor of two! Awesome, right? But what if you had simply hodled your fruits instead of liquidity mining? In that case, you would still have 60 apples and 40 oranges with a total value of 60 · 0.96 + 40 · 1 = 57.6 + 40 = 97.6, which would be even more.

This difference between the actual value of your assets after liquidity mining and the value if had instead hodled them is called the Impermanent Loss or Diversion Loss. In this case, with a relative price change of 44%, the IL is about 1.64% (since 96/97.6 ≈ 0.9836 = 1–0.0164). As long as the rewards that you received are higher than this, everything should be fine.

There are a few things to take note of:

  • It is important that the impermanent loss is always compared to the value if hodled and not to the initial value. When the prices go down, you have price loss in addition to IL. Conversely, we still benefit from growing prices with tokens in the pool, but our gains are reduced by the IL.
  • For the height of the impermanent loss (in percent) only the relative price change between the two tokens (i.e., the change in the ratio of the two amounts) matters. In the example, we denoted both tokens in Cents, but this was purely for making the example more concrete and hopefully easier to follow. In fact, the absolute prices are irrelevant.
  • For small price changes, the impermanent loss is negligible, but — as we have seen above — in the most extreme case, where one token goes to 0, it can be up to 100%. Here are some numbers to get a feeling for how big the impermanent loss is; you can also use an Impermanent Loss Calculator to get the exact numbers for your pool:

There is a lot more to say about impermanent loss, but for the sake of conciseness, I will leave it at that for now and dedicate this a separate post in the future.

What about unbalanced pools?

As we have seen in a previous post, the ratio of a pool and hence the prices of the tokens in the pool shift with every swap. Sometimes a pool ratio gets shifted quite far away from what you would consider the “real” or “correct” price. In this case, the pool becomes unbalanced. Of course, this may be subjective, but often there are outside sources that help determine that “correct” price.

When a token is traded on at least two different exchanges — for example, a DEX and a centralized exchange — you can compare the different prices.

The same is true if there is some other kind of reference price for the token: The DeFiChain stock tokens are (until now) only traded on the DeFiChain DEX (so there is effectively only one price and no way to arbitrage with a different exchange), but there is the oracle price, that reflects the price of the “real” asset the stock token is based on.

I would consider pools like the BTC-DFI, ETH-DFI, or USDC-DFI on DeFiChain balanced if the DEX price of its tokens is close enough to the price on the centralized exchanges. For the stock token pools, this is more difficult since (at least up until now) they usually trade at a premium compared to the oracle prices.

When is a good time to add or withdraw liquidity?

When you want to add liquidity to a pool, it is best to wait for a moment when the pool is balanced. Otherwise there will be some diversion loss when the pool moves back to a balanced state. However, you don’t have to worry about that when withdrawing liquidity. In this case, it is actually beneficial when a pool is temporarily off-balance.

On DeFiChain, there is usually extreme volatility in new pools right after they are created and the pooled liquidity is still very low. So you need to be extra careful when adding liquidity in such situations that the pool is balanced.

From our brief discussion of impermanent loss it should be clear that adding liquidity to an unbalanced pool will lead to IL.

However, let me give an example to back up my claim that it is a good idea to withdraw liquidity when the pool is off-balance. Imagine that you added 1 GLD and 200 DUSD to the GLD-DUSD pool on DeFiChain and also assume that 200 DUSD is the “right” price for one GLD at the current time. Since the GLD-DUSD pool is rather small compared to some of the others, a huge swap can easily shift it. Assume someone sells a huge amount of GLD shifting the price to only 150 DUSD for one GLD. If you withdrew your liquidity at that moment, you would receive 173.21 DUSD and 1.15 GLD. However, since the pool was only temporarily off-balance, it is likely to move back to the right price of 200 DUSD quickly since people will jump at the opportunity to buy GLD cheaply. Once the price is back to 200 DUSD, you can swap your additional 0.15 GLD to 29.88 DUSD (this is after subtracting 0.4% swap fees but ignoring slippage since the amount is very small compared to the pool size). So you will have 1 GLD and 173.21 + 29.88 = 203.09 DUSD, a 0.75% gain on your original 200 DUSD and 1 GLD.
A word of warning though: I don’t think it makes sense to use this as an arbitrage strategy since it is not without risk. (You cannot be sure that the pool shift is temporary and that it will move back. After all, there might be a fundamental reason for the price change that you are not yet aware of.) This example should rather demonstrate that you don’t have to worry about off-balance pools when withdrawing liquidity in the same way you have to when adding it. Also note that if you happened to withdraw while the pool is off-balance, it is important that you wait for the pool ratio to return to its “right” price before swapping anything back.

Join Coinmonks Telegram Channel and Youtube Channel learn about crypto trading and investing

Also, Read

--

--

solros
Coinmonks

Mathematician with a passion for optimization, Python, and blockchain. Likes to teach technical things since that’s the best way to learn them yourself.