What is AMM
Automated Market Maker (AMM) is a pricing & liquidity-determined mechanism commonly used by decentralized exchanges (DEXes). Simply put, those who wish to provide liquidity will place two types of assets in a particular proportion into an asset pool (essentially a smart contract), allowing other traders to trade with the assets in the pool directly. The asset pool uses an algorithm based on the asset supply and demand ratio to determine asset prices automatically, and this is what AMM is.
"Market making" is a common practice that originated from TradFi. A market maker actively answers bids and initiates sell orders, and in this way, it provides liquidity to the market. Kind of like somebody who actively introduces strangers to each other at an awkward party👯♂️👯♀️.
Uniswap and most other DEXs use an Automated Market Maker (AMM) to produce "unlimited liquidity" (i.e., trade whenever you want😎). The assets in a pool are priced relative to each other according to the Constant Function algorithm. It means that any trade must change the reserves so that the product of those reserves remains unchanged (i.e., equal to a constant). In short, to remove a token from the pool, a certain number of other tokens must be deposited.
How AMM works? A Cartoon Guide to AMM
To better illustrate how AMM works, let's return to the ages of bartering.
Suppose you are an apple farmer in the age of bartering where no currency exists. You want to trade some watermelons with your friend John, who happens to have watermelons but would like to make some apple juice.
But sometimes John may be busy, and you need help finding him to exchange your fruits in person. Besides, there are other fruits you want, but you don't know who to look for. There are also a lot of people facing the same problem.
Answering the call, one day, an organization called Unifruit proposes a decentralized fruitshop. Basically, they created a warehouse with a lot of baskets. Each basket contains two different fruits.
✔The goal is simple: a farmer who wants to exchange bananas for oranges can always find the basket with these two fruits, put his bananas in and take some oranges out. No need to wait for the orange farmer.
Now you may have these questions in mind:
❓ Say I go to the Apple/Watermelon basket and want 2 watermelons. How many apples should I put in? And the reverse?
Now let's just assume that everyone in this world is with good faith, willing to obey all rules set by Unifruit.
After being hit by an apple, a member of Unifruit proposes an algorithm for automatically computing the relative price of the fruits, which eventually is agreed upon and known as the constant product algorithm.
Suppose initially, there are 4 apples and 6 watermelons in the basket. Then the product of the number of fruits is 4 * 6 = 24.
Now you want to take 2 watermelons away, leaving 4 watermelons and 4 apples in the basket. But the constant product rule is broken!
In order to make the product 24 again, you will need the number of apples in the pool after the trade to be 24 / 4 = 6. Now there are 4 apples in the basket, so you will need to put 2 more apples into the basket.
The price for this transaction is therefore 1 apple per watermelon.
Suppose then you want to buy 2 watermelons further, leaving only 2 watermelons in the basket. How many apples should you put into the basket?
To reach balance, there should be 24 / (4 - 2) = 12 apples in the basket by the end.
This means that you need to put 6 more apples into the basket.
The price for watermelon is now : 6 apples/2 watermelons, or 3 apples/watermelon
As can be seen from the small quiz above, as the number of watermelons decrease in the basket, a higher number of apples is charged, which coincides with the supply & demand rule.
❓ Then where do all the fruits come from in the first place? If not Unifruit, why are the providers willing to give away their fruits?
Surprisingly, these fruits come from other farmers just like you and John！In order to create a sustainable supply system, Unifruit encourages farmers to hop in and create their own baskets with two different kinds of fruits, effectively becoming "basket providers". For each transaction that happens in the basket, Unifruit requires the buyer to leave some fruit seeds for the basket provider as compensation. In this way, farmers are incentivised to become basket providers.
Order books vs AMM
The key difference between AMM and order books lies in the mechanism of trading and price determination.
While users trade with each other on a CEX using order books (a buy order needs to be paired up with a sell order), AMM users trade against a liquidity pool of a pair of assets.
For instance, if you would like to buy some $ETH with $USDC, the steps taken on different exchanges are as follows:
- Submit a buy order with bid price
- Wait for a sell order with equal or lower selling price
- Find a liquidity pool with $USDC and $ETH
- Take $ETH from the pool. At the same time, put $USDC into the pool, with the amount calculated by pre-determined rules
If it happens that ALL sell orders ask for a higher price than your bid (and you don't want to compromise), your order will be hung up until a seller meets your requirement . This is not the case for AMM, where you can trade directly with the liquidity pool anytime you want.
What else do you want to learn?