This content originally appeared on DEV Community and was authored by Mahima Thacker
Not anymore
This might seem long, but trust me it’s worth every scroll
Let’s break it down in simple terms — no advanced math, no technical fluff.
1/ What is AMM?
- An AMM (Automated Market Maker) is like a robot that lets you swap tokens without needing a buyer or seller.
- Instead of matching orders like an order book used in a centralised exchange. it uses a liquidity pool (a jar of tokens) and a formula to decide the price. So,
- No order books
- No middlemen
- Just a smart contract doing the job
- The formula calculated the price ->X * Y = K
2/ What’s in the Liquidity Pool?
- Each pool holds two tokens, say: Token 1 = ETH (e.g., 50 ETH) Token 2 = DAI (e.g., 10,000 DAI)
- This pool is created by users (called liquidity providers) who deposit equal value of both tokens.
3/ The Magic Formula: X * Y = K
This is the core logic of how prices are determined.
X = Amount of Token 1 (ETH)
Y = Amount of Token 2 (DAI)
K = Constant value that should never changeAs you trade, the values of X and Y shift, but K always remains the same. That’s what keeps everything balanced!
4/ Let’s Understand With an Example:
- Before Trade: ETH in pool = 50 DAI in pool = 10,000 Constant K = 50 * 10,000 = 500,000
Now let’s say you want to buy 1 ETH using DAI.
- After the Trade: ETH left = 49 (because you took out 1 ETH)
- To maintain K = 500,000, the pool must now hold more DAI. 49 * Y = 500,000 Y = 500,000 / 49 ≈ 10,204.08 DAI
So the pool needs 10,204.08 DAI after your trade. That means you have to add ~204.08 DAI to buy 1 ETH
That’s how price is automatically calculated — by using the formula, not a person
5/ Why Price Increases as You Trade?
The more ETH you try to buy, the more DAI you must add to keep K constant.
This makes ETH more expensive with each purchase. That’s slippage — and it’s normal in AMMs
6/ Order Book vs AMM
In an order book, trades are matched between buyers and sellers at the same price.
In an AMM, the price is calculated automatically based on how much is in the pool
7/ Final Takeaway
- You’re trading with math, not a person.
- The pool keeps everything balanced using X * Y = K.
- More buying = price goes up (and vice versa).
- No need for someone on the other side — you just interact with the pool!
This content originally appeared on DEV Community and was authored by Mahima Thacker