Abstract
Automated market making for crypto tokens is an extremely attractive and efficient way to establish decentralized exchanges. An inevitable prerequisite for this type of market is the willingness of participants to provide liquidity. Except in the case of two correlated pairs, providing liquidity is often sub-optimal. In fact, one often faces significant opportunity cost commonly referred to as impermanent loss. Prevailing transaction fee levels, even with levered positions, are often insufficient to compensate for the opportunity costs incurred. Marketability and exchangeability are essential prerequisites for attributing value to many crypto tokens. Therefore, when issuing fiat tokens for the viability of intriguing business models, one ends up with the chicken-or-the-egg causality dilemma; how to achieve sustainable incentives to the liquidity provision for an abstract good whose intrinsic value is defined solely by that liquidity system? This article derives and discusses useful formulas for the quantitative risk management in the context of automated market makers. In addition, order size and pool size-dependent transaction costs are proposed that may incentivize the desired level of liquidity.
Similar content being viewed by others
Avoid common mistakes on your manuscript.
1 Introduction
Central limit order books (CLOBs) are not ideal for decentralized exchanges (DEXs), which run on blockchains. The gas fees tend to be prohibitively expensive for this setup which usually has an ongoing stream of adjustments by the market makers. Consequently, automated market makers (AMMs) are an important feature of DEXs. Currently, these are typically implemented as constant function market makers (CFMM), which calculate an invariant value from the two or more token elements in the DEX; see also Angeris et al. (2023), and Cartea et al. (2023) for market maker designs beyond constant functions. CFMMs usually hold liquidity pools in the traded tokens, and these pools act as counterparties to anyone interacting with the DEX. Arbitrageurs would then make profitable follow-up trades, which reset the liquidity pools to the current market price. DEXs typically charge a transaction feeFootnote 1 of 0.15–0.35% on trades, and some or all of this fee ends up with the liquidity providers. In the Decentralized Finance (DeFi) summer of 2020, so-called yield farming became popular, and liquidity providers could earn additional returns by allocating newly created governance tokens; see Cousaert et al. (2022). This allocation can work to kick-start a project, but it is not a means which is medium-term sustainable, as the tokens will only retain value if their volume remains constrained. The most popular of these CFMMs is the constant product market maker (CPMM), which uses the product of the volumes of the two or more tokens involved as the invariant. The CPMM setup is simple; it is self-balancing through arbitrageurs, requires no active involvement from liquidity providers, and has low computational demands, making it suitable for a smart contract on a blockchain. However, it is not ideal either. It is capital intensive, exposes the liquidity providers to opportunity costs, and overall return-on-investments may range from fair to unacceptably bad once the yields from yield farming run out. The most commonly associated opportunity cost for CPMMs is called impermanent loss. This terminology can however be misleading as the corresponding loss rarely ever disappears in practice. Xu et al. (2023) therefore argues that the term divergence lossFootnote 2 would be more accurate for a scientific context. To generate a solid framework to investigate these problems further, we derive the formulas which apply in this context and look at some aspects in detail; we focus mainly on CPMM. In the mathematical treatment, we ignore gas fees and disregard the possibility of so-called maximum/miner extractable value attacks (MEV attacks), which correspond to a form of front running; see also Daian et al. (2020). Some aspects may be counterintuitive or tricky, although we basically only need elementary mathematics throughout the article. Topics covered include the following:
-
We investigate in the Sects. 2.2 and 3.2 the impact of transaction cost as they are commonly implemented in DeFi applications.
-
We show in the Sect. 3.3 how to exploit arbitrage opportunities in unbalanced liquidity pools.
-
We valuate in the Sect. 3.4 the hedging of the impermanent loss. We demonstrate that hedging the impermanent loss may be quite expensive and that prevalent risk compensations for CPMMs are likely too low.
-
We solve in the Sect. 3.8 an inverse problem such that one can rely on classical FX-rate dynamics in order to simulate consistent roll-forwards of liquidity pools. This is particularly relevant for risk management purposes. The publicly accessible Jupyter notebook illustrates an implementation in Python.
-
We elaborate in the Sect. 3.9 that absolute hedging for flat inventories is not a feasible option for liquidity providing. The costs are comparable to hedging the impermanent loss.
-
We propose in the Sect. 3.10order size as well as pool size dependent transaction cost, which may incentivize the desired levels of liquidity.
-
We derive in the Sect. 3.11 the optimal trade execution for different situations.
-
We tackle in the Sect. 3.12 an analytical argument of noise trades.
-
In the appendix, we briefly look at variations of the CPMM framework, namely Uniswap v3, Balancer, and Flat Curve.
AMM is an emerging field of application and research. There are already a number of publications in this regard; e.g., see Mohan (2022) for a comprehensive introduction and further references. There are also numerous pertinent blogs. Some of our discussion points are treated in greater generality in Cartea et al. (2022b). To the best of our knowledge, particularly the considerations of the Sects. 3.6–3.10 have not yet been addressed conclusively elsewhere.
2 Constant function market maker (CFMM)
2.1 Notation
Notation | Description |
---|---|
\(F(x,y)\equiv c\) | Isoline(s) of the liquidity pool |
f(x) | Explicit solution \(y=f(x)\) of the implicit equation \(F(x,y)=c\) |
\(x_t>0\) | Amount of the first token denoted by X (e.g., XTZ) at time t |
\(y_t>0\) | Amount of the second token denoted by Y (e.g., YOU) at time t |
\(c_t=F(x_t,y_t)\) | Available liquidity at time t |
\(S_t=\dfrac{F_x(x_t,y_t)}{F_y(x_t,y_t)}=-f'(x_t)\) | Implied spot FX-rate (e.g., XTZYOU) at time t, i.e., the value of 1 token X denominated in Y |
\(S_t^x>0\) | Value of 1 token X with respect to some numéraire (e.g., USD) at time t |
\(S_t^y>0\) | Value of 1 token Y with respect to the same numéraire at time t |
\(0\le \kappa _1<1\) | Transaction fee of the infrastructure provider |
\(0\le \kappa _2<1\) | Transaction fee of the liquidity pool |
\(0\le \kappa :=\kappa _1+\kappa _2<1\) | Total transaction fees |
XTZ is the native token of the Tezos blockchain. YOU is the governance token of the youves ecosystem. We use these two tokens to illustrate the two generic placeholders X and Y; see also the schematic chart in the Fig. 1 for a better understanding. All quantities with a subscript t represent càdlàg stochastic processes in continuous time.
2.2 Methodology
There are no fees for posting or withdrawing liquidity. If one exchanges X for Y, or vice versa, via the liquidity pool, one basically does not leave the current isoline from the implicit function definition (modulo transaction fees). Generally speaking, one has to bear a transaction fee of, e.g., \(\kappa =0.35\%\) (excluding gas fees). In fact, things are a bit more involved. On the one hand, the fee consists of a service fee, e.g., \(\kappa _1=0.10\%\) that leaves the pool and rewards the liquidity pool provider. On the other hand, it consists of a \(\kappa _2=0.25\%\) liquidity fee that remains in the pool and remunerates the liquidity providers. For illustration, e.g., see Plenty, Quipuswap.
Definition 1
Let us assume that a market participant initiates a swap at time t by posting \(\Delta x\) of X to the liquidity pool. In return, she receives \(-\Delta y(\Delta x)\) of Y (the sign is by convention), where \(\Delta y(\Delta x)<0\) solves the equation
One part of the transaction fees is paid implicitly to the pool by increasing the liquidity to the updated isoline
The residual part \(\kappa _1\Delta x\) is paid out to the infrastructure provider and leaves our consideration. Analogously, if \(\Delta y\) of Y is posted to the liquidity pool for \(-\Delta x(\Delta y)\) of X in return, the corresponding equation reads
Similarly,
refers to as the updated liquidity level.
Fees are always paid in the posted currency that devaluates. As we shall see, the market impact of transactions is often much greater than the impact of common transaction costs. The superscripts «pre» and «post» indicate that a transaction is taking place at this time instance. Alternatively, one could use another common notation \(x_{t\text{--}}:=x_t^\text{pre}\) and \(x_{t}:=x_t^\text{post}\).
2.3 Consistency of the FX rates
By absence of arbitrage (and by neglecting transaction costs for the sake of simplicity), the parity \(S_t^x=S_tS_t^y\) must prevail. Any discrepancy can theoretically be exploited or constitutes an illiquidity premium. The spot FX-rate \(S_t\) changes with each swap. For the remainder of the article, we tacitly assume without loss of generality that the stochastic rate \(S_t^x\) is given exogenously and that it is not affected by swaps within the liquidity pool. Equivalently, the token X is comparatively liquid, and the size of the liquidity pool is negligible with respect to the total outstanding amount of X. Later on, we will need to distinguish two limiting cases depending on whether the CFMM is just a marketplace (Sect. 3.5) or the market (Sect. 3.6).
Assumption 2
We assume that \((S_t^x)_{t\ge 0}\) is independent of \((y_t)_{t\ge 0}\).
3 Constant product market maker (CPMM)
3.1 Model
Definition 3
F simply is the product of the two components, i.e.,
The involved isolines are hyperbolas. The spot FX-rate is given by
Definition 3 is a popular choice. There are various modifications, e.g., Uniswap v3 (see the section A in the appendix) with leveraged positions, or Balancer (see the section B) involving \(n>2\) assets. With the standard approach, the FX rate changes instantaneously with every transaction. In the context of stable token pairs, other CFMM approaches with less susceptibility toward medium-sized transactions are more suitable, e.g., see the section C for an applicable alternative.
3.2 Dynamics of the liquidity pool
3.2.1 Case of posting X
If one intends to withdraw the target amount \(\Delta y\in(0,y_t^\text{pre})\) of Y, then the required posting of X amounts to
Generally, posting \(\Delta x>0\) of X leads in the liquidity pool to an outflow of
in Y. On the isolated level of the liquidity pool, X devaluates while Y appreciates. The realized FX rate of the trade amounts to
The subsequent state of the liquidity pool consists of the components
\({{\widetilde{S}}_t(\Delta x)\in \big (S_t^\text{post}(\Delta x),S_t^\text{pre}\big )}\) holds, provided that the posted amount is sufficiently large, namely
compare (9) and (12). Otherwise, it even holds \({\widetilde{S}}_t(\Delta x)\le S_t^\text{post}(\Delta x)<S_t^\text{pre}\). If \(\kappa =0\), then \({{\widetilde{S}}_t(\Delta x)}\) is the geometric mean of \(S_t^\text{post}(\Delta x)\) and \(S_t^\text{pre}\).
3.2.2 Case of posting Y
If one intends to withdraw the target amount \(\Delta x\in(0,x_t^\text{pre})\) of X, then the required posting of Y amounts to
Generally, posting \(\Delta y>0\) of Y leads in the liquidity pool to an outflow of
in X. On the isolated level of the liquidity pool, X appreciates while Y depreciates. The realized FX rate amounts to
The subsequent state of the liquidity pool consists of the components
\({{\widetilde{S}}_t(\Delta y)\in \big (S_t^\text{pre},S_t^\text{post}(\Delta y)\big )}\) holds, provided that the posted amount is sufficiently large. Again,
compare (16) and (19). Otherwise, it even holds \({\widetilde{S}}_t(\Delta x)\ge S_t^\text{post}(\Delta x)>S_t^\text{pre}\). If \(\kappa =0\), then \({{\widetilde{S}}_t(\Delta y)}\) is the geometric mean of \(S_t^\text{pre}\) and \(S_t^\text{post}(\Delta y)\).
3.3 Arbitrage
Both sides of the liquidity pool must have the same economic value at all times, i.e., \({S_t^xx_t^\text{pre}{\mathop {=}\limits ^{!}}S_t^yy_t^\text{pre}}\). Otherwise, at least if the discrepancy is sufficiently large, it can be exploited in terms of a roundtrip, ceteris paribus. There is usually a narrow no arbitrage corridor, whose boundaries can be determined explicitly without further ado.
Theorem 4
(Maximal Arbitrage Opportunity) Let us consider a CPMM of Definition 3 and set
-
1.
If it holds \(S_t^xx_t^\text{pre}<S_t^yy_t^\text{pre}\), then posting
$$\begin{aligned} \Delta x=\frac{-sx_t^\text{pre}(2-\kappa _1-\kappa )+\sqrt{D_{\Delta x}}}{2s(1-\kappa _1)(1-\kappa )}, \end{aligned}$$(22)where \(D_{\Delta x}:=\big (sx_t^\text{pre}(2-\kappa _1-\kappa )\big )^2-4\big ( s(1-\kappa _1)(1-\kappa )\big )\big (s(x_t^\text{pre})^2-x_t^\text{pre}y_t^\text{pre}\big )>0,\) initiates the optimal arbitrage opportunity, provided that
$$s<\frac{(1-\kappa_1)(1-\kappa)}{(1+\kappa_2)}\frac{y_t^\text{pre}}{x_t^\text{pre}}$$(23)is satisfied.
-
2.
If it holds \(S_t^xx_t^\text{pre}>S_t^yy_t^\text{pre}\), then posting
$$\begin{aligned} \Delta y=\frac{-y_t^\text{pre}(2-\kappa _1-\kappa )+\sqrt{D_{\Delta y}}}{2(1-\kappa _1)(1-\kappa )}, \end{aligned}$$(24)where \(D_{\Delta y}:=\big (y_t^\text{pre}(2-\kappa _1-\kappa )\big )^2-4\big ((1-\kappa _1)(1-\kappa )\big )\big ( (y_t^\text{pre})^2-sx_t^\text{pre}y_t^\text{pre}\big )>0\), initiates the optimal arbitrage opportunity, provided that
$$s>\frac{(1+\kappa_2)}{(1-\kappa_1)(1-\kappa)}\frac{y_t^\text{pre}}{x_t^\text{pre}}$$(25)is satisfied.
Proof
-
1.
For the regulation, we aim at bringing the liquidity pool back into its equilibrium state \(sx_t^\text{post}=y_t^\text{post}\) by posting \(\Delta x>0\). This leaves us with the Eq.
$$\begin{aligned} S_t^x\left( x_t^\text{pre}+(1-\kappa _1)\Delta x\right) {\mathop {\, = \, } \limits ^{!}}S_t^y\frac{x_t^\text{pre}y_t^\text{pre}}{x_t^\text{pre}+(1-\kappa )\Delta x}. \end{aligned}$$(26)This quadratic equation in \(\Delta x\) can be rearranged into the standard form
$$\begin{aligned} 0=\underbrace{s(1-\kappa _1)(1-\kappa )}_{>0}[\Delta x ]^2+\underbrace{sx_t^\text{pre}(2-\kappa _1-\kappa )}_{>0}\Delta x+\underbrace{s{\left( x_t^\text{pre}\right) }^2-x_t^\text{pre}y_t^\text{pre}}_{<0}. \end{aligned}$$(27)It has the two well-defined solutions
$$\begin{aligned} \Delta x_{1,2}=\frac{-sx_t^\text{pre}(2-\kappa _1-\kappa )\pm \sqrt{D_{\Delta x}}}{2s(1-\kappa _1)(1-\kappa )}\gtrless 0; \end{aligned}$$(28)solely \(\Delta x_1\) is economically meaningful. \(\Delta x_2<-x_t^\text{pre}\) is not feasible economically since we cannot withdraw more than the available amounts from the liquidity pool. \(\Delta x_1\) vanishes for \(s=S_t^\text{pre}\). It needs to be noted that the net value \(-S_t^x\Delta x_1-S_t^y\Delta y(\Delta x_1)\) with respect to the numéraire is not necessarily positive. Hence, whether there is an arbitrage opportunity or not must be examined carefully by checking the validity of (13), which is satisfied exactlyFootnote 3 under the requirement (23).
-
2.
Similarly, we need to establish the parity
$$\begin{aligned} S_t^x\frac{x_t^\text{pre}y_t^\text{pre}}{y_t^\text{pre}+(1-\kappa )\Delta y}{\mathop {=}\limits ^{!}}S_t^y\big (y_t^\text{pre}+(1-\kappa _1)\Delta y\big ). \end{aligned}$$(29)The same procedure as above yields
$$\begin{aligned} 0=\underbrace{(1-\kappa _1)(1-\kappa )}_{>0}[\Delta y]^2+\underbrace{y_t^\text{pre}(2-\kappa _1-\kappa )}_{>0}\Delta y+\underbrace{(y_t^\text{pre})^2-S_t^\text{post}x_t^\text{pre}y_t^\text{pre}}_{<0} \end{aligned}$$(30)with the two solutions
$$\begin{aligned} \Delta y_{1,2}=\frac{-y_t^\text{pre}(2-\kappa _1-\kappa ) \pm \sqrt{D_{\Delta y}}}{2(1-\kappa _1)(1-\kappa )}\gtrless 0; \end{aligned}$$(31)again, solely \(\Delta y_1\) is economically meaningful. \(\Delta y_1\) vanishes for \(S_t^\text{post}=S_t^\text{pre}\). The validity of the condition (20) must be verified just as well, which is equivalent to the requirement (25).
This concludes the proof. \(\square\)
In the absence of transaction fees, the involved quantities simplify considerably, and the two cases unite in one formula. We leave the elementary adjustments of the proof to the knowledgeable reader.
Corollary 5
(Maximal Arbitrage Opportunity in the Absence of Transaction Costs) Let us consider the setting of Theorem 4 with \(\kappa =0\). In either case, eligible swappingFootnote 4
has an economic value of
with respect to the numéraire. For \(s\ne S_t^\text{pre}\), one can exploit an arbitrage opportunity indeed. It vanishes if and only if \(s=S_t^\text{pre}\).
3.4 Impermanent loss without transaction cost
For easier understanding, let us temporarily assume \(\kappa =0\); the general case is treated subsequently in the Sects. 3.5 and 3.6. If the intrinsic FX-rate \(S_t\) remained constant, then one could earn transaction cost from providing liquidity without adverse circumstances. If the FX rate changes in either direction, one has to bear substantial opportunity costs. Let us assume that we provided \(x_t\) and \(y_t\) to the liquidity pool at time t, which was worth
with respect to the numéraire. If the FX-rate at time \(t+\Delta t\) changed to \(S_{t+\Delta t}\), then arbitrageurs would have rebalanced the amounts to
Therefore, the opportunity cost would amount to
which perfectly offsets the gain of the arbitrageurs; see (33). The Fig. 2 depicts the shape of the impermanent loss qualitatively. Note that the impermanent loss is symmetric in the sense that it basically only depends on the relative performance of \(S_{t+\Delta t}\) with respect to \(S_t\). It exceeds the revalued liquidity pool outside of the range \({S_t(2\pm \sqrt{3}\big )^2\approx [0.07S_t,14S_t]}\).
Theoretically, as proposed by Fukasawa et al. (2023), the impermanent loss could be hedged (but typically at significant cost). By the general Carr-Madan-formula (see Carr & Madan, 1999), it holds for any \(g:(0,\infty )\longrightarrow {\mathbb {R}}\) subject to sufficient regularity
For the impermanent loss measured in X, it holds at \(S_t=\dfrac{y_t}{x_t}\)
Thus, the impermanent loss with respect to some fixed maturity \(T>t\) (e.g., one year) can perfectly be replicated in X through a continuum of European put and call options. More precisely, it entails
Furthermore, its economic value can be assessed by approximating the continuum using Riemann sums. For volatilities of \(S_t\) beyond \(100\%\) and \(150\%\) (as often observed with crypto currencies), it typically exceeds \(10\%\) and \(25\%\) respectively of the liquidity pool value over a target horizon of 1y; these estimates can be easily replicated using the Black-Scholes-Merton formulas (see Black & Scholes, 1973, Merton, 1974) and are also integrated in the Jupyter notebook. If \(\kappa =0.35\%\), this is equivalent to a roughly 28- and 70-fold circulation respectively of the entire liquidity pool (before liquidity fees are earned at all). For many crypto token pairs, this impediment is simply not realistic. This finding is corroborated by Loesch et al. (2021) and Cohen et al. (2023). The former examines empirically the encountered impermanent loss for Uniswap v3 (see the section A in the appendix). The latter relies on agent-based simulations.
3.5 Liquidity pool dynamics in the case 1: a marketplace
Consistently, both \(S_t^x\) and \(S_t^y\) remain unaffected by transactions and are given exogenously. On the one hand, \(S_t\) (one monetary unit of X denominated in Y) can be inferred from \(S_t^x\) and \(S_t^y\) by absence of arbitrage; see Theorem 4. On the other hand, \(S_t\) can be inferred from the state and the dynamics of the CPMM. Discrepancies in the FX rate from the two sources can be attributed to asset illiquidity. In the following, we derive several useful quantities of pool dynamics that depend exclusively on independent input parameters, namely
0. Initial state of the liquidity pool in equilibrium:
x. Swap \(\Delta x>0\) against the other token:
y. Swap \(\Delta y>0\) against the other token:
It needs to be noted that this market situation is somewhat pathological as it opens arbitrage opportunities after every excursion of \(S_t\) from the parity, ceteris paribus; see the Sect. 3.3. The liquidity pool can be regarded as immediate counterparty, whereas arbitrageurs assume the role of delayed counterparties who earn the slippage. Moreover, with respect to the numéraire, there is no impermanent loss in this comparatively small marketplace even in the absence of transaction cost; see (54) and (63). Neither X nor Y require the implicit rate \(S_t\) for valuation purposes.
3.6 Liquidity pool dynamics in the case 2: the market
Without loss of generality, let us assume that the CPMM is the only marketplace where Y can be bought and sold against X, whereas X is a comparatively liquid token. Consistently, \(S_t^x\) remains unaffected by the transaction and \(S_t\) is implied by the CPMM. Thus, \(S_t^y\) can be inferred by absence of arbitrage; see Theorem 4. On the one hand, buying and holding a crypto currency pair is a frictionless trading strategy which is far more promising than providing liquidity (since one does not incur an impermanent loss). On the other hand, a token without liquidity has no value. Therefore, one needs to come up with a risk management solution to incentivize liquidity. Apparently, this is not an easy task; we present a viable proposal in the Sect. 3.10. We proceed similarly as in the previous section. This time, the independent input parameters for the model comprise
0. Initial state of the liquidity pool in equilibrium:
x. Swap \(\Delta x>0\) against the other token:
y. Swap \(\Delta y>0\) against the other token:
The simplicity of \({\widetilde{r}}_t(\Delta y)\) in Eq. (89) is remarkable.
3.7 Market capitalization versus sale value
Firstly, let us assume that one holds \(\Delta y>0\) of Y. The accounting value of the holding amounts to
. In turn, by (81), if one wants to dispose of this holding, the realized sale value denominated in the numéraire amounts to
Secondly, let us assume that one holds a fraction \(\lambda \in [0,1]\) of the liquidity pool. The accounting value of the holding amounts to \(V_t=2\lambda S_t^xx_t^\text{pre}\). In turn, the sale value can be calculated by withdrawing \(\lambda x_t^\text{pre}\) and \(\lambda y_t^\text{pre}\)—leading to a new liquidity of \(c_t^\text{post}=(1-\lambda)^2x_t^\text{pre}y_t^\text{pre}\)—and swapping \(\Delta y=\lambda y_t^\text{pre}\) against
With respect to the numéraire, this leaves us with
For \(\kappa=0\), the illiquidity premium reduces to \(\lambda^2S_t^xx_t^\text{pre}\).
3.8 Model-independent simulation and the inverse problem
For a given initial state of a liquidity pool, one can simulate arbitraryFootnote 5 non-negative paths of \(S_t^x\), \(S_t^y\) and \(S_t\) together with stochastic trading instances \({\mathbb {T}}\subset [0,\infty )\) over a predefined time horizon. From this, one derives the associated càdlàg step function \(S_t^\lrcorner :=S_{\max \{t_i\in {\mathbb {T}}|t_i\le t\}}\); see the Fig. 3 for an illustration. For each trading instance, one can utilize the Eqs. (28) or (31) respectively (depending on whether the updated \(S_t^\text{post}:=S_t^\lrcorner\) is larger or smaller than \(S_t^\text{pre}:=S_{t\text{--}}^\lrcorner\)) and back out the unique swap \((\Delta x,\Delta y)\) that caused this FX-rate shift. With this approach, one easily obtains empirically a rich class of consistent roll-forwards of a liquidity pool including all individual transactions. Notably, the approach works regardless of the model choice for the FX-rates and the trading instances. To this end, the following reparametrization of the inverse problem may be useful: Let \(p\in (0,\infty )\) and \(S_t^\text{post}=pS_t^\text{pre}\). Let us introduce the auxiliary quantity
Note that \({\xi (0,0,p)=\dfrac{\sqrt{p}}{p}-1}\) and \(\xi (\kappa _1,\kappa _2,1)=0\). Then, one can retrieve the posted amounts
as well as the revaluation of the liquidity pool
The formulas (95) and (96) highlight a certain symmetry in both directions of FX movements. One obtains the updated accounting value of the liquidity pool through interest-like compounding and discounting respectively. See the Jupyter notebook for a readily available implementation of the simulation framework in Python as well as the Fig. 4.
3.9 Absolute hedge
Issuers of the token Y desire a suitable asset liquidity. Therefore, it is worth looking at whether an absolute hedge (i.e., keeping the economic value of the inventory flat) can be achieved in a CPMM at reasonable cost. Unfortunately, this is not the case. Hedging the significant downside risk at the cost of discarding upside potential comes at the same cost as hedging the impermanent loss. For illustration, we ignore transaction cost and measure everything with respect to X. We intend to replicate
where \({s_t=\dfrac{x_t}{y_t}}\). Consistently, it holds
The Carr–Madan–formula corroborates that absolute hedges for CPMM are hardly feasible. Indeed,
By the put-call-parity, the short position of the flat delta hedge (consisting of \(y_t\) long at-the-money puts and \(y_t\) short at-the-money calls) comes at almost no cost. The continuum of European options has the same value as hedging the impermanent loss; see (41). Funding this significant value requires a lot of noise trading.
3.10 Break-even transaction cost
With automated market making as outlined in the Case 2, one encounters significant opportunity cost. Since we cannot accurately predict the fees earned out of noise trading, we need to come up with a different source of income that offsets the incurred impermanent loss. Whereas \(\kappa _1\) is determined externally (e.g., \(0.10\%\) of the trade volume plus gas), we can implement order size and pool size dependentFootnote 6\(\kappa _2(\Delta x)\) and \(\kappa _2(\Delta y)\) respectively; the higher the relative transaction volume, the higher the illiquidity fee to be borne. We need to distinguish the two cases of posting X and Y. We derive the minimal \(\kappa _2\) such that providing liquidity is at arm’s length with the vanilla portfolio. Hence, if one enforced these fair transaction costs, the impermanent loss would disappear with respect to any reference point repeatedly. We presume that no further spread on top is required in order to incentivize the desired liquidity. On the one hand, the transaction costs involved can become considerably large. On the other hand, one would have to bear comparatively prohibitive costs with market orders in a CLOB, if one trades through the entire order book. The approach also gets strong support from the agent-based considerations in Sabaté-Vidales and Šiška (2022).
Lemma 6
(Break-Even Transaction Cost) Let us consider a CPMM of Definition 3. If one establishes order size and pool size dependent transaction fees
then the liquidity providers do not incur an impermanent loss. It obviously holds \({\displaystyle \lim _{\Delta x\rightarrow \infty }\kappa _2(\Delta x)=\displaystyle \lim _{\Delta y\rightarrow \infty }\kappa _2(\Delta y)=1-\kappa _1}\).
Proof
-
1.
Posting \(\Delta x>0\) yields to
$$\begin{aligned} {V_t^\text {post}(\Delta x)}&{\mathop {=}\limits ^{!}}{S_t^x\big (x_t^\text {pre}+S_t^\text {post}(\Delta x)^{-1}y_t^\text {pre}\big ),} \end{aligned}$$(103)where, because of (77) and (78) respectively,
$$\begin{aligned} {V_t^\text{post}(\Delta x)}&={2S_t^x\big (x_t^\text{pre}+(1-\kappa _1)\Delta x\big ),} \end{aligned}$$(104)$$\begin{aligned} {S_t^\text{post}(\Delta x)^{-1}}&={\dfrac{\big (x_t^\text{pre}+(1-\kappa _1)\Delta x\big )\Big (x_t^\text{pre}+\big (1-\kappa _1-\kappa _2(\Delta x)\big )\Delta x\Big )}{x_t^\text{pre}y_t^\text{pre}}.} \end{aligned}$$(105)$$\begin{aligned} \Longleftrightarrow \qquad {\kappa _2(\Delta x)}&={\dfrac{(1-\kappa _1)^2\Delta x}{x_t^\text{pre}+(1-\kappa _1)\Delta x}=\dfrac{(1-\kappa _1)^2}{\dfrac{x_t^\text{pre}}{\Delta x}+(1-\kappa _1)}{\mathop {\longrightarrow }\limits ^{\Delta x\rightarrow \infty }}1-\kappa _1.} \end{aligned}$$(106) -
2.
Posting \(\Delta y>0\) yields to
$$\begin{aligned} {V_t^\text{post}(\Delta y)}&{\mathop {=} \limits ^{!}}{S_t^x\left( x_t^\text{pre}+S_t^\text{post}(\Delta y)^{-1}y_t^\text{pre}\right) ,} \end{aligned}$$(107)where, because of (86) and (87) respectively,
$$\begin{aligned} {V_t^\text{post}(\Delta y)}&={\dfrac{2S_t^xx_t^\text{pre}y_t^\text{pre}}{y_t^\text{pre}+\big (1-\kappa _1-\kappa _2(\Delta y)\big )\Delta y},} \end{aligned}$$(108)$$\begin{aligned} {S_t^\text{post}(\Delta y)^{-1}}&={\dfrac{x_t^\text{pre}y_t^\text{pre}}{\big (y_t^\text{pre}+(1-\kappa _1)\Delta y\big )\Big (y_t^\text{pre}+\big (1-\kappa _1-\kappa _2(\Delta y)\big )\Delta y\Big )}.} \end{aligned}$$(109)$$\begin{aligned} \Longleftrightarrow \qquad {\kappa _2(\Delta y)}&={\dfrac{(1-\kappa _1)^2\Delta y}{y_t^\text{pre}+(1-\kappa _1)\Delta y}=\dfrac{(1-\kappa _1)^2}{\dfrac{y_t^\text{pre}}{\Delta y}+(1-\kappa _1)}{\mathop {\longrightarrow }\limits ^{\Delta y\rightarrow \infty }}1-\kappa _1.} \end{aligned}$$(110)
This concludes the proof. \(\square\)
Lemma 7
Let the premises of Lemma 6 be given. For receiving a desired \(\Delta y\) of Y, where
the required posting amounts to
Analogously, for receiving a desired \(\Delta x\) of X, where
the required posting entails
Proof
By plugging \(\Delta x (\Delta y)\) from (112) and \(\kappa_2\big(\Delta x(\Delta y)\big)\) from (102) into (72), one easily verifies that
holds indeed. If (112) was not known, then one could solve (115) for \(\Delta x (\Delta y)\) and end up with a linear equation. Its solution is only economically meaningful within the specified boundaries of (111). Regarding (114), either one exploits the symmetry in the x- and y-directions, or one proceeds algebraically in the same way with the expressions (114), (102) and (81) respectively. Again, the algebraic solution makes only sense from the economic viewpoint up to half of the available amount \(x_t^\text{pre}\). \(\square\)
3.11 Optimal trade execution
Without further assumptions on the dynamics of the ecosystem, the question of optimal trade execution cannot be answered conclusively. Optimality highly depends on the behavior of the other market participants. Nonetheless, it is a relevant question whether it may be advisable to split a large transaction into n equally sized small trades, ceteris paribus. For a classical CPMM with flat transaction fees \(\kappa =\kappa _1+\kappa _2\), executing one large swap is better than its counterpart, although the impact is typically negligible. Exemplarily (with an abuse of notation), when posting \(\Delta x>0\) twice, the liquidity pool still ends up with
whereas
the strict inequality holds, because
Consequently, one earns more tokens of Y by contributing \(2\Delta x\) once. Furthermore, for a classical CPMM without transaction cost, the same argument demonstrates that executing one large swap is identical to initiating n small swaps. For break-even transaction cost as in the Sect. 3.10, splitting trades into smaller portions may be worthwhile as the relatively applied \(\kappa _2\) grows with the order size. In this case, a trade-off must be solved between saved transaction fees and additionally required gas fees (which are not order-size-dependent, but due for each transaction). An in-depth analysis in this context can be found in Cartea et al. (2022a).
3.12 Estimating the impact of noise trades through roundtrips
First, we consider for \(\kappa _2\equiv c\) the change in the value of the liquidity pool due to successive posting of \(\Delta x\) and
ceteris paribus. With an abuse of notation, the liquidity pool will then consist of \(\big (x_t^\text{post}(\Delta x)\big )(\Delta y)=x_t^\text{pre}\) tokens of X and
tokens of Y. In the Case 1 of a marketplace, the liquidity pool hosts a windfall profit. In the Case 2 of the market, the liquidity pool consists of the same amount of X tokens and more Y tokens compared to the starting point. Thus, the value of Y has slightly depreciated with respect to the numéraire. Second, we consider by symmetry the change in the value of the liquidity pool due to successive posting of \(\Delta y\) and the analog to (119) in \(\Delta x\). In the Case 1 of the marketplace, the liquidity pool hosts a windfall profit again. In the Case 2 of the market, the liquidity pool consists of more X tokens and the same amount of Y tokens compared to the starting point. Thus, the value of Y has slightly appreciated with respect to the numéraire. If \(\kappa _2\) is order size-dependent as in the section 3.10 (without additional spread), then the analog to (119) is
The first implicit expression may include an additional spread. The second quantity is only meaningful for sufficiently small \(\Delta x\) up until the singularity that occurs at the root of the numerator; the domain is \({\mathbb {D}}=\big \{\Delta x\ge 0\,\big |\,(1-\kappa _1)\Delta x< x_t^\text{pre}\big \}\). Beyond this root, a return to the starting point in X is no longer possible by means of one swap; see also Lemma 7. It is also worth parametrizing roundtrips in terms of returning to the initial FX-rate \(S_t^\text{pre}\); see the Jupyter notebook for a numeric implementation.
Data availability
A sample Python code is available from the corresponding author on reasonable request.
Notes
In this article, we stick to the term «impermanent loss» all the same.
Algebraically, one would have to impose additionally the requirement \(s\stackrel{!}{>}0\). However, \(s\leq 0\) is not reasonable in our setting anyway.
More precisely, this involves posting the positive quantity to the pool and getting the absolute value of the negative quantity in return.
The framework is open to any common model class.
In the notation, we omit the dependence on \(x_t^\text{pre}\) and \(y_t^\text{pre}\) respectively.
One either sets \(\ell =-\infty\) or \(u=+\infty\).
References
Angeris, G., Evans, A., & Chitra, T. (2023). Replicating market makers. Digital Finance. https://doi.org/10.1007/s42521-023-00082-0
Black, F., & Scholes, M. (1973). The pricing of options and corporate liabilities. Journal of Political Economy, 81(3), 637–654. https://doi.org/10.1086/260062
Carr, P., & Madan, D. (1999). Option valuation using the fast Fourier transform. The Journal of Computational Finance, 2(4), 61–73. https://doi.org/10.21314/JCF.1999.043
Cartea, Á., Drissi, F., & Monga, M. (2022a). Decentralised finance and automated market making: Execution and speculation, Rochester, NY. https://doi.org/10.2139/ssrn.4144743. https://papers.ssrn.com/abstract=4144743. Accessed 23 June 2023
Cartea, Á., Drissi, F., & Monga, M. (2022b). Decentralised finance and automated market making: Predictable loss and optimal liquidity provision, Rochester, NY. https://doi.org/10.2139/ssrn.4273989. https://papers.ssrn.com/abstract=4273989. Accessed 30 June 2023
Cartea, Á., Drissi, F., Sànchez-Betancourt, L., Šiška, D., & Szpruch, L. (2023). Automated market makers designs beyond constant functions, Rochester, NY. https://doi.org/10.2139/ssrn.4459177. https://papers.ssrn.com/abstract=4459177. Accessed 23 June 2023
Cohen, S., Sabaté-Vidales, M., Šiška, D., & Szpruch, L. (2023). Inefficiency of CFMs: Hedging perspective and agent-based simulations. https://doi.org/10.48550/arXiv.2302.04345, arXiv. arXiv:2302.04345 [q-fin].
Cousaert, S., Xu, J., & Matsui, T. (2022) SoK: Yield aggregators in DeFi. In: 2022 IEEE International Conference on Blockchain and Cryptocurrency (ICBC), pp. 1–14 . https://doi.org/10.1109/ICBC54727.2022.9805523
Daian, P., Goldfeder, S., Kell, T., Li, Y., Zhao, X., Bentov, I., Breidenbach, L., & Juels, A. (2020). Flash Boys 2.0: Frontrunning in decentralized exchanges, miner extractable value, and consensus instability. In: 2020 IEEE Symposium on Security and Privacy (SP), pp. 910–927 . https://doi.org/10.1109/SP40000.2020.00040. (ISSN: 2375-1207)
Fukasawa, M., Maire, B., & Wunsch, M. (2023). Weighted variance swaps hedge against impermanent loss. Quantitative Finance. https://doi.org/10.1080/14697688.2023.2202708
Loesch, S., Hindman, N., Richardson, M. B., & Welch, N. (2021). Impermanent loss in Uniswap v3. https://doi.org/10.48550/arXiv.2111.09192, arXiv:2111.09192 [q-fin].
Merton, R. C. (1974). On the pricing of corporate debt: The risk structure of interest rates*. The Journal of Finance, 29(2), 449–470. https://doi.org/10.1111/j.1540-6261.1974.tb03058.x
Mohan, V. (2022). Automated market makers and decentralized exchanges: A DeFi primer. Financial Innovation, 8(1), 20. https://doi.org/10.1186/s40854-021-00314-5
Sabaté-Vidales, M., & Šiška, D. (2022). The case for variable fees in constant product markets: An agent based simulation, Rochester, NY. https://doi.org/10.2139/ssrn.4065088 . https://papers.ssrn.com/abstract=4065088. Accessed 23 June 2023
Xu, J., Paruch, K., Cousaert, S., & Feng, Y. (2023). SoK: Decentralized Exchanges (DEX) with Automated Market Maker (AMM) Protocols. ACM Computing Surveys, 55(11), 238–123850. https://doi.org/10.1145/3570639
Xu, T. A., & Xu, J. (2022). A short survey on business models of decentralized finance (DeFi) protocols. https://doi.org/10.48550/arXiv.2202.07742, arXiv:2202.07742 [econ, q-fin].
Acknowledgements
The authors gratefully acknowledge the financial support provided by the Innosuisse grant 55591.1 IP-ICT.
Funding
Open access funding provided by University of Applied Sciences Eastern Switzerland.
Author information
Authors and Affiliations
Corresponding author
Additional information
Publisher's Note
Springer Nature remains neutral with regard to jurisdictional claims in published maps and institutional affiliations.
Appendices
Appendix A: Uniswap v3
1.1 A.1: Model
In this adjusted framework (see Uniswap v3 documentation), one levers the provided funds to a higher level of liquidity. If the FX-rate is at or below the self-determined lower bound \(\ell\) (i.e., \(S_t<\ell <u\)), then the entire liquidity is provided in X; if the FX-rate is at or beyond the self-determined upper bound u (i.e., \(\ell<u<S_t\)), then the entire liquidity is provided in Y. This enables range orders as well as limit orders.Footnote 7 For the sake of simplicity, we ignore transaction cost. Moreover, we do not consider the exact mechanism of the pool factory.
As long as \(S_t\in [\ell ,u]\) prevails, the actually provided funds \(x_t\) and \(y_t\) satisfy
L is an auxiliary quantity and does no longer comply with the natural interpretation of a CPMM. The intuition of the leverage in the Eq. (123) is shown in the Fig. 5. Additionally, the levered positions must coincide with the observed FX-rate, i.e.,
Plugging this into the former equation leaves us with
Hence, if \(\ell\), u, \(S_t{\mathop {<}\limits ^{!}}u\), and \(x_t\) were given exogenously, then
Likewise, we get
If \(\ell\), u, \(S_t{\mathop {>}\limits ^{!}}\ell\), and \(y_t\) were given exogenously, then
1.2 A.2: Dynamics of the liquidity pool
Analogously as for the classical CPMM, we get
provided that the FX rate remains within \([\ell ,u]\). By plugging in the above expressions for \(\Delta x(\Delta y)\) and utilizing the fundamental equation (123), one easily checks that
Analogously,
1.3 A.3: Impermanent Loss
Let us assume that it held \(\ell<S_t<u\) at the time of providing the liquidity. Similarly as in the Sect. 3.4, the impermanent loss denominated in Y amounts to
It is easy to check that the loss function is continuous and negative throughout; exemplarily, utilizing (125) and (127) yields
If it held \(S_t\le \ell <u\) or \(\ell <u\le S_t\) at the time of providing the liquidity, then one would not incur any opportunity loss as long as \(S_{t+\Delta t}\le \ell\) or \(S_{t+\Delta t}\ge u\) respectively. Other than that, the above formula prevails.
One argument in favor of Uniswap v3 is that one can achieve greater capital efficiency with leverage and therefore earn more premiums. Conversely, the leverage also increases the risk and extent of the impermanent loss. Over-leveraged positions have been the recurring cause of critical failures in the financial industry over the past decades. Thus, when facing the situation of the Sect. 3.6, we are not inclined to believe that leveraging is the solution to the quest for a sustainable ecosystem.
Appendix B: Balancer (CPMM with n Assets)
1.1 B.1: Notation
Notation | Description |
---|---|
\(x_t^i\) | Amount of token i (e.g., XTZ) at time t, \(i=1,2,\ldots ,n\) |
\(S_t^i\) | FX-rate of token i in the numéraire currency (e.g., XTZUSD) at time t |
\(c_t:=\displaystyle \prod _{i=1}^nx_t^i\) | Available liquidity at time t |
1.2 B.2: Arbitrage
For the sake of simplicity, we ignore transaction costs. We consider the system of equations
where (ii.) must hold for \(i=2,3,\ldots ,n\). Thus,
Notably, it usually requires all components for the regulation. The arbitrage profit with respect to the numéraire amounts to
the arithmetic average is larger or equal than the geometric average, and equality holds if and only if all components are identical. See also the Balancer documentation for further details.
Appendix C: Flat curve
1.1 C.1: Model
We consider a CFMM approach with
see the corresponding GitHub repository. This choice is convenient for pairs of stable tokens. The isolines \(F(x,y)\equiv c\) for \(c>0\) are a mixture between constant product and constant sum (CSMM); see the Fig. 6. Note that the spot FX-rate for CSMM is unaffected by transactions. However, liquidity could be removed entirely. The model is not analytically tractable; numerical approximations become inevitable, for instance, the Newton–Raphson method. In contrast to the classical CPMM, the parity \(S_t^xx_t=S_t^yy_t\) is usually not met.
Rights and permissions
Open Access This article is licensed under a Creative Commons Attribution 4.0 International License, which permits use, sharing, adaptation, distribution and reproduction in any medium or format, as long as you give appropriate credit to the original author(s) and the source, provide a link to the Creative Commons licence, and indicate if changes were made. The images or other third party material in this article are included in the article's Creative Commons licence, unless indicated otherwise in a credit line to the material. If material is not included in the article's Creative Commons licence and your intended use is not permitted by statutory regulation or exceeds the permitted use, you will need to obtain permission directly from the copyright holder. To view a copy of this licence, visit http://creativecommons.org/licenses/by/4.0/.
About this article
Cite this article
Brönnimann, W., Egloff, P. & Krabichler, T. Automated market makers and their implications for liquidity providers. Digit Finance 6, 573–604 (2024). https://doi.org/10.1007/s42521-024-00117-0
Received:
Accepted:
Published:
Issue Date:
DOI: https://doi.org/10.1007/s42521-024-00117-0
Keywords
- Arbitrage
- Asset liquidity
- Automated market making
- CFMM
- CPMM
- Decentralized exchange
- Liquidity provider
- Transaction cost