-
Notifications
You must be signed in to change notification settings - Fork 443
feat(draft): preview slashOperator
shares + underlying slashed
#1624
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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); | ||
} | ||
} |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
-180 bytes rip
There was a problem hiding this comment.
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