An automated market maker (AMM) is a type of decentralized exchange (DEX) protocol that relies on a mathematical formula to price assets. Instead of using an order book like a traditional exchange, assets are priced according to a pricing algorithm. Pricing information often comes from multiple APIs to always provide the most accurate cost. Also anyone can become a liquidity provider for automated market makers and receive a part of trading commissions.

The market contains an internal state, PRICE, which is the current market price. It would also have two parameters, FEE, and DEPTH. If a user wants to buy ORDER_AMOUNT coins, they would raise the price to PRICE + ORDER_AMOUNT / DEPTH, and pay ORDER_AMOUNT * (PRICE + ORDER_AMOUNT / DEPTH / 2) * (1 + FEE). Essentially, this constitutes buying an infinitesimal number of coins at every price point between the old price and the new price.

**How do Automatic Market Makers (AMMs) work?**

*There are two important things to know first about AMMs:*

Trading pairs you would normally find on a centralized exchange exist as individual “liquidity pools” in AMMs. For example, if you wanted to trade ether for tether, you would need to find an ETH/USDT liquidity pool.

Instead of using dedicated market makers, anyone can provide liquidity to these pools by depositing both assets represented in the pool. For example, if you wanted to become a liquidity provider for an ETH/USDT pool, you’d need to deposit a certain predetermined ratio of ETH and USDT.

To make sure the ratio of assets in liquidity pools remains as balanced as possible and to eliminate discrepancies in the pricing of pooled assets, AMMs use preset mathematical equations. For example, Uniswap and many other DeFi exchange protocols use a simple x*y=k equation to set the mathematical relationship between the particular assets held in the liquidity pools.

Here, x represents the value of Asset A, y denotes the value of Asset B, while k is a constant.

In essence, the liquidity pools of Uniswap always maintain a state whereby the multiplication of the price of Asset A and the price of B always equals the same number.

To understand how this works, let us use an ETH/USDT liquidity pool as a case study. When ETH is purchased by traders, they add USDT to the pool and remove ETH from it. This causes the amount of ETH in the pool to fall, which, in turn, causes the price of ETH to increase in order to fulfill the balancing effect of x*y=k. In contrast, because more USDT has been added to the pool, the price of USDT decreases. When USDT is purchased, the reverse is the case – the price of ETH falls in the pool while the price of USDT rises.

When large orders are placed in AMMs and a sizable amount of a token is removed or added to a pool, it can cause notable discrepancies to appear between the asset’s price in the pool and its market price (the price it’s trading at across multiple exchanges.) For example, the market price of ETH might be $3,000 but in a pool, it might be $2,850 because someone added a lot of ETH to a pool in order to remove another token.

This means ETH would be trading at a discount in the pool, creating an arbitrage opportunity. Arbitrage trading is the strategy of finding differences between the price of an asset on multiple exchanges, buying it on the platform where it’s slightly cheaper and selling it on the platform where it’s slightly higher.

For AMMs, arbitrage traders are financially incentivized to find assets that are trading at discounts in liquidity pools and buy them up until the asset’s price returns in line with its market price.

For instance, if the price of ETH in a liquidity pool is down, compared to its exchange rate on other markets, arbitrage traders can take advantage by buying the ETH in the pool at a lower rate and selling it at a higher price on external exchanges. With each trade, the price of the pooled ETH will gradually recover until it matches the standard market rate.

Note that Uniswap’s x*y=k is just one of the mathematical formulas used by AMMs today. For instance, Balancer uses a much more complex form of mathematical relationship that lets users combine up to 8 digital assets in a single liquidity pool. Curve, on the other hand, adopts a mathematical formula suitable for pairing stablecoins or similar assets.

### Timeline

### Further reading

Let's run on-chain decentralized exchanges the way we run prediction markets

Web

October 3, 2016

On Path Independence

Web

June 33, 2017

### Documentaries, videos and podcasts

How do LIQUIDITY POOLS work? (Uniswap, Curve, Balancer) | DEFI Explained

July 20, 2020