-
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
8 changed files
with
174 additions
and
134 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 |
---|---|---|
|
@@ -57,6 +57,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 | ||
|
@@ -398,37 +403,43 @@ contract DelegationManager is | |
} | ||
} | ||
|
||
// IGNORE THIS FUNCTION | ||
/** | ||
* @notice Decreases a staker's delegated stakeShares for a strategy. | ||
* @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 | ||
* @notice Decreases a native restaker's delegated share balance in a strategy due to beacon chain slashing. This updates their beaconChainScalingFactor. | ||
* Their operator's stakeShares are also updated (if they are delegated). | ||
* @param staker The address to increase the delegated stakeShares for their operator. | ||
* @param existingDepositShares The number of deposit shares the staker already has in the EPM. This does not change upon decreasing shares. | ||
* @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 stakeShares in `strategy` by `scaledShares`. Otherwise does nothing. | ||
* @dev Callable only by the StrategyManager or EigenPodManager. | ||
* @dev *If the staker is actively delegated*, then decreases the `staker`'s delegated stakeShares in `strategy` by `proportionPodBalanceDecrease` proportion. Otherwise does nothing. | ||
* @dev Callable only by the EigenPodManager. | ||
*/ | ||
function decreaseDelegatedShares( | ||
address staker, | ||
IStrategy strategy, | ||
uint256 removedShares | ||
) external onlyStrategyManagerOrEigenPodManager { | ||
// 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 | ||
// }); | ||
// } | ||
function decreaseBeaconChainScalingFactor( | ||
address staker, | ||
uint256 existingDepositShares, | ||
uint256 proportionPodBalanceDecrease | ||
) external onlyEigenPodManager { | ||
uint256 stakeSharesBefore = _convertDepositSharesToStakeShares(staker, beaconChainETHStrategy, existingDepositShares); | ||
|
||
// decrease the staker's beaconChainScalingFactor proportionally | ||
beaconChainScalingFactors[staker] = | ||
beaconChainScalingFactors[staker] | ||
* (PRECISION_FACTOR - proportionPodBalanceDecrease) | ||
/ PRECISION_FACTOR; | ||
|
||
uint256 stakeSharesAfter = _convertDepositSharesToStakeShares(staker, beaconChainETHStrategy, existingDepositShares); | ||
|
||
// if the staker is delegated to an operators | ||
if (isDelegated(staker)) { | ||
address operator = delegatedTo[staker]; | ||
|
||
// subtract strategy shares from delegated scaled shares | ||
_decreaseOperatorStakeShares({ | ||
operator: operator, | ||
staker: staker, | ||
strategy: beaconChainETHStrategy, | ||
stakeShares: stakeSharesBefore - stakeSharesAfter | ||
}); | ||
} | ||
} | ||
|
||
/** | ||
|
@@ -612,18 +623,15 @@ contract DelegationManager is | |
* @param operator The operator to decrease the delegated delegated shares for | ||
* @param staker The staker to decrease the delegated delegated shares for | ||
* @param strategy The strategy to decrease the delegated delegated 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 stakeShares The stakeShares to be removed from the operator's total delegated | ||
*/ | ||
function _decreaseOperatorStakeShares( | ||
address operator, | ||
address staker, | ||
IStrategy strategy, | ||
uint256 shares, | ||
uint64 totalMagnitude | ||
uint256 stakeShares | ||
) internal { | ||
// based on total magnitude, decrement operator's stakeShares | ||
uint256 stakeShares = _convertSharesToStakeShares(shares, totalMagnitude); | ||
operatorStakeShares[operator][strategy] -= stakeShares; | ||
// TODO: What to do about event wrt scaling? | ||
emit OperatorSharesDecreased(operator, staker, strategy, stakeShares); | ||
|
@@ -670,8 +678,7 @@ contract DelegationManager is | |
operator: operator, | ||
staker: staker, | ||
strategy: strategies[i], | ||
shares: sharesToWithdraw[i], | ||
totalMagnitude: totalMagnitudes[i] | ||
stakeShares: stakeSharesToWithdraw[i] | ||
}); | ||
} | ||
|
||
|
@@ -748,9 +755,11 @@ contract DelegationManager is | |
* 3. depositShares | ||
* - These can be converted into stakeShares given a staker and a strategy | ||
* - by multiplying by the staker's depositScalingFactor for the strategy | ||
* - additionally, if the strategy is beaconChainETHStrategy, then multiplying by the staker's beaconChainScalingFactor | ||
* - These values automatically update their conversion into tokens | ||
* - when the staker's depositScalingFactor for the strategy is increased upon new deposits | ||
* - or when the staker's operator's total magnitude for the strategy is decreased upon slashing | ||
* - or when the staker's beaconChainScalingFactor is decreased upon beacon chain slashing | ||
* - These represent the total amount of shares the staker would have of a strategy if they were never slashed | ||
* - These live in the storage of the StrategyManager/EigenPodManager | ||
* - `stakerStrategyShares` in the SM is the staker's depositShares that have not been queued for withdrawal in a strategy | ||
|
@@ -766,11 +775,35 @@ contract DelegationManager is | |
} | ||
|
||
function _convertSharesToDepositShares(address staker, IStrategy strategy, uint256 shares, uint64 totalMagnitude) internal view returns (uint256) { | ||
return shares * PRECISION_FACTOR / _getDepositScalingFactor(staker, strategy) * PRECISION_FACTOR / totalMagnitude; | ||
// scale by depositScalingFactor first | ||
uint256 depositShares = shares * PRECISION_FACTOR / _getDepositScalingFactor(staker, strategy); | ||
// scale by beaconChainScalingFactor if beaconChainETHStrategy | ||
if(strategy == beaconChainETHStrategy) { | ||
depositShares = depositShares * _getBeaconChainScalingFactor(staker) / PRECISION_FACTOR; | ||
} | ||
// finally scale by totalMagnitude | ||
return depositShares * PRECISION_FACTOR / totalMagnitude; | ||
} | ||
|
||
function _convertDepositSharesToShares(address staker, IStrategy strategy, uint256 depositShares, uint64 totalMagnitude) internal view returns (uint256) { | ||
return depositShares * _getDepositScalingFactor(staker, strategy) / PRECISION_FACTOR * totalMagnitude / PRECISION_FACTOR; | ||
// scale by depositScalingFactor first | ||
uint256 shares = depositShares * _getDepositScalingFactor(staker, strategy) / PRECISION_FACTOR; | ||
// scale by beaconChainScalingFactor if beaconChainETHStrategy | ||
if(strategy == beaconChainETHStrategy) { | ||
shares = shares * PRECISION_FACTOR / _getBeaconChainScalingFactor(staker); | ||
} | ||
// finally scale by totalMagnitude | ||
return shares * totalMagnitude / PRECISION_FACTOR; | ||
} | ||
|
||
function _convertDepositSharesToStakeShares(address staker, IStrategy strategy, uint256 depositShares) internal view returns (uint256) { | ||
// scale by depositScalingFactor first | ||
uint256 stakeShares = depositShares * PRECISION_FACTOR / _getDepositScalingFactor(staker, strategy); | ||
// scale by beaconChainScalingFactor if beaconChainETHStrategy | ||
if(strategy == beaconChainETHStrategy) { | ||
stakeShares = stakeShares * _getBeaconChainScalingFactor(staker) / PRECISION_FACTOR; | ||
} | ||
return stakeShares; | ||
} | ||
|
||
/** | ||
|
@@ -823,9 +856,7 @@ contract DelegationManager is | |
depositScalingFactors[staker][strategy] = newDepositScalingFactor; | ||
} | ||
|
||
/** | ||
* @notice depositScalingFactor should be initialized and lower bounded to 1e18 | ||
*/ | ||
/// @notice returns the depositScalingFactor for a staker or PRECISION_FACTOR if it is not set | ||
function _getDepositScalingFactor(address staker, IStrategy strategy) internal view returns (uint256) { | ||
uint256 currDepositScalingFactor = depositScalingFactors[staker][strategy]; | ||
if (currDepositScalingFactor == 0) { | ||
|
@@ -834,6 +865,15 @@ contract DelegationManager is | |
return currDepositScalingFactor; | ||
} | ||
|
||
/// @notice returns the beaconChainScalingFactor factor for a staker or PRECISION_FACTOR if it is not set | ||
function _getBeaconChainScalingFactor(address staker) internal view returns (uint256) { | ||
uint256 currBeaconChainScalingFactor = beaconChainScalingFactors[staker]; | ||
if (currBeaconChainScalingFactor == 0) { | ||
currBeaconChainScalingFactor = PRECISION_FACTOR; | ||
} | ||
return currBeaconChainScalingFactor; | ||
} | ||
|
||
function _getShareManager(IStrategy strategy) internal view returns (IShareManager) { | ||
return strategy == beaconChainETHStrategy ? IShareManager(address(eigenPodManager)) : IShareManager(address(strategyManager)); | ||
} | ||
|
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.