Skip to content

Commit

Permalink
feat: add OperatorSharesSlashed event to track shares slashed per ope…
Browse files Browse the repository at this point in the history
…rator (#1051)

* feat: add OperatorSharesSlashed event to track shares slashed per operator

* feat: add unit tests

* fix: add more tests
  • Loading branch information
bowenli86 authored Feb 4, 2025
1 parent da9f3dc commit 38f5faa
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/contracts/core/DelegationManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,9 @@ contract DelegationManager is
sharesToDecrease: operatorSharesSlashed
});

// Emit event for operator shares being slashed
emit OperatorSharesSlashed(operator, strategy, totalDepositSharesToBurn);

IShareManager shareManager = _getShareManager(strategy);
// NOTE: for beaconChainETHStrategy, increased burnable shares currently have no mechanism for burning
shareManager.increaseBurnableShares(strategy, totalDepositSharesToBurn);
Expand Down
3 changes: 3 additions & 0 deletions src/contracts/interfaces/IDelegationManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,9 @@ interface IDelegationManagerEvents is IDelegationManagerTypes {

/// @notice Emitted when a queued withdrawal is completed
event SlashingWithdrawalCompleted(bytes32 withdrawalRoot);

/// @notice Emitted whenever an operator's shares are slashed for a given strategy
event OperatorSharesSlashed(address indexed operator, IStrategy strategy, uint256 totalSlashedShares);
}

/**
Expand Down
44 changes: 44 additions & 0 deletions src/test/unit/DelegationUnit.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6910,6 +6910,11 @@ contract DelegationManagerUnitTests_slashingShares is DelegationManagerUnitTests
sharesToBurn: sharesToBurn
})
);

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

cheats.prank(address(allocationManagerMock));
delegationManager.slashOperatorShares({
operator: operator,
Expand Down Expand Up @@ -6994,6 +6999,11 @@ contract DelegationManagerUnitTests_slashingShares is DelegationManagerUnitTests
sharesToBurn: sharesToBurn
})
);

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

cheats.prank(address(allocationManagerMock));
delegationManager.slashOperatorShares({
operator: operator,
Expand Down Expand Up @@ -7072,6 +7082,11 @@ contract DelegationManagerUnitTests_slashingShares is DelegationManagerUnitTests
sharesToBurn: sharesToBurn
})
);

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

cheats.prank(address(allocationManagerMock));
delegationManager.slashOperatorShares({
operator: operator,
Expand Down Expand Up @@ -7163,6 +7178,11 @@ contract DelegationManagerUnitTests_slashingShares is DelegationManagerUnitTests
sharesToBurn: sharesToBurn
})
);

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

cheats.prank(address(allocationManagerMock));
delegationManager.slashOperatorShares({
operator: operator,
Expand Down Expand Up @@ -7237,6 +7257,11 @@ contract DelegationManagerUnitTests_slashingShares is DelegationManagerUnitTests
sharesToBurn: sharesToBurn
})
);

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

cheats.prank(address(allocationManagerMock));
delegationManager.slashOperatorShares({
operator: operator,
Expand Down Expand Up @@ -7294,6 +7319,11 @@ contract DelegationManagerUnitTests_slashingShares is DelegationManagerUnitTests
sharesToBurn: sharesToBurn
})
);

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

cheats.prank(address(allocationManagerMock));
delegationManager.slashOperatorShares({
operator: operator,
Expand Down Expand Up @@ -7399,6 +7429,11 @@ contract DelegationManagerUnitTests_slashingShares is DelegationManagerUnitTests
sharesToBurn: 0
})
);

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

cheats.prank(address(allocationManagerMock));
delegationManager.slashOperatorShares({
operator: operator,
Expand Down Expand Up @@ -7474,6 +7509,11 @@ contract DelegationManagerUnitTests_slashingShares is DelegationManagerUnitTests
_setOperatorMagnitude(operator, beaconChainETHStrategy, newMagnitude);
cheats.expectEmit(true, true, true, true, address(delegationManager));
emit OperatorSharesDecreased(operator, address(0), beaconChainETHStrategy, sharesToDecrease);

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

cheats.prank(address(allocationManagerMock));
delegationManager.slashOperatorShares({
operator: operator,
Expand Down Expand Up @@ -7518,6 +7558,10 @@ contract DelegationManagerUnitTests_slashingShares is DelegationManagerUnitTests
newOperatorMagnitude -= slashMagnitude;
_setOperatorMagnitude(defaultOperator, strategyMock, newOperatorMagnitude);

// Assert OperatorSharesSlashed event was emitted with correct params
cheats.expectEmit(true, true, true, true, address(delegationManager));
emit OperatorSharesSlashed(defaultOperator, strategyMock, 44440000449046438731194137360795695);

cheats.prank(address(allocationManagerMock));
delegationManager.slashOperatorShares(
defaultOperator,
Expand Down

0 comments on commit 38f5faa

Please sign in to comment.