Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR implements a linked list mechanism which can be utilised for managing liquidity changes over time for different tokens.
Tracking Liquidity Changes: The contract keeps track of liquidity changes (
LiqChangeNode
) for each token over time. Each node in the linked list represents a change in liquidity (either an inflow or outflow) at a specific timestamp.Maintaining Historical Data: By using a linked list, the contract can maintain a historical record of liquidity changes. This is essential for calculating the current and future liquidity states based on past inflows and outflows.
Dynamic Window Management: The linked list allows for dynamic management of the time window for liquidity changes. Nodes can be added or removed as time progresses, enabling the contract to only consider liquidity changes within a relevant time frame (defined by
withdrawalPeriod
).Efficient Updates and Deletions: The linked list structure enables efficient addition of new liquidity changes at the tail and removal of old changes from the head as they become irrelevant after the withdrawal period. This is crucial for keeping the contract's operations gas-efficient.
Rate Limit Enforcement: The linked list supports the enforcement of withdrawal rate limits. By analyzing the liquidity changes within the specified window, the contract can determine if a withdrawal request breaches the set rate limit, thereby preventing excessive outflows that could destabilize the token's liquidity.
Grace Period Consideration: The linked list helps in managing a grace period following a rate limit breach. It allows the contract to temporarily bypass the rate limit enforcement, enabling withdrawals under certain conditions, such as after an admin override.
Gas Optimization: Traversing and updating the linked list allows for clearing historical data that is no longer relevant, optimizing gas usage for future transactions. This proactive backlog clearing helps in maintaining the contract's efficiency.