The Conceptual flaws of Constant Product Automated Market makers

by Andreas Park

 

Research Presentation

 

The Ugly Truth: token trading and token markets are different from securities trading and markets

Investor

Broker

Venue

Settlement

Exchange

Traditional

Wholeseller

Darkpool

Internalizer

Venue

Settlement

Investor

On chain

Crypto

How do you organize DEX trading?

Atomic swaps

But how?

Key Components

How do you set the price?

  1. Use an oracle
  2. Use a hard-coded function

How do you organize DEX trading?

automated market maker

Price mechanism:

  • \(X=\) contract balance of asset \(A\)
  • \(Y=\) contract balance of asset \(B\)
  • \(k=\) invariance factor
  • key relation \(k=X\times\ Y\)

Prices

  • when you want to sell \(x\le X\) you receive \(y\) that maintains invariance. 
  • implied exchange rate: \(e=\frac{x}{y}\)

How do you organize DEX trading? EXAMPLE

automated market maker

invariant \(k=4\times4=16\) 

Instantaneous exchange rate:

1             =   1

Contract deposit:

How do you organize DEX trading? EXAMPLE

automated market maker

sell 4 DAI for USDC

what price will therefore be quoted?

\begin{array}{rcl} k&=&\#\text{DAI}\times\#\text{USDC}\\ 16&=&(4+4)\times(4-y)\\ x&=&2 \end{array}

how many USDC?

e=x/y~~\to~~e=2

Mempool \(\Rightarrow\) Front-Running!

So what's the Problem?

a

b

c

d

e

f

g

Problem: MEMPOOL Frontrunning is intrinsically profitable

\(X\)

\(Y\)

normal trade: sell \(x\) \(\to\) get \(y'\)

\(Y-y'\)

\(X+x\)

front-running:

  1. front-runner: sells \(x\) \(\to\) gets \(y'\)
  2. front-run: sells \(x\) \(\to\) gets \(y''\)
  3. front-runner: buys \(x\) \(\to\) pays \(y''\) 

\(Y-y'-y''\)

\(X+2x\)

\(y'>y''~\Rightarrow\)

front-running is intrinsically profitable

Disclaimer:

  • this problem is well-known
  • fees can mitigate it
  • several protocols such as the latest iteration by Balancer try to combat it

PingPong-trading

Problem #2

Market 1

\(Y-y\)

\(X+x\)

  • two (identical) markets
  • should split trade \(2x\) into \(2\times x\) but suppose not.
  • \(\to\) price dislocation in 1.
  • Result: buy any \(x'<2x\) in 2 and sell in 1 and earn a profit

\(Y-y'\)

\(X+2x\)

\(X\)

\(Y\)

\(Y-y\)

\(X+x\)

\(Y-y'\)

\(X+2x\)

\(X\)

\(Y\)

Market 2

Is there a better way?

Hard-Coded Market Making

  • Constant product is an ad hoc rule without an economic behavior foundation
    • Aoki (2021) shows that leads to persistent profits for one side of the market
  • Front running doesn't go away with mempools
    •  Daian, Goldfeder, Kell, Li, Zhao,  Bentov,  Breidenbach, and Juels (2019):  Miner Extractable Value (MEV) and gas price auctions (GPA) in the "Flash Bots Project"
    • Noyes (2021): in Dec 2020, MEV = $120M p.d.
    • \(\to\) MEV leads to unnecessary congestion of the Ethereum blockchain
  • Is there are better way? Can we have a price rule such that
    • Front-running not intrinsically  profitable
    • Ping-pong trading not profitable
  • Yes! A standard microstructure model actually works. 

What would be desirable?

Hard-Coded Market Making

  1. Non-Profitable Order Splitting: for \(\alpha\in(0,1)\): \(p(\alpha x,I)+p((1-\alpha)x,I+\alpha x)= p(x,I)\)
     
  2. Unprofitable Front-running: \(-p(x,I)+p(-x,I+2x)=0\)
     
  3. Additivity with split liquidity, \(k\cdot\left. p(x/k,I)\right|_{N\to N/k}=\left. p(x,I)\right|_{N\to N}.\)
     
  4. No Multi-venue arbitrage: \(\forall \alpha>1/2\), \(p(-\alpha x,I+x)-p(\alpha x,I)<0.\)

   

splitting across time ain't profitable

can't make money from scanning the mem-pool

no intrinsic benefit from market fragmentation

no ping-pong trading

Standard Market Making: Biais JF 1993 (a variation)

Hard-Coded Market Making

  • Asset with true value \(v\sim N(V,\sigma^2)\)
  • Investor with exogenous demand \(Q\)
  • \(N\) market makers
    • with aggregate inventory \(I=\sum I_i\)
    • CARA utility of terminal wealth and risk aversion \(\kappa\)
  • Marginal price function \(p\) \(\to\) total cost of trading \(x\): \(p^{mm}(x,I)=\int_0^x p(t,I)dt\) with \[p(x,I)=V+\frac{2\kappa \sigma^2}{N}\ (x-I)\]
  • Define \(l := \kappa\sigma^2\) to get \[p^{mm}(x,I)=x\left(V-\frac{l}{N} ~I\right)+\frac{l}{2N}x^2\]

Constant Product Market Making

Hard-Coded Market Making

  • Tokens A and B
    • A is the "asset"
    • B is "cash"
  • Quantities \(X\) of A and \(Y\) of B in the the swap contract
    • Invariance condition \(c=X\cdot Y\)
    • Marginal price for one unit of the asset is \(Y/X\)
  • Demand of \(x\) \(\to\) get \(y\) such that
    • \(c=(X-x)(Y+y)\)
  • Constant product pricing with token amounts \(X,Y\) in the contract \[p^{cp}(x,X,Y)=x\cdot\frac{Y}{X-x}\]

Comparison

Hard-Coded Market Making

  • For apple-apple comparison:
    • \(I=0\) (everyone is at the "desired" risk amount)
    • \(X=N\) (each of \(N\) market markets contributes a unit amount)
    • \(V=Y/X\) (marginal CP price is the expected fundamental value)
  • Price functions coincide for \[x'=0~~~\text{ and }~~~ x^*:=\frac{X}{l}\ (l-2V).\]

Proposition: For \(x>x^*\), "standard" pricing is "better" for investors than constant product pricing, and for \(x<x^*\) it is the reverse.

What's desirable?

Hard-Coded Market Making

  1. Non-Profitable Order Splitting: for \(\alpha\in(0,1)\): \(p(\alpha x,I)+p((1-\alpha)x,I+\alpha x)= p(x,I)\)
     
  2. Unprofitable Front-running: \(-p(x,I)+p(-x,I+2x)=0\)
     
  3. Additivity with split liquidity, \(k\cdot\left. p(x/k,I)\right|_{N\to N/k}=\left. p(x,I)\right|_{N\to N}.\)
     
  4. No Multi-venue arbitrage: \(\forall \alpha>1/2\), \(p(-\alpha x,I+x)-p(\alpha x,I)<0.\)

   

splitting across time ain't profitable

can't make money from scanning the mem-pool

no intrinsic benefit from market fragmentation

no ping-pong trading

For standard market making

For Constant Product market making

A simple "solution" to front-running

Hard-Coded Market Making

  • Front-running requires two trades
    1. pay transactions fees twice
    2. first fee must exceed original fee
    3. second fee can't be too much lower than original fee
       
  • Front-runner needs to out-bid the original trade

no front-running if:
front-running profit < 2\(\times\) submitted fee

note, however:

  • front-runner often is the miner
  • has a bit of a gun-to-head feel
\frac{2x^2Y}{(X-x)(X-2x)}<2\times f

A simple calibration exercise

What does the data say?

  • Data:
    • Goal: provide a flavor/established stylized facts/indication of the real costs
    • two weeks in January 2020 for USDT-USDC, USDT-ETH, USDT-wBTC
  • What is \(\kappa\)?
    • Babcock, Choi, and Eli Feinerman (1993) (Table 1): between .00001 and 0.5
    • most values at the small end of the spectrum\(\to\kappa= 0.0005\).
  • Rest?
    • Use crypto to stablecoin (aka "money")
    • \(V=\) "average price"
    •  \(\sigma\) price volatility
    • \(X\) the quantity of crypto in a contract in USD
  • And then?
    • How much more do people pay because of constant product pricing?
    • How much is the (hypothetical) no-front-running fee?

A simple calibration exercise

What does the data say?

What have we learned?

Summing up

  • With mempools, front-running is always a possibility
    • \(\Rightarrow\) must avoid design that makes it intrinsically profitable
    • \(\Rightarrow\) most swap exchanges make it so! (fees are only a band-aid)
  • There is also
    • ping-pong trading
    • rule is ad hoc and nothing says that it has any relationship to demand and supply
  • Empirically, mempool arbitrage and gas auctions push up gas costs to astronomical levels.
  • There is a better way:
    • correctly designed "linear" (marginal) pricing makes front-running and ping-pong trading unprofitable 
    • \(\Rightarrow\) there is merit to traditional economic thinking even in DeFi \(\ldots\)

@financeUTM

andreas.park@rotman.utoronto.ca

slides.com/ap248

sites.google.com/site/parkandreas/

youtube.com/user/andreaspark2812/

Conceptual Flaws of Constant Product Market Makers

By Andreas Park

Conceptual Flaws of Constant Product Market Makers

  • 682