Exchanges

·

June 17, 2024

Crypto AMMs explained

Jonatan Blum

Automated Market Makers power decentralized exchanges and are a core innovation of decentralized finance. Learn what market making is, compare the differences between AMMs, and more!

Decentralized exchanges (DEXs) are central to the concept of a decentralized economy. Most DEXs use programs called Automated Market Markers (AMMs) to coordinate trades through pools of tokens contributed by users. While AMMs are present on almost every DEX, the way they function can vary from one exchange to another. In this article, we’ll take a look at the different types of AMMs and how they function. 

What is market-making?

Market-making is a critical function of financial markets that provides liquidity and ensures the efficient trading of assets. Market makers (MMs) are typically wealthy individuals or specialized trading firms, including private market makers (PMMs) in crypto, who quote both buy and sell prices for a particular asset. 

The primary role of MMs is to facilitate trading by providing liquidity across markets and asset classes including stocks, bonds, currencies, and derivatives. They do this by continuously quoting two-sided markets, offering to buy at the bid price and sell at the asking price, commonly known as an order-book model. 

Centralized crypto exchanges such as Binance and Kraken use the order book model, and market makers play a role in maintaining liquid and available markets on their behalf. By standing ready to buy and sell an asset, they absorb temporary imbalances in supply and demand, allowing traders to enter and exit positions smoothly and helping to enable efficient price discovery.

How market makers settle trades for buyers and sellers.
Market Makers use managed assets to settle trades.

Automated Market Making (AMM) in DeFi

The concept of market making has been adapted and automated in the realm of decentralized finance (DeFi) through the use of Automated Market Makers (AMMs). These are smart contracts that facilitate trading in a decentralized and permissionless manner, enabling liquidity provision without the need for centralized intermediaries. 

In DeFi, market-making is automated through smart contracts deployed on the blockchain. Rather than having designated market makers, such as wealthy individuals or institutions, liquidity can be provided by anyone by locking a certain amount of a pair of tokens into the contract, where they can earn fees whenever they are used to complete a trade. 

For liquidity providers (LPs), it is important to be aware of impermanent loss that can occur with volatile trading pairs. If you provide liquidity using two assets and the price of one asset rises, the amount of tokens in the pool is rebalanced so that both asset pools are equal to the same value. As the price moves, there is more of the less valuable asset in the pool. This means that if you withdraw your assets, you will receive less of the valuable token than you initially committed, potentially resulting in a loss compared to simply holding the assets in your wallet. It is impermanent because should prices return back, the loss is unrealized and the LP makes a profit from fees.

AMMs also introduce the phenomenon known as slippage, where prices change before a trade is processed onchain.

Graphic showing the two-sided marketplace of a DEX between Liquidity providers and Traders.
DEXs use smart contracts to run a two-sided marketplace, with traders on one side and liquidity providers on the other.

AMMs are crucial components of DeFi. They provide the liquidity and trading infrastructure so that millions of crypto tokens can be traded with minimal friction at any time. 

Without AMMs, DEXs would have difficulty facilitating trading in a trustless and permissionless manner. Onchain order books such as 0x Mesh provided an alternative way to conduct peer-to-peer order matching, even for low-liquidity markets, but did not offer the scalability of AMMs.

Early DEXs built on AMMs

One of the first major DEXs to pioneer the use of AMMs for automated liquidity provision and decentralized asset exchange (swaps) was Uniswap. Launched in November 2018 as open-source software, Uniswap v1 introduced a novel approach to facilitating trading using the constant product market maker model (CPMM), which used liquidity pools consisting of pairs of ETH and ERC20 tokens. 

These pools were created and funded by liquidity providers, who would deposit an equivalent value of both tokens in the pair. The constant product formula x * y = k, where x and y are the two tokens in the pair and k is a constant, was used to determine the pricing and execute trades in an automated and decentralized way. 

Liquidity pool token balances change with asset prices to equal a constant value
How token balances change to maintain a constant.

Uniswap has since updated its own protocol to Uniswap v2 and later Uniswap v3, introducing features like concentrated liquidity and improved capital efficiency for liquidity providers. The success of Uniswap's AMM model and its open-source license paved the way for numerous other DEXs and AMM protocols to emerge across various blockchain ecosystems. 

Examples of popular DEXs

  • Sushiswap: Sushiswap was a fork of Uniswap for Polygon but has since evolved with its own innovations. It provided trading on more chains and assets than Uniswap and has also introduced cross-chain swaps and limit orders. 
  • Pancakeswap: Pancakeswap is a leading DEX on the Binance Smart Chain. It is known for its user experience and attractive yields for liquidity providers. It has integrated features like lottery and prediction markets.
  • Curve: Curve is a specialized AMM designed for efficient trading of stablecoins and other low-volatility assets. It introduced the concept of "StableSwap" pools, which use a different pricing curve optimized for minimal slippage when trading similar assets.
  • Raydium: Raydium is an AMM-based DEX built on the Solana blockchain, leveraging Solana's high throughput and low fees. It has implemented concentrated liquidity and order book functionality alongside its AMM model.
  • Trader Joe: Trader Joe is a DEX on the Avalanche network. It offers various AMM pool types, such as constant product, stableswap, and concentrated liquidity. It has implemented features like liquidity mining and limit order functionality.

How different AMMs manage pooled liquidity

As of today, the DeFi space has evolved with numerous AMM models each with its own perks and features. 

Constant-product AMM (Uniswap v2)

Maintains the constant x*y=k by adjusting prices based on reserves.

Uniswap v2 built upon the success of the same CPMM model as v1 but introduced several improvements:

  • Support for ERC-20  token pairs beyond just ETH-ERC20 pairs
  • Price oracles for more accurate pricing
  • Flash swaps for advanced trading strategies
  • Core protocol fee (0.05% on swaps) to capture value for token holders

Concentrated liquidity CPMM (Uniswap v3)

Allows LPs to concentrate capital within custom price ranges for improved capital efficiency.

Uniswap v3 aimed to improve capital efficiency within the constant-product AMM model by introducing the concept of concentrated liquidity. In this model, liquidity providers can concentrate their capital to only operate within a custom price range, allowing for more efficient use of their funds. Key features of Uniswap v3 include:

  • Concentrated liquidity positions within customized price ranges
  • Multiple fee tiers (0.05%, 0.30%, and 1.00%) for different levels of risk
  • Improved oracle solution for more accurate pricing
  • Support for liquidity positions through LP Tokens represented as NFTs

Uniswap v3's concentrated liquidity model has since been widely adopted by other DEXs. It offers improved capital efficiency and boosted rewards for liquidity providers while still adhering to the core principles of automated market making. This table compares the different versions of Uniswap AMMs:

AMM Version v1 v2 v3
Token pairs ETH → ERC-20 ETH or ERC-20 → ERC-20 ETH or ERC-20 → ERC-20
Liquidity range 0 → ∞ 0 → ∞ Ra → Rb (range set by LP)

Constant-Sum AMM (CSMM)

Assets are priced based on their ratio to the total pool value to maintain a constant sum.

The constant-sum AMM (CSMM) model is an alternative approach to the constant-product AMM used by Uniswap. In a constant-sum AMM, the total value of the liquidity pool is kept constant, rather than the product of the token reserves. This model is less popular because it allows for the entire pool to be drained easily, however, it is particularly suited for pools consisting of assets with similar values, such as stablecoins. Trader Joe is one example of a Constant-Sum AMM, but with concentrated liquidity.

Stableswap AMM (Curve)

Optimized for low-volatility stablecoin trading by using specialized pricing functions.

Curve is a prominent stableswap DEX that pioneered the use of the "Stableswap" AMM model, which is a variant of the constant function AMM (CFAMM) design. Stableswaps are optimized specifically for trading between stablecoins and other low-volatility assets. The model is great for less volatile asset pairs pegged to the same asset such as the dollar or gold. Importantly, providing liquidity in such same asset-backed pairs reduces the pain points of impermanent loss, because even if the token ratio between tokens changes, the value remains the same. 

The key innovation of Curve's Stableswap is the use of a specialized pricing function that aims to minimize slippage when trading between similar assets. This function adjusts the prices of the assets in the pool based on their relative weights, ensuring that large trades have minimal impact on the prices. Stableswap pools have become popular for efficiently swapping between various stablecoins, such as DAI, USDC, and USDT, with low slippage and fees. The protocol has also expanded to support other low-volatility assets like wrapped Bitcoin and Ethereum. By tailoring the AMM model for low-volatility assets, Curve carved out a niche in the DeFi ecosystem, providing a reliable and efficient platform for trading stablecoins and similar assets.

Comparison of AMM bonding curve models

The graph below reflects how these main AMM models compare to one another. 

The red dotted line shows a CSMM model, which doesn’t curve. This is because it lets users swap all the assets of a liquidity pool at a given price. 

With the more common CPMM variant (in pink), the model enables flexible asset trading, but slippage is increased as the trade moves on the curved line - the bigger the trade, the more it will move up or down. 

Lastly, the stable swap CFAMM variant in blue offers great options for stable pairs as it’s a middle-path solution that retains the bonding curve but at a lesser degree than CPMM. 

Graph showing the different bonding curves of various AMM models
Comparison of price discovery bonding curves: Constant-product AMM (Uniswap v1), Constant-Sum AMM, and Constant Function (Curve Stableswap)

What are DEX Aggregators?

While DEXs provide trading across assets, DEX aggregators provide efficient trading across multiple DEXs and even multiple blockchain networks, enabling a unified trading experience. By aggregating DEXs and liquidity, DEX aggregators help mitigate the problem of liquidity fragmentation and reduce the impact of trades on a single liquidity pool, offering traders better execution prices. Matcha is an EVM-focused DEX aggregator and Jupiter is an example of a popular aggregator on Solana. 

Trading on Matcha vs DEXs

Matcha is unique in that it provides unmatched token trading and features. Aggregating over 130+ DEXs across 9 networks, provides access to over 6 million tokens. In addition, dynamic routing executes trades across the most efficient paths, optimizing for factors like slippage, transaction costs, and price impact.

Trading on DEXs Trading on Matcha
Fragmentation: Trading on individual DEXs often means dealing with more fragmented liquidity pools and potentially higher slippage and price impact, especially for larger trade sizes. Each DEX operates in its own liquidity silo, making it challenging to find the best prices and deepest liquidity across the entire DeFi ecosystem. Matcha seamless trading: In contrast, Matcha aggregates liquidity from over 130 DEXs across multiple networks, giving traders access to vast, unified liquidity across 6+ million tokens. By routing orders through the most efficient paths, Matcha provides superior pricing compared to trading on any single DEX.
MEV and front-running: Additionally, individual DEXs may be more susceptible to issues like maximal extractable value (MEV) and front-running, leading to unfair trade execution. MEV & front-running protection: MEV protection shields traders from these tactics and ensures transparent, reliable trade fulfillment.
Trade lock-in: Trading on DEXs locks you in to a limited supply of liquidity. In addition, many DEXs including Uniswap charge a flat fee on trades conducted through the platform. Multiple trading choices: Matcha offers custom trade parameters for advanced users to trade with no added fees, ensuring you get the most out of every trade. This makes Matcha a cost-effective solution, especially for larger trades.

While individual DEXs offer powerful decentralized trading, Matcha takes it a step further by aggregating liquidity from exchanges, optimizing trade execution, protecting against MEV, streamlining fees, and providing a user-friendly, cross-chain trading experience – advantages that are difficult to achieve when trading on individual DEXs alone.

Want to trade on Matcha? Read how to trade on matcha dex aggregator!

AMMs and aggregators are the core of DeFi!

The rise of AMMs has revolutionized liquidity provision and decentralized trading. AMMs have continuously evolved to address the challenges of capital efficiency, slippage, and impermanent loss through constantly improved pricing models. 

The true power of AMMs lies in their ability to pool liquidity from multiple sources, breaking down barriers for market makers. DEX aggregators like Matcha help reduce fragmentation between this pooled liquidity to improve the user experience of decentralized trading overall. By dynamically optimizing trade execution and implementing robust access to liquidity, aggregators offer superior pricing and trade fulfillment compared to individual DEXs. 

As DeFi grows, AMM DEXs and DEX aggregators will only become more important. They facilitate seamless trading across assets and blockchain networks, unlocking new possibilities for capital efficiency, liquidity provisioning, and decentralized market-making in an open, permissionless, and efficient financial ecosystem.

Contents
Subscribe to our newsletter
By submitting you're confirming that you agree with our Terms and Conditions.
Yay! You’re signed up.
Oops! Something went wrong, but it's not your fault.
Exchanges

·

June 17, 2024

Crypto AMMs explained

Your guide to Crypto AMMs

Automated Market Makers power decentralized exchanges and are a core innovation of decentralized finance. Learn what market making is, compare the differences between AMMs, and more!

Decentralized exchanges (DEXs) are central to the concept of a decentralized economy. Most DEXs use programs called Automated Market Markers (AMMs) to coordinate trades through pools of tokens contributed by users. While AMMs are present on almost every DEX, the way they function can vary from one exchange to another. In this article, we’ll take a look at the different types of AMMs and how they function. 

What is market-making?

Market-making is a critical function of financial markets that provides liquidity and ensures the efficient trading of assets. Market makers (MMs) are typically wealthy individuals or specialized trading firms, including private market makers (PMMs) in crypto, who quote both buy and sell prices for a particular asset. 

The primary role of MMs is to facilitate trading by providing liquidity across markets and asset classes including stocks, bonds, currencies, and derivatives. They do this by continuously quoting two-sided markets, offering to buy at the bid price and sell at the asking price, commonly known as an order-book model. 

Centralized crypto exchanges such as Binance and Kraken use the order book model, and market makers play a role in maintaining liquid and available markets on their behalf. By standing ready to buy and sell an asset, they absorb temporary imbalances in supply and demand, allowing traders to enter and exit positions smoothly and helping to enable efficient price discovery.

How market makers settle trades for buyers and sellers.
Market Makers use managed assets to settle trades.

Automated Market Making (AMM) in DeFi

The concept of market making has been adapted and automated in the realm of decentralized finance (DeFi) through the use of Automated Market Makers (AMMs). These are smart contracts that facilitate trading in a decentralized and permissionless manner, enabling liquidity provision without the need for centralized intermediaries. 

In DeFi, market-making is automated through smart contracts deployed on the blockchain. Rather than having designated market makers, such as wealthy individuals or institutions, liquidity can be provided by anyone by locking a certain amount of a pair of tokens into the contract, where they can earn fees whenever they are used to complete a trade. 

For liquidity providers (LPs), it is important to be aware of impermanent loss that can occur with volatile trading pairs. If you provide liquidity using two assets and the price of one asset rises, the amount of tokens in the pool is rebalanced so that both asset pools are equal to the same value. As the price moves, there is more of the less valuable asset in the pool. This means that if you withdraw your assets, you will receive less of the valuable token than you initially committed, potentially resulting in a loss compared to simply holding the assets in your wallet. It is impermanent because should prices return back, the loss is unrealized and the LP makes a profit from fees.

AMMs also introduce the phenomenon known as slippage, where prices change before a trade is processed onchain.

Graphic showing the two-sided marketplace of a DEX between Liquidity providers and Traders.
DEXs use smart contracts to run a two-sided marketplace, with traders on one side and liquidity providers on the other.

AMMs are crucial components of DeFi. They provide the liquidity and trading infrastructure so that millions of crypto tokens can be traded with minimal friction at any time. 

Without AMMs, DEXs would have difficulty facilitating trading in a trustless and permissionless manner. Onchain order books such as 0x Mesh provided an alternative way to conduct peer-to-peer order matching, even for low-liquidity markets, but did not offer the scalability of AMMs.

Early DEXs built on AMMs

One of the first major DEXs to pioneer the use of AMMs for automated liquidity provision and decentralized asset exchange (swaps) was Uniswap. Launched in November 2018 as open-source software, Uniswap v1 introduced a novel approach to facilitating trading using the constant product market maker model (CPMM), which used liquidity pools consisting of pairs of ETH and ERC20 tokens. 

These pools were created and funded by liquidity providers, who would deposit an equivalent value of both tokens in the pair. The constant product formula x * y = k, where x and y are the two tokens in the pair and k is a constant, was used to determine the pricing and execute trades in an automated and decentralized way. 

Liquidity pool token balances change with asset prices to equal a constant value
How token balances change to maintain a constant.

Uniswap has since updated its own protocol to Uniswap v2 and later Uniswap v3, introducing features like concentrated liquidity and improved capital efficiency for liquidity providers. The success of Uniswap's AMM model and its open-source license paved the way for numerous other DEXs and AMM protocols to emerge across various blockchain ecosystems. 

Examples of popular DEXs

  • Sushiswap: Sushiswap was a fork of Uniswap for Polygon but has since evolved with its own innovations. It provided trading on more chains and assets than Uniswap and has also introduced cross-chain swaps and limit orders. 
  • Pancakeswap: Pancakeswap is a leading DEX on the Binance Smart Chain. It is known for its user experience and attractive yields for liquidity providers. It has integrated features like lottery and prediction markets.
  • Curve: Curve is a specialized AMM designed for efficient trading of stablecoins and other low-volatility assets. It introduced the concept of "StableSwap" pools, which use a different pricing curve optimized for minimal slippage when trading similar assets.
  • Raydium: Raydium is an AMM-based DEX built on the Solana blockchain, leveraging Solana's high throughput and low fees. It has implemented concentrated liquidity and order book functionality alongside its AMM model.
  • Trader Joe: Trader Joe is a DEX on the Avalanche network. It offers various AMM pool types, such as constant product, stableswap, and concentrated liquidity. It has implemented features like liquidity mining and limit order functionality.

How different AMMs manage pooled liquidity

As of today, the DeFi space has evolved with numerous AMM models each with its own perks and features. 

Constant-product AMM (Uniswap v2)

Maintains the constant x*y=k by adjusting prices based on reserves.

Uniswap v2 built upon the success of the same CPMM model as v1 but introduced several improvements:

  • Support for ERC-20  token pairs beyond just ETH-ERC20 pairs
  • Price oracles for more accurate pricing
  • Flash swaps for advanced trading strategies
  • Core protocol fee (0.05% on swaps) to capture value for token holders

Concentrated liquidity CPMM (Uniswap v3)

Allows LPs to concentrate capital within custom price ranges for improved capital efficiency.

Uniswap v3 aimed to improve capital efficiency within the constant-product AMM model by introducing the concept of concentrated liquidity. In this model, liquidity providers can concentrate their capital to only operate within a custom price range, allowing for more efficient use of their funds. Key features of Uniswap v3 include:

  • Concentrated liquidity positions within customized price ranges
  • Multiple fee tiers (0.05%, 0.30%, and 1.00%) for different levels of risk
  • Improved oracle solution for more accurate pricing
  • Support for liquidity positions through LP Tokens represented as NFTs

Uniswap v3's concentrated liquidity model has since been widely adopted by other DEXs. It offers improved capital efficiency and boosted rewards for liquidity providers while still adhering to the core principles of automated market making. This table compares the different versions of Uniswap AMMs:

AMM Version v1 v2 v3
Token pairs ETH → ERC-20 ETH or ERC-20 → ERC-20 ETH or ERC-20 → ERC-20
Liquidity range 0 → ∞ 0 → ∞ Ra → Rb (range set by LP)

Constant-Sum AMM (CSMM)

Assets are priced based on their ratio to the total pool value to maintain a constant sum.

The constant-sum AMM (CSMM) model is an alternative approach to the constant-product AMM used by Uniswap. In a constant-sum AMM, the total value of the liquidity pool is kept constant, rather than the product of the token reserves. This model is less popular because it allows for the entire pool to be drained easily, however, it is particularly suited for pools consisting of assets with similar values, such as stablecoins. Trader Joe is one example of a Constant-Sum AMM, but with concentrated liquidity.

Stableswap AMM (Curve)

Optimized for low-volatility stablecoin trading by using specialized pricing functions.

Curve is a prominent stableswap DEX that pioneered the use of the "Stableswap" AMM model, which is a variant of the constant function AMM (CFAMM) design. Stableswaps are optimized specifically for trading between stablecoins and other low-volatility assets. The model is great for less volatile asset pairs pegged to the same asset such as the dollar or gold. Importantly, providing liquidity in such same asset-backed pairs reduces the pain points of impermanent loss, because even if the token ratio between tokens changes, the value remains the same. 

The key innovation of Curve's Stableswap is the use of a specialized pricing function that aims to minimize slippage when trading between similar assets. This function adjusts the prices of the assets in the pool based on their relative weights, ensuring that large trades have minimal impact on the prices. Stableswap pools have become popular for efficiently swapping between various stablecoins, such as DAI, USDC, and USDT, with low slippage and fees. The protocol has also expanded to support other low-volatility assets like wrapped Bitcoin and Ethereum. By tailoring the AMM model for low-volatility assets, Curve carved out a niche in the DeFi ecosystem, providing a reliable and efficient platform for trading stablecoins and similar assets.

Comparison of AMM bonding curve models

The graph below reflects how these main AMM models compare to one another. 

The red dotted line shows a CSMM model, which doesn’t curve. This is because it lets users swap all the assets of a liquidity pool at a given price. 

With the more common CPMM variant (in pink), the model enables flexible asset trading, but slippage is increased as the trade moves on the curved line - the bigger the trade, the more it will move up or down. 

Lastly, the stable swap CFAMM variant in blue offers great options for stable pairs as it’s a middle-path solution that retains the bonding curve but at a lesser degree than CPMM. 

Graph showing the different bonding curves of various AMM models
Comparison of price discovery bonding curves: Constant-product AMM (Uniswap v1), Constant-Sum AMM, and Constant Function (Curve Stableswap)

What are DEX Aggregators?

While DEXs provide trading across assets, DEX aggregators provide efficient trading across multiple DEXs and even multiple blockchain networks, enabling a unified trading experience. By aggregating DEXs and liquidity, DEX aggregators help mitigate the problem of liquidity fragmentation and reduce the impact of trades on a single liquidity pool, offering traders better execution prices. Matcha is an EVM-focused DEX aggregator and Jupiter is an example of a popular aggregator on Solana. 

Trading on Matcha vs DEXs

Matcha is unique in that it provides unmatched token trading and features. Aggregating over 130+ DEXs across 9 networks, provides access to over 6 million tokens. In addition, dynamic routing executes trades across the most efficient paths, optimizing for factors like slippage, transaction costs, and price impact.

Trading on DEXs Trading on Matcha
Fragmentation: Trading on individual DEXs often means dealing with more fragmented liquidity pools and potentially higher slippage and price impact, especially for larger trade sizes. Each DEX operates in its own liquidity silo, making it challenging to find the best prices and deepest liquidity across the entire DeFi ecosystem. Matcha seamless trading: In contrast, Matcha aggregates liquidity from over 130 DEXs across multiple networks, giving traders access to vast, unified liquidity across 6+ million tokens. By routing orders through the most efficient paths, Matcha provides superior pricing compared to trading on any single DEX.
MEV and front-running: Additionally, individual DEXs may be more susceptible to issues like maximal extractable value (MEV) and front-running, leading to unfair trade execution. MEV & front-running protection: MEV protection shields traders from these tactics and ensures transparent, reliable trade fulfillment.
Trade lock-in: Trading on DEXs locks you in to a limited supply of liquidity. In addition, many DEXs including Uniswap charge a flat fee on trades conducted through the platform. Multiple trading choices: Matcha offers custom trade parameters for advanced users to trade with no added fees, ensuring you get the most out of every trade. This makes Matcha a cost-effective solution, especially for larger trades.

While individual DEXs offer powerful decentralized trading, Matcha takes it a step further by aggregating liquidity from exchanges, optimizing trade execution, protecting against MEV, streamlining fees, and providing a user-friendly, cross-chain trading experience – advantages that are difficult to achieve when trading on individual DEXs alone.

Want to trade on Matcha? Read how to trade on matcha dex aggregator!

AMMs and aggregators are the core of DeFi!

The rise of AMMs has revolutionized liquidity provision and decentralized trading. AMMs have continuously evolved to address the challenges of capital efficiency, slippage, and impermanent loss through constantly improved pricing models. 

The true power of AMMs lies in their ability to pool liquidity from multiple sources, breaking down barriers for market makers. DEX aggregators like Matcha help reduce fragmentation between this pooled liquidity to improve the user experience of decentralized trading overall. By dynamically optimizing trade execution and implementing robust access to liquidity, aggregators offer superior pricing and trade fulfillment compared to individual DEXs. 

As DeFi grows, AMM DEXs and DEX aggregators will only become more important. They facilitate seamless trading across assets and blockchain networks, unlocking new possibilities for capital efficiency, liquidity provisioning, and decentralized market-making in an open, permissionless, and efficient financial ecosystem.

Subscribe for an instantly better inbox

By submitting you're confirming that you agree with our Terms and Conditions.
Yay! You’re signed up.
Oops! Something went wrong while submitting the form.