Genesis Of Liquidity Pool

Genesis Of Liquidity Pool

Liquidity Pool Overview

The word crypto has evolved over time. Some years ago, the word referred primarily to bitcoin, but with the induction of various digital assets, the word became just a shorthand for cryptocurrency. As we know, cryptocurrency is a digital asset that works as a medium of exchange that is not dependent on a centralized entity. Cryptocurrencies opened a new world for decentralization for us. With the prominence of cryptocurrencies in recent years, there has been the establishment of cryptocurrency exchanges like Binance, OKX, and FTX. Cryptocurrency exchanges allow holders of a crypto to exchange it for another crypto. Exchanges can be divided into Decentralized exchanges (DEX) and Centralized exchanges (CEX). Binance, OKX, and FTX, which I mentioned earlier, can be categorized as centralized, while Liquidswap, and Pancake are decentralized exchanges.

A liquidity pool is a reserve of tokens locked in a smart contract on a decentralized exchange (DEX). It enables traders to swap between different tokens without relying on traditional order books like CEX. Instead, trades are executed against the liquidity pool, which ensures the continuous availability of assets for trading. Liquidity pool is usually referred to as a shared pot of tokens

Liquidity Pool Tokens

When LPs (liquidity providers) add crypto to a liquidity pool, they are rewarded with LP tokens. Their portion of the total liquidity in that pool is represented by these tokens. The quantity of liquidity supplied in relation to the total amount of liquidity in the pool is proportional to the LP token reward.

For example, if you provide $100 worth of crypto to a liquidity pool with $1,000 total liquidity, you would receive 10% of the total LP tokens issued for that pool.

LP tokens serve a few important purposes:

  1. Proof of Liquidity Provision LP tokens prove that the holder has provided liquidity to a specific pool. This allows them to earn trading fees and incentives from that pool proportional to their share.

  2. Withdrawing Liquidity To withdraw liquidity from a pool, LPs(Liquidty Providers) need to send their LP tokens back to the pool's smart contract. The contract will then release their proportional share of the tokens back to them.

  3. Earning Trading Fees Most DEXs charge a small fee (usually 0.25% or less) on each trade. This fee is then distributed pro-rata to all LPs based on their share of the pool represented by LP tokens.

  4. Earning Liquidity Mining Rewards Some DEXs and DeFi protocols distribute additional rewards (native tokens) to LPs as an incentive for providing liquidity. These liquidity mining programs aim to bootstrap liquidity.

Calculation of Liquidity

Generally, a liquidity pool allows users to supply liquidity, remove liquidity and swap cryptocurrencies. The liquidity of a pool is determined by the total value of tokens deposited into the pool. I might get a bit technical at this stage but I will do my best to make it easier for non-developers.

1. Constant Product Formula (AMM Magic):

An Automated Market maker (AMM) is a protocol that runs on decentralized exchanges (DEX), that takes away the order book that exists on traditional exchanges, where liquidity is provided by buyer and seller orders, and replaces it with liquidity pools, a shared pot of tokens.

Typically, a liquidity pool is made up of two different crypto that are part of a specific trading pair like ETH/USDT, APT/USDT, APT/GUI, GUI/CAKE. A constant product is generated using the formula

A * B = k

A is the amount of crypto in the trading pair

B is the amount of the other crypto in the trading pair

k is a constant

The purpose of the constant is to allow the total liquidity to be constant across activities in the pool, like swapping crypto, removing liquidity. We are going to be going a bit higher in our math.

When liquidity is supplied, two cryptos are deposited into the liquidity pool. There is an increase of in the crypto reserve in the liquidity pool and the opposite happens when liquidity is removed.

Across these actions, the k is constant, making the liquidity at equilibrium at every given point in time. One of the key features of liquidity pool in DEX is the ability to provide the same swapping opportunities available to one CEX while still upholding core decentralization principles. When a user makes a swap in DEX, an amount of a crypto is deposited into the pool (we’ll call this amount ΔA) in exchange for an amount of another crypto in the pool (we’ll call this amount ΔB).

(A + ΔA) * (B - ΔB) = k

A*B = (A + ΔA) * (B - ΔB)

Let me put that to better context. If the liquidity pool contains 1000 coins of asset A and 1000 coins of asset B, and a user wants to swap 100 coins of asset A for asset B, then the constant product formula is:

A * B = k

1000 * 1000 = 1000000

k = 1000000

To make the swap, we use the following equation

(A+ΔA)*(B-ΔB)= k

(1000 + 100) * (1000 - ΔB) = 1000000

We can resolve ΔB using some algebraic knowledge,

ΔB = ~90.909

This means that if a user deposits 100 of a crypto A, the user will get 90.909 of a crypto B. Let me show you something cool about the entire math, if you resolve the current amount of crypto A in the liquidity pool multiplied by the current amount of crypto B in the liquidity pool, the k remains unchanged, that is why I said it the liquidity pool is in a state of equilibrium.

Let me bring that into better context for you

Current amount of A = 1000 + 100 = 1100

Current amount of B = 1000 - 90.909 = 909.091

To get the k, let’s refer to our equation

A * B = k

1100 * 909.091 = 1000000

Liquidity Reserve and Swapping

The liquidity reserves in a pool refer to the amounts of each crypto pair that have been deposited and locked into the liquidity pool. Swaps are facilitated by the crypto tokens in the liquidity reserve.

When a user wants to swap one crypto for another, the swap is executed against the liquidity reserves in the pool. The user deposits an input crypto into the liquidity pool and gets a calculated amount of an output crypto.

The effect of the reserves on the swap is governed by the constant product formula (A * B = k) that you previously explained. As tokens are swapped, the reserves of the crypto added increase while the reserves of the crypto removed decrease, but the product of the two reserves must remain constant (k).

The size of the liquidity reserves directly affects the slippage (price impact) that a trader experiences during a swap. Larger reserves generally result in lower slippage, as the same trade size has a smaller impact on the reserve ratios.

Let me bring that into better context for you

Scenario 1: High Price Impact Causing a Bad Swap

Imagine a liquidity pool with relatively low liquidity reserves, say 100 ETH and 50,000 USDC. The constant product formula dictates that the price of ETH in this pool is around 500 USDC.

1 ETH = 50000 / 100 = 500 USDC

If a user attempts to swap a large amount, such as 50 ETH, for USDC in this pool, the fact that 50 ETH constitutes half of the liquidity ETH reserve will lead to a high price impact, resulting in a bad swap rate for the user.

Before the swap:

  • Reserves: 100 ETH and 50,000 USDC

After the 50 ETH swap:

  • Reserves: 150 ETH and (50,000 - x) USDC

  • Solving for x using the constant product formula: x = ~20,833 USDC

So, the user would only receive around 20,833 USDC for their 50 ETH, which is approximately 417 USDC per ETH (20,833 / 50). This is significantly lower than the initial price of 500 USDC per ETH due to the high price impact caused by the large trade size relative to the pool's liquidity. In this scenario, the user experiences high slippage (over 16%) and a poor swap rate because the trade size is too large for the pool's limited liquidity reserves.

Scenario 2: Low Price Impact Causing a Normal Swap

Now, consider a liquidity pool with much larger reserves, say 10,000 ETH and 5,000,000 USDC. The constant product formula indicates that the price of ETH in this pool is also around 500 USDC

1 ETH = 5,000,000 / 10, 000 = 500 USDC

If the same user tries to swap 50 ETH for USDC in this larger pool, the price impact would be minimal, resulting in a normal swap rate.

Before the swap:

  • Reserves: 10,000 ETH and 5,000,000 USDC

After the 50 ETH swap:

  • Reserves: 10,050 ETH and (5,000,000 - x) USDC

  • Solving for x using the constant product formula: x = ~24,876 USDC

In this case, the user would receive approximately 24,876 USDC for their 50 ETH, which is very close to the initial price of 500 USDC per ETH (24,876 / 50 = 497.52 USDC).

The slippage is minimal (around 0.5%) because the trade size is relatively small compared to the pool's large liquidity reserves. The user experiences a normal swap rate, close to the expected market price.

Additionally, liquidity providers are incentivized to add to pools with larger reserves, as those pools are more liquid and have lower slippage, resulting in higher trading volumes and fee income for LPs.

Effect of Liquidity Pool on Decentralization

Liquidity pools are a core component of decentralized exchanges (DEXs) and play a significant role in fostering decentralization within the cryptocurrency ecosystem. Here are some key points on how liquidity pools contribute to decentralization:

  1. Removal of Centralized Order Books Traditional centralized exchanges (CEXs) rely on order books managed by a central entity. In contrast, liquidity pools in DEXs replace order books with smart contracts, eliminating the need for a centralized authority to facilitate trades. This aligns with the core principles of decentralization and disintermediation.

  2. Permissionless and Non-Custodial Anyone can provide liquidity to pools on DEXs without permission from a central authority. Additionally, users retain full control over their assets as liquidity is supplied through non-custodial smart contracts, reducing counterparty risk.

  3. Distributed Liquidity Liquidity in DEXs is distributed across multiple liquidity pools, often spanning various DEX protocols and blockchains. This distribution of liquidity reduces the risk of a single point of failure or control, enhancing decentralization.

  4. Community-Driven Liquidity The success of liquidity pools relies on the collective efforts of the community. Users are incentivized to provide liquidity through rewards and trading fees, fostering a self-sustaining ecosystem without reliance on centralized entities.

  5. Censorship Resistance Unlike CEXs, which can potentially censor or block certain trades, DEXs and their liquidity pools operate autonomously based on predetermined smart contract rules. This makes it difficult for any single party to impose censorship or restrictions on trading activities.

  6. Transparency and Auditability The smart contracts governing liquidity pools are open-source and publicly auditable, ensuring transparency and enabling community oversight. This aligns with the principles of decentralization and trust minimization.

  7. Composability and Innovation Liquidity pools and their associated LP tokens enable composability within the DeFi ecosystem, allowing for the creation of new financial primitives and innovative protocols built on top of this decentralized liquidity infrastructure.

Conclusion

Liquidity pools are a crucial part of DeFi. They replaced the traditional order book model of exchange used by CEXs with a more decentralized model. The mathematical formula behind these pools ensures a constant supply of assets for trading. Liquidity providers are rewarded for contributing to these pools. Liquidity pools are essential for achieving the goals of decentralization - allowing anyone to participate freely, with full transparency, and without censorship. The liquidity pool is a step toward our ultimate goal of decentralization, and I can’t wait to see what happens next.

NB: Always check liquidity reserve before making a swap

References

https://www.babypips.com/crypto/glossary/automated-market-maker-amm

https://www.gemini.com/cryptopedia/amm-what-are-automated-market-makers#section-3-which-are-the-popular-am-ms

https://blog.pontem.network/liquidity-pool-mechanics-9ddaf22e7c55

I am Taiwo Ola-Balogun, a blockchain engineer exploring Aptos ecosystem. I write Move when I am not writing Javascript.