Automated Market Maker (AMM) is a pricing and liquidity determination mechanism commonly used in DEX. Simply put, people who want to provide liquidity put two assets into an asset pool (actually a set of smart contracts) in a certain proportion, allowing other traders to directly trade with the assets in the pool. The asset pool uses a method based on The algorithm of asset supply and demand ratio automatically determines asset prices. This is AMM.
“Market making” is a common practice originating from traditional finance (TradFi). Market makers actively respond to buyer orders and initiate sell orders, thereby providing liquidity to the market. A bit like a familiar person who takes the initiative to introduce strangers to each other at an awkward party?♂️?♀️.
Many DEXs (such as Uniswap) use automatic market makers (AMMs) to create so-called "unlimited unlimited liquidity" (that is, trading anytime, anywhere?). The relative pricing of assets in the pool is based on the Constant Product Function algorithm. This means that when buying or selling any one currency, the reserve of the other currency must be changed at the same time, so that the product of the reserves of the two currencies in the pool remains unchanged (that is, equal to a constant). Simply put, to take one coin from the pool, a certain number of another coin must be placed.
To better explain how AMM works, let us go back to the era of "barter".
Suppose you are an apple farmer living in a time without money. You want to trade some watermelons with your friend John, who happens to have watermelons, but wants to make some apple juice.
But sometimes John may be busy and you cannot find him to exchange fruits. Also, you want other fruits but don’t know who to ask for. There are many people facing the same problem. In order to respond to this demand, one day an organization called Unifruit proposed the idea of a decentralized fruit store. Basically, they created a warehouse with lots of fruit baskets. Each basket contains two different fruits.
✔ The goal is simple: people who want to buy fruit can always find the two fruits they want to exchange The basket can be redeemed directly without the need to find a specific fruit farmer. For example, a person who wants to exchange bananas for oranges can find this basket, put his bananas in it, and take out some oranges. There is no need to find a farmer who cultivates oranges to trade.
Now you may have the following questions: ❓ Suppose I go to the apple/watermelon basket and want 2 watermelons. How many apples should I put in? What about the other way around? Now, let's assume that everyone in this world has integrity and is willing to abide by all the rules set by Unifruit. After being hit by an apple, a member of Unifruit proposed an algorithm to automatically calculate the relative prices of fruits, which was eventually adopted and became known as the constant product algorithm.
Assume that there are 4 apples and 6 watermelons in the basket initially, then the product of the number of fruits is 4 * 6 = 24
Now you want to take away the two watermelons, leaving only 4 watermelons and 4 apples in the basket. However, at this time the rule of constant product is broken!
In order for the product to equal 24 again, you need the number of apples in the basket after the transaction to be 24 / 4 = 6. There are only 4 apples in the basket now, so you need to put 2 more apples into the basket.
Therefore, the actual price of this transaction is 1 apple / 1 watermelon.
Then suppose you want to buy 2 more watermelons, leaving only 2 watermelons in the basket. How many apples should you put in the basket?
To achieve equilibrium, the basket should end up with 24 / (4 - 2) = 12 apples.
This means you need to put 6 more apples into the basket.
The current price of watermelons is: 6 apples / 2 watermelons, or 3 apples / 1 watermelon.
As can be seen from the above quiz, as the number of watermelons in the basket decreases, more apples are collected, which is in line with the law of supply and demand.
❓ You may ask, where did all the fruit come from in the first transaction? If it wasn't Unifruit, why would the provider be willing to give up their fruit?
Amazingly, these fruits come from other farmers like you and John! To create a sustainable supply system, Unifruit encourages farmers to get involved and become "basket providers" by creating their own baskets filled with two different types of fruit. Whenever a transaction occurs in the basket, Unifruit requires the buyer to leave some fruit seeds as compensation to the basket provider. In this way, farmers are motivated to become basket providers.
A key difference between AMM and order book model is the price determination mechanism and trading mechanism.
In the order book model, transactions are conducted between users (buy orders in the order book need to be paired with sell orders), while AMM users trade with the liquidity pool of a certain pair of assets. If you want to buy some ETH with USDC, the steps to take in two different types of modes are as follows:
In the order book, if all the sell orders ask for a price higher than your buy order (and you don’t want to compromise), then your order will be put on hold until a seller meets your request. But with AMMs, you can trade with liquidity pools at any time and directly.