Article featured image

A Comprehensive Guide to Automated Market Makers in DeFi

By Romeo F.
18 Mar 2023
9 min read

Automated Market Makers, commonly known as AMMs, are computer protocols that enable decentralized cryptocurrency trading. In the decentralized finance (DeFi) space, AMMs have gained significant importance due to their role in providing liquidity to various platforms. The purpose of this article is to provide a comprehensive overview of AMMs, including how they work, their significance in the DeFi ecosystem, and their advantages and limitations. By the end of this article, you will have a clear understanding of AMMs and their role in the DeFi landscape.

What are AMMs?

Automated Market Makers (AMMs) are a type of decentralized exchange (DEX) that allows for automated trading of crypto assets without the need for an order book or centralized exchange.

The first AMM introduced in 2017 was Bancor, the Uniswap protocol was launched in 2018 and both have since gained popularity within the DeFi space.

AMMs work by using smart contracts to algorithmically set the price of crypto based on the ratio of its supply and demand. This is done by creating liquidity pools that contain two different cryptocurrencies, with the value of each asset determining its share of the pool.

Traders can then trade between these assets by swapping one for the other, with the smart contract automatically adjusting the price based on the ratio of the two assets in the pool.

You can compare AMMs to TradFi currency exchanges to some degree. If you have ever been to an airport currency exchange booth, you'll see two boards displaying the exchange rates for the currencies you want to exchange.

Let's say you want to exchange US dollars for Euros. You'll notice that the exchange rate is constantly changing due to the supply and demand of the two currencies.

The exchange rate is determined by the market, which means that if a lot of people are buying euros, the exchange rate for euros will increase, and if a lot of people are selling euros, the exchange rate will decrease.

In this scenario, the exchange booth acts as an AMM, as it adjusts the exchange rate automatically based on the market demand and supply for the two currencies, allowing for continuous liquidity provision.

That is pretty much how AMMs work, only instead of having centralized authorities control the market, it’s done through smart contracts.


Types of AMMs


There are primarily two types of AMMs—constant product AMMs such as Uniswap and constant sum AMMs such as Balancer.

Constant product AMMs and constant sum AMMs are two different types of mathematical models that are used to facilitate decentralized trading on DEXs.

In a constant product AMM, also known as an x*y=k AMM, the product of the quantities of two tokens in a liquidity pool remains constant at all times.

Constant product AMMs demonstration

As the price of one token increases, the price of the other token must decrease to keep the product constant. This results in a hyperbolic curve on a price chart that serves as a mathematical representation of the liquidity pool.

On the other hand, in a constant sum AMM (following the X+Y=K formula), the sum of the quantities of two tokens in a liquidity pool remains constant at all times.

Two expressions of the constant function automated market maker model

As the price of one token increases, the quantity of that token in the pool decreases, while the quantity of the other token increases, resulting in a linear price chart.

Both types of AMMs have their unique advantages and disadvantages, and their use cases vary depending on the needs of a particular DEX or DeFi project.

So how is it different from traditional order books?

Order book-based systems, also known as central limit order books, are the traditional way of trading assets.

Order book-based systems operate by matching buy and sell orders on an exchange. These orders are entered by traders into an order book, which lists the prices and quantities of the buy and sell orders.

The orders remain in the order book until they are matched by a corresponding order. When a buy order and a sell order match, the trade is executed at the agreed-upon price.

AMMs, on the other hand, use smart contracts to algorithmically determine the price of an asset based on the ratio of the asset's supply and demand. They do not rely on order books to match buyers and sellers but instead use a liquidity pool.

Traders can trade against the liquidity pool by depositing assets, and the smart contract algorithm will automatically calculate the price based on the deposited assets.

One advantage of AMMs over order book-based systems is their transparency. AMMs are completely transparent, meaning that all transactions are visible on the blockchain.

This transparency allows traders to see the entire history of the liquidity pool, including all trades and fees collected. Order book-based systems, on the other hand, often lack transparency and can be prone to market manipulation.

Another advantage of AMMs is their accessibility. Anyone can become a liquidity provider in an AMM pool by simply depositing assets into the pool. This allows for greater market participation and liquidity provision, as anyone can contribute to the liquidity pool regardless of the size of their holdings.

Order book-based systems, on the other hand, require traders to place orders that must be matched by other traders, which can limit market participation.

We will discuss more on the advantages and disadvantages later in this article.

Role of AMMs in DeFi Liquidity Provision

AMMs play a crucial role in providing liquidity to the DeFi ecosystem.

Liquidity providers (LPs) can deposit funds into a liquidity pool, which is used to facilitate trades. In exchange for their contribution, LPs earn a portion of the trading fees generated by the pool.

The benefits of AMMs in terms of liquidity provision are numerous. First and foremost, they offer increased accessibility to liquidity for users, regardless of their location or market size.

AMMs also provide greater flexibility and control to LPs, who can deposit or withdraw their funds from the pool at any time. Additionally, AMMs offer lower fees compared to centralized exchanges, resulting in more cost-effective trading for users.

By utilizing liquidity pools, AMMs are able to provide liquidity without needing counterparties. This has led to increased efficiency and accessibility in the DeFi market, ultimately benefiting users.

Advantages and Limitations of AMMs

I. Advantages of AMMs


Transparency: AMMs are transparent and predictable, allowing users to see exactly how prices are calculated and how trades are executed.

Accessibility: AMMs provide easy access to liquidity pools for anyone with an internet connection and a cryptocurrency wallet, without the need for a central authority.

Efficiency: AMMs operate 24/7, with no downtime or maintenance needed. Additionally, they are designed to be fast and low-cost, with minimal gas fees.


II. Limitations of AMMs


Impermanent Loss


Impermanent loss is a common phenomenon in AMMs where the price of two assets in a liquidity pool changes relative to one another.

When a liquidity provider provides the equal value of two assets to the pool, the liquidity provider receives shares in the pool proportional to their contribution.

However, if the price of one asset changes relative to the other asset, then the liquidity provider may suffer a loss when they withdraw their funds. This is because the value of the shares they receive may be worth less than the value of the assets they originally deposited.

This loss is considered impermanent because it only occurs if the price of the assets in the pool changes, and the liquidity provider can choose to hold their shares in the pool until the price returns to its original level.


How to mitigate impermanent loss?

To mitigate impermanent loss, there are several strategies that liquidity providers can use. One approach is to only provide liquidity for assets that are expected to have relatively stable prices.

You can use liquidity provision incentives, such as rewards or fees, to encourage liquidity providers to hold their positions for longer periods of time.


Price Slippage


Price slippage refers to the difference between the expected price of an asset and the actual executed price. In AMMs, price slippage occurs when the trade volume is larger than the available liquidity in the AMM pool, resulting in the price of the traded asset being impacted.

This is because the AMM's algorithmic pricing function adjusts the price based on the size of the trade, causing the price to move as the trade size increases. This can result in the trader receiving less of the asset they are buying or selling than they anticipated, and it can lead to significant losses for large trades.


How to mitigate price slippage?

You can mitigate price slippage by splitting up larger trades into smaller transactions, which can help ensure that there is enough liquidity available in the AMM pool to complete each trade at a reasonable price.

Another strategy is to use limit orders, which allow traders to specify the maximum price they are willing to pay for an asset.

It’s important to note that despite the benefits of AMMs, they are still relatively new and carry some degree of risk. Smart contracts can have vulnerabilities that may be exploited by attackers, leading to loss of funds.

Conclusion

In conclusion, Automated Market Makers (AMMs) have become a critical component of the DeFi ecosystem, providing a new way for users to exchange assets and provide liquidity.

The advantages of AMMs, such as transparency and accessibility, have led to their widespread adoption, but they also have limitations, such as impermanent loss and price slippage.

Nevertheless, AMMs are constantly evolving, with new developments such as the integration of oracles and the use of layer-two solutions on the horizon.

As the DeFi space continues to grow, it's clear that AMMs will play an increasingly important role in shaping the future of decentralized finance.


Want to Learn more about DeFi? Dyor is here to help.


Dyor is building an investor-friendly decentralized platform to help you navigate and invest in Web3 and DeFi easily. With its unique Swipe-to-Invest interface, access to real user-generated data, and an active community of investors & contributors, Dyor is driven to simplify access to DeFi for all. Learn more on dyor.exchange


Article tags

Follow Dyor

Share the article

© 2024 Dyor Labs. All rights reserved.