diff --git a/src/contracts/core/AllocationManager.sol b/src/contracts/core/AllocationManager.sol index 44aedf268..294261ffa 100644 --- a/src/contracts/core/AllocationManager.sol +++ b/src/contracts/core/AllocationManager.sol @@ -1031,4 +1031,42 @@ contract AllocationManager is return _isOperatorRedistributable(operator, registeredSets) || _isOperatorRedistributable(operator, allocatedSets); } + + /// @inheritdoc IAllocationManager + 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 + }); + } + + /// @inheritdoc IAllocationManager + 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/IAllocationManager.sol b/src/contracts/interfaces/IAllocationManager.sol index 7bbf82e2d..3ec29fd6e 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); } diff --git a/src/contracts/interfaces/IDelegationManager.sol b/src/contracts/interfaces/IDelegationManager.sol index fcbc9a4af..12f980de4 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