Introduction to Markets
How Centralized Exchanges Work
From Blabla :
- Market Maker wins with funding rate
- Binance : when you make an order → more fees than just buy for the price of the market → it will try to fill some sell orders
Constant Function Market Makers
https://github.com/Uniswap/v2-core/blob/master/contracts/UniswapV2Pair.sol
Why:
- There is
skim()
ANDsync()
? - Deep dive :
// scope for _token{0,1}, avoids stack too deep errors
Pricing
The Curve
From Blabla:
- Calculate the number of token B: integral of B - A
- The area under the curve between the start price and end price
Introduction to Uniswap V3
Understand the core
Develop some core concepts from the whitepaper
Understand
$$ L = \sqrt{x \cdot y} $$ELI5 - true purpose of the used of the geometric mean
Imagine you and your friend decide to buy a big pizza together. You pay $8, and your friend pays $12. The whole pizza is worth $20.
Now, the pizza shop gives you a special coupon that says you own a part of the pizza. This coupon is like a share in the pizza. If the pizza shop used a simple method to calculate your share, they might say you own 40% of the pizza ($8 out of $20), and your friend owns 60% ($12 out of $20).
But this method has a problem. Let’s say another friend joins in and pays $20 for the same pizza. Now, the pizza is worth $40. If the pizza shop uses the simple method, your share suddenly becomes smaller (20% instead of 40%), even though you paid the same amount of money!
To avoid this unfairness, the pizza shop uses a special math trick called the geometric mean. This trick makes sure that your share of the pizza stays the same, no matter how much money your friends pay for their shares.
With the geometric mean, your share is calculated like this:
$$ \sqrt{8\$ * 20\$} = 12.65\$ $$This means you own a part of the pizza that’s always worth $12.65, regardless of how much your friends pay.
In the same way, Uniswap v2 uses the geometric mean to calculate the shares of a liquidity pool. This ensures that your share of the pool stays the same, no matter what ratio of tokens other people deposit. This way, everyone gets a fair share of the pool based on how much they put in, and no one’s share gets unfairly reduced.