<100 subscribers
Share Dialog
Share Dialog
The first two articles of this series were mainly about new possibilities which can only be unlocked via Web 3. Two use cases we discussed were: Digitization of Land Records and Stock Prediction tool for Analysts. Bottomline – Web 3 dominates Web 2 in newer use cases… but can Web 3 beat Web 2 on its home turf, i.e., existing use cases? Obviously, the answer is yes, or else I would not be writing this piece. Instead of finding newer applications to prove the worthiness of Web 3, let’s see how blockchain is redefining age-old applications like exchanges.
Exchanges are a business. Every time you trade, you may or may not get rich. But with your every transaction, the exchanges are taking home cold hard cash. In case you’re wondering how… I have a GIF for you :)

Have you ever wondered how much money the exchanges make? Here’s a Twitter thread from SBF which explains the economics of Coinbase, one of the largest crypto exchanges. SBF is the founder of FTX, which itself is another leading crypto exchange and a competitor of Coinbase.
https://twitter.com/SBF_FTX/status/1426431393563873281
The last tweet of this thread is the real jaw-dropper which revealed that Coinbase generated more revenue than all the traditional exchanges.
https://twitter.com/SBF_FTX/status/1426431436484235265
It is surprising that crypto exchanges bring more revenue (and more EBITDA) than the traditional leading exchanges. But the question we should ask is – despite crypto being a growing asset class (which implies a higher growth rate of Coinbase’s revenue), why is Coinbase’s valuation still lower than top traditional exchanges? There are some obvious reasons. Firstly, 2021Q2 was an unusually good quarter for Coinbase, hence the revenues are not stable. Secondly, the commissions crypto exchanges charge are unsustainably high. Lastly, the biggest reason is that there is a safer and cheaper way to trade crypto via decentralized exchanges (aka DEXs).
Decentralized Exchanges are one of the many applications of Defi. Other examples are Decentralized Lending Protocols, StableCoins, etc. So, let’s start with the definition of Defi.
Defi refers to financial protocols which are not just Decentralized but also Non-custodial. What is Non-custodial? Recall that all digital assets on any blockchain are secured by private keys. Most people make their first crypto purchase from a centralized exchange and they are not even aware of these private keys. This is because the exchange manages the custody of the private key for the user. Therefore these exchange accounts are custodial. This is not a safe practice. This became clear in the crypto crash of May 2022, when many exchanges denied withdrawals for their users. This is against the principle of decentralization because the owners should not be denied access to their own funds by any centralized entity.
The job of an exchange is to do market-making (match buyers with suppliers) by quoting a price for every buy and sell order. Traditional non-crypto exchanges do market making via Central Limit Order Book (CLOB). The following diagram is the depth chart of a limit order book. In the above diagram, focus on the gap (shown by a black rectangle) between the highest bid and lowest ask. It is called the bid-ask spread. In the depth chart, the height at each price represents the cumulative buy or sell order size of all limit orders between that price and the bid-ask spread.

The cumulative order size is too small at the highest bid and lowest ask which means if you try to buy (sell) a large amount you will increase (decrease) the lowest-ask (highest-bid) price. Your average trade price will be slightly higher (lower) than the lowest-ask (highest-bid) price. This difference is called slippage. It is a cost of getting your trades executed. We will use the concept of slippage, at multiple points in this article.
CLOB exchanges can be automated using a computer program which is why they are called AMMs (Automated Market Makers). We know that Ethereum can run any computer program, but the CLOB AMMs cannot be run on a decentralized open platform like Ethereum for two main reasons:
Since Ethereum is an open platform where orders get prioritized by the willingness of the user to pay gas fees, it can lead to front running of orders. The nodes which are generating the blocks can include their own transactions ahead of transactions sent by the general public. This is called Miner Extractable Value (MEV).
Even if all nodes are ethical, operating CLOB on Ethereum is inefficient because storing and updating every individual limit order is computationally costly. Note that limit orders in CLOBs can’t lead to any trade execution by themselves if there is no market order.
Therefore, researchers designed another type of AMMs called CFMMs (Constant Function Market Makers). Instead of CLOBs, they use constant functions (aka invariants) to quote prices and execute trades.
Uniswap v2 is DEX smart contract based on a “constant product” function. Here’s an example of a Uniswap v2 market for two currencies.
Start with a pair of equal values of two assets and put them in a Uniswap liquidity pool contract. For example, $10K and ₹1M when the exchange rate is $1 = ₹100.
The contract computes the product (10K * 1M = 10B). The Uniswap v2 protocol says that product (10B) must be constant after executing any trade.
If you want to sell ₹1000 to this contract, it will offer $9.99 (at a rate of 100.1 ₹/$). After the trade, the contract will hold ₹1.001M and $9990.01. The new product is still 10B (9990.01 * 1.001M).
If you want to sell ₹10M to this contract, it will offer $9099.81 (at an absurd rate of 1100 ₹/$). The product is still 10B (909.09 * 11M).
The genius of this contract is that it can execute trades of any size. You don’t need to lock huge amounts of capital in limit orders at many price points to ensure that large orders can be supported. Creating the exchange just requires you to deposit two currencies into a smart contract pool. As shown in the example, by just depositing $10K and ₹1M we can sell ₹10M on this exchange. This means that the constant product CFMM can handle trades sizes that are much larger than the initial capital deposited (locked). But the ability to execute large orders comes at a cost. The algorithm works fine for trades of 2-3% of the pool size, i.e., initial value of the two assets ($10K in our example). The slight change in exchange rate with every trade is analogous to slippage in CLOB exchanges. But for larger orders the exchange rates are absurd, implying too much slippage.
Slippage is not acceptable for commonly traded pairs, especially for Stablecoins whose prices are supposed to be pegged to their respective fiat currencies. What is the easiest function which will ensure zero slippage, and hence constant prices? The answer is the constant sum function: X + Y = c. Whenever X increases by 1 unit, Y must decrease by 1 unit. In other words, If you put 1 unit of X in the liquidity pool, you will get back one unit of Y and vice versa. This is exactly what we wanted – a constant exchange rate (const. price, 1 X = 1 Y) for zero slippage. But the constant price behavior is also a curse. Whenever there is a slight change in price (for example let’s say at some leading centralized exchange, 1 X = 1.01 Y) then everyone who owns the currency Y will deposit their Y into the constant function liquidity pool and convert it into X, at the ratio of 1:1. And then sell all the Xs on the centralized exchange to convert it into Y, at the ratio of 1:1.01. This means that there is a risk-free way for arbitragers to convert one Y into 1.01 Y. When too many send their Ys to the liquidity pool and extract X from it, then soon there will be no more X left in the pool, rendering the exchange pool useless (illiquid). In other words, the constant sum CFMM is liquid at only a single price (the exchange rate is constant).
Curve (another DEX) solved the slippage issue for assets like Stablecoins by using a hybrid of constant-sum and constant-product functions. If you split the StableSwap Invariant (given above) into two parts, the first part [2.𝛘.s(X + Y) = 4.𝛘.s²] is constant-sum and the second part [X.Y = s²] is constant-product. The constant-sum part can be further simplified into X + Y = 2s. Basically, the Curve CFMM is nothing but the constant-sum equation multiplied by 𝛘 and then added to the constant-product equation. Hence 𝛘 is the weight given to constant-sum w.r.t. constant-product. If 𝛘 is 0, the StableSwap Invariant is just a constant product like Uniswap v2. It 𝛘 is infinite, then the StableSwap Invariant is just a constant sum.
2.𝛘.s(X + Y) + X.Y = 4.𝛘.s² + s² can be written as:
2.𝛘.s(X + Y) + X.Y + 4.𝛘².s² = 4.𝛘.s² + s² + 4.𝛘².s² which is same as:
(X + 2.𝛘.s)(Y + 2.𝛘.s) = s²(4.𝛘 + 1 + 4.𝛘²) Simplifying it further:
(X + 2.𝛘.s)(Y + 2.𝛘.s) = [s(2.𝛘 + 1)]²
The above equation looks quite similar to (X + Xoffset).(Y + Yoffset) = L² which is the foundation of Uniswap v3 discussed below.
Recall that the Uniswap v2 liquidity pool was just created by depositing two assets. But a Uniswap v3 liquidity pool is composed of multiple positions, just like CLOBs are made of multiple limit orders. A single position in Uniswap v3 allows Liquidity Providers (LPs) to concentrate their liquidity to smaller price ranges instead of [0, ∞] like Uniswap v2. Each position is defined by three parameters, the first two parameters (Upper price Pupper, and Lower price Plower) define the range in which deposited capital will be used to support trading activity and the third parameter (Liquidity L) defines the liquidity provided by the deposited capital.

Visualizing the graphs:
Price: The slope of the curve in the above graph is the price of
Xin terms ofY. Higher the slope, the more is the worth of X. Therefore, at higher slopes, a small change inXreserves, lead to a big change inYreserves.Price of X = -dy/dx.Liquidity: It is defined as the rate of change of
Y(the reserves of theYtoken) for a given change insqrt(P)(the square root of the price of theXtoken in terms of theYtoken):L = dy/d√P. So, ifYchanges a lot for one unit of change insqrt(P)then it means that without changing the price much, more
If you observe the graphs below, the orange curve is just the shifted version of the blue curve. Since the shape of the curve is not changing, the price and liquidity remain unchanged. But, the capital efficiency will increase because the TVL is decreasing. If you observe the point c in the graph below, the X reserve at that point is just the X coordinate of c. But when the blue curve shifted to the orange curve. The X coordinate of c changes to a smaller value of Xreal. Similarly, the Y coordinate also decreases to Yreal. Hence TVL decreases but the Liquidity remains the same which means that the orange liquidity pool will lead to the same amount of slippage as the blue liquidity pool. Therefore, the orange curve has higher Capital Efficiency.

But the capital efficiency gain comes at a cost. The orange curve provides the same amount of liquidity as the blue curve, but with lesser TVL, therefore, it cannot support large orders. Or in other words, the orange curve supports trading at a limited price range, while the blue curve is liquid at all prices between [0, ∞].
Visualizing price range from CFMM curves: We know that price is nothing but slopes of the CFMM curve. So, just see highest and the lowest slope in the curve to determine the supported price range. The Uniswap v2 supports all the slopes and it has same amount of liquidity at all prices. The StableSwap curve support very narrow range of slopes. It is only liquid between a range of prices:
PupperandPlower. In extreme case when𝛘is infinite, then StableSwap invariant reduces to a simple constant-sum invariant which is only liquid at just a single price point.

Visualizing liquidity at different prices:
L = dy/d√P. So, ifYchanges a lot but the square root of slope (price) does not change too much, then liquidity is high. If you observe the Balancer curve in the diagram above, you will see that it supports all prices just like the constant-product invariant used by Uniswap v2. But, the liquidity is higher at lower prices. This is visible in the graph: at lower prices the slopes are low, which is towards the far right region in the Balancer curve. In that extreme right region, the curve is almost flat which means smaller change in slope. Therefore, the liquidity is high at lower prices than at upper prices.
Uniswap v3 is a collection of custom positions. Price stability is ensured via concentrated liquidity (see the third graph in the diagram given below). This solves the high slippage issue of Uniswap v2. For example, a stablecoin like DAI must always be equal to 1 USD. For such a pair, all LPs can take a position in a narrow band, where Pupper = 1.01 and Plower = 0.99. This liquidity graph can look much more concentrated than the third graph in the figure below. If we take an unpegged pair, say ETH-DAI, then the price need not be stable. At the same time price should not be too volatile because it is a commonly traded pair. This means more liquidity should be present around the current price and less liquidity is acceptable at higher and lower prices. This liquidity graph should resemble the third graph in the diagram shown below.

Uniswap v3 allows for any arbitrary Liquidity-Price curve by making LPs active. Each position only participates in trading if the trade execution price is within its price range. This is similar to limit orders of CLOB exchanges, where a limit order only gets executed when trading happens around that price. So, Uniswap v3 makes LPs active, who were passive in Uniswap v2. The shape of the Liquidity-Price curve in v2 was fixed (first graph in the figure above). But the shape of the Liquidity-Price curve in v3 can look like any arbitrary function, therefore Uniswap v3 is called Universal CFMM.
The lazy (passive) liquidity of Uniswap v2 is no longer profitable because sharp price movements create arbitrage opportunities and arbitrageurs extract value from the liquidity providers. This phenomenon is called impermanent loss. If the prices revert back, the loss goes away, otherwise, it becomes permanent. Let’s understand this with an example:
Alice deposits 1 ETH and 100 DAI in a pool
Today, 1 ETH = 100 DAI
Initial value of Alice's deposits = $200
There are total 10 ETH and 1000 DAI in the pool.
Alice’s share is 10%
The constant product is 10,000.
Tomorrow, ETH appreciates to 1 ETH = 400 DAI
Arbitrage traders will put more DAI and take out ETH from the pool
There is now 5 ETH and 2000 DAI in the pool (Constant product)
Alice takes out her 10% stake, i.e., 0.5 ETH and 200 DAI.
Her total value is now $400.
If she had simply HODLed ETH and DAI, her total value will be $500.
Impermanent loss = $500 - $400 = $100
Therefore, almost all the DEXs (including Uniswap v2 and v3) charge some liquidity fee, which usually offsets the impermanent loss (which is not high as prices usually revert back to great extent). Uniswap v3 goes a step further by supporting custom liquidity fee. LPs (Liquidity Providers) experience high impermanent loss if the treaded pair is not common and hence more volatile. Such pairs need high liquidity fee for the LPs to be profitable. That’s why Uniswap v3 is popular among illiquid pairs.
This is a fun section where the rubber meets the road. We will try to explain some empirical observations market using the technical insights we just learned.
After the crypto crash of May 2022, the Market Cap of stablecoins has increased. People don’t want to hold a lot of volatile assets like BTC or ETH. Now, recall that Curve was designed for stablecoin trading because their prices are not supposed to change much, and hence they need lower slippage CFMM of Curve.

Uniswap has a governance token called UNI, which has the highest market cap among similar DEX tokens. These governance tokens are used to determine the parameters of the Uniswap protocol, for example, the customizable liquidity fee for each pair. The majority of the profits from the exchange go to the liquidity providers but a minority share goes to the UNI token holders which incentivizes them to take more user-friendly governance decisions. One can assume that the UNI holders (investors) are incentivized to use Uniswap for trading, which gives Uniswap an unfair advantage. But this is not the main reason behind Uniswap's dominance. When a liquidity provider is selecting an exchange, everything boils down to a single metric – capital efficiency.

If you compare Uniswap and Curve, Uniswap has a higher trading volume with lower TVL. This means Uniswap is more capital efficient. That is why traders prefer to trade on Uniswap which makes it the most dominant DEX. But what about centralized exchanges? Does a DEX which uses CFMM, has a chance against the CLOB based Binance and Coinbase?
The following graph claims that for ETH/USD, Uniswap has ~2x more liquidity than both Binance and Coinbase. For ETH/mid-cap pairs Uniswap has on average ~3x more liquidity than major centralized exchanges.

But there is a catch – liquidity in the above graph is defined as Depth in the +/- 2% of the current price. But at the beginning of this article, we have seen that the limit order book leads to a lower depth at prices close to the current price. But the liquidity in Uniswap v3 is usually concentrated around the current price. So it is an uphill battle for CLOBs to have more depth than CFMMs in a small range of +/-2% around the current price. But this does not undermine the fact that CFMM design has lesser slippage for small and medium orders – which are usually submitted by retail traders.
If you take one thing away from this – truly this is what I want you to take away: CFMM-based DEXs will always have an advantage over CLOB-based Centralized Exchanges when it comes to illiquid pairs. However, most institutional or experienced retail traders are so used to trading using limit orders that some DEXs are trying to use CLOBs to attract institutional clients.
This article did not discuss derivative exchanges, which is an emerging space. The perp protocol is one of the earliest Futures like derivatives for crypto. DyDx v3 uses zk-rollup based Layer 2 to settle the trades, but trades are executed using a CLOB which runs off-chain. However, due to centralization, they suffered outages. Recently, they announced that they are going to launch a v4 which will be built on a different Layer 1 called Cosmos. In the non-crypto world, derivative markets have 30 to 40 times more trading volume than spot markets. As the extreme price jumps in crypto assets become rare, people will flock towards derivates for leveraged returns.
The first two articles of this series were mainly about new possibilities which can only be unlocked via Web 3. Two use cases we discussed were: Digitization of Land Records and Stock Prediction tool for Analysts. Bottomline – Web 3 dominates Web 2 in newer use cases… but can Web 3 beat Web 2 on its home turf, i.e., existing use cases? Obviously, the answer is yes, or else I would not be writing this piece. Instead of finding newer applications to prove the worthiness of Web 3, let’s see how blockchain is redefining age-old applications like exchanges.
Exchanges are a business. Every time you trade, you may or may not get rich. But with your every transaction, the exchanges are taking home cold hard cash. In case you’re wondering how… I have a GIF for you :)

Have you ever wondered how much money the exchanges make? Here’s a Twitter thread from SBF which explains the economics of Coinbase, one of the largest crypto exchanges. SBF is the founder of FTX, which itself is another leading crypto exchange and a competitor of Coinbase.
https://twitter.com/SBF_FTX/status/1426431393563873281
The last tweet of this thread is the real jaw-dropper which revealed that Coinbase generated more revenue than all the traditional exchanges.
https://twitter.com/SBF_FTX/status/1426431436484235265
It is surprising that crypto exchanges bring more revenue (and more EBITDA) than the traditional leading exchanges. But the question we should ask is – despite crypto being a growing asset class (which implies a higher growth rate of Coinbase’s revenue), why is Coinbase’s valuation still lower than top traditional exchanges? There are some obvious reasons. Firstly, 2021Q2 was an unusually good quarter for Coinbase, hence the revenues are not stable. Secondly, the commissions crypto exchanges charge are unsustainably high. Lastly, the biggest reason is that there is a safer and cheaper way to trade crypto via decentralized exchanges (aka DEXs).
Decentralized Exchanges are one of the many applications of Defi. Other examples are Decentralized Lending Protocols, StableCoins, etc. So, let’s start with the definition of Defi.
Defi refers to financial protocols which are not just Decentralized but also Non-custodial. What is Non-custodial? Recall that all digital assets on any blockchain are secured by private keys. Most people make their first crypto purchase from a centralized exchange and they are not even aware of these private keys. This is because the exchange manages the custody of the private key for the user. Therefore these exchange accounts are custodial. This is not a safe practice. This became clear in the crypto crash of May 2022, when many exchanges denied withdrawals for their users. This is against the principle of decentralization because the owners should not be denied access to their own funds by any centralized entity.
The job of an exchange is to do market-making (match buyers with suppliers) by quoting a price for every buy and sell order. Traditional non-crypto exchanges do market making via Central Limit Order Book (CLOB). The following diagram is the depth chart of a limit order book. In the above diagram, focus on the gap (shown by a black rectangle) between the highest bid and lowest ask. It is called the bid-ask spread. In the depth chart, the height at each price represents the cumulative buy or sell order size of all limit orders between that price and the bid-ask spread.

The cumulative order size is too small at the highest bid and lowest ask which means if you try to buy (sell) a large amount you will increase (decrease) the lowest-ask (highest-bid) price. Your average trade price will be slightly higher (lower) than the lowest-ask (highest-bid) price. This difference is called slippage. It is a cost of getting your trades executed. We will use the concept of slippage, at multiple points in this article.
CLOB exchanges can be automated using a computer program which is why they are called AMMs (Automated Market Makers). We know that Ethereum can run any computer program, but the CLOB AMMs cannot be run on a decentralized open platform like Ethereum for two main reasons:
Since Ethereum is an open platform where orders get prioritized by the willingness of the user to pay gas fees, it can lead to front running of orders. The nodes which are generating the blocks can include their own transactions ahead of transactions sent by the general public. This is called Miner Extractable Value (MEV).
Even if all nodes are ethical, operating CLOB on Ethereum is inefficient because storing and updating every individual limit order is computationally costly. Note that limit orders in CLOBs can’t lead to any trade execution by themselves if there is no market order.
Therefore, researchers designed another type of AMMs called CFMMs (Constant Function Market Makers). Instead of CLOBs, they use constant functions (aka invariants) to quote prices and execute trades.
Uniswap v2 is DEX smart contract based on a “constant product” function. Here’s an example of a Uniswap v2 market for two currencies.
Start with a pair of equal values of two assets and put them in a Uniswap liquidity pool contract. For example, $10K and ₹1M when the exchange rate is $1 = ₹100.
The contract computes the product (10K * 1M = 10B). The Uniswap v2 protocol says that product (10B) must be constant after executing any trade.
If you want to sell ₹1000 to this contract, it will offer $9.99 (at a rate of 100.1 ₹/$). After the trade, the contract will hold ₹1.001M and $9990.01. The new product is still 10B (9990.01 * 1.001M).
If you want to sell ₹10M to this contract, it will offer $9099.81 (at an absurd rate of 1100 ₹/$). The product is still 10B (909.09 * 11M).
The genius of this contract is that it can execute trades of any size. You don’t need to lock huge amounts of capital in limit orders at many price points to ensure that large orders can be supported. Creating the exchange just requires you to deposit two currencies into a smart contract pool. As shown in the example, by just depositing $10K and ₹1M we can sell ₹10M on this exchange. This means that the constant product CFMM can handle trades sizes that are much larger than the initial capital deposited (locked). But the ability to execute large orders comes at a cost. The algorithm works fine for trades of 2-3% of the pool size, i.e., initial value of the two assets ($10K in our example). The slight change in exchange rate with every trade is analogous to slippage in CLOB exchanges. But for larger orders the exchange rates are absurd, implying too much slippage.
Slippage is not acceptable for commonly traded pairs, especially for Stablecoins whose prices are supposed to be pegged to their respective fiat currencies. What is the easiest function which will ensure zero slippage, and hence constant prices? The answer is the constant sum function: X + Y = c. Whenever X increases by 1 unit, Y must decrease by 1 unit. In other words, If you put 1 unit of X in the liquidity pool, you will get back one unit of Y and vice versa. This is exactly what we wanted – a constant exchange rate (const. price, 1 X = 1 Y) for zero slippage. But the constant price behavior is also a curse. Whenever there is a slight change in price (for example let’s say at some leading centralized exchange, 1 X = 1.01 Y) then everyone who owns the currency Y will deposit their Y into the constant function liquidity pool and convert it into X, at the ratio of 1:1. And then sell all the Xs on the centralized exchange to convert it into Y, at the ratio of 1:1.01. This means that there is a risk-free way for arbitragers to convert one Y into 1.01 Y. When too many send their Ys to the liquidity pool and extract X from it, then soon there will be no more X left in the pool, rendering the exchange pool useless (illiquid). In other words, the constant sum CFMM is liquid at only a single price (the exchange rate is constant).
Curve (another DEX) solved the slippage issue for assets like Stablecoins by using a hybrid of constant-sum and constant-product functions. If you split the StableSwap Invariant (given above) into two parts, the first part [2.𝛘.s(X + Y) = 4.𝛘.s²] is constant-sum and the second part [X.Y = s²] is constant-product. The constant-sum part can be further simplified into X + Y = 2s. Basically, the Curve CFMM is nothing but the constant-sum equation multiplied by 𝛘 and then added to the constant-product equation. Hence 𝛘 is the weight given to constant-sum w.r.t. constant-product. If 𝛘 is 0, the StableSwap Invariant is just a constant product like Uniswap v2. It 𝛘 is infinite, then the StableSwap Invariant is just a constant sum.
2.𝛘.s(X + Y) + X.Y = 4.𝛘.s² + s² can be written as:
2.𝛘.s(X + Y) + X.Y + 4.𝛘².s² = 4.𝛘.s² + s² + 4.𝛘².s² which is same as:
(X + 2.𝛘.s)(Y + 2.𝛘.s) = s²(4.𝛘 + 1 + 4.𝛘²) Simplifying it further:
(X + 2.𝛘.s)(Y + 2.𝛘.s) = [s(2.𝛘 + 1)]²
The above equation looks quite similar to (X + Xoffset).(Y + Yoffset) = L² which is the foundation of Uniswap v3 discussed below.
Recall that the Uniswap v2 liquidity pool was just created by depositing two assets. But a Uniswap v3 liquidity pool is composed of multiple positions, just like CLOBs are made of multiple limit orders. A single position in Uniswap v3 allows Liquidity Providers (LPs) to concentrate their liquidity to smaller price ranges instead of [0, ∞] like Uniswap v2. Each position is defined by three parameters, the first two parameters (Upper price Pupper, and Lower price Plower) define the range in which deposited capital will be used to support trading activity and the third parameter (Liquidity L) defines the liquidity provided by the deposited capital.

Visualizing the graphs:
Price: The slope of the curve in the above graph is the price of
Xin terms ofY. Higher the slope, the more is the worth of X. Therefore, at higher slopes, a small change inXreserves, lead to a big change inYreserves.Price of X = -dy/dx.Liquidity: It is defined as the rate of change of
Y(the reserves of theYtoken) for a given change insqrt(P)(the square root of the price of theXtoken in terms of theYtoken):L = dy/d√P. So, ifYchanges a lot for one unit of change insqrt(P)then it means that without changing the price much, more
If you observe the graphs below, the orange curve is just the shifted version of the blue curve. Since the shape of the curve is not changing, the price and liquidity remain unchanged. But, the capital efficiency will increase because the TVL is decreasing. If you observe the point c in the graph below, the X reserve at that point is just the X coordinate of c. But when the blue curve shifted to the orange curve. The X coordinate of c changes to a smaller value of Xreal. Similarly, the Y coordinate also decreases to Yreal. Hence TVL decreases but the Liquidity remains the same which means that the orange liquidity pool will lead to the same amount of slippage as the blue liquidity pool. Therefore, the orange curve has higher Capital Efficiency.

But the capital efficiency gain comes at a cost. The orange curve provides the same amount of liquidity as the blue curve, but with lesser TVL, therefore, it cannot support large orders. Or in other words, the orange curve supports trading at a limited price range, while the blue curve is liquid at all prices between [0, ∞].
Visualizing price range from CFMM curves: We know that price is nothing but slopes of the CFMM curve. So, just see highest and the lowest slope in the curve to determine the supported price range. The Uniswap v2 supports all the slopes and it has same amount of liquidity at all prices. The StableSwap curve support very narrow range of slopes. It is only liquid between a range of prices:
PupperandPlower. In extreme case when𝛘is infinite, then StableSwap invariant reduces to a simple constant-sum invariant which is only liquid at just a single price point.

Visualizing liquidity at different prices:
L = dy/d√P. So, ifYchanges a lot but the square root of slope (price) does not change too much, then liquidity is high. If you observe the Balancer curve in the diagram above, you will see that it supports all prices just like the constant-product invariant used by Uniswap v2. But, the liquidity is higher at lower prices. This is visible in the graph: at lower prices the slopes are low, which is towards the far right region in the Balancer curve. In that extreme right region, the curve is almost flat which means smaller change in slope. Therefore, the liquidity is high at lower prices than at upper prices.
Uniswap v3 is a collection of custom positions. Price stability is ensured via concentrated liquidity (see the third graph in the diagram given below). This solves the high slippage issue of Uniswap v2. For example, a stablecoin like DAI must always be equal to 1 USD. For such a pair, all LPs can take a position in a narrow band, where Pupper = 1.01 and Plower = 0.99. This liquidity graph can look much more concentrated than the third graph in the figure below. If we take an unpegged pair, say ETH-DAI, then the price need not be stable. At the same time price should not be too volatile because it is a commonly traded pair. This means more liquidity should be present around the current price and less liquidity is acceptable at higher and lower prices. This liquidity graph should resemble the third graph in the diagram shown below.

Uniswap v3 allows for any arbitrary Liquidity-Price curve by making LPs active. Each position only participates in trading if the trade execution price is within its price range. This is similar to limit orders of CLOB exchanges, where a limit order only gets executed when trading happens around that price. So, Uniswap v3 makes LPs active, who were passive in Uniswap v2. The shape of the Liquidity-Price curve in v2 was fixed (first graph in the figure above). But the shape of the Liquidity-Price curve in v3 can look like any arbitrary function, therefore Uniswap v3 is called Universal CFMM.
The lazy (passive) liquidity of Uniswap v2 is no longer profitable because sharp price movements create arbitrage opportunities and arbitrageurs extract value from the liquidity providers. This phenomenon is called impermanent loss. If the prices revert back, the loss goes away, otherwise, it becomes permanent. Let’s understand this with an example:
Alice deposits 1 ETH and 100 DAI in a pool
Today, 1 ETH = 100 DAI
Initial value of Alice's deposits = $200
There are total 10 ETH and 1000 DAI in the pool.
Alice’s share is 10%
The constant product is 10,000.
Tomorrow, ETH appreciates to 1 ETH = 400 DAI
Arbitrage traders will put more DAI and take out ETH from the pool
There is now 5 ETH and 2000 DAI in the pool (Constant product)
Alice takes out her 10% stake, i.e., 0.5 ETH and 200 DAI.
Her total value is now $400.
If she had simply HODLed ETH and DAI, her total value will be $500.
Impermanent loss = $500 - $400 = $100
Therefore, almost all the DEXs (including Uniswap v2 and v3) charge some liquidity fee, which usually offsets the impermanent loss (which is not high as prices usually revert back to great extent). Uniswap v3 goes a step further by supporting custom liquidity fee. LPs (Liquidity Providers) experience high impermanent loss if the treaded pair is not common and hence more volatile. Such pairs need high liquidity fee for the LPs to be profitable. That’s why Uniswap v3 is popular among illiquid pairs.
This is a fun section where the rubber meets the road. We will try to explain some empirical observations market using the technical insights we just learned.
After the crypto crash of May 2022, the Market Cap of stablecoins has increased. People don’t want to hold a lot of volatile assets like BTC or ETH. Now, recall that Curve was designed for stablecoin trading because their prices are not supposed to change much, and hence they need lower slippage CFMM of Curve.

Uniswap has a governance token called UNI, which has the highest market cap among similar DEX tokens. These governance tokens are used to determine the parameters of the Uniswap protocol, for example, the customizable liquidity fee for each pair. The majority of the profits from the exchange go to the liquidity providers but a minority share goes to the UNI token holders which incentivizes them to take more user-friendly governance decisions. One can assume that the UNI holders (investors) are incentivized to use Uniswap for trading, which gives Uniswap an unfair advantage. But this is not the main reason behind Uniswap's dominance. When a liquidity provider is selecting an exchange, everything boils down to a single metric – capital efficiency.

If you compare Uniswap and Curve, Uniswap has a higher trading volume with lower TVL. This means Uniswap is more capital efficient. That is why traders prefer to trade on Uniswap which makes it the most dominant DEX. But what about centralized exchanges? Does a DEX which uses CFMM, has a chance against the CLOB based Binance and Coinbase?
The following graph claims that for ETH/USD, Uniswap has ~2x more liquidity than both Binance and Coinbase. For ETH/mid-cap pairs Uniswap has on average ~3x more liquidity than major centralized exchanges.

But there is a catch – liquidity in the above graph is defined as Depth in the +/- 2% of the current price. But at the beginning of this article, we have seen that the limit order book leads to a lower depth at prices close to the current price. But the liquidity in Uniswap v3 is usually concentrated around the current price. So it is an uphill battle for CLOBs to have more depth than CFMMs in a small range of +/-2% around the current price. But this does not undermine the fact that CFMM design has lesser slippage for small and medium orders – which are usually submitted by retail traders.
If you take one thing away from this – truly this is what I want you to take away: CFMM-based DEXs will always have an advantage over CLOB-based Centralized Exchanges when it comes to illiquid pairs. However, most institutional or experienced retail traders are so used to trading using limit orders that some DEXs are trying to use CLOBs to attract institutional clients.
This article did not discuss derivative exchanges, which is an emerging space. The perp protocol is one of the earliest Futures like derivatives for crypto. DyDx v3 uses zk-rollup based Layer 2 to settle the trades, but trades are executed using a CLOB which runs off-chain. However, due to centralization, they suffered outages. Recently, they announced that they are going to launch a v4 which will be built on a different Layer 1 called Cosmos. In the non-crypto world, derivative markets have 30 to 40 times more trading volume than spot markets. As the extreme price jumps in crypto assets become rare, people will flock towards derivates for leveraged returns.
YCapital Efficiency: It is defined as Turnover (or Liquidity) by TVL (Total Volume Locked = X reserves + Y reserves).
YCapital Efficiency: It is defined as Turnover (or Liquidity) by TVL (Total Volume Locked = X reserves + Y reserves).
No comments yet