Bin & Tick
Last updated
Last updated
Bin is a price scale, and like Tick in Uniswap v3, its price is calculated by the formulaand the range of integer is
We use uint256 to record the price, so the theoretical maximum value of the price is . 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
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 . Second, since we set binstep to 0.0001, there is more than 1 bin i letting
Therefore, the actual upper limit of the total amount of bins should be . It is worth noting that this is less than , so there will be no unrecorded situation.
The price inside each bin is determined, and the liquidity curve is , 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).