---
description: Concentrated Active Liquidity Management (CALM)
---

# Technical Overview

## Overview

<figure><img src="https://4257325272-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F8hHvZNCM0oog4K9cunNN%2Fuploads%2FAuqRd97LefmW3O8qXAUo%2Fimage-calm-01_v0.1.png?alt=media&#x26;token=3da6df21-0641-4155-ba83-f857b425fe98" alt=""><figcaption><p>CALM's High-Level Architectural Flow</p></figcaption></figure>

The architectural flow of the CALM solution seamlessly unfolds through the Uniswap v3 NFT staking on Parallax, encompassing a series of key features:

1. [**Deposit an NFT**](#2.-deposit-an-nft)
2. [**Split NFT into Underlying Assets**](#3.-split-nft-into-underlying-assets)
3. [**Provide Liquidity to a Uniswap v3 Pool**](#provide-liquidity-to-a-uniswap-v3-pool)
4. [**Adjust the Price Range of the Pool Position**](#adjust-the-price-range-of-the-pool-position)
5. [**Distribute Rewards from the Uniswap v3 Pool**](#distribute-rewards-from-the-uniswap-v3-pool)
6. [**Compound** ](#compound)
7. [**Claim Staking Rewards**](#claim-staking-rewards)
8. [**Withdraw Funds from Staking**](#withdraw-funds-from-staking)

<figure><img src="https://4257325272-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F8hHvZNCM0oog4K9cunNN%2Fuploads%2FWFKYReZD3YBexSdoOVRu%2Fimage-calm-02_v0.1.png?alt=media&#x26;token=899e4d2d-691c-46a8-84ef-953c5a31dba7" alt=""><figcaption><p>CALM from User's Perspective - Everything else is automated and managed algorithmically. </p></figcaption></figure>

## Deposit an NFT

Users have the flexibility to enter multiple staking contracts and allocate positions according to their preferences within each staking contract. CALM streamlines this process by presenting users with a comprehensive list of available NFT options based on their currently connected wallet, allowing for efficient and customized management of their positions.

<figure><img src="https://4257325272-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F8hHvZNCM0oog4K9cunNN%2Fuploads%2FuLBQCfk6SaJuYeSb7Kx8%2Fimage-calm-03_v0.1.png?alt=media&#x26;token=12903e45-7098-49ee-bd43-5c4619533eab" alt=""><figcaption><p>Multi-Position is OK</p></figcaption></figure>

The CALM system stores user stakes, ensuring precision and accuracy in the distribution of staking rewards.

## **Split NFT into Underlying Assets**

The system forfeits the user's NFT to obtain its underlying tokens, a pivotal feature that serves as the foundation for optimization by addressing two crucial tasks:

* **Voiding Low and No-Profit Deposited Positions:** By forfeiting a user's NFT to acquire its underlying tokens, the system efficiently identifies and eliminates low and non-profitable positions.
* **Reducing Costs of Adjusting Pool Position's Price Range:** The conversion of NFTs into underlying tokens results in a decreased number of positions to manage. This reduction, in turn, minimizes the costs associated with further adjustments to a pool position's price range. The system's streamlined approach not only enhances efficiency but also contributes to a more cost-effective and sustainable staking experience.

## **Provide Liquidity to a Uniswap v3 Pool**

### Business Requirements

The CALM system, in its optimized state, consolidates assets from deposited NFTs into a single Uniswap v3 pool position. This strategic enhancement involves determining the optimal price range for the position during the deposit process, defined by the following parameters:

* Lower price tick
* Upper price tick

The CALM system applies a set of principles to determine the values of these price range parameters:

1. Narrower ranges yield increased earnings from fees and rewards. However, this strategy comes with a higher susceptibility to incurring divergent losses, particularly in high-volatility environments.&#x20;
2. In contrast, during low-volatility conditions, narrower ranges tend to outperform, generating higher fees and benefiting from an elevated fee multiplier. This performance advantage is achieved while experiencing minimal divergent losses, making narrow ranges particularly effective in more stable market conditions.

Hence, it is always recommended to employ a narrow range for more stable token pairs. In such instances, specifying a wide range is unnecessary for several compelling reasons:

1. The predominant trading activity occurs within the most concentrated range, making narrow ranges more aligned with market dynamics.
2. Widening the range inevitably diminishes the amount of liquidity provided, potentially compromising the efficiency of the position.

For less stable token pairs, two distinct options warrant consideration. On one hand, opting for narrow ranges maximizes fees, leveraging the benefits of higher fee earnings. On the other hand, selecting wide ranges signifies increased participation in trading activity, offering an alternative strategy for managing positions in more volatile markets.

Considering the potential of divergent losses, the forthcoming generalized options may include the following scenarios:

**A. High Fees, Occurring Infrequently:** Fees are high but are accrued relatively rarely since most swaps take place outside the specified price ticks - for **narrow ranges**.

**B. Low Fees, Permanent Accrual:** Fees are low but are accrued permanently as most swaps happen within the specified price ticks - for **wide ranges.**

**C. High Fees, Permanent Accrual:** Fees are high and are accrued permanently because most swaps occur within the specified price ticks - for **wide ranges.**

**D. Low Fees, Occurring Infrequently:** Fees are low and are accrued relatively rarely since most swaps take place outside the specified price ticks - for **narrow ranges.**

| Fees/Range | Narrow | Wide |
| ---------- | ------ | ---- |
| High       | A      | C    |
| Low        | D      | B    |

Options C and D are deemed unlikely occurrences, requiring extreme market conditions that stem from either a significant decrease in volatility (C case) or an adverse event (D case). Therefore, as previously mentioned, the primary focus will center on options A and B. **However, it's crucial for strategy A to closely resemble option C, as this alignment is a key optimization goal.**

Each option is influenced by a divergent loss factor. In volatile pairs, the probability of experiencing divergent losses tends to be 100%, with the magnitude of these losses varying. **It is upon the user's responsibility to judiciously determine withdrawal timings, with long positions recommended for wide-range scenarios and short positions suitable for narrow-range situations.**

As the range narrows, the probability of significant losses increases. The impact of divergent loss can be mitigated through trading fees, where narrow-range positions, characterized by higher fees, aim to offset this effect. The relatively low frequency of fee accrual in narrow-range positions can partially or fully compensate for the loss amount. To address this, Uniswap v3 NFT staking on Parallax strategically selects pools with the **highest trading volume and large TVL.** However, in the long run, it is anticipated that the higher fees associated with a narrower range may unlikely outweigh the impact of divergent loss.

Contrastingly, wide-range positions aim to counteract the impact of divergent loss through lower fees. The wider the range, the lower the fees; however, wider ranges are more likely to incur larger swap amounts. Consequently, the overall gain from trading fees in wide-range scenarios may surpass the outcomes of narrower positions. In the long term, the accrued savings from mitigating divergent loss are anticipated to outweigh the higher fees associated with narrower ranges.

Both narrow and wide-range options start at the current price level. The system computes optimal values for the lower and upper ticks, thereby establishing a position range.

The income derived from trading fees is determined by the formula:

<figure><img src="https://lh7-us.googleusercontent.com/yL2EFlbiDusU6gJzOj1V5T-oYYwvKMeuozrFXuz6Cl1FNoGZ2xReIyo5N8CQneYvBW8Rx1hNjzIwEdKs6ygbsKZs_Pjeb7xWMqkwZA04gZNEQeHDbah_hlgVY_8sDkBnm8L2PgxnMsQp28cOFZ8Adc8" alt="" width="188"><figcaption></figcaption></figure>

Where _`Q`_&#x72;epresents the quantity of swaps, _`P`_&#x64;enotes the fee level, and _`N`_ is contingent on the position range, ceteris paribus.

In Uniswap v3, the price range is determined by ticks, integral to the tick "validation" mechanism. This mechanism governs the initialization of ticks, dictating that both the lower and upper limits of the range adhere to tick indices. The best price (lower, upper) is identified first, followed by the selection of the most suitable tick.

For simplicity, the initial version of Uniswap v3 NFT staking on Parallax adopts a minimalist approach to define price ranges for positions, characterized by the following key features:

**Centrality of Current Price:** Both for volatile and stable pairs, the system designates the current price as the center of the range.

**Uniform Spread in Both Directions:** For both volatile and stable pairs, a uniform spread extends in both directions, towards both the lower tick and the upper tick.

**Varied Spread Values:** The spread value for volatile pairs is greater than that of stable pairs, reflecting the greater flexibility required in the face of market fluctuations.

**Example:**&#x20;

Consider a WETH-USDC pool with a current price of 1500 USDC for 1 WETH. Deemed volatile, the spread is set at 5%. Consequently, the resulting price range is \[1425; 1575].

### **Modeling**

The liquidity calculation within Uniswap v3 incorporates several distinctive features:

1. **Symmetric Price Range Extension:**
   * It is feasible to extend the symmetric price range, such as ±10% from the current price, up to a certain threshold without impacting the overall liquidity amount. Notably, this extension applies exclusively to the shift of the upper tick.
2. **Dynamic Liquidity:**
   * The liquidity amount undergoes changes in response to fluctuations in the price of an asset, whether it increases or decreases while maintaining a constant spread within a symmetric price range.

## **Adjust the Price Range of the Pool Position**

### **Adjustment of Position Price Range**

The Uniswap v3 NFT staking on Parallax incorporates the adjustment of position price ranges, recognizing the dynamic nature of asset prices following each swap. The protocol undertakes adjustments in response to significant price shifts, such as a 10% change. While frequent adjustments can incur substantial gas costs, Parallax's management of a single position per pool presents a gas-efficient alternative, contributing to the overall profitability for both Parallax and its users.

### **First Version Approach**

In the initial iteration, the adjustment of the position price range is carried out with simplicity and efficiency:

* The range undergoes modification when the current price shifts into the tenth percentage of the given price range (both lower and upper).
* The range spread rate remains constant after an adjustment.

_Example:_ Considering a WETH-USDC pool with a current price of 1570 USDC for 1 WETH and a price range of \[1425; 1575], the system recalculates the range based on the current price, resulting in a new range of \[1491.5; 1648.5].

### **Advanced Version Approach**

A more advanced version of Uniswap v3 NFT staking on Parallax introduces a flexible implementation of the price range adjustment, expanding the triggers for rebalancing and enabling admins to specify trigger parameters for each pool. The extended list of triggers includes:

1. Automated position rebalance based on the price.
2. Automated position rebalance based on the assets' ratio.
3. Automated position rebalance based on time.

_**Price-based Trigger:**_

* Admins can define a level of price deviation that prompts the adjustment of the main pool position price range.
* The degree of deviation is applied separately to the lower and upper price shift.
* The system checks asset prices every 5 seconds (modifiable) and, if the price exceeds the specified degree, evaluates the price's arithmetic mean for the next 5 minutes (modifiable and pool-specific). A rebalance is triggered if the mean falls beyond the specified degree.

_**Assets Ratio-based Trigger:**_

* Admins can define a pool position composition state that triggers the adjustment of the main pool position price range.
* The system monitors the ratio of assets every 5 seconds (modifiable) and evaluates the arithmetic mean of the dominating asset's pool share for the next 5 minutes (modifiable and pool-specific). A rebalance occurs if the mean exceeds the specified trigger value.

_**Time-based Trigger:**_

* Admins can specify the frequency of the main pool position price range adjustment without price or asset ratio checks.

All triggers derive the new price range from the current price at the moment of rebalancing. Triggers are mutually exclusive, allowing only one type of trigger per pool.

As price changes in a pool alter the token ratio in a user's position, Uniswap v3 NFT staking on Parallax relies on swaps to rebalance the token ratio. Excess of a dominating asset is sold, and an additional amount of the lacking token is acquired at the current price. It's important to note that these swaps are not limit orders and are executed at the current market price.

## **Distribute Rewards from the Uniswap v3 Pool**

**Initial Mechanism**

The system adopts a transparent and equitable approach to distributing accrued trading fees, channeling 100% of these earnings back to depositors within the same staking contract. This ensures that the rewards generated by a specific pool, such as ARB-WETH, are exclusively distributed to ARB-WETH stakers only.

**Equalized Staking Profitability**

User positions are inherently equal in terms of staking profitability, as each individual deposit is aggregated into a unified position governed by the protocol. This unification ensures a level playing field for all participants, aligning with the principles of fairness and impartiality.

**Proportional Yield Based on Staking Share**

A depositor's personal yield is contingent on the share they possess in the overall staking. The system distributes rewards in proportion to users' investments, with both staking total and staking shares derived from the liquidity amount. This precision in reward distribution hinges on periodic estimations of shares, adaptable based on events occurring within the staking contract.

**Periodic Estimation of Shares**

Periodic estimation of shares becomes necessary as the staking landscape evolves, influenced by events within the staking contract. The frequency of these estimations is determined by the occurrence of specific events, ensuring that the share accurately reflects the current state of the staking positions. This adaptability is crucial in maintaining precise and up-to-date reward distribution principles.

**Crediting Accrued Rewards**

Accrued rewards are credited to users in tandem with specific actions, aligning with the compound necessities. These actions include:

1. **Deposit:** When a deposit is made into the current staking.
2. **Withdrawal:** At the moment a user announces a withdrawal from the current staking.
3. **Claim:** When a user claims rewards from the current staking.

**Periodic System Updates**

The system updates the amount of rewards to be distributed before initiating a new period. The commencement of a new period accounts for all active positions, followed by a refresh of the list of active positions. This approach ensures that the staking incentives are dispensed fairly, accounting for changes in the scope and quantity of positions within the staking.&#x20;

{% hint style="info" %}
A secondary mechanism coming soon
{% endhint %}

## Compound&#x20;

**Compounding for Increased Staking Profitability**

The system employs a compounding mechanism for rewards, strategically designed to enhance staking profitability continuously. Compounding is initiated for all accrued rewards within a specified period, ensuring that the entirety of rewards is consistently reinvested back into the staking. This perpetual reinvestment optimizes capital efficiency, guaranteeing a continuous stream of incentives for participants.

**Compounding Triggers**

Compounding is triggered in response to specific events, ensuring a seamless integration with the staking dynamics. The events that prompt compounding include:

1. **Deposit:** Occurs when a deposit is made into the current staking.
2. **Withdrawal:** Activated at the moment a user announces a withdrawal from the current staking.
3. **Claim:** Initiated when a user claims rewards from the current staking.

**Separate Position for Fee Accumulation**

All fees generated are gathered within their separate position, functioning as an addition to the primary staking pool that aggregated the initial stakers' deposits. The compounding process takes place within the scope of this auxiliary NFT.

## **Claim Staking Rewards**

Users have the flexibility to claim their staking rewards at their convenience. Parallax introduces a nominal fee (10%) for each claim, and this fee is directed towards the revenue-sharing contract dedicated to the lockers.

While all staking rewards undergo periodic compounding to optimize profitability, users retain the option to claim their accrued rewards. This claiming process is similar to a withdrawal operation, but despite the similarities, the processes of claiming and withdrawing are different.&#x20;

**Maintaining User Shares and Claim Data:**

Given the dynamic nature of user participation, where individuals can join and depart over time, it is imperative to retain accurate information about their current shares within the system. This preservation of data is crucial to ensuring fair reward distribution, preventing the inadvertent allocation of current rewards to newcomers during compounding events triggered by additional depositors.

**Storage of Claim Data**

The solution incorporates a mechanism for storing data pertaining to claims for each position. This record-keeping serves multiple purposes, including:

1. **User Information and Progress:** Keeping users informed about their accrued benefits and the progress of their staking journey.
2. **Internal Statistical Analysis:** Facilitating internal statistical analysis by leveraging historical claim data, enabling the system to derive insights and optimize its operations based on past user interactions.

## **Withdraw Funds from Staking**

Users can opt to withdraw their funds independently from their rewards. While a withdrawal request can be submitted at any time, the funds remain locked in staking for an additional 7 days. After this waiting period, the position becomes unstaked and claimable, and users can obtain their assets in one of three forms:

1. **LP Token (NFT):** Users can receive the same underlying assets they initially provided, presented in the form of an LP token (NFT).
2. **NFT Creation:** The protocol generates a new position in the same pool for the ex-depositor, and the claimed assets are allocated to this position. The NFT is then transferred to the user's wallet.
3. **Single Underlying Asset:** The protocol executes a swap to retrieve the claimed liquidity as a single underlying asset, allowing users to select the asset based on their preferences.

In all cases, a portion of liquidity is withdrawn from a Uniswap v3 pool, specifically from the position governed by the protocol. Throughout the waiting period, the requested liquidity continues to contribute to the pool, although users do not accrue additional rewards during this time. The income generated during the waiting period is distributed among existing stakers, enhancing their APY.

Users have the option to reverse a withdrawal request and return to the staking pool at any point within the 7-day waiting period. Upon reversal, they resume accruing rewards from the moment of the decision change.

**Withdrawal vs. Claiming:**

Comparison of key characteristics between withdrawal and claiming operations:

<table><thead><tr><th width="255">Operation / Characteristic</th><th width="239">Funds Amount Availability</th><th>Fee Incurred</th></tr></thead><tbody><tr><td>Withdrawal</td><td>In a position’s entirety</td><td>None</td></tr><tr><td>Claim</td><td>Limited to accrued rewards</td><td>10%</td></tr></tbody></table>

While the withdrawal operation offers the possibility of obtaining the entirety of funds within a specific timeframe, the immediate availability of funds is impeded by the amount and the protocol's imposed fee. Notably, withdrawing all assets from a position also includes the claim of all available rewards, leading to a fee based on the portion of funds constituted by these rewards.
