Skip to content

Commit

Permalink
chore: forge fmt src/contracts
Browse files Browse the repository at this point in the history
  • Loading branch information
8sunyuan committed Sep 12, 2024
1 parent 78e8e2f commit 94969be
Show file tree
Hide file tree
Showing 36 changed files with 603 additions and 457 deletions.
44 changes: 17 additions & 27 deletions src/contracts/core/AVSDirectory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ contract AVSDirectory is
* @dev Initializes the immutable addresses of the strategy mananger, delegationManager, slasher,
* and eigenpodManager contracts
*/
constructor(IDelegationManager _delegation) AVSDirectoryStorage(_delegation) {
constructor(
IDelegationManager _delegation
) AVSDirectoryStorage(_delegation) {
_disableInitializers();
ORIGINAL_CHAIN_ID = block.chainid;
}
Expand Down Expand Up @@ -66,25 +68,13 @@ contract AVSDirectory is
ISignatureUtils.SignatureWithSaltAndExpiry memory operatorSignature
) external onlyWhenNotPaused(PAUSED_OPERATOR_REGISTER_DEREGISTER_TO_AVS) {
// Assert `operatorSignature.expiry` has not elapsed.
require(
operatorSignature.expiry >= block.timestamp,
SignatureExpired()
);
require(operatorSignature.expiry >= block.timestamp, SignatureExpired());
// Assert that the `operator` is not actively registered to the AVS.
require(
avsOperatorStatus[msg.sender][operator] != OperatorAVSRegistrationStatus.REGISTERED,
InvalidOperator()
);
require(avsOperatorStatus[msg.sender][operator] != OperatorAVSRegistrationStatus.REGISTERED, InvalidOperator());
// Assert `operator` has not already spent `operatorSignature.salt`.
require(
!operatorSaltIsSpent[operator][operatorSignature.salt],
SaltSpent()
);
require(!operatorSaltIsSpent[operator][operatorSignature.salt], SaltSpent());
// Assert `operator` is a registered operator.
require(
delegation.isOperator(operator),
OperatorNotRegistered()
);
require(delegation.isOperator(operator), OperatorNotRegistered());

// Calculate the digest hash
bytes32 operatorRegistrationDigestHash = calculateOperatorAVSRegistrationDigestHash({
Expand Down Expand Up @@ -115,15 +105,11 @@ contract AVSDirectory is
* @notice Called by an avs to deregister an operator with the avs.
* @param operator The address of the operator to deregister.
*/
function deregisterOperatorFromAVS(address operator)
external
onlyWhenNotPaused(PAUSED_OPERATOR_REGISTER_DEREGISTER_TO_AVS)
{
function deregisterOperatorFromAVS(
address operator
) external onlyWhenNotPaused(PAUSED_OPERATOR_REGISTER_DEREGISTER_TO_AVS) {
// Assert that operator is registered for the AVS.
require(
avsOperatorStatus[msg.sender][operator] == OperatorAVSRegistrationStatus.REGISTERED,
InvalidOperator()
);
require(avsOperatorStatus[msg.sender][operator] == OperatorAVSRegistrationStatus.REGISTERED, InvalidOperator());

// Set the operator as deregistered
avsOperatorStatus[msg.sender][operator] = OperatorAVSRegistrationStatus.UNREGISTERED;
Expand All @@ -135,15 +121,19 @@ contract AVSDirectory is
* @notice Called by an avs to emit an `AVSMetadataURIUpdated` event indicating the information has updated.
* @param metadataURI The URI for metadata associated with an avs
*/
function updateAVSMetadataURI(string calldata metadataURI) external {
function updateAVSMetadataURI(
string calldata metadataURI
) external {
emit AVSMetadataURIUpdated(msg.sender, metadataURI);
}

/**
* @notice Called by an operator to cancel a salt that has been used to register with an AVS.
* @param salt A unique and single use value associated with the approver signature.
*/
function cancelSalt(bytes32 salt) external {
function cancelSalt(
bytes32 salt
) external {
operatorSaltIsSpent[msg.sender][salt] = true;
}

Expand Down
4 changes: 3 additions & 1 deletion src/contracts/core/AVSDirectoryStorage.sol
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ abstract contract AVSDirectoryStorage is IAVSDirectory {
/// @dev Salt is used in the `registerOperatorToAVS` function.
mapping(address => mapping(bytes32 => bool)) public operatorSaltIsSpent;

constructor(IDelegationManager _delegation) {
constructor(
IDelegationManager _delegation
) {
delegation = _delegation;
}

Expand Down
111 changes: 52 additions & 59 deletions src/contracts/core/DelegationManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,9 @@ contract DelegationManager is
*
* @dev The caller must have previously registered as an operator in EigenLayer.
*/
function modifyOperatorDetails(OperatorDetails calldata newOperatorDetails) external {
function modifyOperatorDetails(
OperatorDetails calldata newOperatorDetails
) external {
require(isOperator(msg.sender), OperatorNotRegistered());
_setOperatorDetails(msg.sender, newOperatorDetails);
}
Expand All @@ -133,7 +135,9 @@ contract DelegationManager is
* @notice Called by an operator to emit an `OperatorMetadataURIUpdated` event indicating the information has updated.
* @param metadataURI The URI for metadata associated with an operator
*/
function updateOperatorMetadataURI(string calldata metadataURI) external {
function updateOperatorMetadataURI(
string calldata metadataURI
) external {
require(isOperator(msg.sender), OperatorNotRegistered());
emit OperatorMetadataURIUpdated(msg.sender, metadataURI);
}
Expand Down Expand Up @@ -187,14 +191,9 @@ contract DelegationManager is
bytes32 approverSalt
) external {
// check the signature expiry
require(
stakerSignatureAndExpiry.expiry >= block.timestamp,
SignatureExpired()
);
require(stakerSignatureAndExpiry.expiry >= block.timestamp, SignatureExpired());
require(!isDelegated(staker), ActivelyDelegated());
require(
isOperator(operator), OperatorNotRegistered()
);
require(isOperator(operator), OperatorNotRegistered());

// calculate the digest hash, then increment `staker`'s nonce
uint256 currentStakerNonce = stakerNonce[staker];
Expand All @@ -216,11 +215,9 @@ contract DelegationManager is
* a staker from their operator. Undelegation immediately removes ALL active shares/strategies from
* both the staker and operator, and places the shares and strategies in the withdrawal queue
*/
function undelegate(address staker)
external
onlyWhenNotPaused(PAUSED_ENTER_WITHDRAWAL_QUEUE)
returns (bytes32[] memory withdrawalRoots)
{
function undelegate(
address staker
) external onlyWhenNotPaused(PAUSED_ENTER_WITHDRAWAL_QUEUE) returns (bytes32[] memory withdrawalRoots) {
require(isDelegated(staker), NotActivelyDelegated());
require(!isOperator(staker), OperatorsCannotUndelegate());
require(staker != address(0), InputAddressZero());
Expand Down Expand Up @@ -275,11 +272,9 @@ contract DelegationManager is
*
* All withdrawn shares/strategies are placed in a queue and can be fully withdrawn after a delay.
*/
function queueWithdrawals(QueuedWithdrawalParams[] calldata queuedWithdrawalParams)
external
onlyWhenNotPaused(PAUSED_ENTER_WITHDRAWAL_QUEUE)
returns (bytes32[] memory)
{
function queueWithdrawals(
QueuedWithdrawalParams[] calldata queuedWithdrawalParams
) external onlyWhenNotPaused(PAUSED_ENTER_WITHDRAWAL_QUEUE) returns (bytes32[] memory) {
bytes32[] memory withdrawalRoots = new bytes32[](queuedWithdrawalParams.length);
address operator = delegatedTo[msg.sender];

Expand All @@ -288,10 +283,7 @@ contract DelegationManager is
queuedWithdrawalParams[i].strategies.length == queuedWithdrawalParams[i].shares.length,
InputArrayLengthMismatch()
);
require(
queuedWithdrawalParams[i].withdrawer == msg.sender,
WithdrawerNotStaker()
);
require(queuedWithdrawalParams[i].withdrawer == msg.sender, WithdrawerNotStaker());

// Remove shares from staker's strategies and place strategies/shares in queue.
// If the staker is delegated to an operator, the operator's delegated shares are also reduced
Expand Down Expand Up @@ -406,7 +398,9 @@ contract DelegationManager is
* @notice Owner-only function for modifying the value of the `minWithdrawalDelayBlocks` variable.
* @param newMinWithdrawalDelayBlocks new value of `minWithdrawalDelayBlocks`.
*/
function setMinWithdrawalDelayBlocks(uint256 newMinWithdrawalDelayBlocks) external onlyOwner {
function setMinWithdrawalDelayBlocks(
uint256 newMinWithdrawalDelayBlocks
) external onlyOwner {
_setMinWithdrawalDelayBlocks(newMinWithdrawalDelayBlocks);
}

Expand Down Expand Up @@ -476,15 +470,9 @@ contract DelegationManager is
*/
if (_delegationApprover != address(0) && msg.sender != _delegationApprover && msg.sender != operator) {
// check the signature expiry
require(
approverSignatureAndExpiry.expiry >= block.timestamp,
SignatureExpired()
);
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], SaltSpent());
delegationApproverSaltIsSpent[_delegationApprover][approverSalt] = true;

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

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

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

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

if (receiveAsTokens) {
require(
tokens.length == withdrawal.strategies.length,
InputArrayLengthMismatch()
);
require(tokens.length == withdrawal.strategies.length, InputArrayLengthMismatch());
}

// Remove `withdrawalRoot` from pending roots
Expand Down Expand Up @@ -663,9 +640,7 @@ contract DelegationManager is
IStrategy[] memory strategies,
uint256[] memory shares
) internal returns (bytes32) {
require(
staker != address(0), InputAddressZero()
);
require(staker != address(0), InputAddressZero());
require(strategies.length != 0, InputArrayLengthZero());

// Remove shares from staker and operator
Expand Down Expand Up @@ -746,7 +721,9 @@ contract DelegationManager is
}
}

function _setMinWithdrawalDelayBlocks(uint256 _minWithdrawalDelayBlocks) internal {
function _setMinWithdrawalDelayBlocks(
uint256 _minWithdrawalDelayBlocks
) internal {
require(
_minWithdrawalDelayBlocks <= MAX_WITHDRAWAL_DELAY_BLOCKS,
"DelegationManager._setMinWithdrawalDelayBlocks: _minWithdrawalDelayBlocks cannot be > MAX_WITHDRAWAL_DELAY_BLOCKS"
Expand Down Expand Up @@ -809,35 +786,45 @@ contract DelegationManager is
/**
* @notice Returns 'true' if `staker` *is* actively delegated, and 'false' otherwise.
*/
function isDelegated(address staker) public view returns (bool) {
function isDelegated(
address staker
) public view returns (bool) {
return (delegatedTo[staker] != address(0));
}

/**
* @notice Returns true is an operator has previously registered for delegation.
*/
function isOperator(address operator) public view returns (bool) {
function isOperator(
address operator
) public view returns (bool) {
return operator != address(0) && delegatedTo[operator] == operator;
}

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

/**
* @notice Returns the delegationApprover account for an operator
*/
function delegationApprover(address operator) external view returns (address) {
function delegationApprover(
address operator
) external view returns (address) {
return _operatorDetails[operator].delegationApprover;
}

/**
* @notice Returns the stakerOptOutWindowBlocks for an operator
*/
function stakerOptOutWindowBlocks(address operator) external view returns (uint256) {
function stakerOptOutWindowBlocks(
address operator
) external view returns (uint256) {
return _operatorDetails[operator].stakerOptOutWindowBlocks;
}

Expand All @@ -857,7 +844,9 @@ contract DelegationManager is
* @notice Returns the number of actively-delegatable shares a staker has across all strategies.
* @dev Returns two empty arrays in the case that the Staker has no actively-delegateable shares.
*/
function getDelegatableShares(address staker) public view returns (IStrategy[] memory, uint256[] memory) {
function getDelegatableShares(
address staker
) public view returns (IStrategy[] memory, uint256[] memory) {
// Get currently active shares and strategies for `staker`
int256 podShares = eigenPodManager.podOwnerShares(staker);
(IStrategy[] memory strategyManagerStrats, uint256[] memory strategyManagerShares) =
Expand Down Expand Up @@ -907,7 +896,9 @@ contract DelegationManager is
* from all the inputted strategies. Return value is >= minWithdrawalDelayBlocks as this is the global min withdrawal delay.
* @param strategies The strategies to check withdrawal delays for
*/
function getWithdrawalDelay(IStrategy[] calldata strategies) public view returns (uint256) {
function getWithdrawalDelay(
IStrategy[] calldata strategies
) public view returns (uint256) {
uint256 withdrawalDelay = minWithdrawalDelayBlocks;
for (uint256 i = 0; i < strategies.length; ++i) {
uint256 currWithdrawalDelay = strategyWithdrawalDelayBlocks[strategies[i]];
Expand All @@ -919,7 +910,9 @@ contract DelegationManager is
}

/// @notice Returns the keccak256 hash of `withdrawal`.
function calculateWithdrawalRoot(Withdrawal memory withdrawal) public pure returns (bytes32) {
function calculateWithdrawalRoot(
Withdrawal memory withdrawal
) public pure returns (bytes32) {
return keccak256(abi.encode(withdrawal));
}

Expand Down
Loading

0 comments on commit 94969be

Please sign in to comment.