A Brief Study of CFMM (Constant Function Market Makers)

A Byte Ahead
5 min readDec 3, 2020

Recently I bumped into a new realm of Defi and obviously, one of the core infrastructures is the decentralized exchanges or so-called DEXs. The basic functionality for them is to provide an exchange from coin A to coin B.

Uniswap is one of its kind that exceeds both in volume and easiness to use. Currently, it sits on the throne of “No1. Defi exchange” and locks up to $1.37B worth of assets and trades at $143.77M every day.

The key exchange model used on the platform for matching coin A with coin B isn’t the traditional “order book” style, which requires active traders to place orders from time to time. It employes a clever strategy of CFMM (Constant Function Market Makers) which is Defi’s zero-to-one innovation. Alongside other auto market makers (AMM) strategies, this is the most successful one.

How does it work?

It is best explained here [PDF], There are mainly two roles in the market:

  1. Liquidity Providers (LP): They deposit a pair of coins into the pool, and willing to let others interact with the pool for a fee.
  2. Traders/Arbitrageurs: They swap coins directly on the exchange rather than interacting with a counterparty. With the coins they got, they may sell on other exchanges to make profits.

It all sounds beautiful at first, but the next big question is obvious: who decides the price of A/B pair? Would they be able to find the correct price just like old-time exchanges?

First Step

Quite simple, let’s say Alice wants to establish a pool and to be the first liquid provider. She holds a combination of 1ETH + 100 USD. Now she deposits it into the pool to start her journey as the market maker.

According to the rules, we calculate an equation of Z = X * Y, now Z = 1 * 100 = 100. In the future, the algorithm of the pool tries to maintain the Z constant.

To make the Z constant, any take out of ETH (less ETH in the pool) will result in more USD to be compensated into the pool to keep the Z steady, and vice versa, so the the relationship of X and Y is on a curve:

Z = X * Y

Scenario #1: ETH price increases

A trader finds out the price of ETH/USD in the pool is cheaper than outside exchanges, and buys some cheap ETH from the pool, here are his steps:

Trader buys from the pool of ETH

We can see that, if the trader buys more ETH from the pool, the USD he needs to send back into the pool is rising. And the rising isn’t linear, it rises sharply as the ETH demolishes, from 111.1 USD/ETH to 238.2 USD/ETH. The more he buys, the more USD/coin he pays.

Interesting facts from the table above:

  1. Total 0.4 ETH is bought from the pool, 66.67 USD is paid. (166.67 USD per ETH)
  2. The last 0.1 ETH actually costs 238.2 USD.
  3. The next buyer of ETH will pay even higher (> 238.2 USD per ETH)

From the trader’s perspective:

  1. If he manages to sell the 0.4 ETH he bought at the price of 238.2 USD (on other exchanges for example, Binance), he makes a profit of: 0.4 * 238.2–66.67 = 28.61 USD.

From the liquid provider’s perspective:

  1. Holds 0.6 ETH + 166.67 USD = 0.6 * 238.2 + 166.67 = 309.59 USD
  2. The above is paper wealth, he may not cash out as high as 238.2 USD/ETH
  3. If he doesn’t provide liquidity, instead holds his “1ETH+100USD” combination, he achieves a sum of 1 ETH+100 USD = 238.2 + 100 = 338.2 USD

The difference of 338.2–309.59 = 28.61 USD = the profit the trader makes.

Scenario #2: ETH price decreases

The ETH price decreases. The trader sell his ETH to the pool to make a profit, here is how he does it:

The trader sells ETH to the pool

Same as above example, the more ETH the trader sells to the pool, the more resistance he faces. The selling price of ETH declines sharply, from 91 USD/ETH to 55 USD/ETH.

Interesting facts from the table above:

  1. Total 0.4 ETH is sold for 28.58 USD. ( 71.45 USD per ETH )
  2. The last 0.1 ETH sold at price 55 USD.
  3. The next seller will get a much lower bid than 55 USD.

From the trader’s perspective:

  1. If he manages to buy some ETH back on other exchanges with the 28.58 USD he gained, at the low price of 55 USD/ETH, then he can buy back 0.4 ETH (costs 22USD), and make a profit of 6.58 USD.

From the liquid provider’s perspective:

  1. Currently holds 1.4 ETH + 71.42 USD = 1.4 * 55 + 71.42 = 148.42 USD
  2. If he doesn’t provide liquidity, instead holds his “1ETH+100USD” combination, he achieves a sum of 1 ETH+100 USD = 55 + 100 = 155 USD
  3. The difference of 155–148.42 = 6.58 USD = the profit the trader makes.


With the price of ETH moves either direction, the liquid provider always suffers a sense of “loss” than the most simple strategy: “HODL”. And it is clear that the difference goes into the pocket of the trader as profit.

This is a dead-end strategy without incentives.

Some implications after this study:

  1. If the market is stable, or can come back to the original price, AMM is working.
  2. If the pool is big enough, one cannot easily move the price on the pool.

To improve the liquid provider’s situation, some incentives needed in place to compensate:

  1. Impose a transaction fee: take 0.3% of fee, and award it to the liquid provider. The more the traders trade, the more fees are collected.
  2. Have an incentive token alongside: fees can be in the form of a new incentive token. And the token sale can compensate the liquid providers.