> For the complete documentation index, see [llms.txt](https://magma-finance-1.gitbook.io/magma-developer-sdk/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://magma-finance-1.gitbook.io/magma-developer-sdk/clmm_contract/22.liquidity-correlation-calculation.md).

# Liquidity correlation calculation

## 1. Liquidity to CoinAmount

Method: `ClmmPoolUtil.getCoinAmountFromLiquidity`

### Example

```typescript
const pool = await sdk.Pool.getPool(poolAddress)

const position = await sdk.Position.getSimplePosition(positionAddress)

const lowerSqrtPrice = TickMath.tickIndexToSqrtPriceX64(position.tick_lower_index)
const upperSqrtPrice = TickMath.tickIndexToSqrtPriceX64(position.tick_upper_index)


const liquidity = new BN(position.liquidity)
const curSqrtPrice = new BN(pool.current_sqrt_price)

const lowerSqrtPrice = TickMath.tickIndexToSqrtPriceX64(position.tick_lower_index)
const upperSqrtPrice = TickMath.tickIndexToSqrtPriceX64(position.tick_upper_index)

const amounts = ClmmPoolUtil.getCoinAmountFromLiquidity(
  liquidity,
  curSqrtPrice,
  lowerSqrtPrice,
  upperSqrtPrice,
  false
)

const {coinA, coinB} = amounts
```

## 2. Price to TickIndex

when you want to open position, you dont know how to set your tick\_lower and tick\_upper.

use `/src/math/tick.ts TickMath.priceToTickIndex()`

```typescript
// decimalsA and decimalsB means the decimal of coinA and coinB
const tick_lower = TickMath.priceToTickIndex(price, decimalsA, decimalsB)
```

## 3. Calculate price from sqrt price

use `/src/math/tick.ts TickMath.sqrtPriceX64ToPrice()`

```typescript
const pool = await sdk.Pool.getPool(poolAddress)
const price = TickMath.sqrtPriceX64ToPrice(new BN(pool.current_sqrt_price))
```
