From 78cac23186512ff3f311ac31c4bbab41c7370004 Mon Sep 17 00:00:00 2001 From: Madhur Shrimal Date: Mon, 16 Sep 2024 22:25:38 -0700 Subject: [PATCH] fix: allocation with no deallocations queued --- src/contracts/core/AllocationManager.sol | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/src/contracts/core/AllocationManager.sol b/src/contracts/core/AllocationManager.sol index d39ef3062c..566d2d3665 100644 --- a/src/contracts/core/AllocationManager.sol +++ b/src/contracts/core/AllocationManager.sol @@ -750,17 +750,23 @@ contract AllocationManager is uint256[] memory indices = _queuedDeallocationIndices[operator][strategy][_encodeOperatorSet(operatorSets[i])]; uint256 length = indices.length; - uint256 deallocationIndex = indices[length - 1]; - PendingFreeMagnitude memory latestPendingMagnitude = - _pendingFreeMagnitude[operator][strategy][deallocationIndex]; - if (latestPendingMagnitude.completableTimestamp > block.timestamp) { - pendingMagnitudeDiff[i] = latestPendingMagnitude.magnitudeDiff; - timestamps[i] = latestPendingMagnitude.completableTimestamp; - } else { - // There is no pending deallocation, so we set the pending magnitude and timestamp to 0 + if (length == 0) { + // If there is no deallocations queued for this operator set pendingMagnitudeDiff[i] = 0; timestamps[i] = 0; - } + } else { + uint256 deallocationIndex = indices[length - 1]; + PendingFreeMagnitude memory latestPendingMagnitude = + _pendingFreeMagnitude[operator][strategy][deallocationIndex]; + if (latestPendingMagnitude.completableTimestamp > block.timestamp) { + pendingMagnitudeDiff[i] = latestPendingMagnitude.magnitudeDiff; + timestamps[i] = latestPendingMagnitude.completableTimestamp; + } else { + // There is no pending deallocation, so we set the pending magnitude and timestamp to 0 + pendingMagnitudeDiff[i] = 0; + timestamps[i] = 0; + } + } } return (pendingMagnitudeDiff, timestamps); }