> For the complete documentation index, see [llms.txt](https://midaswap.gitbook.io/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://midaswap.gitbook.io/docs/concepts/bin-and-tick.md).

# Bin & Tick

### What is Bin?

Bin is a price scale, and like Tick in Uniswap v3, its price is calculated by the formula$$Price=1.0001^{i}$$and the range of integer $$i$$ is $$i=\[-2^{23},2^{23}]$$

### **Bin Pricing**

We use uint256 to record the price, so the theoretical maximum value of the price is $$2^{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 $$\[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 $$2^{24}$$. Second, since we set binstep to 0.0001, there is more than 1 bin i letting $$(1+0.0001)^i<2^{128}$$

&#x20;                                                                $$(1+0.0001)^i < 2^{128}$$&#x20;

&#x20;                                                           $$log\_2(1.0001)^i < log\_2(2^{128})$$

&#x20;                                                              $$i\* log\_2(1.0001) < 128$$

&#x20;                                                            $${i<\frac{128}{log\_2(1.0001)}}\approx887,273$$

&#x20;                                                                      $$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 $$2^{24}$$, 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).
