A Brief Study of CFMM (Constant Function Market Makers)

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:

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:

From the trader’s perspective:

From the liquid provider’s perspective:

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:

From the trader’s perspective:

From the liquid provider’s perspective:


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:

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

Passion in computer science.