> For the complete documentation index, see [llms.txt](https://developers.lfj.gg/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://developers.lfj.gg/contracts/libraries/math/liquidityconfigurations.md).

# LiquidityConfigurations

[Git Source](https://github.com/traderjoe-xyz/joe-v2/blob/16f011d25e6bf6d0a0c479974345b623d491104f/src/libraries/math/LiquidityConfigurations.sol)

This library contains functions to encode and decode the config of a pool and interact with the encoded bytes32.

## State Variables

### OFFSET\_ID

```solidity
uint256 private constant OFFSET_ID = 0;
```

### OFFSET\_DISTRIBUTION\_Y

```solidity
uint256 private constant OFFSET_DISTRIBUTION_Y = 24;
```

### OFFSET\_DISTRIBUTION\_X

```solidity
uint256 private constant OFFSET_DISTRIBUTION_X = 88;
```

### PRECISION

```solidity
uint256 private constant PRECISION = 1e18;
```

## Functions

### encodeParams

*Encode the distributionX, distributionY and id into a single bytes32*

```solidity
function encodeParams(uint64 distributionX, uint64 distributionY, uint24 id) internal pure returns (bytes32 config);
```

**Parameters**

| Name            | Type     | Description                          |
| --------------- | -------- | ------------------------------------ |
| `distributionX` | `uint64` | The distribution of the first token  |
| `distributionY` | `uint64` | The distribution of the second token |
| `id`            | `uint24` | The id of the pool                   |

**Returns**

| Name     | Type      | Description                                                                                                               |
| -------- | --------- | ------------------------------------------------------------------------------------------------------------------------- |
| `config` | `bytes32` | The encoded config as follows: \[0 - 24\[: id \[24 - 88\[: distributionY \[88 - 152\[: distributionX \[152 - 256\[: empty |

### decodeParams

*Decode the distributionX, distributionY and id from a single bytes32*

```solidity
function decodeParams(bytes32 config) internal pure returns (uint64 distributionX, uint64 distributionY, uint24 id);
```

**Parameters**

| Name     | Type      | Description                                                                                                               |
| -------- | --------- | ------------------------------------------------------------------------------------------------------------------------- |
| `config` | `bytes32` | The encoded config as follows: \[0 - 24\[: id \[24 - 88\[: distributionY \[88 - 152\[: distributionX \[152 - 256\[: empty |

**Returns**

| Name            | Type     | Description                               |
| --------------- | -------- | ----------------------------------------- |
| `distributionX` | `uint64` | The distribution of the first token       |
| `distributionY` | `uint64` | The distribution of the second token      |
| `id`            | `uint24` | The id of the bin to add the liquidity to |

### getAmountsAndId

*Get the amounts and id from a config and amountsIn*

```solidity
function getAmountsAndId(bytes32 config, bytes32 amountsIn) internal pure returns (bytes32, uint24);
```

**Parameters**

| Name        | Type      | Description                                                                                                               |
| ----------- | --------- | ------------------------------------------------------------------------------------------------------------------------- |
| `config`    | `bytes32` | The encoded config as follows: \[0 - 24\[: id \[24 - 88\[: distributionY \[88 - 152\[: distributionX \[152 - 256\[: empty |
| `amountsIn` | `bytes32` | The amounts to distribute as follows: \[0 - 128\[: x1 \[128 - 256\[: x2                                                   |

**Returns**

| Name     | Type      | Description                                                                   |
| -------- | --------- | ----------------------------------------------------------------------------- |
| `<none>` | `bytes32` | amounts The distributed amounts as follows: \[0 - 128\[: x1 \[128 - 256\[: x2 |
| `<none>` | `uint24`  | id The id of the bin to add the liquidity to                                  |

## Errors

### LiquidityConfigurations\_\_InvalidConfig

```solidity
error LiquidityConfigurations__InvalidConfig();
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

```
GET https://developers.lfj.gg/contracts/libraries/math/liquidityconfigurations.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
