Flat-Curve Constant Function Market Maker Introduction

This blog post first introduces the motivation for a flat-curve constant function market maker (CFMM).

youves
4 min readJan 25, 2022

--

The CFMM and this blog post are based on Arthur Breitman’s Flat Curve CFMM concept and its reference implementation.

Constant Product Market Makers (CPMM)

Most DEXs currently work with a constant product market maker (CPMM). Given adequate liquidity, this works reasonably well. Especially for the trading of pairs where the exchange rate is freely floating and is not supposed to follow a fixed value. The advantage is that it provides a reliable price signal and any trade-in the liquidity pool can in theory never empty out one of the sides (ignoring numerical limits).

Formulas

  • const = x * y
    or
  • y = const / x
    for x,y >= 0

The constant product implies a hyperbola (see below).

Are Linear Responses the solution?

The situation is a little different for trading pairs in which one asset is pegged to the other, or if both assets are pegged to the same underlying value, for example, uBTC <\> tzBTC. From a user point of view, it would be desirable if the exchange rate were always `1 uBTC = 1 tzBTC`. This would imply a straight line response ‘curve’ of the automated market maker (AMM), effectively a constant sum market maker. The problem with such an approach is that it would completely lack any price signal and the liquidity pool in the outgoing asset, say uBTC, could easily be emptied out given enough supply in the other, say tzBTC. This would lead to the undesirable situation where arbitrarily high amounts of incoming tzBTC would still result in 0 outgoing uBTC, effectively implying an infinitely high price for uBTC/tzBTC.

Formulas

  • const = y + x
    or
  • y = const — x
    for x,y >= 0

The constant sum implies a straight line (see below).

Constant Function Market Maker

Requirements

So an ideal response curve for 1:1 asset pairs should be both

  • very flat; but also
  • provide enough price response at the edge, so that the liquidity pools cannot be emptied though trading activity.

So a compromise has to be found.

Possible Solution

The curve `U(x,y) = (x+y)⁸ — (x-y)⁸` works well.

  1. It is very flat around `x = y`, at this point the slope of the curve `dx U / dy U = -1`.
  2. As in CPMMs, even very high inputs of asset 1 in a trade will never empty the asset 2 side of the trade as the function can make the outgoing asset arbitrarily expensive.

This makes it suitable to create a CFMM between two assets which ought to be pegged to one another.

Formulas

U(x,y) = (x+y)⁸ — (x-y)⁸
for x,y >= 0
around the 1:1 point the slope would be
dx U / dy U = -1

Green: Constant product (hyperbola)
Blue: Constant sum (line)
Orange: Constant function
Source: https://github.com/tezos-checker/flat-cfmm
Green: Constant product
Blue: Constant sum
Orange: Constant function
Source: https://github.com/tezos-checker/flat-cfmm

Slippage

The curve is extraordinarily stable in the available trade FX when starting from a balanced pool. Adding 750k (75%) of asset 1 into a balanced pool of previously 1mm in each asset only moves the price by less than 3%.

Liquidity Provision

Advantages

As the price will move only very little, even for relatively large transactions, relative to the pool size, the ratio of the two assets in the liquidity pools may change significantly. However, given that the trading pairs are stable tokens on the same underlying asset, which in theory should fundamentally be worth the same. As long as this equality holds, any notion of impermanent loss will likely be a mere inconvenience.

Please note that a possible downside of the flat curve CFMM is that arbitrage to bring the pool back to its theoretical midpoint will be significantly less profitable, as there are much lower price differences to benefit from.

As a consequence, there is a chance that the ratio of the pools gets stuck close to one of the points where the flat bit of the curve ends and hence trades in one direction start having a larger price impact. If this happens to be the direction needed to unwind one’s position, then the situation would be similar as in a CPMM.

--

--

youves

Your tool on Tezos for asset creation and management.