Skip to content
Draft
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
38 changes: 38 additions & 0 deletions src/contracts/core/AllocationManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -1031,4 +1031,42 @@ contract AllocationManager is
return
_isOperatorRedistributable(operator, registeredSets) || _isOperatorRedistributable(operator, allocatedSets);
}

/// @inheritdoc IAllocationManager
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How much space do we have left?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

-180 bytes rip

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will sort this out as well

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);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should make an internal function that does this logic and is called by this function as well as slashOperator

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree, will sort that out once my fn is sound.


// 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;

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs to also include shares that are being deallocated

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);
}
}
30 changes: 30 additions & 0 deletions src/contracts/interfaces/IAllocationManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
7 changes: 7 additions & 0 deletions src/contracts/interfaces/IDelegationManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading