From 2c54c9a31cb0b9d497aafbb040e7b188f4e4ca1b Mon Sep 17 00:00:00 2001 From: "clandestine.eth" <96172957+0xClandestine@users.noreply.github.com> Date: Wed, 3 Sep 2025 13:33:36 -0400 Subject: [PATCH 1/2] wip --- src/contracts/core/AllocationManager.sol | 36 +++++++++++++++++++ .../interfaces/IDelegationManager.sol | 7 ++++ 2 files changed, 43 insertions(+) diff --git a/src/contracts/core/AllocationManager.sol b/src/contracts/core/AllocationManager.sol index 44aedf268b..f8434f7a06 100644 --- a/src/contracts/core/AllocationManager.sol +++ b/src/contracts/core/AllocationManager.sol @@ -1031,4 +1031,40 @@ contract AllocationManager is return _isOperatorRedistributable(operator, registeredSets) || _isOperatorRedistributable(operator, allocatedSets); } + + function previewSlashOperatorShares( + address operator, + OperatorSet memory operatorSet, + IStrategy strategy, + uint256 wadToSlash + ) public view returns (uint256 shares) { + // Fetch operator's allocation details. + Allocation memory allocation = getAllocation(operator, operatorSet, strategy); + + // Skip if no slashable allocation. + if (allocation.currentMagnitude == 0) return 0; + + uint64 maxMagnitude = getMaxMagnitude(operator, strategy); + uint64 slashedMagnitude = uint64(uint256(allocation.currentMagnitude).mulWadRoundUp(wadToSlash)); + uint64 newMaxMagnitude = maxMagnitude - slashedMagnitude; + + shares = SlashingLib.calcSlashedAmount({ + operatorShares: delegation.operatorShares(operator, strategy), + prevMaxMagnitude: maxMagnitude, + newMaxMagnitude: newMaxMagnitude + }); + } + + function previewSlashOperatorUnderlying( + address operator, + OperatorSet memory operatorSet, + IStrategy strategy, + uint256 wadToSlash + ) external view returns (uint256 underlying) { + uint256 shares = previewSlashOperatorShares(operator, operatorSet, strategy, wadToSlash); + // Skip if no shares to slash. + if (shares == 0) return 0; + // Otherwise, return slashed shares as underlying tokens. + return strategy.sharesToUnderlyingView(shares); + } } diff --git a/src/contracts/interfaces/IDelegationManager.sol b/src/contracts/interfaces/IDelegationManager.sol index fcbc9a4afd..12f980de4c 100644 --- a/src/contracts/interfaces/IDelegationManager.sol +++ b/src/contracts/interfaces/IDelegationManager.sol @@ -425,6 +425,13 @@ interface IDelegationManager is ISignatureUtilsMixin, IDelegationManagerErrors, address operator ) external view returns (address); + /** + * @notice Returns the shares that an operator has delegated to them in a strategy + * @param operator the operator to get shares for + * @param strategy the strategy to get shares for + */ + function operatorShares(address operator, IStrategy strategy) external view returns (uint256); + /** * @notice Returns the shares that an operator has delegated to them in a set of strategies * @param operator the operator to get shares for From bea493206297aa568840608136afe55210f8878e Mon Sep 17 00:00:00 2001 From: "clandestine.eth" <96172957+0xClandestine@users.noreply.github.com> Date: Wed, 3 Sep 2025 13:38:05 -0400 Subject: [PATCH 2/2] cleanup --- src/contracts/core/AllocationManager.sol | 4 ++- .../interfaces/IAllocationManager.sol | 30 +++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/src/contracts/core/AllocationManager.sol b/src/contracts/core/AllocationManager.sol index f8434f7a06..294261ffaa 100644 --- a/src/contracts/core/AllocationManager.sol +++ b/src/contracts/core/AllocationManager.sol @@ -1032,6 +1032,7 @@ contract AllocationManager is _isOperatorRedistributable(operator, registeredSets) || _isOperatorRedistributable(operator, allocatedSets); } + /// @inheritdoc IAllocationManager function previewSlashOperatorShares( address operator, OperatorSet memory operatorSet, @@ -1047,7 +1048,7 @@ contract AllocationManager is uint64 maxMagnitude = getMaxMagnitude(operator, strategy); uint64 slashedMagnitude = uint64(uint256(allocation.currentMagnitude).mulWadRoundUp(wadToSlash)); uint64 newMaxMagnitude = maxMagnitude - slashedMagnitude; - + shares = SlashingLib.calcSlashedAmount({ operatorShares: delegation.operatorShares(operator, strategy), prevMaxMagnitude: maxMagnitude, @@ -1055,6 +1056,7 @@ contract AllocationManager is }); } + /// @inheritdoc IAllocationManager function previewSlashOperatorUnderlying( address operator, OperatorSet memory operatorSet, diff --git a/src/contracts/interfaces/IAllocationManager.sol b/src/contracts/interfaces/IAllocationManager.sol index 7bbf82e2d5..3ec29fd6e0 100644 --- a/src/contracts/interfaces/IAllocationManager.sol +++ b/src/contracts/interfaces/IAllocationManager.sol @@ -676,4 +676,34 @@ interface IAllocationManager is IAllocationManagerErrors, IAllocationManagerEven function isOperatorRedistributable( address operator ) external view returns (bool); + + /** + * @notice Returns the number of shares that would be slashed for an operator in a given strategy. + * @param operator The address of the operator to preview slashed shares for. + * @param operatorSet The operator set to preview slashed shares for. + * @param strategy The strategy to preview slashed shares for. + * @param wadToSlash The proportion (in wad) of the operator's allocation to be slashed. + * @return shares The number of shares that would be slashed. + */ + function previewSlashOperatorShares( + address operator, + OperatorSet memory operatorSet, + IStrategy strategy, + uint256 wadToSlash + ) external view returns (uint256 shares); + + /** + * @notice Returns the amount of underlying tokens that would be slashed for an operator in a given strategy. + * @param operator The address of the operator to preview slashed underlying for. + * @param operatorSet The operator set to preview slashed underlying for. + * @param strategy The strategy to preview slashed underlying for. + * @param wadToSlash The proportion (in wad) of the operator's allocation to be slashed. + * @return underlying The amount of underlying tokens that would be slashed. + */ + function previewSlashOperatorUnderlying( + address operator, + OperatorSet memory operatorSet, + IStrategy strategy, + uint256 wadToSlash + ) external view returns (uint256 underlying); }