Andreas Park PRO
Professor of Finance at UofT
Andreas Park
Goal of this class
Why care about Decentralized Trading?
Traditional Markets
What is Market Microstructure?
There are many ways to arrange trading
central limit order book
centralized auction
bilateral
negotiation
Request
for Quote
open
outcry
How hard is it to organize trading?
central limit order book
operational complexity
centralized auction
bilateral
negotiation
Request
for Quote
open
outcry
Do you know who you are trading with?
central limit order book
operational complexity
centralized auction
bilateral
negotiation
Request
for Quote
open
outcry
little
a lot
How good is the arrangement at discovering the market price?
central limit order book
operational complexity
centralized auction
bilateral
negotiation
Request
for Quote
open
outcry
bad
good
CoW? \(\to\) Liquidity Provision
For all practical purposes, modern electronic markets are organized as limit order books
a person wants to buy \(x\) shares up to price \(p\)
For all practical purposes, modern electronic markets are organized as limit order books
quantity
price
\(Q\)
\(p(Q)\)
\(P^{\mathsf{dp}}(Q)=\int_0^Qp(q)~dq\)
a person wants to buy \(x\) shares up to price \(p\)
Some first principles insights
quantity
price
\(Q\)
\(p(Q)\)
\(P^{\mathsf{dp}}(Q)=\int_0^Qp(q)~dq\)
How can the liquidity provider survive?
{
{
the bid ask spread
Idea: earn the bid ask spread sufficiently often
every microstructure model has some form of compensation for liquidity provision
Super-quick overview over seminal papers
TradFi vs Crypto Trading
What makes DeFi different from TradFi?
{
{
features
consequences
Could this give us Fisher Black's vision of a fully automated stock exchange?
Actually ...
What would a minimalist automated market look like?
Changes to liquidity
Requirements on the marginal price
These minimal requirements define a pricing rule
Proposition: Consider an automated market with liquidity deposits in cash \(c>0\), asset \(a>0.\) Costs for a trade of \(q<a\) is defined by a function \(C(q):=\Delta c(q)\) that satisfies a boundary and monotonicity conditions \(C(0)=0,\;C(q)>0,\;C'(q)>0\) as well as spot–marginal consistency \( C'(q)=\frac{c+C(q)}{a-q}\qquad(0\le q<a).\) Then the trading costs in this automated market is uniquely defined by
\[\Delta c(q)=q\cdot\frac{c}{a-q}~~\text{ so that }~~\Delta c'(q)=\frac{ac}{(a-s)^2}.\]
This pricing rule has a limit order book interpretation:
\[\Delta c(q)=\int_0^q \Delta c'(s)ds=\int_0^q \rho(s) ds=\int_0^q \frac{ac}{(a-s)^2} ds=q\cdot\frac{c}{a-q}.\]
A few observations
Decentralized Trading
Broker
Exchange
Internalizer
Wholeseller
Darkpool
Venue
Settlement
The Basic Organization of the Market
Liquidity providers
Liquidity demander
Liquidity Pool
AMM pricing is mechanical:
No effect on the marginal price
Most Common Pricing Rule in DeFi: Constant Product
Most Common Pricing Rule in DeFi: Constant Product
Insight: AMM pricing function is the same as a limit order book when we require
The Pricing Function
An Alternative Pricing Function
Some Pricing Rules from Traditional Markets: Uniform Price
\(q=2\)
\(\Delta c(q)= q\times p^m(q)=2\times 15.5\)
Some insights on pricing functions
UniSwap v3
UniSwap v3 has "concentrated liquidity provision"
Just a little more institutional details
users submit liquidity positions \((u,d,p_u,p_d)\) and receive an ERC-721 (=NFT) token as a receipt
the code segments liquidity into discrete exponential intervals \([p_k,p_{k+1}]\) with \[p_k=(1+\delta)^k. ~~~(\text{numerically: }p(k)=1.0001^k)\]
it aggregates liquidity over these intervals
the pricing curve for each interval is determined by the constant product rule
intervals may be "empty"
How the price is determined
where \(\tilde{a}\) is the virtual liquidity
quick disclaimer: what follows is not how UniSwap is explained on its website etc. But the resulting maths are the same
\(p_d\)
\(p_u\)
\(p_0\)
UniSwap v3: An Example
\(p_u=15\)
\(p_d=7\)
\(u=2\)
\(p_0=10\) (that's exogenous, not a choice)
marginal price
\[\gamma(s)=\frac{\tilde{a}c}{(\tilde{a}-s)^2}.\]
Finding virtual liquidity factor \(\tilde{a}\)
marginal price
\[\gamma(s)=\frac{\tilde{a}c}{(\tilde{a}-s)^2}.\]
\(p_u=15\)
\(p_d=7\)
\(u=2\)
\(p_0=10\) (that's exogenous, not a choice)
= find the right curve
= find the right "\(\tilde{a}\)"
= find \(\tilde{a}\) such that \[\gamma(u)=p_u\]
Finding the fourth parameter \(\Delta c(d)\)
\(p_u=15\)
\(p_d=7\)
\(u=2\)
\(d=?\)
required cash deposit \(\Delta c(d)=\) the amount that I pay for \(d\)
marginal price
\[\gamma(s)=\frac{\tilde{a}c}{(\tilde{a}-s)^2}.\]
Given \(\tilde{a}\) solves \(\gamma(u)=p_u\), we
Solutions
For those in the know: These formulae/solutions are exactly the same as those in the UniSwap v3 whitepaper
Numerical example
Want to read more?
Liquidity Supply and Demand in an Automated Market Maker
Facts about modelling liquidity provision
Each case has a different interpretation and each has been used in some form in the literature.
Key questions:
Two broad approaches for modelling liquidity provision
You worry about the positional loss relative to any income.
You worry whether you can rebalance your liquidity profitably.
(im)permanent loss
"LVR" = loss-vs-rebalancing
Provide-and-Forget Liquidity Provision (HODL)
Buy and hold
Provided liquidity
in the pool
Provide-and-Forget Liquidity Provision
\[\underbrace{F \int DV \mu(DV) }_{\text{fees earned on}\atop \text{balanced flow}}+\int_0^\infty\underbrace{(\Delta c(q^*)-q^*p_t(R)}_{\text{adverse selection loss} \atop \text{when the return is {\it R}}} +\underbrace{F \cdot \Delta c(q^*))}_{\text{fees earned}\atop \text{from arbitrageurs}}~\phi(R)dR \ge 0.\]
\(q^* \) is what arbitrageurs trade to move the price to reflect \(R\)
Basic idea of liquidity provision: earn more on balanced flow than what you lose on price movement
\[\text{fee income} +\underbrace{\text{what I sold it for}-\text{value of net position}}_{\text{adverse selection loss}} \ge \text{cost of capital} \]
in AMMs:
protocol fee
in tradFi: bid-ask spread
Sidebar: we can quantify how much a PASSIVE LP loses when the price moves by \(R\)
for orientation:
\[\frac{\text{adverse selection loss when the return is \(R\)}}{\text{initial deposit}}=\sqrt{R}-\frac{1}{2}(R+1)\]
see Barbon & Ranaldo (2022)
adverse selection loss
(or: impermanent loss)
Liquidity Demander's Decision & (optimal) AMM Fees
Result:
competitive liq provision\(\to\) there exists an optimal (min trading costs) fee \(>0\)
Similar to Lehar&Parlour (2023) and Hasbrouck, Riviera, Saleh (2023)
\[F^\pi=\frac{1}{E[|\sqrt{R}-1|/2]+V}\left(-2q\ E[\text{position loss}]+ \sqrt{-2qV\ E[\text{position loss}]}\right).\]
assume: liquidity providers add liquidity until they break even in expectation
Liquidity Provision as Options
Ciamac Moallemi will explain details later!
Empirical Work
Lehar and Parlour (2021)
Barbon & Ranaldo (2023)
Other notables:
Malinova & Park (2023): AMM applied to equities would reduce trading costs by 30%
Concerns around Automated Market Makers
a
b
c
d
e
f
g
Problem 1: Sandwich (MEV) attacks
related paper: “Maximal Extractable Value and Allocative Inefficiencies in Public Blockchains”. A. Capponi, R. Jia, and Y. Wang (2023)
NB: PBS does not solve the problem
a
b
c
d
e
f
g
Problem 2: Arbitrage Trades that Reduce LVR
PBS creates the problem
builder/searcher
Problem 3a: Just-In-Time Liquidity (single trade cream skimming)
X-Router
Liquidity pool
OTC
Problem 3b: Just-In-Time Liquidity (at the builder/MEV level)
X-Router
Liquidity pool
searcher/builder
balanced orders
add as much liquidity as possible
withdraw liquidity
unbalanced orders
related paper: Capponi, Jia, and Zhu (2024) "The Paradox of Just-in-Time Liquidity in Decentralized Exchanges: More Providers Can Lead to Less Liquidity"
Other things
The Bigger Picture and Last Words
Last Words
@financeUTM
andreas.park@rotman.utoronto.ca
slides.com/ap248
sites.google.com/site/parkandreas/
youtube.com/user/andreaspark2812/
By Andreas Park