Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: beaconchain slashable shares in queue #1087

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 5 additions & 7 deletions src/contracts/core/DelegationManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -770,13 +770,11 @@ contract DelegationManager is

/// @dev Add to the cumulative withdrawn scaled shares from an operator for a given strategy
function _addQueuedSlashableShares(address operator, IStrategy strategy, uint256 scaledShares) internal {
if (strategy != beaconChainETHStrategy) {
uint256 currCumulativeScaledShares = _cumulativeScaledSharesHistory[operator][strategy].latest();
_cumulativeScaledSharesHistory[operator][strategy].push({
key: uint32(block.number),
value: currCumulativeScaledShares + scaledShares
});
}
uint256 currCumulativeScaledShares = _cumulativeScaledSharesHistory[operator][strategy].latest();
_cumulativeScaledSharesHistory[operator][strategy].push({
key: uint32(block.number),
value: currCumulativeScaledShares + scaledShares
});
}

/// @dev Get the shares from a queued withdrawal.
Expand Down
11 changes: 6 additions & 5 deletions src/test/unit/DelegationUnit.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7491,8 +7491,8 @@ contract DelegationManagerUnitTests_slashingShares is DelegationManagerUnitTests
delegationManager.queueWithdrawals(queuedWithdrawalParams);
assertEq(
delegationManager.getSlashableSharesInQueue(operator, beaconChainETHStrategy),
0,
"there should be 0 withdrawAmount slashable shares in queue since this is beaconChainETHStrategy"
withdrawAmount,
"there should be withdrawAmount slashable shares in queue"
);
}

Expand All @@ -7504,6 +7504,7 @@ contract DelegationManagerUnitTests_slashingShares is DelegationManagerUnitTests
// Therefore amount of shares to burn should be what the staker still has remaining + staker1 shares and then
// divided by 2 since the operator was slashed 50%
uint256 sharesToDecrease = (shares + depositAmount - withdrawAmount) * 3 / 4;
uint256 sharesToBurn = sharesToDecrease + (delegationManager.getSlashableSharesInQueue(operator, beaconChainETHStrategy) * 3 / 4);

// 4. Burn shares
_setOperatorMagnitude(operator, beaconChainETHStrategy, newMagnitude);
Expand All @@ -7512,7 +7513,7 @@ contract DelegationManagerUnitTests_slashingShares is DelegationManagerUnitTests

// Assert OperatorSharesSlashed event was emitted with correct params
cheats.expectEmit(true, true, true, true, address(delegationManager));
emit OperatorSharesSlashed(operator, beaconChainETHStrategy, sharesToDecrease);
emit OperatorSharesSlashed(operator, beaconChainETHStrategy, sharesToBurn);

cheats.prank(address(allocationManagerMock));
delegationManager.slashOperatorShares({
Expand All @@ -7525,8 +7526,8 @@ contract DelegationManagerUnitTests_slashingShares is DelegationManagerUnitTests
// 5. Assert expected values
uint256 queuedSlashableSharesAfter = delegationManager.getSlashableSharesInQueue(operator, beaconChainETHStrategy);
uint256 operatorSharesAfter = delegationManager.operatorShares(operator, beaconChainETHStrategy);
assertEq(queuedSlashableSharesBefore, 0, "Slashable shares in queue should be 0 for beaconChainStrategy");
assertEq(queuedSlashableSharesAfter, 0, "Slashable shares in queue should be 0 for beaconChainStrategy");
assertEq(queuedSlashableSharesBefore, withdrawAmount, "Slashable shares in queue should be full withdraw amount");
assertEq(queuedSlashableSharesAfter, withdrawAmount / 4, "Slashable shares in queue should be 1/4 withdraw amount after slashing");
assertEq(operatorSharesAfter, operatorSharesBefore - sharesToDecrease, "operator shares should be decreased by sharesToDecrease");
}

Expand Down
Loading