# 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).


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://midaswap.gitbook.io/docs/concepts/bin-and-tick.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
