ข้ามไปยังเนื้อหาหลัก

Exness คืน 100% ของค่าคอมมิชชั่น IB

ไม่มีการหักใด ๆ ก่อนเงินถึงบัญชีของคุณ

EA และอินดิเคเตอร์ฟรี

XM คืน 90% ฝากขั้นต่ำ $5

What is an automated market maker?

An automated market maker, or AMM, is a smart contract that holds a pool of two tokens and quotes prices from a formula instead of matching buyers with sellers. You swap against the pool, and every trade moves its price. The people who supply the tokens earn fees and carry a risk called impermanent loss.

เนื้อหานี้ยังมีเฉพาะภาษาอังกฤษ

อ่าน 6 นาทีAutoFXRebate

On an exchange with an order book, your trade needs someone on the other side at a price you accept. If nobody is there, you wait.

An automated market maker, or AMM, replaces that person with a pool of tokens and a formula written into a smart contract. As long as the pool holds tokens, it will quote you a price.

Why order books are hard on a blockchain

An order book is a list of buy and sell orders that traders and market makers keep updating. On a blockchain, every new order, change and cancellation is a transaction that pays a fee and waits for a block.

An AMM needs no stream of orders. Liquidity providers deposit tokens into a pool, and the contract prices every trade from the pool's balances. Many decentralized exchanges in DeFi work this way.

The constant product formula

The best-known design keeps one number fixed. Multiply the amounts of the two tokens in the pool, and the result must stay the same after each trade, before fees. It is written x × y = k.

Take an illustrative pool of 100 ETH and 200,000 USDC. Then k = 100 × 200,000 = 20,000,000. The pool's price is the ratio of the two balances: 200,000 ÷ 100 = 2,000 USDC per ETH.

When you add one token, the formula decides how much of the other you get back, so the product stays at 20,000,000. Each ETH you take out leaves fewer behind, so the next one costs more.

Worked example: a 10,000 USDC swap

The numbers are illustrative, and the pool fee is left out for now.

  1. You put in 10,000 USDC. The pool now holds 200,000 + 10,000 = 210,000 USDC.
  2. To keep k, the pool's ETH must fall to 20,000,000 ÷ 210,000 = 95.238 ETH.
  3. You receive 100 minus 95.238 = 4.762 ETH.
  4. Your average price is 10,000 ÷ 4.762 = 2,100 USDC per ETH, 5% above where the pool started.
  5. The pool's new price is 210,000 ÷ 95.238 = 2,205 USDC per ETH.
The pool before the swap holds 100 ETH and 200,000 USDC at a price of 2,000, and after a 10,000 USDC swap it holds 95.238 ETH and 210,000 USDC at a price of 2,205, with 4.762 ETH paid out.
The product stays at 20,000,000 while the price moves from 2,000 to 2,205.

The gap between 2,000 and your 2,100 is price impact, the cost of moving the pool with your own trade.

In this design it follows a simple rule: the extra you pay, in percent, equals your trade as a share of the pool's USDC. 10,000 is 5% of 200,000.

You pay inETH outAverage priceAbove 2,000
1,000 USDC0.49752,0100.5%
10,000 USDC4.76192,1005%
50,000 USDC20.00002,50025%
A curve of ETH against USDC held in the pool, with the starting point at 100 ETH and 200,000 USDC, and points for 10,000 and 50,000 USDC swaps showing average prices of 2,100 and 2,500.
Bigger trades slide further along the curve, so each one pays a worse average price.

A deeper pool moves less for the same trade, which is what good liquidity means here. In a pool of 200 ETH and 400,000 USDC, the same 10,000 USDC pays 2.5% above 2,000 instead of 5%.

Real pools also charge a fee, such as 0.3%. In this design it comes off your 10,000 USDC first: 30 USDC.

The other 9,970 USDC goes through the formula and buys 4.748 ETH, an average of 2,106 USDC per ETH. The 30 USDC stays in the pool, and that is how the liquidity providers get paid.

How the pool price follows the market

After your swap the pool says 2,205, while other markets still say 2,000. An arbitrage trader buys ETH elsewhere at 2,000 and sells it into the pool.

Selling 4.762 ETH brings the pool back to 100 ETH and 200,000 USDC, and its price back to 2,000. The trader receives 10,000 USDC for ETH that cost about 9,524 USDC elsewhere, a profit of about 476 USDC before fees.

That profit came from your trade: you paid 10,000 USDC for ETH worth 9,524 USDC at the market price. Arbitrage keeps the pool in line with other markets, and your price impact is what the arbitrage trader earns.

Liquidity providers and impermanent loss

The tokens in a pool come from liquidity providers. Each deposits both tokens in equal value, receives a share of the pool recorded as LP tokens, and earns trading fees in proportion to that share.

In return, they carry impermanent loss. When the price moves, arbitrage leaves the pool holding more of the token that fell and less of the one that rose, compared with simply keeping both.

The numbers below are illustrative, and fees are left out.

  1. You deposit 10 ETH and 20,000 USDC, worth 40,000 USDC at 2,000. With your deposit, the pool holds 100 ETH and 200,000 USDC, so your share is 10%.
  2. The ETH price elsewhere rises to 8,000. Arbitrage traders buy ETH from the pool until its price is 8,000 too.
  3. With k = 20,000,000 and a price of 8,000, the pool holds 50 ETH and 400,000 USDC. Check: 50 × 400,000 = 20,000,000, and 400,000 ÷ 50 = 8,000.
  4. Your 10% is 5 ETH and 40,000 USDC, worth 5 × 8,000 + 40,000 = 80,000 USDC.
  5. Had you kept the tokens in your wallet, they would be worth 10 × 8,000 + 20,000 = 100,000 USDC.
Two bars at an ETH price of 8,000: keeping 10 ETH and 20,000 USDC is worth 100,000 USDC, while the pool share of 5 ETH and 40,000 USDC is worth 80,000 USDC, a gap of 20 percent.
The pool sold half your ETH on the way up, so you end 20% behind holding.

Your pool share grew from 40,000 to 80,000 USDC, yet it trails holding by 20%. A fall to 500 USDC per ETH gives the same 20% gap, and a doubling of the price gives about 5.7%.

The loss is called impermanent because it shrinks back to zero if the price returns to 2,000 before you withdraw. Withdraw at any other price and it becomes permanent.

Trading fees earned while you wait can cover part or all of the gap, depending on how much trading the pool sees.

คำถามที่พบบ่อย

Who sets the price in an automated market maker?

The formula sets it from the pool's balances, and arbitrage traders keep those balances in line with other markets. Nobody posts a quote.

What does x × y = k mean?

The amounts of the two tokens in the pool, multiplied together, must stay the same after each trade, before fees. That rule makes each unit you take out cost more than the last.

Can impermanent loss be avoided?

Not in a pool of two tokens whose prices can drift apart. It is smallest in pools of two tokens that track each other, such as two dollar stablecoins.

Why did I get fewer tokens than the quoted price suggested?

Your own trade moved the pool's price, the pool took its fee, and other trades may have landed just before yours. Your slippage tolerance sets how much of that you accept before the swap fails.

ความคิดเห็น

บัญชีของคุณอยู่กับโบรกเกอร์ไหน?

แต่ละโบรกเกอร์มีขั้นตอนไม่เหมือนกัน เราจึงจะพาคุณไปยังชุดขั้นตอนที่ถูกต้องโดยตรง