From 162ae8cd1385336d6806f1fc93a679f444e9d7a2 Mon Sep 17 00:00:00 2001 From: eagle Date: Sat, 18 Jan 2025 19:12:45 +0530 Subject: [PATCH] fix: handle rebalance issue --- src/interfaces/IAssetPool.sol | 2 ++ src/protocol/AssetPool.sol | 13 +++++++++++++ 2 files changed, 15 insertions(+) diff --git a/src/interfaces/IAssetPool.sol b/src/interfaces/IAssetPool.sol index b794961..4509c07 100644 --- a/src/interfaces/IAssetPool.sol +++ b/src/interfaces/IAssetPool.sol @@ -149,6 +149,8 @@ interface IAssetPool { error InsufficientLPLiquidity(); /// @notice Thrown when rebalance parameters don't match requirements error RebalanceMismatch(); + /// @notice Thrown when a user attempts to interact with an LP's rebalance + error InvalidCycleRequest(); // -------------------------------------------------------------------------------- // USER ACTIONS diff --git a/src/protocol/AssetPool.sol b/src/protocol/AssetPool.sol index 6d64bd7..8d89309 100644 --- a/src/protocol/AssetPool.sol +++ b/src/protocol/AssetPool.sol @@ -189,6 +189,8 @@ contract AssetPool is IAssetPool, Ownable, Pausable { cycleState = CycleState.ACTIVE; cycleTime = _cyclePeriod; rebalanceTime = _rebalancingPeriod; + nextRebalanceStartDate = block.timestamp + _cyclePeriod; + nextRebalanceEndDate = nextRebalanceStartDate + _rebalancingPeriod; } // -------------------------------------------------------------------------------- @@ -395,6 +397,17 @@ contract AssetPool is IAssetPool, Ownable, Pausable { } } + function updateCycle() external { + if (cycleState != CycleState.REBALANCING) revert InvalidCycleState(); + if (cycleTotalDepositRequests[cycleIndex] > 0) revert InvalidCycleRequest(); + if (cycleTotalRedemptionRequests[cycleIndex] > 0) revert InvalidCycleRequest(); + + cycleIndex++; + cycleState = CycleState.ACTIVE; + nextRebalanceStartDate = block.timestamp + cycleTime; + nextRebalanceEndDate = nextRebalanceStartDate + rebalanceTime; + } + // -------------------------------------------------------------------------------- // GOVERNANCE FUNCTIONS // --------------------------------------------------------------------------------