SecondsOutside
DiamondSwap SecondsOutside Library
The DiamondSwap SecondsOutside Library provides utility functions for tracking and calculating the time spent by liquidity positions outside their initialized tick ranges within the DiamondSwap protocol. This information is crucial for understanding the duration liquidity positions have been out of range, which impacts fee calculations and other aspects of liquidity management. Below is a detailed breakdown of the functions within the DiamondSwap SecondsOutside Library.
Functions
get(uint32 secondsOutsideLower, uint32 secondsOutsideUpper, int24 tickLower, int24 tickUpper, int24 currentTick) → uint32
get(uint32 secondsOutsideLower, uint32 secondsOutsideUpper, int24 tickLower, int24 tickUpper, int24 currentTick) → uint32
This function calculates the total time (in seconds) that a liquidity position has been outside its specified tick range. The function takes into account the current position of the pool's tick and determines how much time has been spent outside the range defined by the tickLower
and tickUpper
parameters.
-
secondsOutsideLower: The accumulated time (in seconds) that liquidity has been outside the lower tick.
-
secondsOutsideUpper: The accumulated time (in seconds) that liquidity has been outside the upper tick.
-
tickLower: The lower bound of the tick range for the liquidity position.
-
tickUpper: The upper bound of the tick range for the liquidity position.
-
currentTick: The current tick of the pool.
-
Returns: The total time (in seconds) that the liquidity position has spent outside its tick range, as a
uint32
.
This function is essential for determining the time-weighted metrics for liquidity positions. By calculating the amount of time liquidity spends outside its range, this function helps liquidity providers understand how effectively their liquidity has been utilized.
update(uint32 secondsOutside, uint32 secondsPerLiquidityOutsideX128, uint128 liquidity, bool add) → uint32
update(uint32 secondsOutside, uint32 secondsPerLiquidityOutsideX128, uint128 liquidity, bool add) → uint32
This function updates the secondsOutside
value based on changes in liquidity. If liquidity is added or removed, this function adjusts the accumulated time accordingly, ensuring that the time spent outside the tick range is accurately tracked.
-
secondsOutside: The current accumulated time (in seconds) that liquidity has been outside the tick range.
-
secondsPerLiquidityOutsideX128: The cumulative seconds per liquidity outside the tick range, scaled by
2^128
. -
liquidity: The amount of liquidity being adjusted.
-
add: A boolean indicating whether liquidity is being added (
true
) or removed (false
). -
Returns: The updated
secondsOutside
value as auint32
.
This function is critical for maintaining accurate time-weighted metrics as liquidity changes. It ensures that liquidity providers are credited or debited for the correct amount of time when they adjust their positions.
Use Cases
The DiamondSwap SecondsOutside Library is particularly valuable in scenarios that require precise tracking of liquidity positions over time, including:
- Fee Calculation: Understanding the time liquidity spends outside its range is essential for calculating fees owed to liquidity providers. By accurately tracking this time, the library ensures that fees are distributed fairly.
- Performance Analysis: Liquidity providers can use this information to analyze the effectiveness of their positions and make informed decisions about when to add or remove liquidity.
- Risk Management: Tracking time outside of tick ranges helps liquidity providers assess the risks associated with their positions, especially in volatile markets where the price frequently moves outside expected ranges.
Conclusion
The DiamondSwap SecondsOutside Library provides essential utilities for tracking and updating the time that liquidity positions spend outside their tick ranges within the DiamondSwap protocol. By using functions like get
and update
, developers can accurately calculate time-weighted metrics, manage liquidity effectively, and ensure fair distribution of fees. Whether you're building decentralized finance (DeFi) applications, managing liquidity, or analyzing the performance of liquidity positions, this library is a powerful tool for working with time-based data in the DiamondSwap ecosystem.
Updated 3 months ago