Skip to main content

Part 3: Understanding Automated Market Makers (AMM)

"AMM adalah inovasi yang mengubah setiap orang menjadi market maker - pekerjaan yang sebelumnya hanya bisa dilakukan oleh institusi Wall Street."


๐Ÿ“š Overviewโ€‹

Di Part 2, kita belajar bahwa Uniswap (2018) revolusioner karena memperkenalkan Automated Market Maker (AMM).

Di Part 3 ini, kita akan melakukan pembahasan mendalam:

  • Bagaimana AMM bekerja secara detail
  • Formula x ร— y = k dengan contoh praktis
  • Analogi petani kentang & apel (dari Whiteboard Crypto)
  • Liquidity pools & liquidity providers
  • Slippage & price impact
  • Impermanent loss (risiko terbesar!)

Durasi: 120 menit (2 jam)


๐ŸŽฏ Apa itu Automated Market Maker (AMM)?โ€‹

Definitionโ€‹

Automated Market Maker (AMM) adalah algoritma yang:

  1. โœ… Menentukan harga aset berdasarkan rasio di liquidity pool
  2. โœ… Memungkinkan trading instant tanpa order book
  3. โœ… Menggunakan formula matematika (biasanya x ร— y = k)
  4. โœ… Berjalan 24/7 tanpa manusia (pure smart contract)

AMM vs Order Bookโ€‹

Mari bandingkan kedua model:

Order Book (Traditional)โ€‹

Cara kerja:

BUY ORDERS (Bids):          SELL ORDERS (Asks):
Alice: 1 ETH @ $2,450 David: 1 ETH @ $2,470
Bob: 2 ETH @ $2,445 Eve: 3 ETH @ $2,475
Carol: 5 ETH @ $2,440 Frank: 2 ETH @ $2,480

Spread = $2,470 - $2,450 = $20

Pros:

  • โœ… Price discovery (market sets exact price)
  • โœ… Tidak ada price impact untuk limit orders
  • โœ… Familiar untuk traders

Cons:

  • โŒ Butuh market makers (professionals yang provide liquidity)
  • โŒ Gas intensive di blockchain (setiap order = transaction)
  • โŒ Slow matching di blockchain
  • โŒ Liquidity fragmentation (berbeda di setiap exchange)

AMM (Uniswap Model)โ€‹

Cara kerja:

Liquidity Pool:
100 ETH + 250,000 USDC = 25,000,000 (k)

Current Price:
250,000 USDC / 100 ETH = 2,500 USDC per ETH

No orders needed - trade instantly!

Pros:

  • โœ… Instant trading (tidak perlu menunggu untuk pencocokan)
  • โœ… Always liquid (selama ada tokens di pool)
  • โœ… Permissionless (anyone can be liquidity provider)
  • โœ… Simple (no complex order management)
  • โœ… Passive income untuk LPs (earn fees)

Cons:

  • โŒ Price impact (large trades move price significantly)
  • โŒ Slippage (harga berubah selama trading)
  • โŒ Impermanent loss untuk LPs (risiko karena volatilitas harga)
  • โŒ Kurang capital efficient (idle capital di pool)

๐Ÿงฎ Formula AMM: x ร— y = kโ€‹

Core Conceptโ€‹

Constant Product Formula (digunakan oleh Uniswap V1 & V2):

x ร— y = k

x = jumlah Token A di pool
y = jumlah Token B di pool
k = konstanta yang HARUS SELALU TETAP

Rules:

  1. ๐Ÿ”’ k harus tetap konstan (kecuali ada liquidity added/removed)
  2. ๐Ÿ“Š Price = y / x (ratio dari kedua token)
  3. ๐Ÿ”„ Setiap swap: jumlah x naik, maka y turun (atau sebaliknya) agar k tetap konstan

Why "Constant Product"?โ€‹

Constant Product = hasil kali (product) dari x dan y harus konstan (constant).

Matematika:

Before swap: xโ‚ ร— yโ‚ = k
After swap: xโ‚‚ ร— yโ‚‚ = k

Therefore: xโ‚ ร— yโ‚ = xโ‚‚ ร— yโ‚‚

Implikasi penting:

  • Semakin banyak token A di pool โ†’ semakin murah token A
  • Semakin sedikit token B di pool โ†’ semakin mahal token B
  • Automatic price adjustment! ๐Ÿ“ˆ๐Ÿ“‰

Visual: The Curveโ€‹

Grafik x ร— y = k membentuk hyperbola (kurva melengkung):

y (Token B)
โ”‚
โ”‚ โ•ฑ
โ”‚โ•ฑ
โ”‚ โ•ฒ
โ”‚ โ•ฒ
โ”‚ โ•ฒ_______________
โ”‚ x (Token A)
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€

Titik di kurva = possible pool states
Semakin jauh dari origin = semakin banyak liquidity

Properties:

  • ๐Ÿ“‰ Asymptotic: Kurva mendekati axis tapi tidak pernah menyentuh (pool tidak pernah kosong!)
  • ๐Ÿ“Š Slope = price: Kemiringan kurva di setiap titik adalah harga relatif
  • ๐Ÿ”„ Trades move along curve: Swap menggerakkan titik pool sepanjang kurva

Ini adalah BRILLIANT design! Matematika memastikan pool tidak pernah kehabisan salah satu token. ๐Ÿง 


๐Ÿฅ”๐ŸŽ Analogi Petani: Kentang & Apelโ€‹

Video reference: Whiteboard Crypto - "What is an Automated Market Maker?"

Mari kita gunakan analogi sederhana untuk memahami AMM!


๐ŸŒพ Setting: Dua Desa Petaniโ€‹

Desa A: Petani kentang ๐Ÿฅ”

  • Bosan makan kentang terus
  • Ingin apel ๐ŸŽ

Desa B: Petani apel ๐ŸŽ

  • Bosan makan apel terus
  • Ingin kentang ๐Ÿฅ”

Problem: Desa terlalu jauh, sulit barter langsung.


๐Ÿงžโ€โ™‚๏ธ Pedagang & "Jin Ajaib"โ€‹

Pedagang datang dengan solusi:

"Saya punya jin ajaib yang tinggal di lampu ajaib. Jin ini akan menyimpan kentang dan apel, dan siapapun bisa datang menukar kapanpun!"

Setup awal:

  • Desa A deposit: 50,000 kentang ๐Ÿฅ”
  • Desa B deposit: 50,000 apel ๐ŸŽ

Lampu ajaib sekarang berisi:

50,000 kentang ร— 50,000 apel = 2,500,000,000 (ini adalah k!)

๐Ÿ“œ Aturan Jin: "Rasio Nilai Sempurna"โ€‹

Jin punya satu aturan sakral:

"Jumlah kentang DIKALI jumlah apel harus SELALU sama dengan 2,500,000,000!"

kentang ร— apel = 2,500,000,000 (k)

ATAU

x ร— y = k

Mengapa aturan ini cemerlang?

  • โœ… Mencegah pool kehabisan kentang atau apel
  • โœ… Harga menyesuaikan otomatis berdasarkan supply & demand
  • โœ… Simple (cuma satu formula!)

๐Ÿ“ Contoh Swap #1: Menukar 7,000 Kentangโ€‹

Timeline: 00:03:02 di video Whiteboard Crypto


Step-by-Step Calculationโ€‹

State Awal:

Kentang (x) = 50,000
Apel (y) = 50,000
k = 2,500,000,000

Harga awal:
1 kentang = 50,000 apel / 50,000 kentang = 1 apel
1 apel = 1 kentang

Rasio 1:1 karena jumlah sama! ๐Ÿ“Š


Petani Charlie datang dengan 7,000 kentang:

"Jin, saya mau tukar 7,000 kentang. Berapa apel yang saya dapat?"


Step 1: Jin terima kentang

Kentang baru di lampu = 50,000 + 7,000 = 57,000 kentang

Step 2: Jin hitung berapa apel yang tersisa agar k = 2,500,000,000

x ร— y = k
57,000 ร— y = 2,500,000,000

y = 2,500,000,000 / 57,000
y = 43,859.65 apel (pembulatan: 43,860)

Jin harus menyimpan 43,860 apel di lampu!


Step 3: Berapa apel yang diberikan ke Charlie?

Apel awal - Apel tersisa = Apel untuk Charlie
50,000 - 43,860 = 6,140 apel ๐ŸŽ

๐Ÿค” Analisis: Mengapa 7,000 kentang = 6,140 apel?โ€‹

Perhatikan:

  • Charlie kasih: 7,000 kentang
  • Charlie dapat: 6,140 apel
  • Ratio: 6,140 / 7,000 = 0.877 apel per kentang

Initial ratio: 1 apel per kentang Actual ratio: 0.877 apel per kentang

Charlie dapat KURANG dari expected! Kenapa? ๐Ÿค”

Jawaban: PRICE IMPACT!

Saat Charlie "membeli" apel (dengan menjual kentang):

  • โŒ Supply apel di pool turun (50,000 โ†’ 43,860) - apel jadi langka
  • โœ… Supply kentang di pool naik (50,000 โ†’ 57,000) - kentang jadi banyak

Hasilnya: Harga apel naik, harga kentang turun selama trading! ๐Ÿ“ˆ๐Ÿ“‰


๐Ÿ’ฐ Harga Baru Setelah Swapโ€‹

Asumsi: Total value di setiap sisi = $50,000 awal

Harga kentang baru:

$50,000 / 57,000 kentang = $0.877 per kentang
(Turun dari $1 karena supply naik!)

Harga apel baru:

$50,000 / 43,860 apel = $1.14 per apel
(Naik dari $1 karena supply turun!)

Spread:

1 apel = 1.14 / 0.877 = 1.30 kentang
(Sebelumnya 1:1, sekarang butuh 1.3 kentang untuk 1 apel!)

Pool secara otomatis menyesuaikan harga berdasarkan trading activity! ๐Ÿ”„


๐Ÿ“Š State Pool Setelah Swap #1โ€‹

BEFORE:                        AFTER:
50,000 kentang 57,000 kentang (+14%)
50,000 apel 43,860 apel (-12.3%)
k = 2,500,000,000 k = 2,499,942,000 โœ… (virtually same, rounding)

Price: 1 apel = 1 kentang Price: 1 apel = 1.3 kentang

Pool masih balanced (k preserved)! โœ…


๐Ÿ“ Contoh Swap #2: Menukar 10,000 Kentang Lagiโ€‹

Timeline: 00:06:02 di video

Petani lain datang, kali ini dengan 10,000 kentang!


Calculationโ€‹

State sebelum swap:

Kentang = 57,000
Apel = 43,860
k = 2,500,000,000 (approximately)

Step 1: Kentang masuk pool

57,000 + 10,000 = 67,000 kentang

Step 2: Calculate apel yang tersisa

67,000 ร— y = 2,500,000,000
y = 2,500,000,000 / 67,000
y = 37,313 apel

Step 3: Apel yang diberikan

43,860 - 37,313 = 6,547 apel

๐Ÿค” Analisis Swap #2โ€‹

Petani kedua:

  • Kasih: 10,000 kentang (lebih banyak dari Charlie!)
  • Dapat: 6,547 apel

Ratio: 6,547 / 10,000 = 0.655 apel per kentang

Compare dengan Charlie (swap #1):

  • Charlie: 0.877 apel per kentang
  • Petani kedua: 0.655 apel per kentang (25% lebih buruk!)

Kenapa lebih buruk? ๐Ÿค”

Jawaban: LARGER PRICE IMPACT!

Pool sudah "imbalanced" dari swap #1:

  • Kentang sudah banyak (57,000) โ†’ kentang sudah murah
  • Apel sudah sedikit (43,860) โ†’ apel sudah mahal

Trading 10,000 kentang (14.9% dari pool) menggerakkan harga secara signifikan! ๐Ÿ“‰

Pelajaran: Larger trades = worse price (exponential impact) ๐Ÿ’ก


๐Ÿ’ฐ Harga Setelah Swap #2โ€‹

Harga kentang:

$50,000 / 67,000 = $0.746 per kentang (turun lagi!)

Harga apel:

$50,000 / 37,313 = $1.34 per apel (naik lagi!)

Spread:

1 apel = 1.34 / 0.746 = 1.80 kentang
(Butuh 1.8 kentang untuk 1 apel sekarang!)

Pool semakin imbalanced! โš ๏ธ


๐Ÿ“ Contoh Swap #3: Menukar 2,000 Apel (Reverse Direction)โ€‹

Timeline: 00:07:53 di video

Sekarang petani apel datang! Dia bosan apel, mau kentang.


Calculationโ€‹

State sebelum swap:

Kentang = 67,000
Apel = 37,313
k = 2,500,000,000

Petani deposit: 2,000 apel


Step 1: Apel masuk pool

37,313 + 2,000 = 39,313 apel

Step 2: Calculate kentang tersisa

x ร— 39,313 = 2,500,000,000
x = 2,500,000,000 / 39,313
x = 63,592 kentang

Step 3: Kentang yang diberikan

67,000 - 63,592 = 3,408 kentang ๐Ÿฅ”

๐ŸŽ‰ Analisis Swap #3โ€‹

Petani apel:

  • Kasih: 2,000 apel
  • Dapat: 3,408 kentang

Ratio: 3,408 / 2,000 = 1.704 kentang per apel

Bandingkan dengan ratio sebelumnya (1:1):

  • Initial: 1 apel = 1 kentang
  • Now: 1 apel = 1.704 kentang (70% better!) ๐ŸŽ‰

Kenapa petani apel dapat deal bagus? ๐Ÿค”

Jawaban: Pool IMBALANCED ke arah kentang!

67,000 kentang vs 37,313 apel

Ratio: 67,000 / 37,313 = 1.80
(Ada 1.8x lebih banyak kentang!)

โ†’ Kentang murah, apel mahal
โ†’ Selling apel = great deal!

Pelajaran: Trade ke arah yang imbalanced = better price ๐Ÿ’ก


๐Ÿ”„ Arbitrage Opportunity!โ€‹

Bayangkan:

Initial state (equal value):

  • 1 apel = $1
  • 1 kentang = $1

After swaps (imbalanced):

  • 1 apel = $1.34 (di pool)
  • 1 kentang = $0.746 (di pool)

Arbitrage strategy:

  1. Beli kentang murah dari pool ($0.746)
  2. Jual kentang di market eksternal ($1)
  3. Profit: $1 - $0.746 = $0.254 per kentang (34% profit!)

Atau:

  1. Beli apel dari market eksternal ($1)
  2. Jual apel di pool ($1.34)
  3. Profit: $0.34 per apel (34% profit!)

Arbitrageurs akan balance pool kembali! ๐Ÿ”„

Inilah cara AMM tetap sejalan dengan harga pasar eksternal. (This is how AMMs stay roughly in line with external market prices.) โœ…


๐ŸŠโ€โ™‚๏ธ Liquidity Pools: Deeper Diveโ€‹

Apa itu Liquidity Pool?โ€‹

Liquidity Pool = smart contract yang menyimpan dua tokens (pair) untuk memfasilitasi trading.

Dalam analogi kita:

  • Liquidity Pool = "lampu ajaib" ๐Ÿช”
  • Tokens = kentang & apel
  • Jin = smart contract algorithm

Pool Size = Stabilityโ€‹

Rule: Semakin besar pool, semakin stabil harga!

Example:

Small Pool:

100 ETH ร— 250,000 USDC = 25,000,000 (k)

Swap 10 ETH (10% of pool):
110 ETH ร— y = 25,000,000
y = 227,272 USDC

Price impact: 250,000 - 227,272 = 22,728 USDC for 10 ETH
= 2,272 per ETH (9.1% worse than initial 2,500!)

Large Pool:

10,000 ETH ร— 25,000,000 USDC = 250,000,000,000 (k)

Swap 10 ETH (0.1% of pool):
10,010 ETH ร— y = 250,000,000,000
y = 24,975,024 USDC

Price impact: 25,000,000 - 24,975,024 = 24,976 USDC for 10 ETH
= 2,498 per ETH (0.09% worse than initial 2,500!)

10 ETH swap:

  • Small pool: 9.1% price impact โŒ
  • Large pool: 0.09% price impact โœ… (100x better!)

Kesimpulan: Deep liquidity = minimal slippage! ๐Ÿ’ง


Initial Liquidity & Price Settingโ€‹

Q: Siapa yang menentukan harga awal pool?

A: FIRST LIQUIDITY PROVIDER!

Scenario:

Alice creates ETH/USDC pool:

She deposits:
- 100 ETH
- 200,000 USDC

Initial price: 200,000 / 100 = 2,000 USDC per ETH

Alice sets initial price at $2,000!


Q: Bagaimana jika Alice set harga salah?

Example:

Alice deposits:
- 100 ETH
- 100,000 USDC

Initial price: 100,000 / 100 = 1,000 USDC per ETH

Market price di CEX: 2,500 USDC per ETH

Alice's price: $1,000 (60% below market!)

What happens?

Arbitrageurs INSTANTLY:

  1. Buy cheap ETH dari pool (pay 1,000 USDC, get 1 ETH)
  2. Sell ETH di Coinbase (receive 2,500 USDC)
  3. Profit: 1,500 USDC per ETH! ๐Ÿ’ฐ

Arbitrageurs drain pool until price = market price.

Alice loses money! โŒ

Pelajaran: ALWAYS set initial price = market price! โš ๏ธ


๐ŸŽ Liquidity Providers (LPs): The Heroesโ€‹

Siapa itu Liquidity Provider?โ€‹

Liquidity Provider (LP) = orang/entitas yang deposit tokens ke liquidity pool.

Dalam analogi:

  • Desa A & Desa B yang deposit 50,000 kentang & apel awal = initial LPs

Mengapa Jadi LP?โ€‹

Incentives:

1. Trading Fees ๐Ÿ’ฐ

  • Setiap swap charge fee (typically 0.3% di Uniswap)
  • Fee dibagi ke semua LP sesuai proporsi share mereka
  • Passive income!

Example:

Pool has $10M total liquidity
You provide $100,000 (1% of pool)

Daily trading volume: $5M
Daily fees: $5M ร— 0.3% = $15,000

Your share: $15,000 ร— 1% = $150 per day
= $54,750 per year

ROI: $54,750 / $100,000 = 54.75% APR ๐Ÿš€

2. Liquidity Mining Rewards ๐ŸŒพ

Many protocols give extra tokens to LPs:

Uniswap LP earnings:
- Trading fees: 20% APR
- UNI rewards: 30% APR
- Total: 50% APR ๐Ÿค‘

3. Support Your Own Token ๐Ÿ’ช

If you launch token, you provide initial liquidity to enable trading!


LP Tokens: Proof of Depositโ€‹

Saat Anda deposit, Anda menerima "LP tokens" (ERC-20) sebagai bukti deposit.

Example:

You deposit:

10 ETH + 25,000 USDC
(Total value: $50,000)

Pool has:

100 ETH + 2,500,000 USDC
(Total value: $5,000,000)

Your share: $50,000 / $5,000,000 = 1%

You receive:

LP tokens representing 1% of pool
(Exact amount depends on contract, maybe 100 LP tokens)

LP tokens are:

  • โœ… Transferable (you can send/sell them)
  • โœ… Composable (use in other DeFi protocols)
  • โœ… Redeemable (burn untuk menarik proportional share dari pool)

How to Become LP (Uniswap)โ€‹

Step-by-step:

1. Choose pair (e.g., ETH/USDC)

2. Deposit nilai yang sama dari kedua tokens

Example:
- 1 ETH (worth $2,500)
- $2,500 USDC

3. Receive LP tokens

UNI-V2 LP tokens (proof of deposit)

4. Earn fees automatically

Fees accumulate in pool
Your share grows over time

5. Withdraw anytime

Burn LP tokens โ†’ receive proportional ETH + USDC

๐Ÿ“‰ Slippage & Price Impactโ€‹

Slippage vs Price Impactโ€‹

Often confused! Let's clarify:


Price Impact ๐Ÿ“Šโ€‹

Definition: Seberapa besar trade Anda mengubah harga pool.

Caused by: Trade size relative to pool size

Formula:

Price Impact = |New Price - Old Price| / Old Price ร— 100%

Example:

Before swap:
Pool: 100 ETH ร— 250,000 USDC
Price: 2,500 USDC per ETH

After swapping 10 ETH โ†’ USDC:
Pool: 110 ETH ร— 227,272 USDC
Price: 2,066 USDC per ETH

Price Impact = |2,066 - 2,500| / 2,500 ร— 100%
= 17.4% ๐Ÿ“‰

You moved price 17.4% with 10 ETH swap!


Slippage ๐ŸŽขโ€‹

Definition: Perbedaan antara expected price (saat submit transaction) dan actual execution price.

Caused by:

  1. Price impact (your trade)
  2. Other trades yang execute sebelum Anda (front-running, atau organic trading)

Example:

You submit transaction:

Expected: 1 ETH = 2,500 USDC
Slippage tolerance: 1%
Min acceptable: 2,475 USDC

By the time transaction executes (12 seconds later):

Actual: 1 ETH = 2,460 USDC (1.6% slippage)

Within tolerance โ†’ transaction succeeds โœ…

If slippage was 2,400 USDC (4% slippage):

Below min acceptable (2,475)
โ†’ Transaction REVERTS โŒ

Setting Slippage Toleranceโ€‹

UI typically has slider:

Slippage Tolerance: [0.1%] [0.5%] [1%] [5%] [Custom]

Trade-offs:

Low slippage (0.1-0.5%):

  • โœ… Protected from bad prices
  • โŒ Transaction likely fails (reverts) during volatility
  • Use for: Stableswap pairs (USDC/USDT), low volatility

Medium slippage (1-2%):

  • โœ… Balanced
  • Use for: Normal trading

High slippage (5%+):

  • โœ… Transaction likely succeeds
  • โŒ Vulnerable to sandwich attacks (MEV bots)
  • Use for: Low liquidity tokens (only if desperate!)

๐Ÿฅช Sandwich Attacks (MEV)โ€‹

Sandwich attack = MEV bot mengeksploitasi Anda dengan front-run & back-run transaction Anda.

Attack flow:

1. Bot sees your pending transaction:

You: Swap 10 ETH โ†’ USDC
Your slippage: 5%

2. Bot front-runs (transaction execute BEFORE yours):

Bot: Swap 50 ETH โ†’ USDC
โ†’ Price moves up (ETH becomes expensive)

3. Your transaction executes:

You: Get worse price (5% worse, within tolerance)

4. Bot back-runs (transaction execute AFTER yours):

Bot: Swap USDC โ†’ ETH
โ†’ Buy back ETH at lower price
โ†’ Profit = difference ๐Ÿ’ฐ

You lose, bot profits. ๐Ÿ˜ž

Protection:

  • โœ… Use low slippage (harder to sandwich)
  • โœ… Use private RPC (Flashbots Protect)
  • โœ… Trade on low-latency L2s (Arbitrum, Optimism)

๐Ÿ’” Impermanent Loss: The LP's Biggest Riskโ€‹

Apa itu Impermanent Loss?โ€‹

Impermanent Loss (IL) = kerugian "sementara" yang dialami LP ketika harga tokens berubah dibandingkan dengan saat deposit.

Disebut "impermanent" karena:

  • Kerugian hilang jika harga kembali ke titik awal
  • Menjadi permanen jika Anda withdraw

Example: ETH/USDC Poolโ€‹

Scenario:

Initial deposit (Day 0):

Price: 1 ETH = 2,000 USDC

You deposit:
- 1 ETH
- 2,000 USDC
Total value: $4,000

Pool total:
- 100 ETH
- 200,000 USDC
Your share: 1%

Strategy A: Just HODL (tidak jadi LP)

Day 0: 1 ETH + 2,000 USDC = $4,000

After 30 days: ETH price DOUBLES (2,000 โ†’ 4,000 USDC)

Your holdings:
- 1 ETH (worth $4,000)
- 2,000 USDC (worth $2,000)
Total: $6,000 ๐ŸŽ‰

Gain: $2,000 (50% profit)

Strategy B: LP di pool

After ETH doubles, arbitrageurs balance pool:

Before arbitrage:

100 ETH ร— 200,000 USDC = 20,000,000 (k)
External price: 4,000 USDC per ETH
Pool price: 2,000 USDC per ETH (out of sync!)

Arbitrageurs buy cheap ETH dari pool until prices match:

After arbitrage (balanced):

Pool must satisfy:
- x ร— y = 20,000,000
- y / x = 4,000 (match market price)

Solving:
x ร— (4,000x) = 20,000,000
4,000xยฒ = 20,000,000
xยฒ = 5,000
x = 70.71 ETH

y = 4,000 ร— 70.71 = 282,843 USDC

New pool composition:

70.71 ETH ร— 282,843 USDC = 20,000,000 โœ…

(Was 100 ETH ร— 200,000 USDC initially)

Your 1% share:

You receive:
- 0.7071 ETH (worth $2,828)
- 2,828 USDC (worth $2,828)
Total: $5,656

Plus trading fees earned: ~$50 (assumed)
Grand total: $5,706

Compare strategies:

Strategy A (HODL):      $6,000 โœ…
Strategy B (LP): $5,706 โŒ

Impermanent Loss: $6,000 - $5,706 = $294
IL percentage: $294 / $6,000 = 4.9%

You LOST $294 by being LP instead of HODL! ๐Ÿ˜ž


๐Ÿงฎ IL Formulaโ€‹

For x% price change:

IL = 2 ร— โˆš(price_ratio) / (1 + price_ratio) - 1

Where:

price_ratio = new_price / initial_price

Common IL scenarios:

Price ChangeImpermanent Loss
1.25x (25% up)-0.6%
1.5x (50% up)-2.0%
2x (100% up)-5.7%
3x (200% up)-13.4%
4x (300% up)-20.0%
5x (400% up)-25.5%

Observations:

  • ๐Ÿ“ˆ Higher price change = higher IL (exponential!)
  • โš ๏ธ 4x price = 20% IL (significant!)
  • ๐Ÿ˜ฑ Large moves = devastating IL

When Do Fees Overcome IL?โ€‹

LPs profit when:

Trading Fees Earned > Impermanent Loss

Example:

ETH doubles (2x), IL = 5.7%

Your initial value: $4,000
IL loss: $4,000 ร— 5.7% = $228

If you earned $300 in fees:
Net profit: $300 - $228 = +$72 โœ…

Key factors:

  1. High trading volume = more fees
  2. Low volatility = less IL
  3. Time = more fees accumulate

Best pairs untuk menjadi LP:

  • โœ… Stablecoin pairs (USDC/USDT, DAI/USDC) - minimal IL
  • โœ… Correlated assets (ETH/stETH, WBTC/renBTC) - low IL
  • โš ๏ธ Volatile pairs (ETH/SHIB, ETH/MEME) - high IL risk

IL Visualizationโ€‹

Graph:

Profit/Loss (%)
โ”‚
โ”‚ HODL (linear growth)
โ”‚ โ•ฑ
โ”‚ โ•ฑ
โ”‚ โ•ฑ
โ”‚ โ•ฑ
โ”‚โ•ฑ_____________________ Price Change
โ”‚ โ•ฒ
โ”‚ โ•ฒ
โ”‚ โ•ฒ LP (IL drag)
โ”‚ โ•ฒ

Interpretation:

  • When price is stable โ†’ LP earns fees (ahead of HODL)
  • When price moves significantly โ†’ HODL outperforms (IL kicks in)

๐Ÿ›ก๏ธ IL Protection Strategiesโ€‹

1. Choose Low-IL Pairsโ€‹

Stablecoin pairs:

USDC/DAI, USDT/USDC
โ†’ Minimal IL (maybe 0.01%)
โ†’ Lower fees (0.01% instead of 0.3%)
โ†’ Still profitable due to high volume

2. Provide Liquidity Short-Termโ€‹

During high volatility:

  • โŒ Avoid LP (too much IL risk)

During consolidation/sideways:

  • โœ… LP aggressively (fees without IL)

Withdraw before major moves!


3. Use Concentrated Liquidity (Uniswap V3)โ€‹

Uniswap V3 allows you to provide liquidity in specific price range:

Instead of:
0 โ†’ โˆž (inefficient, most capital idle)

You choose:
2,400 - 2,600 USDC per ETH (concentrated!)

Benefits:

  • โœ… Capital efficient (earn more fees per $)
  • โœ… Lower IL (if price stays in range)

Risks:

  • โŒ Out-of-range = no fees earned (need active management)

4. IL Insurance/Protectionโ€‹

Some protocols offer IL protection:

Bancor:

  • 100% IL protection after 100 days staked
  • Protocol uses BNT emissions untuk menutupi IL

Tokemak:

  • "Liquidity Directors" vote on incentives
  • Single-sided staking (no IL!)

๐ŸŽฏ Advanced AMM Variantsโ€‹

1. Constant Product (x ร— y = k)โ€‹

Used by: Uniswap V1, V2, SushiSwap

Pros:

  • โœ… Simple
  • โœ… Works for any pair

Cons:

  • โŒ Capital inefficient (most idle)
  • โŒ High slippage untuk trading besar

2. Stable Swap (Curve)โ€‹

Formula: Hybrid antara constant product & constant sum

Optimized for: Stablecoin pairs

Example:

USDC/USDT/DAI pool
โ†’ Minimal slippage even untuk trading besar
โ†’ 0.04% fee (lower than Uniswap)

Hasilnya:

  • โœ… Deep liquidity untuk stables
  • โœ… Minimal IL

3. Concentrated Liquidity (Uniswap V3)โ€‹

LPs choose price range:

Traditional: Provide liquidity 0 โ†’ โˆž
V3: Provide liquidity 2,400 โ†’ 2,600 USDC per ETH

Benefits:

  • โœ… 4,000x more capital efficient (if range tight!)
  • โœ… Earn more fees per $ deposited

Trade-offs:

  • โŒ Active management needed
  • โŒ Out-of-range = no fees

4. Dynamic Fees (Uniswap V4, Balancer)โ€‹

Fees adjust based on volatility:

Low volatility: 0.05% fee
High volatility: 1% fee (melindungi LPs dari IL)

5. Weighted Pools (Balancer)โ€‹

Not 50/50, can be any ratio:

Example:
80% WETH / 20% USDC

โ†’ Less IL (more exposure to WETH)
โ†’ Similar to "hodling" with some LP fees

๐Ÿง  Key Takeawaysโ€‹

AMM Core Conceptsโ€‹

  1. โœ… x ร— y = k is simple but brilliant formula
  2. โœ… Larger pool = more stable price (less slippage)
  3. โœ… Price impact meningkat secara eksponensial sesuai dengan ukuran trade
  4. โœ… Arbitrageurs keep AMM prices synced dengan external markets

For Tradersโ€‹

  1. โœ… Check price impact before large trades
  2. โœ… Set appropriate slippage (1-2% for most trades)
  3. โœ… Split large orders untuk mengurangi impact
  4. โœ… Use aggregators (1inch, Matcha) untuk mendapatkan harga terbaik

For LPsโ€‹

  1. โœ… Understand IL - biggest risk!
  2. โœ… Choose pairs wisely (correlated = less IL)
  3. โœ… High volume pairs = more fees to overcome IL
  4. โœ… Monitor positions (pertimbangkan active management untuk V3)
  5. โœ… Calculate break-even:
    Days to break-even = IL / Daily fees

๐Ÿ”œ Next: Build Your Own DEX!โ€‹

Di Part 4: Hands-on Lab - Build Simple DEX โ†’, kita akan:

  • ๐Ÿ’ป Build SimpleDEX smart contract dengan Solidity
  • โš™๏ธ Implement x ร— y = k formula di code
  • ๐Ÿงช Write comprehensive tests
  • ๐Ÿš€ Deploy ke Lisk Sepolia testnet
  • ๐ŸŽจ (Optional) Build frontend interface

Sekarang Anda paham teori. Time to code it! ๐Ÿ’ช


๐Ÿ“š Further Resourcesโ€‹

Videosโ€‹

Articlesโ€‹

Toolsโ€‹

Deep Divesโ€‹


Ready to code? Let's build! Part 4 โ†’ ๐Ÿš€