Automated market makers and decentralized exchanges: a DeFi primer

Recent advancements in decentralized finance (DeFi) have resulted in a rapid increase in the use of Automated Market Makers (AMMs) for creating decentralized exchanges (DEXs). In this paper, we organize these developments by treating an AMM as a neoclassical black-box characterized by the conversion of inputs (tokens) to outputs (prices). The conversion is governed by the technology of the AMM summarized by an ‘exchange function’. Various types of AMMs are examined, including: Constant Product Market Makers; Constant Mean Market Makers; Constant Sum Market Makers; Hybrid Function Market Makers; and, Dynamic Automated Market Makers. The paper also looks at the impact of introducing concentrated liquidity in an AMM. Overall, the framework presented here provides an intuitive geometric representation of how an AMM operates, and a clear delineation of the similarities and differences across the various types of AMMs.

so, we show that the graphical and mathematical methods familiar to generations of students of economics can provide broad insights into certain aspects of DeFi, and that many recent experiments in DeFi are applications of more general production technologies.Ultimately, the motivation here is to introduce these ideas to DeFi aficionados who are interested in an economic theory perspective, and to present some wonderful new applications of old tools to economists, especially students and educators. 2he application of DeFi that this paper focuses on is decentralized exchanges (DEXs).In contrast to an over-the-counter (OTC) market that enables direct trading between two agents, an exchange is an institution which standardizes assets and trading rules for multiple participants.To do so, an exchange must provide mechanisms to maintain liquidity of assets and to determine prices for assets.A stock exchange, for example, implements this through an order book system, where buyers and sellers submit 'orders': prices and volumes for an asset they would like to buy or sell.The trading price is determined by matching orders.Typically, orders are public information, allowing market participants to gauge information about interest in an asset and the price at which it is trading.In a centralized exchange, orders are maintained by a central authority (say, the New York Stock Exchange).
A DEX provides agents with the opportunity to exchange one asset for another without a centralized third-party responsible for overseeing trading activity.The cryptocurrency space has been dominated by centralized exchanges in the past, many of whom, such as Mt.Gox, met with disastrous downfalls and losses that have, if anything, only strengthened the resolve to make DEXs work.Schär (2021) and Pourpouneh et al (2020)  list the various pros and cons of centralized and decentralized exchanges.Specifically, centralized exchanges can be easier to implement but suffer from a number or drawbacks: traders lose custody of assets and must trust the exchange to not seize assets; they can be susceptible to security threats due to a single point of attack; and, centralized exchanges for cryptocurrencies have been subject to little regulation.DEXs, on the other hand, do not rely on trust in, or security of, a single centralized party as traders retain custody of assets and smart contracts execute trades.They are, however, harder to design and implement, and can charge higher fees to attract liquidity.
DEXs can be implemented in different ways.Some replicate the order book format of a centralized exchange.One way to do this is through an on-chain order book where every order is recorded on the blockchain, but this can be expensive.An alternative approach involves constructing an off-chain order book, which only uses the blockchain for settlement, but orders are recorded elsewhere (possibly by some centralized third-party).This is less expensive, but also less decentralized and secure compared to an on-chain order book (Schär 2021; Pourpouneh et al. 2020).
Instead of using an order book, more recent attempts at establishing DEXs have revolved around the use of automated market makers (AMMs), which is the subset that this paper focuses on.Following Hanson (2003) and Hanson (2007), AMMs first gained popularity in prediction markets for aggregating predictions of agents into prices.In general, a market maker is an institution that stands ready to buy or sell an asset, generating a profit from the bid-ask spread: the difference between the ask or offer rate (the rate at which the market maker sells an asset) and the bid rate (the rate at which the market maker buys an asset).An AMM automates this by allowing traders to place orders with the AMM, which then algorithmically provides a price.It is worth reiterating how this process is distinct from the order book system that requires matches between price and volume orders provided by buyers and sellers.With a market maker, an agent trades with the market maker by selecting a quantity of an asset to trade at a price specified by the market maker.This is particularly beneficial in thin markets where there are few buyers and sellers, so that there may be a wide gap between the maximum price any buyer is willing to pay and the minimum price any seller is willing to accept, thereby causing no trades to occur.When a market maker acts as the counterparty to all trades, liquidity can be provided even when markets are thin.
Traders on a DEX are interested in swapping one token for another with the AMM.So, the question that arises is: who exactly provides liquidity for an AMM to act as a DEX?The answer is that owners of various tokens do so by placing their tokens within a liquidity pool in the AMM; the quantities of tokens in a liquidity pool are its reserves. 3In return, liquidity providers are typically entitled to a share of the fees paid by traders for exchanging tokens.Returns in the form of trading fees provide incentives for agents to act as liquidity providers.
In an order book system, the matching of orders by buyers and sellers (that is, the forces of demand and supply) produces a price.In an AMM, prices are determined algorithmically; what guarantees, then, that the AMM prices reflect demand and supply conditions in the wider market for cryptocurrencies?For example, suppose there exists another exchange-an 'external' or 'reference' market-that prices some token, say ABC token, at 2 XYZ tokens.If a trader wants to swap between ABC and XYZ tokens at the AMM, the AMM's algorithm should set a price close to the price in the external market.There are, in fact, a couple of different ways in which the price in the AMM can be made to align with that of the external market.The first, and most common, is through the process of arbitrage, wherein arbitrageurs buy and sell assets across markets to take advantage of price differentials and make (risk-free) profits.In doing so, arbitrageurs cause an alignment of prices.The second is by allowing the reference market to act as an oracle, which is essentially an external source of information used by the AMM to set its price.

Smart contracts
Smart contracts are at the heart of DeFi applications and, consequently, current DeFi platforms are being built predominantly on Ethereum's smart contract-based blockchain. 4Smart contracts were first introduced by Szabo (1996), along with a working definition: "A smart contract is a set of promises, specified in digital form, including protocols within which the parties perform on these promises" [emphasis added].Closer 3 Of course, a single agent is free to perform both functions-provide liquidity and trade-on an AMM. 4 See https:// ether eum.org (accessed 20th September, 2021), and https:// ether eum.org/ en/ white paper/ (accessed 20th September, 2021) or Buterin (2014).
examination of this definition reveals two distinct aspects of a smart contract: a legal contractual aspect and a technological aspect.The contractual aspect of a smart contract arises from the concepts of 'promise' and 'performance' contained in the definition.Presumably, promises are based on intention and performance will involve consideration, so one could compare this to a standard contract as defined by the legal profession.But the definition also suggests that the contract is 'digital ' and includes 'protocols' (read:  algorithms), which provides a distinct technological twist to the definition.
Using Szabo's (1996) definition, therefore, one can come away with different impressions of a smart contract, depending on which facet one wishes to emphasize.In this paper, we do not approach a smart contract from a legal point of view, not least because the literature on the issue of how standard contract law applies to smart contracts warrants its own separate study.Nor do we focus on issues that economists typically examine in contract theory: asymmetric information (the complete contract literature), or property rights and organizational boundaries (the incomplete contract literature).Rather, for the purpose of this paper, the most fruitful avenue is to focus on technological aspects of a smart contract.As a definition, the US National Institute of Standards and Technology defines a smart contract as "A collection of code and data (sometimes referred to as functions and state) that is deployed using cryptographically signed transactions on the blockchain network." 5 Similarly, the Ethereum whitepaper states that, "Smart contracts, cryptographic 'boxes' that contain value and only unlock it if certain conditions are met, can also be built on top of the platform, with vastly more power than that offered by Bitcoin scripting because of the added powers of Turing-completeness, value-awareness, blockchain-awareness and state." 6 The Ethereum network has two types of accounts: externally owned accounts (EOAs) and contract accounts (or smart contracts).EOAs in Ethereum are standard cryptocurrency accounts and are characterized by three elements: a private key, a public key and a balance of the cryptocurrency native to the blockchain, which in the case of Ethereum is Ether (ETH).The public key is used to generate an address that identifies an EOA in the network, and the private key, known only to the holder of the account, is used to (cryptographically) authorize transactions.Thus, one agent can use her private key to authorize the transfer of a certain amount of ETH to another agent on the network.When the transaction is added to a block, the blockchain state is updated and the EOAs of both agents change to reflect the transaction.
In contrast, a smart contract is characterized by an address, a balance and code.A number of features follow.First, the absence of a private key associated with a smart contract implies that no agent on the network can authorize a change to the smart contract code (even if it has a bug).Rather, the smart contract is controlled by the code embedded within it, which is immutable once the contract is added to the network, and cannot be altered by any agent. 7Second, apart from ETH, a smart contract can hold compatible 5 See https:// csrc.nist.gov/ gloss ary/ term/ Smart_ contr act (accessed 20th September, 2021). 6See https:// ether eum.org/ en/ white paper/ (accessed 20th September, 2021). 7The main hurdle to simply replacing a smart contract (say, that has a bug in it) with a new one occurs when the address generated for a smart contract depends on the current state.So, if a bug is found in a smart contract after deployment, a new contract deployed (in the future) with new code would receive a new address.Even with this constraint, there exist ways to 'upgrade' a contract, for example by using a proxy contract, or by deploying a new contract (with a new address) and migrating users and data to the new address (which can be expensive).In 2019, as part of the Constantinople upgrade to the Ethereum blockchain, the CREATE2 functionality was introduced (see https:// eips.ether tokens, such as 'ERC-20' tokens (that conform to ERC-20 standards for fungible tokens) or 'ERC-721' tokens (that meet ERC-721 standards for non-fungible tokens).8This is a useful feature because the smart contract acts as a sort of custodian of tokens, receiving and disbursing tokens using algorithms specified by the code.
A liquidity pool in an AMM is a smart contract with a certain set of tokens that the smart contract can maintain balances of, as specified by its code.The balances of tokens are the quantities that serve as reserves, which change as traders swap tokens in the liquidity pool.The code specifies, among other things, the rules for trading, how prices are determined based on reserves, the rules for liquidity provision, and the trading fees that traders pay to utilize the liquidity pool.An AMM itself, then, is simply a set of liquidity pools.
Finally, there are multiple transaction costs an agent may incur when utilizing an AMM.First, the agent may have to pay a trading fee (or swap fee) for exchanging tokens with the AMM; these fees act as returns for liquidity providers.Second, there is a cost to changing ledger entries on the blockchain to record changes in the ownership of tokens.These gas fees on Ethereum vary depending on the extent to which the blockchain is being used for any purpose, DeFi or otherwise.In what follows, we do not factor in gas fees and focus entirely on the impact of trading fees charged by a specific AMM.In reality, when performing DeFi transaction gas fees have to be included in trading decisions, and can sometimes be significant enough to deter use of DeFi applications.9Some AMMs also have the ability to charge protocol fees that are, essentially, meant for future development of the AMM.We do not examine protocol fees in this paper.10

The approach and contribution of this paper
This paper examines how AMMs operate as DEXs to facilitate price discovery, arbitrage, and the exchange of one cryptocurrency token for another.To achieve this, we view an AMM in much the same way as neoclassical economic theory models a firm: as a 'black-box' .A neoclassical firm is characterized entirely by its ability to convert factor inputs, such as labour and capital, into output using some technology made available by scientists and engineers.The nature (or if one were to depict this graphically, the 'shape') of the technology is summarized by a production function, which then delineates which combinations of inputs and outputs are feasible.Given the costs associated eum.org/ EIPS/ eip-1014, accessed 20th September, 2021).This essentially allows the address to be independent of future states, so it is possible to calculate a smart contract's address even without deployment.In terms of upgrading a smart contract, this implies that if a smart contract is issued an address using the CREATE2 functionality, it can be instructed to self-destruct and a new smart contract can be deployed with the same address.
Footnote 7 (continued) with purchasing inputs and the revenues generated by selling the output, different feasible combinations of inputs and outputs generate different profits.The firm then, automaton-like, simply picks the combination of inputs and output from the set of all feasible combinations that yields the maximum profit.
In the neoclassical characterization of the firm there is scant attention paid to what goes on inside a firm (hence the term 'black-box').Issues that real-world businesses must tackle on a daily basis, such as providing incentives to workers to exert effort, determining appropriate pay packages for employees, resolving problems associated with hierarchy and authority, and so on, are entirely ignored in a black-box view, which is based on the premise that the technology behind the production of goods and services is of paramount importance.Moreover, the black-box model does little to address what determines the boundaries of a firm-why some activities are organized within a firm and others through market transactions.Many of these problems were addressed in later developments to the theory of the firm in the form of principal-agent models and transaction cost theories. 11he drawbacks of the black-box methodology notwithstanding, it does what it's supposed to do-describing the conversion of inputs to outputs-extremely well.If in some context of analysis the focus is indeed on the technology behind this conversion, the black-box nature of the neoclassical firm is, to borrow a phrase from programmers, a feature and not a bug, because it removes all the clutter about what goes in on inside a firm to hone in on what is contextually important: the technology.
Given the myriad DEX platforms that have emerged in the recent past, one could make the argument that our current understanding is at a stage where it would benefit from a careful examination of how inputs are converted to an output by an AMM.The approach adopted by this paper is to view an AMM as a black-box that transforms quantities of tokens in an AMM (inputs) into a price (output).The transformation is governed by the specification of an 'exchange function' that describes the technology of token trade in an AMM. 12 It is worth emphasizing that we do not equate an AMM to a firm; rather, the methodology of treating the firm as a black-box is utilized here to model an AMM.
The exchange function that has received the most attention in the DeFi community is used by a Constant Product Market Maker (CPMM), Uniswap. 13Since this is typically the first type of AMM that many entrants into the DeFi space encounter, the section "The workings of a Constant Product Market Maker (CPMM): Uniswap-v1 and v2" provides a detailed account, using examples, of how such an AMM operates as a DEX and how fees generate bid-ask spreads.Moreover, given the importance of arbitrage in pricing, this section examines two and three-point arbitrage, along with relevant noarbitrage conditions.
Following its inception in 2018, Uniswap has undergone multiple iterations: Uniswap version 1 (v1) was the original proof of concept;14 this was upgraded to version 2 in 2020 (v2; Adams et al. 2020). 15While our analysis in the section "The workings of a Constant Product Market Maker (CPMM): Uniswap-v1 and v2" is based on the characteristics of Uniswap-v1 and v2, other CPMMs exist, such as Sushiswap and Mooniswap. 16Consequently, in order to generalize the ideas here, we will often refer to a CPMM-v1 or v2 to characterize a CPMM that has the characteristics of Unsiwap-v1 or v2, respectively.
The section "The geometry of a CPMM" introduces some basic tools of economic modelling-homogeneous functions, homothetic functions and Euler's theorem-as well the geometric properties characterizing these tools.While the material here is fairly self-contained, more detailed and leisurely discussions of these topics can be found in any introductory text on mathematical methods in economics, such as Chiang (1984)  or Silberberg (1990). 17This facilitates an examination of the properties and geometry of a CPMM, which complements and extends existing contributions to the analysis of price formation and arbitrage in a CPMM, such as Angeris et al. (2019) and Zhang et al.  (2018).
The section "Other types of AMMs for decentralized exchanges" examines other AMMs that have gathered interest as DEXs, including a: Constant Mean Market Maker (CMMM), such as Balancer; Constant Sum Market Maker (CSMM), which has drawbacks as a DEX; Hybrid Function Market Makers (HFMM), such as Curve Finance; and, Dynamic Automated Market Maker (DAMM), such as Bancor. 18The focus here is very much on fitting these AMMs into the framework developed in "The geometry of a CPMM", as well as on drawing out similarities and points of departure in their characteristics.The specific institutional features of each of these AMMs are not described nearly as carefully as for the CPMM, though in many instances, if required, these features can be readily related to concepts introduced for a CPMM. 19verall, while a variety of AMMs have emerged to trade tokens in a decentralized manner, their performance and attributes are connected.Figure 1 below serves to summarize the links we develop between the various AMMs.As the figure shows, a CPMM is a special case of a CMMM.Allowing for weights to change in a CMMM replicates the performance (in terms of price adjustments) of a DAMM.Mixing a CSMM with a CMMM yields a HFMM.
Recently, Uniswap released Version 3 (v3; Adams et al. 2021), which is a significant departure from v2.In the section "An AMM with 'concentrated liquidity': Uniswap-v3", we review the changes brought about by Uniswap-v3 and turn to broadly outlining the geometry behind this AMM by examining the idea of concentrated liquidity.We show here that Uniswap-v3 displays some characteristics of both a CPMM and a CSMM.
Like the neoclassical firm, the black-box view of an AMM has limitations in describing other aspects of an AMM, such as how decentralized governance of an AMM is organized, how communities are formed in this space, and so on; this paper does not address these important and interesting issues.Nor does this paper delve into the uses of AMMs other than for the purpose of creating a DEX.Some concluding thoughts on this are offered in the section "Conclusions".

The workings of a Constant Product Market Maker (CPMM): Uniswap-v1 and v2
In a CPMM such as Uniswap, the product of the quantity of two tokens in a liquidity pool is a constant.The example examined here replicates and extends the one developed in the original Uniswap-v1 whitepaper.When needed, we will introduce the changes brought about in Uniswap-v2, and how this impacts the workings of the CPMM platform.

Examples and some basic pricing equations
The two tokens in focus here are token X (which we assume to be ETH) and token Y (some ERC-20 token, say ABC).In what follows, we use upper-case letters for the token in general and lower-case letters for specific quantities of the tokens.For any given token quantities, (x, y) , a CPMM utilizes the exchange function xy = k to algorithmi- cally govern trade between the two tokens.To see how this works, let the initial amount of ETH supplied by liquidity providers be x 0 = 10 , and the amount of ABC provided be y 0 = 500 ; these are the initial reserves of the two tokens in the AMM liquidity pool.In a CPMM, the product of the two is a constant or invariant, k , which takes an initial value k 0 = x 0 y 0 = 5000.
A trader in this market is any agent who exchanges one token for another in the pool.In order to do this, the trader must pay a trading fee, which accrues to the liquidity providers.However, to establish a baseline case, let us first consider the situation where the trading fee is zero.Suppose the trader wishes to sell 1 ETH in exchange for ABC.In the absence of a trading fee, this entire amount is added to the liquidity pool, resulting in a pool balance of x 1 = 11 ETH.Given k 0 , the amount of ABC in the pool is y 1 = k 0 x 1 = 454.5454 .The change in the pool reserves of ABC is y 1 − y 0 = −45.4546, which is negative because the reserves of ABC in the AMM have fallen; this quantity of 45.4546 ABC is sent to the trader's account.The trader has effectively sold 1 ETH in order to buy 45.4546ABC with the AMM, which is the counterparty to the trade; con- sequently, the liquidity providers for the AMM now, in aggregate, hold 1 ETH more and 45.4546ABC less.While the AMM has an altered reserve profile (x 1 , y 1 ) , it is evident that x 1 y 1 = k 0 , and the product of the new reserve quantities equals the constant k 0 .The price of 1 ETH in terms of ABC in this example is P b Y /X = 45.4546ABC/ETH.In terms of the notation, the subscript Y /X indicates that the price is for one unit of token X (ETH) in terms of token Y (ABC), while the superscript b indicates that this is the bid price: the price at which the AMM buys ETH. 20It is straightforward to work the example in reverse, where the trader buys 1 ETH from the AMM.Proceeding as before: x 1 = 555.5556and y 1 − y 0 = 55.5556 .The price in this instance is P a Y /X = 55.5566ABC/ETH, where the superscript a indicates that this is the ask (or offer) price of ETH: the price at which the AMM sells 1 unit of ETH to the trader.
The bid and ask rates in this example seem appreciably different-the bid-ask spread is P a Y /X − P b Y /X = 10.102 , primarily because the changes considered here are lumpy and fairly large in magnitude.In reality, ETH is divisible to 18 decimal places, so much smaller trades are feasible. 21Suppose the trader were to buy and sell 0.01 ETH instead of 1 ETH in the example.The bid and ask prices are now P b Y /X = 49.9500ABC/ETH and P a Y /X = 50.0501ABC/ETH and the spread is only P a Y /X − P b Y /X = 0.1001 .Indeed, as the change in ETH in the trade keeps getting smaller, the two converge towards the price of 50 ABC/ETH.In general, it can be shown (which we do subsequently) that with infinitesimal changes and no trading fees: There are a few features to take away from this example.First, Eq. (1) summarizes the fact that the bid and ask prices collapse to a single price ( P Y /X ) for infinitesimally small changes, and that this price equals the ratio of the two reserves ( y 0 x 0 ).Second, the price of one unit of ABC in terms of ETH (that is, P X/Y ) converges to: Third, with no fees, k 0 remains the same for all subsequent trades, and only changes when liquidity is injected into, or withdrawn from, the pool by liquidity providers.Now consider a situation where the trader is required to pay an ad valorem trading fee, τ .Apart from the addition of fees, all the other features of the example are main- tained.The trading fee is assumed to be τ = .25% in the example constructed in the (1) In the notation Y/X , X is the 'base' token and Y is the 'pricing' token.As in traditional finance, we use the terms 'bid' and 'ask' (or 'offer') as rates viewed from the perspective of the market maker.A trader, therefore, sells at the bid price, and buys at the ask price. 21See https:// ether eum.org/ en/ eth/ (accessed 20th September, 2021).
Uniswap-v1 whitepaper, which we follow here as well; in reality, the fee on Uniswap-v1 and v2 is 0.3%.The trading fee is paid using the token that is added to the liquidity pool (that is, the token sold by the trader).Assuming, as before, that the trader sells 1 ETH, the transaction cost of a sale of 1 ETH by the trader is τ × 1 = .0025ETH.This leaves (1 − τ ) × 1 = .9975ETH available for the trade.To save on notation, let (1 − τ ) = φ .There are two stages to the process now: in the first stage, the fee is deducted, and the trade is enforced using the initial invariant k 0 .In the second stage, the fees are added to the liquidity pool, which gives rise to a new invariant, k 1 .This ensures that the value of k changes with every trade; so, the term 'constant' or 'invari- ant' is somewhat misleading when there are trading fees-it is more of a predetermined variable prior to a trade.In the first stage, which we can think of as the interim trading stage, the amount of ETH in the pool is x 1′ = 10.9975ETH (where the superscript ′ denotes interim).Given k 0 = 5000 , the new amount of ABC balance in the pool is y 1 = k 0 x 1 ′ = 454.6488, implying a change y 1 − y 0 = −45.3512ABC.The trader effectively receives the bid price of p b Y /X = 45.3512ABC/ETH.In terms of notation, the lower-case p indicates that the price now refers to a scenario where a trading fee has been imposed.In the second stage of the trade, the fees are added to the liquidity pool, giving a final ETH pool balance of x 1 = 11 .The new value of k at the end of the trade is k 1 = x 1 y 1 = 5001.1368, which is higher than before and is a predetermined variable for the next trade on the AMM.
Comparing the case with trading fees to the case without, we can see that the bid price of ETH is lower than before ( p b Y /X < P b Y /X ), and the trader receives less ABC per ETH than when there are no transaction costs.Secondly, the change in k is k 1 − k 0 = 1.1368 .Greater the number of transactions on Unsiwap-v1 or v2, more rapid is the expansion of k , even if liquidity providers add no further tokens to the pool themselves.Now suppose the trader were to buy one unit of ETH, which would leave 9 ETH in the pool.The fee here is charged for the volume of ABC traded for 1 ETH.So, if the trader deposits an amount y ABC, after the fees are deducted the trader adds an interim (Stage 1) amount of φ�y ABC to the pool.It follows that �y = 1 φ k 0 x 1 − y 0 = 55.6948 .The ask price has now increased with the introduction of the transaction fee ( p a Y /X > P a Y /X ).Moreover, the bid-ask spread is p a Y /X − p b Y /X = 10.3436 , which is larger than the case with no trading fees, because the bid rate is lower and the ask rate is higher.This is intuitively the reason why there are lower arbitrage opportunities available in the presence of higher transaction costs.
We can now ask, once again, what happens if a smaller ETH amount, say 0.01 ETH, is traded.Replicating the procedure, we find that p b Y /X = 48.7025, while p a Y /X = 50.1755, so p a Y /X − p b Y /X = 1.473 .While this is smaller than the spread when 1 ETH was traded, it is still fairly significant.In fact, we show analytically in the section "The geometry of a CPMM" that for infinitesimal changes, p b Y /X = 49.875 and p a Y /X = 50.1253, which implies p a Y /X − p b Y /X = 0.2503 is the minimum spread achievable in this example with a fee of 0.25%.This wedge between the two prices cannot reduce to zero-we need to work with bid and ask rates even with infinitesimal changes.
Finally, since the sale (purchase) of one token by a trader goes hand-in-hand with the purchase (sale) of the other token, Eq. (2) needs to be modified to:

Arbitrage using AMMs
In this section, we consider two different ways in which an AMM can be used for arbitrage: two-point arbitrage and three-point arbitrage.The arbitrage terminology we employ here is consistent with standard usage in the finance and foreign exchange market literatures. 22

Two-point arbitrage
Two-point arbitrage or locational arbitrage is triggered due to a difference in prices across different markets (or exchanges or platforms, as the case may be) for the same asset.Consider a situation where there exists another (possibly centralized) exchange, which is the external reference market.An agent seeks to exchange between Y (ABC) and X (ETH).Two-point arbitrage refers to the fact that a token bought in one mar- ket can be sold in the other in order to realize risk-free profits.Doing so is profitable (subject to transaction costs) if there is a mismatch in the prices quoted in the two markets.However, as agents take advantage of arbitrage opportunities and transact in the two markets, the demand and supply forces they set into motion eventually cause these opportunities to disappear.An equilibrium occurs when there are no arbitrage opportunities left, and the equilibrium no-arbitrage condition essentially involves no mismatch in prices between the two markets.Arbitrage is, in general, a powerful pricing tool: first, it is attractive because it results in risk-free profits, so we can be sure agents will jump to take advantage of arbitrage opportunities when they arise; second, the process of arbitrage conveniently eliminates these opportunities eventually, so we can be confident that, all else being the same, markets will gravitate towards an equilibrium where prices equalize (to the extent permitted by transaction costs).
To examine two-point arbitrage in more detail, let the price of one unit of X in terms of Y in the external market be M Y /X .The upper-case M denotes a situation where there are no trading fees for transacting in the external market.This is altered readily enough by considering bid and ask rates in the external market: m b Y /X and m a Y /X .We could make the story even more realistic by adding other transaction costs (such as gas fees).In reality, all such costs must be accounted for.However, for the task at hand of understanding the mechanics of how arbitrage works, we can ignore transaction costs other than the AMM trading fees, with the caveat that they must be factored in when actually trading.
To begin with, consider the case when there are no trading fees on the AMM and infinitesimal trade volumes are possible.Suppose that M Y /X = 49.9 in the exter- nal market, while P Y /X = 50.0 in the AMM.An arbitrageur could buy X in the exter- nal market for 49.9 and sell it in the AMM for 50.0 Y , thereby making a profit of P Y /X − M Y /X = 50.0− 49.9 = 0.1 units of Y per unit of X .However, as arbitrageurs 22 Two-point and three-point arbitrage in the context of foreign exchange markets are covered in most undergraduate texts in international finance; see, for example, Moosa (2010).Our discussion draws on these insights, along with simple ways to visualize the arbitrage process, such as Fig. 2.
do this, the increased demand for X in the external market will increase M Y /X , and the increased sale of X in the AMM will reduce P Y /X till the arbitrage profits are wiped away. 23The prices in the two markets are brought into alignment due to the actions of arbitrageurs, and prices in the AMM cannot diverge randomly for any significant period of time.The equilibrium no-arbitrage condition satisfies: Similarly, in instances where P Y /X < M Y /X we would expect arbitrage to occur in the opposite direction.Demand-supply forces would then result in Eq. ( 4) holding at equilibrium.Now, suppose there is a trading fee of τ = 0.25% on AMM which, as we have seen earlier, results in p b Y /X = 49.875 and p a Y /X = 50.125 .With M Y /X = 49.9 , arbitrage is no longer feasible: buying ETH in the external market and selling in the AMM involves a loss of 0.025 ABC, and going in the reverse direction yields a loss of 0.225 ABC.Thus, the no-arbitrage condition in Eq. ( 4) is transformed to: In the range prescribed by Eq. ( 5), arbitrage between the external market and the AMM is not profitable.If M Y /X moves outside this range, arbitrage is triggered which will result in demand-supply changes that bring the rates into alignment, so that Eq. ( 5) holds again.
Two observations are worth noting about the arbitrage process described here.First, the numbers we have used for p b Y /X and p a Y /X are taken from example in the section "Examples and some basic pricing equations" with infinitesimal trade volume.However, moving to discrete changes only serves to widen the spread p a Y /X − p b Y /X , which extends the range in Eq. ( 5) for which arbitrage is not profitable.A similar widening of the spread occurs when τ rises, so that increased trading fees (and transaction costs in general) also reduce arbitrage opportunities.Second, if one incorporates bid and offer rates in the external market, m b Y /X and m a Y /X , the equilibrium no-arbitrage condition in Eq. ( 5) will have to factor this in; specifically:

Three-point (or triangular) arbitrage
Two-point arbitrage exploits differences in prices across markets and, as the name suggests, requires two price quotes-one from each market-for arbitrage possibilities to emerge.In contrast, three-point arbitrage (or triangular arbitrage) focuses on the internal consistency in the prices offered within a single market and requires three price quotes for its implementation.Although three-point arbitrage can also be performed across markets, it is not necessary-a price misalignment in a single market can trigger three-point arbitrage opportunities.We will see that as agents take advantage of (4) three-point arbitrage within a single AMM, the changing forces of demand and supply ensure that prices in different liquidity pools in the AMM are ultimately aligned in a logically consistent way.Suppose there are three tokens, X , Y and Z , that are offered for trade and that a trader can swap between any pair.The question is: can the trader start off with 1 unit of any arbitrary token (say Z ) and cycle through the tokens by, for example, selling Z for X , then selling the X proceeds for Y before converting back to Z in order to end up (magically) with more than 1 unit of Z ?In terms of notation, we use the symbols Z → X → Y → Z to describe this sequence of conversions.However, this is not the only sequence that is feasible: the trader could also perform the sequence Z → Y → X → Z .In either one of these cases, if the trader starts with 1 unit of Z at the beginning of the cycle in order to end up with more than 1 unit of Z at the end of the cycle, the possibility of three-point arbitrage exists.Moreover, the choice of Z as the starting token is arbitrary: a trader could realize arbitrage profits by cycling through starting with X or Y .As Fig. 2 shows, all these possibilities can be visualized using a triangle (hence the name triangular arbitrage), with the three tokens located on the three vertices, and a specific cycle forming a path along the sides starting and ending with a given vertex.The arrows in Fig. 2 depending on which vertex forms the starting point.The opposite cycles can be visualized by reversing the direction of the arrows.
Uniswap runs on the Ethereum network and ETH ( X ) is the native settlement token.However, there are a number of ERC-20 tokens that can be traded on the network, and one can swap between any two ERC-20 tokens Y and Z on Uniswap.How exactly this exchange is facilitated varies between v1 and v2 of Uniswap.In Uniswap-v1, the platform performs an exchange between Y and Z by implicitly using ETH as a via medium.Uniswap achieves this by maintaining a separate smart contract for the exchange of each ERC-20 token with ETH.Uniswap-v1 does not incorporate the possibility of a smart contract for direct conversions between Y and Z .This feature changes in Uniswap-v2, where a distinct smart contract can be created for direct exchanges between ERC-20 tokens.Adams et al (2020) recognize the added complexity of this change,24 without explicitly outlining the new possibilities for arbitrage this generates.Much of the focus of this section, then, is to outline how Uniswap-v2 creates the possibility of three-point arbitrage that is absent in v1.
More generally, we explore the outcomes under two types of CPMMs: CPMM-v1 that uses a token X as an intermediary in the exchange between and Y and Z ; and CPMM-v2 that allows for a smart contract as a Y − Z liquidity pool.Consider CPMM-v1 to begin with.If a trader wishes to sell Z and purchase Y , the AMM will proceed by converting Z to X (ETH) and then by converting the proceeds to Y , which are added to the trad- er's account.Suppose that there are no trading fees ( τ = 0 ).If the trader sells 1 unit of token Z , P X/Z determines how many units of X the AMM delivers in exchange using the X − Z liquidity pool.The P X/Z units of X can then be converted to Y at the price P Y /X , yielding the trader P Y /X × P X/Z units of Y .Consequently, the price offered by CPMM- v1 for converting 1 unit of Z to Y , P Y /Z , is: To borrow some terminology from the foreign exchange rate literature, P Y /Z is the cross-rate (or cross-price) that can be derived from the other two prices ( P Y /X and P X/Z ).In CPMM-v1, there are two prices, P Y /X and P X/Z , that are determined in the two liquid- ity pools that are available, the X − Y pool and the X − Z pool.The third price, P Y /Z , is derived from the other two (using Eq. 7).Now, in CPMM-v2, a third market price exists due to the creation of a direct Y − Z liquidity pool.The three liquidity pools (the X − Y , X − Z and Y − Z pools) can move independently due to trader activities.Intuitively, we can see from Fig. 2 that the presence of a third liquidity pool creates an independent price to connect the vertices Y and Z.
When Eq. ( 7) holds, three-point arbitrage is not feasible; it is, therefore, a no-arbitrage condition.To see this, consider CPMM-v2 with X − Y , X − Z and Y − Z liquidity pools, along with prices ( P Y /X , P X/Z and P Y /Z ).Let us further posit that these three pools yield the relationship P Y /Z < P Y /X × P X/Z , which violates Eq. ( 7).A trader could then per- form the sequence Z → X → Y → Z to make a risk-free profit.25 Starting off with 1 unit of Z , this sequence of conversions yields P Z/Y × P Y /X × P X/Z units of Z at the end of the cycle.As P Z/Y = 1 P Y /Z (Eq. 2),we can rewrite the expression and, given the assumption that P Y /Z < P Y /X × P X/Z , it follows that As enough traders do this, relative prices will change until the arbitrage opportunity is wiped out, which occurs when P Y /Z = P Y /X × P X/Z (in other words, P Z/Y × P Y /X × P X/Z = 1 ) and the inequality no longer holds.A simple demand- supply argument suffices to verify this.In the first step of the arbitrage sequence (7) the trader sells Z in exchange for X , which decreases P X/Z .In the next step, the trader sells X in exchange for Y , which reduces P Y /X .In the last step, the trader sells Y in exchange for Z , which reduces P Z/Y .So, starting with the inequality P Y /Z < P Y /X × P X/Z , the arbitrage process increases the term on the left-hand side of the inequality and reduces the terms on the right; the process stops only when equality is restored and Eq. ( 7) holds, thereby making it a no-arbitrage condition.
In CPMM-v1, Eq. ( 7) always holds by construction, so one can think of this being an identity in this type of AMM.On the other hand, in CPMM-v2, Eq. ( 7) holds as an equilibrium condition after arbitrage opportunities have been eliminated.To put this slightly differently, there exists only one price for exchanging between Y and Z a trader can obtain in CPMM-v1, which is automatically determined by the AMM using Eq. ( 7).In CPMM-v2, there are two prices that are available to a trader: P Y /Z , that comes about by trading in the Y − Z pool, and P Y /X × P X/Z , that can be obtained by performing the sequence Z → X → Y ; the two are necessarily equal only at equilibrium.If there is disequilibrium, the trader can make arbitrage profits by buying through the method that is cheaper and selling through other method.Thus, when P Y /Z < P Y /X × P X/Z , the trader can buy Z through the Y − Z pool and sell it through the sequence Z → X → Y to make a profit.
Adding a fee, τ , does not alter the fundamental nature of the process; it does make the calculations more cumbersome though.To see the implications of this, consider CPMM-v2.The Y − Z pool has a bid-ask spread p a Y /Z − p b Y /Z , and the trader can directly buy Z at the ask-price and sell it at the bid-price.However, the trader also has the alternative option of performing the sequence Z → X → Y to sell Z and buy Y , and the sequence Y → X → Z to sell Y and buy Z .This alternative method requires two trading fees.For the sequence Z → X → Y , for example, there exists a fee for each step Z → X and X → Y ; consequently, the trader sells Z at price p b X/Z , and then sells the X proceeds at p b Y /X .This implies that the exchange rate associated with the sequence Similarly, the rate associated with the sequence Y → X → Z is p a Y /X × p a X/Z .This yields no-arbitrage conditions: Equation ( 8) essentially states that it is never profitable to buy Z through one method available to the trader and sell it through the other. 27

Liquidity provision and fees in a CPMM: Uniswap-v1 and v2
Any liquidity provider on Uniswap-v1 and v2 simultaneously adds both tokens in a liquidity pool.This is a desirable feature which ensures that prices do not fluctuate due to liquidity provision.Suppose the price of X in terms of Y (when τ = 0 ) is P Y /X = y x .Consider a situation where an agent wished to add liquidity to the X − Y pool, and did 27 If the trader wishes to buy Z using the Y − Z pool, the trader incurs a price of p a Y/Z ; if the trader the sells the proceeds using the sequence Z → X → Y , the trader receives p b Y/X × p b X /Z .When p a y/z ≥ p b y/x × p b x/z holds, this strategy is not profitable.Similarly, if the trader buys Z using the sequence Y → X → Z the effective price is p a Y/X × p a X /Z .When p a Y/X ×p a X /Z ≥ p b Y/Z holds, selling the proceeds in the Y − Z pool is unprofitable.Equation ( 8), therefore, describes the equilibrium no-arbitrage condition in CPMM-v2.No such arbitrage opportunities can exist in CPMM-v1, since the trader has only the bid-ask spread p a Y/X ×p a X /Z − p b Y/X × p b X /Z to work with.
so by only adding a certain amount of X , equal to x .This would result in a price of Adding a significant amount of X to the pool by liquidity providers, then, would depress the price of X , which is undesirable; ideally, we would like the price to change because of trading activity and not due to the act of providing liquidity.To prevent a price change from occurring, we would require y y is the amount of Y that needs to be added to make this condition hold, some alge- braic manipulation then yields the fact that we would need y x = y x ; that is, the two tokens have to be added in the same proportion as the existing reserves so as to not cause a price change. 28For infinitesimally small changes, this can be rewritten as differentials, dy y = dx x .Liquidity providers are entitled to the fees that are paid by traders on Uniswap, in proportion to the amount a liquidity provider has contributed.To facilitate this, and the process of adding and removing liquidity, Uniswap-v1 and v2 mints and distributes liquidity tokens, with a specific token issued to each liquidity pool.These tokens are themselves tradeable as fungible ERC-20 tokens.

Preliminaries: homogenous and homothetic functions
The function xy = k used in a CPMM is an example of a class of functions referred to as homogenous functions, which we define formally below.
Homogenous functions A function f (x 1 , x 2 , . . ., x n ) is defined to be homogenous of degree r when the following condition is satisfied: Essentially, this states that if all the independent variables (x 1 , x 2 , . . ., x n ) are mul- tiplied by some factor , the value of the function is multiplied by r .The CPMM function xy is a simplified version of this, with two independent variables.Utilizing Definition 1, it is evident that this function is homogenous of degree 2: if xy = k , then ( x) y = 2 xy = 2 k .So, for instance, if one were to double both x and y , k would quadruple.
A homogenous function k = f (x 1 , x 2 , . . ., x n ) can be used in different contexts to characterize different things.In consumer theory it describes, for example, the utility function: the level of utility ( k ) derived from the consumption of certain quantities of commodities (x 1 , x 2 , . . ., x n ) .In production theory it describes the production func- tion: the quantity of good or service ( k ) produced by a firm from a certain combina- tion of factor inputs (x 1 , x 2 , . . ., x n ) .In the current context of an AMM, we think of it as an exchange function that links various amounts of tokens (x 1 , x 2 , . . ., x n ) to the AMM's invariant, k.
Geometrically, the exchange function xy = k generates level or contour curves that are rectangular hyperbolas in a two-dimensional graph, as shown in Fig. 3.A level curve shows, in the x − y plane, various combinations of x and y that yield a specific value of 3 depicts two level curves; the first shows all the combinations of x and y that yield a specific value of k 0 ; the second shows all combinations of x and y that yield k 1 .Since k can take any value (greater than zero), there are an infinite such level curves that can be drawn, each corresponding to a particular value of k.29 Subsequently, in the sec- tion "Measuring liquidity in a CPMM", we will argue that the level curves of the exchange function can best be thought of as 'isoliquidity' curves.
In general, suppose we allow x and y to change.Taking the total derivative of xy = k , we get that ydx + xdy = dk .Along any particular level curve, however, dk = 0 , and so: The intuition behind Eq. ( 9) is as follows.Suppose we consider a particular point, say point A in Fig. 3, which has pool reserves of x A and y A .Starting from point A , if x changes infinitesimally, y has to change by a certain amount so that xy = k 0 continues to hold and we remain on the level curve.The left-hand side of Eq. ( 9) is the slope of the curve at A , which corresponds to the slope of the tangent aa in Fig. 3.This slope is nega- tive due the fact that if x increases, y must decrease in order for the value of k not to change.The right-hand side of Eq. ( 9) is the slope of the ray OA connecting A to the ori- gin O .So, Eq. ( 9) states that if x and y change along curve k 0 , the slope of the tangent at A equals the negative of the slope of the ray OA ; that is: x B holds and the absolute value of the slope is lower at point B compared to A.
(9) dy dx = − y x Fig. 3 The xy = k function One of the features of a homogenous function is that the slope remains unchanged as we move from one level curve to another along a given ray.While we do not provide a formal proof of this here for a general homogenous function, it can be shown for our context in a straightforward manner using Fig. 3. 30 Specifically, since points A and C both lie on the ray OR , the slope of OA is equal to the slope of OC ; that is, y A x A = y C x C .From Eq. ( 9) it then follows that dy (slope of aa equals cc ).In fact, this property of slopes of level curves being invariant along a ray from the origin is termed homotheticity and is true of a broader class of functions: homothetic functions.
Homothetic functions Here h ′ (k) is the derivative with respect to k .A homothetic function is a monotonic transformation of a homogenous function.While the transformation can, in general, be positive or negative, it is often useful to focus on the positive transformation where h ′ (k) > 0 , because this has the desirable property that a higher k is associated with a higher H. Though a homothetic function transforms a homogenous function, it is itself not necessarily homogenous.The classic example of this is a log transformation.If we start with k = xy (which is homogeneous of degree 2), H(x, y) = log(k) = log(xy) is a homothetic function since dlogk dk > 0 .However, H is not a homogenous function, because log( x × y) � = 2 log(xy) .Nevertheless, H inherits the homotheticity property.This is because at any arbitrary point the level curves of H(•) function have exactly the same slope as the corresponding level curve of f (•) through that point.For example, consider the two-independent variable case, where k = f (x, y) is homogenous of degree r , and H (x, y) = h(k) = h(f x, y ) .The slope of the level curve of H(•) at any point is ∂H /∂y , while the slope of the level curve of the f (•) function through that point is dy dx f = − ∂f /∂x ∂f /∂y .To show that the slopes of the two level curves are the same: The homotheticity property is useful because it tells us what happens to level curves if we start with a CPMM with an exchange function xy = k and transform it monotonically.
Another handy property of homogenous functions is Euler's theorem, which we will find useful in the next section for valuing a liquidity pool 31 : Euler's Theorem Suppose f (x 1 , x 2 , . . ., x n ) is a homogenous function of degree r .Then: (10) The proof is standard in any text on introductory mathematical economics (for example, Silberberg 1990). 31The interested reader is referred to Silberberg (1990) or Chiang (1984) for a proof.

Arbitrage and price determination in a CPMM
We are now in a position to provide a simple graphical representation of much our discussion on arbitrage and price determination.To do this, we can contextualize Fig. 3 as the exchange function of a CPMM.As before, we begin with the situation where τ = 0.The price of X in terms of Y is P Y /X ; graphically, for infinitesimal changes, this trans- lates to the absolute value of the slope ( − dy dx ).For any combination of reserves (x, y) , Eq. ( 9) indicates that P Y /X = − dy dx = y x , which is essentially Eq. ( 1).So, consider point A in Fig. 3 with pool reserves (x A , y A ) .P Y /X offered by the CPMM can be read off the dia- gram in one of two equivalent ways: either as the absolute value of the slope of the tangent aa at A ( − dy dx A ), or as the slope of the ray OA ( y A x A ).Our view here is that an AMM is a black-box for converting inputs (token quantities) into outputs (prices).The equation P Y /X = y x links the inputs in our black-box ( x and y ) to the output ( P Y /X ) using the exchange function k = xy .Graphically, the output of the AMM is the slope of a level curve of the exchange function.
There are a couple of other issues about price determination in a CPMM that are worth noting.First, the exchange function k = xy is homogenous and the slopes of level curves are the same along a ray from the origin.Since P Y /X is the absolute value of the slope, it follows that all points (reserve pairs) on a specific ray from the origin will entail the same price.Thus, returning to Fig. 3, P Y /X is exactly the same at points A (where k = k 0 ) and C (where k = k 1 ), and indeed at every point along the ray OR , each of which falls on a different level curve.Secondly, when the amount of a token, say X , approaches zero, the token's price tends to infinity.Consequently, the reserves of a token can never fall to zero due to trading activity as the level curves never intersect the axes. 32ext, we can see the price slippage that occurs with larger size transactions in Fig. 3.At point C , the slope of the tangent cc determines P Y /X when an infinitesimal amount X is traded.For a larger trade that moves the CPMM from C to D , the price is given by the absolute value of slope of the line CD , which is larger than that of tangent cc .Similarly, when X is sold by the trader, the absolute value slope of the slope of CE is less than that of cc .It is readily visualized that larger the transaction size, greater is the slippage that occurs.
Figure 3 also describes what happens if liquidity providers were to add tokens to the pool.Starting from reserves (x A , y A ) , suppose liquidity providers add reserves in the same proportion as the initial reserves, so that y x = y A x A .Adding liquidity in the same proportion implies that new reserves (x C , y C ) satisfy y C x C = y A x A ; in other words, we move along ray OR , and prices are the same at the two points.Liquidity provision conducted in this manner changes the level curve from k 0 to k 1 without changing the price.
Consider now the process of two-point arbitrage, which is described in Fig. 4. Suppose the price of X in the external reference market is M Y /X , where M Y /X > P Y /X .This exter- nal market price is shown in Fig. 4  external market.The buying activity in the CPMM increases P Y /X (while the selling in the external market can decrease M Y /X ), and the price in the CPMM will approach M , as shown by the arrow in Fig. 4.This process continues till the no-arbitrage condition in Eq. ( 4) is met and M Y /X = P Y /X , which can occur anywhere between points A and M .When the external market is relatively large, the sale of X in the external market may have little impact on M Y /X ; in that case, P Y /X will settle at point M , with reserves (x M , y M ) .It is straightforward to construct the reverse argument if M Y /X < P Y /X and the starting point is point B.
Now suppose there is a trading fee, τ .To examine this, we summarize the analytical procedure described in Angeris et al. (2019) for deriving the bounds of arbitrage.Suppose we start with reserves (x 0 , y 0 ) , and k 0 = x 0 y 0 .In the absence of trading fees, the price would be P Y /X = y 0 x 0 , irrespective of whether a trader wished to buy or sell X .The two-step process followed by Uniswap for price changes with a fee is described in detail in the section "Examples and some basic pricing equations"; we replicate that process analytically, assuming that it holds for any arbitrary CPMM. 33o begin with, assume that a trader wishes to sell X to the CPMM in exchange for Y .If the trader sells an amount x , the AMM retains τ �x , and the remainder (1 − τ )�x = φ�x is available for the trade, which occurs utilizing the initial value of the constant, k 0 .If the trader receives y in return, we get: (11) x 0 + φ�x y 0 + �y = k 0 Fig. 4 Price and arbitrage in a CPMM with no transaction fees Since the liquidity pool receives X , we have that �x > 0 , from which it follows that �y < 0 .Simplifying, we get that �y �x = − φy 0 x 0 +φ�x .When changes are infinitesimal, this reduces to dy dx = lim �x→0 �y �x = −φ y 0 x 0 .As p b Y /X = − dy dx in this case, we get the bid-price as: Similar arguments when the trader buys X from the CPMM ( �y > 0 ) yields an ask- price of: , where P Y /X = y 0 x 0 .Figure 5 shows the bid and offer rate graphically.The reserves are depicted by point P , and the slope of ray OP is y 0 x 0 = P X/Y .This point lies on the level curve k 0 .The slope of the ray OB is φ y 0 x 0 = p b Y /X ; we can visually associate point B , therefore, with the bid-price.Similarly, the slope of OA is 1 φ y 0 x 0 = p a Y /X , and point A is associated with the ask-price.To bring in the idea of arbitrage in Fig. 5, suppose the external market price is M Y /X .This is represented by a point M , which (uniquely on curve k 0 ) satisfies the condition that the slope of OM = M Y /X .In this particular instance, M lies within the arc AB .As the slope of OM is greater than that of OB , but less than that of OA , we have that p b Y /X ≤ M Y /X ≤ p a Y /X holds at point M .This is, of course, nothing but the no-arbitrage condition in Eq. ( 5).This inequality is true for any point we select in the arc AB ; thus, this arc corresponds to Eq. ( 5) as the range where arbitrage is not feasible.It is evident that the range widens (and the arc AB becomes longer) the greater the value τ takes, since p b Y /X = φ y 0 x 0 and p a Y /X = 1 φ y 0 x 0 .This goes back to the point made earlier: larger transaction costs curtail arbitrage.If we consider a point outside arc AB , such as point M ′ , where p b Y /X > M Y /X , then arbitrageurs can buy X in the external market and sell it in the CPMM to make profits.This sale of X to the CPMM will drive point P to the right, and the arc AB along with it, till p b Y /X = M Y /X .Similar arguments in the reverse direction hold if M Y /X is repre- sented by M ′′ .The second step of the exchange process in Uniswap-v1 and v2 is that the fees are added to generate a new value of k that satisfies k 1 = x 0 + x y 0 + y = x 1 y 1 .In the case where X is sold to the CPMM, for example, τ �x is added to the pool reserves, which causes a rightward shift of the level curve to k 1 .The starting point for the next trade is then a reserve pair (x 1 , y 1 ) on k 1 , which has a no-trading fee price of P Y /X = y 1 x 1 and a corresponding bid-ask spread as derived earlier.

Valuing a liquidity pool and a CPMM: Uniswap-v1 and v2
Consider a specific liquidity pool with tokens X and Y in CPMM-v1 or v2.There are cir- cumstances where one may wish to value the liquidity pool.Since x and y are different tokens, they have to be brought to the same unit of account before their values can be added.Let us suppose that X (ETH) is the unit of account in the X − Y pool.One way to value the liquidity pool is then V X,Y = x + P X/Y y. 34 This converts Y to an equivalent amount of X using P X/Y = x y .Substituting P X/Y = x y , it follows that: Equation ( 14) states that in order to value a liquidity pool that has ETH in it, one simply needs to double the amount of ETH in the pool.An implication of Eq. ( 14) is that the valuation of a pool is independent of the price P X/Y at which X and Y trade and, indeed, independent of the value of k .This is shown in Fig. 6.All three points, A , B and C have a valuation of 2 x 0 , even though they lie on different level curves and are associated with different prices.On the other hand, even though C , D and E have the same prices (they are on the same ray from the origin), the liquidity pool has different valuations at these points, with the valuation at C being the highest as it has the highest amount of X.
This is, of course, not a unique way of valuing the pool.With trading fees and a bid-ask spread one may wish to use the mid-rate pX/Y = x y (from Eqs. ( 12), ( 13) and ( 3)) to value the pool.However, the mid-rate is a function of φ , which implies that the pool valuation using pX/Y to convert units of Y to X would be sensitive to the fees.Whether this is desirable or not depends on the context.The pool valuation in this case is: In the extreme case where there are no trading fees, φ = 1 and it is evident that ṼX,Y = V X,Y .Moreover, as d dφ (1+φ) 2 2φ < 0 , ṼX,Y falls as φ rises.This implies that as fees fall, the pool valuation decreases as well.This makes intuitive sense if one were to value 34 See also Angeris et al (2019) and Angeris and Chitra (2020), who address the issue of pool valuation.
the pool from the perspective of liquidity providers.Lower fees signal lower returns to pool providers, and ṼX,Y is lower as well.Thus, whether one wishes to use ( 14) or ( 15) depends on the perspective one takes.The valuation V X,Y is preferable if one looks at the liquidity pool as a whole.On the other hand, if the focus is on liquidity providers, then ṼX,Y is a candidate for pool valuation.
One can generalize Eq. ( 14) to a broader class of functions where k = f x, y = x α y β , with α, β > 0 .The k = xy function is simply a special case of this where α = β = 1 .Using Euler's theorem from the section "Preliminaries: homogenous and homothetic functions" for this case, we have that: Since ∂f /∂y ∂f /∂x = − dx dy , it follows that P X/Y = ∂f /∂y ∂f /∂x . 35The left-hand side of Eq. ( 16) is, therefore, nothing but V X,Y .For the right-hand side, using f (x, y) = x α y β , ∂f ∂x = αx α−1 y β , and r = (α + β) , Eq. ( 16) reduces to: Comparing Eq. ( 17) with Eq. ( 14), we see that the former collapses to the latter whenever α = β .So, doubling the amount of X(ETH) in a liquidity pool to value a liquidity pool is a valid technique for all AMMs that attach equal weights to X and Y in the k = x α y β function, and is not limited to the specific exchange function used by Uniswap.For this general class of exchange functions, even when α = β , the pool valuation depends only on x and some constant factor α+β α . 36It is also worth noting that the share of value of X to the value of the pool is x/V X,Y , which equals α α+β and is fixed once the parameters α and β are fixed. 37Similarly, the share of Y is P X/Y y/V X,Y = β α+β .When α = β , each token's share of the total pool value is ½.Now suppose we would like to value an entire CPMM operating with an exchange function k = xy across all liquidity pools that exist on the platform.In a CPMM-v1, as outlined earlier, all liquidity pools have ETH as a common token.If there are n liquid- ity pools, each of which has X as a token along with another token, Y i , i ∈ {1, 2, 3, . . .n} .The n liquidity pools yield a set of reserves: { x 1 , y 1 , x 1 , y 1 . . .x n , y n } , where x i is the amount of X (ETH) in the liquidity pool with token Y i .From Eq. ( 14), each liquidity pool has a valuation V X,Y i = 2x i , ∀i ∈ {1, 2, 3, . . .n} .This allows a simple method to value the entire CPMM-v1: Equation ( 18) states that to value a CPMM-v1 with the exchange function k = xy , one needs to simply add all the ETH across the various liquidity pools on the platform and double it.
Valuing CPMM-v2 is slightly more complicated, because there are liquidity pools available that do not involve ETH.So apart from the n original liquidity pools with reserves { x 1 , y 1 , x 1 , y 1 . . .x n , y n } that were available in CPMM-v1, CPMM-v2 allows for an additional n(n−1) 2 liquidity pools between tokens Y i and Y j , ∀i, j ∈ {1, 2, . . .n}, i � = j .In terms of notation, let y ij denote the quantity of Y i in a Y i − Y j liquidity pool.To value a liquidity pool with Y i and Y j , we would first need to pick a pric- ing token (say Y i ); it follows from a parallel to Eq. ( 14) that V Y i ,Y j = 2y ij .However, this is denominated in units of token Y i ; to convert this to units of X (ETH), so that there exists a common unit of account to value different pools, we can use the price P X/Y i = x i y i generated by the reserves x i , y i in the X − Y i liquidity pool.Thus, we get y i y ij , which is denominated in X. Suppose we use an indicator d ij = 1 if Y i is used as the pricing token in the pool with Y j and d ij = 0 if it is not.The value of all pools Y i − Y j that uses Y i as the pricing currency, but denominated in units of X is x. 37 Later on, in the secion "Constant Mean Market Makers (CMMM)", we show that other types of AMMs, such as a Constant Mean Market Maker, also have a similar property of fixed shares of value.
The second term in Eq. ( 19) corresponds to Eq. ( 18), and refers to the value of all pools that involve X .The first term adds the values of all Y i − Y j pools after denominating them in X.

Interpreting k
How exactly is one to interpret the economic meaning of k in the exchange function k = f (x 1 , x 2 , . . ., x n ) ?In consumer theory, k is interpreted as the level of utility, while in production theory, it is the quantity of goods and services produced.In an AMM, the 'output' is the price of one token in terms of the other, which is slope of the level curves of f (.) ; this corresponds to the marginal rate of substitution in consumer theory and to the marginal rate of technical substitution in production theory.There is no direct economic significance of k that is apparent when calculating these slopes in the context of AMMs. 38eometrically, we can associate a value of k with a level curve generated by the exchange function, as we have done in Fig. 3.This affords the most satisfactory interpretation that one can ascribe to k-as an ordinal measure of liquidity, in much the same way as utility serves as an ordinal measure of satisfaction in consumer theory.Viewed in this way, we can think of the level curves of the exchange function as 'isoliquidity' curves.
Thus, if k 1 > k 0 in a given liquidity pool, it is intuitive to infer that the liquidity level at k 1 is higher than the liquidity level at k 0 because, starting at any point on k 0 , the injec- tion of tokens by liquidity providers will move the reserves to a higher level curve like k 1 .This provides a valid way of comparing the liquidity levels provided by any two arbitrary reserve token pairs (x 0 , y 0 ) and (x 1 , y 1 ) in a liquidity pool even if, say, x 0 < x 1 but y 0 > y 1 ; (x 1 , y 1 ) can be said to provide a higher level of liquidity if The nature of the concept of liquidity as defined here suggests that inter-pool comparisons of k are meaningless.So, if we have two liquidity pools with different tokens and calculate that x 1 y 1 = k 1 > k 0 = x 0 z 0 , we cannot conclude that the X − Z pool has a lower level of liquidity than the X − Y pool.Essentially, the numbers k 1 and k 0 are not comparable in this instance because their units of measurement are different.

Liquidity in a CPMM
While the parameter k is a measure of liquidity in a pool, it has a few problems, arising from the fact the function k = xy is homogeneous of degree two.To see the implica- tions of this, suppose one liquidity provider doubles the amount of tokens in the pool.The new value of the invariant is 4xy = 4k ; in other words, the invariant has quadru- pled even though 'liquidity' has, for all practical purposes, only doubled due to the doubling of token volume.This is particularly problematic in CPMM-v1 and CPMM-v2, where fungible ERC-20 liquidity tokens are issued.If these tokens are issued one-to-one with the value of k , by doubling the tokens the liquidity provider in this example would 38 Alternatively, in the case where, k = xy , as in Fig. 3, we can think of k geometrically as the area of the rectangle asso- ciated with a point; thus at point A in Fig. 3, we have that Area Ox A Ay A = k 0 .However, the dimension of the area is units of X × units of Y, which has little economic meaning as well.
have received 75% of the liquidity tokens in circulation, even though the provider has accounted for only half the tokens.
To quantify liquidity in general, and to keep track of liquidity tokens in particular, a better measure would involve using a function that is homogenous of degree 1.To that end, suppose we define . Now, if a liquidity provider, for example, doubles both tokens, the value of L also doubles.Indeed, we can generalize the benefits of utilizing L to measure liquidity even for small additions to the liquidity pool.As shown in the section "Liquidity provision and fees in a CPMM: Uniswap-v1 and v2", in order for liquidity provision not to change price in CPMM-v1 and v2, the condition dy y = dx x holds.It is readily seen that dL L = dx x also holds, 39 implying that the percentage change in L equals the percentage change in either token.If X is ETH, then CPMM-v1 and v2 can distribute new liquidity tokens based on changes in L ; specifically, dL = dx x × L (or its discrete counterpart, L = x x × L ).Consequently, L serves as a better measure of liquidity in CPMMs.

Competing interests in an AMM and the efficiency-liquidity provision trade-off
Liquidity providers act as the counterparty to all trading activity on an AMM.In this section we explore a number of issues related to liquidity provision and the conflicts of interests that can arise in this context.In order to do so, we keep track of four types of agents who participate in an AMM: liquidity providers, traders interested in swapping assets, arbitrageurs, and attackers who exploit the system.While we approach this in the context of a CPMM, the general principles hold for other types of AMMs, even if specifics may vary.
Consider traders to begin with.Liquidity providers earn returns as fees from transactions with traders, even if there were no movements in the external market price.Clearly, traders would prefer the trading fee to be as little as possible.From the point of view of liquidity providers, a higher fee yields higher returns per trade, but discourages trading activity.To characterize this trade-off in a simple manner, suppose v(τ ) is the (average) value of tokens transacted by traders on the AMM (denominated in a numeraire, say X ) over a given period of time, where τ is the ad valorem fee.Since higher fees reduce trad- ing activity, it is reasonable to suppose that dv dτ < 0 .Assuming liquidity provision costs are normalized to zero, the profits that liquidity providers get from traders is τ v(τ ) .To maximize this, liquidity providers would set the optimum fee, τ * , which satisfies the first order condition τ * dv(τ * ) dτ v(τ * ) = −1 .In terms of interaction with traders, the AMM essentially provides a service, and the optimum fees from the point of view of liquidity providers balances the trade-offs between the price of the service ( τ ) and the demand for the ser- vice ( v(τ )).
However, liquidity providers also have to contend with arbitrageurs.In Fig. 5, traders will participate even when the external market price lies within the arc AB , but arbi- trage is not profitable in that range.When the external market price moves beyond AB , arbitrageurs are vital for AMMs such as Uniswap to achieve an alignment between the AMM price and the external market price.If trading fees are increased to favor liquidity 39 Taking log of L = x providers, the arc AB widens, which discourages arbitrage over a wider range of prices.This indicates an intuitive trade-off between efficiency in terms of price alignment with external markets, and the incentives for liquidity provision.
It is worthwhile exploring further how external market price movements and the resultant arbitrage activities affect liquidity providers.To do so, we assume that there are no traders, so that there is only interaction between liquidity providers and arbitrageurs.To begin with, consider the case where τ = 0 ; Fig. 4 serves as a visual reference.One way to measure the performance of liquidity provision is to compare it to a situation when the same assets are held in the external market.Essentially, this is the opportunity cost of placing the tokens in the CPMM, assuming that the next best alternative is holding it in an external wallet.
At the initial equilibrium when P 0 Y /X = M 0 Y /X (say point A in Fig. 4), the reserves in a CPMM are (x 0 , y 0 ) .Using the external price to value assets, the value of tokens in the CPMM liquidity pool (measured in units of Y ) is v 0 C = y 0 + M 0 Y /X x 0 , which equals the value in the external market, v 0 E .Now suppose the price in the external market were to change to M 1 Y /X > M 0 Y /X (say point M in Fig. 4).Arbitrage implies that we move from point A to M , so that P 1 Y /X = M 1 Y /X and new CPMM reserves are (x 1 , y 1 ) .The values of the tokens in the two cases are now , the values are different because the CPMM has rebalanced to ensure that y 1 = P 1 Y /X x 1 , whereas no such automatic rebalancing occurs in the external market.Since the arbitrage activity implies that CPMM liquidity providers are holding less of the token that is gaining value ( X in this case), it is intuitive that v , the percentage difference in the CPMM pool value relative to the external market value when there are no fees is 40 : Since 2 √ θ < (1 + θ) , we have that I(θ) < 0 , and liquidity providers suffer a loss in value relative to holding a non-rebalanced portfolio in the external market.Moreover, as this inequality holds for any price ratio θ , the movement in the reverse direction (where say the change is from point B to M in Fig. 4) also yields similar results.In the DeFi community, I(θ) is referred to as impermanent loss or divergence loss, because this is an unrealized loss relative to the external market; if the price were to revert to M 0 Y /X again, we would have that v 0 C = v 0 E , and the loss disappears.As this primarily reflects the impact of rebalancing in the CPMM, one could relabel this as a rebalancing cost.
Adding fees moves the analysis from Fig. 4 to Fig. 5, which introduces additional features: first, there exists a range (the arc AB ) where no arbitrage takes place; and second, there are multiple prices in the CPMM ( P Y /X , p b Y /X = φP Y /X and p a Y /X = 1 φ P Y /X ).To see how these features play out, suppose the initial equilibrium is at point P in Fig. 5, so that M 0 Y /X = P 0 Y /X .Now, if the external price reduces to M 1 Y /X equal to slope of ray OM , (20) 40 See Pintail (2019) for this formula, along with examples.Formally, from the relationships xy = k and y x = P Y/X , we have that x = k PY/X and y = kP Y/X .This holds both before and after the price change, along with the fact that M Y/X = P Y/X at equilibrium.So, Xu et al  (2021) for calculations for other types of AMMs.
arbitrage is not triggered and the CPMM reserve assets continue to be located at P .In this case no rebalancing occurs, and the valuation exercise is trivial: if the same price is used for valuing assets in both cases, there is no difference in the valuation of tokens.
Things become more meaningful once we reach the boundaries of the arc AB.Suppose the initial equilibrium is at B , where M 0 Y /X = p b0 Y /X .Now, a small fall in the external price to M 1 Y /X < M 0 Y /X (point M ′ ) will trigger arbitrage till the new bid price satisfies 41 On the other hand, a small rise in price will not result in arbitrage, as we return to the interior of arc AB. 42 Consequently, the useful case to examine is where M 1 Y /X = p b1 Y /X , and so 43 : It follows that I(θ, φ) < 0 when θ < 1 φ 2 , which must hold when θ < 1 .As a result, fees do not alter the fact that rebalancing costs exist beyond the range of the spread.A similar analysis occurs when Our comparative static analysis suggests that the costs of rebalancing are inevitable, and liquidity providers must depend on fees from users to outweigh this.However, this does not factor in how price movements impact the compounding of wealth over time.Tassy and White (2020) show that, under certain circumstances, rebalancing is useful to minimize the negative effect of losses on compounding.In this scenario, it can be optimal to set the fees as low as possible (without being zero), thereby taking advantage of rebalancing when prices are volatile around a narrow spread. 45While this presents some preliminary insights into the dynamics in a specialized circumstance, there is more work to be done in this area.
Fees can impact the security of the system in terms of exploits, such as a sandwich attack. 46A sandwich attack involves both front-running and back-running a transaction.Suppose a trader places an order to sell Y and buy X .Upon seeing the (public) order, an attacker can front-run the transaction by buying X at the offer price ( p a0 Y /X ), thereby driving up the price of X .The trader's original transaction drives the price even higher, 47 and the attack is then completed with a back-run sale of X by the attacker at a new bid ( 21) 41 We assume that the external market is large enough that arbitrage with the CPMM does not affect M Y/X .
42 A large increase in price, of course, can trigger arbitrage if the new price is higher than slope OA .But recalling that these price formulas are for small changes, we focus on this case.
1+θφ − 1. 44 We have that √ θ(1+φ) φ+θ < 1 when θ > φ 2 , which must be true for the relevant range where θ > 1. 45 See White et al. (2020) for an intuitive description of these ideas. 46See Zhou et al. (2020) for a deeper analysis of sandwich attacks.See also Buterin (2018) for an early exploration. 47As a practical matter, the exact amount by which price changes depends on the extent of the slippage; see Zhou et al  (2020).
price p b1 Y /X ; the profit of the attacker is p b1 Y /X − p a0 Y /X .For (no-fee) prices P 1 Y /X and P 0 Y /X , the profit equals φP , which is decreasing in the trading fee τ .A higher trad- ing fee can, therefore, reduce the incentives for such attacks and favor traders whose transactions are sandwiched (though the higher fees increase the spread, which affects traders adversely).
Intuition suggests that the nature of the tokens being traded is also important when determining fees.As such, tokens with low volatility and stable relative prices (for example, correlated token pairs) can afford a lower width of the arc AB (that is, lower fees) in Fig. 5 compared to more volatile assets.The low fees encourage more trading activity in low-volatility tokens, while the price stability minimizes the need for rebalancing due to arbitrage activity, even with a low spread.On the other hand, for tokens that exhibit larger relative price movement, a narrow arc AB would result in frequent arbitrage and rebalancing.In that circumstance, it may be worthwhile to impose higher fees. 48he design of AMM fees must attempt to balance all these interests.Higher trading fees benefit liquidity providers and reduce exploits, but discourage trading and arbitrage, thereby reducing efficiency.Lower fees have a reverse effect.Overall, the design of optimum fees for an AMM is complicated and would have to weigh all these tradeoffs.Current research has, in general, focussed on the optimizing fees for a single entity (typically, liquidity providers, as in Tassy and White 2020).As such, this is an ongoing research endeavour.

Other types of AMMs for decentralized exchanges
In this section, we introduce other types of AMMs.While these are not covered in nearly the same detail as the CPMM, many of the techniques and insights from previous sections carry over here, so that they can be extrapolated in a straightforward way.

Constant Mean Market Makers (CMMM)
A constant mean market maker (CMMM) has reserves (x 1 , x 2 , . . .x n ) of n tokens X 1 , X 2 , . . .X n that satisfy the exchange function: The CPMM is a special case of ( 22) where n = 2 and w i = 0.5 for i ∈ {1, 2} , which can then be squared to yield a CPMM of the type examined before.An example of a DeFi platform which operates as a CMMM is Balancer, 49 and our analysis here is related to the Balancer whitepaper (Martinelli and Mushegian, 2019).An important aspect of the Balancer protocol is that the weights, once fixed, determine the share of the value a particular token has in relation to the overall value of the pool; from this point of view, the (22 48 Indeed, Uniswap-v3 allows for multiple fee structures, initially set at 0.05% (intended for stablecoins), 0.3% (for standard token pairs) and 1% (for highly volatile tokens). 49See https:// balan cer.finan ce (accessed on 20th September, 2021).
Balancer protocol has similarities to index funds that construct a portfolio of assets with fixed weights for each asset (Martinelli and Mushegian, 2019). 50o begin the analysis, suppose there are no trading fees.The bilateral trading price of one unit of X i in terms of X j is P X j /X i = − dx j dx i .Letting n i=1 x w i i = f (x 1 , x 2 , . . .x n ) , Eq. ( 22) yields n i=1 ∂f ∂x i dx i = dk .Along any particular level curve dk = 0 ; moreover, since only quantities x i and x j change in this transaction, dx l = 0 for l = {i, j} .Consequently, for any arbitrary reserve quantities (x 1 , x 2 , . . .x n ) , dx j dx i = − ∂f /∂x i ∂f /∂x j = − w i w j x j x i , and we have: We are now in a position to see how the process of two-point arbitrage works in a CMMM.Consider the case where M X j /X i < P X j /X i = w i w j x j x i .Arbitrageurs will purchase X i in the external market and sell it in the CMMM in exchange for X j .This causes x j x i to fall till the no-arbitrage condition M X j /X i = P X j /X i is restored.
We can also calculate the liquidity pool value after selecting a numeraire to do the pricing.Without loss of generality, let us suppose X 1 is selected as the token to price the liquidity pool; X 1 could be, for example, ETH.Using Euler's theorem 51 : The share of any token value to the pool value is: In a CMMM, therefore, the share of the value of any token to the value of the entire pool is fixed and equal to the weight of the token in the liquidity pool.Now suppose we add ad valorem fees, τ , to the price calculation problem assuming, as before, that the fees are paid in units of the token sold by a trader into the liquidity pool.While slightly more tedious to calculate, we can show that p b X j /X i = φ w i w j x j x i and p a X j /X i = 1 φ w i w j x j x i . 52Using Eq. ( 5), the no-arbitrage condition is: (23) 51 From Euler's theorem we have that x 1 + ∂f /∂x2 ∂f /∂x1 x 2 + . . .∂f /∂xn ∂f /∂x1 x n = rf (x1,x2,...xn) ∂f /∂x1 .Since ∂f /∂xi ∂f /∂x1 = wi w1 x1 xi = P X1/Xi , the left hand side of Euler's equation is V X1,X2,...,Xn .Given the constraint that n i=1 w i = 1 , we have that r = 1 , and the right-hand side equals x1 w1 .
52 Suppose the trader sells X i and purchases X j ; this yields the bid-price p b Xj /Xi .Assume we start with pool reserves (x 1 , x 2 , . . ., x n ) which satisfies n r=1 x wr r = k .For the trade we have x wr r ) x i + φ�x i wi x j + �x j wj = n r=1 x wr r = k .This implies that �x j = x j 1 + φ�x i xi −

Constant Sum Market Makers (CSMM)
There has been some discussion in the DeFi space about the usefulness and limitations of a constant sum market maker (CSMM). 53For reserves (x, y) , a CSMM holds the sum of reserves constant, that is, the exchange function satisfies x + y = k .Of course, one could generalize this to ax + by = k , or to The main point we wish to make here is that a CSMM functions poorly as a decentralized exchange because arbitrage activity can entirely drain the liquidity pool of a token, and the simple x + y = k case suffices to show that.Before doing so, however, it is worthwhile examining why a CSMM may be attractive.One of the features of a CPMM (and a CMMM) is that along a particular level curve, say k 0 in Fig. 4, the slope varies at every point, and consequently the price changes every time the reserves change, even if by a small amount.In contrast, in a CSMM ax + by = k , the price is constant and equal to P Y /X = − dy dx = a b ; indeed, in the special case where a = b = 1 , P Y /X = 1 , and the two tokens trade on a one-to-one basis.The price stability is attractive in that it reduces slippage, which is a useful feature to have when trading tokens with stable relative prices.
In a decentralized exchange, however, the constant price in a CSMM is problematic if the external market price is variable.Intuitively, arbitrageurs will constantly take advantage of the price differential in the two markets and because the constant price in the CSMM cannot, by construction, respond to this pressure by arbitrageurs, they may drain the CSMM of one token or the other.This intuition is described more systematically in Fig. 7, which depicts the exchange function x + y = k .Suppose that τ = 0 to begin with.
Consider a situation where the reserves in the CSMM are (x A , y A ) , and the level curve is k = k 0 .The absolute value of slope of the line BD is P Y /X = 1 .Now suppose the exter- nal market price is M Y /X > 1 .In this case, arbitrageurs will buy X in the CSMM and sell it in the external market to make a profit of M Y /X − P Y /X for every unit of X bought and sold this way.If the CSMM is small compared to the external market, M Y /X may change little in response to the sale of X there, and the process will continue till the CSMM is drained of all X since P Y /X is fixed.
In Fig. 7, starting from point A , arbitrageurs can buy Ox A units of X by selling By A units of Y to the CSMM, which causes a movement to the corner point B .The line BC describes the trading possibilities in the external market, and has a slope greater than 1 , thereby capturing the fact that M Y /X > P Y /X .Arbitrageurs can sell the Ox A units of X purchased in the CSMM for By M units of Y in the external market, making an overall profit of y M y A units of Y .For the CSMM, the arbitrage process drains all X reserves and the CSMM is left with k 0 units of Y , leading to a corner equilibrium at point B. 54 The arguments when M Y /X < 1 are similar, with a corner equilibrium at D. 53 An example of using a CSMM as the exchange function is mStable, which used a CSMM to initially develop mUSD.However, as users identified concerns with the design, it has moved away from the CSMM model for mBTC: see https:// github.com/ mstab le/ MIPs/ blob/ master/ MIPS/ mip-7.md (accessed 20th September, 2021).Egorov (2020) discusses the problems with a CSMM, before utilizing a mix of the CSMM and CPMM exchange functions to develop a hybrid AMM. 54A corner solution such as this is discussed in many undergraduate microeconomics textbooks (see, for example, Varian 1987) in the context of perfect substitution between goods in a utility function.In this case, indifference curves are straight lines.The consumer simply spends her entire budget on the lower priced good, yielding a corner solution to the consumer utility maximization problem.The fact that the AMM will lose the more valuable token in its reserves also bears some similarity in a macroeconomic context to Gresham's Law: bad money drives out good money (for example, see Dernburg 1989).This phenomenon typically happens when there are multiple competing reserves, for example, gold and silver in a bimetallic standard.
Adding trading fees as before, we have that p b Y /X = φ and p a Y /X = 1 φ .In the scenario above where an arbitrageur buys X from the CPMM, the relevant price of X is 1 φ units of Y .So, if fees are high and 1 φ > M Y /X , arbitrage is no longer profitable; on the other hand, if fees are low and 1 φ < M Y /X , arbitrage continues as before and yields a corner equilib- rium.Overall, the no-arbitrage condition in this case is φ ≤ M Y /X ≤ 1 φ .Higher the fees, wider is the gap and it is less likely that the CSMM is depleted of one token due to the action of arbitrageurs.

Hybrid Function Market Makers (HFMM)
One of the advantages of a CSMM is that there is no price slippage, which is a problem with a CPMM/CMMM.However, the disadvantage of a CSMM is the possibility of a corner equilibrium when token prices are volatile, which cannot happen in a CPMM/ CMMM.A mix of a CPMM/CMMM and a CSMM that emphasizes both their advantages, while minimizing their problems, would be a desirable middle-ground in many situations, such as the exchange of stablecoins.A Hybrid Function Market Maker (HFMM) attempts to achieve this by integrating the exchange functions of a CSMM and a CPMM/CMMM.
Much of the discussion below is inspired by the whitepaper for Curve Finance (or, formerly, Stableswap; see Egorov 2019), an AMM that facilitates trade in stablecoins.Our focus here is to bring out the intuition behind how an integration of a CPMM/ CMMM and CSMM may be achieved and the HFMM described here is, consequently, Fig. 7 Price and arbitrage in a CSMM with no trading fees considerably less complex than that of Egorov (2019). 55To keep the exposition simple, trading fees are assumed to be zero.
Consider a CMMM described in Eq. ( 22), with equal weights so that n i=1 x = k .Why these special cases with equal- ized weights and coefficients were chosen will become apparent presently.The bilateral price in the CMMM is P X j /X i = x j x i and in the CSMM is P X j /X i = 1 .Our goal is to mix these two AMMs to form a hybrid, and the simplest way to do that is to take a weighted average of the two: The problem with this scheme, however, is that the weight attached to each function is independent of the reserves (x 1 , x 2 , . . ..x n ) .Ideally, we would like to assign more weight to the CMMM when any of these token reserve approaches zero to ensure its price escalates rapidly.Similarly, when the amounts of the tokens are roughly equal, assigning greater weight to the CSMM will ensure that prices do not change too rapidly, thereby minimizing slippage.
To construct a scheme where is sensitive to the quantity of reserves, we note the arithmetic mean (AM) of the reserves is quently, specifies various combinations of reserves that yield a particular AM.Similarly, the geometric mean (GM) of the reserves is G = n i=1 x 1 n i = k looks at combinations of reserves yielding a specific GM.Now, consider the relationship between A and G .A well-known theorem (which we do not prove here) is the AM-GM inequality: The AM-GM inequality: For any non-negative real numbers x 1 , x 2 , . . ., x n : Suppose we focus on the ratio G/A , where A = 0 .Given the AM-GM inequality, it fol- lows that G A ≤ 1 and that G A = 1 only when the reserves of all tokens are equal.Moreover, it is evident that G A ≥ 0 and that G A = 0 only if at least one of the reserves (but not all, since A = 0 ) satisfies x i = 0 .So, 0 ≤ G A ≤ 1 holds, and G A is a feasible candidate for the weight .Let us set, then, = G A in Eq. ( 27), which yields: From Eq. ( 28), we can derive the bilateral price using the same procedure as before: (27 x 55 Specifically, Egorov (2019) uses the exchange function , where χ is a 'leverage' parameter, D is the sum all token balances, x i is the reserve of token i , and n is the number of tokens.
Equation (29) implies that when reserves of any token, say X i , tends to zero, we have that G A → 0 and P X j /X i → ∂G/∂x i ∂G/∂x j , which is the price that would exist under a CMMM.Similarly, when G A → 1 , P X j /X i → ∂A/∂x i ∂A/∂x j , which is the price that exists under a CSMM.The outcome of this discussion is shown geometrically in Fig. 8 for the two token case.The curve GG represents the CMMM x 1 2 y 1 2 = k and the line AA represents the CSMM x+y 2 = k .The mixing of the two AMMs using a fixed is shown with the dashed-curve CC , which has been drawn with = 0.5 .It is evident that CC reduces the problem of dwindling reserves experienced by the CSMM AA ; however, there is still considerable price slippage as, starting from the 45 • line, the slopes change rela- tively rapidly.Choosing a different would involve a different trade-off between the twin problems of draining reserves and price slippage; the point is that this trade-off is fixed for all reserve combinations once is chosen.The HFMM with = G A is shown using the dotted-curve HH .Compared to the CC curve, HH is closer to AA when reserves are roughly equal and, at the same time, is closer to GG when one of the reserves in the liquidity pool starts to fall, thereby transferring weight to the AMM that better resolves the more damaging problem for a specific reserve combination.
While this example of forming a hybrid represents one way of moving between a CSMM and a CMMM, other possibilities exist.For example, one could specify the general CES (Constant Elasticity of Substitution) function as the AMM exchange function.The CES function with two tokens X and Fig. 8 Hybrid Function Market Makers efficiency parameter, α is the distribution parameter and ρ is the substitution param- eter.When E = 1, this will approach the two token CMMM exchange function x α y 1−α as ρ → 0 and equals the CSMM αx + (1 − α)y when ρ = 1. 56This allows for a way to change the curvature of the exchange function parametrically, similar to changing a fixed above. 57

Dynamic weights in a CMMM
The section "Hybrid Function Market Makers (HFMM)" provided the basic intuition behind how a HFMM attempts to modify a CMMM to keep prices relatively stable.
A HFMM provides a satisfactory solution in the context of stablecoins where prices exhibit low volatility in the external market.However, the HFMM method of changing the shape of the AMM function may be less suitable when dealing with volatile tokens, where arbitrage activity may be high.Fees reduce arbitrage but negatively affect the efficiency of an AMM.So, the question that we now address is whether arbitrage activity on a CMMM can be reduced: (a) while still reflecting the external market price; but, (b) without changing the n i=1 x w i i = k exchange function; and (c) without increasing fees?In the section "Constant Mean Market Makers (CMMM)", the CMMM required that the weights were fixed at some level.Consider, now, a scenario where the CMMM could alter the weights dynamically in response to some external market stimulus.To see the implications of this possibility, let us recap the CMMM arbitrage response with zero trading fees.If M X j /X i < P X j /X i = w i w j x j x i , for example, arbitrageurs purchase X i in the external market and sell it in the CMMM in exchange for X j till M X j /X i = P X j /X i holds.All the response in this case is through changes in x j x i .There is, however, an alternative way to get P X j /X i to fall: by reducing w i w j .If the CMMM were to adjust weights to w ′ i and w ′ j , we can have M X j /X i = P X j /X i = x i , with no change in the ratio of reserves x j x i .Prices in the two markets have become aligned not because of arbitrage activity, but rather due to 'dynamic' adjustments of the weights.
The above discussion suggests that weights that are flexible provide an additional equilibrating factor other than arbitrage to ensure that AMM prices track external market prices.The external market price now serves the purpose of an oracle: an external source of information that is fed into the smart contract.The relative importance of dynamic weights and arbitrage in keeping prices aligned between the two markets then depends on how frequently and reliably the oracle provides information to the AMM.Finally, it is worth noting that dynamic weights cause two important changes to the CMMM.First, the shares in Eq. ( 25) are no longer fixed, causing the CMMM to no longer be analogous to a standard fixed weight index fund.Second, from Eq. ( 24), in the standard CMMM, the valuation changes only when the quantity x 1 changes.Changing weights, however, present an additional source of change for pool valuation, potentially making the pool value more volatile.

An example of a DAMM: Bancor
Bancor is an example of an AMM that dynamically adjusts weights as the external market price changes, thereby reducing arbitrage activity.Bancor does not directly use a CMMM function as its trading technology; our goal here is to show that the price output is, nevertheless, the same as the CMMM discussed above.The important institutional features of Bancor described here are based on Hertzog et al (2018) and Rosenfeld  (2017). 58 smart contract in Bancor has two types of tokens: a 'smart token' (say Y ) and a set of n 'connected tokens' , where n ≥ 1 .Let the connected tokens be X 1 , X 2 . . ., X n .Let P Y /X i denote the price of 1 unit of X i in terms of Y (in the absence of any trading fees). 59A trader can purchase or sell X i against Y at any time using the smart contract at the going price.When a trader sells X i its reserve balance, x i , increases and the smart contract automatically increases supply of Y .The opposite occurs when a trader buys X i : reserve x i decreases, as does the supply of Y .The mechanics of operation thus far appear entirely different than a CMMM.What makes the two comparable are 'connector weights' or 'fractional reserve ratios' , w i , i ∈ {1, 2, . . .n} .Letting y denote the total quantity of Y , w i satisfies the condition: The numerator is the value of token X i denominated in units of Y , while the denomi- nator is the total value of Y in the smart contract.Equation ( 30) essentially defines the connector weight as the ratio of the value of reserves of X i to the total value of all the Y supplied.When n i=1 w i = 1 , it follows that n i=1 P Y /X i x i = y and the sum of the values of all the 'connector tokens' exactly equals the value of Y minted by the smart contract.Now, Eq. ( 30) can be rearranged to get P Y /X i : For any two tokens, X i and X j , we can get the cross-rate that is implied by Eq. ( 31): This is, of course, exactly the same as Eq. ( 23) for a CMMM.So, any set of reserves on Bancor generates exactly the same price as a CMMM when the connector weight for each token on Bancor equals the weight for that token on the CMMM.Consequently, Bancor and Balancer can be viewed as being equivalent in terms of the technology for converting quantities of tokens reserves to prices, even though the institutional mechanisms may be different.It also follows straight away that when Bancor assigns dynamic weights, its outcomes replicate the CMMM with dynamic weights outlined in the (30) 58 Our exposition here is meant to capture the overall logic of the system, rather than all the institutional details of the Bancor protocol; see https:// app.bancor.netwo rk/ eth/ data (accessed on 20 th September, 2021), Hertzog et al (2018) and Rosenfeld (2017) for further details. 59Hertzog et al (2018) and Rosenfeld (2017) work with the price P Xi /Y , which (from Eq. 2) is the reciprocal of P Y/Xi used here; the latter is used in this paper mainly for expositional ease.section "Dynamic weights in a CMMM" and the intuition of price adjustment provided there is applicable here as well.
Overall, revisiting Fig. 1, we have formed connections between a number of different types of AMMs: CPMM-v1 and v2, CMMM, HFMM, CSMM and DAMM.While the possibilities for experimenting with AMMs appear endless, simple geometric tools based on homogeneity and homotheticity are often suffice to discern similarities and differences in their structures.

Proposed changes in Uniswap-v3
The Unswap-v3 whitepaper (Adams et al. 2021) proposes three important changes to v1 and v2, which we summarize briefly here.
First, in the Uniswap-v1 and v2 protocols, tokens of liquidity providers are pooled together and can be traded anywhere along the exchange function.In contrast, Uniswap-v3 implements concentrated liquidity, where a liquidity provider can specify a price range, P, P , within which to add liquidity.The main purpose of this change is to improve capital efficiency.Consequently, liquidity provision no longer requires deposits of X and Y of equal value.Since a liquidity provider needs to cover only the range speci- fied, the deposit ratios of can vary depending on the price range specified and the current price of tokens.
The implication of introducing concentrated liquidity is that each position is unique.Intuitively, in Uniswap-v1 and v2, liquidity provision was characterized by the amount x added to the pool (the condition that tokens are provided in equal value determines y ); as a result, fungible liquidity tokens are capable of tracking liquidity contributions by providers.In Uniswap-v3, however, liquidity provision is characterized by x and by a price range P, P specified by the provider, and the latter distinguishes the contribution of one provider from another who also adds x but specifies a different price range.As a result, the second major change is that v3 protocol uses non-fungible tokens to track liquidity.
The third change occurs to trading fees and how these fees are distributed to liquidity providers.In Uniswap-v1 and v2, all pools have a uniform trading fee of 0.3% and these were automatically added to the liquidity pool causing k to expand over time from fees alone.In v3, multiple pools can exist for the same token pair with varying fees, with 0.05%, 0.3% or 1% being the initial fee tiers (with the capability to add more tiers).Moreover, fees are no longer added to the liquidity pool, and are stored separately.In some ways, the addition of fee tiers is an alternative strategy to ex ante designing an 'optimal' fee for the AMM; liquidity providers can select their preferred fees for any pair of tokens and the market can converge towards a trading fee for the token pair.One would expect that, over time, this will also be conditioned by the extent of competition that exists between AMMs providing similar services.

The geometry of a single concentrated liquidity position
We now investigate more closely the implications of introducing concentrated liquidity.As will be seen, the geometry becomes more complex due to this feature.Our analysis here follows broadly along the lines of Adams et al. (2021) and Mellow Protocol (2021).
However, we develop a set of geometric techniques that are consistent with the previous sections, and that allows us to better understand the relationship between Unsiwap-v1 and v2 on one hand, and Unsiwap-v3 on the other.Trading fees are assumed to be zero for simplicity.
Consider the exchange function k = xy in Fig. 9, which is the same as the Uniswap- v2 exchange function.To begin with, we assume that there exists a single user who has specified the price interval [P F Y /X , P C Y /X ] for the liquidity bounds.As before, we have that P C Y /X = y C x C and P F Y /X = y F x F .Assume the current price is P B Y /X = y B x B .A position is characterized by P F Y /X , P C Y /X and the reserves placed within that price range. 60There are now two aspects to focus on: first, what occurs in a position; and second, how this relates to the overall exchange function.To distinguish between the two, Uniswap-v3 uses the term real to keep track of actual reserves within a specific price range and virtual to refer to the overall exchange function.The exchange function k = xy is defined, then, in terms of virtual reserves x and y .Virtual reserves are important in this context because they determine prices along the exchange function.
Geometrically, Fig. 9 differentiates between virtual and real by drawing a separate set of 'real axes' , x and y (with origin O ), to keep track of real reserves within the position CF .The 'virtual axes' , x and y , keep track of virtual reserves.The real axes are, essentially, a translation of the virtual axes.Any point x, y in the virtual Fig. 9 A single position in a Uniswap-v3 pool 60 Uniswap-v3 keeps track of every .01%change between prices.Specifically, a pool tracks prices P = 1.0001 i , for i ∈ {. . ., −2, −1, 0, 1, 2, . . .} ; each i corresponds to a price 'tick' .The change in prices between two ticks is then dP di = Pln(1.0001)∼ = .0001× P .This results in a discretization of the prices, a complication that we shall conveniently ignore here.
x − y space can be translated to a point x, y = x − h, y − m in the real x − y space, where (h, m) is the co-ordinate of O in relation to the origin O .In Fig. 9, h = x C and m = y F ; the coordinate of the real origin O is clearly a function of the bounds of the interval [P F Y /X , P C Y /X ] specified by the liquidity provider.Thus, at point C , the virtual reserves are x C and y C , but the position has real reserves x C = x C − x C = 0 of X and y C = (y C − y F ) of Y .Similarly, at point F , the real reserves are x F = (x F − x C ) and y F = 0 (while virtual reserves are y F and x F ).In general, for any virtual reserve (x, y) in the arc FC , the translation of the axes yields corresponding real reserves x, y = (x − x C ,y − y F ). Now, suppose we start at some point, say B , where real reserves are equal to x B , y B = (x B − x C ,y B − y F ) .As traders swap X for Y , the liquidity pool loses Y and gains X , with prices moving along the exchange function till we hit point F .Here, y F = 0 and the position holds only X .Similarly, as prices move in the reverse direc- tion from B , the position will run out of reserves of X at point C and be left with reserves of only token Y .
The real axes x and y highlight that even though the virtual reserves can never fall to zero for any asset due to the curvature of the xy = k exchange function, real reserves can indeed do so.The latter occurs when the level curve intersects the y or x axis.This necessitates differentiating between active and inactive positions: when the actual trading price is in the range (P F Y /X , P C Y /X ) , the position CF is active.This occurs, for example, when the actual price equals the slope of ray OB in Fig. 9.When the price is outside that range, at say points D or E , the position is inactive.Inactive positions earn no fees on Uniswap-v3, which is a marked difference from Uniswap-v2 where liquidity providers earn fees along the entire exchange function.If the position is inactive at the time of liquidity provision, say at point D , the liquidity pro- vider deposits only asset Y when specifying the inactive range [P F Y /X , P C Y /X ] .Similarly, if the current price corresponds to point E , the liquidity provider deposits only asset X when specifying the same price range.In either case, the position becomes active when the price enters the specified price range.
The feature of real reserves falling to zero bears similarity to a CSMM, such as the one shown in Fig. 7. To highlight the similarity, we have drawn the chord connecting C and F in Fig. 9; with respect to the axes x and y , the line CF behaves like a CSMM.As pointed out in the section "Constant Sum Market Makers (CSMM)", the slope of the CSMM is the fixed price at which the two assets trade.It is worth investigating, then, what information the slope of the line CF provides in Uniswap-v3.The slope of line CF is y C −y F x C −x F , which is the rate at which the two assets exchange on average in the position.We can, therefore, think of the absolute value of the slope of CF as the average price of the liquid- ity position bounded by the prices P F Y /X and P C Y /X .Denoting the average price as P CF Y /X : To understand how the chord CF is related to the arc CF , we utilize a fundamental theorem in calculus, the Mean Value Theorem.
Mean Value Theorem Consider a continuous function y = f (x) on an interval [x 1 , x 2 ] that is differentiable in (x 1 , x 2 ) .Then, there exists some x A ∈ (x 1 , x 2 ) such that: (33) In terms of Fig. 9, the Mean Value Theorem implies that there exists a point A (as shown in the figure) on the exchange function between C and F that has the same slope as the line CF .Consequently, we can identify A as a point on the exchange function that has the same price as the average price of the liquidity position bounded by C and F .It is straightforward to show that this average price is the geometric mean of the price bounds 61 : The average price is also the effective price for a range order in Unsiwap-v3, where a liquidity provider contributes a single token in an inactive position (typically with a narrow price range).In Fig. 9, if the liquidity position becomes active at F and the price moves through arc CF before exiting at C , the average price for exchanging X to Y is then given by (34).
It is worth noting that while "price equals the ratio of reserves" is an unambiguous statement in Uniswap v1 and v2, this is no longer true in Uniswap-v3, where there are two reserve ratios to keep track of: first, the virtual reserve ratio y x (which equals P Y /X ); and second, the real reserve ratio y x (which need not).To see the difference between the two, in Fig. 9 at point B , we have that the virtual reserve ratio y B x B equals the slope of the ray OB .However, the real reserve ratio is y B x B = y B −y F x B −x C , which is obviously different.Indeed, the real reserve ratio equals the slope of the line OB running through the real origin.The real reserve ratio y x ranges from 0 to ∞ as the virtual reserve ratio y x varies between P F Y /X and P C Y /X .The upshot of the above discussion is that all these variables lying on the same graphx, y, x, y, P Y /X , P F Y /X , P C Y /X , k-must be systematically linked.To delve into these links, we follow Adams et al (2021) by substituting L = √ k in the exchange function, though this is not necessary and one can simply use √ k instead of L in subsequent analysis. 62With this change, the exchange function is xy = L 2 .For a given interval [P F Y /X , P C Y /X ] , the vir- tual and real reserves are linked by x = x + x C and y = y + y F .The exchange function is then: Once the liquidity provider has specified interval [P F Y /X , P C Y /X ] , the quantities x C and y F are fixed along a level curve.This allows us to describe x C and y F in terms of L, P F Y /X and P C Y /X .Specifically, we get that x C = L P C Y /X and y F = L P F Y /X . 63Plugging this in Eq. ( 35) yields: 62 However, as pointed out in the section "Liquidity in a CPMM", L = √ k is a better measure of liquidity.The idea of adding liquidity from different positions is more intuitively captured using L.
63 At any arbitrary point (x, y) , we have that xy = L 2 and y x = P Y/X , which implies that x = L √ PY/X and y = L P Y/X .Since this is true at any arbitrary point, it holds at both points C and F.
Equation ( 36) is useful because it tells us the various combinations of real reserves ( x, y) that yield the same level of L for given P C Y /X and P F Y /X .In other words, it describes the behavior of real reserves in the arc FC in Fig. 9.
Next, consider any arbitrary point on the arc FC characterized by virtual reserves (x, y) and price P Y /X = y x .It is worthwhile to describe real reserves at that point, x, y = (x − x C ,y − y F ) , in terms of L, P F Y /X , P C Y /X and P Y /X 64 : Equation (37) allows us to see how logically consistent liquidity provision occurs on Uniswap-v3 for an active position, when the current price is P Y /X .Eliminating L in Eq. ( 37), we get: So, if a user specifies a certain quantity x of token X , along with a price range bounded by P C Y /X and P F Y /X , Eq. ( 38) determines the amount of token Y that must be added by the user for liquidity provision at the current price of P Y /X .To see how this compares to Uniswap-v1 and v2, recall that in these earlier versions, liquidity is provided over the entire range of the exchange function.This is equivalent to a position on Uniswap-v3 where P F Y /X → 0 and P C Y /X → ∞ ; indeed, when these limits are taken in Eq. ( 38), we get y = xP Y /X , which is the Uniswap-v1 and v2 liquidity provision rule.

Combining positions
The section "The geometry of a single concentrated liquidity position" showed that for liquidity provision in a single position, given the current price ( P Y /X ) and a user- defined price range (bounded by P C Y /X and P F Y /X ), a specified amount x of token X is associated with an amount y of token Y (Eq.( 38)) and a certain level curve k = L 2 (Eq.( 37)).This can be now used to derive how multiple positions interact for liquidity provision on Uniswap-v3.
Consider, to begin with, the simplest possible case when there are two positions defined over the same price interval [P F Y /X , P C Y /X ] , but where the liquidity providers specify two separate quantities of token X when providing liquidity: x ′ and x ′′ .At the current price of P Y /X , the amounts of token Y that must be added is given by Eq. ( 38).From Eq. (37), we see that these amounts of X are consistent with different level curves: (36) 64 This follows directly from the previous footnote.
It is readily observed that summing these positions is equivalent to a single position with x ′′′ = x ′ + x ′′ ; that is: This is shown graphically in Fig. 10, where the real axes for the two positions have been drawn with origins O ′ and O ′′ .The prices P F Y /X , P C Y /X and P Y /X correspond to the slopes of rays OF , OC and OP , respectively.The amount of X provided in the first posi- tion, x ′ , corresponds to the distance O ′ x ′ .Once the user has determined the amount of X to provide, the corresponding amount of Y is given by Eq. ( 38) and is shown by the distance O ′ y ′ .The level curve corresponding to these real reserves can be determined by Eq. ( 39) and is shown as k . A similar set of arguments hold for the second position labelled with '' on the graph.The combined liquidity provision is given by Eq. ( 40  In general, intervals specified by liquidity providers may partially overlap (or not at all).While this yields more complex graphs, the underlying logic is the same.In Fig. 11, we depict a scenario with a partial overlap, with the two user-specified price ranges being [P F ′ Y /X , P C ′ Y /X ] and [P F ′′ Y /X , P C ′′ Y /X ] .These price ranges and the corresponding liquidi- ties translate the axes to O ′ and O ′′ , respectively.The prices can be read off the graph as the slope of rays OF ′ , OF ′′ , OC ′ and OC ′ ′ .To keep the graph devoid of clutter, the figure does not contain information such as the current price, the real reserves and so on.The overlap of the price interval suggests that there are 3 disjoint ranges to consider: . While the algebra of the breakdown is somewhat messy, the intuition of what happens in this instance is clear from the geometry.Suppose we start at a situation where the current price satisfies P Y /X < P F ′ Y /X ; at such a price both positions are inactive and real reserves are held entirely in token X .When the price increases to P Y /X = P F ′ Y /X , the first position is activated.This occurs at point A in Fig. 11.
In the price range [P F ′ Y /X , P F ′′ Y /X ] , only this position provides liquidity, so the relevant level curve is k ′ .This holds till point B , but once the price reaches P Y /X = P F ′′ Y /X the second position is activated.Consequently, in the range [P F ′′ Y /X , P C ′ Y /X ] , both positions are active, and the relevant level curve of the exchange function is k , which combines both positions in that price range.There is, in essence, a jump from point B to D to reflect the joining of a second position to liquidity provision.As the price increases beyond P F ′′ Y /X , we move along the arc DE ; at point E , we have that P Y /X = P C ′ Y /X and all the real reserves in the first position have been converted to token Y , leaving only the second position with liquidity in both tokens to facilitate further swaps by traders that involve the purchase of X .In the final range [P C ′ Y /X , P C ′′ Y /X ] , only the second position is active, so we drop to point G on the level curve k ′′ .Further price increases involve moving along the arc GH , till P Y /X = P C ′′ Y /X , at which point real reserves of X are exhausted in the sec- ond position as well.
There are two features to take away from this discussion.First, unlike Uniswap-v1 and v2, trade does not take place along a single level curve.Rather, as shown by Fig. 11, there are jumps in the level curves as trading occurs, leading to discontinuities.In Fig. 11, there are three discontinuous arcs that characterize liquidity provision: arc AB , arc DE and arc GH .Secondly, despite this added complexity, the geometry behind Fig. 11 is straightforward, and combining additional positions is readily visualized using the same procedure. 65nsiwap-v3, therefore, functions differently than its predecessor v2 in significant ways.While the same exchange function is used to convert (now virtual) reserves to prices, the introduction of concentrated liquidity produces features that are distinct.Apart from the liquidity provisioning being discontinuous, each position behaves similar to a CSMM in the sense that it can run out of one reserve or the other, which cannot occur on Uniswap-v1 an v2.It is intuitive that adding concentrated liquidity to other AMMs, such as a CMMM like Balancer, will also produce such changes.As a consequence, it may be worthwhile to add to the alphabet soup of AMM labels by giving AMMs with concentrated liquidity their own name, perhaps Concentrated Liquidity Market Makers (CLMMs). 66aving pointed out how different Uniswap-v3 is to v2 and v1 in terms of yielding discontinuous liquidity levels, we conclude our analysis of Uniswap-v3 by summarizing when its liquidity provision does correspond to continuous curves in a manner similar to earlier versions.The first is when all liquidity providers specify a price range where P F Y /X = 0 and P C Y /X = ∞ ; this replicates Uniswap-v2 essentially because concentrated liquidity is no longer relevant.The second is when the level curve is partitioned by positions; partitioning implies that positions are disjoint and cover the entire range of prices.This is shown in Fig. 12, where there are four disjoint positions, all of which involve liquidity provision such that they lie on the level curve k .Here, trading occurs along a single level curve with no discontinuities, like Uniswap-v2.However, each position can be drained of a single reserve, like a CSMM (dashed lines).Consequently, Fig. 12 highlights the somewhat hybrid nature of Unsiwap-v3. 65Though, as mentioned earlier, since price moves in ticks on Uniswap-v3 and fees are charged as well, the actual computations are more complicated than those described here. 66Cyclos, for example, labels itself as a concentrated liquidity market maker for the Solana network; see https:// cyclos.io (accessed 20 th September, 2021).

Conclusions
This paper presented a unified framework based on the neoclassical black-box to characterize different types of AMMs that are currently popular as DEXs.One of the main advantages of such a framework is that it provides a set of simple tools that can be used to visualize the geometry of a given AMM.This makes it easy to see, for example, why the price remains unchanged when both reserves are doubled.It also allows for a simple way to check when manipulating a given exchange function makes a significant difference and when it does not.In a CPMM, for example, the homotheticity property suggests that any monotonic transformation of the exchange function does not alter the price for any given set of reserves, making these various functions equivalent.Other properties, such as Euler's theorem provide a convenient method to value a liquidity pool in an AMM.
Importantly, the methodology also allows for comparisons across a variety of AMMs, in order to examine how similar or different various types of AMMs are.While the coverage of AMMs in this paper is certainly not exhaustive, especially since this is a fertile area for innovation with new ideas for AMMs being developed at a rapid pace, the analytical and geometric tools described here are fairly general and (hopefully) present an intuitive framework to allow new AMMs to be scrutinized and contrasted with existing AMMs.
The focus of this paper has been on the analytical framework behind AMMs.As such, AMMs rely on arbitrage or oracles to align prices with the broader market.Our understanding of how well arbitrage operates in this space and how it performs relative to oracles is still nascent.This is partly an empirical endeavour (which has not been addressed in this paper at all), but there are theoretical considerations here as well.For example, there are many impediments (other than transaction fees) to how efficiently AMMs can operate.These include phenomena such as frontrunning of trades, the worrisome presence of generalized bots that are capable of traversing the landscape of the Ethereum terrain to 'snipe' arbitrage transactions entered into by others, the reordering of transactions by miners, and so on. 67The last couple are particularly interesting, because they can destroy incentives to engage in arbitrage: if arbitrage opportunities spotted by an agent (in the broadest of being any entity, human or a program, that recognizes an arbitrage opportunity) are likely to be stolen by a bot, there is little incentive to identify arbitrage opportunities in the first place.This questions the incentive structure for arbitrage to be undertaken.
While this primer takes a fairly deep look at AMMs and DEXs, it barely scratches the surface of advancements to financial instruments and institutions that are taking place in the DeFi space.This paper does not, for example, examine borrowing and lending institutions being developed, the use of derivatives such as perpetual swaps, or how stablecoins operate. 68Moreover, as mentioned in the introduction, the main disadvantage of the black-box approach is that it precludes an examination of many interesting issues, such as how communities are formed in a decentralized environment, how governance takes place, what restrictions are imposed by the ability to fork, and so on.In other words, there is much scope for exciting research to be done in the DeFi space.
Like blockchains in general, DeFi is the amalgamation of different fields of expertise: computer science, cryptography, finance, economics and game theory, to name a few.These fields have developed with their own jargon, methodologies and tools of analysis, with ever growing levels of sub-specialization and narrowness in expertise. 69It comes as no surprise, then, that computers scientists and entrepreneurs at the forefront of the technological developments in the blockchain space often invent new jargon and methodologies to describe phenomena that economists have examined over many decades.At best this creates confusion; at worst, it creates inefficiencies in the scientific process as one field reinvents the knowledge already accumulated by another, or as one field eschews incorporating useful new ideas due to the barriers imposed by multidisciplinary communication.This review presents an attempt to connect advancements in DeFi with the traditional toolkit of economics for one use-case of DeFi, and in doing so takes a few, admittedly small, steps forward in the direction of developing an integrated theory of DeFi.
67 See Daian et al (2019) for these and other issues related to vulnerabilities in the DeFi space.Robinson and Konstantopoulos (2020) provide an interesting account of Ethereum as a 'dark forest' . 68For a broader treatise on the current state of DeFi, see Harvey et al. (2021). 69In a memorable exchange between Sherlock Holmes and Dr. Watson in A Study in Scarlet, when the latter expresses astonishment at the former's lack of awareness of the solar system, Holmes responds, "A fool takes in all the lumber of every sort that he comes across, so that the knowledge which might be useful to him gets crowded out, or at best is jumbled up with a lot of other things, so that he has a difficulty in laying his hands upon it.Now the skilful workman is very careful indeed as to what he takes into his brain-attic…" When Dr. Watson persists, "But the solar system!", Holmes counters with "What the deuce is it to me?", and then goes on to state, "You say that we go round the sun.If we went round the moon it would not make a pennyworth of difference to me or to my work." Fig. 1 Links between AMMs

Fig. 2
Fig. 2 Three-point arbitrage slopes of tangents are equal at A and C by the point M where the absolute value of the slope of the tangent mm equals the external market price.If the reserve levels in the CPMM is at point A , we have that M Y /X = − dy dx M > − dy dx A = P Y /X .This price differential trig- gers two-point arbitrage with arbitrageurs buying X from the CPMM and selling it in the 32 Reserves can, of course, fall to zero if liquidity providers decide to withdraw their tokens.

Fig. 5
Fig. 5 Price and arbitrage in a CPMM with transaction fees

Fig. 6
Fig. 6 Liquidity pool valuation dy y = dx x , it follows that dL L = dx x .

43
There are now three relationships we work with: p b Y/X = φP Y/X , P Y/X = yx and xy = k .These yield x = hold both before and after the price change.The valuations are then v 1

.
Using L'Hôpital's rule, the right-hand side is −φ wi wj xj xi , and consequently, p b Xj /Xi = − dxj dxi = φ wi wj xj xi .The proof for p a Xj /Xi = 1 φ wi wj xj xi follows along similar lines. 50As shown earlier, a CPMM also shares this feature.