-
Notifications
You must be signed in to change notification settings - Fork 375
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
103 additions
and
128 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -59,6 +59,11 @@ contract DelegationManager is | |
_; | ||
} | ||
|
||
modifier onlyEigenPodManager() { | ||
require(msg.sender == address(eigenPodManager), OnlyEigenPodManager()); | ||
_; | ||
} | ||
Check notice Code scanning / Slither Incorrect modifier Low
Modifier DelegationManager.onlyEigenPodManager() does not always execute _; or revert
|
||
|
||
/** | ||
* | ||
* INITIALIZING FUNCTIONS | ||
|
@@ -411,35 +416,42 @@ contract DelegationManager is | |
} | ||
|
||
/** | ||
* @notice Decreases a staker's delegated share balance in a strategy. Note that before removing from operator shares, | ||
* the delegated shares are scaled according to the operator's total magnitude as part of slashing accounting. Unlike | ||
* `increaseDelegatedShares`, the staker's scaling factor is not updated here. | ||
* @notice Decreases a native restaker's delegated share balance in a strategy due to beacon chain slashing. This updates their beaconChainScalingFactor. | ||
* Their operator's scaled shares are also updated (if they are delegated). | ||
* @param staker The address to increase the delegated scaled shares for their operator. | ||
* @param strategy The strategy in which to decrease the delegated scaled shares. | ||
* @param removedShares The number of shares to decremented for the strategy in the | ||
* StrategyManager/EigenPodManager | ||
* @param shares The number of shares of beaconChainETHStrategy the staker has, not including scaling factors or magnitudes. | ||
* @param proportionPodBalanceDecrease The proportion of the staker's shares to decrease. This is a fraction of the staker's shares in the strategy. | ||
* | ||
* @dev *If the staker is actively delegated*, then decreases the `staker`'s delegated scaled shares in `strategy` by `scaledShares`. Otherwise does nothing. | ||
* @dev Callable only by the StrategyManager or EigenPodManager. | ||
* @dev Callable only by the EigenPodManager. | ||
*/ | ||
function decreaseDelegatedShares( | ||
address staker, | ||
IStrategy strategy, | ||
uint256 removedShares | ||
) external onlyStrategyManagerOrEigenPodManager { | ||
function decreaseBeaconChainScalingFactor( | ||
address staker, | ||
uint256 shares, | ||
uint256 proportionPodBalanceDecrease | ||
) external onlyEigenPodManager { | ||
uint256 scaledSharesBefore = | ||
shares | ||
* beaconChainScalingFactors[staker] / SlashingConstants.PRECISION_FACTOR | ||
* depositScalingFactors[staker][beaconChainETHStrategy] / SlashingConstants.PRECISION_FACTOR; | ||
|
||
beaconChainScalingFactors[staker] = beaconChainScalingFactors[staker] * (SlashingConstants.PRECISION_FACTOR - proportionPodBalanceDecrease) / SlashingConstants.PRECISION_FACTOR; | ||
|
||
uint256 scaledSharesAfter = | ||
shares | ||
* beaconChainScalingFactors[staker] / SlashingConstants.PRECISION_FACTOR | ||
* depositScalingFactors[staker][beaconChainETHStrategy] / SlashingConstants.PRECISION_FACTOR; | ||
|
||
// if the staker is delegated to an operator | ||
if (isDelegated(staker)) { | ||
address operator = delegatedTo[staker]; | ||
|
||
uint64 totalMagnitude = allocationManager.getTotalMagnitude(operator, strategy); | ||
|
||
// subtract strategy shares from delegated scaled shares | ||
_decreaseOperatorScaledShares({ | ||
operator: operator, | ||
staker: staker, | ||
strategy: strategy, | ||
shares: removedShares, | ||
totalMagnitude: totalMagnitude | ||
strategy: beaconChainETHStrategy, | ||
scaledShares: scaledSharesBefore - scaledSharesAfter | ||
}); | ||
} | ||
} | ||
|
@@ -684,9 +696,9 @@ contract DelegationManager is | |
* Update shares amount depending upon the returned value. | ||
* The return value will be lower than the input value in the case where the staker has an existing share deficit | ||
*/ | ||
(shares, existingShares) = eigenPodManager.addShares({podOwner: staker, shares: shares}); | ||
eigenPodManager.addShares({podOwner: staker, shares: shares}); | ||
} else { | ||
existingShares = strategyManager.addShares(msg.sender, tokens[i], withdrawal.strategies[i], shares); | ||
strategyManager.addShares(msg.sender, tokens[i], withdrawal.strategies[i], shares); | ||
} | ||
} | ||
} | ||
|
@@ -719,18 +731,14 @@ contract DelegationManager is | |
* @param operator The operator to decrease the delegated scaled shares for | ||
* @param staker The staker to decrease the delegated scaled shares for | ||
* @param strategy The strategy to decrease the delegated scaled shares for | ||
* @param shares The shares removed from the staker in the StrategyManager/EigenPodManager | ||
* @param totalMagnitude The current total magnitude of the operator for the strategy | ||
* @param scaledShares The scaled shares removed from the staker in the StrategyManager/EigenPodManager | ||
*/ | ||
function _decreaseOperatorScaledShares( | ||
address operator, | ||
address staker, | ||
IStrategy strategy, | ||
uint256 shares, | ||
uint64 totalMagnitude | ||
uint256 scaledShares | ||
) internal { | ||
// based on total magnitude, decrement operator's scaled shares | ||
uint256 scaledShares = _scaleShares(shares, totalMagnitude); | ||
operatorScaledShares[operator][strategy] -= scaledShares; | ||
// TODO: What to do about event wrt scaling? | ||
emit OperatorSharesDecreased(operator, staker, strategy, scaledShares); | ||
|
@@ -789,8 +797,7 @@ contract DelegationManager is | |
operator: operator, | ||
staker: staker, | ||
strategy: strategies[i], | ||
shares: sharesToWithdraw[i], | ||
totalMagnitude: totalMagnitudes[i] | ||
scaledShares: _scaleShares(sharesToWithdraw[i], totalMagnitudes[i]) | ||
}); | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.