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:
- โ Menentukan harga aset berdasarkan rasio di liquidity pool
- โ Memungkinkan trading instant tanpa order book
- โ Menggunakan formula matematika (biasanya x ร y = k)
- โ 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:
- ๐ k harus tetap konstan (kecuali ada liquidity added/removed)
- ๐ Price = y / x (ratio dari kedua token)
- ๐ 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:
- Beli kentang murah dari pool ($0.746)
- Jual kentang di market eksternal ($1)
- Profit: $1 - $0.746 = $0.254 per kentang (34% profit!)
Atau:
- Beli apel dari market eksternal ($1)
- Jual apel di pool ($1.34)
- 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:
- Buy cheap ETH dari pool (pay 1,000 USDC, get 1 ETH)
- Sell ETH di Coinbase (receive 2,500 USDC)
- 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:
- Price impact (your trade)
- 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 Change | Impermanent 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:
- High trading volume = more fees
- Low volatility = less IL
- 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โ
- โ x ร y = k is simple but brilliant formula
- โ Larger pool = more stable price (less slippage)
- โ Price impact meningkat secara eksponensial sesuai dengan ukuran trade
- โ Arbitrageurs keep AMM prices synced dengan external markets
For Tradersโ
- โ Check price impact before large trades
- โ Set appropriate slippage (1-2% for most trades)
- โ Split large orders untuk mengurangi impact
- โ Use aggregators (1inch, Matcha) untuk mendapatkan harga terbaik
For LPsโ
- โ Understand IL - biggest risk!
- โ Choose pairs wisely (correlated = less IL)
- โ High volume pairs = more fees to overcome IL
- โ Monitor positions (pertimbangkan active management untuk V3)
- โ
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โ
- Whiteboard Crypto: What is an Automated Market Maker? - Analogi petani!
- Finematics: How Do Liquidity Pools Work?
- Finematics: Impermanent Loss Explained
Articlesโ
Toolsโ
Deep Divesโ
Ready to code? Let's build! Part 4 โ ๐