What Is an Automated Market Maker (AMM)?

BeginnerJan 16, 2023
A tool for price regulation of digital assets in Decentralized Finance (DeFi)
What Is an Automated Market Maker (AMM)?

The automated market maker (AMM) is a major innovation in the crypto space. It relies on automatically executed smart contracts and algorithms to price assets. It not only significantly improved liquidity, but also opened up a new way of making earnings and removed the trust and censorship risks of traditional centralized exchanges. It allows anyone to exchange assets in a fast, easy way. AMMs drive decentralized finance (DeFi) to prosper and have become the foundation of today’s diversified derivative tokens and yield farming strategy.

Decentralized exchanges (DEXs) basically adopt the automatic market maker model, allowing traders to buy or sell cryptocurrencies in liquidity pools via smart contracts. The transaction price is automatically calculated based on the mathematical formula pre-programmed in the smart contract. In contrast, traditional exchanges adopt the order book model to match buying and selling orders.

DEXs encourage users to deposit assets into liquidity pools. Users who deposit assets will become liquidity providers of the trading pair market and can obtain passive income by charging a certain percentage of the trading fees. Anyone can become a trader in liquidity pools or a liquidity provider who deposits assets in the pools. AMMs provide huge liquidity to the cryptocurrency trading market and significantly help improve trading efficiency on the blockchain.

Understanding “Market Maker”

What is a market maker? There are several types of participants in financial markets: investors, speculators (position traders), hedgers, and scalpers. Investors buy and hold an asset for a long time if they are bullish on the industry and the underlying asset; speculators pay close attention to market information and news, trying to go long or short through price trends to make more earnings; hedgers usually run entities and are unwilling to bear the risk of price fluctuation; market makers provide liquidity to the market and conduct repeated transactions in the market in a short period of time to earn spreads.

How do market makers provide liquidity and earn profits? It is completed through a large number of buying and selling orders listed in the order book. The working mechanism of market makers is simple: If someone wants to buy an asset, market makers sell it to them; if someone wants to sell an asset, market makers buy it from them. The counterparty trading with the market maker may not be the same each time, but as long as there is a price difference between the buying and selling behavior - specifically, buying low and selling high - the market maker can make profits in this way.

Only individuals or companies with huge funds can become market makers as they need to continuously provide liquidity. In order to ensure fast transaction speed, there are high requirements for market makers’ equipment and technology. Although technically, any trader who places an order is providing liquidity on the market and hence becomes a market maker, it is not easy for ordinary traders to place orders frequently and make profits continuously.

Market makers play an essential role in the operations of the trading market. They ensure that everyone can buy or sell an asset quickly and conveniently without having to wait for a long time. Without the participation of market makers, buyers often place orders at very low prices because they are unwilling to take the risk that prices may fall, while sellers basically place sell orders at very high prices because they are reluctant to take the risk that prices may rise. This will significantly increase transaction costs and reduce liquidity. To encourage market makers to join, some exchanges offer fee discounts and additional commissions, making the trading market more dynamic and efficient.

What Is an Automated Market Maker (AMM)?

In the early days of DeFi, many DEXs, such as EtherDelta, tried to run trading markets on the blockchain using the order book model but soon encountered several problems. The first one is the scalability issue. At the very beginning when Ethereum was created, it could only process 12~15 transactions per second and took 10~19 seconds to produce a new block. Obviously, this cannot meet market makers’ demands for high-speed and frequent transactions. Besides, the cost of using the blockchain network is also a consideration. Even pending orders and canceled orders require a gas fee, making it difficult for market makers to flexibly cancel orders or place new orders.

The order book model will cause high transaction costs, expensive gas fees, slow transaction speeds, and low liquidity. However, smart contracts-based AMM programs make it possible to track market prices without external instructions and could automatically execute buying and selling orders. AMMs can improve asset liquidity and have become a top choice for many DEXs. The concept of AMM was first proposed by Vitalik Buterin, the founder of Ethereum, in 2017, and was further developed by other well-known DEXs, such as Uniswap, SushiSwap, Balancer, Curve, etc., which hence contributed to a diversity of AMMs we see today.

AMMs are relatively new technology compared to traditional market makers. AMMs create different liquidity pools and trading markets based on smart contracts and automatically adjust prices according to the proportions of each asset in the liquidity pool. For example, on Uniswap, traders exchange tokens directly in liquidity pools instead of placing orders in the order book. If you want to exchange ETH for USDT, you just need to put in a certain amount of ETH and get USDT out in an ETH/USDT liquidity pool. The buying or selling price is calculated by the mathematical formula of the AMM protocol. Trading fees (usually 0.3%) and gas fees of the blockchain are required for every transaction made.

The Role of Liquidity Providers (LPs) in AMMs

In DEXs that use AMM protocols, market makers are not institutions with deep pockets, but all asset holders. When the price of an asset increases or other assets with higher growth potential are discovered, holders will be incentivized to exchange their assets. Decentralized exchanges have created smart contracts called liquidity pools, allowing users to stake assets and become liquidity providers (LPs).

In a DEX, some users provide asset A, while others provide asset B or C, or provide all of them at the same time. When a large number of users provide many different types of assets, a trading market forms. Then the algorithm will calculate the relative price according to the supply and demand of each asset. Then all users who stake assets in the liquidity pool become market makers. They provide liquidity for the market, ensuring that different assets can be exchanged with each other.

In return for providing liquidity, they can charge traders a percentage of transaction fees. In addition, DEXs may incentivize users to provide liquidity by giving out governance tokens. Therefore, the liquidity providers in AMMs are all market makers of an asset trading pair. The DEX protocols use smart contracts to automatically calculate prices 24/7, and provide users with a way to swap, trade, or earn.

Automatic Market Maker (AMM) Price Mechanism

In AMMs, the asset you want to buy or sell is priced by a mathematical formula. Users cannot set the price they want to buy or sell according to their preferences. The liquidity pool will quote a price, at which users can only decide whether to trade or not. This is because the smart contract uses a pre-programmed mathematical formula to automatically adjust the price according to the supply of different assets in the liquidity pool and ensure the ratio of the two assets remains balanced.

Different AMMs and DEXs adopt different quotation algorithms. But generally, these algorithms can be classified into four models as follows:

  1. Constant Product Market Maker (CPMM)

  2. Constant Sum Market Maker (CSMM)

  3. Constant Mean Market Maker (CMMM)

  4. Constant Function Market Makers (CFMM)

Taking the most commonly used CPMM as an example. In CPMM, the product of the amount of two assets, X and Y, in the liquidity pool is a fixed value. Mathematical formula:

X * Y = K

Image: A typical AMM algorithm

For example, Uniswap uses the X * Y = K algorithm, where X is the amount of one token in the liquidity pool, Y is the amount of another token, and K is a fixed constant. Since the product of X and Y always remains the same, when the number of X in the liquidity pool increases, Y will decrease correspondingly to keep K constant, and vice versa.

When traders use the ETH/USDT liquidity pool to buy ETH on Uniswap, they need to add USDT to the pool before they can withdraw ETH from the pool. This will decrease the amount of ETH and increase the amount of USDT in the liquidity pool to make X * Y = K hold. Also, it will drive up the exchange rate of ETH to USDT. Conversely, if more ETH is provided to the liquidity pool, the amount of ETH will increase, and USDT decrease, causing ETH prices to drop.

To better understand how this mathematical formula works in practice, let’s take a simpler example:

Suppose there is a liquidity pool containing 100,000 oranges and 100,000 apples on an AMM-powered exchange. Here, X is the number of oranges and Y apples. According to the formula X * Y = K, K will be:

100,000 * 100,000 = 10,000,000,000

Now, an orange farmer produces 4,000 oranges. If he wants to exchange his 4,000 oranges for apples, he can deposit these oranges into the liquidity pool. Now that there are 104,000 oranges in the pool, how many apples could the orange farmer get?

104,000 oranges * Y apples = 10,000,000,000

Y = 10,000,000,000 / 104,000 = 96153.8

Since only 96153.8 apples are needed in the liquidity pool to make X * Y = K hold. So the orange farmer could get 3,846 apples from the pool.

After this transaction, how do we calculate the price of oranges and apples in the market? When there are 100,000 oranges and 100,000 apples in the liquidity pool from the very beginning, each orange and apple costs $1 in the market.

However, after the transaction by the orange farmer, the number of the two fruits in the liquidity pool changed. There are now 104,000 oranges and 96,154 apples, and the prices of oranges and apples have also changed.

The price of an apple = 100,000/96,154 =$1.04

The price of an orange = 100,000/104,000 = $0.96

In the above example, we can see how an AMM works. When the number of oranges in the pool increases, the number of apples decreases, so apples become rarer relative to oranges, and its price increases. We can see that if the number of any asset in the liquidity pool increases, its price falls.

How Are AMM Prices Kept the Same as That of External Markets?

You may wonder, what if the price of an asset in the liquidity pool differs from that of the external market? A liquidity pool sounds like an isolated place. Then how do you ensure that the price in the liquidity pool is the same as that of the real trading market?

Though assets in the liquidity pool are priced according to their own rules, liquidity providers are not isolated from the external market. When they find the price in the liquidity pool is different from the external prices, an arbitrage opportunity will occur. Traders can exchange assets in the liquidity pool to make profits.

For example, if the price of asset A in the liquidity pool is lower than that of the external market, arbitrageurs can buy asset A from the liquidity pool and sell it at a higher price in the external trading market to earn the spread. Conversely, if the price of asset A in the liquidity pool is higher than that of the external market, arbitrageurs can buy asset A from the external trading market and sell it at a higher price in the liquidity pool to earn the spread.

Because of the arbitrage activities in the market, the AMM algorithm can ensure that the asset price in the liquidity pool will gradually return to a balanced level that is in line with the external market price.

Liquidity Pool Token (LP Token)

In decentralized exchanges, liquidity providers can obtain liquidity pool tokens (LP Tokens) as rewards. LP tokens represent the liquidity provider’s share of the assets in the entire liquidity pool. LP token holders can redeem their assets from the liquidity pool. Therefore, LP tokens are also proof of liquidity provided to the liquidity pool.

On Ethereum, LP tokens are ERC-20 tokens that can be transferred, sold, or even deposited into another pool to earn more. Whenever a user conducts a transaction in the liquidity pool, the LP token holder can charge a proportion of transaction fees. The total fees obtained are proportional to the asset share of the LP token holder in the pool.

For example, let’s say you deposited $100 worth of ETH and $100 worth of DAI ($200 in total) to the ETH/DAI pool, and the total value of the assets in the liquidity pool is $20,000, then your share in the liquidity pool is 1%. If the pool receives $100 of fees from the transaction that day, you will receive 1% of the fee, which is $1.

Alternatively, liquidity providers can also stake LP tokens to get more returns. Staking tokens means locking them in a smart contract for a period of time to gain additional rewards from the protocol. Liquidity providers can also deposit LP tokens into different AMM-powered liquidity pools to make more profits. The act of moving multiple tokens into or out of different DeFi protocols can improve users’ funds’ utilization and maximize profits. The method of providing liquidity to the liquidity pool and using spare assets to obtain passive income is known as liquidity mining or yield farming.

What Is Impermanent Loss?

While being liquidity providers will earn you transaction fees and native tokens, you will face some risks, among which is impermanent loss. When the price of your assets in the liquidity pool differs from that when you deposited it, whether it increases or decreases, you will face impermanent losses.

Image: Impermanence Loss Function

It is called impermanent loss because the loss is temporary and will change as the asset prices fluctuate. The temporary loss will become a permanent loss only after users redeem their assets from the liquidity pool. That is to say, as long as the assets are still in the liquidity pool, impermanent losses are only booked losses. The closer the asset price is to the initial price when it was deposited into the liquidity pool, the smaller the proportion of impermanent losses.

Why does impermanent loss exist whether the price increases or decreases? This is because when the asset price changes, liquidity providers are acting as market makers by selling some of the assets they hold and buying the assets sold by other users.

Taking the liquidity pool of asset A/B trading pair as an example. When the price of asset A rises, the number of asset B in the liquidity pool will increase and A will decrease. That is to say, liquidity providers will reduce the position of asset A whose value is rising, and increase the position of asset B whose value is declining. In this condition, the liquidity provider bears the opportunity cost (risk) that the value of asset A continues to rise.

Inversely, when the price of asset B rises, the number of asset A in the liquidity pool will increase, and B decrease. That is to say, liquidity providers will reduce the position of asset B whose value is rising, and increase the position of asset A whose value is declining. In this condition, the liquidity provider bears the opportunity cost (risk) that the value of asset B continues to rise.

As can be seen from the above example, no matter how the price fluctuates, the liquidity provider bears some risks but gets transaction fees as rewards. The more the price rises or falls, the higher the risk, and the higher the percentage of impermanent losses. Generally, if there is only a slight difference in price changes between the two tokens in the liquidity pool, the transaction fees or additional rewards of the protocol will be sufficient to cover the opportunity cost of impermanent losses.

Pros and Cons of AMM

With the development of DeFi, people have a deeper understanding of the principles and applications of AMMs, as well as their increasingly obvious pros and cons.

Pros:

  1. Compared with the limit order book model of traditional exchanges, AMMs reduce the bid-ask spread in the trading market and create a new revenue-earning approach for users. They effectively improve the liquidity of the overall crypto market.

  2. Assets are swapped in a convenient, fast way. DEXs users can trade with AMM without having to go through account verification or KYC. Anyone with a crypto wallet can trade with AMM protocols.

  3. AMMs also bring liquidity to many cryptos with small market caps. Issuers of these cryptocurrencies can put their tokens into circulation and trade on the blockchain network without paying high listing fees on traditional centralized exchanges.

Cons:

  1. AMMs are nowhere near the traditional order book-based trading market when processing large orders. In the order book-based market, users can place orders at a set price and wait for a large number of buying or selling orders. However, in AMMs, each buying or selling will affect the proportion of assets in the liquidity pool and cause the price to change. Large buying orders will become more expensive, while large selling orders will become ​​cheaper. This phenomenon, called slippage, is more obvious in pools with poor liquidity.

  2. The capital efficiency of the AMM liquidity pool is low because most transactions take place within a narrow price range, which also indicates that the majority of the funds in the liquidity pool are actually spare. They are only used to provide liquidity in case of extreme market volatility.

  3. Liquidity providers will face some risks, such as impermanent losses as described earlier, smart contract code vulnerabilities, hacker attacks, etc.

Conclusion

AMM is a key innovation that has proven to work successfully in DeFi. AMMs follow the original intention of making cryptocurrencies permissionless, trustless, and decentralized, and provide users with a simple, transparent and efficient way to exchange assets and value through automatically executed smart contracts and mathematical formulas. AMMs are free from censorship and even asset freezing from traditional centralized exchanges.

AMM is also an important momentum that drives the rapid development of blockchain. It brings huge liquidity to unpopular trading pairs in the primary market and promotes the advent of liquidity mining, yield farming, and various interest-earning assets and financial derivatives. Today, the vast majority of DEXs on the blockchain, such as Uniswap, Sushiswap, and Curve, are powered by AMM protocol rather than order book. AMMs can be regarded as the foundation of many blockchain applications today.

However, AMM has some disadvantages. While opening up new revenue-earning approaches for liquidity providers, it also comes with the risk of impermanent losses. Problems such as low capital utilization and price slippage are some of the limitations of AMM technology. Despite that, AMM is undergoing continuous improvements, such as Uniswap’s different price range to improve capital utilization and Curve’s stablecoin transaction with low slippage. All in all, AMMs have ushered in an era that supports transparent, decentralized, and efficient blockchain transactions. How to take full advantage of AMM’s strengths and overcome its shortcomings will be a key consideration to further develop this technology.

Tác giả: Piccolo
Thông dịch viên: binyu
(Những) người đánh giá: Hugo、Edward、Ashely、Joyce
* Đầu tư có rủi ro, phải thận trọng khi tham gia thị trường. Thông tin không nhằm mục đích và không cấu thành lời khuyên tài chính hay bất kỳ đề xuất nào khác thuộc bất kỳ hình thức nào được cung cấp hoặc xác nhận bởi Gate.io.
* Không được phép sao chép, truyền tải hoặc đạo nhái bài viết này mà không có sự cho phép của Gate.io. Vi phạm là hành vi vi phạm Luật Bản quyền và có thể phải chịu sự xử lý theo pháp luật.
Bắt đầu giao dịch
Đăng ký và giao dịch để nhận phần thưởng USDTEST trị giá
$100
$5500
Đăng ký ngay