Skip to content

Commit

Permalink
chore: dmgr error tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
wadealexc authored and gpsanant committed Sep 17, 2024
1 parent 47f3fd8 commit d120e1c
Show file tree
Hide file tree
Showing 14 changed files with 63 additions and 68 deletions.
2 changes: 1 addition & 1 deletion pkg/bindings/AVSDirectory/binding.go

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions pkg/bindings/DelegationManager/binding.go

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion pkg/bindings/DelegationManagerStorage/binding.go

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion pkg/bindings/EigenPod/binding.go

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion pkg/bindings/EigenPodManager/binding.go

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion pkg/bindings/EigenStrategy/binding.go

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion pkg/bindings/IDelegationManager/binding.go

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion pkg/bindings/RewardsCoordinator/binding.go

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion pkg/bindings/StrategyBase/binding.go

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion pkg/bindings/StrategyBaseTVLLimits/binding.go

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion pkg/bindings/StrategyFactory/binding.go

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion pkg/bindings/StrategyManager/binding.go

Large diffs are not rendered by default.

51 changes: 20 additions & 31 deletions src/contracts/core/DelegationManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,7 @@ contract DelegationManager is

// @notice Simple permission for functions that are only callable by the StrategyManager contract OR by the EigenPodManagerContract
modifier onlyStrategyManagerOrEigenPodManager() {
require(
msg.sender == address(strategyManager) || msg.sender == address(eigenPodManager),
OnlyStrategyManagerOrEigenPodManager()
);
require(msg.sender == address(strategyManager) || msg.sender == address(eigenPodManager), UnauthorizedCaller());
_;
}

Expand Down Expand Up @@ -108,7 +105,7 @@ contract DelegationManager is
OperatorDetails calldata registeringOperatorDetails,
string calldata metadataURI
) external {
require(!isDelegated(msg.sender), ActivelyDelegated());
require(!isDelegated(msg.sender), AlreadyDelegated());
_setOperatorDetails(msg.sender, registeringOperatorDetails);
SignatureWithExpiry memory emptySignatureAndExpiry;
// delegate from the operator to themselves
Expand All @@ -127,7 +124,7 @@ contract DelegationManager is
function modifyOperatorDetails(
OperatorDetails calldata newOperatorDetails
) external {
require(isOperator(msg.sender), OperatorNotRegistered());
require(isOperator(msg.sender), OperatorDoesNotExist());
_setOperatorDetails(msg.sender, newOperatorDetails);
}

Expand All @@ -138,7 +135,7 @@ contract DelegationManager is
function updateOperatorMetadataURI(
string calldata metadataURI
) external {
require(isOperator(msg.sender), OperatorNotRegistered());
require(isOperator(msg.sender), OperatorDoesNotExist());
emit OperatorMetadataURIUpdated(msg.sender, metadataURI);
}

Expand All @@ -160,8 +157,8 @@ contract DelegationManager is
SignatureWithExpiry memory approverSignatureAndExpiry,
bytes32 approverSalt
) external {
require(!isDelegated(msg.sender), ActivelyDelegated());
require(isOperator(operator), OperatorNotRegistered());
require(!isDelegated(msg.sender), AlreadyDelegated());
require(isOperator(operator), OperatorDoesNotExist());
// go through the internal delegation flow, checking the `approverSignatureAndExpiry` if applicable
_delegate(msg.sender, operator, approverSignatureAndExpiry, approverSalt);
}
Expand Down Expand Up @@ -192,8 +189,8 @@ contract DelegationManager is
) external {
// check the signature expiry
require(stakerSignatureAndExpiry.expiry >= block.timestamp, SignatureExpired());
require(!isDelegated(staker), ActivelyDelegated());
require(isOperator(operator), OperatorNotRegistered());
require(!isDelegated(staker), AlreadyDelegated());
require(isOperator(operator), OperatorDoesNotExist());

// calculate the digest hash, then increment `staker`'s nonce
uint256 currentStakerNonce = stakerNonce[staker];
Expand All @@ -218,14 +215,14 @@ contract DelegationManager is
function undelegate(
address staker
) external onlyWhenNotPaused(PAUSED_ENTER_WITHDRAWAL_QUEUE) returns (bytes32[] memory withdrawalRoots) {
require(isDelegated(staker), NotActivelyDelegated());
require(isDelegated(staker), NotCurrentlyDelegated());
require(!isOperator(staker), OperatorsCannotUndelegate());
require(staker != address(0), InputAddressZero());
address operator = delegatedTo[staker];
require(
msg.sender == staker || msg.sender == operator
|| msg.sender == _operatorDetails[operator].delegationApprover,
CallerCannotUndelegate()
UnauthorizedCaller()
);

// Gather strategies and shares to remove from staker/operator during undelegation
Expand Down Expand Up @@ -432,11 +429,11 @@ contract DelegationManager is
function _setOperatorDetails(address operator, OperatorDetails calldata newOperatorDetails) internal {
require(
newOperatorDetails.stakerOptOutWindowBlocks <= MAX_STAKER_OPT_OUT_WINDOW_BLOCKS,
"DelegationManager._setOperatorDetails: stakerOptOutWindowBlocks cannot be > MAX_STAKER_OPT_OUT_WINDOW_BLOCKS"
StakerOptOutWindowBlocksExceedsMax()
);
require(
newOperatorDetails.stakerOptOutWindowBlocks >= _operatorDetails[operator].stakerOptOutWindowBlocks,
"DelegationManager._setOperatorDetails: stakerOptOutWindowBlocks cannot be decreased"
StakerOptOutWindowBlocksCannotDecrease()
);
_operatorDetails[operator] = newOperatorDetails;
emit OperatorDetailsModified(msg.sender, newOperatorDetails);
Expand Down Expand Up @@ -472,7 +469,7 @@ contract DelegationManager is
// check the signature expiry
require(approverSignatureAndExpiry.expiry >= block.timestamp, SignatureExpired());
// check that the salt hasn't been used previously, then mark the salt as spent
require(!delegationApproverSaltIsSpent[_delegationApprover][approverSalt], SaltSpent());
require(!delegationApproverSaltIsSpent[_delegationApprover][approverSalt], SignatureSaltSpent());
delegationApproverSaltIsSpent[_delegationApprover][approverSalt] = true;

// forgefmt: disable-next-item
Expand Down Expand Up @@ -527,11 +524,11 @@ contract DelegationManager is
) internal {
bytes32 withdrawalRoot = calculateWithdrawalRoot(withdrawal);

require(pendingWithdrawals[withdrawalRoot], WithdrawalNotQueued());
require(pendingWithdrawals[withdrawalRoot], WithdrawalDoesNotExist());

require(withdrawal.startBlock + minWithdrawalDelayBlocks <= block.number, WithdrawalDelayNotElapsed());

require(msg.sender == withdrawal.withdrawer, WithdrawerNotCaller());
require(msg.sender == withdrawal.withdrawer, UnauthorizedCaller());

if (receiveAsTokens) {
require(tokens.length == withdrawal.strategies.length, InputArrayLengthMismatch());
Expand Down Expand Up @@ -567,7 +564,7 @@ contract DelegationManager is
for (uint256 i = 0; i < withdrawal.strategies.length;) {
require(
withdrawal.startBlock + strategyWithdrawalDelayBlocks[withdrawal.strategies[i]] <= block.number,
"DelegationManager._completeQueuedWithdrawal: withdrawalDelayBlocks period has not yet passed for this strategy"
WithdrawalDelayNotElapsed()
);

/**
Expand Down Expand Up @@ -667,6 +664,7 @@ contract DelegationManager is
*/
eigenPodManager.removeShares(staker, shares[i]);
} else {
// If thirdPartyTransfersForbidden is set, withdrawer and staker must be the same address
require(
staker == withdrawer || !strategyManager.thirdPartyTransfersForbidden(strategies[i]),
WithdrawerNotStaker()
Expand Down Expand Up @@ -724,10 +722,7 @@ contract DelegationManager is
function _setMinWithdrawalDelayBlocks(
uint256 _minWithdrawalDelayBlocks
) internal {
require(
_minWithdrawalDelayBlocks <= MAX_WITHDRAWAL_DELAY_BLOCKS,
"DelegationManager._setMinWithdrawalDelayBlocks: _minWithdrawalDelayBlocks cannot be > MAX_WITHDRAWAL_DELAY_BLOCKS"
);
require(_minWithdrawalDelayBlocks <= MAX_WITHDRAWAL_DELAY_BLOCKS, WithdrawalDelayExceedsMax());
emit MinWithdrawalDelayBlocksSet(minWithdrawalDelayBlocks, _minWithdrawalDelayBlocks);
minWithdrawalDelayBlocks = _minWithdrawalDelayBlocks;
}
Expand All @@ -740,19 +735,13 @@ contract DelegationManager is
IStrategy[] calldata _strategies,
uint256[] calldata _withdrawalDelayBlocks
) internal {
require(
_strategies.length == _withdrawalDelayBlocks.length,
"DelegationManager._setStrategyWithdrawalDelayBlocks: input length mismatch"
);
require(_strategies.length == _withdrawalDelayBlocks.length, InputArrayLengthMismatch());
uint256 numStrats = _strategies.length;
for (uint256 i = 0; i < numStrats; ++i) {
IStrategy strategy = _strategies[i];
uint256 prevStrategyWithdrawalDelayBlocks = strategyWithdrawalDelayBlocks[strategy];
uint256 newStrategyWithdrawalDelayBlocks = _withdrawalDelayBlocks[i];
require(
newStrategyWithdrawalDelayBlocks <= MAX_WITHDRAWAL_DELAY_BLOCKS,
"DelegationManager._setStrategyWithdrawalDelayBlocks: _withdrawalDelayBlocks cannot be > MAX_WITHDRAWAL_DELAY_BLOCKS"
);
require(newStrategyWithdrawalDelayBlocks <= MAX_WITHDRAWAL_DELAY_BLOCKS, WithdrawalDelayExceedsMax());

// set the new withdrawal delay blocks
strategyWithdrawalDelayBlocks[strategy] = newStrategyWithdrawalDelayBlocks;
Expand Down
54 changes: 30 additions & 24 deletions src/contracts/interfaces/IDelegationManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,40 +15,46 @@ import "./ISignatureUtils.sol";
* - enabling a staker to undelegate its assets from the operator it is delegated to (performed as part of the withdrawal process, initiated through the StrategyManager)
*/
interface IDelegationManager is ISignatureUtils {
/// @dev Thrown when an account is actively delegated.
error ActivelyDelegated();
/// @dev Thrown when attempting to execute an action that was not queued.
error WithdrawalNotQueued();
/// @dev Thrown when caller cannot undelegate on behalf of a staker.
error CallerCannotUndelegate();
/// @dev Thrown when msg.sender is not allowed to call a function
error UnauthorizedCaller();

/// Delegation Status

/// @dev Thrown when an account is currently delegated.
error AlreadyDelegated();
/// @dev Thrown when an account is not currently delegated.
error NotCurrentlyDelegated();
/// @dev Thrown when an operator attempts to undelegate.
error OperatorsCannotUndelegate();
/// @dev Thrown when `operator` is not a registered operator.
error OperatorDoesNotExist();

/// Invalid Inputs

/// @dev Thrown when two array parameters have mismatching lengths.
error InputArrayLengthMismatch();
/// @dev Thrown when input arrays length is zero.
error InputArrayLengthZero();
/// @dev Thrown when `operator` is not a registered operator.
error OperatorNotRegistered();
/// @dev Thrown when caller is neither the StrategyManager or EigenPodManager contract.
error OnlyStrategyManagerOrEigenPodManager();
/// @dev Thrown when an operator attempts to undelegate.
error OperatorsCannotUndelegate();
/// @dev Thrown when an account is not actively delegated.
error NotActivelyDelegated();
/// @dev Thrown when attempting to spend a spent eip-712 salt.
error SaltSpent();
/// @dev Thrown when attempting to use an expired eip-712 signature.
error SignatureExpired();
/// @dev Thrown when provided `stakerOptOutWindowBlocks` cannot decrease.
error StakerOptOutWindowBlocksCannotDecrease();
/// @dev Thrown when provided `stakerOptOutWindowBlocks` exceeds maximum.
error StakerOptOutWindowBlocksExceedsMax();
/// @dev Thrown when provided delay exceeds maximum.
error WithdrawalDelayExceedsMax();

/// Signatures

/// @dev Thrown when attempting to spend a spent eip-712 salt.
error SignatureSaltSpent();
/// @dev Thrown when attempting to use an expired eip-712 signature.
error SignatureExpired();

/// Withdrawal Processing

/// @dev Thrown when attempting to execute an action that was not queued.
error WithdrawalDoesNotExist();
/// @dev Thrown when attempting to withdraw before delay has elapsed.
error WithdrawalDelayNotElapsed();
/// @dev Thrown when provided delay exceeds maximum.
error WithdrawalDelayExeedsMax();
/// @dev Thrown when a withdraw amount larger than max is attempted.
error WithdrawalExeedsMax();
/// @dev Thrown when withdrawer is not the current caller.
error WithdrawerNotCaller();
/// @dev Thrown when `withdrawer` is not staker.
error WithdrawerNotStaker();

Expand Down

0 comments on commit d120e1c

Please sign in to comment.