Concentrated-Liquidity Position
Install and import
npm install fintech-algorithmsimport { 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
| Name | Type | Notes |
|---|---|---|
liquidity | number | Position liquidity L. min: 0 |
priceLower | number | Lower bound of the range. min: 0 |
priceUpper | number | Upper bound of the range. min: 0 |
currentPrice | number | Current 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
10000.811.210.7Call
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
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.
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