-
Notifications
You must be signed in to change notification settings - Fork 359
/
Copy pathAVSDirectory.sol
142 lines (121 loc) · 4.67 KB
/
AVSDirectory.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.27;
import "@openzeppelin-upgrades/contracts/proxy/utils/Initializable.sol";
import "@openzeppelin-upgrades/contracts/access/OwnableUpgradeable.sol";
import "@openzeppelin-upgrades/contracts/security/ReentrancyGuardUpgradeable.sol";
import "../mixins/SignatureUtils.sol";
import "../permissions/Pausable.sol";
import "./AVSDirectoryStorage.sol";
contract AVSDirectory is
Initializable,
OwnableUpgradeable,
Pausable,
AVSDirectoryStorage,
ReentrancyGuardUpgradeable,
SignatureUtils
{
/**
*
* INITIALIZING FUNCTIONS
*
*/
/**
* @dev Initializes the immutable addresses of the strategy mananger, delegationManager,
* and eigenpodManager contracts
*/
constructor(
IDelegationManager _delegation,
IPauserRegistry _pauserRegistry
) AVSDirectoryStorage(_delegation) Pausable(_pauserRegistry) {
_disableInitializers();
}
/// @inheritdoc IAVSDirectory
function initialize(address initialOwner, uint256 initialPausedStatus) external initializer {
_setPausedStatus(initialPausedStatus);
_transferOwnership(initialOwner);
}
/**
*
* EXTERNAL FUNCTIONS
*
*/
/// @inheritdoc IAVSDirectory
function updateAVSMetadataURI(
string calldata metadataURI
) external override {
emit AVSMetadataURIUpdated(msg.sender, metadataURI);
}
/// @inheritdoc IAVSDirectory
function cancelSalt(
bytes32 salt
) external override {
// Mutate `operatorSaltIsSpent` to `true` to prevent future spending.
operatorSaltIsSpent[msg.sender][salt] = true;
}
/**
*
* LEGACY EXTERNAL FUNCTIONS - SUPPORT DEPRECATED IN FUTURE RELEASE AFTER SLASHING RELEASE
*
*/
/// @inheritdoc IAVSDirectory
function registerOperatorToAVS(
address operator,
ISignatureUtils.SignatureWithSaltAndExpiry memory operatorSignature
) external override onlyWhenNotPaused(PAUSED_OPERATOR_REGISTER_DEREGISTER_TO_AVS) {
// Assert that the `operator` is not actively registered to the AVS.
require(
avsOperatorStatus[msg.sender][operator] != OperatorAVSRegistrationStatus.REGISTERED,
OperatorAlreadyRegisteredToAVS()
);
// Assert `operator` has not already spent `operatorSignature.salt`.
require(!operatorSaltIsSpent[operator][operatorSignature.salt], SaltSpent());
// Assert `operator` is a registered operator.
require(delegation.isOperator(operator), OperatorNotRegisteredToEigenLayer());
// Assert that `operatorSignature.signature` is a valid signature for the operator AVS registration.
_checkIsValidSignatureNow({
signer: operator,
signableDigest: calculateOperatorAVSRegistrationDigestHash({
operator: operator,
avs: msg.sender,
salt: operatorSignature.salt,
expiry: operatorSignature.expiry
}),
signature: operatorSignature.signature,
expiry: operatorSignature.expiry
});
// Mutate `operatorSaltIsSpent` to `true` to prevent future respending.
operatorSaltIsSpent[operator][operatorSignature.salt] = true;
// Set the operator as registered
avsOperatorStatus[msg.sender][operator] = OperatorAVSRegistrationStatus.REGISTERED;
emit OperatorAVSRegistrationStatusUpdated(operator, msg.sender, OperatorAVSRegistrationStatus.REGISTERED);
}
/// @inheritdoc IAVSDirectory
function deregisterOperatorFromAVS(
address operator
) external override onlyWhenNotPaused(PAUSED_OPERATOR_REGISTER_DEREGISTER_TO_AVS) {
// Assert that operator is registered for the AVS.
require(
avsOperatorStatus[msg.sender][operator] == OperatorAVSRegistrationStatus.REGISTERED,
OperatorNotRegisteredToAVS()
);
// Set the operator as deregistered
avsOperatorStatus[msg.sender][operator] = OperatorAVSRegistrationStatus.UNREGISTERED;
emit OperatorAVSRegistrationStatusUpdated(operator, msg.sender, OperatorAVSRegistrationStatus.UNREGISTERED);
}
/**
*
* VIEW FUNCTIONS
*
*/
/// @inheritdoc IAVSDirectory
function calculateOperatorAVSRegistrationDigestHash(
address operator,
address avs,
bytes32 salt,
uint256 expiry
) public view override returns (bytes32) {
return _calculateSignableDigest(
keccak256(abi.encode(OPERATOR_AVS_REGISTRATION_TYPEHASH, operator, avs, salt, expiry))
);
}
}