Advanced Topics

Automatic Market Maker (AMM)

What is an Automated Market Maker (AMM)?

An Automated Market Maker (AMM) is a type of software (usually a smart contract) that automatically sets the price of digital assets and allows users to trade them on a decentralized platform. It eliminates the need for traditional order books (used by centralized exchanges like Binance) and instead uses a formula to determine asset prices.

In simple terms, think of an AMM as a vending machine: you put in one type of token (e.g., Ethereum) and get out another (e.g., USDC). The price you pay for the second token depends on how much is available in the "pool" (like how a vending machine changes prices based on supply).

Example: A Basic Trade on an AMM

Let’s say you’re on a decentralized exchange that uses an AMM, like Uniswap, and you want to trade ETH for USDC. Here's how the process would look:

Liquidity Pool Setup:

There's a liquidity pool with 100 ETH and 200,000 USDC. This pool has been funded by users called liquidity providers (more on that later). The product of these two amounts, 100 ETH x 200,000 USDC, equals 20,000,000, which is the constant k.

You Buy ETH:

You want to buy 10 ETH from the pool. When you take 10 ETH out, the amount of ETH left in the pool decreases to 90 ETH. To maintain the constant product, the amount of USDC in the pool must increase. This will drive the price of ETH higher.

Here's the math: After you buy 10 ETH, the formula becomes: 90 · y = 20,000,000. Solving for y gives 222,222 USDC, meaning the pool now has 222,222 USDC. Therefore, to buy 10 ETH, you have to pay the difference: 222,222 USDC - 200,000 USDC = 22,222 USDC.

So, you pay 22,222 USDC to get 10 ETH. The price of ETH has increased because there's now less ETH in the pool and more USDC.

Automated Pricing Without Order Books

On centralized exchanges, trades rely on order books, where buyers place bids at their preferred price and sellers place offers. However, this system requires human interaction or bots, which can slow things down. AMMs automate the pricing and trade process using algorithms. Instead of matching buyers and sellers, AMMs match buyers and liquidity pools, allowing users to trade instantly. The pricing is handled automatically based on the ratio of tokens in the pool.

How AMM Pools Change Prices

AMMs use supply and demand to change prices dynamically: when a token is bought, the price of that token rises because its supply in the pool decreases; when a token is sold, the price of that token falls because its supply in the pool increases. The more a token is traded in one direction, the more the price moves in that direction. This is called slippage, and it happens because the AMM adjusts prices based on the current state of the liquidity pool.

Automated Market Makers (AMMs) are a critical innovation in decentralized finance, enabling token swaps without relying on traditional buyers and sellers. By using smart contracts and mathematical formulas, AMMs provide constant liquidity, decentralized trading, and the ability for users to earn passive income as liquidity providers. Despite the benefits, they come with certain risks like impermanent loss and slippage, which users need to understand before participating in AMM-based trading or liquidity provision.