TONCO Docs
Документация и Гайды
Документация и Гайды
  • TONCO
    • Что такое TONCO?
    • Концентрированная ликвидность впервые на TON
    • Команда
    • Социальные сети
    • Аудиты
    • Roadmap
  • Что такое концентрированная ликвидность?
    • Глоссарий
    • Fees
    • NFT-токены поставщиков ликвидности
    • Фарминг (Farming)
    • Farming FAQ
  • Ценовые диапазоны
    • Значение ценовых диапазонов
    • Предустановленные диапазоны
    • Продвинутые пресеты диапазонов
    • Движение цены в пределах диапазонов
    • Непостоянные потери (Impermanent Loss)
    • Выбор стратегии
    • Сценарии при управлении ликвидностью
  • Преимущества концентрированной ликвидности
    • Преимущества для поставщиков ликвидности
    • Преимущества для трейдеров
    • Преимущества для проектов
    • Токены ликвидного стейкинга (LST)
  • Стратегии Концентрированной Ликвидности
    • Базовые стратегии
    • Хэджирование с EVAA (lending)
    • Хэджирование с Tradoor (perps)
    • Хэджирование со Storm Trade (perps)
  • Руководство по предоставлению ликвидности
    • Добавление ликвидности
    • Управление позицией
    • Руководство по миграции ликвидности
    • Как рассчитывается APR
    • LPs FAQ
  • TONCO Points Program
    • Introduction
    • How to Earn Points
  • Ambassador Program
    • Introduction
    • Content Creators
    • Community Moderators
    • International Ambassadors
  • Technical Reference
    • 📇Indexer
    • GraphQL Schema
    • Integration FAQ
    • Core Logic
      • 🧺Pool overview
      • Swap calculation
      • 💰Liquidity and positions
      • 📏Ticks
      • 🏦Reserves
    • Contracts
      • 📜Scenarios
      • Pool
      • Router
      • Position NFT
      • Account
Powered by GitBook
On this page
  • Definition of liquidity
  • Liquidity position
  • Fee distribution between liquidity positions
  1. Technical Reference
  2. Core Logic

Liquidity and positions

PreviousSwap calculationNextTicks

Definition of liquidity

As stated in , the internal state of the TONCO AMM at any moment is determined by two values:

P\sqrt PP​ - the root of the current price of token1(jetton1) relative to token0(jetton0).

LLL - liquidity.

A change in the current price in the pool (via swaps) entails the movement of jettons from / to the pool, with the number of jettons depending on a coefficient called liquidity. Formulas linking token deltas, price change, and liquidity value:

ΔP=ΔY/L\Delta \sqrt P = \Delta Y / LΔP​=ΔY/L

Δ(1P)=ΔX/L\Delta ({1 \over \sqrt P}) = \Delta X / LΔ(P​1​)=ΔX/L

Thus, liquidity LLL can be defined as a coefficient that determines the "speed" of price change when tokens are swapped. Change of P\sqrt PP​ (or 1/P1 / \sqrt P1/P​, depending on the direction of the swap) is inversely proportional to liquidity. This means that the greater the liquidity, the more tokens need to be swapped to move the price by a given value.

Liquidity position

TONCO is based on the concept of concentrated liquidity. This means that users can provide their tokens as liquidity for swaps at a certain price range. The following describes what this means and how the value of liquidity is related to tokens.

A liquidity position in TONCO is an entity defined by the following parameters:

  1. positionv3::user_address - Position owner

  2. positionv3::pool_address - Pool to which the position belongs

  3. positionv3::tickLower - the tick corresponding to the lowest price at which the liquidity of this position can be used

  4. positionv3::tickUpper - is the tick corresponding to the highest price at which the liquidity of this position can be used

  5. positionv3::liquidity - ΔL\Delta LΔL - liquidity value associated with this position

Ptop\sqrt {P_{top}}Ptop​​ - the price root value corresponding to the upper tick of the position.

Pbottom\sqrt {P_{bottom}}Pbottom​​ - the price root value corresponding to the lower tick of the position.

Pcurrent\sqrt {P_{current}}Pcurrent​​ - the current value of the price root in the pool.

Note that during the upward price movement (zeroToOne = false) the pool buys jetton1 (Y) and sells jetton0 (X). On the other hand, during the downward price movement (zeroToOne = true) the pool buys jetton0 and sells token1.

This means that a liquidity position must, on the one hand, provide enough jetton0 for the sale to move the price up to the Ptop\sqrt {P_{top}}Ptop​​, and, on the other hand, provide for sale a sufficient amount of jetton1 to move the price to Pbottom\sqrt {P_{bottom}}Pbottom​​ .

Correlation between the liquidity value and the amount of tokens(jettons)

Then we can express the correlation between the number of jettons and ΔL\Delta LΔL, if Pcurrent\sqrt {P_{current}}Pcurrent​​ is inside the price range of the position:

ΔX=−(1/Ptop−1/Pcurrent)⋅ΔL\Delta X = - (1 / \sqrt {P_{top}} - 1 / \sqrt {P_{current}}) \cdot \Delta LΔX=−(1/Ptop​​−1/Pcurrent​​)⋅ΔL

ΔY=−(Pbottom−Pcurrent)⋅ΔL\Delta Y = - (\sqrt {P_{bottom}} - \sqrt {P_{current}}) \cdot \Delta LΔY=−(Pbottom​​−Pcurrent​​)⋅ΔL

IfPcurrent\sqrt P_{current}P​current​ is not inside the position's price range, the amount of jettons associated with the position must cover price movement in one direction only (depending on the position of the current price).

If the current price is higher than the upper price of the position ( Pcurrent≥Ptop\sqrt {P_{current}} \ge \sqrt {P_{top}}Pcurrent​​≥Ptop​​):

ΔX=0\Delta X = 0ΔX=0

ΔY=−(Ptop−Pbottom)⋅ΔL\Delta Y = - ( \sqrt {P_{top}} - \sqrt {P_{bottom}}) \cdot \Delta LΔY=−(Ptop​​−Pbottom​​)⋅ΔL

If the current price is below the price range of the position ( Pcurrent<Pbottom\sqrt {P_{current}} \lt \sqrt {P_{bottom}}Pcurrent​​<Pbottom​​ ):

ΔX=−(1/Ptop−1/Pbottom)⋅ΔL\Delta X = - (1 / \sqrt {P_{top}} - 1 / \sqrt {P_{bottom}}) \cdot \Delta LΔX=−(1/Ptop​​−1/Pbottom​​)⋅ΔL

ΔY=0\Delta Y = 0ΔY=0

Thus, when creating a position with the given ΔL\Delta LΔL, Ptop\sqrt {P_{top}}Ptop​​, Pbottom\sqrt {P_{bottom}}Pbottom​​, the user must provide ΔX\Delta XΔXjetton0 and ΔY\Delta YΔYjetton1, calculated according to the above formulas taking into account the current price in the pool.

On the other hand, when withdrawing liquidity, the user should receiveΔX\Delta XΔXjetton0 and ΔY\Delta YΔYjetton1, also calculated using the same formulas considering the current price and the change in ΔL\Delta LΔL.

Fee distribution between liquidity positions

Two accumulators of the following form are used for this purpose:

totalFeeGrowthJetton0=∑Famountx/LtotalFeeGrowthJetton0 = \sum F^x_{amount} / LtotalFeeGrowthJetton0=∑Famountx​/L

totalFeeGrowthJetton1=∑Famounty/LtotalFeeGrowthJetton1 = \sum F^y_{amount} / LtotalFeeGrowthJetton1=∑Famounty​/L

where Famount{x,y}F^{\{x, y\}}_{amount}Famount{x,y}​ - the collected amount of fees in jetton0 or jetton1, LLL - the current global value of the fee.

During the swap, each iteration of the main loop holds the commission in the input token and increments the value of the corresponding accumulator.

The corresponding values of accumulators increment are recorded in the position when it was created, let's call them:

innerFeeGrowthJetton0oldinnerFeeGrowthJetton0_{old}innerFeeGrowthJetton0old​ - accumulator increment for jetton0 that occurred between specified ticks

innerFeeGrowthJetton1oldinnerFeeGrowthJetton1_{old}innerFeeGrowthJetton1old​ - accumulator increment for jetton1 that occurred between specified ticks

Then the amount of tokens that correspond to the share of the fees for a liquidity position can be calculated at any time:

Δfeesx=ΔL⋅(innerFeeGrowthJetton0new−innerFeeGrowthJetton0old)\Delta fees_x = \Delta L \cdot (innerFeeGrowthJetton0_{new} - innerFeeGrowthJetton0_{old})Δfeesx​=ΔL⋅(innerFeeGrowthJetton0new​−innerFeeGrowthJetton0old​)

Δfeesy=ΔL⋅(innerFeeGrowthJetton1new−innerFeeGrowthJetton1old)\Delta fees_y = \Delta L \cdot (innerFeeGrowthJetton1_{new} - innerFeeGrowthJetton1_{old})Δfeesy​=ΔL⋅(innerFeeGrowthJetton1new​−innerFeeGrowthJetton1old​)

This is followed by an update of innerFeeGrowthJetton0oldinnerFeeGrowthJetton0_{old}innerFeeGrowthJetton0old​ and innerFeeGrowthJetton1oldinnerFeeGrowthJetton1_{old}innerFeeGrowthJetton1old​

The liquidity value associated with the position ΔL\Delta LΔL adds to the global liquidity value when the position becomes active (price inside the specified tick range) and is subtracted from the global liquidity value when the position becomes inactive (price outside the specified tick range). These changes take place during the on the crossing of position-related .

Thus, the value ΔL\Delta LΔL must ensure the fulfillment of the formulas from the section on the price range defined by the upper and lower tick of the position. Then the correlation between the number of tokens and ΔL\Delta LΔL can be obtained as follows. Let:

For , the pool deducts a fee that is allocated to the currently active liquidity positions (positions whose liquidity is used for the swap).

Thanks to this mechanism, it is easy to calculate the share of fees due to each liquidity position. With the help of the ticks mechanism, it is possible to know at any moment what parts of accumulators were added at the moment when the price was between two given ticks. The definition of accumulator increments within the tick range is described in more detail in .

💰
the article about swap calculations
swap
ticks
swaps
the article about ticks
liquidity definition