Bin & Tick
What is Bin?
Bin is a price scale, and like Tick in Uniswap v3, its price is calculated by the formulaPrice=1.0001iand the range of integer i is i=[−223,223]
Bin Pricing
We use uint256 to record the price, so the theoretical maximum value of the price is 2256−1. Since we have to consider the very small price, we still use 128. 128 binary fixed-point numbers: The first 128 bits are used to record the left of the decimal point, and the last 128 bits are used to record the right of the decimal point. Because our price range is [2−128,2128]
Bin Limits
Through the price range, we can calculate the upper limit of the number of bins. First, since we use uint24 to record the bin number, the upper limit of the number of bins is 224. Second, since we set binstep to 0.0001, there is more than 1 bin i letting (1+0.0001)i<2128
(1+0.0001)i<2128
log2(1.0001)i<log2(2128)
i∗log2(1.0001)<128
i<log2(1.0001)128≈887,273
i=887,272
Therefore, the actual upper limit of the total amount of bins should be 887,272∗2=1,777,544. It is worth noting that this is less than 224, so there will be no unrecorded situation.
Bin Liquidity
The price inside each bin is determined, and the liquidity curve is P∗x+y=L, where x is the number of X assets, y is the number of Y assets, and P is the price of the current bin (X assets are in units of Y).
Last updated