Tutorials:Automated Market Making
Revision as of 01:41, 4 November 2025 by Move page script (talk | contribs) (Move page script moved page Tutorials:78ee to Tutorials:Automated Market Making)
Quest: Automated Market Making
Liquidity Pools are used to implement decentralized, automated, and trust-less markets.
- These work differently from traditional order-book-based exchanges, where buyers and sellers place orders, and the exchange matches them.
- In a decentralized exchange, a person trades with the liquidity pool, not directly with another person.
Key Concepts
- Buying or selling a token in a decentralized exchange affects the price of the token.
- The price is calculated after the impact of your trade is taken into account.
- To calculate the price Uniswap uses the Constant Product Formula.
Formula for Token Price
Let’s assume a liquidity pool contains:
- T amount of tokens
- E amount of Ether
The price of a token in units of Ether is given by:
P = E / T
- Buyers:
- Take tokens and deposit Ether, increasing the price.
- Sellers:
- Deposit tokens and take Ether, decreasing the price.
Price Determination
Prices are determined by maintaining the condition:
T * E = k
Where k is a constant.
Why this condition?
- The formula is simple and requires no active management.
- It ensures the liquidity pool can never be completely drained of either asset.
- Prices are sensitive to trade size: Larger trades have a more significant impact on the price.
This encourages smaller, frequent trades and discourages large market-moving trades.
Key Insights:
- When you buy:
- You don’t get the listed price but a higher price calculated after your Ether is deposited, and tokens are taken. - The more you want to buy, the more expensive it gets.
- When you sell:
- You don’t get the listed price but a lower price calculated after your tokens are deposited, and Ether is taken. - The more you sell, the cheaper it gets.
Example:
An example will be better for understanding how this works.