forked from Layr-Labs/eigenlayer-middleware
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathIntegrationDeployer.t.sol
536 lines (472 loc) · 21 KB
/
IntegrationDeployer.t.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
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
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.27;
import "forge-std/Test.sol";
// OpenZeppelin
import "@openzeppelin/contracts/token/ERC20/presets/ERC20PresetFixedSupply.sol";
import "@openzeppelin/contracts/proxy/transparent/ProxyAdmin.sol";
import "@openzeppelin/contracts/proxy/transparent/TransparentUpgradeableProxy.sol";
import "@openzeppelin/contracts/proxy/beacon/IBeacon.sol";
import "@openzeppelin/contracts/proxy/beacon/UpgradeableBeacon.sol";
import "@openzeppelin/contracts/utils/Strings.sol";
// Core contracts
import "eigenlayer-contracts/src/contracts/core/DelegationManager.sol";
import "eigenlayer-contracts/src/contracts/core/StrategyManager.sol";
import "eigenlayer-contracts/src/contracts/core/AVSDirectory.sol";
import "eigenlayer-contracts/src/contracts/core/RewardsCoordinator.sol";
import "eigenlayer-contracts/src/contracts/core/AllocationManager.sol";
import "eigenlayer-contracts/src/contracts/strategies/StrategyBase.sol";
import "eigenlayer-contracts/src/contracts/pods/EigenPodManager.sol";
import "eigenlayer-contracts/src/contracts/pods/EigenPod.sol";
import "eigenlayer-contracts/src/contracts/permissions/PauserRegistry.sol";
import "eigenlayer-contracts/src/contracts/permissions/PermissionController.sol";
import "eigenlayer-contracts/src/test/mocks/ETHDepositMock.sol";
// Middleware contracts
import "src/RegistryCoordinator.sol";
import "src/StakeRegistry.sol";
import "src/IndexRegistry.sol";
import "src/BLSApkRegistry.sol";
import "test/mocks/ServiceManagerMock.sol";
import "src/OperatorStateRetriever.sol";
import "src/SocketRegistry.sol";
// Mocks and More
import "src/libraries/BN254.sol";
import "src/libraries/BitmapUtils.sol";
import "eigenlayer-contracts/src/test/mocks/EmptyContract.sol";
// import "src/test/integration/mocks/ServiceManagerMock.t.sol";
import "test/integration/User.t.sol";
abstract contract IntegrationDeployer is Test, IUserDeployer {
using Strings for *;
Vm cheats = Vm(VM_ADDRESS);
// Core contracts to deploy
DelegationManager delegationManager;
AVSDirectory public avsDirectory;
StrategyManager strategyManager;
EigenPodManager eigenPodManager;
RewardsCoordinator rewardsCoordinator;
PauserRegistry pauserRegistry;
IBeacon eigenPodBeacon;
EigenPod pod;
ETHPOSDepositMock ethPOSDeposit;
AllocationManager allocationManager;
PermissionController permissionController;
// Base strategy implementation in case we want to create more strategies later
StrategyBase baseStrategyImplementation;
// Middleware contracts to deploy
RegistryCoordinator public registryCoordinator;
ServiceManagerMock serviceManager;
BLSApkRegistry blsApkRegistry;
StakeRegistry stakeRegistry;
IndexRegistry indexRegistry;
SocketRegistry socketRegistry;
OperatorStateRetriever operatorStateRetriever;
TimeMachine public timeMachine;
// Lists of strategies used in the system
IStrategy[] allStrats;
IERC20[] allTokens;
// ProxyAdmin
ProxyAdmin proxyAdmin;
// Admin Addresses
address eigenLayerReputedMultisig = address(this); // admin address
address constant pauser = address(555);
address constant unpauser = address(556);
address public registryCoordinatorOwner =
address(uint160(uint256(keccak256("registryCoordinatorOwner"))));
uint256 public churnApproverPrivateKey = uint256(keccak256("churnApproverPrivateKey"));
address public churnApprover = cheats.addr(churnApproverPrivateKey);
address ejector = address(uint160(uint256(keccak256("ejector"))));
address rewardsUpdater = address(uint160(uint256(keccak256("rewardsUpdater"))));
// Constants/Defaults
uint64 constant GENESIS_TIME_LOCAL = 1 hours * 12;
uint256 constant MIN_BALANCE = 1e6;
uint256 constant MAX_BALANCE = 5e6;
uint256 constant MAX_STRATEGY_COUNT = 32; // From StakeRegistry.MAX_WEIGHING_FUNCTION_LENGTH
uint96 constant DEFAULT_STRATEGY_MULTIPLIER = 1e18;
// RewardsCoordinator
// Config Variables
/// @notice intervals(epochs) are 1 weeks
uint32 CALCULATION_INTERVAL_SECONDS = 7 days;
/// @notice Max duration is 5 epochs (2 weeks * 5 = 10 weeks in seconds)
uint32 MAX_REWARDS_DURATION = 70 days;
/// @notice Lower bound start range is ~3 months into the past, multiple of CALCULATION_INTERVAL_SECONDS
uint32 MAX_RETROACTIVE_LENGTH = 84 days;
/// @notice Upper bound start range is ~1 month into the future, multiple of CALCULATION_INTERVAL_SECONDS
uint32 MAX_FUTURE_LENGTH = 28 days;
/// @notice absolute min timestamp that a rewards can start at
uint32 GENESIS_REWARDS_TIMESTAMP = 1712188800;
/// @notice Equivalent to 100%, but in basis points.
uint16 internal constant ONE_HUNDRED_IN_BIPS = 10000;
uint32 defaultOperatorSplitBips = 1000;
/// @notice Delay in timestamp before a posted root can be claimed against
uint32 activationDelay = 7 days;
/// @notice intervals(epochs) are 2 weeks
uint32 calculationIntervalSeconds = 14 days;
/// @notice the commission for all operators across all avss
uint16 globalCommissionBips = 1000;
function setUp() public virtual {
// Deploy ProxyAdmin
proxyAdmin = new ProxyAdmin();
// Deploy PauserRegistry
address[] memory pausers = new address[](1);
pausers[0] = pauser;
pauserRegistry = new PauserRegistry(pausers, unpauser);
// Deploy mocks
EmptyContract emptyContract = new EmptyContract();
ethPOSDeposit = new ETHPOSDepositMock();
/**
* First, deploy upgradeable proxy contracts that **will point** to the implementations. Since the implementation contracts are
* not yet deployed, we give these proxies an empty contract as the initial implementation, to act as if they have no code.
*/
delegationManager = DelegationManager(
address(
new TransparentUpgradeableProxy(address(emptyContract), address(proxyAdmin), "")
)
);
strategyManager = StrategyManager(
address(
new TransparentUpgradeableProxy(address(emptyContract), address(proxyAdmin), "")
)
);
eigenPodManager = EigenPodManager(
address(
new TransparentUpgradeableProxy(address(emptyContract), address(proxyAdmin), "")
)
);
avsDirectory = AVSDirectory(
address(
new TransparentUpgradeableProxy(address(emptyContract), address(proxyAdmin), "")
)
);
allocationManager = AllocationManager(
address(
new TransparentUpgradeableProxy(address(emptyContract), address(proxyAdmin), "")
)
);
permissionController = PermissionController(
address(
new TransparentUpgradeableProxy(address(emptyContract), address(proxyAdmin), "")
)
);
rewardsCoordinator = RewardsCoordinator(
address(
new TransparentUpgradeableProxy(address(emptyContract), address(proxyAdmin), "")
)
);
// Deploy EigenPod Contracts
pod = new EigenPod(ethPOSDeposit, eigenPodManager, GENESIS_TIME_LOCAL);
eigenPodBeacon = new UpgradeableBeacon(address(pod));
PermissionController permissionControllerImplementation = new PermissionController();
// Second, deploy the *implementation* contracts, using the *proxy contracts* as inputs
DelegationManager delegationImplementation = new DelegationManager(
strategyManager,
eigenPodManager,
allocationManager,
pauserRegistry,
permissionController,
0
);
StrategyManager strategyManagerImplementation =
new StrategyManager(delegationManager, pauserRegistry);
EigenPodManager eigenPodManagerImplementation =
new EigenPodManager(ethPOSDeposit, eigenPodBeacon, delegationManager, pauserRegistry);
AVSDirectory avsDirectoryImplementation =
new AVSDirectory(delegationManager, pauserRegistry);
RewardsCoordinator rewardsCoordinatorImplementation = new RewardsCoordinator(
delegationManager,
IStrategyManager(address(strategyManager)),
allocationManager,
pauserRegistry,
permissionController,
CALCULATION_INTERVAL_SECONDS,
MAX_REWARDS_DURATION,
MAX_RETROACTIVE_LENGTH,
MAX_FUTURE_LENGTH,
GENESIS_REWARDS_TIMESTAMP
);
AllocationManager allocationManagerImplementation = new AllocationManager(
delegationManager,
pauserRegistry,
permissionController,
uint32(7 days), // DEALLOCATION_DELAY
uint32(1 days) // ALLOCATION_CONFIGURATION_DELAY
);
// Third, upgrade the proxy contracts to point to the implementations
uint256 minWithdrawalDelayBlocks = 7 days / 12 seconds;
IStrategy[] memory initializeStrategiesToSetDelayBlocks = new IStrategy[](0);
uint256[] memory initializeWithdrawalDelayBlocks = new uint256[](0);
// DelegationManager
proxyAdmin.upgradeAndCall(
TransparentUpgradeableProxy(payable(address(delegationManager))),
address(delegationImplementation),
abi.encodeWithSelector(
DelegationManager.initialize.selector,
eigenLayerReputedMultisig, // initialOwner
0 /* initialPausedStatus */
)
);
// StrategyManager
proxyAdmin.upgradeAndCall(
TransparentUpgradeableProxy(payable(address(strategyManager))),
address(strategyManagerImplementation),
abi.encodeWithSelector(
StrategyManager.initialize.selector,
eigenLayerReputedMultisig, //initialOwner
eigenLayerReputedMultisig, //initial whitelister
0 // initialPausedStatus
)
);
// EigenPodManager
proxyAdmin.upgradeAndCall(
TransparentUpgradeableProxy(payable(address(eigenPodManager))),
address(eigenPodManagerImplementation),
abi.encodeWithSelector(
EigenPodManager.initialize.selector,
eigenLayerReputedMultisig, // initialOwner
0 // initialPausedStatus
)
);
// AVSDirectory
proxyAdmin.upgradeAndCall(
TransparentUpgradeableProxy(payable(address(avsDirectory))),
address(avsDirectoryImplementation),
abi.encodeWithSelector(
AVSDirectory.initialize.selector,
eigenLayerReputedMultisig, // initialOwner
// pauserRegistry,
0 // initialPausedStatus
)
);
proxyAdmin.upgrade(
TransparentUpgradeableProxy(payable(address(permissionController))),
address(permissionControllerImplementation)
);
proxyAdmin.upgradeAndCall(
TransparentUpgradeableProxy(payable(address(rewardsCoordinator))),
address(rewardsCoordinatorImplementation),
abi.encodeWithSelector(
RewardsCoordinator.initialize.selector,
eigenLayerReputedMultisig, // initialOwner
0, // initialPausedStatus
rewardsUpdater,
activationDelay,
defaultOperatorSplitBips // defaultSplitBips
)
);
proxyAdmin.upgradeAndCall(
TransparentUpgradeableProxy(payable(address(allocationManager))),
address(allocationManagerImplementation),
abi.encodeWithSelector(
AllocationManager.initialize.selector,
eigenLayerReputedMultisig, // initialOwner
0 // initialPausedStatus
)
);
// Deploy and whitelist strategies
baseStrategyImplementation = new StrategyBase(strategyManager, pauserRegistry);
for (uint256 i = 0; i < MAX_STRATEGY_COUNT; i++) {
string memory number = uint256(i).toString();
string memory stratName = string.concat("StrategyToken", number);
string memory stratSymbol = string.concat("STT", number);
_newStrategyAndToken(stratName, stratSymbol, 10e50, address(this));
}
// wibbly-wobbly timey-wimey shenanigans
timeMachine = new TimeMachine();
cheats.startPrank(registryCoordinatorOwner);
registryCoordinator = RegistryCoordinator(
address(
new TransparentUpgradeableProxy(address(emptyContract), address(proxyAdmin), "")
)
);
stakeRegistry = StakeRegistry(
address(
new TransparentUpgradeableProxy(address(emptyContract), address(proxyAdmin), "")
)
);
socketRegistry = SocketRegistry(
address(
new TransparentUpgradeableProxy(address(emptyContract), address(proxyAdmin), "")
)
);
indexRegistry = IndexRegistry(
address(
new TransparentUpgradeableProxy(address(emptyContract), address(proxyAdmin), "")
)
);
blsApkRegistry = BLSApkRegistry(
address(
new TransparentUpgradeableProxy(address(emptyContract), address(proxyAdmin), "")
)
);
serviceManager = ServiceManagerMock(
address(
new TransparentUpgradeableProxy(address(emptyContract), address(proxyAdmin), "")
)
);
cheats.stopPrank();
StakeRegistry stakeRegistryImplementation = new StakeRegistry(
ISlashingRegistryCoordinator(registryCoordinator),
IDelegationManager(delegationManager),
IAVSDirectory(avsDirectory),
allocationManager
);
BLSApkRegistry blsApkRegistryImplementation =
new BLSApkRegistry(ISlashingRegistryCoordinator(registryCoordinator));
IndexRegistry indexRegistryImplementation =
new IndexRegistry(ISlashingRegistryCoordinator(registryCoordinator));
ServiceManagerMock serviceManagerImplementation = new ServiceManagerMock(
IAVSDirectory(avsDirectory),
rewardsCoordinator,
ISlashingRegistryCoordinator(registryCoordinator),
stakeRegistry,
permissionController,
allocationManager
);
SocketRegistry socketRegistryImplementation =
new SocketRegistry(IRegistryCoordinator(registryCoordinator));
proxyAdmin.upgrade(
TransparentUpgradeableProxy(payable(address(stakeRegistry))),
address(stakeRegistryImplementation)
);
proxyAdmin.upgrade(
TransparentUpgradeableProxy(payable(address(blsApkRegistry))),
address(blsApkRegistryImplementation)
);
proxyAdmin.upgrade(
TransparentUpgradeableProxy(payable(address(indexRegistry))),
address(indexRegistryImplementation)
);
proxyAdmin.upgrade(
TransparentUpgradeableProxy(payable(address(serviceManager))),
address(serviceManagerImplementation)
);
proxyAdmin.upgrade(
TransparentUpgradeableProxy(payable(address(socketRegistry))),
address(socketRegistryImplementation)
);
serviceManager.initialize({
initialOwner: registryCoordinatorOwner,
rewardsInitiator: address(msg.sender)
});
IStakeRegistryTypes.StakeType[] memory quorumStakeTypes =
new IStakeRegistryTypes.StakeType[](0);
uint32[] memory slashableStakeQuorumLookAheadPeriods = new uint32[](0);
RegistryCoordinator registryCoordinatorImplementation = new RegistryCoordinator(
serviceManager,
stakeRegistry,
blsApkRegistry,
indexRegistry,
socketRegistry,
allocationManager,
pauserRegistry
);
proxyAdmin.upgradeAndCall(
TransparentUpgradeableProxy(payable(address(registryCoordinator))),
address(registryCoordinatorImplementation),
abi.encodeWithSelector(
SlashingRegistryCoordinator.initialize.selector,
registryCoordinatorOwner,
churnApprover,
ejector,
0, /*initialPausedStatus*/
new IRegistryCoordinator.OperatorSetParam[](0),
new uint96[](0),
new IStakeRegistryTypes.StrategyParams[][](0),
quorumStakeTypes,
slashableStakeQuorumLookAheadPeriods
)
);
operatorStateRetriever = new OperatorStateRetriever();
// Setup UAM Permissions
cheats.startPrank(serviceManager.owner());
// 1. set AVS registrar
serviceManager.setAppointee({
appointee: serviceManager.owner(),
target: address(allocationManager),
selector: IAllocationManager.setAVSRegistrar.selector
});
// 2. create operator sets
serviceManager.setAppointee({
appointee: address(registryCoordinator),
target: address(allocationManager),
selector: IAllocationManager.createOperatorSets.selector
});
// 3. deregister operator from operator sets
serviceManager.setAppointee({
appointee: address(registryCoordinator),
target: address(allocationManager),
selector: IAllocationManager.deregisterFromOperatorSets.selector
});
// 4. add strategies to operator sets
serviceManager.setAppointee({
appointee: address(registryCoordinator),
target: address(stakeRegistry),
selector: IAllocationManager.addStrategiesToOperatorSet.selector
});
// 5. remove strategies from operator sets
serviceManager.setAppointee({
appointee: address(registryCoordinator),
target: address(stakeRegistry),
selector: IAllocationManager.removeStrategiesFromOperatorSet.selector
});
cheats.stopPrank();
_setOperatorSetsEnabled(false);
_setM2QuorumsDisabled(false);
}
/// @notice Overwrite RegistryCoordinator.operatorSetsEnabled to the specified value.
/// This is to enable testing of RegistryCoordinator in non-operator set mode.
function _setOperatorSetsEnabled(
bool operatorSetsEnabled
) internal {
// 1. First read the current value of the entire slot
// which holds operatorSetsEnabled, m2QuorumsDisabled, and accountIdentifier
bytes32 currentSlot = cheats.load(address(registryCoordinator), bytes32(uint256(161)));
// 2. Clear only the first byte (operatorSetsEnabled) while keeping the rest
bytes32 newSlot = (currentSlot & ~bytes32(uint256(0xff)))
| bytes32(uint256(operatorSetsEnabled ? 0x01 : 0x00));
// 3. Store the modified slot
cheats.store(address(registryCoordinator), bytes32(uint256(161)), newSlot);
}
/// @notice Overwrite RegistryCoordinator.m2QuorumsDisabled to the specified value.
function _setM2QuorumsDisabled(
bool m2QuorumsDisabled
) internal {
// 1. First read the current value of the entire slot
// which holds operatorSetsEnabled, m2QuorumsDisabled, and accountIdentifier
bytes32 currentSlot = cheats.load(address(registryCoordinator), bytes32(uint256(161)));
// 2. Clear only the second byte (m2QuorumsDisabled) while keeping the rest
bytes32 newSlot = (currentSlot & ~bytes32(uint256(0xff) << 8))
| bytes32(uint256(m2QuorumsDisabled ? 0x01 : 0x00) << 8);
// 3. Store the modified slot
cheats.store(address(registryCoordinator), bytes32(uint256(161)), newSlot);
}
/// @dev Deploy a strategy and its underlying token, push to global lists of tokens/strategies, and whitelist
/// strategy in strategyManager
function _newStrategyAndToken(
string memory tokenName,
string memory tokenSymbol,
uint256 initialSupply,
address owner
) internal {
IERC20 underlyingToken =
new ERC20PresetFixedSupply(tokenName, tokenSymbol, initialSupply, owner);
StrategyBase strategy = StrategyBase(
address(
new TransparentUpgradeableProxy(
address(baseStrategyImplementation),
address(proxyAdmin),
abi.encodeWithSelector(
StrategyBase.initialize.selector, underlyingToken, pauserRegistry
)
)
)
);
// Whitelist strategy
IStrategy[] memory strategies = new IStrategy[](1);
bool[] memory thirdPartyTransfersForbiddenValues = new bool[](1);
strategies[0] = strategy;
cheats.prank(strategyManager.strategyWhitelister());
strategyManager.addStrategiesToDepositWhitelist(strategies);
// Add to allStrats
allStrats.push(strategy);
allTokens.push(underlyingToken);
}
}