Skip to content

Commit

Permalink
fix: handle rebalance issue
Browse files Browse the repository at this point in the history
  • Loading branch information
bhargavaparoksham committed Jan 18, 2025
1 parent 3d1e0a4 commit 162ae8c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/interfaces/IAssetPool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 13 additions & 0 deletions src/protocol/AssetPool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,8 @@ contract AssetPool is IAssetPool, Ownable, Pausable {
cycleState = CycleState.ACTIVE;
cycleTime = _cyclePeriod;
rebalanceTime = _rebalancingPeriod;
nextRebalanceStartDate = block.timestamp + _cyclePeriod;
nextRebalanceEndDate = nextRebalanceStartDate + _rebalancingPeriod;
}

// --------------------------------------------------------------------------------
Expand Down Expand Up @@ -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
// --------------------------------------------------------------------------------
Expand Down

0 comments on commit 162ae8c

Please sign in to comment.