> ## Documentation Index
> Fetch the complete documentation index at: https://shield.fi/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Liquidity formulas

> Current Q128.128 amount and liquidity relationships.

Let `P` be current Q128.128 square-root price. Let `A < B` be the lower and upper Q128.128 boundaries. Let `L` be liquidity. Amounts are native token base units.

## Amounts from liquidity

Below the range:

```text theme={"languages":{"custom":["/languages/leo.tmLanguage.json"]}}
amount0 = L * 2^128 * (B - A) / (A * B)
amount1 = 0
```

Inside the range:

```text theme={"languages":{"custom":["/languages/leo.tmLanguage.json"]}}
amount0 = L * 2^128 * (B - P) / (P * B)
amount1 = L * (P - A) / 2^128
```

Above the range:

```text theme={"languages":{"custom":["/languages/leo.tmLanguage.json"]}}
amount0 = 0
amount1 = L * (B - A) / 2^128
```

The contract applies explicit floor or ceiling rounding and saturation checks through wide helpers.

## Liquidity cap

Pool creation calculates a net-liquidity-sum cap from the number of usable ticks and then selects the smaller value against `LIQ_AMOUNT_SAFE_CAP = 702075911466779181339691826086`.

Read `Slot.max_liquidity_per_tick` from chain state. Do not reconstruct it from a legacy Q64 constant.

## Mint and increase

The contract transfers the full desired amounts into public AMM custody, calculates the maximum supported liquidity, and then calculates the actual native base-unit amounts used. It credits `desired - used` to the position's public `tokens_owed` balances. The returned token change records contain only input-record value above the desired transfer amounts.
