Skip to content

What is DEX Liquidity?

Published:  at  05:00 PM

The Basics

  • DEX liquidity works using the constant-product principle
  • It ensures that the product of the two assets, usually denoted kk, is constant
  • When one asset (asset A) is sold for another (asset B), the price of A goes down while the price of asset B goes up
  • No tokens are created, they’re given from and deposited into the liquidity pool.


  • The more assets deposited in the pool, the less a trade changes the price - If you keep on trading, eventually the token you deposit will be worth essentially 0 and the token you’re swapping to will be worth essentially infinite.


  • The ratio between the tokens is expressed as the following formula: a×b=ka \times b = k
  • The more tokens you put in, the more stable the pool is
  • If you have a new token, you can’t “earn” any additional money by providing liquidity and then swapping

If you’re at all active in the Ethereum space, chances are you’ve come across decentralized exchanges (DEXs) like Uniswap. And if you’re a visitor of my blog, you’ve likely even tried your hand at creating a few.

If you have, you might notice that tokens don’t have any built-in way of swapping themselves. The token standard that most people talk about is called ERC-20, which defines a standard interface for all tokens to follow. A large majority of tokens use it, including tokens such as Tether (USDT), Wrapped Ether (WETH), and even tokens on other chains.

However, this interface doesn’t cover anything related to making token trades. In fact, there isn’t even any notion of price. This is where the need for decentralized exchanges (DEX’s) come from.

In this mini-series, I will be mainly focusing on Uniswap. This is the platform most dominantly used on Ethereum (to my knowledge), and the PancakeSwap project is a fork of Uniswap that handles a majority of all liquidity on the Binance Smart Chain. In other words, it’s pretty important.


Uniswap has implemented a concept known as liquidity. The liquidity of a token refers to how easily you can trade a token without affecting its price.

Uniswap allows you to deposit two tokens, which are deposited into a smart contract known as a pool. A combination of the two tokens deposited into the pool is called a pair, represented by the token symbols. For example, a WETH/USDC pair contains the WETH and USDC tokens.

When you swap from one token to the other, what you’re really doing is putting in one token and getting another. For example, if you trade 1 WETH to 1000 USDC, then you’re depositing 1 WETH into the liquidity contract and getting 1000 USDC (minus fees) in exchange. There is no magic token creation, just a simple transfer of tokens from the liquidity pool.


Imagine you put 1 WETH into the liquidity pool. How does Uniswap know how much USDC you should get? This calculation is elegantly simple. Because the pool represents how much of each token are available, it also naturally forms a ratio representing the price.

The ratio between the tokens is expressed as the following formula:

a×b=ka \times b = k

Here, aa and bb are the amounts of each token, and kk is a constant that stays constant even when you swap.

Let’s use the following example: there are 15 ETH and 15,000 USDC in a pool. This makes the constant kk equal to 15×15,00015 \times 15{\small,}000, which is 225,000225{\small,}000.

Now, let’s say that someone swapped one ETH for USDC. We need to keep k=225,000k = 225{\small,}000, so we can calculate that the user would get 937.50937.50 USDC (as (15+1)×(15,000937.50)=225,000(15 + 1) \times (15{\small,}000 - 937.50) = 225{\small,}000).

If this pattern continues, with people swapping ETH for USDC, the amount they would get would slowly decrease. However, this process isn’t linear; for each ETH they deposit into the pool, the USDC that gets removed decreases, making it so eventually ETH would be barely worth anything, making USDC relatively more valuable. This price difference incentivizes traders to buy the “cheaper” ETH using their USDC, naturally rebalancing the pool

Now, you may have noticed that the more tokens you put in, the more stable the pool is. Let’s say that Elon Musk himself puts in a lot of tokens, such that the pool now has a thousand times the original amount, with 15,00015{\small,}000 ETH and 15,000,00015{\small,}000{\small,}000 USDC.

When the same user swaps their 1 ETH, the price wouldn’t change as much; in fact, they get more value out of their ETH, gaining 999.933999.933 USDC from their ETH.

Adding on to that, if you have a new token (say we call it GimmeMoney, with symbol GMM), you can’t “earn” any additional money by providing liquidity and then swapping. For example, if you make a new pair GMM/WETH and put in 100 GMM with 100 WETH, this technically sets the price of 1 GMM to be equal to 1 WETH.

However, you can’t mint 200 new GMM and swap it for 200 WETH; As a matter of fact, you would actually be losing both GMM and gas fees, and as the amount of GMM you swap nears infinity, the amount of WETH you get only nears the 100 WETH you put in.


Here is a small simulation I built, allowing you to, well, simulate trades with different amounts of liquidity. Play around with it!

There are 15.000000 ETH and 15000.000000 USDC in the pool.

One ETH is worth 937.500000 USDC.

One USDC is worth 0.000999933 ETH.


So, as you can see, the more of both tokens inside a liquidity pool, the more stable the price. However, what attracts folks to add tokens?

First of all, when a user swaps, there is a small fee that liquidity providers get a share of according to the amount of tokens they provide. This is usually very small (0.3% of the swapped value in the case of Uniswap), but in the case of hundreds or thousands of swaps every day, it can quickly add up.

Usually, the very first amount of liquidity is provided by the project creators. Because they want to see their token succeed, they will often put in a sizable amount (usually in the thousands or tens of thousands of dollars) to both set the price and allow users and investors to buy their token.


Liquidity is a really neat concept; it easily creates a way to perform swaps, set the price, and earn money with cryptocurrencies.

This exploration merely scratches the surface of DEX liquidity. In the next installment of this series, we’ll delve into advanced concepts like impermanent loss and different liquidity pool models. Stay tuned!