Finance:Constant function market maker

From HandWiki
Short description: Type of market maker

Constant-function market makers (CFMM) are a paradigm in the design of trading venues where a trading function and a set of rules determine how liquidity takers (LTs) and liquidity providers (LPs) interact, and how markets are cleared. The trading function is deterministic and known to all market participants.

CFMMs display pools of liquidity of two assets. The takers and providers of liquidity interact in the liquidity pools: LPs deposit their assets in the pool and LTs exchange assets directly with the pool. CFMMs rely on two rules; the LT trading condition and the LP provision condition.[1] The LT trading condition links the state of the pool before and after a trade is executed, and it determines the relative prices between the assets by their quantities in the pool.[2] The LP provision condition links the state of the pool before and after liquidity is deposited or withdrawn by an LP. Thus, the trading function establishes the link between liquidity and prices, so LTs can compute the execution costs of their trades as a function of the trade size, and LPs can compute the exact quantities that they deposit. In CFMMs, both conditions state that price formation happens only through LT trades (see below).

In decentralized platforms running on peer-to-peer networks, CFMMs are hard-coded and immutable programs implemented as Smart Contracts,[3] where LPs and LTs invoke the code of the contract to execute their transactions. A particular case of CFMMs are the constant product market makers (CPMMs) such as Uniswap v2 and Uniswap v3 where the trading function uses the product of the quantities of each asset in the pool to determine clearing prices. CFMMs are also popular in prediction markets.[4]

Definition

Trading function

Consider a reference asset [math]\displaystyle{ X }[/math] and an asset [math]\displaystyle{ Y }[/math] which is valued in terms of [math]\displaystyle{ X }[/math]. Assume that the liquidity pool of the CFMM initially consists of quantity [math]\displaystyle{ x }[/math] of asset [math]\displaystyle{ X }[/math] and quantity [math]\displaystyle{ y }[/math] of asset [math]\displaystyle{ Y }[/math]. The pair [math]\displaystyle{ (x, y) }[/math] is referred to as the reserves of the pool (the following definitions can be extended to a basket of more than two assets[5]). The CFM is characterised by a trading function [math]\displaystyle{ f : \mathbb{R}_{++} \times \mathbb{R}_{++} \rightarrow \mathbb{R} }[/math] (also known as the invariant) defined over the pool reserves [math]\displaystyle{ x }[/math] and [math]\displaystyle{ y }[/math]. The trading function is continuously differentiable and increasing in its arguments ([math]\displaystyle{ \mathbb{R}_{++} }[/math] denotes the set of positive real numbers).

For instance, the trading function of the constant product market maker (CPMM) is [math]\displaystyle{ f(x,y)=x\times y }[/math]. Other types of CFMMs are the constant sum market maker with [math]\displaystyle{ f(x,y) = x+y }[/math]; the constant mean market maker with [math]\displaystyle{ f(x,y) = w_x x + w_y y }[/math], where [math]\displaystyle{ w_x, w_y \gt 0 }[/math] and [math]\displaystyle{ w_x + w_y = 1 }[/math]; and the hybrid function market maker, which uses combinations of trading functions.

LT trading condition and convexity

LT transactions involve exchanging a quantity [math]\displaystyle{ \Delta^y }[/math] of asset [math]\displaystyle{ Y }[/math] for a quantity [math]\displaystyle{ \Delta^x }[/math] of asset [math]\displaystyle{ X }[/math], and vice-versa. The quantities to exchange are determined by the LT trading condition:

(1) [math]\displaystyle{ f(x,y) = f(x+ \Delta^x, y - \Delta^y) = \kappa\,, }[/math]

where [math]\displaystyle{ \kappa }[/math] is the depth of the pool[2] (see the LP provision condition below) and is a measure of the available liquidity. The value of the depth [math]\displaystyle{ \kappa \gt 0 }[/math] is constant before and after a trade is executed, so the LT trading condition (1) defines a level curve. For a fixed value of the depth [math]\displaystyle{ \kappa }[/math], the level function [math]\displaystyle{ \varphi_{\kappa} }[/math] (also known as the forward exchange function [5]) is such that [math]\displaystyle{ f(x,y) = \kappa^2 \iff x=\varphi_{\kappa}(y) }[/math]. For any value [math]\displaystyle{ \kappa }[/math] of the depth, the level function [math]\displaystyle{ \varphi_{\kappa}: \mathbb R_{++} \mapsto \mathbb R_{++} }[/math] is twice differentiable.[6]

The LT trading condition (1) links the state of the pool before and after a liquidity taking trade is executed. For LTs, this condition specifies the exchange rate [math]\displaystyle{ \tilde Z(\Delta^y) }[/math], of asset [math]\displaystyle{ Y }[/math] in terms of the reference asset [math]\displaystyle{ X }[/math], to trade a (possibly negative) quantity [math]\displaystyle{ \Delta^y }[/math] of asset [math]\displaystyle{ Y }[/math]:

[math]\displaystyle{ \tilde Z(\Delta^y) = \left(\varphi_\kappa\left(y\right)-\varphi_\kappa\left(y+\Delta^y\right)\right)\big / \Delta^y\,. }[/math]

The marginal exchange rate of asset [math]\displaystyle{ Y }[/math] in terms of asset [math]\displaystyle{ X }[/math], akin to the midprice in a limit order book (LOB), is the price for an infinitesimal trade in a CFMM:

[math]\displaystyle{ Z = \lim_{\Delta^y \rightarrow 0} \tilde Z(\Delta^y) = -\varphi'_{\kappa}(y). }[/math]

It is proven that no roundtrip arbitrage in a CFMM implies that the level function [math]\displaystyle{ \varphi }[/math] must be convex.[1]

Execution costs in the CFMM are defined as the difference between the marginal exchange rate and the exchange rate at which a trade is executed. It has been shown that LTs can use the convexity of the level function around the pool's reserves level to approximate the execution costs [math]\displaystyle{ \left|\tilde Z(\Delta^y) - Z\right| }[/math] by [math]\displaystyle{ \frac12\,\varphi_\kappa^{''}(y) \left|\Delta^y\right| }[/math].[2]


LP provision condition and homotheticity

LP transactions involve depositing or withdrawing quantities [math]\displaystyle{ (\Delta^x, \Delta^y) }[/math] of asset [math]\displaystyle{ X }[/math] and asset [math]\displaystyle{ Y }[/math]. Let [math]\displaystyle{ \kappa_0 }[/math] be the initial depth of the pool and let [math]\displaystyle{ \kappa_1 }[/math] be the depth of the pool after an LP deposits [math]\displaystyle{ \Delta^x, \Delta^y }[/math], i.e., [math]\displaystyle{ f(x , y ) = \kappa_0^2 }[/math] and [math]\displaystyle{ f(x + \Delta x, y + \Delta y) = \kappa_1^2 }[/math]. Let [math]\displaystyle{ \varphi_{\kappa_0} }[/math] and [math]\displaystyle{ \varphi_{\kappa_1} }[/math] be the level functions corresponding to the values [math]\displaystyle{ \kappa_0 }[/math] and [math]\displaystyle{ \kappa_1 }[/math], respectively. Denote by [math]\displaystyle{ Z }[/math] the initial marginal exchange rate of the pool. The LP provision condition requires that LPs do not change the marginal rate [math]\displaystyle{ Z }[/math], so

(2) [math]\displaystyle{ -\varphi'_{\kappa_0}\left(y\right) = -\varphi'_{\kappa_1}\left(y + \Delta^y\right)=Z\,. }[/math]

The LP provision condition (2) links the state of the pool before and after a liquidity provision operation is executed. The trading function [math]\displaystyle{ f(x,y) }[/math] is increasing in the pool reserves [math]\displaystyle{ x }[/math] and [math]\displaystyle{ y. }[/math] So, when liquidity provision activity increases (decreases) the size of the pool, the value of the pool's depth [math]\displaystyle{ \kappa }[/math] increases (decreases). The value of [math]\displaystyle{ \kappa }[/math] can be seen as a measure of the liquidity depth in the pool. Note that the LP provision condition holds for any homothetic trading function.

Constant Product Market Maker

In CPMMs such as Uniswap v2, the trading function is [math]\displaystyle{ f\left(x, y\right) = x\times y, }[/math] so the level function is [math]\displaystyle{ \varphi\left(y\right) = \kappa^2 \big / y }[/math], the marginal exchange rate is [math]\displaystyle{ Z = x / y, }[/math] and the exchange rate for a quantity [math]\displaystyle{ \Delta^y }[/math] is [math]\displaystyle{ \tilde Z\left(\Delta^y\right) = Z - Z^{3/2} \Delta^y \big / \kappa. }[/math]

In CPMMs, the liquidity provision condition is [math]\displaystyle{ x/y = (x+ \Delta^x)/(y+ \Delta^y) }[/math] when the quantities [math]\displaystyle{ (\Delta^x,\Delta^y) }[/math] are deposited to the pool. Thus, liquidity is provided so that the proportion of the reserves [math]\displaystyle{ x }[/math] and [math]\displaystyle{ y }[/math] in the pool is preserved. [2]

Profits and losses of liquidity providers

Fees

For LPs, the key difference between the traditional markets based on LOBs and CFMMs is that in LOBs, market makers post limit orders above and below the mid-price to earn the spread on roundtrip trades, while in CFMMs, LPs earn fees paid by LTs when their liquidity is used.

Loss-Versus-Rebalancing

Without fees paid by LTs, liquidity provision in CFMMs is a loss-leading activity. Loss-Versus-Rebalancing (LVR) is a popular measure of these losses.[7] Assume the price follows the dynamics [math]\displaystyle{ dS_t = \sigma_t dW_t }[/math] then the LVR is given by [math]\displaystyle{ \text{LVR}_{t}=-\frac{1}{2}\int_{0}^{t}\,\sigma_s^2\,\text{d}s \,\leq 0\,. }[/math]

Predictable loss

To thoroughly characterise their losses, LPs can also use Predictable Loss (PL), which is a comprehensive and model-free measure for the unhedgeable and predictable losses of liquidity provision.[1] One source of PL is the convexity cost (losses due to adverse selection, they can be regarded as generalized LVR) whose magnitude depends on liquidity taking activity and the convexity of the level function. The other source is the opportunity cost, which is incurred by LPs who lock assets in the pool instead of investing them in the risk-free asset. For an LP providing reserves [math]\displaystyle{ (x_0, y_0) }[/math] at time [math]\displaystyle{ t=0 }[/math] and withdrawing liquidity at time [math]\displaystyle{ T \gt 0 }[/math], PL is

[math]\displaystyle{ \text{PL}_{T}= -\,\,\underbrace{\frac{1}{2}\int_{0}^{T}\,\varphi''\left(y_{s}\right)\,\text{d}\left\langle y,y\right\rangle_{s}\,}_{\text{Convexity cost}\,\geq\,0} \,\,-\,\, \underbrace{\int_{0}^{T}\xi_s\,r\,\text{d}s \,}_{\text{Opportunity cost}\,\geq\,0} \,, }[/math]

where [math]\displaystyle{ \left(\xi_t\right)_{t\in[0, T]} }[/math] is an increasing stochastic process with initial value [math]\displaystyle{ 0 }[/math], and [math]\displaystyle{ \left(y_t\right)_{t\in[0, T]} }[/math] is a process that describes the reserves in asset [math]\displaystyle{ Y }[/math]. In particular, [math]\displaystyle{ \text{PL} }[/math] satisfies

[math]\displaystyle{ \text{PL}_{t}\leq-\frac{1}{2}\int_{0}^{t}\,\varphi''\left(y_{s}\right)\,\text{d}\left\langle y,y\right\rangle_{s} \,\leq 0\,. }[/math]

PL can be estimated without specifying dynamics for the marginal rate or the trading flow[8] and without specifying a parametric form for the level function. PL shows that liquidity provision generates losses for any type of LT trading activity (informed and uninformed). The level of fee revenue must exceed PL in expectation for liquidity provision to be profitable in CFMMs.

Impermanent loss

Impermanent loss, or divergence loss, is sometimes used to characterise the risk of providing liquidity in a CFMM.[9] Impermanent loss compares the evolution of the value of the LP's assets in the pool with the evolution of a self-financing buy-and-hold portfolio invested in an alternative venue. The self-financing portfolio is initiated with the same quantities [math]\displaystyle{ \left(x_0, y_0\right) }[/math] as those that the LP deposits in the pool. It can be shown that the impermanent loss [math]\displaystyle{ \text{IL}_t }[/math] at time [math]\displaystyle{ t\gt 0 }[/math] is

[math]\displaystyle{ \text{IL}_t = \ -\left(\varphi\left(y_0\right)-\varphi\left(y_{t}\right)-\varphi'(y_{t})\left(y_0-y_{t}\right)\right) }[/math]

where [math]\displaystyle{ y_t }[/math] are the reserves in asset [math]\displaystyle{ Y }[/math] in the pool at time [math]\displaystyle{ t }[/math].

The convexity of the level function shows that [math]\displaystyle{ \text{IL}_t \leq 0 }[/math]. In the case of CPMMs, the impermanent loss is given by

[math]\displaystyle{ \text{IL}_t = -\kappa\,\sqrt{Z_t}\left(1-\sqrt{\frac{Z_{t}}{Z_0}}\right)^{2}\leq 0\,. }[/math]

where [math]\displaystyle{ Z_t }[/math] is the marginal exchange rate in the CPMM pool at time [math]\displaystyle{ t }[/math].

[math]\displaystyle{ \text{IL} }[/math] is not an appropriate measure to characterise the losses of LPs because it can underestimate or overestimate the losses that are solely imputable to liquidity provision. More precisely, the alternative buy-and-hold portfolio is not exposed to the same market risk as the holdings of the LP in the pool, and the impermanent loss can be partly hedged. In contrast, PL is the predictable and unhedgeable component in the wealth of LPs.[1]

Concentrated liquidity

Concentrated liquidity is a feature introduced by Uniswap v3 for CPMMs. The key feature of a CPMM pool with CL is that LPs specify a range of exchange rates in which to post liquidity. The bounds of the liquidity range take values in a discretised finite set of exchange rates called ticks. Concentrating liquidity increases fee revenue, but also increases PL and concentration risk, i.e., the risk of the exchange rate exiting the range.[10]

History

An early description of a CFMM was published by economist Robin Hanson in "Logarithmic Market Scoring Rules for Modular Combinatorial Information Aggregation" (2002).[11] Early literature referred to the broader class of "automated market makers", including that of the Hollywood Stock Exchange founded in 1999; the term "constant-function market maker" was introduced in "Improved Price Oracles: Constant Function Market Makers" (Angeris & Chitra 2020).[12] First be seen in production on a Minecraft server in 2012,[13] CFMMs are a popular DEX architecture.

Crowdfunded CFMMs

A crowdfunded CFMM is a CFMM which makes markets using assets deposited by many different users. Users may contribute their assets to the CFMM's inventory, and receive in exchange a pro rata share of the inventory, claimable at any point for the assets in the inventory at that time the claim is made.[3]

Examples

  • Uniswap [math]\displaystyle{ \varphi = R_1 * R_2 }[/math]
  • RMM-01 [math]\displaystyle{ \varphi = -K\Phi(\Phi^{-1}(1-R_1)-\sigma\sqrt{\tau}) + R_2 }[/math]
  • PMMP [math]\displaystyle{ \varphi = R_{1}-\left(p_{1}-\frac{1}{2}R_{2}\right)^{2} }[/math]
  • StableSwap [math]\displaystyle{ \varphi = R_1 + R_2 }[/math]

References

  1. 1.0 1.1 1.2 1.3 Template:Cite SSRN
  2. 2.0 2.1 2.2 2.3 Template:Cite SSRN
  3. 3.0 3.1 Schär, Fabian (Apr 15, 2021). "Decentralized Finance: On Blockchain- and Smart Contract-Based Financial Markets". Federal Reserve Bank of St. Louis Review 103 (2). doi:10.20955/r.103.153-74. https://research.stlouisfed.org/publications/review/2021/02/05/decentralized-finance-on-blockchain-and-smart-contract-based-financial-markets. 
  4. Othman, Abraham; Pennock, David; Reeves, Daniel; Sandholm, Thomas (Sep 2013). "A Practical Liquidity-Sensitive Automated Market Maker". ACM Transactions on Economics and Computation 1 (3): 1–25. doi:10.1145/2509413.2509414. https://www.cs.cmu.edu/~sandholm/liquidity-sensitive%20automated%20market%20maker.teac.pdf. 
  5. 5.0 5.1 Angeris, Guillermo; Agrawal, Akshay; Evans, Alex; Chitra, Tarun; Boyd, Stephen (2021). "Constant Function Market Makers: Multi-Asset Trades via Convex Optimization". arXiv:2107.12484 [math.OC].
  6. Angeris, Guillermo; Evans, Alex; Chitra, Tarun (2021). "Replicating Market Makers". arXiv:2103.14769 [q-fin.MF].
  7. Milionis, Jason; Moallemi, Ciamac; Roughgarden, Tim; Zhang, Anthony Lee (2022). "Automated market making and loss-versus-rebalancing". arXiv:2208.06046 [q-fin.MF].
  8. Barndorff-Nielsen, Ole; Shephard, Neil (2002). "Estimating quadratic variation using realized variance". Journal of Applied Econometrics 17 (5): 457-477. doi:10.1002/jae.691. http://www.nuffield.ox.ac.uk/economics/papers/2001/w20/jae.pdf. 
  9. Fukasawa, Masaaki; Maire, Basile; Wunsch, Marcus (2023). "Weighted variance swaps hedge against impermanent loss". Quantitative Finance 23 (6): 901–911. doi:10.1080/14697688.2023.2202708. 
  10. Cartea, Álvaro; Drissi, Fayçal; Monga, Marcello (10 November 2022). Decentralised Finance and Automated Market Making: Predictable Loss and Optimal Liquidity Provision. doi:10.2139/ssrn.4273989. 
  11. Hanson, Robin (Dec 13, 2012). "Logarithmic markets coring rules for modular combinatorial information aggregation". The Journal of Prediction Markets 1 (1): 3–15. doi:10.5750/jpm.v1i1.417. https://mason.gmu.edu/~rhanson/mktscore.pdf. 
  12. Angeris, Guillermo; Chitra, Tarun (26 October 2020). "Improved Price Oracles: Constant Function Market Makers". Proceedings of the 2nd ACM Conference on Advances in Financial Technologies. pp. 80–91. doi:10.1145/3419614.3423251. ISBN 9781450381390. 
  13. "HyperConomy". https://github.com/patrick-layden/HyperConomy.