fintech-algorithms
Using a coding agent? Give it the skill: npx skills add IslamBaraka90/Fintech-Algorithms-Library What it does →

Concentrated-Liquidity Position

Install and import#

bash
npm install fintech-algorithms
ts
import { concentratedLiquidityPosition } from "fintech-algorithms/digital-assets-and-on-chain-finance/amm-pricing/concentrated-liquidity-position";

Signature#

concentratedLiquidityPosition(liquidity, priceLower, priceUpper, currentPrice)

Uniswap v3 positions: liquidity supplied only within a price range. Far more capital-efficient inside the range, and entirely one-sided outside it — a position whose price has left its range is holding only the losing asset.

Parameters#

NameTypeNotes
liquiditynumberPosition liquidity L.
min: 0
priceLowernumberLower bound of the range.
min: 0
priceUppernumberUpper bound of the range.
min: 0
currentPricenumberCurrent pool price.
min: 0

Returns#

{ amount0, amount1, inRange, … }

Token amounts held with an explicit in-range flag — out of range is the state that surprises position holders.

Errors#

  • When priceLower is not below priceUpper — throws

Complexity: time O(1), space O(1).

Worked example#

executed Captured by running this function on the input its own test provides. Real output of real code — but not asserted against a published figure.

Input#

liquidity
1000
priceLower
0.81
priceUpper
1.21
currentPrice
0.7

Call#

concentratedLiquidityPosition(liquidity, priceLower, priceUpper, currentPrice)

Returns#

object with 14 fields: model, liquidity, priceLowerToken1PerToken0, priceUpperToken1PerToken0, currentPriceToken1PerToken0, sqrtPriceLower, sqrtPriceUpper, sqrtPriceCurrent, …

{
  "model": "concentrated-liquidity-position",
  "liquidity": 1000,
  "priceLowerToken1PerToken0": 0.81,
  "priceUpperToken1PerToken0": 1.21,
  "currentPriceToken1PerToken0": 0.7,
  "sqrtPriceLower": 0.9,
  "sqrtPriceUpper": 1.1,
  "sqrtPriceCurrent": 0.836660026534,
  "amount0": 202.020202020202,
  "amount1": 0,
  "valueInToken1AtCurrentPrice": 141.414141414141,
  "state": "below-range",
  "active": false,
  "boundaryConvention": "price<=lower is below; lower<price<upper is active; price>=upper is above"
}

Other exports#

This module also exports constantProductQuote, constantSumQuote, stableSwapInvariant, stableSwapQuote, weightedProductQuote. Every module additionally exports run as an alias of its primary function, and a meta object carrying its catalog id, domain, family, shape and article URL.

Diagrams#

Concentrated-Liquidity Position — system map

Calculation flow#

Diagram
flowchart LR
    A["Normalize balances, amount, and token order"] --> B["Select Concentrated-Liquidity Position contract"]
    B --> C["Apply declared fee convention"]
    C --> D["Solve invariant or piecewise position"]
    D --> E{"Valid state?"}
    E -- "No" --> F["Reject: exhaustion, bounds, or convergence"]
    E -- "Yes" --> G["Update actual balances"]
    G --> H["Compute spot, execution, and diagnostics"]
    H --> I["Report exclusions and state label"]

How it works#

This page states the contract — how to call it correctly. The article explains the concept: why it works, and where it breaks.

Read the article →

References#

  • Uniswap v2 Core whitepaper — Uniswap
  • StableSwap whitepaper — Curve Finance / Michael Egorov
  • Balancer whitepaper — Balancer Labs
  • Uniswap v3 Core whitepaper — Uniswap
  • Uniswap concentrated-liquidity concept guide — Uniswap Labs
  • Source discipline

The rest of the AMM Pricing family#