Bin & Tick

What is Bin?

Bin is a price scale, and like Tick in Uniswap v3, its price is calculated by the formulaPrice=1.0001iPrice=1.0001^{i}and the range of integer ii is i=[223,223]i=[-2^{23},2^{23}]

Bin Pricing

We use uint256 to record the price, so the theoretical maximum value of the price is 225612^{256-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 [2128,2128][2^{-128},2^{128}]

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 2242^{24}. 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<2^{128}

(1+0.0001)i<2128(1+0.0001)^i < 2^{128}

log2(1.0001)i<log2(2128)log_2(1.0001)^i < log_2(2^{128})

ilog2(1.0001)<128i* log_2(1.0001) < 128

i<128log2(1.0001)887,273{i<\frac{128}{log_2(1.0001)}}\approx887,273

i=887,272i=887,272

Therefore, the actual upper limit of the total amount of bins should be 887,2722=1,777,544887,272*2=1,777,544. It is worth noting that this is less than 2242^{24}, so there will be no unrecorded situation.

Bin Liquidity

The price inside each bin is determined, and the liquidity curve is Px+y=LP*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