Dynamic Curves for Decentralized Autonomous Cryptocurrency Exchanges
DDynamic Curves for Decentralized AutonomousCryptocurrency Exchanges
Bhaskar Krishnamachari, Qi Feng, Eugenio GrippoDepartment of Electrical and Computer Engineering,Viterbi School of EngineeringUniversity of Southern California
Abstract —One of the exciting recent developments in decen-tralized finance (DeFi) has been the development of decentralizedcryptocurrency exchanges that can autonomously handle conver-sion between different cryptocurrencies. Decentralized exchangeprotocols such as Uniswap, Curve and other types of AutomatedMarket Makers (AMMs) maintain a liquidity pool (LP) of two ormore assets constrained to maintain at all times a mathematicalrelation to each other, defined by a given function or curve.Examples of such functions are the constant-sum and constant-product AMMs. Existing systems however suffer from severalchallenges. They require external arbitrageurs to restore theprice of tokens in the pool to match the market price. Suchactivities can potentially drain resources from the liquidity pool.In particular dramatic market price changes can result in lowliquidity with respect to one or more of the assets and reduce thetotal value of the LP. We propose in this work a new approachto constructing the AMM by proposing the idea of dynamiccurves . It utilizes input from a market price oracle to modifythe mathematical relationship between the assets so that the poolprice continuously and automatically adjusts to be identical to themarket price. This approach eliminates arbitrage opportunitiesand, as we show through simulations, maintains liquidity in theLP for all assets and the total value of the LP over a wide rangeof market prices.
I. I
NTRODUCTION
Since the introduction of Bitcoin as the first peer-to-peerdigital cash [1], the birth of different cryptocurrencies hasrevolutionized the world of finance [2]. As of the time ofwriting this article, it is estimated that the total cryptocurrencymarket capitalization is more than $600 Billion, involvingthousands of different coins [3].Traditionally, cryptocurrency exchanges, which use an orderbook mechanism, are centralized. They suffer from concernsabout the concentration of financial power [4] and beingprone to a single point of failure, resulting in a potentiallysignificant loss of funds when attacked [5]. Additionally, theyalso pose a liquidity problem for tokens with a smaller marketcapitalization resulting in barriers to entry to the financialmarket [4].On the other hand, it is difficult to implement the orderbook model in a decentralized manner in the form of ablockchain smart contract [6] [5]. First, market makers willface high gas costs to execute transactions, regardless of theirsizes [6]. Second, it will require a complex matching algorithmto support a variety of order types [5].Automated Market Makers such as Hanson’s logarithmicmarket scoring rules (LMSRs) are widely used in traditional prediction markets to address the problem of low liquidityand trading volume [7], [8]. An LMSR-based AMM is alsoused in decentralized prediction markets such as Gnosis [9]and Augur [10]. Given certain similar market characteristics,curve-based Automated Market Makers (AMM) were recentlyintroduced to address the challenges in a currency exchangecontext. They are currently one of the areas of decentralizedfinance receiving the most attention. Instead of relying on thetraditional market makers to provide liquidity, decentralizedexchanges utilizing curve-based AMMs, such as Bancor [4],Uniswap [11], StableSwap/Curve [12] and many others im-plement a liquidity pool (LP) using smart contracts on ablockchain. In this model, liquidity providers supply single ormultiple types of tokens to the designated liquidity pools, andtraders exchange against the pools of tokens instead of relyingon order matching. The liquidity pool of these AMMs tracka pre-defined mathematical function (curve), thus determininghow many tokens of one type to provide to a trader in exchangefor a certain amount of another. Curve-based AMMs providea continuous supply of liquidity compared to the order bookmodel. Additionally, depending on the mathematical function(curve) utilized, they can potentially allow for a wide range ofexchange prices. However, the token price within a liquiditypool for a given AMM (which we refer to as the pool price)might be different from the market price.When such a gap occurs on a decentralized AMM-basedexchange, arbitrageurs may have the opportunity to buy or selltokens to set the pool price equal to the market price, restoringequilibrium. However, in some cases, particularly when themarket price changes dramatically, the AMM-based LP couldlose liquidity with respect to one or more of the assets. Wepropose in this work a new approach to constructing the AMMby proposing the idea of dynamic curves . It utilizes input froma market price oracle to modify the mathematical relationshipbetween the assets so that the pool price continuously andautomatically adjusts to be identical to the market price. Thiseliminates arbitrage opportunities and, as we show throughsimulations, helps the AMM-based LP maintain liquidity andtotal value over a wide range of market prices.The following are the key contributions of this work: • We present a simple and unified mathematical and con-ceptual framework (in section III) describing existingcurve-based AMMs and key metrics such as pool price,slippage, divergence loss. It unifies much of what is a r X i v : . [ q -f i n . T R ] J a n nown about them today. We believe this section willbe of independent interest to researchers starting out inthis area. • We focus on the liquidity problem posed by arbitrageurson existing AMMs, especially when the market pricefor one of the assets becomes too high, causing assetdepletion and value reduction of the liquidity pool. • We present a new dynamic curve mechanism, which isgeneral enough to be adapted to any monotonic func-tion/curve used on an AMM. This mechanism relies on anexternal market price oracle and eliminates arbitrageurs.We illustrate the mechanism concretely through gen-eralizations of both constant-sum and constant-productmodels. • We present numerical simulations showing the clear ad-vantages of our proposed dynamic curve mechanism ina) retaining greater liquidity in the pool to benefit smalltraders, b) retaining greater total value in the liquiditypool, and c) functioning effectively over a much largerrange of market prices.The rest of this paper is organized as follows: we presentand discuss relevant prior work in section II. In section IIIwe give a unified treatment and definition of key conceptsand metrics relevant to decentralized AMMs. In section IVwe propose and describe our new dynamic AMM models. Insection V we present agent-based simulations and comparethe performance of four different AMMs, including two staticAMMs (Constant- Sum AMM, Constant-Product AMM) andtheir two dynamic generalizations that we introduce in thiswork. We present concluding comments in section VI.II. R
ELATED W ORK
Bancor was the first DEX to implement the type of AMMcalled Bonding Curve, which provides continuous liquidity[4]. In this type of AMM, there is a single token (BancorNetwork Token - BNT) used as an intermediate currency.There are separate pools for each non-native currency to betraded against BNT. This model is a little different from thearbitrary two-asset curve based AMM’s that we focus on inthis paper (though there are significant connections as well).In curve-based AMMs, any two currencies could be tradeddirectly against each other.Borrowing solutions from the prediction market, Bu-terin [13] first proposed such a curve-based AMM for adecentralized exchange. Specifically, he proposed the ConstantProduct Curve. It is a convex curve that takes the form of x · y = k , where x and y are the total supply of two tokensin a liquidity pool and k is the product constant. It wassubsequently implemented by Adams et al. [11] to createUniswap.With the shape of a downward-sloping straight line, theConstant Sum Curve [14][15] takes the form of x + y = k . x and y are the total supply of two tokens in a liquidity pool, and k is the sum constant. StableSwap/Curve [12] implemented anAMM curve that is a blend of Constant Sum and Constant Product to provide continuous liquidity, price stability and abuilt-in pool balancing mechanism.Wang [8] proposed the Constant Ellipse Curve AMM withthe general form of ( x − a ) +( y − a ) + b · xy = C , in which a and b are constant. One can choose between the concave andthe convex curve in the first quadrant [8]. Wang also presentsthe curve corresponding to the LMSR rule.Angeris and Chitra analyze such curve-based AMMs, whichthey refer to as constant function market makers in the generalcase, i.e., with arbitrarily many tokens [16]. They analyzevarious mathematical properties of such AMMs, includingformulating the optimal arbitrage by traders as a convexoptimization problem. A. Performance metrics for AMMs
Slippage and divergence loss are the two main factorscontributing to the proposal and adoption of different AMMs.The former is directly tied to the loss of traders, while thelatter is directly connected to the liquidity providers’ returns.Slippage is the difference between the expected and actualtrade execution price [17], and in the AMM context, it isdefined as the gap between the pool price before a trade andthe effective price obtained for the trade (see section III-C).As long as token price changes during trade, slippage incurs.In addition, when large trades happen compared to pool size,slippage increases dramatically, resulting in lower tradingprofits [18].Divergence loss, sometimes called impermanent loss, incurswhen liquidity providers withdraw liquidity with the presenceof a difference in token price before and after trades [19].If funds are pulled out during a large price swing, liquidityproviders will suffer a loss of total asset value, comparedto simply holding the assets [20]. Given trades might affecttoken pool prices and hence divergence loss, it is important todistinguish between regular and arbitrage trading. Divergenceloss due to arbitrage trading in closing pool and market pricegap can be mitigated by incorporating reliable oracles toprotect liquidity providers [21].
B. Slippage and Divergence Loss in AMMs
In Bancor, given the dynamic pool price by design, tradesexperience slippage. Divergence loss incurs as the pool priceis intrinsic and relies on arbitrageurs to close price gaps [4]. Toprotect liquidity providers, Bancor v2 integrates with Chain-link price oracle to reduce divergence loss from arbitraging[21].In Uniswap, similar to Bancor, the pool price is inherentlyunstable and the size of trades in relation to pool size affectspool price to different extents. The larger the trades are, thehigher slippage and divergence loss can occur.The constant-sum curve has zero slippage [14][15] and nodivergence loss (as we show in section III). However, becauseit has a fixed price and finite liquidity, it is only suitable forstablecoins and could easily be depleted of one of its poolassets; for this reason, it is primarily of theoretical interest[14][15]. We use it as a baseline in our work.tableSwap/Curve introduces an invariant that allows trad-ing on a Constant Sum shaped curve when the portfolio isrelatively balanced and switch trading to a Constant Productshaped curve when imbalanced [12]. Such a design allowsmuch lower slippage and divergence loss but is only applicableto stablecoins as the price of the desired trading range isalways close to 1.The constant ellipse curve introduced by Wang [8] has afixed price range compared to that of a Constant Product Curveand thus a fixed range of slippage and divergence loss. Wangalso concludes that the LMSR curve would not be suitable forexchanges if the numbers of the two tokens are not balancedin the liquidity pool.The proposal in this paper presents an approach for AMM-based decentralized exchanges using dynamic curves thateliminates the possibility of arbitrage and thus any divergenceloss. Instead, as we show, depending on the chosen family ofcurves, any slippage loss incurred by traders is converted to anequivalent gain for the liquidity providers. A dynamic versionof the constant sum curve is a special case of our proposedsolution, and in that case, there is no slippage loss at all.
C. Simulation
There are two simulations conducted respectively on Sta-bleSwap/Curve and Uniswap v1 to evaluate the DEXes perfor-mance. Egorov [12] suggests that StableSwap/Curve generates312% APR and 0.06% fee per trade for liquidity providerswith total liquidity of $30000 in DAI, USDC and USTD over6 months. Angeris et al. [5] conduct an agent-based simulationto test the hypothesis that Uniswap has a robust market mech-anism with little arbitrage opportunities under various marketconditions. Three types of agents, including profit-maximizingarbitrageurs, traders with exogenous motives and liquidityproviders (both active/Markowitz portfolio optimizing andpassive), interact in the Uniswap and a stochastic referencemarkets. The results show that Uniswap tracks market pricesclosely in different market environments, and Constant ProductCurves have the potential to be price oracles [5].III. B
ACKGROUND - AMM C
URVES AND K EY M ETRICS
Consider a liquidity pool with two coins, whose amounts aredenoted by x and y . For convenience, we will refer to thesetwo tokens as X and Y . The AMM will allow the exchange ofone token for another following a given function f as follows: y = f ( x ) (1)We refer to a plot of this function showing all allowedcombinations of y and x as the AMM curve . For example,there can be a constant product curve, which is y = kx or aconstant sum curve, which would be denoted as y = c − x . Itis generally considered reasonable for the AMM curve to beconvex and monotonically decreasing because this ensures (aswe shall see in the next section) that the price for the token X is monotonically decreasing as a function of its availabilityin the pool, as should be expected of a typical supply curve. Fig. 1. Illustration of Price Slippage on a Trade
A. Price and Bonding Curve
Given an AMM curve, we can derive the price of the X token as follows: p X ( x, y ) = − dydx (2)For example, for the constant product curve, we would get p X ( x, y ) = kx and likewise for the constant sum curve, wewould get that p X ( x, y ) = 1 .A plot of p X ( x, y ) versus x shows how the price of token X varies with its supply in the liquidity pool. Such a curveis referred to as a bonding curve or as a price curve . Notethat if f ( x ) is monotonically decreasing, then the price willalways be positive, and if f ( x ) is convex, then the bondingcurve will be monotonically decreasing (as it should, being atype of supply curve). B. Value of the pool
Given the definition of price, we can also assess the valueof a given liquidity pool (measured in terms of Y ) as follows: V p ( x, y ) = p X · x + y (3) C. Slippage
For curve-based AMM, slippage is defined as the lossincurred by a trader due to the price mismatch between thepool price at which the trade is initiated and the effective priceobtained during the trade. Let us consider a trader seeking tobuy ∆ x units of token X when the LP is at a state ( x , y ) .Say that on the curve, the new point after the trade will be ( x n , y n ) , where x n = x − ∆ x . The amount that the traderwould then need to put into the LP will be ∆ y = y n − y .If the pool price at the original point was p , then the buyerwould have to pay ∆ y = p ∆ x . The difference between ∆ y and ∆ y is defined as the slippage loss S ( x , y , ∆ x ) . This isillustrated in figure 1.Similarly, when the trader wishes to sell ∆ x units of token X , the gap between the ∆ y = p ∆ x that the trader wouldlike to receive and the ∆ y = y − y n that he will actuallyreceive would be the slippage loss on the sale, which couldbe expressed as S ( x , y , − ∆ x ) .t is easy to see that on a constant sum AMM, the slippageloss is always 0 (because the price is constant at all pointson the curve, or, equivalently, the tangent line at any pointand the AMM curve always coincide). On any strictly convexcurve, because the tangent line is always below the curve, theslippage loss will always be a positive quantity (i.e., the traderalways incurs a penalty). The total slippage will be higher fora larger trade, and therefore acts as a disincentive for a traderto make large trades with the LP. D. Divergence Loss
In general, when a trade is made, the price may change,as the original pair of values ( x o , y o ) moves to a new pair ( x n , y n ) following the curve, resulting in a new price p n .Accordingly, the value of the liquidity pool could potentiallydecrease after a trade. This decrease as a relative or percentagedecrease is referred to as divergence loss δ , and can beformally defined as follows: δ = V p n ( x n , y n ) − V p n ( x , y ) V p n ( x , y ) (4)We work out below the divergence loss for the two examplecurves.
1) Divergence loss for constant-product curve:
For theconstant product curve, recall that the following hold: p n ( x n , y n ) = kx n = ⇒ x n = (cid:113) kp n (5) y n = kx n = ⇒ y n = √ k · p n (6)Similarly, we also have that x o = (cid:113) kp o and y o = √ k · p o .Then we can define V p n ( x n , y n ) as follows: V p n ( x n , y n ) = p n · x n + y n = p n (cid:115) kp n + (cid:112) k · p n = 2 (cid:112) k · p n (7)Likewise, we can define V p n ( x o , y o ) as follows: V p n ( x o , y o ) = p n · x o + y o = p n (cid:115) kp o + (cid:112) k · p o (8)Based on the above two equations, we can calculate thedivergence loss as follows: δ = 2 √ k · p n − p n (cid:113) kp o + √ k · p o p n (cid:113) kp o + √ k · p o (9)Denoting by ρ the ratio of the two prices p n p o , the divergenceloss for the constant product curve can be simplified to: δ = 2 √ ρ − − ρ ρ (10)This result is given in [19].
2) Divergence loss for constant-sum curve:
Here the priceis always 1. The two values can be written as follows: V p n ( x o , y o ) = x o + y o = cV p n ( x n , y n ) = x n + y n = c (11)Since both are the same, the liquidity pool does not showany change in value, and thus the divergence loss in this casewill be 0. IV. D YNAMIC CURVES
In the prior work on AMMs, the curve has a fixed form andthe exact shape is determined by the initial total liquidity. E.g.,in the constant product curve, the parameter k = x i · y i where x i , y i are the initial amounts of the two tokens. In other words,the curve can only change if the liquidity providers add/removetokens from the pool, but not from trading activity.Consider a trade that happens while the market price oftoken X remains unchanged at some price p mkt . If the poolchanges from the state ( x o , y o ) to a new state ( x n , y n ) , thenthe pool price would potentially change from p ( x o , y o ) to p ( x n , y n ) (assuming the curve is not the constant-sum curvein which case there is no change in the pool price). This canresult in at least a temporary difference between the pool priceand the market price. As we do in the rest of the paper, we areassuming here that the pool’s capitalization is a relatively smallfraction of the total market capitalization of the underlyingassets so that the market price is not determined or affectedby the pool price.Another reason for a temporary difference between the poolprice and the market price could be that the market pricechanges due to some external market conditions. In either case,traditionally, it is expected that these temporary differenceswill be erased by the action of arbitrageurs, restoring the poolprice back to the market price.We propose a new mechanism that instead changes the curveevery time the market price changes in such a way as to ensurethat the current pool price will always equal the market price, without requiring action by external arbitrageurs . We illustratebelow how this new mechanism would generalize the constant-product and constant-sum curves – the same approach can beused to generalize other smooth, decreasing, convex curves tothe dynamic setting as well. A. Dynamic curve adjustment to generalize constant-sum
In this case, we can describe the market-price-trackingdynamic curve as follows: p mkt ( t ) · ( x ( t ) − a ( t )) + y ( t ) = c (12)Here, the parameter a ( t ) will also be adjusted dynamicallywhen the market price changes, to ensure that the new linearcurve passes through the current pair of ( x ( t ) , y ( t )) values. Forsimplicity, say the market is initialized at some pair ( x (0) , y (0) at a market price of 1. Then c could be set to be x (0) + y (0) ,with the original a (0) = 0 .f the market shifts to a price of p mkt ( t ) at some time t andthe liquidity pool at this arbitrary time is ( x ( t ) , y ( t )) , then thevalue of a ( t ) will also be adjusted as follows to match theabove dynamic curve: a ( t ) = x ( t ) − c − y ( t ) p mkt ( t ) (13)Intuitively, this dynamic curve is always a line that has theslope corresponding to the current market price and alwayspassing through the current liqudity pair ( x ( t ) , y ( t )) .Any trade that happens uses the current (instantaneous)curve. This allows the constant sum AMM to flexibly support awider range of market prices while still providing 0 slippagecompared to the original design (which allows only a fixedpool price and thus will not work when the market price isdramatically different). B. Dynamic curve adjustment to generalize constant-product
In this case, we can describe the market-price-trackingdynamic curve as follows: w ( t ) · ( x ( t ) − a ( t )) · y ( t ) = k (14)Or alternatively, as: y ( t ) = kw ( t ) x ( t ) − a ( t ) (15)Note that in the above expressions, x ( t ) and y ( t ) mustalways be strictly positive; a ( t ) must be constrained to bealways strictly less than x ( t ) ; and w ( t ) should always bestrictly positive. The instantaneous price corresponding to thedynamic version of the constant product curve can be definedas follows: p X ( t ) = kw ( t ) · x − a ( t )) (16)When the market price changes, then both w ( t ) and a ( t ) will have to be changed in order to (a) make sure that the newmarket price p mkt ( t ) matches p X ( t ) in equation (16) and (b)x(t),y(t) match the curve described in equation (14). Thus wehave to solve two equations and two unknowns. The solutionturns out to be the following : a ( t ) = x ( t ) − y ( t ) p mkt ( t ) w ( t ) = k · p mkt ( t ) y ( t ) (17)We remark: the first expression above ensures the require-ment mentioned above that a ( t ) will remain strictly less than x ( t ) and the second expression ensures that w ( t ) is strictlypositive, so long as k , p mkt ( t ) , x ( t ) and y ( t ) are all keptstrictly positive at all. C. From divergence loss to slippage gain
As with the static setting, there is no slippage loss for tradersor divergence loss in the case of dynamic constant sum AMM.This is because in the absence of any change in market price,the pool price does not change during a trade.In the case of the dynamic constant product AMM, thetraders do experience a slippage loss just like in the staticconstant product AMM case. However, corresponding gain invalue is accrued entirely to the liquidity pool and could bereferred to as a slippage gain for the LP. Further, in the absenceof change in the market price, because the pool price doesnot change in the dynamic constant product curve, there is nodivergence loss. Rather, the LP benefits from each trade by thesame slippage gain. Thus, the dynamic constant product AMMprovides a strict improvement from the LP’s perspective. Thisresult, in fact, generalizes to the dynamic version of any strictlyconvex curve, as we show below.
Theorem 1.
In a dynamic AMM based on a family ofmonotonically decreasing y = f ( x ) curves that are strictlyconvex, when the market price remains fixed, the LP will gainvalue after each trade by an amount equivalent to the slippageloss of the trader.Proof. Assuming the market price does not change duringa trade, for any strictly convex curve, the trader suffers aslippage loss at each trade. This is because the tangent to thecurve (whose slope is equal to the pool price and thereforethe market price) lies below the curve if it is strictly convex.If the trader buys X tokens, it will therefore have to give thepool an amount of Y tokens that exceeds what it should havegiven at the current market price. Likewise, if the trader sells X tokens, it will receive an amount of Y tokens less than whatit should have received at the current market price. The gap,in either case, corresponds to the slippage loss. An equivalentamount is gained by the LP (when the trader buys X tokens,the excess Y tokens are sent to the LP; when the trader sells X tokens, the gap corresponds to Y tokens are withheld bythe LP). There is no other source of divergence loss for theLP because the pool price is readjusted to the market priceimmediately after execution of the trade - its value increasesprecisely by the amount of slippage loss experienced by thetrader. V. S IMULATION R ESULTS
We conduct a number of simulations to compare theperformance of four different AMM’s, two static AMM’s(Constant-Sum AMM, Constant-Product AMM) and their twodynamic generalizations that we have introduced in section IV.Although it is not practically implemented due to its short-comings, we nevertheless use the constant-sum AMM as abaseline to highlight how the dynamic version of this schemehas advantages and may be more interesting from a practicalperspective.a) X token holdings (b) Y token holdings (c) Total Value(d) Market vs Pool Price (e) Collected Fees (f) Declined Trades
Fig. 2. Simulation of a Static Constant Sum AMM
A. Simulation Setup
In all our simulations, we consider the three parties in-volved: • The liquidity pool (LP). • A trader (which could be viewed as a collection orseries of independent traders who are merely interestedin exchanging a relatively small amount of one of thetokens in the LP for another). • An arbitrageur (a profit-maximizing agent respondingspecifically to any gaps in price between the pool and thebroader market; the arbitrageur in our simulation couldalso be viewed as a collection or series of independentarbitragers).Initially, all three parties have 1000 X tokens and 1000 Y tokens. At each time, a trader makes a random trade (buyor sell X token) drawn from a standard normal distribution(i.i.d. Gaussian process with zero mean and unit variance). Therelatively small standard deviation would result in relativelylight trading or profit from transaction fees collected fromtrades (that are not for the purpose of arbitrage). We use theexact same sequence of random trades in evaluating all fourAMM’s, to enable a fair comparison. We model the marketprice as undergoing a linear increase from 0 to 10 over thecourse of 1000 time steps. B. Static Constant Sum AMM
Figure 2 shows the results for the baseline static constantAMM. As shown by figure 2(d), the market price is initiallybelow the pool price of 1, and after 100 time steps it switchesto being above the pool price. As can be seen from figure 2(a), (b), the arbitrageur initially sells all its X tokens to buyup all of the Y tokens from the LP when the market price islow, and then it buys up all the X tokens from the LP when the market price becomes high. By draining the pool of itsliquidity in one of its assets, to the pool’s disadvantage, thearbitrageur effectively extracts most of the total value from theLP. Figure 2(c) shows the total value of the LP, the arbitrageurand the trader measured in terms of the market price at theend of the simulation (when X tokens are worth 10 Y tokens);it shows that the LP ends up with only about a tenth ofthe value it had at the beginning of the simulation. The LPdoes collect some fees from the arbitrageur (per figure2(e)),but they are relatively modest compared to the loss in value.Although the trader doesn’t suffer slippage loss in this case, itcan be disappointed and face a rejection of its requested tradewhenever the pool lacks sufficient tokens of the type soughtby the trader (as shown in figure 2(f); this happens particularlyearly on when the arbitrageur is able to cause the LP to benearly empty of one of its assets, then another, disrupting theLP’s ability to serve the regular trader). C. Static Constant Product AMM
Figure 3 shows the results for the static constant productAMM. Here too, we can see from Figures 3(a) and (b), thearbitrageur has a big impact on the token holdings of the LP.Over time, as the market price goes up, the arbitrageur keepsbuying X tokens from the pool, equalizing the pool price andthe market price. Eventually the arbitrageur has no more Y tokens available (after which point the pool prize stays belowthe market price, see Figure 3(e)). As shown in figure 3(c),the total value of the LP reduces while that of the arbitrageurgrows until the latter runs out of Y tokens. In reality, however,a well-funded arbitrageur would keep going until all X tokensare depleted from the LP, causing it to lose even more value.The trader suffers some constant slippage on average in everytrade, as illustrated by the cumulative slippage showing aa) X token holdings (b) Y token holdings (c) Total Value(d) Cumulative Slippage (e) Market vs Pool Price (f) Collected Fees Fig. 3. Simulation of a Static Constant Product AMM (a) X token holdings (b) Y token holdings (c) Total Value(d) Market vs Pool Price (e) Collected Fees (f) Declined Trades
Fig. 4. Simulation of a Dynamic Constant Sum AMM linear increasing trend in Figure 3(d). There are again somecollected fees from the arbitrageur and the regular trader, buthere too they pale in comparison to the loss in value causedby the arbitrageur’s actions. It is clear that just like with theconstant sum setting, in the long term, the LP is at the mercyof the arbitrageur in the presence of significant market pricevolatility.
D. Dynamic Constant Sum AMM
Figure 4 shows the results for the dynamic constant sumAMM. Here the arbitrageur is eliminated as the pool priceis automatically adjusted to the market price after each trade. The total tokens of either types X or Y remain the sameand the holdings of the LP and the trader are mirror imagesof each other, as shown in figures 4(a) and 4(b). The totalvalue of the LP doesn’t show a dramatic change other thanrandom fluctuation caused by stochastic trading on the pool.In the absence of aggressive arbitrage, the collected fees aresomewhat modest. As shown by figure 4(e), the LP collectsthe expected amount of fees (about 80 over 1000 trades,corresponding to the expectation of the absolute value of anormal random variable). A noticeable fact about the dynamicconstant sum AMM is that the LP maintains more than 85% a) X token holdings (b) Y token holdings (c) Total Value(d) Cumulative Slippage (e) Collected Fees (f) Market vs Pool Price Fig. 5. Simulation of a Dynamic Constant Product AMM of the original amount of tokens of both types at all times during the simulation. This is in sharp contrast to the liquidityproblems observed in the static settings (figures 2 and 3). As aresult, there are no declined trades, as evidenced by figure 4(f).Another related comment to be made here is that there is littleincentive for large trades in this dynamic AMM because theprice is always pegged to the market price and the transactionfees (being a constant percentage) impose a higher cost inabsolute terms on larger trades.
E. Dynamic Constant Product AMM
Finally, figure 5 shows the results for the dynamic constantproduct AMM. Here too, the arbitrageur is eliminated as thepool price is automatically adjusted to the market price aftereach trade (see figure 5(f)), and the X and Y tokens held bythe trader and LP mirror each other as shown in figure 5(a)and figure 5(b). The total value of the LP in figure 5(c) doesn’tshow a dramatic change other than the fluctuation caused bystochastic trading on the pool and a slight increase in value forthe LP due to the slippage gain discussed earlier in this paper.The corresponding cumulative slippage loss for the trader,equivalent to the cumulative slippage gain for the LP, is shownin figure 5(d), and it is this gain that results in a slight positivedrift in the LP value over time. As with the dynamic constantsum AMM, in the absence of aggressive arbitrage, the LPcollects the expected amount of fees from the regular trader( ≈ over 1000 trades, corresponding to the expectation ofthe absolute value of a normal random variable). Comparedto the dynamic constant sum setting, here, there is even lessincentive for any trader to execute a large trade as they wouldsuffer a large slippage loss in addition to paying transactionfees. Figure 5(a) and figure 5(b) show that the LP maintainshigh liquidity in both assets again – more than 90% of the original amount of tokens of both types at all times during thesimulation. VI. C ONCLUSIONS
We have given a detailed introduction to curve-based AMMsfor decentralized cryptocurrency exchanges in this work. Weintroduced a new approach to operating such curve-basedAMM decentralized exchanges that utilizes an oracle with areal-time market price feed to continuously and automaticallyadjust the pool price to the market price by dynamicallyadjusting the curves over time. We showed that in such adynamic AMM, there is no room for arbitrage. The slippageloss for traders is converted to an equivalent gain for theliquidity pool. The LP maintains a high level of liquidityin all assets and its total value stays fairly stable over time.Such a dynamic AMM results in a slightly lower collectionof transaction fees due to the elimination of arbitrageurs, butthis loss is more than offset by the ability to maintain the totalvalue of the pool.From a practical perspective, implementing such a dynamicAMM requires the use of a low-latency and accurate marketprice oracle. It would be of great interest to develop andevaluate a real-world decentralized exchange based on thisapproach. R
EFERENCES[1] S. Nakamoto, “Bitcoin: A peer-to-peer electronic cash system,” tech.rep., 2019.[2] L. H. White, “The market for cryptocurrencies,”
Cato J. , vol. 35, p. 383,2015.[3] “Coinmarketcap: Cryptocurrency prices, charts and market capitaliza-tions.” https://coinmarketcap . com/. Accessed: 2020-12-18.[4] E. Hertzog, G. Benartzi, and G. Benartzi, “Bancor protocol:continuousliquidity for cryptographic tokens through their smart contracts,” tech.rep., 2018.5] G. Angeris, H.-T. Kao, R. Chiang, C. Noyes, and T. Chitra, “An analysisof uniswap markets,” Cryptoeconomic Systems Journal , 2019.[6] W. Warren and A. Bandeali, “0x: An open protocol for decentralizedexchange on the ethereum blockchain,” https://github . com/0xProject/whitepaper , 2017.[7] R. Hanson, “Logarithmic markets scoring rules for modular combinato-rial information aggregation,” The Journal of Prediction Markets , vol. 1,no. 1, pp. 3–15, 2007.[8] Y. Wang, “Automated market makers for decentralized finance (defi),” arXiv preprint arXiv:2009.01676 , 2020.[9] “Gnosis whitepaper,” tech. rep., 2017.[10] J. Peterson, J. Krug, M. Zoltu, A. K. Williams, and S. Alexander,“Augur: a decentralized oracle and prediction market platform,” arXivpreprint arXiv:1501.01042 . reddit . com/r/ethereum/comments/55m04x/lets run onchain decentralized exchanges the way/, Oct2016. Accessed: 2020-12-18.[14] D. Berenzon, “Constant function market makers: Defi’s ”zero to one”innovation.” https://medium . com/bollinger-investment-group/constant-function-market-makers-defis-zero-to-one-innovation-968f77022159,May 2020. Accessed: 2020-12-18.[15] Chainlink, “How to bring more capital and less risk to automatedmarket maker dexs.” https://blog . chain . link/challenges-in-defi-how-to-bring-more-capital-and-less-risk-to-automated-market-maker-dexs/,Jun 2020. Accessed: 2020-12-18.[16] G. Angeris and T. Chitra, “Improved price oracles: Constant functionmarket makers,” arXiv preprint arXiv:2003.10001 , 2020.[17] Totle, “Do dexs have a slippage problem?.” https://medium . com/totle/do-dexs-have-a-slippage-problem-68c3a4fe5161, Sep 2019. Accessed:2020-12-18.[18] R. Chen, “A comparison of decentralized exchange designs.”https://thecontrol . co/a-comparison-of-decentralized-exchange-designs-1deef249f56a, Apr 2019. Accessed: 2020-12-18.[19] Pintail, “Uniswap: A good deal for liquidity providers?.”https://pintail . medium . com/uniswap-a-good-deal-for-liquidity-providers-104c0b6816f2, Aug 2020. Accessed: 2020-12-18.[20] Chainsecurity, “Upcoming exchange concepts – a farewell to the orderbook?.” https://chainsecurity . com/disruption-or-disillusion/. Accessed:2020-12-18.[21] Bancor, “Announcing Bancor V2.” https://blog . bancor ..