Paradigm: Understanding what automated market makers are, what exactly is AMM doing? Part 1

share
Paradigm: Understanding what automated market makers are, what exactly is AMM doing? Part 1

Every day, tens of thousands of users are using decentralized exchanges (DEX) for the first time. Even for those familiar with traditional trading platforms, the characteristics of public chains often leave newcomers at a loss, resulting in users unwittingly handing their hard-earned money to arbitrageurs and frontrunners, which is worse than doing nothing at all.

(This article is sourced from Paradigm, translated and titled "Understanding Automated Market-Makers, Part 1: Price Impact." Original article here.)

From a broad perspective, we can divide the cost of each transaction into:

Advertisement - Please scroll down for more
  1. Price Impact
  2. Trading Fees
  3. Slippage
  4. Underlying blockchain transaction fees

This article primarily explains Automated Market-Makers (AMM) mechanism as an introductory article for a series and will discuss the users' first and most critical cost: Price Impact.

You will learn:

  • Pricing mechanisms of AMMs such as Uniswap v2, Sushiswap, and Balancer
  • Utilizing simple strategies to minimize the impact of price on trades

What is a Liquidity Pool?

Most DEXs consist of liquidity pools for various trading pairs, such as ETH/WBTC. However, liquidity pools do not match buyers and sellers as in the order book of traditional exchanges; instead, they act as automated market makers.

A liquidity pool is a smart contract that holds a large amount of two or more tokens, allowing anyone to deposit or withdraw tokens based on specific rules.

The specific rule mentioned here is the "constant product formula: x * y = k," where x and y represent the supply of tokens A and B. To buy a certain amount of token A, one must deposit a certain amount of token B to maintain the constant k.

How does an AMM quote?

The constant product formula leads to:

Price of token A = Supply of token B / Supply of token A

Figure 1: Different AMM formulas result in different price curves. For example, in the Uniswap v2 liquidity pool, with 15 units of token Y, a user only needs 0.1 unit of token X to obtain one unit of token Y; whereas if the pool contains only 2.5 units of token Y, the user must trade 4 units of token X to get one unit of token Y.

Other price curves aim to concentrate liquidity primarily around a certain price, such as stablecoins. Source: Curve Finance.

In a real example, as of writing on April 19, 2021, the Uniswap ETH/WBTC pool contained:

  • 2,700 WBTC
  • 86,000 ETH

Calculating according to the constant product formula and supply, the price of ETH would be:

2,700 / 86,000 = 0.0314 WBTC.

The key point is that when prices fluctuate on other trading platforms, AMMs do not update prices automatically. Their prices only fluctuate based on changes in the proportion of tokens in the pool; in other words, the price changes only when someone trades.

For instance, if the price of the trading pair on Binance drops to 0.0310 WBTC, what happens? This indicates that liquidity providers on Uniswap (LPs) are buying Ether above market price, creating arbitrage opportunities. Arbitrageurs can buy "discounted" Ether on Binance and sell it on Uniswap for profit.

Arbitrageurs will continue until the price of the trading pair on Uniswap drops to the same 0.0310 WBTC as Binance, at which point they can no longer arbitrage.

In the example, the arbitrageur sells 550 ETH to the liquidity pool for the trading pair, receiving 17.2 WBTC, only then does the price align. Transaction fees and Gas fees are omitted here.

As a result, even though AMMs do not sync prices with real-world market information, users can still expect price quotes from AMMs because of continuous arbitrage, closely following global market prices.

What is Price Impact?

From the above, we understand how to calculate the current market price based on the proportion of two token supplies in the liquidity pool. However, this market price is for a very small amount of tokens. In reality, users typically trade larger amounts of tokens, and the price for each token increases compared to the previous one.

The difference between the "current market price" and the "expected execution price" is known as Price Impact.

Factors affecting price impact include:

  • The user's trade size relative to the size of the liquidity pool
  • AMM's trading rules such as the constant product formula

Figure 2: Comparing the impact of different order sizes on the average execution price on the left Y-axis and price change on the right Y-axis, both increasing with the size of the trade. The larger the relative trade size in the liquidity pool, the more the execution price deviates from the market price.

Figure 3: Comparing the impact of selling a 10 WBTC order in different-sized Uniswap liquidity pools on the average execution price on the left Y-axis and price change on the right Y-axis.

The size of the pool represents the total amount of the two assets in the pool, with order sizes accounting for 0.19%, 1.85%, and 18.52% of the pool, meaning price changes are roughly twice the size of the user's order.

How to Minimize Price Impact?

As mentioned earlier, price impact can make up a significant portion of trading costs. Here are some simple strategies to minimize it:

Find the Most Liquid Market

Given that price impact stems from order size and pool size, it is essential to find the most liquid pool within the price range of interest to achieve execution prices closest to the market price. Checking the "Token Market Depth Data" on Coingecko can be a good starting point.

Figure 4: UNI trading pairs sorted by liquidity within a 2% spread, noting the price discrepancy between Uniswap and Bitfinex. Source: Coingecko

Explore Platforms Beyond DeFi

While this is an article about AMMs, it's not always the case that you'll get the best trade results on-chain. In fact, since AMMs distribute liquidity across a range of price intervals, liquidity is often not concentrated around the current market price.

Many DEXs are trying to address this issue; for example, Uniswap v3 allows liquidity providers to concentrate liquidity around the current market price, making prices more competitive with centralized exchanges.

When a trade causes a price shift within a DEX, it creates arbitrage opportunities compared to the same trade in other markets. As mentioned earlier, arbitrageurs follow backrun trades, intervening immediately after the trade is completed to rebalance the price to the global market price.

It's easy to understand why the existence of such arbitrage behavior proves the trade was a mistake. Because traders are essentially donating funds to arbitrageurs, this raises a question:

Should you conduct on-chain trades with price impact exceeding 2-3% if there are other trading markets available?

Consider Transaction Fees

AMM's trading fee is 0.30%, meaning a spread of 0.6% between the best buy and sell orders. Within this range, AMM does not provide quotes. Even the most liquid AMM will have an implicit spread of 0.3%.

Minimizing transaction fees is crucial, especially for assets with minimal price movements on centralized exchanges. Therefore, centralized exchanges may be a better platform for executing trades. For comparison, Binance charges a 0.10% fee per trade, while FTX charges 0.07%.

This implies that paying more to use a DEX has other reasons, including retaining full custody, avoiding registration, bypassing KYC or deposit processes. However, users should be aware of the higher execution prices on DEXs, including the implied premium of decentralization or immediate liquidity.

Split Trades

Splitting an order into several smaller trades is crucial for users inclined to trade on DEXs, although there are other platforms in DeFi.

In this scenario, you can incrementally trade in 20% increments and wait for arbitrageurs to rebalance the price. Compared to a single order, five orders will result in a smaller price impact. However, this will increase Gas costs and execution time. This strategy is more effective with larger trade sizes, as fixed Gas costs decrease the overall transaction cost, and it works well for mean-reverting asset classes like stablecoins.

Direct Trade Routes Are Not Always the Cheapest

Not every trade has a corresponding trading pair, and even if it does, using different trade paths for tokens may be cheaper. For instance, tokens A and B may have a trading pair, but if trading through a different path, such as A→ETH→B, offers more liquidity, the trade cost will be lower. Therefore, even if you are solely checking trade paths, a trade aggregator is very useful in this scenario.

Use DEX Aggregators

Lastly, you can utilize DEX aggregators like 1inch, Matcha, or Paraswap. Aggregators in DeFi are akin to smart order routers in traditional finance, working on the principle that AMMs will "sell the first token cheaper than the tenth token."

When a token is traded across many pools, the aggregator buys that token from all pools to minimize price fluctuations. Unlike splitting a trade across a single pair, the aggregator's trades are executed across multiple markets simultaneously, slightly increasing Gas costs compared to single trades due to the manual splitting of trades.

Figure 5: Aggregator's optimal strategy to buy 10 units of $3,200, 50 units of $16,000, 100 units of $32,000, and 200 AAVE units of $64,000 using Ethereum. As trade volume increases, more exchanges are added to the trading path to prevent significant slippage in a single pool. Source: 1inch

Outlook

In the second part of this series, we will focus entirely on slippage. Almost all AMM trades are subject to frontrunning, where traders are willing to accept the maximum slippage. This is a somewhat unique "feature" on public chains, inevitable in the current operation of decentralized exchanges. These costs can only be transferred, forming what is known as "The Sandwich Trilemma."