0Pricing
Web3 & DApp Development Fundamentals · บทเรียน

ผู้ดูแลสภาพคล่องอัตโนมัติ

สูตรผลคูณคงที่

ผู้ดูแลสภาพคล่องอัตโนมัติ เป็นบทเรียน Web3 & DApp Development Fundamentals ฟรีบน CoddyKit นี่คือบทเรียนที่ 2 จากทั้งหมด 4 บทเรียน คุณสามารถอ่านบทเรียนทั้งหมดด้านล่างฟรี — จากนั้นลองปฏิบัติด้วยตัวคุณเองในเบราว์เซอร์พร้อมตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7 บทเรียนนี้เป็นส่วนหนึ่งของเส้นทางการเรียน Web3 & DApp Development Fundamentals และความก้าวหน้าของคุณจะซิงค์ข้ามเว็บและแอป CoddyKit คอร์ส Web3 & DApp Development Fundamentals มีบทเรียนทั้งหมด 4 บทเรียน

บางส่วนของบทเรียนนี้ยังไม่ได้รับการแปล และแสดงเป็นภาษาอังกฤษ

What Is an AMM?

An Automated Market Maker (AMM) is a smart contract that prices and executes trades using a mathematical formula instead of an order book.

Instead of matching a buyer with a seller, traders swap against a shared pool of tokens.

Order Books vs AMMs

Traditional exchanges match individual buy and sell orders. AMMs replace that with a liquidity pool and a pricing curve.

  • Order book: needs active market makers
  • AMM: always available, prices set by formula

The Liquidity Pool

An AMM pool holds a reserve of two tokens, for example ETH and USDC. Traders add one token and remove the other.

The pool's reserves determine the price — the contract never needs a counterparty.

Pool reserves:
    x = 100 ETH
    y = 200000 USDC

The Constant Product Formula

The most famous AMM (Uniswap v2) uses the constant product formula:

x * y = k

The product of the two reserves must stay equal to a constant k after every trade (ignoring fees).

x * y = k
100 ETH * 200000 USDC = 20,000,000 = k

How a Swap Moves Reserves

To buy ETH, a trader adds USDC. The USDC reserve grows and the ETH reserve shrinks, but the product must remain k.

Before: 100 ETH * 200000 USDC = 20,000,000
Trader adds 10000 USDC -> y = 210000
New x = k / y = 20,000,000 / 210000
      = 95.238 ETH
Trader receives 100 - 95.238 = 4.76 ETH

Price From the Curve

The instantaneous price is the ratio of reserves: price = y / x.

As one reserve shrinks, that token becomes more expensive. The curve makes large trades cost progressively more per unit.

price of ETH in USDC = y / x
= 200000 / 100 = 2000 USDC per ETH

Slippage

Slippage is the difference between the expected price and the price you actually get. Big trades move along the curve and suffer more slippage.

Deeper pools (larger reserves) reduce slippage because each trade shifts the ratio less.

Trading Fees

Each swap charges a fee (often 0.30%) that is added to the pool. This grows k slightly over time.

Fees are the reward that compensates liquidity providers for supplying capital.

amountIn after fee = amountIn * 0.997
// 0.30% fee stays in the pool

Arbitrage Keeps Prices Honest

If the AMM price drifts from the wider market, arbitrageurs trade against the pool until it matches.

This self-correcting pressure keeps AMM prices aligned with external markets without any oracle.

Other AMM Curves

Constant product is not the only design:

  • Curve uses a stableswap formula for assets that should trade near 1:1
  • Uniswap v3 adds concentrated liquidity within chosen price ranges

Each curve optimizes for a different asset type.

Putting It Together

AMMs price trades with a formula like x * y = k against a shared pool. Reserves set the price, large trades cause slippage, fees reward providers, and arbitrage keeps prices accurate.

Next we look at the liquidity pools themselves.

Quick Check

Test your AMM math intuition.

Recap: Automated Market Makers

You learned that:

  • AMMs replace order books with a formula + pool
  • The constant product rule is x * y = k
  • Price is the reserve ratio; big trades cause slippage
  • Fees reward providers; arbitrage keeps prices honest

Next: providing liquidity to these pools.

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

บทเรียน “ผู้ดูแลสภาพคล่องอัตโนมัติ” ฟรีหรือไม่

ใช่ — ข้อความเต็มของ “ผู้ดูแลสภาพคล่องอัตโนมัติ” ฟรีให้อ่านที่นี่บนเว็บ เพื่อปฏิบัติแบบโต้ตอบ (ตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7) และปลดล็อคส่วนที่เหลือของคอร์ส Web3 & DApp Development Fundamentals ให้อัปเกรดเป็น CoddyKit PRO คอร์ส Web3 & DApp Development Fundamentals มีบทเรียนทั้งหมด 4 บทเรียน

คุณจะเรียนรู้อะไรในบทเรียน “ผู้ดูแลสภาพคล่องอัตโนมัติ”

สูตรผลคูณคงที่ คุณปฏิบัติ Web3 & DApp Development Fundamentals ด้วยโค้ดที่ใช้งานได้จริงที่คุณเรียกใช้โดยตรงในเบราว์เซอร์ และติวเตอร์ AI ตลอด 24/7 ตอบคำถามของคุณขณะที่คุณไปผ่านบทเรียน

คุณต้องมีประสบการณ์ก่อนที่จะเริ่มเรียน Web3 & DApp Development Fundamentals หรือไม่

ไม่จำเป็นต้องมีประสบการณ์มาก่อน Web3 & DApp Development Fundamentals บน CoddyKit ออกแบบมาสำหรับผู้เริ่มต้นไปจนถึงผู้เรียนขั้นสูง คุณสามารถเริ่มต้นที่นี่หรือเริ่มจากตัวแรกและเรียนด้วยความเร็วของคุณเอง นี่คือบทเรียนที่ 2 จากทั้งหมด 4 บทเรียน

บทเรียน “ผู้ดูแลสภาพคล่องอัตโนมัติ” ใช้เวลานานแค่ไหน

บทเรียน CoddyKit ส่วนใหญ่ใช้เวลาประมาณ 5–10 นาที แต่ละบทเรียนจึงสั้นและเป็นแบบโต้ตอบ คุณสามารถก้าวหน้าอย่างต่อเนื่องและกลับมาเรียนต่อจากตรงที่เพิ่งหยุดบนเว็บและแอปได้เลย

ฉันเขียนและรันโค้ดในบทเรียน Web3 & DApp Development Fundamentals นี้ได้ไหม

ได้ บทเรียน Web3 & DApp Development Fundamentals ทุกบทมีตัวแก้ไขโค้ดในตัว คุณจึงเขียนและรันโค้ดจริงได้เลยในเบราว์เซอร์ และได้รับข้อเสนอแนะจาก AI ในทันที — ไม่ต้องติดตั้งในเครื่องของคุณ

บทเรียนทั้งหมดในหลักสูตรนี้

  1. ภาพรวม DeFi
  2. ผู้ดูแลสภาพคล่องอัตโนมัติ
  3. พูลสภาพคล่อง
  4. การสร้างสวอปอย่างง่าย
← กลับไปที่ Web3 & DApp Development Fundamentals