Oct 31, 2022

Why AMMs in DeFi and not in TradFi

In decentralized finance (DeFi), two paradigms are prevalent in the market structure for exchanging crypto assets: Traditional central limit order books (CLOBs) and automated market makers (AMMs). Even though limit order books organize trading in traditional equities, futures, and currency exchanges worldwide, they have not been generally adopted in DeFi markets.

As seen in Figure 1, AMMs currently have a huge lead over CLOBs when looking at the trading volumes of decentralized exchanges (DEXs). Accordingly, this post's first goal is to answer why AMMs became so popular in DeFi. After reviewing the basic mechanisms of AMMs, we will look into some shortcomings of the first AMM designs. These shortcomings motivated the current wave of next-generation AMMs, which are presented in a compact survey at the end of this post.

Figure 1: DEX volume share –  CLOBs (blue and violet) vs AMMs (pink). Source: TheBlock/CoinGecko.

What caused the rise of AMMs in crypto?

DeFi is disrupting an increasing number of services in traditional finance (TradFi), including exchanges. Without relying on a centralized intermediary, like an exchange, bank, or broker, a DEX allows people to trade assets using smart contracts in a decentralized and trustless fashion.



Since DeFi runs on blockchain technology, it inherits the benefits of decentralization and trade-offs compared with centralized single authority infrastructures. Blockchains tend to have lower performance (data throughput), higher network fees, and higher latency (processing time). That posed a significant challenge for CLOB-based DEX implementations (e.g. EtherDelta). Since CLOBs consist of a book with all active orders and a matching engine, 
this design quickly reached its feasibility limits:

  • Performance: an on-chain CLOB stores all pending orders in the smart contract and runs the matching logic (polynomial run time!) upon arrival of a new order for uncrossing the order book. For realistic large numbers of pending orders, it marks a big performance challenge for any underlying blockchain – also for high performance ones.  
  • Fees: the complexity of the matching engine execution incurs high network fees. Moreover, any operation (replace, modify, cancel, and also place an order) carries a network fee. Imagining the network fees on Ethereum, market making becomes something infeasible.
  • Latency: The current standard for responsiveness of order book operations in high-frequency trading (HFT) ranges from microseconds to milliseconds.  Latency up to two minutes (block confirmation time in Ethereum’s PoW; six minutes “finality” in Ethereum PoS) is not compatible with the industry standard, even Algorand’s four seconds finalization time is not enough.

In summary, early fully on-chain CLOB implementations (hybrid designs will be mentioned in our upcoming post) reached performance limits and were incapable of providing high liquidity, which caused slow execution and stale order books with significant bid-ask spreads. It is clear that there was a strong need for alternatives.


AMMs – a way out: although AMMs were around long before, acceptance of AMMs in DeFi can be observed 
in 2020 when DEX protocols such as Uniswap and Curve deployed them as their underlying market model . 
To make it short (more details below), AMMs only have market orders which are matched immediately, eliminating the matching engine and improving on the performance issue. Secondly, liquidity is not generated as in CLOBs by market makers who have to constantly update their limit orders, but liquidity providers fund a reserve (only one deposit fee), and trade orders are matched against the reserve. This could solve the liquidity problem.

How AMMs work

In general, AMMs define a “pricing function” (cf. Figure 2) that algorithmically determines the execution price that will be charged based on the AMM’s inventory at the current moment. Prominent examples in DeFi are constant function market makers (CFMMs) with the constant product market maker (CPMM) being a special case of it. Uniswap V2, 
for example, runs on a CPMM. Let’s work through the example of a CPMM, and investigate the properties of other CFMMs at the end. 



Traders and Liquidity Providers in AMMs: the two actors in AMMs are traders and liquidity providers (LPs). In a market of a token pair X and Y, liquidity providers fund the reserves x,y of token X and Y. For example, X could be ETH and Y could be ALGO. Traders transact immediately against these reserves (and not against another trader’s order as in the case of a CLOB), and it is the AMMs role to determine the execution price.



Price discovery: in a market for a token pair X and Y, the fundamental AMM rule is comprised of the simple formula (Uniswap V2)

F(x,y) := x * y = constant (*)

where x,y are the reserve sizes of token X and Y. Assuming that the liquidity providers already put liquidity in the reserves, i.e.  x, y >0, price discovery is achieved by the simple rule, that both reserves must satisfy the constraint (*) also after the trade: if traders wants to buy δX tokens of X, then their sell amount δY of token Y  must be so that  the new reserve sizes x-δX and y+δY lie on the same curve, i.e.

F(x,y)=F(x-δX ,y+δY)      x * y =(x-δX) *(y+δY) (**)

Using equation (**), the sell amount δY for buying δX can be found to be δY=yδx / (x-δX) which determines the execution price:  δY / δX =y / (x-δX).

Figure 2: How the product formula determines the token price.

In this case, the convexity of the pricing curve ensures that the reserves are not becoming emptied completely, since price goes to infinity towards the edges.

Example: Assume reserves x=10 000 and y=20 000, and a trader who wants to buy δX=2000. 
Then, the execution price is determined by:

δY/ δX=20 000 / (10 000 -2000) =2.5

The marginal price is the execution price for an infinitesimal buy amount δX, i.e. when δX converges to 0. Therefore, 
the marginal price reads as y/x, and is the current market price. 



Liquidity Provision & Fees: Liquidity providers have to put the correct amounts (x', y') on both sides (X and Y) so that the marginal price does not change. This implies the constraint

y/x=(y+y')/(x+x')       y'=y/x * x' (***)

Example: Assuming a USD stablecoin trading pair, the marginal price is 1, hence x=y. Then, equation (***) reads simply as x'=y', and LPs have to put the same amounts on both sides — as expected.

Figure 3: Depositing tokens to the reserve pool.

Liquidity providers are not actively making price decisions in an AMM model, but instead deposit funds into the reserves x and y. By providing liquidity to the pool, LPs earn an income from trading fees (e.g 0.3 % in Uniswap V2).

Potential Issues in CPMM Market Microstructure

Slippage is not specific to AMMs, but is caused by different reasons compared to CLOBs. In general, slippage refers to the difference between the average price of the trade execution compared to the current market price when the trader places the order, i.e. the marginal price in AMMs (see Figure 4). In the example from above, the market price is 2 while the final execution price is 2.5, and instead of the expected 4000 token Y to pay for the 2000 token X (at marginal price), the trader has to pay 5000. After the trade the reserves are updated to x=8000 and y=25000 resulting in a new market price of 3.125

Figure 4: Illustration of slippage in a CPMM.

Slippage in CPMMs is a function of the trade size X, and unlike in an order book, is deterministic and can be expressed in precise mathematical formulas (see [2] or [5]). As noticed in [3], slippage is asymmetric. In our above example, selling 2000 token X would give the trader 3333 token Y. This market dynamic is beyond the scope of our analysis. We just mention that it may lead to the phenomenon that informed traders tend to prefer the sell side.

Impact

  1. Higher trade execution costs: the higher the slippage the higher the execution cost. Execution cost also includes transaction and network fees. From a capital velocity perspective (trade volume/TVL), slippage should be as low as possible to increase trade volume and LPs’ returns.


  2. Arbitrage opportunities: large trades generate arbitrage opportunities with other DEX/CEX platforms. Taking transaction costs into account, arbitrage opportunities can exactly be anticipated in terms of the trade size. Although arbitrage in AMM designs is necessary for price correction, it comes at the expense of LPs’ profit.

Drivers

  1. Shape of the pricing curve: The slippage effect depends on how strongly the pricing function is curved (cf Figure 6). This led to other pricing functions than CPMM. Nevertheless, improved slippage in one price range leads to higher slippage in other price ranges.
  2. Reserve sizes: large trades generate arbitrage opportunities with other DEX/CEX platforms. Taking transaction costs into account, arbitrage opportunities can exactly be anticipated in terms of the trade size. Although arbitrage in AMM designs is necessary for price correction, it comes at the expense of LPs’ profit. 


  3. Inefficient use of capital: In a CPMM liquidity is provided at all “price levels”. Although trades might occur only in a certain price range, part of the liquidity is reserved for prices outside that range and is “unused”. This leads to higher slippage for the actual performed trades.

Impermanent (or Divergence) Loss: is a phenomenon which was already discussed in [4]. To understand this issue, consider the total market value of the token pair X and Y: mv(x,y)=p*x + y with p the marginal price of token X. When the reserves update to xnew ,ynew and the marginal price changes accordingly to the new price pnew, the market value shrinks (and so do the LPs). Basically, the reserve which is higher priced shrinks in size, and the lower priced side increases. This loss is called impermanent or divergence loss and is defined by

dl=(mv(xnew,ynew)-mv(x,y))/mv(x,y)

For Uniswap V2 the divergence loss can be compactly written in terms of the ratio r= pnew / p as

dl = 2 * sqrt(r)/(1+ r) – 1.

Figure 5: Depositing tokens to the reserve pool.

In our example the ratio after the trade is r=2.5/2 which implies a divergence loss of -0.0062 which means a loss of 0.62% compared to holding the funds and not engaging with providing liquidity. Note that, if the trader is lucky and the price ratio moves back to when she deposited her funds, no loss occurs – therefore, divergence loss is also called impermanent loss.

Impact

Reduction of LP profit: LPs’ profit calculation must consider the potential loss through divergence loss (cf. [6] where it is diagnosed that most AMMs do not provide profit without any additional yield payments).



Possibly higher transaction fees: One way to compensate for the loss can be achieved by increasing trading fees, which causes higher execution price, and therefore may lower the trading volume, and hence LP reward.

Drivers

  1. Volatility: Trading pairs of volatile tokens tend to have a higher divergence ratio, and therefore cause increased loss.
  2. Un-correlated pairs: Trading pairs which are not correlated have non-constant divergence ratios. The higher their divergence ratio, the higher the loss for LPs.

Remark: front-running is a general concern for any application, also for blockchain applications (cf. “MEV”). That impacts any DEX design, and therefore also AMMs based DEXs where special attacks such as sandwich attacks are known. This is out of the scope of this survey.

Innovations

Of course, these problems did not stay unnoticed, and better alternatives emerged over the past years since the launch of Bancor and Uniswap V1.



Low curvature price curve (slippage – driver 1): The pricing curve of Curve.fi is a mix of a constant product and constant sum formula resulting in a much flatter price change at the “center”, i.e. at the initial ratio of the reserves 
(cf. Figure 6). This is tuned for stablecoin pairs which are expected to be mean-preserving. Their AMM allows them 
to trade high amounts with low slippage. Note, however, that when reaching towards the end of the reserves slippage increases much faster. In case of stablecoin pairs, LPs profit from high trade volume and very low divergence loss which made Curve.fi to one of the most successful DEXs next to Uniswap.

Figure 6: The pricing curve of Curve.fi for stablecoin pairs.

Concentrated Liquidity (slippage – driver 3): Uniswap V3 (see [1]) introduces concentrated liquidity and range orders. This is an attempt to improve capital efficiency by allowing to set “price levels” and to attract more professional market makers (see Figure 7). Both can help to decrease slippage.

Concentrated Liquidity

Figure 7: Concentrated liquidity and range orders as in Uniswap V3.

Range orders mimic what limit orders are, although they do not behave in exactly the same way. For instance, an LP can set a price range for which she wants to provide liquidity. Nevertheless, a trade is not executed against her order, but against the reserve, and the range order remains active. This approach shows to have first trading strategies 
(cf. here).

Oracles (slippage – impact 2 & driver 3, divergence loss): instead of using the same pricing curve over all times, protocols such as Balancer, DODO, and Kyber Network feed external market price information into their protocol
and “center” their pricing curve around the tokens fundamental value. This helps to reduce slippage and lowers
the arbitrage opportunities caused by large trades. In the case of DODO, asset prices are adjusted based on primary market information to incentivize arbitrageurs to bring the pool in its initial equilibrium state (initial reserve ratio) eliminating divergence loss. On the other hand, oracles increase the attack surface of their protocols.



With respect to the divergence loss problem, further countermeasure are:



  • Dynamic Fees: instead of fixing the fees at setup, Balancer and Uniswap V3 adjust fees. This can be achieved either by a fee tier or by dynamically based adjustments depending on the volatility. Dynamic fees policies can be a potential solution to cover divergence loss, but increase trade execution costs. It certainly helps against liquidity fragmentation by the desire to set different trading fees.
  • Virtual AMMs: protocols such as Perpetual protocol or Drift employ the product formula, but only for price discovery of derivatives while the locked amount in vaults serve only as collateral. Since there are no actual tokens exchanged, there is no need for liquidity providers. Nevertheless, since price discovery is based on the same rule, the discussion with respect to slippage stays valid also for virtual AMMs. Drift employs dynamic pricing and mentions the funding payments to counteract slippage.
  • Weighted Reserve Sizes: in the CPMM explained above, the reserve sizes x,y had to be chosen such that the marginal price corresponds to the current market price. Balancer introduces weights which allow it to move away from the reserve sizes keeping the market price. This can lower the divergence loss, but it remains a directional bet.
  • Liquidity mining: most protocols allow for yield farming in order to compensate the loss through divergence loss. The downside of it is that it creates inflation of the protocol token.
  • Hedging: using risk-neutral evaluation, impermanent loss can be hedged by simultaneously purchasing European options, both puts and calls.

Conclusions and Outlook

AMMs help to build the first working trustless and non-custodial DEXs. Their appealing simplicity allowed efficient DEX implementations, and still shape today’s DeFi landscape. Since efficient non-custodial and trustless limit order book implementations became possible, too, the question, however, shifts towards the difference of their different market making behavior.

Issues related to the “pure” constant product formula automated market makers concern high slippage and impermanent loss. The former impacts traders and LPs alike, and the latter strongly impacts LPs’ profit causing often even loss. Over the past years we have seen interesting improvements over the initial constant product market maker. For example, AMMs turned out to be a good solution for strongly correlated token pairs, demonstrated by Curve’s specific pricing function. In general, however, it remains open whether AMMs can compete in its simple structure with CLOBs. Only a few studies of these new markets and their interplays with other exchanges are available (e.g. [3]).

In the next post, the fundamental difference between AMMs and CLOBs will be taken under focus.

References

  1. H. Adams et al.; Uniswap V3. 2021.
  2. G. Angeris, A. Evans, T. Chitra; When does the tail wag the dog? Curvature and market making, 2020.
  3. Y. Aoyagi and Y. Ito; Coexisting Exchange Platforms: Limit Order Books and Automated Market Makers, 4D5966
  4. Pintail; Uniswap: A Good Deal for Liquidity Providers?, 2020.
  5. J. Xu et al; SoK: Decentralized Exchanges (DEX) with Automated Market Maker (AMM) protocols, 2022.
  6. KPMG: Crypto Insights #2. Decentralised Exchanges & Automated Market Makers – Innovations, Challenges & Prospects, 2021.

Authors
Youngun
Onemanarmy
Oldman2

You may be interested in these articles

Newsletter

Insights
Your mail
Thank you! Your submission has been received!
Oops! Something went wrong while submitting the form.
Copyright © 2022 C3. All rights reserved. Privacy PolicyCookie PolicyDisclaimer