Drixx Academy/DeFi Liquidity Mining Explained: AMMs, Rewards, Risks and Math/

DeFi Liquidity Mining Explained: AMMs, Rewards, Risks and Math

Lawrence Zhou
Drixx Quant
April 5, 2021

Liquidity Mining in DeFi Explained - AMMs, Rewards, Risks and Math


DeFi liquidity mining is a form of yield farming that involves being a liquidity provider (or LP) on decentralized exchanges. Effectively, liquidity providers are acting as market makers. In exchange for assuming the risks and capital costs of being an LP, LPs are rewarded with both exchange fees and (potentially) projects-specific incentives. These rewards are effectively the “yield” (when compared to the capital outlay).

Currently, the majority of DeFi trading activity still happens on Ethereum (or EVM compatible chains). However, because of the transaction speed limitations of ETH, there is not enough capacity to support order books. Consequently, most decentralized exchanges are automated market makers (called AMMs) like Uniswap, Sushi, and Balancer.

In this article, we will look at how DeFi liquidity mining works from a user perspective. We will then go into detail on AMMs like Uniswap and Sushiswap. Finally, we will look at the math behind these AMMs.

Being an AMM Liquidity Provider (LP)

Being an AMM LP can be different depending on how the decentralized exchange is designed. However, we will primarily focus on Uniswap V2 and Sushiswap. Interested readers can refer to exchange whitepapers (such as the Balancer whitepaper: https://balancer.finance/whitepaper/) for examples of other AMM designs. Uniswap V3 (https://uniswap.org/whitepaper-v3.pdf) will also have a different design (though it will still use constant products).

In both the Uniswap and Sushiswap designs (Sushiswap being a fork of Uniswap), tradeable asset pairs have a “pool”. We can think about these pools as buckets of the two pairs of assets. For example, we might have an ETH / USDT pool. This pool, then, would have some quantity of ETH and some quantity of USDT. There are three main actions that a trader or LP can take with the pool:

Swap Assets

When a trader wants to swap one asset for another, they will deposit one asset and take out the other. For example, if you wanted to swap the ETH for USDT, you would deposit ETH into the pool (thereby increasing the quantity of ETH in the pool) and take out USDT (thereby decreasing the quantity of USDT). The quantity of USDT that you receive is determined by a pricing formula. In the case of Uniswap and Sushiswap, a “constant product” formula is used (sometimes called x * y = k). We will be talking more about this formula and AMM math in the next section.

Add Liquidity

An LP can add liquidity to the pool by adding assets in the exact same proportion as the assets in the pool. For example, if you wanted to add 10 ETH to a pool with 100 ETH and 200 USDT, you would need to pair the 10 ETH with 20 USDT. This maintains the pool ratio, since 100 / 200 = 110 / 220.

In exchange for the 10 ETH and 20 USDT that you place in the pool, you will receive UNI or SUSHI pool tokens (called LP tokens) that represents your share in the pool. Of course, the actual percentage share will vary as other LPs add and remove liquidity.

Remove Liquidity

Instead of adding liquidity, an LP can also remove liquidity from the pool. When they remove liquidity, they will exchange their UNI or SUSHI tokens for ETH and USDT. Note, though, that they might receive back different ratios of the two assets (ETH and USDT) than they had originally put in. This is because LPs assume impermanent loss risk (ie, price impact). We will talk more about this effect in the AMM math section.

The primary benefit of being an LP is receiving a cut of the fees from swaps (or trades) on the pool. For example, Uniswap v2 charges a 0.3% fixed fee for trades. This fee is effectively paid out to LPs based on their percentage share of the pool when the trade happens.

The secondary benefit of being an LP is from liquidity incentives. When a new DeFi project starts out, there is not much liquidity in the pool. This means that even swaps of small size will move the price significantly. To bootstrap liquidity (and to compensate LPs for the risk of a new token), projects will often give a fixed quantity of incentive rewards to LPs. To “prove” that you are an LP, you will need to stake your LP tokens (the ones you received from the exchange pool) with the project itself.

In general, these rewards are fixed in size and weekly.

For example, the project might reward a fixed 10,000 tokens weekly to LPs. The rewards are then given out based on your share of all staked tokens (weighted by the amount of time staked). So, if you staked 100 LP tokens, and there are 2,000 total LP tokens staked, then you would receive 5% of the 10,000 incentive tokens = 500 tokens (if you remain staked for the entire week).

Because the rewards are fixed, more new staked LPs would reduce your APY (whereas fewer participants would increase your APY). In addition, the price of the tokens themselves can affect APY (ie, higher token price means higher APY, and vice versa).

We can see an example of this kind of LP incentive from Rari Capital (with the RGT token) below. Rari gives out RGT rewards for staking your RGT-ETH LP tokens from SushiSwap. In this case, the project is offering roughly 18% APY. However, as discussed before, this figure can vary wildly depending on: the amount of LP capital in the pool (higher = less APY) and the price of the token itself (higher = higher APY). We also see that there is an end date for the incentive reward (which is common for projects).

Rari-Capital-SushiSwap-LP-Rewards.jpg Source: Rari Capital (https://app.rari.capital/pool2)

Commonly, incentivized pools of a project’s token + another asset is known as “Pool 2”. Conversely, an incentivized pool without the project token is called “Pool 1”.

The Risks of Liquidity Mining

Obviously, being an LP comes with several kinds of risk. We highlight them below:

Price Risk:

First, there is the price risk of holding 1 or 2 risky assets. If you contributed to an RGT-ETH pool, for example, you would be taking on the price volatility of two risky assets: ETH and RGT (which might move substantially vs USD). If you contributed to an ETH-USDT pool, you would still be holding 50% of your money in a risky asset.

Consequently, in projects with more than one incentivized pool, pools with 2 risky assets typically end up with a higher APY.

Impermanent Loss:

A second risk is impermanent loss (we will talk more about this effect in the next section). Effectively, like being a traditional market maker, LPs are subject to adverse selection and large one-directional moves in asset prices.

Smart Contract Risk:

A third risk is contract risk: either at the exchange or with the DeFi protocol where you have staked your LP tokens. If the DeFi exchange gets exploited, then you would lose the two tokens you contributed to the liquidity pool. If the DeFi protocol gets exploited, then you would lose your LP tokens (and consequently, your claim to tokens at the exchange).

Rug Pull / Scam:

Finally, there is always a risk of a scam / rug pull. Being a liquidity provider means that unscrupulous teams can mint an infinite number of tokens to “dump” on the liquidity pool. They could drain your valuable coins (like ETH, USDT, etc) in exchange for their worthless tokens. Now that we have a good idea about being an LP, we can go over the math surrounding AMMs.

Simple Automated Market Maker Math

<u>How AMMs Basically Work</u>

An AMM pre-defines the price and size relationship with a mathematical formula instead of an order book. Effectively, instead of relying on limit orders, it defines the “shape” of the order book via formula (see our Market Liquidity article to learn more about orderbook shape). Note, therefore, that the Limit Order Book, aka LOB, is then a generalized and unconstrained form of the AMM (since it can replicate any size to price shape).

For this article, we will only consider the 50-50 constant-product AMMs like Uniswap and Sushiswap (where most of the trading currently happens). In a pool on Uniswap, we assume that the “values” of the two tokens inside the pool are equal. For example, if there are 2 ETH and 3,000 USDT in the pool, then it is assumed that the 2 ETH equals 3,000 USDT. In other words, the price of ETH is 3000 USDT / 2 ETH = $1,500. In a constant product AMM, it is assumed that:

<div align="center"><p><b>Quantity of Asset 1 * Quantity of Asset 2 = Constant</b></p> <p>or</p> <p><b>x * y = k</b></p> </div>

In the example above: 2 * 3000 = 6000 (constant).

So how is the price / quantity related?

If you try to buy 0.5 ETH from the pool above, then the resulting quantity of ETH is 1.5 ETH. If we assume a constant product, then the resulting USDT must equal 6000 / 1.5 ETH = 4000 USDT.

This means that you receive 0.5 ETH in exchange for (4000 – 3000) = 1000 USDT.

The average price for the swap is then $2,000.

The final spot price of ETH in the pool, then, is 1.5 ETH to 4,000 USDT (or $2,666).

Now, let us tie this directly to the price impact function we talked about in the “Market Liquidity” article. If you are buying and selling ETH, what are the Pbuy and Psell functions?

AMM Pbuy and Psell functions.jpg

Where Q = the quantity traded. A = amount of token A. B = amount of token B.

Using the formula above, we can confirm that for a buy of 0.5 ETH, you would get an average price of (3000 / (2 – 0.5)) = $2,000. However, what happens when a trade goes through? We see that when the trade goes through, the spot price of one asset changes versus the other. LPs are effectively giving up the higher priced asset for the lower priced asset. This effect is called “impermanent loss”.

<u>Impermanent Loss Risk</u>

As an LP in the pool, you are effectively always adverse selected when the price of one asset moves against another. This means that you are eating the price impact whenever trades happen. Let us better illustrate this effect with an example:

Let us say that you are the owner of the entire AMM pool. What would your return be between just holding 2 ETH and 3,000 USDT versus being an LP in the pool after a 0.5 ETH buy trade happens?


As you can see, the impermanent loss here is around 4%. After a trade against the pool, you would have been better off holding the 2 ETH and 3,000 USDT instead of being an LP (by around 333 USDT).

Note, though, that if the opposite trade happens after this trade (ie, a 0.5 ETH sell), you would be better off being an LP – since the pool would return to 2 ETH and 3,000 USDT (not including fees). Therefore, LPs make money vs holding a static portfolio if the price of the two assets does not drift too much.

If we assume that the AMM-implied price (asset A / asset B) is correct, we can estimate the impact of impermanent loss by the proportional change of asset A’s price and asset B’s price:

Let M = the relative percentage change in price between asset A and asset B.

For example, let us say we had an AMM pool of ETH and BTC. If the price of ETH goes up 80% and the price of BTC does not change, then M would be 1.8. However, if the price of BTC was up also 40%. Then M would be (1 + 80%) / (1 + 40%) = 1.286.

The impermanent loss (IL) is then: Drixx impermanent loss formula.jpg

For example, we see that in the ETH and USDT example (in the previous section), the price of ETH goes from 1500 to 2667 (vs USDT). Then IL = 2 * sqrt(1.778) / (1 + 1.778) – 1 = -4%.

Drixx Impermanent Loss Graph.jpg

We end up with the following impermanent loss curve with different M ratios. Note, that impermanent loss is never positive (for any percentage change between asset A and asset B).

In Summary

DeFi liquidity mining is one of the more exciting opportunities in DeFi to earn Yield. The Drixx Yield product includes these strategies (combined with robust risk management) in generating yield for its customers. While the APYs can be high from liquidity mining, there are always risks attached – including price, impermanent loss, smart contract risk, and the possibility of scams. Now that we have a better understanding of AMMs and liquidity mining, we will be able to explore (in greater detail) yield farming math in a follow-on article.