-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathDeployAVS.s.sol
More file actions
302 lines (253 loc) · 13.7 KB
/
DeployAVS.s.sol
File metadata and controls
302 lines (253 loc) · 13.7 KB
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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.12;
import {ProxyAdmin} from "@openzeppelin/contracts/proxy/transparent/ProxyAdmin.sol";
import {TransparentUpgradeableProxy} from "@openzeppelin/contracts/proxy/transparent/TransparentUpgradeableProxy.sol";
import {ITransparentUpgradeableProxy} from "@openzeppelin/contracts/proxy/transparent/TransparentUpgradeableProxy.sol";
import {PauserRegistry} from "eigenlayer-core/contracts/permissions/PauserRegistry.sol";
import {EmptyContract} from "eigenlayer-core/test/mocks/EmptyContract.sol";
import {IDelegationManager} from "eigenlayer-core/contracts/interfaces/IDelegationManager.sol";
import {IAVSDirectory} from "eigenlayer-core/contracts/interfaces/IAVSDirectory.sol";
import {IRewardsCoordinator} from "eigenlayer-core/contracts/interfaces/IRewardsCoordinator.sol";
import {IAllocationManager} from "eigenlayer-core/contracts/interfaces/IAllocationManager.sol";
import {IAVSRegistrar} from "eigenlayer-core/contracts/interfaces/IAVSRegistrar.sol";
import {IPermissionController} from "eigenlayer-core/contracts/interfaces/IPermissionController.sol";
import {BLSApkRegistry} from "eigenlayer-middleware/BLSApkRegistry.sol";
import {SlashingRegistryCoordinator} from "eigenlayer-middleware/SlashingRegistryCoordinator.sol";
import {OperatorStateRetriever} from "eigenlayer-middleware/OperatorStateRetriever.sol";
import {IRegistryCoordinator} from "eigenlayer-middleware/interfaces/IRegistryCoordinator.sol";
import {IndexRegistry} from "eigenlayer-middleware/IndexRegistry.sol";
import {IIndexRegistry} from "eigenlayer-middleware/interfaces/IIndexRegistry.sol";
import {StakeRegistry, IStrategy} from "eigenlayer-middleware/StakeRegistry.sol";
import {IStakeRegistry, IStakeRegistryTypes} from "eigenlayer-middleware/interfaces/IStakeRegistry.sol";
import {IServiceManager} from "eigenlayer-middleware/interfaces/IServiceManager.sol";
import {IBLSApkRegistry} from "eigenlayer-middleware/interfaces/IBLSApkRegistry.sol";
import {ServiceManagerBase} from "eigenlayer-middleware/ServiceManagerBase.sol";
import {ISocketRegistry, SocketRegistry} from "eigenlayer-middleware/SocketRegistry.sol";
import {IPauserRegistry} from "eigenlayer-core/contracts/interfaces/IPauserRegistry.sol";
import {ISlashingRegistryCoordinator, ISlashingRegistryCoordinatorTypes} from "eigenlayer-middleware/interfaces/ISlashingRegistryCoordinator.sol";
import {MinimalServiceManager} from "../src/MinimalServiceManager.sol";
import {MinimalCertificateVerifier} from "../src/MinimalCertificateVerifier.sol";
import "forge-std/Test.sol";
import "forge-std/Script.sol";
import "forge-std/StdJson.sol";
contract DeployAVS is Script, Test {
// Core contracts
ProxyAdmin public avsProxyAdmin;
PauserRegistry public avsPauserReg;
EmptyContract public emptyContract;
// Middleware contracts
BLSApkRegistry public apkRegistry;
IServiceManager public serviceManager;
MinimalCertificateVerifier public certificateVerifier;
SlashingRegistryCoordinator public slashingRegistryCoordinator;
IIndexRegistry public indexRegistry;
IStakeRegistry public stakeRegistry;
ISocketRegistry public socketRegistry;
OperatorStateRetriever public operatorStateRetriever;
// Implementation contracts
BLSApkRegistry public apkRegistryImplementation;
IServiceManager public serviceManagerImplementation;
MinimalCertificateVerifier public certificateVerifierImplementation;
ISlashingRegistryCoordinator public slashingRegistryCoordinatorImplementation;
IIndexRegistry public indexRegistryImplementation;
IStakeRegistry public stakeRegistryImplementation;
ISocketRegistry public socketRegistryImplementation;
struct EigenlayerDeployment {
address allocationManager;
address delegationManager;
address permissionController;
address rewardsCoordinator;
address avsDirectory;
}
function run(
string memory inputConfigPath,
uint256 maxOperatorCount,
IStrategy[] memory strategies
) external {
// read the json file
string memory inputConfig = vm.readFile(inputConfigPath);
EigenlayerDeployment memory eigenlayerDeployment = EigenlayerDeployment({
allocationManager: stdJson.readAddress(inputConfig, ".allocationManager"),
delegationManager: stdJson.readAddress(inputConfig, ".delegationManager"),
permissionController: stdJson.readAddress(inputConfig, ".permissionController"),
rewardsCoordinator: stdJson.readAddress(inputConfig, ".rewardsCoordinator"),
avsDirectory: stdJson.readAddress(inputConfig, ".avsDirectory")
});
emit log_named_address("allocation manager", eigenlayerDeployment.allocationManager);
emit log_named_address("delegation manager", eigenlayerDeployment.delegationManager);
emit log_named_address("permission controller", eigenlayerDeployment.permissionController);
emit log_named_address("rewards coordinator", eigenlayerDeployment.rewardsCoordinator);
emit log_named_address("avs directory", eigenlayerDeployment.avsDirectory);
// only a lower bound for the deployment block number
uint256 deploymentBlock = block.number;
vm.startBroadcast();
// deploy proxy admin for ability to upgrade proxy contracts
avsProxyAdmin = new ProxyAdmin();
// deploy pauser registry
{
address[] memory pausers = new address[](1);
pausers[0] = msg.sender;
avsPauserReg = new PauserRegistry(pausers, msg.sender);
}
emptyContract = new EmptyContract();
// Deploy upgradeable proxy contracts pointing to empty contract initially
serviceManager = ServiceManagerBase(
address(new TransparentUpgradeableProxy(address(emptyContract), address(avsProxyAdmin), ""))
);
certificateVerifier = MinimalCertificateVerifier(
address(new TransparentUpgradeableProxy(address(emptyContract), address(avsProxyAdmin), ""))
);
slashingRegistryCoordinator = SlashingRegistryCoordinator(
address(new TransparentUpgradeableProxy(address(emptyContract), address(avsProxyAdmin), ""))
);
indexRegistry = IIndexRegistry(
address(new TransparentUpgradeableProxy(address(emptyContract), address(avsProxyAdmin), ""))
);
stakeRegistry = IStakeRegistry(
address(new TransparentUpgradeableProxy(address(emptyContract), address(avsProxyAdmin), ""))
);
apkRegistry = BLSApkRegistry(
address(new TransparentUpgradeableProxy(address(emptyContract), address(avsProxyAdmin), ""))
);
socketRegistry = ISocketRegistry(
address(new TransparentUpgradeableProxy(address(emptyContract), address(avsProxyAdmin), ""))
);
// Deploy implementations and upgrade proxies
indexRegistryImplementation = new IndexRegistry(
slashingRegistryCoordinator
);
avsProxyAdmin.upgrade(
ITransparentUpgradeableProxy(payable(address(indexRegistry))),
address(indexRegistryImplementation)
);
stakeRegistryImplementation = new StakeRegistry(
slashingRegistryCoordinator,
IDelegationManager(eigenlayerDeployment.delegationManager),
IAVSDirectory(eigenlayerDeployment.avsDirectory),
IAllocationManager(address(0))
);
avsProxyAdmin.upgrade(
ITransparentUpgradeableProxy(payable(address(stakeRegistry))),
address(stakeRegistryImplementation)
);
apkRegistryImplementation = new BLSApkRegistry(
slashingRegistryCoordinator
);
avsProxyAdmin.upgrade(
ITransparentUpgradeableProxy(payable(address(apkRegistry))),
address(apkRegistryImplementation)
);
socketRegistryImplementation = new SocketRegistry(slashingRegistryCoordinator);
avsProxyAdmin.upgrade(
ITransparentUpgradeableProxy(payable(address(socketRegistry))),
address(socketRegistryImplementation)
);
serviceManagerImplementation = new MinimalServiceManager(
IAVSDirectory(eigenlayerDeployment.avsDirectory),
IRewardsCoordinator(eigenlayerDeployment.rewardsCoordinator),
slashingRegistryCoordinator,
stakeRegistry,
IPermissionController(address(eigenlayerDeployment.permissionController)),
IAllocationManager(eigenlayerDeployment.allocationManager)
);
// Initialize ServiceManagerBase
avsProxyAdmin.upgradeAndCall(
ITransparentUpgradeableProxy(payable(address(serviceManager))),
address(serviceManagerImplementation),
abi.encodeWithSelector(
MinimalServiceManager.initialize.selector,
msg.sender,
msg.sender
)
);
slashingRegistryCoordinatorImplementation = new SlashingRegistryCoordinator(
stakeRegistry,
apkRegistry,
indexRegistry,
socketRegistry,
IAllocationManager(eigenlayerDeployment.allocationManager),
avsPauserReg
);
{
ISlashingRegistryCoordinatorTypes.OperatorSetParam[] memory operatorSetParams = new ISlashingRegistryCoordinatorTypes.OperatorSetParam[](strategies.length);
for (uint i = 0; i < strategies.length; i++) {
operatorSetParams[i] = ISlashingRegistryCoordinatorTypes.OperatorSetParam({
maxOperatorCount: uint32(maxOperatorCount),
kickBIPsOfOperatorStake: 11000,
kickBIPsOfTotalStake: 1001
});
}
uint96[] memory minimumStakeForQuourm = new uint96[](strategies.length);
for (uint i = 0; i < strategies.length; i++) {
minimumStakeForQuourm[i] = 1;
}
IStakeRegistryTypes.StrategyParams[][] memory strategyAndWeightingMultipliers = new IStakeRegistryTypes.StrategyParams[][](strategies.length);
for (uint i = 0; i < strategies.length; i++) {
strategyAndWeightingMultipliers[i] = new IStakeRegistryTypes.StrategyParams[](1);
strategyAndWeightingMultipliers[i][0] = IStakeRegistryTypes.StrategyParams({
strategy: strategies[i],
multiplier: 1 ether
});
}
avsProxyAdmin.upgradeAndCall(
ITransparentUpgradeableProxy(payable(address(slashingRegistryCoordinator))),
address(slashingRegistryCoordinatorImplementation),
abi.encodeWithSelector(
SlashingRegistryCoordinator.initialize.selector,
msg.sender, // initial owner
msg.sender, // churn approver
msg.sender, // ejector
0, // initial paused status
address(serviceManager) // accountIdentifier
)
);
// set AVS Registrar on AllocationManager to SlashingRegistryCoordinator
serviceManager.setAppointee(
msg.sender,
eigenlayerDeployment.allocationManager,
IAllocationManager(eigenlayerDeployment.allocationManager).setAVSRegistrar.selector
);
IAllocationManager(eigenlayerDeployment.allocationManager).setAVSRegistrar(
address(serviceManager),
IAVSRegistrar(slashingRegistryCoordinator)
);
// give slashingregistrycoordindator permission to createTotalDelegatedStakeQuorum
serviceManager.setAppointee(
address(slashingRegistryCoordinator),
eigenlayerDeployment.allocationManager,
IAllocationManager(eigenlayerDeployment.allocationManager).createOperatorSets.selector
);
for (uint i = 0; i < strategies.length; i++) {
slashingRegistryCoordinator.createTotalDelegatedStakeQuorum(
operatorSetParams[i],
minimumStakeForQuourm[i],
strategyAndWeightingMultipliers[i]
);
}
}
certificateVerifierImplementation = new MinimalCertificateVerifier(
slashingRegistryCoordinator
);
avsProxyAdmin.upgrade(
ITransparentUpgradeableProxy(payable(address(certificateVerifier))),
address(certificateVerifierImplementation)
);
operatorStateRetriever = new OperatorStateRetriever();
vm.stopBroadcast();
string memory output = "deployment";
vm.serializeAddress(output, "serviceManager", address(serviceManager));
vm.serializeAddress(output, "certificateVerifier", address(certificateVerifier));
vm.serializeAddress(output, "slashingRegistryCoordinator", address(slashingRegistryCoordinator));
vm.serializeAddress(output, "indexRegistry", address(indexRegistry));
vm.serializeAddress(output, "stakeRegistry", address(stakeRegistry));
vm.serializeAddress(output, "apkRegistry", address(apkRegistry));
vm.serializeAddress(output, "socketRegistry", address(socketRegistry));
vm.serializeAddress(output, "operatorStateRetriever", address(operatorStateRetriever));
vm.serializeAddress(output, "avsProxyAdmin", address(avsProxyAdmin));
vm.serializeAddress(output, "avsPauserReg", address(avsPauserReg));
vm.serializeUint(output, "deploymentBlock", deploymentBlock);
string memory finalJson = vm.serializeString(output, "object", output);
vm.createDir("./script/output", true);
vm.writeJson(finalJson, "./script/output/avs_deploy_output.json");
}
}