MoonPay logo
0 minsPublished on 9/6/2024

What is an Automated Market Maker (AMM)? AMMs explained

Learn more about how Automated Market Makers (AMMs) provide liquidity to decentralized exchanges for permissionless cryptocurrency trading.

By Mrig P

 What are Automated Market Makers (AMMs)?

Trading (or swapping) cryptocurrencies is one of the most common transaction types that contributes to the overall activity in the decentralized finance (DeFi) ecosystem. 

The beauty of DeFi is that when conducting a token swap on a decentralized crypto exchange (DEX), users never need a specific counterparty or intermediary. Automated systems called smart contracts manage things end-to-end.

DEXs rely on a special kind of system called automated market makers (AMMs) to facilitate trades in the absence of counterparties or intermediaries.

But what exactly are AMMs?

This article explains what automated market makers are, how they work, and why they are critical to the DeFi ecosystem.

What is an automated market maker (AMM)?

An automated market maker (AMM) is an autonomous protocol that decentralized crypto exchanges (DEXs) use to facilitate crypto trades on a blockchain. Instead of trading with a counterparty, AMMs allow users to trade their digital assets against liquidity stored in smart contracts, called liquidity pools.

Conversely, centralized exchanges (CEXs) use an order book to match a buyer with a seller to execute a cryptocurrency trade at a mutually agreed exchange price.

AMMs introduce two fundamental changes to crypto trading:

No waiting time

Traders don’t need to wait for a counterparty when using an AMM. Instead, they interact with smart contracts to buy, sell, or trade assets. These smart contracts use the asset liquidity contributed by liquidity providers to execute trades.

Algorithmically determined exchange prices

The supply-demand ratio of cryptocurrency trading pairs determines their exchange rates. For example, if a token's liquidity supply exceeds demand in the liquidity pool, it will lead to a fall in its prices, and vice versa.

How do automated market makers work?

AMMs work by replacing the traditional order book model with mathematical formulas and logic wrapped in smart contracts. 

To further understand how AMMs work, let’s take a look at the key components that make up an AMM and how they function.

Liquidity pools and liquidity providers

A liquidity pool refers to a digital pool of crypto assets present within a smart contract on a blockchain. These pools typically have two tokens, but in some instances, they may have more than two tokens.

Liquidity providers deposit two or more tokens in a liquidity pool such that the proportion of the tokens has a 1:1 price ratio.

An illustration of how liquidity pools work
How liquidity pools work

For example, in an ETH/USDC liquidity pool, if 1 ETH is worth 2000 USDC at the time of deposit, a liquidity provider must deposit both ETH and USDC in the proportion of 1:2000. 

In DeFi protocols like an automated market maker, any person can create liquidity pools and add liquidity to trading pairs. Liquidity providers then receive LP tokens against their deposits which represent their share in the liquidity pool. These tokens are redeemable when the liquidity provider exits the pool. 

DEXs reward users with a portion of transaction fees and, at times, additional governance tokens for providing liquidity. 

Acting as a liquidity provider comes with risks too.

Liquidity providers take on the risk of impermanent loss, a potential loss that they might incur if the value of the underlying token pair drastically changes in either direction. If the loss is greater than the gain obtained through collecting trading fees, the liquidity provider would have been better off just HODLing the tokens.

Now that you know how liquidity pools work, let's understand the nature of pricing algorithms.

Pricing Algorithm

With centralized exchanges, a buyer can see all the asks, such as the prices at which sellers are willing to sell a given cryptocurrency. While this offers more options for a buyer to purchase crypto assets, the waiting time for a perfect match may be too long for their liking.

Other disadvantages of CEXs include front-running bots and the absence of enough sellers.

However, in an AMM, there is a certain price which is ‘a take-it or leave-it’ offer made by the smart contract that runs the liquidity pool. This offer is based on a mathematical formula ‘x*y=k’, where, 

x: quantity of Asset A, 

y: quantity of Asset B, 

k: is a constant and a product of x and y.

Now, how does this equation turn into a pricing algorithm?

AMM transaction process

Imagine a BTC/USDT liquidity pool, and the initial exchange ratio is set at 1 BTC = 25,000 USDT. 

The pool consists of an initial 10 BTC and 250,000 USDT. So, trades in this liquidity pool can either be:

  • Add USDT to receive a corresponding quantity of BTC from the pool, or 
  • Add BTC to receive a corresponding quantity of USDT.

Now, let's say Bob wants to add 50,000 USDT to the pool. How much BTC will he receive? 

Note: This example uses the formula (x * y = k) of a Constant product market maker (CPMM), a popular type of automated market maker that is also the basis on which other AMM variants evolved. We'll cover CPMMs and some popular types of AMMs below.

Previous state of the pool:

  • Reserves: x: 10 BTC | y: 250,000 USDT
  • Value: k: 2,500,000 

In dollar terms, 1 BTC = $25000, and 1 USDT = $1.

Now, Bob’s transaction adds 50,000 USDT.

Current state of the pool

  • Reserves: x: ? BTC | y: 300,000 USDT
  • Value: k: 2,500,000 (constant)

Since there is more USDT now than before in the pool, this means there is more demand for BTC, making it more valuable. This is where market supply and demand act to change the initial exchange price of BTC, which was equal to 25,000 USDT.

So, how much BTC does Bob receive?

To get that number, we must solve for “x * y = k” 

x * 300,000 = 2,500,000

x = 2,500,000 / 300,000 = 8.33

By this constant equation, the BTC quantity (x) in the pool should be 8.33 and not 10 as in the first place. That means, on adding 50,000 USDT to the pool, Bob would receive 1.67 BTC (10 - 8.33).

Post-Bob’s transaction state of the pool:

  • Reserves: x: 8.33 | y: 300,000 USDT
  • Value: k: 2,500,000 (constant)

This is how an AMM transaction works and also the way an AMM acts as both liquidity provider and pricing system. Due to the versatility of AMMs, some of the most popular DEXs like Curve, Uniswap, and Bancor use a similar mechanism to operate.

Now, let’s look at the different types of AMMs currently in action.

What are the different types of AMM models?

Constant product market maker (CPMM)

Constant product market makers (CPMMs) are the first type of automated market maker (AMM), introduced by Bancor in 2017. A year later, the launch of Uniswap made the CPMM model even more popular. 

CPMMs function on both the logic and equation we discussed above (x * y = k).

As per the formula, if the supply of one token (x) increases, the supply of the other token (y) must decrease, and vice versa, to uphold the constant value (k).

Constant sum market maker (CSMM)

Constant sum market makers (CSMMs) are an AMM variant that use the sum of two tokens as the basis, unlike CPMM which uses the product

The equation behind this is x + y = k. Accordingly, when one token's supply increases, the other token's supply decreases proportionally to uphold the constant sum (k). 

CPMM vs CSMM illustration.
CSMMs differ from CPMMs in their use of the sum vs the product of two tokens (Image source)

The risk of slippage is pretty low in a CSMM model compared to other types. This is because the trade size doesn’t affect the exchange price present in the liquidity pool.

Despite this, CSMMs are rarely used as a standalone market maker, due to liquidity concerns about handling large trades. 

Constant mean market maker (CMMM)

Constant mean market makers (CMMMs) introduce liquidity pools with more than 2 tokens within a pool. The equation for CMMM is (x*y*z) ⅓ = k where the geometric mean of each reserve is the constant (k). 

This type of AMM also allows for locking tokens in a proportion that is not always fixed at 50:50. In a way, CMMMs democratize AMMs by removing restrictions like two-token pools, equal distribution, etc.

Balancer made CMMM popular by pooling its liquidity into one CMMM pool rather than multiple unrelated liquidity pools. CMMMs stand out with some interesting use cases such as one-tap portfolio services and index investing.

These first-generation AMM variants are powering some of the most reliable AMM-based DEXs in the current DeFi ecosystem. Here are some of the most popular ones by volume and market cap:

Uniswap

Uniswap is an Ethereum-based decentralized exchange that leverages AMMs to offer a liquidity-rich DEX for traders. 

The DEX started with the popular x * y = k AMM model, though it has consistently evolved to provide better service to users. It's currently running its 3rd version — Uniswap V3

A pie chart of the Uniswap (UNI) token supply and distribution.
Uniswap (UNI) token supply and distribution

Every Uniswap version works on improving the user experience. For instance, Uniswap V2 offered traders the ability to create liquidity for ERC-20 token trading pairs. And V3 offers concentrated liquidity, a feature that lets liquidity providers earn similar trading fees at lower risk, since not all their capital is at stake.

The competitive advantage of Uniswap lies in its peerless high liquidity, financial incentives in UNI rewards, and technological evolution.

Did you know? Uniswap is a market maker giant with over $3 billion total value locked (TVL), dominating over 59% of overall DEX volume.

Curve

Curve Finance is an automated market maker-based DEX with a unique positioning of being a dominating stablecoin exchange. This enables Curve to be a reliable DEX with low slippage since prices of stablecoins are usually less volatile than many other cryptocurrencies (usually within a price band of $0.95 - $1.05). 

A pie chart of the Curve (CRV) token supply and distribution.
Curve (CRV) token supply and distribution

Additionally, Curve offers multiple passive income opportunities like factory pools, metapools, and lending pools for liquidity providers (LPs). Each of these earns variable amounts of yield for LPs against their associated risks. Besides earning a share of transaction fees, users that provide liquidity will also earn additional CRV tokens that carry voting rights.

By prioritizing pegged assets, Curve is a reliable market maker for large trades, opening up specific use cases like crypto ETFs.

Did you know? Curve Finance executed a $2.5 million sUSD-USDC trade that cost less than $2 in gas fees.

Balancer

Balancer is an AMM-based decentralized exchange that launched in 2020. It uses the CMMM model to take AMM offerings a step further. Balancer offers multi-asset pools to increase exposure to different crypto assets and deepen liquidity. 

A pie chart of the Balancer (BAL) token supply and distribution.
Balancer (BAL) token supply and distribution

To refine this further, the platform offers customizable weights for the assets in a single pool. This provides a granular level of control for traders to adjust where their digital assets are deployed, rather than a generic 50:50 ratio.

Through this feature, Balancer has a competitive advantage of higher gas efficiency and deeper liquidity compared to many of its peers. However, the complexity of the platform may somewhat hinder its growth potential and ease-of-use for beginners. 

Uniswap, Curve, and Balancer are prominent first-generation automated market makers, but they are not without their defects.

Risks of first-gen automated market makers

Impermanent loss

Impermanent loss occurs when the price ratio of pooled assets deviates from the tokens' initial values. Liquidity providers automatically incur losses if and only when they withdraw funds during a period of such fluctuation. 

The greater the price shift, the more significant the loss, particularly in pools with volatile digital assets. However, this loss will not occur if asset prices normalize before withdrawal, hence the term 'impermanent.'

A screenshot of a graph representing impermanent loss.
(Image source)

To put it another way, impermanent loss is the opportunity cost that LPs take on by providing liquidity instead of just holding their digital assets.

Slippage risks

A slippage risk in AMMs refers to the potential change in the price of an asset between the time a trade order is submitted and when it's actually executed. Large trades relative to the pool size can have a significant impact, causing the final execution price to deviate from the market price from when the trade was initiated. 

An image of a MoonPay-shaped pool
Walk, don't run to the liquidity pool (or you may slip)

This price change is referred to as the 'slippage.' Given that AMM pricing algorithms rely on asset ratios within a pool, they can be susceptible to such slippage.

Currently, developers are building newer iterations of AMMs to overcome drawbacks like slippage and impermanent loss, as well as others like security, smart contract vulnerability, and low capital efficiency.

How can the current AMM model be improved?

DeFi is a work in progress. And every few months, we see some groundbreaking changes both in terms of backend operations and frontend experiences. 

Let’s check out some improvements that AMMs might implement.

Hybrid AMM models

This suggested improvement stems from the belief that a standalone AMM model may not suffice to address all challenges. Hybrid models can incorporate working elements of different AMM models to achieve specific outcomes. 

For instance, a hybrid model can combine the CSMM variant's ability to reduce the impact of large trades on the entire pool with the CMMM variant's functionality to enable multi-asset liquidity pools.

The challenge with hybrid models is to stitch these different elements into a robust and reliable AMM fabric. An example of such a model is Curve Finance, which combines CPMM and CSMM models to offer a capital-efficient platform to decentralized exchange pegged assets.

External price sources

AMMs can make use of off-chain sources like price oracles to offer reliable price discovery and capital efficiency. They can use data from real-world external price oracles like Chainlink to determine the current market price of the assets involved. 

This allows AMMs to actively adjust the price in their market to be more in line with the external market price.

Through oracles, DEXs can also concentrate liquidity within these price ranges and enhance capital efficiency. This also reduces the risk of slippage, since prices are more in sync with other markets.

DODO is an example of a decentralized trading protocol that uses external price feeds for its AMM. To date, DODO has facilitated a trading volume of more than $120 billion.

Synthetic assets

Synthetic assets are a way for AMMs to use smart contracts to virtualize the AMM itself, making it more composable. An implementation of this can be seen in virtual AMMs (vAMMs), where market participants trade using synthetic tokens (vDAI for DAI, vETH for ETH, etc.) while their actual crypto is locked in a smart contract. 

This makes synthetic assets more secure because the underlying assets stay untouched while trading activity continues. They also help in risk management since adjusting parameters dynamically based on external market conditions can help mitigate the risk of impermanent loss and slippage.

By using synthetic assets, users make all their trades without relying on their underlying digital assets, making financial products possible in DeFi, including futures, options, and prediction markets.

Begin your DeFi journey

Automated market makers (AMMs) are a critical part of decentralized finance as it continues to take on centralized finance. As AMMs evolve, DeFi becomes a better and more reliable space for traders and financial institutions alike to participate.

To get started in DeFi, simply buy cryptocurrency via MoonPay using your credit card or any other preferred payment method.

MoonPay also makes it easy to sell crypto when you decide it's time to cash out. Simply enter the amount of the token you'd like to sell and enter the details where you want to receive your funds.

Mrig P
Written byMrig P

You might also like