Skip to content

Commit

Permalink
refactor: remove deprecated methods (#903)
Browse files Browse the repository at this point in the history
* refactor: rename parameter to be more accurate

* refactor: remove deprecated methods from dm

* refactor: remove operator details usage

* chore: nit word
  • Loading branch information
wadealexc authored Nov 25, 2024
1 parent 28fc33e commit 601f8e2
Show file tree
Hide file tree
Showing 9 changed files with 97 additions and 223 deletions.
9 changes: 1 addition & 8 deletions script/tasks/register_as_operator.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,8 @@ contract RegisterAsOperator is Script, Test {
// Attach the delegationManager
DelegationManager delegation = DelegationManager(delegationManager);

// Define OperatorDetails struct instance
IDelegationManagerTypes.OperatorDetails memory operatorDetails = IDelegationManagerTypes.OperatorDetails({
__deprecated_earningsReceiver: address(0),
delegationApprover: operator,
__deprecated_stakerOptOutWindowBlocks: 0
});

// Register the sender as an Operator
delegation.registerAsOperator(operatorDetails, 0, metadataURI);
delegation.registerAsOperator(operator, 0, metadataURI);

// STOP RECORDING TRANSACTIONS FOR DEPLOYMENT
vm.stopBroadcast();
Expand Down
70 changes: 17 additions & 53 deletions src/contracts/core/DelegationManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -94,28 +94,28 @@ contract DelegationManager is

/// @inheritdoc IDelegationManager
function registerAsOperator(
OperatorDetails calldata registeringOperatorDetails,
address initDelegationApprover,
uint32 allocationDelay,
string calldata metadataURI
) external {
require(!isDelegated(msg.sender), ActivelyDelegated());

allocationManager.setAllocationDelay(msg.sender, allocationDelay);
_setOperatorDetails(msg.sender, registeringOperatorDetails);
_setDelegationApprover(msg.sender, initDelegationApprover);

// delegate from the operator to themselves
_delegate(msg.sender, msg.sender);

emit OperatorRegistered(msg.sender, registeringOperatorDetails);
emit OperatorRegistered(msg.sender, initDelegationApprover);
emit OperatorMetadataURIUpdated(msg.sender, metadataURI);
}

/// @inheritdoc IDelegationManager
function modifyOperatorDetails(
OperatorDetails calldata newOperatorDetails
address newDelegationApprover
) external {
require(isOperator(msg.sender), OperatorNotRegistered());
_setOperatorDetails(msg.sender, newOperatorDetails);
_setDelegationApprover(msg.sender, newDelegationApprover);
}

/// @inheritdoc IDelegationManager
Expand Down Expand Up @@ -289,7 +289,7 @@ contract DelegationManager is
function increaseDelegatedShares(
address staker,
IStrategy strategy,
uint256 curDepositShares,
uint256 prevDepositShares,
uint256 addedShares
) external onlyStrategyManagerOrEigenPodManager {
address operator = delegatedTo[staker];
Expand All @@ -301,7 +301,7 @@ contract DelegationManager is
operator: operator,
staker: staker,
strategy: strategy,
curDepositShares: curDepositShares,
prevDepositShares: prevDepositShares,
addedShares: addedShares,
slashingFactor: slashingFactor
});
Expand Down Expand Up @@ -378,35 +378,6 @@ contract DelegationManager is
}
}

/**
*
* BACKWARDS COMPATIBLE LEGACY FUNCTIONS
* TO BE DEPRECATED IN FUTURE
*
*/

/// @inheritdoc IDelegationManager
function completeQueuedWithdrawal(
Withdrawal calldata withdrawal,
IERC20[] calldata tokens,
uint256, // middlewareTimesIndex
bool receiveAsTokens
) external onlyWhenNotPaused(PAUSED_EXIT_WITHDRAWAL_QUEUE) nonReentrant {
_completeQueuedWithdrawal(withdrawal, tokens, receiveAsTokens);
}

/// @inheritdoc IDelegationManager
function completeQueuedWithdrawals(
Withdrawal[] calldata withdrawals,
IERC20[][] calldata tokens,
uint256[] calldata, // middlewareTimesIndexes
bool[] calldata receiveAsTokens
) external onlyWhenNotPaused(PAUSED_EXIT_WITHDRAWAL_QUEUE) nonReentrant {
for (uint256 i = 0; i < withdrawals.length; ++i) {
_completeQueuedWithdrawal(withdrawals[i], tokens[i], receiveAsTokens[i]);
}
}

/**
*
* INTERNAL FUNCTIONS
Expand All @@ -416,11 +387,11 @@ contract DelegationManager is
/**
* @notice Sets operator parameters in the `_operatorDetails` mapping.
* @param operator The account registered as an operator updating their operatorDetails
* @param newOperatorDetails The new parameters for the operator
* @param newDelegationApprover The new parameters for the operator
*/
function _setOperatorDetails(address operator, OperatorDetails calldata newOperatorDetails) internal {
_operatorDetails[operator] = newOperatorDetails;
emit OperatorDetailsModified(msg.sender, newOperatorDetails);
function _setDelegationApprover(address operator, address newDelegationApprover) internal {
_operatorDetails[operator].delegationApprover = newDelegationApprover;
emit DelegationApproverUpdated(msg.sender, newDelegationApprover);
}

/**
Expand Down Expand Up @@ -450,7 +421,7 @@ contract DelegationManager is
operator: operator,
staker: staker,
strategy: strategies[i],
curDepositShares: uint256(0),
prevDepositShares: uint256(0),
addedShares: depositedShares[i],
slashingFactor: slashingFactors[i]
});
Expand Down Expand Up @@ -517,7 +488,7 @@ contract DelegationManager is
});
} else {
// Award shares back in StrategyManager/EigenPodManager.
(uint256 curDepositShares, uint256 addedShares) = shareManager.addShares({
(uint256 prevDepositShares, uint256 addedShares) = shareManager.addShares({
staker: withdrawal.staker,
strategy: withdrawal.strategies[i],
token: tokens[i],
Expand All @@ -529,7 +500,7 @@ contract DelegationManager is
operator: newOperator,
staker: withdrawal.staker,
strategy: withdrawal.strategies[i],
curDepositShares: curDepositShares,
prevDepositShares: prevDepositShares,
addedShares: addedShares,
slashingFactor: newSlashingFactors[i]
});
Expand All @@ -550,15 +521,15 @@ contract DelegationManager is
* @param operator The operator to increase the delegated delegatedShares for
* @param staker The staker to increase the depositScalingFactor for
* @param strategy The strategy to increase the delegated delegatedShares and the depositScalingFactor for
* @param curDepositShares The number of deposit shares the staker already has in the strategy.
* @param prevDepositShares The number of delegated deposit shares the staker had in the strategy prior to the increase
* @param addedShares The shares added to the staker in the StrategyManager/EigenPodManager
* @param slashingFactor The current slashing factor for the staker/operator/strategy
*/
function _increaseDelegation(
address operator,
address staker,
IStrategy strategy,
uint256 curDepositShares,
uint256 prevDepositShares,
uint256 addedShares,
uint256 slashingFactor
) internal {
Expand All @@ -569,7 +540,7 @@ contract DelegationManager is
// Update the staker's depositScalingFactor. This only results in an update
// if the slashing factor has changed for this strategy.
DepositScalingFactor storage dsf = _depositScalingFactor[staker][strategy];
dsf.update(curDepositShares, addedShares, slashingFactor);
dsf.update(prevDepositShares, addedShares, slashingFactor);
emit DepositScalingFactorUpdated(staker, strategy, dsf.scalingFactor());

// If the staker is delegated to an operator, update the operator's shares
Expand Down Expand Up @@ -820,13 +791,6 @@ contract DelegationManager is
return operator != address(0) && delegatedTo[operator] == operator;
}

/// @inheritdoc IDelegationManager
function operatorDetails(
address operator
) external view returns (OperatorDetails memory) {
return _operatorDetails[operator];
}

/// @inheritdoc IDelegationManager
function delegationApprover(
address operator
Expand Down
14 changes: 7 additions & 7 deletions src/contracts/core/StrategyManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -203,19 +203,19 @@ contract StrategyManager is
require(staker != address(0), StakerAddressZero());
require(shares != 0, SharesAmountZero());

uint256 existingShares = stakerDepositShares[staker][strategy];
uint256 prevDepositShares = stakerDepositShares[staker][strategy];

// if they dont have existingShares of this strategy, add it to their strats
if (existingShares == 0) {
// if they dont have prevDepositShares of this strategy, add it to their strats
if (prevDepositShares == 0) {
require(stakerStrategyList[staker].length < MAX_STAKER_STRATEGY_LIST_LENGTH, MaxStrategiesExceeded());
stakerStrategyList[staker].push(strategy);
}

// add the returned depositedShares to their existing shares for this strategy
stakerDepositShares[staker][strategy] = existingShares + shares;
stakerDepositShares[staker][strategy] = prevDepositShares + shares;

emit Deposit(staker, token, strategy, shares);
return (existingShares, shares);
return (prevDepositShares, shares);
}

/**
Expand All @@ -240,13 +240,13 @@ contract StrategyManager is
shares = strategy.deposit(token, amount);

// add the returned shares to the staker's existing shares for this strategy
(uint256 existingShares, uint256 addedShares) = _addShares(staker, token, strategy, shares);
(uint256 prevDepositShares, uint256 addedShares) = _addShares(staker, token, strategy, shares);

// Increase shares delegated to operator
delegation.increaseDelegatedShares({
staker: staker,
strategy: strategy,
curDepositShares: existingShares,
prevDepositShares: prevDepositShares,
addedShares: addedShares
});

Expand Down
55 changes: 12 additions & 43 deletions src/contracts/interfaces/IDelegationManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -136,11 +136,11 @@ interface IDelegationManagerTypes {
}

interface IDelegationManagerEvents is IDelegationManagerTypes {
// @notice Emitted when a new operator registers in EigenLayer and provides their OperatorDetails.
event OperatorRegistered(address indexed operator, OperatorDetails operatorDetails);
// @notice Emitted when a new operator registers in EigenLayer and provides their delegation approver.
event OperatorRegistered(address indexed operator, address delegationApprover);

/// @notice Emitted when an operator updates their OperatorDetails to @param newOperatorDetails
event OperatorDetailsModified(address indexed operator, OperatorDetails newOperatorDetails);
/// @notice Emitted when an operator updates their delegation approver
event DelegationApproverUpdated(address indexed operator, address newDelegationApprover);

/**
* @notice Emitted when @param operator indicates that they are updating their MetadataURI string
Expand Down Expand Up @@ -199,7 +199,8 @@ interface IDelegationManager is ISignatureUtils, IDelegationManagerErrors, IDele

/**
* @notice Registers the caller as an operator in EigenLayer.
* @param registeringOperatorDetails is the `OperatorDetails` for the operator.
* @param initDelegationApprover is an address that, if set, must provide a signature when stakers delegate
* to an operator.
* @param allocationDelay The delay before allocations take effect.
* @param metadataURI is a URI for the operator's metadata, i.e. a link providing more details on the operator.
*
Expand All @@ -208,19 +209,19 @@ interface IDelegationManager is ISignatureUtils, IDelegationManagerErrors, IDele
* @dev Note that the `metadataURI` is *never stored * and is only emitted in the `OperatorMetadataURIUpdated` event
*/
function registerAsOperator(
OperatorDetails calldata registeringOperatorDetails,
address initDelegationApprover,
uint32 allocationDelay,
string calldata metadataURI
) external;

/**
* @notice Updates an operator's stored `OperatorDetails`.
* @param newOperatorDetails is the updated `OperatorDetails` for the operator, to replace their current OperatorDetails`.
* @notice Updates an operator's stored `delegationApprover`.
* @param newDelegationApprover is the new delegationApprover for the operator
*
* @dev The caller must have previously registered as an operator in EigenLayer.
*/
function modifyOperatorDetails(
OperatorDetails calldata newOperatorDetails
address newDelegationApprover
) external;

/**
Expand Down Expand Up @@ -332,7 +333,7 @@ interface IDelegationManager is ISignatureUtils, IDelegationManagerErrors, IDele
* the delegated delegatedShares. The staker's depositScalingFactor is updated here.
* @param staker The address to increase the delegated shares for their operator.
* @param strategy The strategy in which to increase the delegated shares.
* @param curDepositShares The number of deposit shares the staker already has in the strategy. This is the shares amount stored in the
* @param prevDepositShares The number of deposit shares the staker already had in the strategy. This is the shares amount stored in the
* StrategyManager/EigenPodManager for the staker's shares.
* @param addedShares The number of shares added to the staker's shares in the strategy
*
Expand All @@ -344,7 +345,7 @@ interface IDelegationManager is ISignatureUtils, IDelegationManagerErrors, IDele
function increaseDelegatedShares(
address staker,
IStrategy strategy,
uint256 curDepositShares,
uint256 prevDepositShares,
uint256 addedShares
) external;

Expand Down Expand Up @@ -383,31 +384,6 @@ interface IDelegationManager is ISignatureUtils, IDelegationManagerErrors, IDele
uint64 newMaxMagnitude
) external;

/**
*
* BACKWARDS COMPATIBLE LEGACY FUNCTIONS
* TO BE DEPRECATED IN FUTURE
*
*/

/// @notice Overloaded version of `completeQueuedWithdrawal` that includes a `middlewareTimesIndex` parameter
/// for backwards compatibility with the M2 release. To be deprecated in a future release.
function completeQueuedWithdrawal(
Withdrawal calldata withdrawal,
IERC20[] calldata tokens,
uint256 middlewareTimesIndex,
bool receiveAsTokens
) external;

/// @notice Overloaded version of `completeQueuedWithdrawals` that includes a `middlewareTimesIndexes` parameter
/// for backwards compatibility with the M2 release. To be deprecated in a future release.
function completeQueuedWithdrawals(
Withdrawal[] calldata withdrawals,
IERC20[][] calldata tokens,
uint256[] calldata middlewareTimesIndexes,
bool[] calldata receiveAsTokens
) external;

/**
*
* VIEW FUNCTIONS
Expand Down Expand Up @@ -450,13 +426,6 @@ interface IDelegationManager is ISignatureUtils, IDelegationManagerErrors, IDele
address operator
) external view returns (bool);

/**
* @notice Returns the OperatorDetails struct associated with an `operator`.
*/
function operatorDetails(
address operator
) external view returns (OperatorDetails memory);

/**
* @notice Returns the delegationApprover account for an operator
*/
Expand Down
18 changes: 9 additions & 9 deletions src/contracts/libraries/SlashingLib.sol
Original file line number Diff line number Diff line change
Expand Up @@ -100,21 +100,21 @@ library SlashingLib {

function update(
DepositScalingFactor storage dsf,
uint256 curDepositShares,
uint256 prevDepositShares,
uint256 addedShares,
uint256 slashingFactor
) internal {
// If this is the staker's first deposit for this operator, set the scaling factor to
// If this is the staker's first deposit, set the scaling factor to
// the inverse of slashingFactor
if (curDepositShares == 0) {
if (prevDepositShares == 0) {
dsf._scalingFactor = uint256(WAD).divWad(slashingFactor);
return;
}

/**
* Base Equations:
* (1) newShares = currentShares + addedShares
* (2) newDepositShares = curDepositShares + addedShares
* (2) newDepositShares = prevDepositShares + addedShares
* (3) newShares = newDepositShares * newDepositScalingFactor * slashingFactor
*
* Plugging (1) into (3):
Expand All @@ -124,23 +124,23 @@ library SlashingLib {
* (5) newDepositScalingFactor = (currentShares + addedShares) / (newDepositShares * slashingFactor)
*
* Plugging in (2) into (5):
* (7) newDepositScalingFactor = (currentShares + addedShares) / ((curDepositShares + addedShares) * slashingFactor)
* (7) newDepositScalingFactor = (currentShares + addedShares) / ((prevDepositShares + addedShares) * slashingFactor)
* Note that magnitudes must be divided by WAD for precision. Thus,
*
* (8) newDepositScalingFactor = WAD * (currentShares + addedShares) / ((curDepositShares + addedShares) * slashingFactor / WAD)
* (9) newDepositScalingFactor = (currentShares + addedShares) * WAD / (curDepositShares + addedShares) * WAD / slashingFactor
* (8) newDepositScalingFactor = WAD * (currentShares + addedShares) / ((prevDepositShares + addedShares) * slashingFactor / WAD)
* (9) newDepositScalingFactor = (currentShares + addedShares) * WAD / (prevDepositShares + addedShares) * WAD / slashingFactor
*/

// Step 1: Calculate Numerator
uint256 currentShares = dsf.calcWithdrawable(curDepositShares, slashingFactor);
uint256 currentShares = dsf.calcWithdrawable(prevDepositShares, slashingFactor);

// Step 2: Compute currentShares + addedShares
uint256 newShares = currentShares + addedShares;

// Step 3: Calculate newDepositScalingFactor
/// forgefmt: disable-next-item
uint256 newDepositScalingFactor = newShares
.divWad(curDepositShares + addedShares)
.divWad(prevDepositShares + addedShares)
.divWad(slashingFactor);

dsf._scalingFactor = newDepositScalingFactor;
Expand Down
Loading

0 comments on commit 601f8e2

Please sign in to comment.