This paper was converted on www.awesomepapers.org from LaTeX by an anonymous user.
Want to know more? Visit the Converter page.

Expiring Assets in Automated Market Makers

Kenan Wood
[email protected]
Davidson College
   Maurice Herlihy
[email protected]
Brown University
   Hammurabi Mendes
[email protected]
Davidson College
   Jonad Pulaj
[email protected]
Davidson College
(January 2024)
Abstract

An automated market maker (AMM) is a state machine that manages pools of assets, allowing parties to buy and sell those assets according to a fixed mathematical formula. AMMs are typically implemented as smart contracts on blockchains, and its prices are kept in line with the overall market price by arbitrage: if the AMM undervalues an asset with respect to the market, an “arbitrageur” can make a risk-free profit by buying just enough of that asset to bring the AMM’s price back in line with the market.

AMMs, however, are not designed for assets that expire: that is, assets that cannot be produced or resold after a specified date. As assets approach expiration, arbitrage may not be able to reconcile supply and demand, and the liquidity providers that funded the AMM may have excessive exposure to risk due to rapid price variations.

This paper formally describes the design of a decentralized exchange (DEX) for assets that expire, combining aspects of AMMs and limit-order books. We ensure liveness and market clearance, providing mechanisms for liquidity providers to control their exposure to risk and adjust prices dynamically in response to situations where arbitrage may fail.

1 Introduction

An automated market maker (AMM) [7] is an automaton (usually implemented as a smart contract) that trades one electronic asset for another at rates set by a fixed mathematical formula. Liquidity providers (LPs) lend assets to the AMM in return for a share of transaction fees and governance rights. Today, AMMs form a multi-billion dollar business [18]. The principal benefit of AMMs over more traditional order-book methods is that an AMM offers its assets at a take-it-or-leave-it price, so trades occur immediately, without need for complex bidding strategies.

AMMs typically trade long-lived assets such as cryptocurrencies or stablecoins. In this paper, we investigate a decentralized exchange (DEX) that can be designed to trade expiring assets, those that have a fixed date after which they cannot be resold. For example, a flight ticket from New York to Paris that departs on Monday cannot be sold on Tuesday. Expiration can have complicated effects on price: a last-minute airline ticket may sell at a premium, but a last-minute ticket for a Broadway show may sell at a discount.

Parties can play three distinct roles. Producers sell (expiring) tokens through the DEX. For ease of exposition, all tokens expire at the same well-known time and date. Consumers use (electronic) cash to purchase those tokens through the DEX. Cash has a stable value, and acts as the numéraire. (Some parties may combine both roles to act as arbitrageurs, buying and selling tokens with the effect of aligning the DEX token price with an exogenous market price.) Finally, liquidity providers (LPs) are market makers, buying tokens from producers and selling them to consumers in return for fees.

For most of the DEX’s lifetime, it acts like a standard automated market maker. Producers and consumers sell and buy tokens at a take-it-or-leave-it price determined by the formula specific to the DEX. All transactions are executed immediately. If there is a known, exogenous “market” where tokens can also be bought and sold, then arbitrageurs keep the DEX price in agreement with the market price. Liquidity providers bootstrap the DEX by loaning assets, and they profit by taking a fee for each transaction. When the the system shuts down, its remaining cash is returned to the LPs.

As the expiration date approaches, standard market mechanisms may fail. For some unknown but brief time before token expiration, token supply may vanish: producers stop selling new tokens on the DEX, no matter the price. (For example, airlines cannot create more seats for an imminent Monday flight to Paris.) Similarly, token demand may vanish: consumers stop buying tokens on the DEX, no matter the price. (Hotel rooms in the Caribbean are not going to be booked by people that cannot get there on time) In addition, airline tickets, hotel rooms, and similar expiring assets have prices that can vary highly in response to exogenous events that may be harder to predict, such as weather, geopolitics, etc. Under these circumstances, the DEX can no longer rely on arbitrage to keep the market efficient.

In particular, conventional AMMs fail under those circumstances. Normally, if an AMM’s price for tokens (in cash) rises above the market price, then an arbitrageur would buy (or create) new tokens and sell them to the AMM, thus collecting a risk-free profit and bringing the AMM’s token price back to the market rate. If supply vanishes, however, each token purchase will drive the AMM price up, and eventually the AMM’s token price will rise just above the market price, and the remaining tokens will expire unsold, even though both the consumers and the LPs would have been better off selling those tokens at a lower price. From this we learn that a DEX for expiring assets cannot rely exclusively on arbitrage to keep prices in line with the market.

In an alternative scenario, if demand vanishes, token producers will dump their expiring tokens on the AMM. Of course, such panicky selling will cause the AMM price to fall, but the token producers will realize at least some cash for their tokens. But these trades come at the expense of the LPs who loaned the cash that is being replaced with soon-to-be worthless tokens. From this we learn that AMMs for expiring assets must provide some way for LPs to intervene to limit their exposure to market distortions due to expiration.

This paper describes the design of a decentralized exchange (DEX) for tokens that expire, with the following design goals.

  • Market clearing: at expiration time, it is never the case that there is a producer willing to sell a token at some price 111 A producer may have a minimum price even for expiring tokens. For example, a hotel might not rent a room for less than the cost of cleaning that room., and a consumer willing to buy at that price, yet that token remains unsold,

  • Instant gratification: each asset is bought and sold either immediately (during normal operations) or after a known delay (as expiration approaches), and

  • Incentives: each participant has an incentive to participate.

This paper’s contribution is the design and analysis of a novel DEX for trading assets that expire. Our analysis points out ways in which conventional AMM design fails to address issues raised by expiring tokens, and we propose the following mechanisms to augment conventional AMMs to handle expiring assets.

  • LPs can respond to unforeseen fluctuations in token supply and demand – in particular, in cases resulting in arbitrage failure – by directly intervening to change the shape of the AMM’s curve.

  • LPs can limit its exposure to demand failure by setting a token price below which their cash cannot be used to buy tokens (similar to Uniswap V3’s concentrated liquidity).

  • The AMM is augmented with a pair of order books to ensure market clearing, even in situations of supply and demand failure. For example, just before the tokens expire, any tokens remaining in the DEX are auctioned off, prioritizing LPs in order of cumulative participation.

LPs are assumed to be rational. They may disagree on market predictions, but they do not act maliciously against one another.

2 Related Work

Today, the most popular automated market maker is Uniswap [1, 4, 13, 19], a family of constant-product AMMs. Originally trading between ERC-20 tokens and ether cryptocurrency, later versions added direct trading between pairs of ERC-20 tokens, and allowed liquidity providers to restrict the range of prices in which their assets participate. Bancor [14] AMMs permit more flexible pricing schemes, and later versions [6] include integration with external “price oracles” to keep prices in line with market conditions. Balancer [15] AMMs trade across more than two assets, based on a constant mean formula that generalizes constant product. Curve [11] uses a custom curve specialized for trading stablecoins, maintaining low slippage and divergence loss as long as the stablecoins trade at near-parity. The formal model for AMMs used here is adapted from Engel and Herlihy [12].

Xu et al. [18] and Bartoletti et al. [7] provide informative overviews on AMM protocols. Angeris and Chitra [2] introduce a constant function market maker model and focus on conditions that ensure that agents who interact with AMMs correctly report asset prices.

Aoyagi [5] analyzes strategies for constant-product AMM liquidity providers in the presence of “noise” trading, which is not intended to move prices, and “informed” trading, intended to move the AMM to the stable point for a new and more accurate valuation. Angeris et al. [3] propose an economic model relating how the curvature of the AMM’s function affects LP profitability in the presence of informed and noise traders. Bichuch and Feinstein [8] propose a general mathematical framework for AMMs, and Capponi et al. [9] analyze AMMs using a game theoretic model.

Our mechanism where liquidity providers can freeze their liquidity under adverse market conditions is similar to Uniswap V3’s [13] notion of concentrated liquidity, though the purpose and operational details are somewhat different.

Ramseyer et al. [17] describe several ways to integrate constant-function AMMs with batch auctions. Like the exchange described in this paper, their exchanges have hybrid structures, but their goals and techniques are substantially different, as they are concerned with broad economic properties, not with expiring assets.

3 Informal System Overview

Our DEX is composed of an AMM and two order books that operate under specific rules. We give now an operational overview of our DEX, starting with the AMM component. We point the reader to the appropriate sections containing detailed discussion as we present the concepts below.

An AMM owns and trades two kinds of assets: a stable asset XX (informally called cash), and an expiring asset YY (informally called tokens), These assets are loaned to the AMM by liquidity providers (LPs). As explained later, LPs can be active or inactive.

The AMM tracks a pair (x,y)>02(x,y)\in\mathbb{R}_{>0}^{2}, where xx (respectively yy) is the amount of XX (respectively YY) that the AMM offers for trading.

Any party \ell can become a liquidity provider by lending assets to the AMM. In return, \ell receives a share s(0,1]s_{\ell}\in(0,1] proportional to its contribution. In departure from “pure” AMM designs, an LP can dynamically influence AMM prices to a degree proportional to its share. The particular protocol and curve design is discussed in Section 5.

LPs can withdraw liquidity at well-defined times, called epoch boundaries. LPs can make withdrawals denominated in both types of assets, or in only the stable asset XX. LPs can freeze their liquidity, in a manner comparable to Uniswap V3’s notion of concentrated liquidity [13]. An LP \ell can set a minimum spot price for YY tokens in terms of XX cash. If the AMM’s spot price for tokens falls below that LP’s minimum, that LP becomes inactive and its liquidity is not used in trades. Of course, LPs do not accrue fees while they are inactive. An LP can use freezing to protect itself if it fears that demand has collapsed, causing producers to flood the AMM with YY tokens no one will buy. If the price later rises above an LP’s minimum, that LP becomes active again. Details are discussed in Section 6.

To ensure market clearing, there are complementary buyer and seller order books that are primarily used in the following situations: just before the tokens expire, when there are not enough tokens in the system to execute any more cash-for-tokens trades (demand is too high), or when all LPs are inactive, so no more AMM trades can be executed temporarily. Details can be found in Section 7. If a consumer registers a below-spot-market bid (on YY tokens) on the buyer order book and is still present near the expiration time, that bid is executed with a second price auction. There is also a seller order book, (almost) symmetric to the buyer order book, where sellers offer to sell YY tokens that remain after the AMM token pool is exhausted. The combination of the AMM and the two order books acts like an AMM while normal supply-and-demand laws hold, but acts more like an order book (or auction) near the expiration date when those laws may fail.

We also include a mechanism to incentivize LP participation, so that the AMM (instant-gratification) component of the DEX remains live for a longer period of time. Of course, LPs can withdraw or freeze liquidity. However, if an LP \ell chooses to take on more risk by participating more, they will be given priority in clearing their own tokens, and with a higher price, in the described market clearing auction. Thus, even if two LPs 1,2\ell_{1},\ell_{2} have the same share and hold the same number of tokens, if 1\ell_{1} participates in many more (and larger) trades than 2\ell_{2}, then 1\ell_{1} will receive a greater share of the auction proceeds than 2\ell_{2}. We discuss these details in Section 7.

3.1 Classifying Consumers

In standard AMM models (e.g., Milionis et al. [16]), so-called noise traders buy tokens with the intent of consuming them when they expire, while arbitrageurs (sometimes called informed traders) trade between the DEX and a centralized market to make a profit. These distinctions still apply when assets expire; but consumers, producers, and even LPs have important additional characteristics.

  • Price: How much are customers willing to pay for tokens as expiration approaches? If demand outlasts supply, then producers may be unable to bring new tokens to market, driving up the price as time runs out. If supply outlasts demand, producers may flood the DEX with unwanted tokens, yielding a final price of (practically) zero. The design of the DEX should be able to accommodate both extremes as well as outcomes in between.

  • Urgency: What kinds of risks influence consumer behavior? A consumer who waits until the last minute may not be able to buy a token if demand outstrips supply (e.g., all flights to Paris on Monday are sold out). Alternatively, a last-minute consumer may receive a favorable deal if supply outstrips demand (e.g., a last-minute bargain on a theater ticket). Consumers worried about missing out are said to have high urgency, while those willing to gamble on last-minute bargains have low urgency.

To summarize, there are three kinds of consumers:

  • Bargain hunters: low urgency, low price. For example, a consumer who is willing to buy a last-minute ticket to a Broadway show if those tickets are cheap enough.

  • Normal customers: high urgency, low price. These are conventional AMM (noise or informed) traders who want to execute their trades immediately at a take-it-or-leave it price.

  • High flyers: high urgency, high price. For example, a consumer who suddenly needs to fly to an urgent business meeting in Paris on Monday.

We do not consider consumers with low urgency but high price. A symmetric classification can be applied to producers, but we focus mostly on consumers.

The last-minute consumer order book allows bargain hunters to bid on tokens at prices below the AMM’s asking price. A bargain hunter unwilling to meet the AMM’s asking price can register a bid on the last-minute consumer order book. That bid will be executed immediately if the AMM price falls to the bid price. Just before expiration, any unsold tokens will be distributed among the order book bidders via a second-price auction (or any other incentive-compatible auction mechanism).

Normal consumers, who want to buy tokens at market price right away, and normal producers, who want to sell tokens at market price right away both use the AMM component of the DEX.

High flyers, who need tokens at (almost) any price, will first go to the AMM. If the AMM is sold out of tokens (because, for example, expiration is near and supply is exhausted), then a high-flyer can place an order on the last-minute consumer order book. Last-minute producers who consider the AMM price too low can monitor this order book and fulfill any satisfactory orders.

The last-minute producer and consumer order books ensure market clearing: just before expiration, no token remains unsold if its producer was willing to sell at a price some unfulfilled consumer was willing to pay.

As discussed below, additional mechanisms are necessary to serve the interests of LPs, who are also exposed to risks stemming from failures in either supply or demand as expiration approaches.

4 Mathematical Preliminaries

We now prepare to describe the system in proper detail, first quickly discussing preliminary notation and concepts that are necessary for a formal system presentation in the sections that follow.

For vectors x=(x1,,xn)nx=(x_{1},\dots,x_{n})\in\mathbb{R}^{n} and y=(y1,,yn)ny=(y_{1},\dots,y_{n})\in\mathbb{R}^{n}, we write xyx\leq y provided xiyix_{i}\leq y_{i} for all i[n]i\in[n], where [n]={1,,n}[n]=\{1,\dots,n\}; if also xyx\neq y, we write xyx\lneq y. When referencing topological properties in this paper, we assume that any subset of n\mathbb{R}^{n} (for any n1n\geq 1) is given the subspace topology, unless otherwise specified. We define >0={x:x>0}\mathbb{R}_{>0}=\{x\in\mathbb{R}:x>0\}. A function A:nA:\mathbb{R}^{n}\to\mathbb{R} is twice-differentiable if all of its second partial derivatives exist and are continuous. We also say that AA is strictly increasing in each coordinate if for all x,ynx,y\in\mathbb{R}^{n} such that xyx\lneq y, we have A(x)<A(y)A(x)<A(y).

A set Ωn\Omega\subseteq\mathbb{R}^{n} is convex if for all distinct x,yΩx,y\in\Omega and t(0,1)t\in(0,1), we have tx+(1t)yΩtx+(1-t)y\in\Omega; if every such vector tx+(1t)ytx+(1-t)y is in the interior of Ω\Omega, we say Ω\Omega is strictly convex. It follows that that any convex open set is strictly convex. Given a set SnS\subseteq\mathbb{R}^{n}, the convex hull of SS, denoted convS\operatorname{conv}S, is defined as the intersection of all nonempty convex sets Ωn\Omega\subseteq\mathbb{R}^{n} that contain SS. Suppose Ωn\Omega\subseteq\mathbb{R}^{n} is convex. A function f:Ωf:\Omega\to\mathbb{R} is said to be strictly convex provided that for every distinct x,yΩx,y\in\Omega and t(0,1)t\in(0,1), it follows that f(tx+(1t)y)<tf(x)+(1t)f(y)f(tx+(1-t)y)<tf(x)+(1-t)f(y).

5 Price Adjustment Mechanisms

As discussed in Section 3, our DEX has an AMM meant to provide an instant buying price for consumers. In a conventional constant-function AMM, token prices are kept consistent with the market by external arbitrageurs; if the token price rises above the market price, an arbitrageur may sell overpriced tokens to the AMM, making a risk-free profit. Conversely, if the AMM price falls below the market price, an arbitrageur may buy the bargain tokens from the AMM and resell them on the market. Arbitrage works well for a conventional AMM because there are sufficiently many tokens available to be traded, so that arbitrageurs are always able to trade in the direction needed to bring the AMM price back in line with the market. But close to expiration date, token supply or demand may vanish, and the normal price regulation cannot take place. For example, airlines will not schedule new seats to Paris as the flight time becomes too close. Similarly it makes little sense to book a room in the Caribbean starting in one hour if the room is five hours away. In addition, airline tickets, hotel rooms, event seats, and similar expiring assets have prices that may be influenced by hard-to-predict, exogenous events, such as weather, geopolitical events, etc.

In conventional AMMs, LPs can deposit or withdraw liquidity, but are otherwise passive, allowing producers and consumers to set asset prices via trading. As noted, however, arbitrageurs may become unable to intervene to keep prices close to market levels as expiration approaches. So we propose a mechanism to allow LPs to intervene actively to adjust the curve when conventional methods are in danger of failing.

More specifically, in the period while expiration is far off, when the DEX acts like a conventional AMM, arbitrageur profits come at the expense of LPs, a cost known as divergence loss. The LPs effectively gamble that asset prices will be stable enough that the fees collected will outweigh any divergence loss. As expiration approaches, however, prices may become volatile and arbitrage may become ineffective, so LPs require the ability protect their investments by intervening directly to adjust prices (also to actively protect their capital – see Section 6), effectively assuming the role of conventional arbitrageurs, but without divergence loss.

The duration between when the DEX is started and when the token expires is divided into disjoint intervals called epochs, separated by epoch boundaries. There are two special epoch boundaries: tet_{e}, when the tokens expire, and tr<tet_{r}<t_{e}, when the AMM halts and the last-minute auctions occur. Let TT be the set of all epoch boundaries strictly before trt_{r}.

We say that a state curve is a strictly decreasing homeomorphism f:>0>0f:\mathbb{R}_{>0}\to\mathbb{R}_{>0}. If x>0x>0, we say that the pair (x,f(x))(x,f(x)) is a state of ff, and we denote the set of all states of ff by state(f)\operatorname{state}(f). Operationally, we say that the AMM is in state (x,y)state(f)(x,y)\in\operatorname{state}(f) if it contains xx units of XX and yy units of YY. Trades change the amounts xx and yy of XX and YY, respectively, so that (x,y)(x,y) is always in state(f)\operatorname{state}(f).

We consider only a fixed subfamily of possible state curves. Let 0<a<b0<a<b be fixed positive lower and upper bounds. (We may wish to require that a<1a<1 and b=1ab=\frac{1}{a} for symmetry, though this is not required.) For every c[a,b]c\in[a,b] and possible state (x0,y0)>02(x_{0},y_{0})\in\mathbb{R}_{>0}^{2}, define the state curve

fc,x0,y0(x)=y0(xx0)cf_{c,x_{0},y_{0}}(x)=y_{0}\left(\frac{x}{x_{0}}\right)^{-c}

for all x>0x>0. Then (x0,y0)state(fc,x0,y0)(x_{0},y_{0})\in\operatorname{state}(f_{c,x_{0},y_{0}}). Let LL be the current set of active liquidity providers (whose assets are allocated to trading), and LL^{\prime} is the set of inactive liquidity providers (whose assets are frozen). The sets LL and LL^{\prime} and their associated methods are formally defined in Section 6.

At each time in TT, each liquidity provider LL\ell\in L\cup L^{\prime} chooses some c[a,b]c_{\ell}\in[a,b] that informally represents the price \ell believes is most economically efficient, with knowledge of the current state of the AMM. Each c[a,b]c_{\ell}\in[a,b] is aggregated into a single c[a,b]c\in[a,b] with some deterministic aggregation algorithm 𝚊𝚐𝚐𝚛𝚎𝚐𝚊𝚝𝚎()\mathtt{aggregate}() by computing c𝚊𝚐𝚐𝚛𝚎𝚐𝚊𝚝𝚎()c\leftarrow\mathtt{aggregate}() at each epoch boundary. The 𝚊𝚐𝚐𝚛𝚎𝚐𝚊𝚝𝚎()\mathtt{aggregate}() algorithm has parameters (c)L(c_{\ell})_{\ell\in L} and (s)L(s_{\ell})_{\ell\in L}222We exclude the cc_{\ell}’s and shares of inactive liquidity providers because their share of liquidity is not well-defined, as it is not necessarily the same over both of the assets. See Section 6 for details. and returns some element of [a,b][a,b]. For fixed LL, since 𝚊𝚐𝚐𝚛𝚎𝚐𝚊𝚝𝚎()\mathtt{aggregate}() is deterministic, it can be viewed as a map

𝚊𝚐𝚐𝚛𝚎𝚐𝚊𝚝𝚎:[a,b]L×{(s)L[0,1]L:Ls=1}[a,b],\mathtt{aggregate}:[a,b]^{L}\times\left\{(s_{\ell})_{\ell\in L}\in[0,1]^{L}:\sum_{\ell\in L}s_{\ell}=1\right\}\to[a,b],

where ABA^{B} is the set of all tuples indexed by BB with values in AA for any sets A,BA,B. Now we define the soundness properties for an aggregation algorithm.

Definition 5.1.

Let 𝚊𝚐𝚐𝚛𝚎𝚐𝚊𝚝𝚎()\mathtt{aggregate}() be an aggregation algorithm; let LL be the particular set of active LPs at some time, and consider the corresponding aggregation function. We say that 𝚊𝚐𝚐𝚛𝚎𝚐𝚊𝚝𝚎()\mathtt{aggregate}() is valid if the following axioms hold.

  1. 1.

    For each L\ell\in L, the function 𝚊𝚐𝚐𝚛𝚎𝚐𝚊𝚝𝚎\mathtt{aggregate} has continuous partial derivatives with respect to cc_{\ell}. Additionally,

    (𝚊𝚐𝚐𝚛𝚎𝚐𝚊𝚝𝚎)log(c)=s𝚊𝚐𝚐𝚛𝚎𝚐𝚊𝚝𝚎((c)L,(s)L).\frac{\partial(\mathtt{aggregate})}{\partial\log(c_{\ell})}=s_{\ell}\cdot\mathtt{aggregate}((c_{\ell})_{\ell\in L},(s_{\ell})_{\ell\in L}).
  2. 2.

    If there exists some xx such that c=xc_{\ell}=x for all L\ell\in L, then

    𝚊𝚐𝚐𝚛𝚎𝚐𝚊𝚝𝚎((c)L,(s)L)=x.\mathtt{aggregate}((c_{\ell})_{\ell\in L},(s_{\ell})_{\ell\in L})=x.

For brevity, let c=𝚊𝚐𝚐𝚛𝚎𝚐𝚊𝚝𝚎((c)L,(s)L)c=\mathtt{aggregate}((c_{\ell})_{\ell\in L},(s_{\ell})_{\ell\in L}).

The first condition implies that for a small fixed change in logc\log c_{\ell} from an LP \ell with share ss_{\ell}, the corresponding change in cc is proportional to ss_{\ell}. We use a logarithmic scale since derivatives are limits of additive changes, and log\log is an isomorphism from the group >0\mathbb{R}_{>0} under multiplication to the group \mathbb{R} under addition. (Note that c>0c_{\ell}\in\mathbb{R}_{>0}, so it only makes sense to give them a multiplicative structure.)

The second condition is a simple boundary condition to guarantee that if all LPs are in consensus with a particular value cc, the aggregated constant is the common value cc.

In our model, we define 𝚊𝚐𝚐𝚛𝚎𝚐𝚊𝚝𝚎((c)L,(s)L)\mathtt{aggregate}((c_{\ell})_{\ell\in L},(s_{\ell})_{\ell\in L}) to return

Lcs,\prod_{\ell\in L}c_{\ell}^{s_{\ell}}, (1)

the geometric mean of each cc_{\ell} weighted by the share s[0,1]s_{\ell}\in[0,1] each liquidity provider holds in the system. Interestingly, we show in the Appendix that this aggregation algorithm is the unique valid aggregation algorithm.

The state curve is implied from the global variables c,x0,y0c,x_{0},y_{0} stored in the AMM. Until the next time in TT in which liquidity providers may update their value of cc_{\ell}, we fix cc as defined above. Note that when the state (x,y)(x,y) changes from adding/removing liquidity, freezing/unfreezing liquidity, and liquidating (specified in Section 6), we update x0xx_{0}\leftarrow x and y0yy_{0}\leftarrow y, and we must also update the state curve in these cases. This is necessary because the liquidity state (x,y)(x,y) after completing any of these methods is no longer in the state space of the current state curve fc,x0,y0f_{c,x_{0},y_{0}}. We omit updates to (x0,y0)(x_{0},y_{0}) in any pseudocode of these methods for simplicity of presentation.

5.1 State Curve Properties

Now, let us show that this state curve construction acts like an AMM. We use axioms proposed by Engel and Herlihy [12] that define an AMM as follows. We note that this definition is only used in this section, and other references to the AMM refer to the system model described in this paper.

Definition 5.2.

An AMM is a function A:>02A:\mathbb{R}_{>0}^{2}\to\mathbb{R} that satisfies the following:

  • AA is twice-differentiable;

  • AA is strictly increasing in each coordinate;

  • For each b0b\geq 0, the set {(x,y)>02:A(x,y)b}\{(x,y)\in\mathbb{R}_{>0}^{2}:A(x,y)\geq b\} is closed and strictly convex.

Under this definition, the state space of AA is the set {(x,y)>02:A(x,y)=0}\{(x,y)\in\mathbb{R}_{>0}^{2}:A(x,y)=0\} and is denoted state(A)\operatorname{state}(A). This is the same notation as the state space of a state curve, but the definition of state space should be clear, according to whether the function is a state curve or an AMM. Henceforth, we use AA to denote an AMM and ff to denote a state curve. It is important to note the difference between an AMM and a state curve as defined previously; an AMM is a function >02\mathbb{R}_{>0}^{2}\to\mathbb{R}, but a state curve is a function >0>0\mathbb{R}_{>0}\to\mathbb{R}_{>0}. An AMM captures more information than the set of states alone on a state curve alone. In particular, if AA is an AMM, then we may construct its state curve by mapping x>0x>0 to the unique y>0y>0 such that A(x,y)=0A(x,y)=0. However, the converse is not necessarily true as not every state curve can be extended to an AMM satisfying the above three properties. Observe that there is no operational difference between an AMM and a state curve since the set of states completely determines the behavior of the system. This motivates the following definition.

Definition 5.3.

Given state curve ff, we say that ff induces an AMM if there exists an AMM AA such that state(f)=state(A)\operatorname{state}(f)=\operatorname{state}(A).

We will prove that for any (x0,y0)>02(x_{0},y_{0})\in\mathbb{R}_{>0}^{2} and c>0c>0 that fc,x0,y0f_{c,x_{0},y_{0}} induces an AMM. For the remainder of this section, fix (x0,y0)>02(x_{0},y_{0})\in\mathbb{R}_{>0}^{2} and c>0c>0. To prove that fc,x0,y0f_{c,x_{0},y_{0}} induces an AMM, we let A(x,y)=xcyx0cy0A(x,y)=x^{c}y-x_{0}^{c}y_{0}. We shall first prove that AA is an AMM. It is easy to see the following two lemmas, and the third one is simple.

Lemma 5.1.

AA is twice differentiable.

Proof.

Observe that Ax=cxc1y\frac{\partial A}{\partial x}=cx^{c-1}y and Ay=xc\frac{\partial A}{\partial y}=x^{c}. Then 2Ax2=c(c1)xc2y\frac{\partial^{2}A}{\partial x^{2}}=c(c-1)x^{c-2}y and 2Ay2=0\frac{\partial^{2}A}{\partial y^{2}}=0, which are both continuous. Since both second partial derivatives of AA exist and are continuous, AA is twice differentiable. ∎

Lemma 5.2.

AA is strictly increasing in each coordinate.

Proof.

If x>x>0x^{\prime}>x>0 and y>0y>0, then since c>0c>0, A(x,y)=(x)cyx0cy0>xcyx0cy0=A(x,y)A(x^{\prime},y)=(x^{\prime})^{c}y-x_{0}^{c}y_{0}>x^{c}y-x_{0}^{c}y_{0}=A(x,y). Similarly, if x>0x>0 and y>y>0y^{\prime}>y>0, then A(x,y)=xcyx0cy0>xcyx0cy0=A(x,y)A(x,y^{\prime})=x^{c}y^{\prime}-x_{0}^{c}y_{0}>x^{c}y-x_{0}^{c}y_{0}=A(x,y), as desired. ∎

Lemma 5.3.

For any b0b\geq 0, the set {(x,y)>02:A(x,y)b}\{(x,y)\in\mathbb{R}_{>0}^{2}:A(x,y)\geq b\} is closed and strictly convex.

Proof.

Let b0b\geq 0 and let S={(x,y)>02:A(x,y)b}S=\{(x,y)\in\mathbb{R}_{>0}^{2}:A(x,y)\geq b\}. Since AA is continuous and [b,)[b,\infty) is closed, S=A1([b,))S=A^{-1}([b,\infty)) is closed because the preimage of a closed set under a continuous function is closed. To prove that SS is strictly convex, it suffices to show that for any distinct (x1,y1),(x2,y2)S(x_{1},y_{1}),(x_{2},y_{2})\in S and t(0,1)t\in(0,1), it follows that A(t(x1,y1)+(1t)(x2,y2))>bA(t\cdot(x_{1},y_{1})+(1-t)\cdot(x_{2},y_{2}))>b. To this end, notice that since (x1,y1),(x2,y2)S(x_{1},y_{1}),(x_{2},y_{2})\in S, we know x1cy1b+x0cy0x_{1}^{c}y_{1}\geq b+x_{0}^{c}y_{0} and x2cy2b+x0cy0x_{2}^{c}y_{2}\geq b+x_{0}^{c}y_{0}. Thus, by the Weighted AM-GM Inequality [10, p. 74],

A(t(x1,y1)+(1t)(x2,y2))\displaystyle A(t\cdot(x_{1},y_{1})+(1-t)\cdot(x_{2},y_{2})) =(tx1+(1t)x2)c(ty1+(1t)y2)x0cy0\displaystyle=(tx_{1}+(1-t)x_{2})^{c}(ty_{1}+(1-t)y_{2})-x_{0}^{c}y_{0}
>(x1tx21t)c(y1ty21t)x0cy0\displaystyle>(x_{1}^{t}x_{2}^{1-t})^{c}(y_{1}^{t}y_{2}^{1-t})-x_{0}^{c}y_{0}
=(x1cy1)t(x2cy2)1tx0cy0\displaystyle=(x_{1}^{c}y_{1})^{t}(x_{2}^{c}y_{2})^{1-t}-x_{0}^{c}y_{0}
(b+x0cy0)t(b+x0cy0)1tx0cy0\displaystyle\geq(b+x_{0}^{c}y_{0})^{t}(b+x_{0}^{c}y_{0})^{1-t}-x_{0}^{c}y_{0}
=b.\displaystyle=b.

This shows that SS is a strictly convex set, as desired. ∎

Finally, we must verify that fc,x0,y0f_{c,x_{0},y_{0}} and AA have the same state spaces.

Lemma 5.4.

state(fc,x0,y0)=state(A)\operatorname{state}(f_{c,x_{0},y_{0}})=\operatorname{state}(A).

Proof.

Observe that

(x,y)state(fc,x0,y0)y=y0(x/x0)cxcy=x0cy0(x,y)state(A).(x,y)\in\operatorname{state}(f_{c,x_{0},y_{0}})\Leftrightarrow y=y_{0}(x/x_{0})^{-c}\Leftrightarrow x^{c}y=x_{0}^{c}y_{0}\Leftrightarrow(x,y)\in\operatorname{state}(A).

Thus state(fc,x0,y0)=state(A)\operatorname{state}(f_{c,x_{0},y_{0}})=\operatorname{state}(A). ∎

As a consequence, we have the following.

Theorem 5.5.

The state curve fc,x0,y0f_{c,x_{0},y_{0}} induces an AMM.

Proof.

In letting A(x,y)=xcyx0cy0A(x,y)=x^{c}y-x_{0}^{c}y_{0} as above, Lemmas 5.1, 5.2, and 5.3 imply that AA is an AMM. By Lemma 5.4, it follows that fc,x0,y0f_{c,x_{0},y_{0}} induces an AMM. ∎

Since every state curve used in our price control model induces an AMM, it follows that long before the expiration time, within epochs, our construction satisfies all of the properties and corollaries in [12]. However, approaching the expiration tet_{e} of the expiring token, the assumptions in [12] begin to break down as market conditions shift. Thus an additional mechanism – in particular, the market clearing mechanism in section 8 – is needed to clear the market in the case of extreme conditions, such as when all liquidity providers are inactive or no more tokens can be sold using the AMM component of the DEX.

Now we study the behavior of price and slippage with respect to the variable cc and changes in liquidity states. In particular, we have the following definitions.

Definition 5.4 (Price and Slippage).

Given a state curve fc,x0,y0f_{c,x_{0},y_{0}} and a particular state (x,y)state(fc,x0,y0)(x,y)\in\operatorname{state}(f_{c,x_{0},y_{0}}), the instantaneous price, or the spot price, at (x,y)(x,y) is defined by

pc,x0,y0(x)=1fc,x0,y0(x).p_{c,x_{0},y_{0}}(x)=\frac{1}{-f_{c,x_{0},y_{0}}^{\prime}(x)}.

Additionally, we define the instantaneous slippage by

sc,x0,y0(x)=pc,x0,y0(x)=fc,x0,y0′′(x)(fc,x0,y0(x))2.s_{c,x_{0},y_{0}}(x)=p_{c,x_{0},y_{0}}^{\prime}(x)=\frac{f_{c,x_{0},y_{0}}^{\prime\prime}(x)}{(f_{c,x_{0},y_{0}}^{\prime}(x))^{2}}.
Proposition 5.6.

Given a state (x0,y0)(x_{0},y_{0}), the instantaneous price pc,x0,y0(x0)p_{c,x_{0},y_{0}}(x_{0}) and slippage sc,x0,y0(x0)s_{c,x_{0},y_{0}}(x_{0}) are strictly decreasing in cc, for c>0c>0. That is, if 0<c1<c20<c_{1}<c_{2}, then

pc1,x0,y0(x0)>pc2,x0,y0(x0)andsc1,x0,y0(x0)>sc2,x0,y0(x0).p_{c_{1},x_{0},y_{0}}(x_{0})>p_{c_{2},x_{0},y_{0}}(x_{0})\quad\text{and}\quad s_{c_{1},x_{0},y_{0}}(x_{0})>s_{c_{2},x_{0},y_{0}}(x_{0}).
Proof.

Observe that for all c>0c>0,

fc,x0,y0(x)=cy0(xx0)c11x0,fc,x0,y0′′(x)=c(c+1)y0(xx0)c21x02,f_{c,x_{0},y_{0}}^{\prime}(x)=-cy_{0}\left(\frac{x}{x_{0}}\right)^{-c-1}\cdot\frac{1}{x_{0}},\qquad f_{c,x_{0},y_{0}}^{\prime\prime}(x)=c(c+1)y_{0}\left(\frac{x}{x_{0}}\right)^{-c-2}\cdot\frac{1}{x_{0}^{2}},

so that

fc,x0,y0(x0)=cy0x0,fc,x0,y0′′(x0)=c(c+1)y0x02f_{c,x_{0},y_{0}}^{\prime}(x_{0})=-c\frac{y_{0}}{x_{0}},\qquad f_{c,x_{0},y_{0}}^{\prime\prime}(x_{0})=c(c+1)\frac{y_{0}}{x_{0}^{2}}

Thus

pc1,x0,y0(x0)=1fc1,x0,y0(x0)=x0y0c1>x0y0c2=1fc2,x0,y0(x0)=pc2,x0,y0(x0).p_{c_{1},x_{0},y_{0}}(x_{0})=\frac{1}{-f_{c_{1},x_{0},y_{0}}^{\prime}(x_{0})}=\frac{x_{0}}{y_{0}c_{1}}>\frac{x_{0}}{y_{0}c_{2}}=\frac{1}{-f_{c_{2},x_{0},y_{0}}^{\prime}(x_{0})}=p_{c_{2},x_{0},y_{0}}(x_{0}).

Furthermore, for all c>0c>0,

sc,x0,y0(x0)=fc,x0,y0′′(x0)(fc,x0,y0(x0))2=c(c+1)y0x02(cy0x0)2=c+1c1y0=1y0(1+1c).s_{c,x_{0},y_{0}}(x_{0})=\frac{f_{c,x_{0},y_{0}}^{\prime\prime}(x_{0})}{(f_{c,x_{0},y_{0}}^{\prime}(x_{0}))^{2}}=\frac{c(c+1)\frac{y_{0}}{x_{0}^{2}}}{\left(-\frac{cy_{0}}{x_{0}}\right)^{2}}=\frac{c+1}{c}\cdot\frac{1}{y_{0}}=\frac{1}{y_{0}}\cdot\left(1+\frac{1}{c}\right).

Therefore

sc1,x0,y0(x0)=1y0(1+1c1)>1y0(1+1c2)=sc2,x0,y0(x0).s_{c_{1},x_{0},y_{0}}(x_{0})=\frac{1}{y_{0}}\cdot\left(1+\frac{1}{c_{1}}\right)>\frac{1}{y_{0}}\cdot\left(1+\frac{1}{c_{2}}\right)=s_{c_{2},x_{0},y_{0}}(x_{0}).

Finally, we prove that adding and removing liquidity does not change the instantaneous price. As discussed in the next section, we require that the ratio x/yx/y of active liquidity in the AMM stays constant during these operations. It is also insightful to prove that adding liquidity decreases instantaneous slippage, and removing liquidity increases slippage. Since adding and removing liquidity holds x/yx/y constant, the following proposition shows these results.

Proposition 5.7.

Let c>0c>0, and consider a state (x1,y1)state(fc,x0,y0)(x_{1},y_{1})\in\operatorname{state}(f_{c,x_{0},y_{0}}) and some (x2,y2)>02(x_{2},y_{2})\in\mathbb{R}_{>0}^{2} such that x1y1=x2y2\frac{x_{1}}{y_{1}}=\frac{x_{2}}{y_{2}}, where we fix (x0,y0)>02(x_{0},y_{0})\in\mathbb{R}_{>0}^{2}. Then pc,x0,y0(x1)=pc,x2,y2(x2)p_{c,x_{0},y_{0}}(x_{1})=p_{c,x_{2},y_{2}}(x_{2}). Furthermore, sc,x0,y0(x1)>sc,x2,y2(x2)s_{c,x_{0},y_{0}}(x_{1})>s_{c,x_{2},y_{2}}(x_{2}) if and only if y1<y2y_{1}<y_{2}.

Proof.

Observe that

fc,x0,y0(x)=cy0(xx0)c11x0=cfc,x0,y0(x)xf_{c,x_{0},y_{0}}^{\prime}(x)=-cy_{0}\left(\frac{x}{x_{0}}\right)^{-c-1}\frac{1}{x_{0}}=-c\cdot\frac{f_{c,x_{0},y_{0}}(x)}{x}

for all x>0x>0. Because (x1,y1)state(fc,x0,y0)(x_{1},y_{1})\in\operatorname{state}(f_{c,x_{0},y_{0}}) and (x2,y2)state(fc,x2,y2)(x_{2},y_{2})\in\operatorname{state}(f_{c,x_{2},y_{2}}), we have

pc,x0,y0(x1)=1cfc,x0,y0(x1)x1=x1cy1=x2cy2=1cfc,x2,y2(x2)x2=pc,x2,y2(x2).p_{c,x_{0},y_{0}}(x_{1})=\frac{1}{c\cdot\frac{f_{c,x_{0},y_{0}}(x_{1})}{x_{1}}}=\frac{x_{1}}{cy_{1}}=\frac{x_{2}}{cy_{2}}=\frac{1}{c\cdot\frac{f_{c,x_{2},y_{2}}(x_{2})}{x_{2}}}=p_{c,x_{2},y_{2}}(x_{2}).

We also have

fc,x0,y0′′(x)=c(c+1)y0(xx0)c21x02=c(c+1)fc,x0,y0(x)x2,f_{c,x_{0},y_{0}}^{\prime\prime}(x)=c(c+1)y_{0}\left(\frac{x}{x_{0}}\right)^{-c-2}\cdot\frac{1}{x_{0}^{2}}=c(c+1)\cdot\frac{f_{c,x_{0},y_{0}}(x)}{x^{2}},

so that sc,x0,y0(x)=c+1c1fc,x0,y0(x)s_{c,x_{0},y_{0}}(x)=\frac{c+1}{c}\cdot\frac{1}{f_{c,x_{0},y_{0}}(x)} for all x>0x>0. It follows that

sc,x0,y0(x1)=c+1c1y1,sc,x2,y2(x2)=c+1c1y2s_{c,x_{0},y_{0}}(x_{1})=\frac{c+1}{c}\cdot\frac{1}{y_{1}},\qquad s_{c,x_{2},y_{2}}(x_{2})=\frac{c+1}{c}\cdot\frac{1}{y_{2}}

since (x1,y1)state(fc,x0,y0)(x_{1},y_{1})\in\operatorname{state}(f_{c,x_{0},y_{0}}) and (x2,y2)state(fc,x2,y2)(x_{2},y_{2})\in\operatorname{state}(f_{c,x_{2},y_{2}}). Hence sc,x0,y0(x1)>sc,x2,y2(x2)s_{c,x_{0},y_{0}}(x_{1})>s_{c,x_{2},y_{2}}(x_{2}) if and only if y1<y2y_{1}<y_{2}. ∎

6 Freezing Liquidity and Related Methods

With expiring assets (and exogenous events that affect price), it is important to avoid that LPs have their cash (XX) drained upon a sudden decrease in demand for tokens (YY). In this section, we discuss liquidity freezing, a tool allowing an LP to alter how much of its liquidity the AMM can use for trading under current market conditions.

LPs add liquidity in a way almost identical to AMMs such as Uniswap [1]. If (x,y)(x,y) is the current liquidity state of the AMM, then any party \ell may deposit x>0x_{\ell}>0 of XX and y>0y_{\ell}>0 of YY in a proportion that reflects the current price: xy=xy\frac{x_{\ell}}{y_{\ell}}=\frac{x}{y}.333In an initial state where x=0x=0 or y=0y=0, there are no restrictions on how liquidity is added. Then the state (x,y)(x,y) is updated appropriately, we do x0xx_{0}\leftarrow x and y0yy_{0}\leftarrow y, and finally, LL{}L\leftarrow L\cup\{\ell\}. The depositing LP receives shares in the usual way, but in addition it is allowed to specify its contribution c[a,b]c_{\ell}\in[a,b] in the 𝚊𝚐𝚐𝚛𝚎𝚐𝚊𝚝𝚎()\mathtt{aggregate}() algorithm (Equation 1), changing the state curve at the next epoch boundary. However, an LP can freeze its liquidity when it considers market conditions to be adverse. The LP establishes a bound on the spot price of tokens (YY) in terms of cash (XX) below which its liquidity will not participate. Each liquidity provider LL\ell\in L\cup L^{\prime} sets a lower bound d0d_{\ell}\geq 0, updated at the beginning of each epoch (after 𝚛𝚎𝚖𝚘𝚟𝚎𝙻𝚒𝚚𝚞𝚒𝚍𝚒𝚝𝚢()\mathtt{removeLiquidity}() and 𝚕𝚒𝚚𝚞𝚒𝚍𝚊𝚝𝚎()\mathtt{liquidate}() defined subsequently). A liquidity provider \ell can alter its dd_{\ell} at any time, but no change will occur until the next epoch boundary.

For any initial state (x0,y0)(x_{0},y_{0}) and current state (x,y)(x,y) of the AMM with aggregate constant cc, let pp denote the (instantaneous) spot price

p=1fc,x0,y0(x),p=\frac{1}{-f_{c,x_{0},y_{0}}^{\prime}(x)},

as defined in Definition 5.4. This value is stored in the AMM and is updated appropriately. As soon as p<dp<d_{\ell} for some \ell, the AMM moves \ell’s liquidity into a distinct, untraded liquidity pool. If, at a later time, pdp\geq d_{\ell}, the AMM unfreezes \ell’s liquidity by moving it back into the trading state. To ensure no consumer or producer pushes pp to be much smaller than some dd_{\ell}, trades are restricted to one unit increments. The assumption is primarily made for simplification of the proof of Proposition 6.3. For completeness, we write the exact trading algorithm for multiple tokens YY and the corresponding system state changes in pseudocode below. A more efficient implementation is a discretized version of Uniswap V3’s concentrated liquidity [13]. We delay discussion of Lines 1-1 and  1-1 to Section 7.

1 if 𝚝𝚘𝚔𝚎𝚗𝙸𝚗=X\mathtt{tokenIn}=X then
2       𝚊𝚖𝚘𝚞𝚗𝚝𝚄𝚜𝚎𝚍0\mathtt{amountUsed}\leftarrow 0
3      𝚍𝚘𝚗𝚎𝚏𝚊𝚕𝚜𝚎\mathtt{done}\leftarrow\mathtt{false}
4      while LL\neq\emptyset and not 𝚍𝚘𝚗𝚎\mathtt{done} do
5             Let 𝚙𝚛𝚒𝚌𝚎\mathtt{price} be the current price in XX to buy one YY token
6            𝚊𝚖𝚘𝚞𝚗𝚝𝚄𝚜𝚎𝚍𝚊𝚖𝚘𝚞𝚗𝚝𝚄𝚜𝚎𝚍+𝚙𝚛𝚒𝚌𝚎\mathtt{amountUsed}\leftarrow\mathtt{amountUsed}+\mathtt{price}
7            if 𝚊𝚖𝚘𝚞𝚗𝚝𝚄𝚜𝚎𝚍>𝚊𝚖𝚘𝚞𝚗𝚝𝙸𝚗\mathtt{amountUsed}>\mathtt{amountIn} then
8                   𝚍𝚘𝚗𝚎𝚝𝚛𝚞𝚎\mathtt{done}\leftarrow\mathtt{true}
9            
10            else
11                   𝚝𝚛𝚊𝚗𝚜𝚏𝚎𝚛𝙸𝚗(𝚙𝚛𝚒𝚌𝚎,X,𝚜𝚘𝚞𝚛𝚌𝚎=𝚊𝚍𝚍𝚛𝚎𝚜𝚜)\mathtt{transferIn}(\mathtt{price},X,\mathtt{source=address})
12                  𝚝𝚛𝚊𝚗𝚜𝚏𝚎𝚛𝙾𝚞𝚝(1,Y,𝚍𝚎𝚜𝚝𝚒𝚗𝚊𝚝𝚒𝚘𝚗=𝚊𝚍𝚍𝚛𝚎𝚜𝚜)\mathtt{transferOut}(1,Y,\mathtt{destination=address})
13                  𝚏𝚛𝚎𝚎𝚣𝚎_𝚞𝚗𝚏𝚛𝚎𝚎𝚣𝚎()\mathtt{freeze\_unfreeze}()
14                  for L\ell\in L do
15                         rr+s𝚙𝚛𝚒𝚌𝚎r_{\ell}\leftarrow r_{\ell}+s_{\ell}\cdot\mathtt{price}
16                  
17            
18      
19if 𝚝𝚘𝚔𝚎𝚗𝙸𝚗=Y\mathtt{tokenIn}=Y then
20       𝚝𝚘𝚔𝚎𝚗𝚜𝚄𝚜𝚎𝚍0\mathtt{tokensUsed}\leftarrow 0
21      𝚍𝚘𝚗𝚎𝚏𝚊𝚕𝚜𝚎\mathtt{done}\leftarrow\mathtt{false}
22      while LL\neq\emptyset and not 𝚍𝚘𝚗𝚎\mathtt{done} do
23             Let 𝚙𝚛𝚒𝚌𝚎\mathtt{price} be the current price in XX to sell one YY token
24            𝚝𝚘𝚔𝚎𝚗𝚜𝚄𝚜𝚎𝚍𝚝𝚘𝚔𝚎𝚗𝚜𝚄𝚜𝚎𝚍+1\mathtt{tokensUsed}\leftarrow\mathtt{tokensUsed}+1
25            if 𝚝𝚘𝚔𝚎𝚗𝚜𝚄𝚜𝚎𝚍>𝚊𝚖𝚘𝚞𝚗𝚝𝙸𝚗\mathtt{tokensUsed}>\mathtt{amountIn} then
26                   𝚍𝚘𝚗𝚎𝚝𝚛𝚞𝚎\mathtt{done}\leftarrow\mathtt{true}
27            
28            else
29                   𝚝𝚛𝚊𝚗𝚜𝚏𝚎𝚛𝙸𝚗(1,Y,𝚜𝚘𝚞𝚛𝚌𝚎=𝚊𝚍𝚍𝚛𝚎𝚜𝚜)\mathtt{transferIn}(1,Y,\mathtt{source=address})
30                  𝚝𝚛𝚊𝚗𝚜𝚏𝚎𝚛𝙾𝚞𝚝(𝚙𝚛𝚒𝚌𝚎,X,𝚍𝚎𝚜𝚝𝚒𝚗𝚊𝚝𝚒𝚘𝚗=𝚊𝚍𝚍𝚛𝚎𝚜𝚜)\mathtt{transferOut}(\mathtt{price},X,\mathtt{destination=address})
31                  𝚏𝚛𝚎𝚎𝚣𝚎_𝚞𝚗𝚏𝚛𝚎𝚎𝚣𝚎()\mathtt{freeze\_unfreeze}()
32                  for L\ell\in L do
33                         rr+s𝚙𝚛𝚒𝚌𝚎r_{\ell}\leftarrow r_{\ell}+s_{\ell}\cdot\mathtt{price}
34                  
35            
36      
Algorithm 1 𝚝𝚛𝚊𝚍𝚎(𝚝𝚘𝚔𝚎𝚗𝙸𝚗,𝚊𝚖𝚘𝚞𝚗𝚝𝙸𝚗,𝚊𝚍𝚍𝚛𝚎𝚜𝚜)\mathtt{trade(tokenIn,amountIn,address)}

We showed in Proposition 5.7 that the price pp is invariant under adding and removing liquidity, so we update pp only on epoch boundaries and after every trade. The AMM maintains the set {d}LL\{d_{\ell}\}_{\ell\in L\cup L^{\prime}} and a map 𝚏𝚛:L2\mathtt{fr}:L^{\prime}\to\mathbb{R}^{2} to keep track of the liquidity that inactive providers have the right to. Immediately after every epoch boundary and every trade, we execute the method 𝚏𝚛𝚎𝚎𝚣𝚎_𝚞𝚗𝚏𝚛𝚎𝚎𝚣𝚎()\mathtt{freeze\_unfreeze}() defined in Algorithm 2.

1 𝚞𝚗𝚏𝚛𝚎𝚎𝚣𝚎()\mathtt{unfreeze}()
𝚏𝚛𝚎𝚎𝚣𝚎()\mathtt{freeze}()
Algorithm 2 𝚏𝚛𝚎𝚎𝚣𝚎_𝚞𝚗𝚏𝚛𝚎𝚎𝚣𝚎()\mathtt{freeze\_unfreeze()}

The 𝚏𝚛𝚎𝚎𝚣𝚎()\mathtt{freeze}() function finds all active liquidity providers \ell whose price tolerance dd_{\ell} is less than the current price, and moves their liquidity into a non-trading pool. If LL\neq\emptyset, 𝚞𝚗𝚏𝚛𝚎𝚎𝚣𝚎()\mathtt{unfreeze}() finds the inactive liquidity providers \ell whose price tolerance dd_{\ell} is at least pp, and moves as much of their inactive liquidity back into the trading pool as possible, subject to preserving the ratio of xx to yy in the liquidity pool. If, however, L=L=\emptyset, the instantaneous price pp is not well-defined, so we retrieve the values of xx and yy from the last point in time where some liquidity provider was active, and unfreeze all the liquidity providers to have a liquidity ratio of x/yx/y. In both cases L=L=\emptyset or LL\neq\emptyset, the 𝚏𝚛𝚎𝚎𝚣𝚎_𝚞𝚗𝚏𝚛𝚎𝚎𝚣𝚎()\mathtt{freeze\_unfreeze}() method freezes or unfreezes liquidity providers as needed.

1
2L𝚏𝚛𝚎𝚎𝚣𝚎{L:p<d}L_{\mathtt{freeze}}\leftarrow\{\ell\in L:p<d_{\ell}\}
3 LLL𝚏𝚛𝚎𝚎𝚣𝚎L\leftarrow L\setminus L_{\mathtt{freeze}}
4 LLL𝚏𝚛𝚎𝚎𝚣𝚎L^{\prime}\leftarrow L^{\prime}\cup L_{\mathtt{freeze}}
5 for L𝚏𝚛𝚎𝚎𝚣𝚎\ell\in L_{\mathtt{freeze}} do
6       𝚏𝚛()(sx,sy)\mathtt{fr}(\ell)\leftarrow(s_{\ell}x,s_{\ell}y)
7      
8s𝚝𝚘𝚝𝚊𝚕kLsks_{\mathtt{total}}\leftarrow\sum_{k\in L}s_{k}
9 xs𝚝𝚘𝚝𝚊𝚕xx\leftarrow s_{\mathtt{total}}x
10 ys𝚝𝚘𝚝𝚊𝚕yy\leftarrow s_{\mathtt{total}}y
11 for L\ell\in L do
12       sss𝚝𝚘𝚝𝚊𝚕s_{\ell}\leftarrow\frac{s_{\ell}}{s_{\mathtt{total}}}
Algorithm 3 𝚏𝚛𝚎𝚎𝚣𝚎()\mathtt{freeze()}
1
2if L=L=\emptyset then
3       Let rr be the ratio x/yx/y the last instant where LL\neq\emptyset.
4       while L\exists\ell\in L^{\prime} do
5             𝚞𝚗𝚏𝚛𝚎𝚎𝚣𝚎𝙿𝚛𝚘𝚟𝚒𝚍𝚎𝚛(,r)\mathtt{unfreezeProvider}(\ell,r)
6            
7      LLL\leftarrow L^{\prime}
8       LL^{\prime}\leftarrow\emptyset
9      
10else
11       L𝚞𝚗𝚏𝚛𝚎𝚎𝚣𝚎{L:pd}L_{\mathtt{unfreeze}}\leftarrow\{\ell\in L^{\prime}:p\geq d_{\ell}\}
12       while L𝚞𝚗𝚏𝚛𝚎𝚎𝚣𝚎L\exists\ell\in L_{\mathtt{unfreeze}}\cap L^{\prime} do
13             𝚞𝚗𝚏𝚛𝚎𝚎𝚣𝚎𝙿𝚛𝚘𝚟𝚒𝚍𝚎𝚛(,x/y)\mathtt{unfreezeProvider}(\ell,x/y)
14      
Algorithm 4 𝚞𝚗𝚏𝚛𝚎𝚎𝚣𝚎()\mathtt{unfreeze()}
1
2require L\ell\in L^{\prime}
3(x,y)𝚏𝚛()(x_{\ell},y_{\ell})\leftarrow\mathtt{fr}(\ell)
4 if x/yrx_{\ell}/y_{\ell}\geq r then
5       xryx_{\ell}^{\prime}\leftarrow ry_{\ell}
6       yyy_{\ell}^{\prime}\leftarrow y_{\ell}
7       yy+yy\leftarrow y+y_{\ell}
8       xx+xx\leftarrow x+x_{\ell}^{\prime}
9       𝚝𝚛𝚊𝚗𝚜𝚏𝚎𝚛𝙾𝚞𝚝(xx,X,𝚍𝚎𝚜𝚝𝚒𝚗𝚊𝚝𝚒𝚘𝚗=)\mathtt{transferOut}(x_{\ell}-x_{\ell}^{\prime},X,\mathtt{destination}=\ell)
10else
11       xxx_{\ell}^{\prime}\leftarrow x_{\ell}
12       yx/ry_{\ell}^{\prime}\leftarrow x_{\ell}/r
13       yy+yy\leftarrow y+y_{\ell}^{\prime}
14       xx+xx\leftarrow x+x_{\ell}
15       𝚝𝚛𝚊𝚗𝚜𝚏𝚎𝚛𝙾𝚞𝚝(yy,Y,𝚍𝚎𝚜𝚝𝚒𝚗𝚊𝚝𝚒𝚘𝚗=)\mathtt{transferOut}(y_{\ell}-y_{\ell}^{\prime},Y,\mathtt{destination}=\ell)
16LL{}L^{\prime}\leftarrow L^{\prime}\setminus\{\ell\}
17 LL{}L\leftarrow L\cup\{\ell\}
18 sxxs_{\ell}\leftarrow\frac{x_{\ell}^{\prime}}{x}
19 for lL{}l\in L\setminus\{\ell\} do
20       slsl(1s)s_{l}\leftarrow s_{l}\cdot(1-s_{\ell})
21
Algorithm 5 𝚞𝚗𝚏𝚛𝚎𝚎𝚣𝚎𝙿𝚛𝚘𝚟𝚒𝚍𝚎𝚛(,r)\mathtt{unfreezeProvider}(\ell,r)

Finally, we define 𝚛𝚎𝚖𝚘𝚟𝚎𝙻𝚒𝚚𝚞𝚒𝚍𝚒𝚝𝚢()\mathtt{removeLiquidity}() and 𝚕𝚒𝚚𝚞𝚒𝚍𝚊𝚝𝚎()\mathtt{liquidate}(). These methods are similar, but with one key difference. When 𝚛𝚎𝚖𝚘𝚟𝚎𝙻𝚒𝚚𝚞𝚒𝚍𝚒𝚝𝚢()\mathtt{removeLiquidity}() is called by some LL\ell\in L\cup L^{\prime}, the AMM adds \ell to a set L𝚛𝚎𝚖𝚘𝚟𝚎L_{\mathtt{remove}} initialized to \emptyset; at the next epoch boundary, the AMM simply sends the assets that each L𝚛𝚎𝚖𝚘𝚟𝚎\ell\in L_{\mathtt{remove}} has the right to (computed in the obvious way, depending on if L\ell\in L or L\ell\in L^{\prime}) back to \ell, while doing the appropriate bookkeeping. As this is the only difference from usual practice (e.g., [1]), so pseudocode is omitted.

Like 𝚛𝚎𝚖𝚘𝚟𝚎𝙻𝚒𝚚𝚞𝚒𝚍𝚒𝚝𝚢()\mathtt{removeLiquidity}(), when 𝚕𝚒𝚚𝚞𝚒𝚍𝚊𝚝𝚎()\mathtt{liquidate}() is called by an LP LL\ell\in L\cup L^{\prime}, then \ell is added to a set L𝚕𝚒𝚚𝚞𝚒𝚍𝚊𝚝𝚎L_{\mathtt{liquidate}}. At each epoch boundary, the following is executed in an atomic step: for each liquidity provider in L𝚕𝚒𝚚𝚞𝚒𝚍𝚊𝚝𝚎L_{\mathtt{liquidate}}, get the amounts of XX and YY they have the right to, remove this liquidity, sell the total units of YY that have been traded for XX, and distribute these funds to each member of L𝚕𝚒𝚚𝚞𝚒𝚍𝚊𝚝𝚎L_{\mathtt{liquidate}} in proportion to their shares of asset XX; then set L𝚕𝚒𝚚𝚞𝚒𝚍𝚊𝚝𝚎L_{\mathtt{liquidate}}\leftarrow\emptyset. This protocol is listed as Algorithm 6. Both these methods run atomically at each epoch boundary, where 𝚛𝚎𝚖𝚘𝚟𝚎𝙻𝚒𝚚𝚞𝚒𝚍𝚒𝚝𝚢()\mathtt{removeLiquidity}() is executed first.

1 while L𝚕𝚒𝚚𝚞𝚒𝚍𝚊𝚝𝚎L\exists\ell\in L_{\mathtt{liquidate}}\cap L do
2       xsxx_{\ell}\leftarrow s_{\ell}x
3       ysyy_{\ell}\leftarrow s_{\ell}y
4       xxxx\leftarrow x-x_{\ell}
5       yyyy\leftarrow y-y_{\ell}
6       LL{}L\leftarrow L\setminus\{\ell\}
7while L𝚕𝚒𝚚𝚞𝚒𝚍𝚊𝚝𝚎L\exists\ell\in L_{\mathtt{liquidate}}\cap L^{\prime} do
8       (x,y)𝚏𝚛()(x_{\ell},y_{\ell})\leftarrow\mathtt{fr}(\ell)
9       LL{}L^{\prime}\leftarrow L^{\prime}\setminus\{\ell\} delete 𝚏𝚛()\mathtt{fr}(\ell)
10s𝚝𝚘𝚝𝚊𝚕kLsks_{\mathtt{total}}\leftarrow\sum_{k\in L}s_{k}
11 for L\ell\in L do
12       sss𝚝𝚘𝚝𝚊𝚕s_{\ell}\leftarrow\frac{s_{\ell}}{s_{\mathtt{total}}}
13y𝚕𝚒𝚚𝚞𝚒𝚍𝚊𝚝𝚎L𝚕𝚒𝚚𝚞𝚒𝚍𝚊𝚝𝚎yy_{\mathtt{liquidate}}\leftarrow\sum_{\ell\in L_{\mathtt{liquidate}}}y_{\ell}
14x𝚕𝚒𝚚𝚞𝚒𝚍𝚊𝚝𝚎0x_{\mathtt{liquidate}}\leftarrow 0
15for L𝚕𝚒𝚚𝚞𝚒𝚍𝚊𝚝𝚎\ell\in L_{\mathtt{liquidate}} do
16       s¯yy𝚕𝚒𝚚𝚞𝚒𝚍𝚊𝚝𝚎\overline{s_{\ell}}\leftarrow\frac{y_{\ell}}{y_{\mathtt{liquidate}}}
17
18/* Sell the y𝚕𝚒𝚚𝚞𝚒𝚍𝚊𝚝𝚎y_{\mathtt{liquidate}} units of YY back to the AMM one at a time */
19while y𝚕𝚒𝚚𝚞𝚒𝚍𝚊𝚝𝚎>0y_{\mathtt{liquidate}}>0 and LL\neq\emptyset do
20       Trade one unit of YY for x𝚛𝚎𝚝𝚞𝚛𝚗𝚎𝚍x_{\mathtt{returned}} units of XX /* This updates state
21       variables appropriately */
22      x𝚕𝚒𝚚𝚞𝚒𝚍𝚊𝚝𝚎x𝚕𝚒𝚚𝚞𝚒𝚍𝚊𝚝𝚎+x𝚛𝚎𝚝𝚞𝚛𝚗𝚎𝚍x_{\mathtt{liquidate}}\leftarrow x_{\mathtt{liquidate}}+x_{\mathtt{returned}}
23       y𝚕𝚒𝚚𝚞𝚒𝚍𝚊𝚝𝚎y𝚕𝚒𝚚𝚞𝚒𝚍𝚊𝚝𝚎1y_{\mathtt{liquidate}}\leftarrow y_{\mathtt{liquidate}}-1
24
25for L𝚕𝚒𝚚𝚞𝚒𝚍𝚊𝚝𝚎\ell\in L_{\mathtt{liquidate}} do
26       xx+s¯x𝚕𝚒𝚚𝚞𝚒𝚍𝚊𝚝𝚎x_{\ell}\leftarrow x_{\ell}+\overline{s_{\ell}}\cdot x_{\mathtt{liquidate}}
27       ys¯y𝚕𝚒𝚚𝚞𝚒𝚍𝚊𝚝𝚎y_{\ell}\leftarrow\overline{s_{\ell}}\cdot y_{\mathtt{liquidate}}
28       𝚝𝚛𝚊𝚗𝚜𝚏𝚎𝚛𝙾𝚞𝚝(x,X,𝚍𝚎𝚜𝚝𝚒𝚗𝚊𝚝𝚒𝚘𝚗=)\mathtt{transferOut}(x_{\ell},X,\mathtt{destination}=\ell)
29       𝚝𝚛𝚊𝚗𝚜𝚏𝚎𝚛𝙾𝚞𝚝(y,Y,𝚍𝚎𝚜𝚝𝚒𝚗𝚊𝚝𝚒𝚘𝚗=)\mathtt{transferOut}(y_{\ell},Y,\mathtt{destination}=\ell)
L𝚕𝚒𝚚𝚞𝚒𝚍𝚊𝚝𝚎L_{\mathtt{liquidate}}\leftarrow\emptyset
Algorithm 6 𝚕𝚒𝚚𝚞𝚒𝚍𝚊𝚝𝚎()\mathtt{liquidate()}

6.1 Freezing, Removal, and Liquidation Properties

The advantage of including two different ways of removing liquidity and only at epoch boundaries is primarily to spread out the loss of the liquidity providers who choose to liquidate and provide those who call 𝚛𝚎𝚖𝚘𝚟𝚎𝙻𝚒𝚚𝚞𝚒𝚍𝚒𝚝𝚢()\mathtt{removeLiquidity}() a guaranteed risk-free liquidity removal; the received liquidity from the 𝚛𝚎𝚖𝚘𝚟𝚎𝙻𝚒𝚚𝚞𝚒𝚍𝚒𝚝𝚢()\mathtt{removeLiquidity}() method is not affected by liquidity providers calling 𝚕𝚒𝚚𝚞𝚒𝚍𝚊𝚝𝚎()\mathtt{liquidate}() since the AMM’s execution of 𝚛𝚎𝚖𝚘𝚟𝚎𝙻𝚒𝚚𝚞𝚒𝚍𝚒𝚝𝚢()\mathtt{removeLiquidity}() precedes that of 𝚕𝚒𝚚𝚞𝚒𝚍𝚊𝚝𝚎()\mathtt{liquidate}().

We will prove a more formal version of the following claim: no rational liquidity provider will call 𝚛𝚎𝚖𝚘𝚟𝚎𝙻𝚒𝚚𝚞𝚒𝚍𝚒𝚝𝚢()\mathtt{removeLiquidity}() and then sell their YY tokens back to the AMM in exchange for XX. In particular, this means that liquidity providers who wish to keep their YY tokens upon removal call the 𝚛𝚎𝚖𝚘𝚟𝚎𝙻𝚒𝚚𝚞𝚒𝚍𝚒𝚝𝚢()\mathtt{removeLiquidity}() method, and liquidity providers who only want to remove liquidity with the maximum number of XX tokens possible (YY is worthless to them) call the 𝚕𝚒𝚚𝚞𝚒𝚍𝚊𝚝𝚎()\mathtt{liquidate}() method. First, we prove the following lemmas.

Lemma 6.1.

Let c>0c>0 and (x0,y0)>02(x_{0},y_{0})\in\mathbb{R}_{>0}^{2}. If (x,y)state(fc,x0,y0)(x^{\prime},y^{\prime})\in\operatorname{state}(f_{c,x_{0},y_{0}}) and (x′′,y′′)>02(x^{\prime\prime},y^{\prime\prime})\in\mathbb{R}_{>0}^{2} satisfy xy=x′′y′′\frac{x^{\prime}}{y^{\prime}}=\frac{x^{\prime\prime}}{y^{\prime\prime}} and x′′<xx^{\prime\prime}<x^{\prime} and y′′<yy^{\prime\prime}<y^{\prime}, then

|fc,x′′,y′′(x)||fc,x0,y0(x+xx′′)|,|f_{c,x^{\prime\prime},y^{\prime\prime}}^{\prime}(x)|\geq|f_{c,x_{0},y_{0}}^{\prime}(x+x^{\prime}-x^{\prime\prime})|,

for all x(0,x′′]x\in(0,x^{\prime\prime}].

Proof.

Suppose (x,y)state(fc,x0,y0)(x^{\prime},y^{\prime})\in\operatorname{state}(f_{c,x_{0},y_{0}}) and (x′′,y′′)>02(x^{\prime\prime},y^{\prime\prime})\in\mathbb{R}_{>0}^{2} satisfy xy=x′′y′′\frac{x^{\prime}}{y^{\prime}}=\frac{x^{\prime\prime}}{y^{\prime\prime}} and x′′<xx^{\prime\prime}<x^{\prime} and y′′<yy^{\prime\prime}<y^{\prime}. Notice that

fc,x0,y0(x)=cy0(xx0)c11x0=cfc,x0,y0(x)x,f_{c,x_{0},y_{0}}^{\prime}(x)=-cy_{0}\left(\frac{x}{x_{0}}\right)^{-c-1}\cdot\frac{1}{x_{0}}=-c\cdot\frac{f_{c,x_{0},y_{0}}(x)}{x},

and similarly,

fc,x′′,y′′(x)=cfc,x′′,y′′(x)x.f_{c,x^{\prime\prime},y^{\prime\prime}}^{\prime}(x)=-c\cdot\frac{f_{c,x^{\prime\prime},y^{\prime\prime}}(x)}{x}.

Since (x,y)state(fc,x0,y0)(x^{\prime},y^{\prime})\in\operatorname{state}(f_{c,x_{0},y_{0}}), we know

fc,x0,y0(x)=y0x0cxc=y0(xx0)c(x)cxc=fc,x0,y0(x)(x)cxc=y(x)cxc.f_{c,x_{0},y_{0}}(x)=y_{0}x_{0}^{c}x^{-c}=y_{0}\left(\frac{x^{\prime}}{x_{0}}\right)^{-c}(x^{\prime})^{c}x^{-c}=f_{c,x_{0},y_{0}}(x^{\prime})\cdot(x^{\prime})^{c}x^{-c}=y^{\prime}(x^{\prime})^{c}x^{-c}.

Fix some x(0,x′′]x\in(0,x^{\prime\prime}]. Since xx′′0x^{\prime}-x^{\prime\prime}\geq 0, 0<x′′x0<x^{\prime\prime}\leq x^{\prime}, and xx′′=yy′′\frac{x^{\prime}}{x^{\prime\prime}}=\frac{y^{\prime}}{y^{\prime\prime}}, we have

(x+xx′′x)c+1\displaystyle\left(\frac{x+x^{\prime}-x^{\prime\prime}}{x}\right)^{c+1} (1+xx′′x)c+1(1+xx′′x′′)c+1\displaystyle\geq\left(1+\frac{x^{\prime}-x^{\prime\prime}}{x}\right)^{c+1}\geq\left(1+\frac{x^{\prime}-x^{\prime\prime}}{x^{\prime\prime}}\right)^{c+1}
=(xx′′)c+1=yy′′(xx′′)c.\displaystyle=\left(\frac{x^{\prime}}{x^{\prime\prime}}\right)^{c+1}=\frac{y^{\prime}}{y^{\prime\prime}}\cdot\left(\frac{x^{\prime}}{x^{\prime\prime}}\right)^{c}.

It follows that

y′′xc1(x′′)cy(x+xx′′)c1(x)c.y^{\prime\prime}\cdot x^{-c-1}(x^{\prime\prime})^{c}\geq y^{\prime}(x+x^{\prime}-x^{\prime\prime})^{-c-1}(x^{\prime})^{c}.

Multiplying by cc yields that

|fc,x′′,y′′(x)|\displaystyle|f_{c,x^{\prime\prime},y^{\prime\prime}}^{\prime}(x)| =cfc,x′′,y′′(x)x=cy′′xc1(x′′)c\displaystyle=c\cdot\frac{f_{c,x^{\prime\prime},y^{\prime\prime}}(x)}{x}=c\cdot y^{\prime\prime}x^{-c-1}(x^{\prime\prime})^{c}
cy(x+xx′′x)cx+xx′′=cfc,x0,y0(x+xx′′)x+xx′′\displaystyle\geq c\cdot\frac{y^{\prime}\left(\frac{x+x^{\prime}-x^{\prime\prime}}{x^{\prime}}\right)^{-c}}{x+x^{\prime}-x^{\prime\prime}}=c\cdot\frac{f_{c,x_{0},y_{0}}(x+x^{\prime}-x^{\prime\prime})}{x+x^{\prime}-x^{\prime\prime}}
=|fc,x0,y0(x+xx′′)|.\displaystyle=|f_{c,x_{0},y_{0}}^{\prime}(x+x^{\prime}-x^{\prime\prime})|.

Lemma 6.2.

Suppose some party sells one unit of YY to the AMM for x1x_{1} of XX, and then sells another unit of YY to the AMM for x2x_{2} of XX. Then x1x2x_{1}\geq x_{2}.

Proof.

Let fc,x0,y0f_{c,x_{0},y_{0}} be the state curve before the first trade. If LL and LL^{\prime} are the same after the first trade (so 𝚏𝚛𝚎𝚎𝚣𝚎_𝚞𝚗𝚏𝚛𝚎𝚎𝚣𝚎()\mathtt{freeze\_unfreeze}() did not update any global variables), then since fc,x0,y0f_{c,x_{0},y_{0}} is a convex function, we certainly have x1x2x_{1}\geq x_{2}.

Now suppose the execution of 𝚏𝚛𝚎𝚎𝚣𝚎_𝚞𝚗𝚏𝚛𝚎𝚎𝚣𝚎()\mathtt{freeze\_unfreeze}() changed the sets LL and LL^{\prime} after the first trade. It suffices to prove that x2x_{2} is at most the amount of XX one would get if the state curve never updated and was always equal to fc,x0,y0f_{c,x_{0},y_{0}}, given the observation above. To this end, we consider two possible cases for the second trade. Let (x,y)state(fc,x0,y0)(x^{\prime},y^{\prime})\in\operatorname{state}(f_{c,x_{0},y_{0}}) be the state after the first trade but before calling 𝚏𝚛𝚎𝚎𝚣𝚎_𝚞𝚗𝚏𝚛𝚎𝚎𝚣𝚎()\mathtt{freeze\_unfreeze}(); let (x′′,y′′)(x^{\prime\prime},y^{\prime\prime}) be the state after completing the first trade, so the state curve updates to fc,x′′,y′′f_{c,x^{\prime\prime},y^{\prime\prime}}. Observe that the updated set LL after the first trade is a subset of the initial LL because the instantaneous price pp can only decrease after the first selling trade. By inspection of 𝚏𝚛𝚎𝚎𝚣𝚎()\mathtt{freeze}() and 𝚞𝚗𝚏𝚛𝚎𝚎𝚣𝚎()\mathtt{unfreeze}(), we see that xy=x′′y′′\frac{x^{\prime}}{y^{\prime}}=\frac{x^{\prime\prime}}{y^{\prime\prime}} but 0<x′′<x0<x^{\prime\prime}<x^{\prime} and 0<y′′<y0<y^{\prime\prime}<y^{\prime}.

Let x2x_{2}^{\prime} be the amount received for the second trade if the state curve is fc,x0,y0f_{c,x_{0},y_{0}}; let x2′′x_{2}^{\prime\prime} be the amount received for the second trade if the state curve is fc,x′′,y′′f_{c,x^{\prime\prime},y^{\prime\prime}}. The convexity of fc,x0,y0f_{c,x_{0},y_{0}} implies that x1x2x_{1}\geq x_{2}^{\prime}. If we can show x2x2′′x_{2}^{\prime}\geq x_{2}^{\prime\prime}, then we know x1x2x_{1}\geq x_{2} because x2{x2,x2′′}x_{2}\in\{x_{2}^{\prime},x_{2}^{\prime\prime}\}.

By Lemma 6.1, |fc,x′′,y′′(x)||fc,x0,y0(x+xx′′)||f_{c,x^{\prime\prime},y^{\prime\prime}}^{\prime}(x)|\geq|f_{c,x_{0},y_{0}}^{\prime}(x+x^{\prime}-x^{\prime\prime})| for all x(0,x′′]x\in(0,x^{\prime\prime}]. This implies that

|ddyfc,x′′,y′′1(y)||ddyfc,x0,y01(y+yy′′)|\left|\frac{d}{dy}f^{-1}_{c,x^{\prime\prime},y^{\prime\prime}}(y)\right|\leq\left|\frac{d}{dy}f^{-1}_{c,x_{0},y_{0}}(y+y^{\prime}-y^{\prime\prime})\right|

for all y[y′′,)y\in[y^{\prime\prime},\infty).

Finally, we prove x2x2′′x_{2}^{\prime}\geq x_{2}^{\prime\prime}, showing the lemma. We have

x2\displaystyle x_{2}^{\prime} =fc,x0,y01(y)fc,x0,y01(y+1)\displaystyle=f^{-1}_{c,x_{0},y_{0}}(y^{\prime})-f^{-1}_{c,x_{0},y_{0}}(y^{\prime}+1)
=y′′+1y′′ddyfc,x0,y01(y+yy′′)𝑑y\displaystyle=\int_{y^{\prime\prime}+1}^{y^{\prime\prime}}\frac{d}{dy}f^{-1}_{c,x_{0},y_{0}}(y+y^{\prime}-y^{\prime\prime})dy
=y′′y′′+1|ddyfc,x0,y01(y+yy′′)|𝑑y\displaystyle=\int_{y^{\prime\prime}}^{y^{\prime\prime}+1}\left|\frac{d}{dy}f^{-1}_{c,x_{0},y_{0}}(y+y^{\prime}-y^{\prime\prime})\right|dy
y′′y′′+1|ddyfc,x′′,y′′1(y)|𝑑y\displaystyle\geq\int_{y^{\prime\prime}}^{y^{\prime\prime}+1}\left|\frac{d}{dy}f^{-1}_{c,x^{\prime\prime},y^{\prime\prime}}(y)\right|dy
=y′′+1y′′ddyfc,x′′,y′′1(y)𝑑y\displaystyle=\int_{y^{\prime\prime}+1}^{y^{\prime\prime}}\frac{d}{dy}f^{-1}_{c,x^{\prime\prime},y^{\prime\prime}}(y)dy
=fc,x′′,y′′1(y′′)fc,x′′,y′′1(y′′+1)=x2′′.\displaystyle=f^{-1}_{c,x^{\prime\prime},y^{\prime\prime}}(y^{\prime\prime})-f^{-1}_{c,x^{\prime\prime},y^{\prime\prime}}(y^{\prime\prime}+1)=x_{2}^{\prime\prime}.

Proposition 6.3.

Let LL\ell\in L\cup L^{\prime}. Suppose that in some execution α\alpha, the liquidity provider \ell calls 𝚛𝚎𝚖𝚘𝚟𝚎𝙻𝚒𝚚𝚞𝚒𝚍𝚒𝚝𝚢()\mathtt{removeLiquidity}() to obtain x,1αx^{\alpha}_{\ell,1} of XX and y,1αy^{\alpha}_{\ell,1} of YY, and then trades y,1αy^{\alpha}_{\ell,1} of YY to the AMM in exchange for x,2αx^{\alpha}_{\ell,2} of XX, so that \ell receives xα=x,1α+x,2αx^{\alpha}_{\ell}=x^{\alpha}_{\ell,1}+x^{\alpha}_{\ell,2} of XX. Suppose that in some otherwise identical execution β\beta, \ell instead calls 𝚕𝚒𝚚𝚞𝚒𝚍𝚊𝚝𝚎()\mathtt{liquidate}() and receives xβx^{\beta}_{\ell} of XX. Then xαxβx_{\ell}^{\alpha}\leq x_{\ell}^{\beta}.

Proof.

Consider the sets L𝚕𝚒𝚚𝚞𝚒𝚍𝚊𝚝𝚎αL_{\mathtt{liquidate}}^{\alpha} and L𝚕𝚒𝚚𝚞𝚒𝚍𝚊𝚝𝚎βL_{\mathtt{liquidate}}^{\beta} in executions α\alpha and β\beta, respectively. Consider the cc, which is the same in both executions. Notice that, by construction, the effective AMM state (x0,y0)(x_{0},y_{0}) after executing the loop in line 14 of 𝚕𝚒𝚚𝚞𝚒𝚍𝚊𝚝𝚎()\mathtt{liquidate}() is the same in both executions α\alpha and β\beta. Suppose that in execution α\alpha, there is some other liquidity provider (not \ell) that removed liquidity and sold it to the system before \ell. By Lemma 6.2, the received amount x,2αx^{\alpha}_{\ell,2} of XX is at most the amount \ell would have received if \ell was the first provider to sell their removed liquidity back to the AMM. Thus it suffices to prove the claim when \ell was the first liquidity provider to sell their liquidity back to the AMM after 𝚕𝚒𝚚𝚞𝚒𝚍𝚊𝚝𝚎()\mathtt{liquidate}() was called in execution α\alpha.

To this end, consider the sequence (xkα)k=1n(x^{\alpha}_{k})_{k=1}^{n} of received amounts of XX for consecutive single-unit trades made by 𝚕𝚒𝚚𝚞𝚒𝚍𝚊𝚝𝚎()\mathtt{liquidate}() and \ell’s atomic selling trades, in execution α\alpha. Similarly, let (xkβ)k=1n(x^{\beta}_{k})_{k=1}^{n} be the sequence of received amounts of XX for consecutive single-unit trades made by 𝚕𝚒𝚚𝚞𝚒𝚍𝚊𝚝𝚎()\mathtt{liquidate}(), in execution β\beta. It is clear that ny𝚕𝚒𝚚𝚞𝚒𝚍𝚊𝚝𝚎n\leq y_{\mathtt{liquidate}}, as defined in 𝚕𝚒𝚚𝚞𝚒𝚍𝚊𝚝𝚎()\mathtt{liquidate}(), so that we may extend both sequences by setting xkα=xkβ=0x^{\alpha}_{k}=x^{\beta}_{k}=0 for n<ky𝚕𝚒𝚚𝚞𝚒𝚍𝚊𝚝𝚎n<k\leq y_{\mathtt{liquidate}} By the assumption made above, these two sequences are equal: xkα=xkβx^{\alpha}_{k}=x^{\beta}_{k} for all k[y𝚕𝚒𝚚𝚞𝚒𝚍𝚊𝚝𝚎]k\in[y_{\mathtt{liquidate}}]. Then we may let (xk)k=1y𝚕𝚒𝚚𝚞𝚒𝚍𝚊𝚝𝚎(x_{k})_{k=1}^{y_{\mathtt{liquidate}}} be this sequence. By Lemma 6.2, (xk)k=1y𝚕𝚒𝚚𝚞𝚒𝚍𝚊𝚝𝚎(x_{k})_{k=1}^{y_{\mathtt{liquidate}}} is a nonincreasing sequence. Thus

x,2α=k=y𝚕𝚒𝚚𝚞𝚒𝚍𝚊𝚝𝚎y,1α+1y𝚕𝚒𝚚𝚞𝚒𝚍𝚊𝚝𝚎xkαy,1αy𝚕𝚒𝚚𝚞𝚒𝚍𝚊𝚝𝚎k=1y𝚕𝚒𝚚𝚞𝚒𝚍𝚊𝚝𝚎xk=s¯x𝚕𝚒𝚚𝚞𝚒𝚍𝚊𝚝𝚎,x^{\alpha}_{\ell,2}=\sum_{k=y_{\mathtt{liquidate}}-y^{\alpha}_{\ell,1}+1}^{y_{\mathtt{liquidate}}}x^{\alpha}_{k}\leq\frac{y^{\alpha}_{\ell,1}}{y_{\mathtt{liquidate}}}\cdot\sum_{k=1}^{y_{\mathtt{liquidate}}}x_{k}=\overline{s_{\ell}}\cdot x_{\mathtt{liquidate}},

where s¯\overline{s_{\ell}} and x𝚕𝚒𝚚𝚞𝚒𝚍𝚊𝚝𝚎x_{\mathtt{liquidate}} are defined in 𝚕𝚒𝚚𝚞𝚒𝚍𝚊𝚝𝚎()\mathtt{liquidate}(). Note that the xx_{\ell} in 𝚕𝚒𝚚𝚞𝚒𝚍𝚊𝚝𝚎()\mathtt{liquidate}() is equal to x,1αx_{\ell,1}^{\alpha}, so that

xα=x,1α+x,2αx,1α+s¯x𝚕𝚒𝚚𝚞𝚒𝚍𝚊𝚝𝚎=xβ.x_{\ell}^{\alpha}=x_{\ell,1}^{\alpha}+x_{\ell,2}^{\alpha}\leq x_{\ell,1}^{\alpha}+\overline{s_{\ell}}\cdot x_{\mathtt{liquidate}}=x_{\ell}^{\beta}.

We also show that the 𝚏𝚛𝚎𝚎𝚣𝚎_𝚞𝚗𝚏𝚛𝚎𝚎𝚣𝚎()\mathtt{freeze\_unfreeze}() method yields a stable liquidity state; that is, a liquidity provider LL\ell\in L\cup L^{\prime} is active if and only if pdp\geq d_{\ell}. Proving this is important for proving LP Stability in Theorem 8.2.

Proposition 6.4.

Consider the AMM state immediately after calling 𝚏𝚛𝚎𝚎𝚣𝚎_𝚞𝚗𝚏𝚛𝚎𝚎𝚣𝚎()\mathtt{freeze\_unfreeze}(). Let LL\ell\in L\cup L^{\prime}. Then L\ell\in L if and only if pdp\geq d_{\ell}.

Proof.

Inspecting both 𝚏𝚛𝚎𝚎𝚣𝚎()\mathtt{freeze}() and 𝚞𝚗𝚏𝚛𝚎𝚎𝚣𝚎()\mathtt{unfreeze}(), the AMM state changes of the variables (x,y)(x,y) are indistinguishable from a sequence of adding and removing liquidity. By Lemma 5.7, the current instantaneous price pp is invariant throughout 𝚏𝚛𝚎𝚎𝚣𝚎_𝚞𝚗𝚏𝚛𝚎𝚎𝚣𝚎()\mathtt{freeze\_unfreeze}(). If L=L=\emptyset before executing 𝚏𝚛𝚎𝚎𝚣𝚎_𝚞𝚗𝚏𝚛𝚎𝚎𝚣𝚎()\mathtt{freeze\_unfreeze}(), then this implies that after executing 𝚞𝚗𝚏𝚛𝚎𝚎𝚣𝚎()\mathtt{unfreeze}() and 𝚏𝚛𝚎𝚎𝚣𝚎()\mathtt{freeze}(), we can see that L\ell\in L if and only if L𝚏𝚛𝚎𝚎𝚣𝚎\ell\notin L_{\mathtt{freeze}} (as defined in 𝚏𝚛𝚎𝚎𝚣𝚎()\mathtt{freeze}()), which holds if and only if pdp\geq d_{\ell}. On the other hand, if LL\neq\emptyset before executing 𝚏𝚛𝚎𝚎𝚣𝚎_𝚞𝚗𝚏𝚛𝚎𝚎𝚣𝚎()\mathtt{freeze\_unfreeze}(), then by a similar reasoning, L\ell\in L after executing the algorithm if and only pdp\geq d_{\ell}. ∎

7 Market Clearing Auction

In this section, we describe a mechanism for bargain hunters, consumers with low price and low urgency willing to wait until the last minute to acquire tokens. We also describe a complementary mechanism for producers to ensure market clearance.

The first protocol we use is a form of a second-price auction. Importantly, we fairly distribute these profits to LPs according to their cumulative participation in the protocol before retrieval time trt_{r}. Informally, if an LP \ell takes on more risk by participating in a large number of trades with a large share of liquidity, then, in addition to receiving more fees, the market clearing auction will prioritize clearing \ell’s remaining tokens (YY) for cash (XX) at a higher price than other, more risk-averse, LPs.

A consumer order, or bid bb has two attributes:

  • 𝚊𝚍𝚍𝚛𝚎𝚜𝚜(b)\mathtt{address}(b): if a party uu submits the order bb, we set 𝚊𝚍𝚍𝚛𝚎𝚜𝚜(b)=u\mathtt{address}(b)=u.

  • 𝚙𝚛𝚒𝚌𝚎(b)\mathtt{price}(b): the party 𝚊𝚍𝚍𝚛𝚎𝚜𝚜(b)\mathtt{address}(b) sets a price 𝚙𝚛𝚒𝚌𝚎(b)>0\mathtt{price}(b)>0 that they are willing to pay for one unit of the token.

When a bid is submitted, it is not locked; any user can remove any of their bids if desired, at any time. For ease of exposition, each bid is for a single unit of YY. A user who wishes to buy multiple units of YY simply submits multiple bids.

The AMM maintains a dynamic list \mathcal{B} that keeps track of all existing bids at any given time. The list \mathcal{B} is called the consumer order book. Initially \mathcal{B} is empty, and every time a bid bb is submitted, bb is added to \mathcal{B}, so that \mathcal{B} is monotone decreasing by the price of each bid (highest price to lowest price). This implies that [0]\mathcal{B}[0] is a bid with maximum price. If the AMM price pYp_{Y} for a single unit of YY falls to below 𝚙𝚛𝚒𝚌𝚎(b)\mathtt{price}(b) for the bid b=[0]b=\mathcal{B}[0], then bb is removed from \mathcal{B} and one unit of YY is immediately sold to 𝚊𝚍𝚍𝚛𝚎𝚜𝚜(b)\mathtt{address}(b) via a trade at the price pY𝚙𝚛𝚒𝚌𝚎(b)p_{Y}\leq\mathtt{price}(b), so that the profits and fees of the trade are distributed to the active liquidity providers (LL) in proportion to their shares as usual.

We next describe the market clearing algorithm 𝚌𝚕𝚎𝚊𝚛𝚒𝚗𝚐()\mathtt{clearing}(). From the perspective of a buyer, 𝚌𝚕𝚎𝚊𝚛𝚒𝚗𝚐()\mathtt{clearing}() is purely a second-price auction. However, the distribution of profits to the LPs is more intricate. Each LP LL\ell\in L\cup L^{\prime} is assigned some variable rr_{\ell} that informally keeps track of the cumulative risk \ell has faced.444rr_{\ell} is initialized to 0 when \ell joins the set of LPs. When a trade (buying or selling) that exchanges xx^{\prime} of XX and some amount of YY, we do the following:

  • For each L\ell\in L, compute xsxx_{\ell}\leftarrow s_{\ell}x^{\prime} and increment rr+xr_{\ell}\leftarrow r_{\ell}+x_{\ell}.555Fees are also distributed in proportion to this xx_{\ell}.

Now consider the state of the AMM at the retrieval time trt_{r}. We execute the following market clearing algorithm 𝚌𝚕𝚎𝚊𝚛𝚒𝚗𝚐()\mathtt{clearing}() at this time.

1 for L\ell\in L do
2       𝙶𝚕𝚘𝚋𝚊𝚕:xsx\mathtt{Global}:x_{\ell}\leftarrow s_{\ell}x
3       𝙶𝚕𝚘𝚋𝚊𝚕:ysy\mathtt{Global}:y_{\ell}\leftarrow s_{\ell}y
4for L\ell\in L^{\prime} do
5       𝙶𝚕𝚘𝚋𝚊𝚕:(x,y)𝚏𝚛()\mathtt{Global}:(x_{\ell},y_{\ell})\leftarrow\mathtt{fr}(\ell)
6for LL\ell\in L\cup L^{\prime} do
7       𝙶𝚕𝚘𝚋𝚊𝚕:s¯rkLLrk\mathtt{Global}:\overline{s_{\ell}}\leftarrow\frac{r_{\ell}}{\sum_{k\in L\cup L^{\prime}}r_{k}}
8
9𝙶𝚕𝚘𝚋𝚊𝚕:L𝚊𝚟𝚊𝚒𝚕𝚊𝚋𝚕𝚎LL\mathtt{Global}:L_{\mathtt{available}}\leftarrow L\cup L^{\prime}
10while ||1|\mathcal{B}|\geq 1 and LLy1\sum_{\ell\in L\cup L^{\prime}}y_{\ell}\geq 1 do
11       b[0]b\leftarrow\mathcal{B}[0]
12      𝚍𝚎𝚕𝚎𝚝𝚎\mathtt{delete} [0]\mathcal{B}[0]
13      p𝚙𝚛𝚒𝚌𝚎([0])p\leftarrow\mathtt{price}(\mathcal{B}[0]) /* Second price */
14      𝚎𝚡𝚎𝚌𝚞𝚝𝚎(b,p)\mathtt{execute}(b,p)
15for LL\ell\in L\cup L^{\prime} do
16       𝚝𝚛𝚊𝚗𝚜𝚏𝚎𝚛𝙾𝚞𝚝(x,X,𝚍𝚎𝚜𝚝𝚒𝚗𝚊𝚝𝚒𝚘𝚗=)\mathtt{transferOut}(x_{\ell},X,\mathtt{destination}=\ell)
17      𝚝𝚛𝚊𝚗𝚜𝚏𝚎𝚛𝙾𝚞𝚝(y,Y,𝚍𝚎𝚜𝚝𝚒𝚗𝚊𝚝𝚒𝚘𝚗=)\mathtt{transferOut}(y_{\ell},Y,\mathtt{destination}=\ell)
Algorithm 7 𝚌𝚕𝚎𝚊𝚛𝚒𝚗𝚐()\mathtt{clearing()}
1 y𝚝𝚘𝚝𝚊𝚕0y_{\mathtt{total}}\leftarrow 0
2while y𝚝𝚘𝚝𝚊𝚕<1y_{\mathtt{total}}<1 do
3       L𝚝𝚘𝚁𝚎𝚖𝚘𝚟𝚎L_{\mathtt{toRemove}}\leftarrow\emptyset
4      for L𝚊𝚟𝚊𝚒𝚕𝚊𝚋𝚕𝚎\ell\in L_{\mathtt{available}} do
5             if y<s¯(1y𝚝𝚘𝚝𝚊𝚕)y_{\ell}<\overline{s_{\ell}}(1-y_{\mathtt{total}}) then
6                   y𝚝𝚘𝚝𝚊𝚕y𝚝𝚘𝚝𝚊𝚕+yy_{\mathtt{total}}\leftarrow y_{\mathtt{total}}+y_{\ell}
7                  y0y_{\ell}\leftarrow 0
8                  xx+pyx_{\ell}\leftarrow x_{\ell}+p\cdot y_{\ell}
9                  L𝚝𝚘𝚁𝚎𝚖𝚘𝚟𝚎L𝚝𝚘𝚁𝚎𝚖𝚘𝚟𝚎{}L_{\mathtt{toRemove}}\leftarrow L_{\mathtt{toRemove}}\cup\{\ell\}
10                  for kL𝚊𝚟𝚊𝚒𝚕𝚊𝚋𝚕𝚎L𝚝𝚘𝚁𝚎𝚖𝚘𝚟𝚎k\in L_{\mathtt{available}}\setminus L_{\mathtt{toRemove}} do
11                         sk¯sk¯1s¯\overline{s_{k}}\leftarrow\frac{\overline{s_{k}}}{1-\overline{s_{\ell}}}
12                  
13            else
14                   y𝚝𝚘𝚝𝚊𝚕y𝚝𝚘𝚝𝚊𝚕+s¯(1y𝚝𝚘𝚝𝚊𝚕)y_{\mathtt{total}}\leftarrow y_{\mathtt{total}}+\overline{s_{\ell}}(1-y_{\mathtt{total}})
15                  yys¯(1y𝚝𝚘𝚝𝚊𝚕)y_{\ell}\leftarrow y_{\ell}-\overline{s_{\ell}}(1-y_{\mathtt{total}})
16                  xx+ps¯(1y𝚝𝚘𝚝𝚊𝚕)x_{\ell}\leftarrow x_{\ell}+p\cdot\overline{s_{\ell}}(1-y_{\mathtt{total}})
17            
18      L𝚊𝚟𝚊𝚒𝚕𝚊𝚋𝚕𝚎L𝚊𝚟𝚊𝚒𝚕𝚊𝚋𝚕𝚎L𝚝𝚘𝚁𝚎𝚖𝚘𝚟𝚎L_{\mathtt{available}}\leftarrow L_{\mathtt{available}}\setminus L_{\mathtt{toRemove}}
19𝚝𝚛𝚊𝚗𝚜𝚏𝚎𝚛𝙾𝚞𝚝(1,Y,𝚍𝚎𝚜𝚝𝚒𝚗𝚊𝚝𝚒𝚘𝚗=𝚊𝚍𝚍𝚛𝚎𝚜𝚜(b))\mathtt{transferOut}(1,Y,\mathtt{destination}=\mathtt{address}(b))
20𝚝𝚛𝚊𝚗𝚜𝚏𝚎𝚛𝙸𝚗(p,X,𝚜𝚘𝚞𝚛𝚌𝚎=𝚊𝚍𝚍𝚛𝚎𝚜𝚜(b))\mathtt{transferIn}(p,X,\mathtt{source}=\mathtt{address}(b))
Algorithm 8 𝚎𝚡𝚎𝚌𝚞𝚝𝚎(b,p)\mathtt{execute}(b,p)

Essentially, we execute the bid bb with highest price for the second-highest price in \mathcal{B}, and the profits and fees from this trade are distributed so that the liquidity providers \ell get priority proportional to their cumulative risk variable rr_{\ell}. If all LPs LL\ell\in L\cup L^{\prime} have sufficiently many tokens, in particular, ys¯y_{\ell}\geq\overline{s_{\ell}}, then the profits to \ell are distributed in exact proportion to rr_{\ell}. Otherwise, we keep running a similar process until the system can “complete” a unit of YY, keeping profits to LPs in proportion to rr_{\ell}. This provides an incentive for liquidity providers to keep the system live: to not leave the AMM early, and to keep providing ample liquidity until the retrieval time.

In addition to maintaining the consumer order book, the AMM keeps track of a producer order book 𝒫\mathcal{P}, so that any party that has a unit of YY can escrow it into the system, and sell it for some minimum price that they set. In particular, a producer order ss has two attributes:

  • 𝚊𝚍𝚍𝚛𝚎𝚜𝚜(s)\mathtt{address}(s): if a party uu submits the selling order ss, we set 𝚊𝚍𝚍𝚛𝚎𝚜𝚜(s)=u\mathtt{address}(s)=u.

  • 𝚙𝚛𝚒𝚌𝚎(s)\mathtt{price}(s): the party 𝚊𝚍𝚍𝚛𝚎𝚜𝚜(s)\mathtt{address}(s) sets a price 𝚙𝚛𝚒𝚌𝚎(s)>0\mathtt{price}(s)>0 for which they are willing to sell one unit of the token.

The producer order book 𝒫\mathcal{P} is a list, initialized to \emptyset, that is always sorted from least to greatest (the reverse of \mathcal{B}) by the price of selling orders. At any time, a user can submit a producer order ss by escrowing one unit of YY into the AMM and setting a minimum selling price 𝚙𝚛𝚒𝚌𝚎(s)\mathtt{price}(s) for that producer order. If the AMM price qYq_{Y} to sell one unit of YY ever rises so that s=𝒫[0]s=\mathcal{P}[0], the producer order with the lowest price, has a price 𝚙𝚛𝚒𝚌𝚎(s)qY\mathtt{price}(s)\leq q_{Y}, then ss is removed from 𝒫\mathcal{P} and one unit of YY is immediately sold to the AMM from 𝚊𝚍𝚍𝚛𝚎𝚜𝚜(s)\mathtt{address}(s) via a regular AMM trade at the price qYq_{Y}.

We also impose a standard kind of interaction between \mathcal{B} and 𝒫\mathcal{P} that functions identically to a limit order book. Any time a new consumer or producer order is submitted to the AMM, we run the following algorithm. While ||>0|\mathcal{B}|>0 and |𝒫|>0|\mathcal{P}|>0 and 𝚙𝚛𝚒𝚌𝚎([0])𝚙𝚛𝚒𝚌𝚎(𝒫[0])\mathtt{price}(\mathcal{B}[0])\geq\mathtt{price}(\mathcal{P}[0]), then do b[0]b\leftarrow\mathcal{B}[0], s𝒫[0]s\leftarrow\mathcal{P}[0]; do

𝚝𝚛𝚊𝚗𝚜𝚏𝚎𝚛𝙾𝚞𝚝(1,Y,𝚍𝚎𝚜𝚝𝚒𝚗𝚊𝚝𝚒𝚘𝚗=𝚊𝚍𝚍𝚛𝚎𝚜𝚜(b));\displaystyle\mathtt{transferOut}(1,Y,\mathtt{destination}=\mathtt{address}(b));
𝚝𝚛𝚊𝚗𝚜𝚏𝚎𝚛𝙾𝚞𝚝(𝚙𝚛𝚒𝚌𝚎(b),X,𝚍𝚎𝚜𝚝𝚒𝚗𝚊𝚝𝚒𝚘𝚗=𝚊𝚍𝚍𝚛𝚎𝚜𝚜(s));\displaystyle\mathtt{transferOut}(\mathtt{price}(b),X,\mathtt{destination}=\mathtt{address}(s));

finally, remove bb from \mathcal{B} and remove ss from 𝒫\mathcal{P}. No state variables are updated, since the funds for the orders are initially escrowed from the addresses of the orders.

This order-book style protocol is only used in extreme market conditions: (i) all but one unit of YY remains in the liquidity pool, so that no consumer can make a trade with the AMM state curve; or (ii) all liquidity providers have been frozen, so that, again, no more trades can happen. In these two scenarios, the consumers and producers must submit consumer orders and producer orders, so that the interaction between the consumer order book and producer order book allows the market to remain live until the retrieval time trt_{r}.

8 Liveness and Market Clearance

Two of the most important properties that a DEX can satisfy are liveness and market clearance. The liveness property in our context states that at any time before the retrieval time trt_{r}, (a) there are always actions that parties can take (via the DEX) to execute a trade (trades are always possible), and (b) if the time is less than maxT\max T, then all liquidity providers \ell can take some action so that L\ell\in L after the next time in TT (liquidity providers are not permanently locked).

In addition to liveness, market clearance is a desirable property of a DEX, and mirrors the safety condition usually desired in a distributed system. In this context, market clearance means that (a) liquidity providers are always in a stable state (in the context of Proposition 6.4), (b) no two parties that are willing to trade do not end up trading by retrieval time, and (c) if the DEX contains any tokens left in the system after executing the clearing protocol 𝚌𝚕𝚎𝚊𝚛𝚒𝚗𝚐()\mathtt{clearing}(), then there is no remaining consumer. Just as safety in a distributed system requires that no correct processors ever have inconsistent views, market clearance in our AMM requires that there are no inconsistencies between the actions that parties wish to take and the transactions that actually happen in the DEX.

Now, we formally define and prove the liveness of our DEX model. Let 𝙳𝚢𝚗𝚊𝚖𝚒𝚌𝙰𝙼𝙼\mathtt{DynamicAMM} be the DEX described in this paper. We assume that there are three types of parties: buyers (consumers), sellers (producers), and liquidity providers.

Definition 8.1.

The DEX 𝙳𝚢𝚗𝚊𝚖𝚒𝚌𝙰𝙼𝙼\mathtt{DynamicAMM} is live if the following hold:

  • (Consumer Liveness) Consider any time t<trt<t_{r}, a buyer ubu_{b} at time tt, and a seller usu_{s} at time tt. Then there is a sequence of transactions that can submitted and executed by a nonempty subset of the parties {ub,us}\{u_{b},u_{s}\} where usu_{s} sells a YY token or ubu_{b} buys a YY token.

  • (LP Liveness) Given any liquidity provider \ell, a time t<maxTt<\max T, and the AMM state at time tt, there is a transaction that can be submitted by \ell so that L\ell\in L when the time is at least min{tT:t>t}\min\{t^{\prime}\in T:t^{\prime}>t\} and at most trt_{r}.

Theorem 8.1 (Liveness).

The DEX 𝙳𝚢𝚗𝚊𝚖𝚒𝚌𝙰𝙼𝙼\mathtt{DynamicAMM} is live.

Proof.

Consider any time t<trt<t_{r}, a buyer ubu_{b}, and a seller usu_{s}. Regardless of if a trade can be made using the AMM curve of 𝙳𝚢𝚗𝚊𝚖𝚒𝚌𝙰𝙼𝙼\mathtt{DynamicAMM} or not, ubu_{b} and usu_{s} can submit the following transactions. First, ubu_{b} submits a consumer order bb for a price qq; then usu_{s} submits a producer order ss for the same price qq. If either of these two orders can be executed using the AMM curve, then at least one of them will be, so that we are done. Otherwise, the interaction between \mathcal{B} and 𝒫\mathcal{P} described in Section 7, implies that at least one of the orders bb and ss will be executed, showing that the AMM satisfies Consumer Liveness. (This still holds even if some other order is submitted between when the orders bb and ss are submitted, or if some other orders are removed.)

Let \ell be a liquidity provider at time t<maxTt<\max T. Then \ell can simply request that d0d_{\ell}\leftarrow 0 at time tt. Then 𝙳𝚢𝚗𝚊𝚖𝚒𝚌𝙰𝙼𝙼\mathtt{DynamicAMM} will update d0d_{\ell}\leftarrow 0 at the time t=min{tT:t>t}t^{\prime}=\min\{t^{\prime}\in T:t^{\prime}>t\} and then immediately run 𝚏𝚛𝚎𝚎𝚣𝚎_𝚞𝚗𝚏𝚛𝚎𝚎𝚣𝚎()\mathtt{freeze\_unfreeze}(). By inspection, L\ell\in L after running 𝚞𝚗𝚏𝚛𝚎𝚎𝚣𝚎()\mathtt{unfreeze}(). Since p>0p>0 and d=0d_{\ell}=0 at time tt^{\prime}, we have pdp\geq d_{\ell}, so that L𝚏𝚛𝚎𝚎𝚣𝚎\ell\notin L_{\mathtt{freeze}} in the 𝚏𝚛𝚎𝚎𝚣𝚎()\mathtt{freeze}() algorithm; hence L\ell\in L after executing 𝚏𝚛𝚎𝚎𝚣𝚎_𝚞𝚗𝚏𝚛𝚎𝚎𝚣𝚎()\mathtt{freeze\_unfreeze}(). At any time in (t,tr)(t^{\prime},t_{r}), we will still have p>0p>0, so that L\ell\in L. Thus 𝙳𝚢𝚗𝚊𝚖𝚒𝚌𝙰𝙼𝙼\mathtt{DynamicAMM} also satisfies LP Liveness. ∎

Let us now formally define and prove market clearance in the context of our DEX. We assume that participants of each type are rational, as defined below:

  • Each liquidity provider \ell has a sequence of prices666\ell discovers this sequence as time progresses and is not known a priory. (qt)tT=(q()t)tT(q_{t})_{t\in T}=(q(\ell)_{t})_{t\in T} where they are willing to provide liquidity to 𝙳𝚢𝚗𝚊𝚖𝚒𝚌𝙰𝙼𝙼\mathtt{DynamicAMM} and engage in a trade as long as the current spot price is at least qtq_{t}, where tt is the greatest time in TT less than the current time. In this case, we assume that each LL\ell\in L\cup L^{\prime} has sets dqtd_{\ell}\leftarrow q_{t} at each time tTt\in T. Furthermore, if the current time tt is in (maxT,tr)(\max T,t_{r}), then every remaining liquidity provider is willing to sell the remaining tokens of YY for any price when the time is in (maxT,tr)(\max T,t_{r}); that is, qmaxT=0q_{\max T}=0.

  • For each buyer ubu_{b}, there is some fixed price q=q(ub)q=q(u_{b}) such that if the AMM price to buy one unit of YY falls to at most qq, then ubu_{b} will buy at the AMM price; if the producer order s=𝒫[0]s=\mathcal{P}[0] satisfies 𝚙𝚛𝚒𝚌𝚎(s)q\mathtt{price}(s)\leq q, then ubu_{b} will buy from the seller 𝚊𝚍𝚍𝚛𝚎𝚜𝚜(s)\mathtt{address}(s) for the price 𝚙𝚛𝚒𝚌𝚎(s)\mathtt{price}(s) (by issuing a consumer order for a price 𝚙𝚛𝚒𝚌𝚎(s)\mathtt{price}(s)); if both of these happen at the same time, ubu_{b} will buy the token YY at the lower price of the two available options. At some time t<trt<t_{r}, if ubu_{b} has not bought a YY token by time tt, they will register a bid for a price qq.

  • For each seller usu_{s}, there is some fixed price q=q(us)q=q(u_{s}) such that if the AMM price to sell one unit of YY rises to at least qq, then usu_{s} will sell at the AMM price; if the bid b=[0]b=\mathcal{B}[0] with 𝚙𝚛𝚒𝚌𝚎(b)q\mathtt{price}(b)\geq q, then usu_{s} will sell to the buyer 𝚊𝚍𝚍𝚛𝚎𝚜𝚜(b)\mathtt{address}(b) for the price 𝚙𝚛𝚒𝚌𝚎(b)\mathtt{price}(b); if both of these happen at the same time, usu_{s} sells the token YY at the higher price of the two available options. At some time t<trt<t_{r}, if usu_{s} has not sold a YY token by time tt, they will register a producer order for a price qq.

Definition 8.2.

We say that 𝙳𝚢𝚗𝚊𝚖𝚒𝚌𝙰𝙼𝙼\mathtt{DynamicAMM} satisfies market clearance if the following hold:

  • (LP Stability) At all times tt between the initialization of the AMM and retrieval time for which LL\neq\emptyset, a liquidity provider LL\ell\in L\cup L^{\prime} is active (in LL) if and only if q()t0pq(\ell)_{t_{0}}\geq p, where t0t_{0} is the greatest time in TT less than tt.

  • (Consumer Clearance) At time trt_{r}, there is no buyer ubu_{b} and seller usu_{s} where ubu_{b} is willing to buy at a price that is at least what usu_{s} is willing to sell for.

  • (System Clearance) At time trt_{r}, after 𝚌𝚕𝚎𝚊𝚛𝚒𝚗𝚐()\mathtt{clearing}() has executed, if 𝙳𝚢𝚗𝚊𝚖𝚒𝚌𝙰𝙼𝙼\mathtt{DynamicAMM} contains any of YY, then there is no remaining buyer.

Theorem 8.2.

The DEX 𝙳𝚢𝚗𝚊𝚖𝚒𝚌𝙰𝙼𝙼\mathtt{DynamicAMM} satisfies market clearance.

Proof.

Consider the state of 𝙳𝚢𝚗𝚊𝚖𝚒𝚌𝙰𝙼𝙼\mathtt{DynamicAMM} at an arbitrary time tt for which LL\neq\emptyset. Let t0=max{tT:t<t}t_{0}=\max\{t^{\prime}\in T:t^{\prime}<t\}. Let LL\ell\in L\cup L^{\prime}. Then by assumption, at time t0t_{0}, \ell must have set dq()t0d_{\ell}\leftarrow q(\ell)_{t_{0}}. Notice that the value of pp at time tt is the same as it was at the latest time t1<tt_{1}<t for which 𝚏𝚛𝚎𝚎𝚣𝚎_𝚞𝚗𝚏𝚛𝚎𝚎𝚣𝚎()\mathtt{freeze\_unfreeze}() was called, since 𝚏𝚛𝚎𝚎𝚣𝚎_𝚞𝚗𝚏𝚛𝚎𝚎𝚣𝚎()\mathtt{freeze\_unfreeze}() is called precisely when pp changes. Then Proposition 6.4 implies that at time t1t_{1}, we know L\ell\in L if and only if q()t0=dpq(\ell)_{t_{0}}=d_{\ell}\geq p at time t1t_{1}. Since pp is the same at time tt as it was at time t1t_{1}, we know that L\ell\in L if and only if q()t0pq(\ell)_{t_{0}}\geq p at time tt. Thus 𝙳𝚢𝚗𝚊𝚖𝚒𝚌𝙰𝙼𝙼\mathtt{DynamicAMM} satisfies LP Stability.

For the remainder of this proof, consider the state of 𝙳𝚢𝚗𝚊𝚖𝚒𝚌𝙰𝙼𝙼\mathtt{DynamicAMM} at time trt_{r}. Suppose there is a buyer ubu_{b} and a seller usu_{s} where q(ub)q(us)q(u_{b})\geq q(u_{s}). Since ubu_{b} and usu_{s} are unfulfilled at retrieval time, our hypothesises on buyers and sellers imply that there is a bid bb\in\mathcal{B} and producer order s𝒫s\in\mathcal{P} such that 𝚊𝚍𝚍𝚛𝚎𝚜𝚜(b)=ub,𝚊𝚍𝚍𝚛𝚎𝚜𝚜(s)=us,𝚙𝚛𝚒𝚌𝚎(b)=q(ub),𝚙𝚛𝚒𝚌𝚎(s)=q(us)\mathtt{address}(b)=u_{b},\mathtt{address}(s)=u_{s},\mathtt{price}(b)=q(u_{b}),\mathtt{price}(s)=q(u_{s}). If ss was submitted to 𝙳𝚢𝚗𝚊𝚖𝚒𝚌𝙰𝙼𝙼\mathtt{DynamicAMM} before bb, then the submission of bb (which was before trt_{r}) succeeds the check 𝚙𝚛𝚒𝚌𝚎(𝒫[0])>𝚙𝚛𝚒𝚌𝚎(b)\mathtt{price}(\mathcal{P}[0])>\mathtt{price}(b) (otherwise ubu_{b} would not be unfulfilled); because 𝒫\mathcal{P} is sorted in increasing order by price, 𝚙𝚛𝚒𝚌𝚎(s)𝚙𝚛𝚒𝚌𝚎(𝒫[0])>𝚙𝚛𝚒𝚌𝚎(b)\mathtt{price}(s)\geq\mathtt{price}(\mathcal{P}[0])>\mathtt{price}(b), so that q(us)>q(ub)q(u_{s})>q(u_{b}), a contradiction. The case when bb was submitted before ss gives a similar contradiction. Hence 𝙳𝚢𝚗𝚊𝚖𝚒𝚌𝙰𝙼𝙼\mathtt{DynamicAMM} satisfies Consumer Clearance.

Finally, suppose that 𝙳𝚢𝚗𝚊𝚖𝚒𝚌𝙰𝙼𝙼\mathtt{DynamicAMM} contains at least one unit of YY after 𝚌𝚕𝚎𝚊𝚛𝚒𝚗𝚐()\mathtt{clearing}() executed, and that there is some unfulfilled buyer ubu_{b}. Clearly 𝚌𝚕𝚎𝚊𝚛𝚒𝚗𝚐()\mathtt{clearing}() does eventually terminate, and LLy>0\sum_{\ell\in L\cup L^{\prime}}y_{\ell}>0 when 𝚌𝚕𝚎𝚊𝚛𝚒𝚗𝚐()\mathtt{clearing}() terminates. The termination criteria for 𝚌𝚕𝚎𝚊𝚛𝚒𝚗𝚐()\mathtt{clearing}() imply that =\mathcal{B}=\emptyset after 𝚌𝚕𝚎𝚊𝚛𝚒𝚗𝚐()\mathtt{clearing}() terminates. By our initial assumptions, ubu_{b} must have submitted a consumer order for the price q(ub)q(u_{b}) before the time trt_{r}, so that before 𝚌𝚕𝚎𝚊𝚛𝚒𝚗𝚐()\mathtt{clearing}() was executed, there was some bb\in\mathcal{B} with 𝚊𝚍𝚍𝚛𝚎𝚜𝚜(b)=ub\mathtt{address}(b)=u_{b}. We assumed that ubu_{b} is a remaining buyer after 𝚌𝚕𝚎𝚊𝚛𝚒𝚗𝚐()\mathtt{clearing}() was executed, which implies bb\in\mathcal{B} upon termination, a contradiction. Hence 𝙳𝚢𝚗𝚊𝚖𝚒𝚌𝙰𝙼𝙼\mathtt{DynamicAMM} satisfies System Clearance. ∎

9 Conclusion

This paper proposed novel DEX for trading assets that expire. This DEX includes both AMM and auction mechanisms: an AMM for normal execution, when expiration is far away, and auctions when expiration is imminent. To address market failures that may accompany expiration, the DEX include an LP-controlled price adjustment protocol, and a hybrid market clearing protocol that combines the benefits of AMMs and incentive-compatible auctions.

Allowing LPs to dynamically adjust prices requires admitting a larger family of state curves than the constant-product curves commonly used by popular AMMs [1, 13]. LPs can intervene to adjust spot prices, where an LP’s influence is proportional to its investment.

As expiration approaches, prices may become highly volatile. To discourage LPs from withdrawing their investments, the DEX allows nervous LPs to freeze their assets if spot prices fall below a specified minimum, and unfreeze if it later rises above that minimum.

The DEX includes a market clearing mechanism that functions in two ways. First, it can function as a limit order book before the expiration date to ensure market-liveness when all the liquidity providers are frozen, or when no more tokens can be bought from the system at a certain time. Second, it acts like a second-price auction to sell the remaining tokens in the system to unfulfilled customers. One key difference between our market clearing protocol and a standard second price auction is the way profits are distributed to liquidity providers: We distribute profits in proportion to the total participation of the liquidity providers, measured in the sum of the absolute change of the LP’s cash over all trades.

We prove a number of properties which show our DEX construction is sound. First, we prove some soundness properties of our price and curve adjustment protocol – such as monotonicity of instantaneous price as a function of cc and price-invariance under dynamic liquidity. Second, we prove a bound on the profit obtained by liquidity providers when given the option of calling two different, intricately connected methods of removal; this shows that it is always best to liquidate and share the losses with everyone else who wishes to liquidate, instead of attempting to act selfishly. Finally, we prove that our system is live – which roughly means that it cannot be permanently frozen until retrieval time – and it clears the market – there are no two remaining parties who would have been willing to make a trade but did not meet through the system.

References

  • [1] Hayden Adams, Noah Zinsmeister, and Dan Robinson. Uniswap v2 core. https://uniswap.org/whitepaper.pdf, March 2020. As of 8 February 2021.
  • [2] Guillermo Angeris and Tarun Chitra. Improved Price Oracles: Constant Function Market Makers. SSRN Electronic Journal, 2020.
  • [3] Guillermo Angeris, Alex Evans, and Tarun Chitra. When does the tail wag the dog? Curvature and market making. arXiv:2012.08040 [q-fin], December 2020. arXiv: 2012.08040.
  • [4] Guillermo Angeris, Hsien-Tang Kao, Rei Chiang, Charlie Noyes, and Tarun Chitra. An analysis of Uniswap markets. arXiv:1911.03380 [cs, math, q-fin], February 2021. arXiv: 1911.03380.
  • [5] Jun Aoyagi. Lazy Liquidity in Automated Market Making. SSRN Electronic Journal, 2020.
  • [6] Bancor. Proposing bancor v2.1: Single-sided amm with elastic bnt supply. https://blog.bancor.network/proposing-bancor-v2-1-single-sided-amm-with-elastic-bnt-supply-bcac9fe655b, October 2020. As of 8 February 2021.
  • [7] Massimo Bartoletti, James Hsin-yu Chiang, and Alberto Lluch-Lafuente. A theory of Automated Market Makers in DeFi. arXiv:2102.11350 [cs], April 2021. arXiv: 2102.11350.
  • [8] Maxim Bichuch and Zachary Feinstein. Axioms for automated market makers: A mathematical framework in fintech and decentralized finance, 2023.
  • [9] Agostino Capponi and Ruizhe Jia. The adoption of blockchain-based decentralized exchanges. arXiv preprint arXiv:2103.08842, 2021.
  • [10] Zdravko Cvetkovski. Inequalities: theorems, techniques and selected problems. Springer Science & Business Media, 2012.
  • [11] Michael Egorov. Stableswap - efficient mechanism for stablecoin liquidity. https://www.curve.fi/stableswap-paper.pdf, November 2019. As of 8 Februaary 2021.
  • [12] Daniel Engel and Maurice Herlihy. Composing Networks of Automated Market Makers. ArXiv, June 2021. arXiv: 2106.00083.
  • [13] Hayden Adams, Noah Zinsmeister, Moody Salem, River Keefer, and Dan Robinson. Uniswap v3 Core, March 2021.
  • [14] Eyal Hertzog, Guy Benartzi, and Galia Benartzi. Bancor protocol, 2017.
  • [15] Fernando Martinelli and Nikolai Mushegian. Balancer: A non-custodial portfolio man- ager, liquidity provider, and price sensor. https://balancer.finance/whitepaper/, 2109. As of 2 February 2021.
  • [16] Jason Milionis, Ciamac C. Moallemi, Tim Roughgarden, and Anthony Lee Zhang. Automated Market Making and Loss-Versus-Rebalancing, September 2022. arXiv:2208.06046 [math, q-fin].
  • [17] Geoffrey Ramseyer, Mohak Goyal, Ashish Goel, and David Mazières. Augmenting batch exchanges with constant function market makers, 2023.
  • [18] Jiahua Xu, Krzysztof Paruch, Simon Cousaert, and Yebo Feng. Sok: Decentralized exchanges (dex) with automated market maker (amm) protocols. ACM Computing Surveys, 55(11):1–50, 2023.
  • [19] Yi Zhang, Xiaohong Chen, and Daejun Park. Formal specification of constant product (x . y = k) market maker model and implementation. https://github.com/runtimeverification/verified-smart-contracts/blob/uniswap/uniswap/x-y-k.pdf, 2018.

Appendix A Aggregation Mechanics

Here, we will show that the weighted geometric mean aggregation algorithm described by equation 1 is the unique valid aggregation algorithm. To this end, fix an arbitrary finite nonempty set of LPs LL, and let

𝚊𝚐𝚐𝚛𝚎𝚐𝚊𝚝𝚎𝟶((c)L,(s)L)=Lcs.\mathtt{aggregate_{0}}((c_{\ell})_{\ell\in L},(s_{\ell})_{\ell\in L})=\prod_{\ell\in L}c_{\ell}^{s_{\ell}}.

Recall the definition of a valid aggregation algorithm, which we rewrite here for convenience.

Definition A.1.

Let 𝚊𝚐𝚐𝚛𝚎𝚐𝚊𝚝𝚎()\mathtt{aggregate}() be an aggregation algorithm; let LL be the particular set of active LPs at some time, and consider the corresponding aggregation function. We say that 𝚊𝚐𝚐𝚛𝚎𝚐𝚊𝚝𝚎()\mathtt{aggregate}() is valid if the following axioms hold.

  1. 1.

    For each L\ell\in L, 𝚊𝚐𝚐𝚛𝚎𝚐𝚊𝚝𝚎\mathtt{aggregate} has continuous partial derivatives with respect to cc_{\ell}. Additionally,

    (𝚊𝚐𝚐𝚛𝚎𝚐𝚊𝚝𝚎)log(c)=s𝚊𝚐𝚐𝚛𝚎𝚐𝚊𝚝𝚎((c)L,(s)L).\frac{\partial(\mathtt{aggregate})}{\partial\log(c_{\ell})}=s_{\ell}\cdot\mathtt{aggregate}((c_{\ell})_{\ell\in L},(s_{\ell})_{\ell\in L}).
  2. 2.

    If there exists some xx such that c=xc_{\ell}=x for all L\ell\in L, then

    𝚊𝚐𝚐𝚛𝚎𝚐𝚊𝚝𝚎((c)L,(s)L)=x.\mathtt{aggregate}((c_{\ell})_{\ell\in L},(s_{\ell})_{\ell\in L})=x.
Proposition A.1.

𝚊𝚐𝚐𝚛𝚎𝚐𝚊𝚝𝚎𝟶()\mathtt{aggregate_{0}}() defines a valid aggregation algorithm.

Proof.

Fix some L\ell\in L. We write c=𝚊𝚐𝚐𝚛𝚎𝚐𝚊𝚝𝚎𝟶((ck)kL,(sk)kL)c=\mathtt{aggregate_{0}}((c_{k})_{k\in L},(s_{k})_{k\in L}). Observe that

(𝚊𝚐𝚐𝚛𝚎𝚐𝚊𝚝𝚎𝟶)logc\displaystyle\frac{\partial(\mathtt{aggregate_{0}})}{\partial\log c_{\ell}} =(𝚊𝚐𝚐𝚛𝚎𝚐𝚊𝚝𝚎𝟶)clogcc\displaystyle=\frac{\frac{\partial(\mathtt{aggregate_{0}})}{\partial c_{\ell}}}{\frac{\partial\log c_{\ell}}{\partial c_{\ell}}}
=ckLcksk1c\displaystyle=\frac{\frac{\partial}{\partial c_{\ell}}\prod_{k\in L}c_{k}^{s_{k}}}{\frac{1}{c_{\ell}}}
=cscs1kL{}cksk\displaystyle=c_{\ell}s_{\ell}\cdot c_{\ell}^{s_{\ell}-1}\cdot\prod_{k\in L\setminus\{\ell\}}c_{k}^{s_{k}}
=skLcksk=sc.\displaystyle=s_{\ell}\prod_{k\in L}c_{k}^{s_{k}}=s_{\ell}c.

This shows condition 1 of Definition A.1. Finally, consider any ((ck)kL,(sk)kL)((c_{k})_{k\in L},(s_{k})_{k\in L}) in the domain of 𝚊𝚐𝚐𝚛𝚎𝚐𝚊𝚝𝚎𝟶\mathtt{aggregate_{0}} such that there exists some xx such that c=xc_{\ell}=x for all L\ell\in L. Since kLsk=1\sum_{k\in L}s_{k}=1,

c=kLcksk=kLxsk=x,c=\prod_{k\in L}c_{k}^{s_{k}}=\prod_{k\in L}x^{s_{k}}=x,

as desired. ∎

Now we prove the uniqueness of 𝚊𝚐𝚐𝚛𝚎𝚐𝚊𝚝𝚎𝟶()\mathtt{aggregate_{0}}().

Proposition A.2.

𝚊𝚐𝚐𝚛𝚎𝚐𝚊𝚝𝚎𝟶()\mathtt{aggregate_{0}}() is the only valid aggregation algorithm.

Proof.

Let 𝚊𝚐𝚐𝚛𝚎𝚐𝚊𝚝𝚎()\mathtt{aggregate}() be any valid aggregation algorithm. It suffices to show that 𝚊𝚐𝚐𝚛𝚎𝚐𝚊𝚝𝚎=𝚊𝚐𝚐𝚛𝚎𝚐𝚊𝚝𝚎𝟶\mathtt{aggregate}=\mathtt{aggregate_{0}} as functions, for all nonempty finite sets LL. To this end, let LL be finite and nonempty. Consider the function of the algorithm 𝚊𝚐𝚐𝚛𝚎𝚐𝚊𝚝𝚎()\mathtt{aggregate}() on LP set LL, which we call cc for brevity. Fix (s)L[0,1]L(s_{\ell})_{\ell\in L}\in[0,1]^{L} such that Ls=1\sum_{\ell\in L}s_{\ell}=1. Since 𝚊𝚐𝚐𝚛𝚎𝚐𝚊𝚝𝚎\mathtt{aggregate} is valid, for all L\ell\in L,

clog(c)=sc.\frac{\partial c}{\partial\log(c_{\ell})}=s_{\ell}\cdot c.

By the chain rule,

clogc\displaystyle\frac{\partial c}{\partial\log c_{\ell}} =clogclogcc\displaystyle=\frac{\frac{\partial c}{\partial\log c_{\ell}}}{\frac{\partial\log c_{\ell}}{\partial c_{\ell}}}
=ccc.\displaystyle=c_{\ell}\cdot\frac{\partial c}{\partial c_{\ell}}.

Thus

cc\displaystyle\frac{\partial c}{\partial c_{\ell}} =scc\displaystyle=\frac{s_{\ell}}{c_{\ell}}\cdot c
dcc\displaystyle\implies\int\frac{dc}{c} =sdcc\displaystyle=\int s_{\ell}\cdot\frac{dc_{\ell}}{c_{\ell}}
log(c)\displaystyle\implies\log(c) =slog(c)+A((ck)kL{})\displaystyle=s_{\ell}\log(c_{\ell})+A((c_{k})_{k\in L\setminus\{\ell\}})
=log(cs)+A((ck)kL{})\displaystyle=\log(c_{\ell}^{s_{\ell}})+A((c_{k})_{k\in L\setminus\{\ell\}})
c\displaystyle\implies c =csB((ck)kL{})\displaystyle=c_{\ell}^{s_{\ell}}\cdot B((c_{k})_{k\in L\setminus\{\ell\}})

for some functions A((ck)kL{})A((c_{k})_{k\in L\setminus\{\ell\}}) and B((ck)kL{})B((c_{k})_{k\in L\setminus\{\ell\}}) This implies that there exists a constant CC (possibly dependent on (s)L(s_{\ell})_{\ell\in L}) such that

c=CLcs.c=C\cdot\prod_{\ell\in L}c_{\ell}^{s_{\ell}}.

Since this holds for any (c)L(c_{\ell})_{\ell\in L}, we may choose (c)L(c_{\ell})_{\ell\in L} so that c=xc_{\ell}=x for all L\ell\in L, for a fixed x>0x>0. Using the second condition of Definition A.1, we know that

c((c)L,(s)L)=x.c((c_{\ell})_{\ell\in L},(s_{\ell})_{\ell\in L})=x.

This implies

x\displaystyle x =c((c)L,(s)L)\displaystyle=c((c_{\ell})_{\ell\in L},(s_{\ell})_{\ell\in L})
=CLcs\displaystyle=C\cdot\prod_{\ell\in L}c_{\ell}^{s_{\ell}}
=CLxs\displaystyle=C\cdot\prod_{\ell\in L}x^{s_{\ell}}
=Cx\displaystyle=C\cdot x

Since x>0x>0, it follows that C=1C=1. Thus, for any ((c)L,(s)L)((c_{\ell})_{\ell\in L},(s_{\ell})_{\ell\in L}) in the domain of cc, it follows that

c((c)L,(s)L)=Lcs,c((c_{\ell})_{\ell\in L},(s_{\ell})_{\ell\in L})=\prod_{\ell\in L}c_{\ell}^{s_{\ell}},

as desired. ∎

We conclude by proving some basic properties of 𝚊𝚐𝚐𝚛𝚎𝚐𝚊𝚝𝚎𝟶()\mathtt{aggregate_{0}}().

Proposition A.3.

Fix a finite nonempty set LL. Fix (s)L(s_{\ell})_{\ell\in L} satisfying Ls=1\sum_{\ell\in L}s_{\ell}=1. Then the corresponding function of 𝚊𝚐𝚐𝚛𝚎𝚐𝚊𝚝𝚎𝟶()\mathtt{aggregate_{0}}(), simply denoted 𝚊𝚐𝚐𝚛𝚎𝚐𝚊𝚝𝚎𝟶\mathtt{aggregate_{0}}, satisfies the following.

  • (Continuity.) 𝚊𝚐𝚐𝚛𝚎𝚐𝚊𝚝𝚎𝟶\mathtt{aggregate_{0}} is continuous in each coordinate.

  • (Increasing.) 𝚊𝚐𝚐𝚛𝚎𝚐𝚊𝚝𝚎𝟶\mathtt{aggregate_{0}} is weakly increasing in each cc_{\ell}, and strictly increasing in cc_{\ell} if s>0s_{\ell}>0.

  • (Convexity.) For all ((c)L,(s)L)((c_{\ell})_{\ell\in L},(s_{\ell})_{\ell\in L}) in the domain of 𝚊𝚐𝚐𝚛𝚎𝚐𝚊𝚝𝚎𝟶\mathtt{aggregate_{0}},

    𝚊𝚐𝚐𝚛𝚎𝚐𝚊𝚝𝚎𝟶((c)L,(s)L)conv{c:L}.\mathtt{aggregate_{0}}((c_{\ell})_{\ell\in L},(s_{\ell})_{\ell\in L})\in\operatorname{conv}\{c_{\ell}:\ell\in L\}.
  • (Boundary conditions.) If s=1s_{\ell}=1, then 𝚊𝚐𝚐𝚛𝚎𝚐𝚊𝚝𝚎𝟶((c)L,(s)L)=c\mathtt{aggregate_{0}}((c_{\ell})_{\ell\in L},(s_{\ell})_{\ell\in L})=c_{\ell}.

Proof.

The Continuity, Increasing, and Boundary conditions properties are obvious. For the Convexity property, let c=𝚊𝚐𝚐𝚛𝚎𝚐𝚊𝚝𝚎𝟶((c)L,(s)L)c=\mathtt{aggregate_{0}}((c_{\ell})_{\ell\in L},(s_{\ell})_{\ell\in L}). Let c𝚖𝚒𝚗=min{ck:kL}c_{\mathtt{min}}=\min\{c_{k}:k\in L\} and c𝚖𝚊𝚡=max{ck:kL}c_{\mathtt{max}}=\max\{c_{k}:k\in L\}. Since kLsk=1\sum_{k\in L}s_{k}=1, it follows that

c𝚖𝚒𝚗=kLc𝚖𝚒𝚗skkLckskkLc𝚖𝚊𝚡sk=c𝚖𝚊𝚡.c_{\mathtt{min}}=\prod_{k\in L}c_{\mathtt{min}}^{s_{k}}\leq\prod_{k\in L}c_{k}^{s_{k}}\leq\prod_{k\in L}c_{\mathtt{max}}^{s_{k}}=c_{\mathtt{max}}.

Since c=kLckskc=\prod_{k\in L}c_{k}^{s_{k}}, it follows that cconv{ck:kL}c\in\mathrm{conv}\{c_{k}:k\in L\}. ∎