Download uniswap whitepaper: https://app.uniswap.org/whitepaper.pdf
it’s not very friendly to read, I learned so hard, then this is my summaries.
Origin AMM formula:
Assume the fee is 0.3% (in uniswapv-v2, this is a fixed fee), dx is the token you’re trying to exchange, the fee will be charged on this dx, so we just change the dx of the formula above like list:
this is the dy we correctly will get. And, this formula actually is what the getAmountOut function does, look:
function getAmountOut(...) {
...
uint amountInWithFee = amountIn.mul(997); //1-0.003=0.997
...
}
Once the fee is taken out, it flows into the pool, not to a specific account, so the liquidity will increase as swaps accumulate.
Here is the breakdown of the flow.
-
Here is pool for USDT/DAI, initially their liquidity are: (100USDT and 100 DAI, they’re woth same)
1
2
3
4
5
6
7
8
9Liquidity(√k)
^
| 100 100
| ██ ██
| ██ ██
| ██ ██
| ██ ██
+--+---+---+---+---> token
USDT DAI -
After some swaps, USDT got 104, DAI got 98.
1
2
3
4
5
6
7
8
9Liquidity(√k)
^
| 104
| ██ 98
| ██ ██
| ██ ██
| ██ ██
+--+---+---+---+---> token
USDT DAI -
But immediately, they return back a balanced position. Bcz there usually are arbitrage bots are keep detecting whether there are an imbalance that can profit from , which brings the pool back to balance.
1
2
3
4
5
6
7
8
9Liquidity(√k)
^
| 101 101
| ██ ██
| ██ ██
| ██ ██
| ██ ██
+--+---+---+---+---> token
USDT DAI -
Can easily see they’ve increased, say again: once the fee is taken out, it flows into the pool, not to a specific account, so the liquidity will increase as swaps accumulate.
pool liquidity
-
The growth in liquidity , that's exactly where LPs earn, as the pool growth , so do their profit. Amount of the profit just is equivalent to the `increased liquidity`, equivalent to sum of all gathered fees.→increased liquidity
But, where does the project team who writes contracts benefit from? -
in uniswap-v2’s code project team doesn’t charge fee for themselves by default, can open it by giving an account address which receives fee to the
feeTovariable inUniswapV2Pair.sol’s factory’:function _mintFee(...) returns (bool feeOn) { ... address feeTo = IUniswapV2Factory(factory).feeTo(); feeOn = feeTo != address(0); // feeTo=0x0, feeOn=false, by default. if (feeOn) { ... } } -
If we set feeTo to an account address , what will that be?
-
Obviously, according to the
_mintFeefunction above, it will get into theifcharges fee to the account. -
there’s a φ=1/6 , means project team will take away 1/6 of the
increased liquidity.
-
-
-
let φ=1/6,
Sm goes to project team, the rest goes to the LPs.