Automated Market Makers (AMMs): How They Work in DeFi

Automated Market Makers (AMMs): How They Work in DeFi - featured image

If you’ve ever tried to buy stocks in traditional markets, you’d probably have to wait till the markets open. However, as a trader - how would you react to news or events when the markets are closed? 

The difference between a profitable trader and a beginner comes down to three main factors: speed, price, and liquidity. Introducing Automated Market Makers (AMM) which eliminates the need for human intermediaries by using smart contracts, allowing traders to execute 24/7 whenever and wherever. 

In this article, you'll learn the core mechanics of how an AMM works, how it stacks up against the traditional order book, and the real risks and benefits of using this powerful, automated system.

TL;DR

AMMs is a decentralised mechanism that allows traders to buy and sell cryptocurrencies without centralised intermediaries. Traditional markets often relied on human market makers to match orders, AMMs eliminated this through the power of liquidity pools and mathematical formulas, allowing traders access to the market 24/7 and in a permissionless manner. 

What Is an AMM?

An AMM is a type of smart contract used in Decentralised Finance (DeFi) that facilitates cryptocurrency buy and sell without the need of human intermediaries. Instead of matching a buyer with a seller using a traditional order book, AMMs allow users to trade directly against a shared pool of tokens held within a smart contract. 

This structure ensures 24/7 liquidity availability and democratises the function of market-making, allowing anyone to participate. Users interact directly with this smart contract, trading against the pooled assets rather than a counterparty. Prices are determined automatically by mathematical algorithms, facilitating continuous trading and decentralised price discovery.

How AMMs Work (Step-by-Step)

To understand AMMs better, it’s important to grasp the foundational components that run it.

Let’s dive in to see how each of the core components operate: 

Liquidity Pools & LP Tokens

amm2

At the heart of an AMM are liquidity pools that are crowdsourced ,known as liquidity providers (LP), that typically deposit an equal amount of tokens into a pool. (e.g. 50 Token A, 50 Token B). Every trader will swap directly against the pool’s supply. In return, they receive a LP token as a digital receipt of their share of the pool and entitle them to a portion of trading fees as an incentive. LP tokens are burned when a LP withdraws their assets back.

For example, if an LP contributes $100 to a pool with a total value of $1,000, they would receive 10% of the LP tokens minted, representing their 10% ownership share.

Pricing Basics

The AMM prices the tokens based on a mathematical formula rather than market demands. The formula prices are based on the current ratio of tokens in the pool. 

x • y = k 

X - quantity of Token A

Y - quantity of Token B

K - the constant the pool must maintain.

Since it’s not based on market supply and demand, what happens if the AMM’s price differs a lot from the broader market? This creates a profitable opportunity for arbitrageurs to quickly trade against the pool to level the price back to market. 

Fees & Who Earns Them

For using the AMM, traders must pay a small swap fee to swap tokens. This is usually charged as a percentage of the transaction volume(.e.g 0.30%). However, fees vary between AMMs with some newer models having deployed new fee tiers or dynamic pricing models.

This fee is then accrued back to the LP as an incentive for providing liquidity. However, fees earned are only realised after LP withdraws their assets back out from the pool. Instead, fees are automatically reinvested back in the pool to increase liquidity and compound more fees. 

AMM Math in Plain English x•y = k

The way many AMMs function is governed by a conservation principle, often called the invariant. This means that every trade must satisfy a specific mathematical formula.The most famous and widely used formula is the Constant Product Market Maker (CPMM), defined as x • y = k

  • x - quantity of Token A 

  • Y - quantity of Token B 

  • k is the constant product, which must remain unchanged (excluding fees) 

In this scenario, 'k' is a constant that must remain unchanged (excluding fees) after every transaction. The smart contract calculates how many tokens must be withdrawn to ensure the product x • y still equals k. This equation effectively describes a hyperbola on a graph. However, the larger your trade relative to the pool size, the more you disrupt the x • y = k ratio, resulting in price slippage.

Let’s take a look at an example: A liquidity pool has 100,000 USDC and 5 BTC. Applying the CPMM formula, we would have a constant of 500,000 (100,000 • 5). 

Let’s imagine a trader wants to buy 1 BTC, meaning there will be 4 BTC left in the pool after the trade. As the constant needs to be maintained, the USDC must increase to pay for the reduction in BTC.

  1. 4 BTC • y = 500,000. 

  2. 500,000/4 = 125,000

 The trader would then have to pay the difference between the new and old USDC amount of 25,000 USDC (125,000 - 100,000).

amm3

AMM Types

While the Constant Product formula is the most famous, the DeFi ecosystem has evolved to include several AMM types. Let’s breakdown each type and it’s characteristics:

AMM Type

Invariant Function

Primary Use Case 

Key Characteristic

Constant Product (CPMM)

x•y = k

Volatile, uncorrelated assets (Uniswap V2)

Guarantees infinite liquidity; prone to high slippage

Constant Sum (CSMM)

x+y = k

Theoretical/Stable assets

Offers low slippage at the intended price peg; vulnerable to pool draining

Constant Mean (CMMM)

Multi-asset, weighted pools (Balancer)

Supports pools with more than two tokens (up to eight) and non-50/50 weighting

StableSwap

Hybrid Function

Highly correlated stable assets (Curve)

Uses a hybrid function to provide extremely low slippage near the 1:1 price peg

AMMs vs. Order Books

AMMs have been at the cornerstone of Decentralised Finance and largely used among Decentralized Exchanges (DEX). However, the order book model has been predominantly used within the traditional asset trading markets and centralized cryptocurrency exchanges. Centralised exchanges (CEX) rely on off-chain Central Limit Order Books (CLOBs). Implementing a CLOB directly on a public blockchain is often costly and inefficient due to the high transaction fees associated with constantly updating the volume of orders on-chain.

The difference between AMMs and order books lies in the counterparty and how prices are determined. AMMs are quoted massively through its algorithm whilst order books are actively quoted and matched amongst traders. As mentioned, AMMs guarantee continuous liquidity, while Order Books traditionally offer superior execution precision. Let’s take a closer look at their differences down below:

Feature

Automated Market Makers (AMMs)

Order Books (CLOBs/CEXs)

Liquidity Source

Crowdsourced Liquidity Pools (LPs)

Explicit Buy/Sell Orders from Traders/Dealers

Price Determination

Algorithmic Invariant Formula

Bid/Ask Spread (Matching Quotes)

Trade Execution

Swapped against the immutable Smart Contract (Pool)

Matched directly between two Counterparties

Accessibility

Permissionless; anyone can be an LP

Often requires KYC/KYB or institutional status for market making

Benefits & Risks

Benefits

  1. Continuous Liquidity: AMMs provide 24/7, continuous liquidity for virtually any token pair by trading against the pool.

  2. Permissionless Accessibility: Anyone can provide liquidity or trade on AMMs without needing to create an account or go through a KYC process.

  3. Transparency and Security: All transactions are recorded on the blockchain, ensuring transparency and security through the execution of immutable smart contracts .

  4. Instant Market Creation: AMMs allow any project to instantly establish liquidity for a new token pair without requiring centralized exchange approval, democratizing the process of token launch and distribution.

Risks

  1. Impermanent Loss (IL): The primary risk for Liquidity Providers (LPs). IL is the temporary loss of value that occurs when the market price of the pooled assets changes (diverges) compared to what those assets would be worth if simply held outside the pool (HODLing). The loss becomes permanently realized the moment the LP withdraws their capital while the price divergence persists.

  2. Slippage: This is the difference between the expected quoted price and the final execution price received by the trader. It is an inherent feature of the AMM curve because any executed trade inevitably moves the reserves along the invariant curve . The severity of slippage is directly correlated to the size of the trade relative to the total liquidity (TVL) in the pool.

  3. Maximal Extractable Value (MEV): MEV is a complex risk where block producers or automated trading bots ("searchers") manipulate transaction ordering (e.g., Sandwich Attacks or Front-running) to extract profit from regular traders' pending swaps. This manipulation increases transaction costs and worsens trade execution for the victim.

Common Use Cases

AMMs are foundational to the functionality and expansion of the wider DeFi ecosystem:

  1. Decentralized Token Swapping: The primary use case, enabling trustless, instantaneous, and permissionless exchanges between any two supported tokens, directly from a user's wallet .

  2. Passive Income/Yield Generation: Providing a mechanism for crypto holders to earn continuous yield (trading fees) on their idle assets by acting as liquidity providers.3

  3. Instant Token Listing and Distribution: AMMs allow any project to instantly establish liquidity for a new token pair without the need to appeal to a centralised exchange, democratizing the process of token launch and initial distribution .

  4. Portfolio Management: Constant Mean Market Makers (CMMMs) like Balancer allow LPs to create weighted, multi-asset pools (e.g., 80/20 or 25/25/25/25), effectively functioning as dynamic index funds . The AMM algorithm automatically rebalances the portfolio over time as market prices shift .

Frequently Asked Questions (FAQs)

Q1: What’s the difference between AMMs and DEXs with order books?

The core difference lies in the counterparty and the pricing mechanism. AMM-based DEXs facilitate swaps against a smart contract holding a shared pool of assets, determining the price algorithmically via a constant function x•y = k. Conversely, Order Book-based DEXs function by matching explicit limit or market orders submitted by individual traders . While order books generally offer superior price precision when liquid, AMMs are advantageous because they guarantee continuous, 24/7 liquidity for virtually any asset pair . (For a deeper dive on this market structure, see our guide: DEX vs CEX: How Decentralised Exchanges Compare to Centralised Trading.)

Q2: Do AMMs always charge a fee? Who gets it?

Yes, virtually all AMMs charge a transaction fee—a small percentage of the swap amount—which is paid by the trader (liquidity taker) . The overwhelming majority of this fee revenue (e.g., 84% in some models) is automatically collected by the smart contract and distributed proportionally to the Liquidity Providers (LPs) . This fee income serves as the primary compensation for LPs accepting the risks associated with providing capital, particularly impermanent loss.

Q3: What are LP tokens and what can I do with them?

LP tokens are fungible receipt tokens (usually ERC-20 standard) issued to Liquidity Providers upon depositing assets . They represent the provider's proportional ownership share of the pool’s capital and accumulated trading fees . LP tokens are critical for maintaining the non-custodial nature of AMMs, as the LP holds the receipt in their own wallet, retaining complete control over when to redeem their share . Their adherence to token standards also unlocks composability, enabling LPs to deposit or stake these tokens in other DeFi protocols (e.g., lending or yield farming platforms) to generate additional layers of yield or use them as collateral.

Q4: Can anyone create a pool?

Yes, in most major AMM protocols (like Uniswap), creating a new liquidity pool for any two tokens is a permissionless action that can be initiated by any user. The user who creates the pool is also the first liquidity provider . However, some blockchain ledgers (such as the XRP Ledger) may have protocol-level constraints, limiting the system to only one official AMM pool per specific asset pair.