Expiring Assets in Automated Market Makers
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 (informally called cash), and an expiring asset (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 , where (respectively ) is the amount of (respectively ) that the AMM offers for trading.
Any party can become a liquidity provider by lending assets to the AMM. In return, receives a share 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 . LPs can freeze their liquidity, in a manner comparable to Uniswap V3’s notion of concentrated liquidity [13]. An LP can set a minimum spot price for tokens in terms of 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 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 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 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 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 have the same share and hold the same number of tokens, if participates in many more (and larger) trades than , then will receive a greater share of the auction proceeds than . 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 and , we write provided for all , where ; if also , we write . When referencing topological properties in this paper, we assume that any subset of (for any ) is given the subspace topology, unless otherwise specified. We define . A function is twice-differentiable if all of its second partial derivatives exist and are continuous. We also say that is strictly increasing in each coordinate if for all such that , we have .
A set is convex if for all distinct and , we have ; if every such vector is in the interior of , we say is strictly convex. It follows that that any convex open set is strictly convex. Given a set , the convex hull of , denoted , is defined as the intersection of all nonempty convex sets that contain . Suppose is convex. A function is said to be strictly convex provided that for every distinct and , it follows that .
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: , when the tokens expire, and , when the AMM halts and the last-minute auctions occur. Let be the set of all epoch boundaries strictly before .
We say that a state curve is a strictly decreasing homeomorphism . If , we say that the pair is a state of , and we denote the set of all states of by . Operationally, we say that the AMM is in state if it contains units of and units of . Trades change the amounts and of and , respectively, so that is always in .
We consider only a fixed subfamily of possible state curves. Let be fixed positive lower and upper bounds. (We may wish to require that and for symmetry, though this is not required.) For every and possible state , define the state curve
for all . Then . Let be the current set of active liquidity providers (whose assets are allocated to trading), and is the set of inactive liquidity providers (whose assets are frozen). The sets and and their associated methods are formally defined in Section 6.
At each time in , each liquidity provider chooses some that informally represents the price believes is most economically efficient, with knowledge of the current state of the AMM. Each is aggregated into a single with some deterministic aggregation algorithm by computing at each epoch boundary. The algorithm has parameters and 222We exclude the ’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 . For fixed , since is deterministic, it can be viewed as a map
where is the set of all tuples indexed by with values in for any sets . Now we define the soundness properties for an aggregation algorithm.
Definition 5.1.
Let be an aggregation algorithm; let be the particular set of active LPs at some time, and consider the corresponding aggregation function. We say that is valid if the following axioms hold.
-
1.
For each , the function has continuous partial derivatives with respect to . Additionally,
-
2.
If there exists some such that for all , then
For brevity, let .
The first condition implies that for a small fixed change in from an LP with share , the corresponding change in is proportional to . We use a logarithmic scale since derivatives are limits of additive changes, and is an isomorphism from the group under multiplication to the group under addition. (Note that , 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 , the aggregated constant is the common value .
In our model, we define to return
(1) |
the geometric mean of each weighted by the share 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 stored in the AMM. Until the next time in in which liquidity providers may update their value of , we fix as defined above. Note that when the state changes from adding/removing liquidity, freezing/unfreezing liquidity, and liquidating (specified in Section 6), we update and , and we must also update the state curve in these cases. This is necessary because the liquidity state after completing any of these methods is no longer in the state space of the current state curve . We omit updates to 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 that satisfies the following:
-
•
is twice-differentiable;
-
•
is strictly increasing in each coordinate;
-
•
For each , the set is closed and strictly convex.
Under this definition, the state space of is the set and is denoted . 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 to denote an AMM and 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 , but a state curve is a function . An AMM captures more information than the set of states alone on a state curve alone. In particular, if is an AMM, then we may construct its state curve by mapping to the unique such that . 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 , we say that induces an AMM if there exists an AMM such that .
We will prove that for any and that induces an AMM. For the remainder of this section, fix and . To prove that induces an AMM, we let . We shall first prove that is an AMM. It is easy to see the following two lemmas, and the third one is simple.
Lemma 5.1.
is twice differentiable.
Proof.
Observe that and . Then and , which are both continuous. Since both second partial derivatives of exist and are continuous, is twice differentiable. ∎
Lemma 5.2.
is strictly increasing in each coordinate.
Proof.
If and , then since , . Similarly, if and , then , as desired. ∎
Lemma 5.3.
For any , the set is closed and strictly convex.
Proof.
Let and let . Since is continuous and is closed, is closed because the preimage of a closed set under a continuous function is closed. To prove that is strictly convex, it suffices to show that for any distinct and , it follows that . To this end, notice that since , we know and . Thus, by the Weighted AM-GM Inequality [10, p. 74],
This shows that is a strictly convex set, as desired. ∎
Finally, we must verify that and have the same state spaces.
Lemma 5.4.
.
Proof.
Observe that
Thus . ∎
As a consequence, we have the following.
Theorem 5.5.
The state curve induces an AMM.
Proof.
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 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 and changes in liquidity states. In particular, we have the following definitions.
Definition 5.4 (Price and Slippage).
Given a state curve and a particular state , the instantaneous price, or the spot price, at is defined by
Additionally, we define the instantaneous slippage by
Proposition 5.6.
Given a state , the instantaneous price and slippage are strictly decreasing in , for . That is, if , then
Proof.
Observe that for all ,
so that
Thus
Furthermore, for all ,
Therefore
∎
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 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 constant, the following proposition shows these results.
Proposition 5.7.
Let , and consider a state and some such that , where we fix . Then . Furthermore, if and only if .
Proof.
Observe that
for all . Because and , we have
We also have
so that for all . It follows that
since and . Hence if and only if . ∎
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 () drained upon a sudden decrease in demand for tokens (). 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 is the current liquidity state of the AMM, then any party may deposit of and of in a proportion that reflects the current price: .333In an initial state where or , there are no restrictions on how liquidity is added. Then the state is updated appropriately, we do and , and finally, . The depositing LP receives shares in the usual way, but in addition it is allowed to specify its contribution in the 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 () in terms of cash () below which its liquidity will not participate. Each liquidity provider sets a lower bound , updated at the beginning of each epoch (after and defined subsequently). A liquidity provider can alter its at any time, but no change will occur until the next epoch boundary.
For any initial state and current state of the AMM with aggregate constant , let denote the (instantaneous) spot price
as defined in Definition 5.4. This value is stored in the AMM and is updated appropriately. As soon as for some , the AMM moves ’s liquidity into a distinct, untraded liquidity pool. If, at a later time, , the AMM unfreezes ’s liquidity by moving it back into the trading state. To ensure no consumer or producer pushes to be much smaller than some , 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 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.
We showed in Proposition 5.7 that the price is invariant under adding and removing liquidity, so we update only on epoch boundaries and after every trade. The AMM maintains the set and a map 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 defined in Algorithm 2.
The function finds all active liquidity providers whose price tolerance is less than the current price, and moves their liquidity into a non-trading pool. If , finds the inactive liquidity providers whose price tolerance is at least , and moves as much of their inactive liquidity back into the trading pool as possible, subject to preserving the ratio of to in the liquidity pool. If, however, , the instantaneous price is not well-defined, so we retrieve the values of and from the last point in time where some liquidity provider was active, and unfreeze all the liquidity providers to have a liquidity ratio of . In both cases or , the method freezes or unfreezes liquidity providers as needed.
Finally, we define and . These methods are similar, but with one key difference. When is called by some , the AMM adds to a set initialized to ; at the next epoch boundary, the AMM simply sends the assets that each has the right to (computed in the obvious way, depending on if or ) back to , while doing the appropriate bookkeeping. As this is the only difference from usual practice (e.g., [1]), so pseudocode is omitted.
Like , when is called by an LP , then is added to a set . At each epoch boundary, the following is executed in an atomic step: for each liquidity provider in , get the amounts of and they have the right to, remove this liquidity, sell the total units of that have been traded for , and distribute these funds to each member of in proportion to their shares of asset ; then set . This protocol is listed as Algorithm 6. Both these methods run atomically at each epoch boundary, where is executed first.
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 a guaranteed risk-free liquidity removal; the received liquidity from the method is not affected by liquidity providers calling since the AMM’s execution of precedes that of .
We will prove a more formal version of the following claim: no rational liquidity provider will call and then sell their tokens back to the AMM in exchange for . In particular, this means that liquidity providers who wish to keep their tokens upon removal call the method, and liquidity providers who only want to remove liquidity with the maximum number of tokens possible ( is worthless to them) call the method. First, we prove the following lemmas.
Lemma 6.1.
Let and . If and satisfy and and , then
for all .
Proof.
Suppose and satisfy and and . Notice that
and similarly,
Since , we know
Fix some . Since , , and , we have
It follows that
Multiplying by yields that
∎
Lemma 6.2.
Suppose some party sells one unit of to the AMM for of , and then sells another unit of to the AMM for of . Then .
Proof.
Let be the state curve before the first trade. If and are the same after the first trade (so did not update any global variables), then since is a convex function, we certainly have .
Now suppose the execution of changed the sets and after the first trade. It suffices to prove that is at most the amount of one would get if the state curve never updated and was always equal to , given the observation above. To this end, we consider two possible cases for the second trade. Let be the state after the first trade but before calling ; let be the state after completing the first trade, so the state curve updates to . Observe that the updated set after the first trade is a subset of the initial because the instantaneous price can only decrease after the first selling trade. By inspection of and , we see that but and .
Let be the amount received for the second trade if the state curve is ; let be the amount received for the second trade if the state curve is . The convexity of implies that . If we can show , then we know because .
Finally, we prove , showing the lemma. We have
∎
Proposition 6.3.
Let . Suppose that in some execution , the liquidity provider calls to obtain of and of , and then trades of to the AMM in exchange for of , so that receives of . Suppose that in some otherwise identical execution , instead calls and receives of . Then .
Proof.
Consider the sets and in executions and , respectively. Consider the , which is the same in both executions. Notice that, by construction, the effective AMM state after executing the loop in line 14 of is the same in both executions and . Suppose that in execution , there is some other liquidity provider (not ) that removed liquidity and sold it to the system before . By Lemma 6.2, the received amount of is at most the amount would have received if was the first provider to sell their removed liquidity back to the AMM. Thus it suffices to prove the claim when was the first liquidity provider to sell their liquidity back to the AMM after was called in execution .
To this end, consider the sequence of received amounts of for consecutive single-unit trades made by and ’s atomic selling trades, in execution . Similarly, let be the sequence of received amounts of for consecutive single-unit trades made by , in execution . It is clear that , as defined in , so that we may extend both sequences by setting for By the assumption made above, these two sequences are equal: for all . Then we may let be this sequence. By Lemma 6.2, is a nonincreasing sequence. Thus
where and are defined in . Note that the in is equal to , so that
∎
We also show that the method yields a stable liquidity state; that is, a liquidity provider is active if and only if . Proving this is important for proving LP Stability in Theorem 8.2.
Proposition 6.4.
Consider the AMM state immediately after calling . Let . Then if and only if .
Proof.
Inspecting both and , the AMM state changes of the variables are indistinguishable from a sequence of adding and removing liquidity. By Lemma 5.7, the current instantaneous price is invariant throughout . If before executing , then this implies that after executing and , we can see that if and only if (as defined in ), which holds if and only if . On the other hand, if before executing , then by a similar reasoning, after executing the algorithm if and only . ∎
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 . Informally, if an LP 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 ’s remaining tokens () for cash () at a higher price than other, more risk-averse, LPs.
A consumer order, or bid has two attributes:
-
•
: if a party submits the order , we set .
-
•
: the party sets a price 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 . A user who wishes to buy multiple units of simply submits multiple bids.
The AMM maintains a dynamic list that keeps track of all existing bids at any given time. The list is called the consumer order book. Initially is empty, and every time a bid is submitted, is added to , so that is monotone decreasing by the price of each bid (highest price to lowest price). This implies that is a bid with maximum price. If the AMM price for a single unit of falls to below for the bid , then is removed from and one unit of is immediately sold to via a trade at the price , so that the profits and fees of the trade are distributed to the active liquidity providers () in proportion to their shares as usual.
We next describe the market clearing algorithm . From the perspective of a buyer, is purely a second-price auction. However, the distribution of profits to the LPs is more intricate. Each LP is assigned some variable that informally keeps track of the cumulative risk has faced.444 is initialized to when joins the set of LPs. When a trade (buying or selling) that exchanges of and some amount of , we do the following:
-
•
For each , compute and increment .555Fees are also distributed in proportion to this .
Now consider the state of the AMM at the retrieval time . We execute the following market clearing algorithm at this time.
Essentially, we execute the bid with highest price for the second-highest price in , and the profits and fees from this trade are distributed so that the liquidity providers get priority proportional to their cumulative risk variable . If all LPs have sufficiently many tokens, in particular, , then the profits to are distributed in exact proportion to . Otherwise, we keep running a similar process until the system can “complete” a unit of , keeping profits to LPs in proportion to . 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 , so that any party that has a unit of can escrow it into the system, and sell it for some minimum price that they set. In particular, a producer order has two attributes:
-
•
: if a party submits the selling order , we set .
-
•
: the party sets a price for which they are willing to sell one unit of the token.
The producer order book is a list, initialized to , that is always sorted from least to greatest (the reverse of ) by the price of selling orders. At any time, a user can submit a producer order by escrowing one unit of into the AMM and setting a minimum selling price for that producer order. If the AMM price to sell one unit of ever rises so that , the producer order with the lowest price, has a price , then is removed from and one unit of is immediately sold to the AMM from via a regular AMM trade at the price .
We also impose a standard kind of interaction between and 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 and and , then do , ; do
finally, remove from and remove from . 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 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 .
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 , (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 , then all liquidity providers can take some action so that after the next time in (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 , 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 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 is live if the following hold:
-
•
(Consumer Liveness) Consider any time , a buyer at time , and a seller at time . Then there is a sequence of transactions that can submitted and executed by a nonempty subset of the parties where sells a token or buys a token.
-
•
(LP Liveness) Given any liquidity provider , a time , and the AMM state at time , there is a transaction that can be submitted by so that when the time is at least and at most .
Theorem 8.1 (Liveness).
The DEX is live.
Proof.
Consider any time , a buyer , and a seller . Regardless of if a trade can be made using the AMM curve of or not, and can submit the following transactions. First, submits a consumer order for a price ; then submits a producer order for the same price . 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 and described in Section 7, implies that at least one of the orders and will be executed, showing that the AMM satisfies Consumer Liveness. (This still holds even if some other order is submitted between when the orders and are submitted, or if some other orders are removed.)
Let be a liquidity provider at time . Then can simply request that at time . Then will update at the time and then immediately run . By inspection, after running . Since and at time , we have , so that in the algorithm; hence after executing . At any time in , we will still have , so that . Thus 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 has a sequence of prices666 discovers this sequence as time progresses and is not known a priory. where they are willing to provide liquidity to and engage in a trade as long as the current spot price is at least , where is the greatest time in less than the current time. In this case, we assume that each has sets at each time . Furthermore, if the current time is in , then every remaining liquidity provider is willing to sell the remaining tokens of for any price when the time is in ; that is, .
-
•
For each buyer , there is some fixed price such that if the AMM price to buy one unit of falls to at most , then will buy at the AMM price; if the producer order satisfies , then will buy from the seller for the price (by issuing a consumer order for a price ); if both of these happen at the same time, will buy the token at the lower price of the two available options. At some time , if has not bought a token by time , they will register a bid for a price .
-
•
For each seller , there is some fixed price such that if the AMM price to sell one unit of rises to at least , then will sell at the AMM price; if the bid with , then will sell to the buyer for the price ; if both of these happen at the same time, sells the token at the higher price of the two available options. At some time , if has not sold a token by time , they will register a producer order for a price .
Definition 8.2.
We say that satisfies market clearance if the following hold:
-
•
(LP Stability) At all times between the initialization of the AMM and retrieval time for which , a liquidity provider is active (in ) if and only if , where is the greatest time in less than .
-
•
(Consumer Clearance) At time , there is no buyer and seller where is willing to buy at a price that is at least what is willing to sell for.
-
•
(System Clearance) At time , after has executed, if contains any of , then there is no remaining buyer.
Theorem 8.2.
The DEX satisfies market clearance.
Proof.
Consider the state of at an arbitrary time for which . Let . Let . Then by assumption, at time , must have set . Notice that the value of at time is the same as it was at the latest time for which was called, since is called precisely when changes. Then Proposition 6.4 implies that at time , we know if and only if at time . Since is the same at time as it was at time , we know that if and only if at time . Thus satisfies LP Stability.
For the remainder of this proof, consider the state of at time . Suppose there is a buyer and a seller where . Since and are unfulfilled at retrieval time, our hypothesises on buyers and sellers imply that there is a bid and producer order such that . If was submitted to before , then the submission of (which was before ) succeeds the check (otherwise would not be unfulfilled); because is sorted in increasing order by price, , so that , a contradiction. The case when was submitted before gives a similar contradiction. Hence satisfies Consumer Clearance.
Finally, suppose that contains at least one unit of after executed, and that there is some unfulfilled buyer . Clearly does eventually terminate, and when terminates. The termination criteria for imply that after terminates. By our initial assumptions, must have submitted a consumer order for the price before the time , so that before was executed, there was some with . We assumed that is a remaining buyer after was executed, which implies upon termination, a contradiction. Hence 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 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 , and let
Recall the definition of a valid aggregation algorithm, which we rewrite here for convenience.
Definition A.1.
Let be an aggregation algorithm; let be the particular set of active LPs at some time, and consider the corresponding aggregation function. We say that is valid if the following axioms hold.
-
1.
For each , has continuous partial derivatives with respect to . Additionally,
-
2.
If there exists some such that for all , then
Proposition A.1.
defines a valid aggregation algorithm.
Proof.
Fix some . We write . Observe that
This shows condition 1 of Definition A.1. Finally, consider any in the domain of such that there exists some such that for all . Since ,
as desired. ∎
Now we prove the uniqueness of .
Proposition A.2.
is the only valid aggregation algorithm.
Proof.
Let be any valid aggregation algorithm. It suffices to show that as functions, for all nonempty finite sets . To this end, let be finite and nonempty. Consider the function of the algorithm on LP set , which we call for brevity. Fix such that . Since is valid, for all ,
By the chain rule,
Thus
for some functions and This implies that there exists a constant (possibly dependent on ) such that
Since this holds for any , we may choose so that for all , for a fixed . Using the second condition of Definition A.1, we know that
This implies
Since , it follows that . Thus, for any in the domain of , it follows that
as desired. ∎
We conclude by proving some basic properties of .
Proposition A.3.
Fix a finite nonempty set . Fix satisfying . Then the corresponding function of , simply denoted , satisfies the following.
-
•
(Continuity.) is continuous in each coordinate.
-
•
(Increasing.) is weakly increasing in each , and strictly increasing in if .
-
•
(Convexity.) For all in the domain of ,
-
•
(Boundary conditions.) If , then .
Proof.
The Continuity, Increasing, and Boundary conditions properties are obvious. For the Convexity property, let . Let and . Since , it follows that
Since , it follows that . ∎