forked from Layr-Labs/eigenlayer-middleware
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathIntegrationDeployer.t.sol
371 lines (329 loc) · 14.9 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
// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.12;
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/Slasher.sol";
import "eigenlayer-contracts/src/contracts/core/AVSDirectory.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/pods/DelayedWithdrawalRouter.sol";
import "eigenlayer-contracts/src/contracts/permissions/PauserRegistry.sol";
import "eigenlayer-contracts/src/test/mocks/ETHDepositMock.sol";
// import "eigenlayer-contracts/src/test/integration/mocks/BeaconChainOracleMock.t.sol";
import "test/integration/mocks/BeaconChainOracleMock.t.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";
// 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(HEVM_ADDRESS);
// Core contracts to deploy
DelegationManager delegationManager;
AVSDirectory public avsDirectory;
StrategyManager strategyManager;
EigenPodManager eigenPodManager;
PauserRegistry pauserRegistry;
Slasher slasher;
IBeacon eigenPodBeacon;
EigenPod pod;
DelayedWithdrawalRouter delayedWithdrawalRouter;
ETHPOSDepositMock ethPOSDeposit;
BeaconChainOracleMock beaconChainOracle;
// 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;
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"))));
// Constants/Defaults
uint64 constant MAX_RESTAKED_BALANCE_GWEI_PER_VALIDATOR = 32e9;
uint constant MIN_BALANCE = 1e6;
uint constant MAX_BALANCE = 5e6;
uint constant MAX_STRATEGY_COUNT = 32; // From StakeRegistry.MAX_WEIGHING_FUNCTION_LENGTH
uint96 constant DEFAULT_STRATEGY_MULTIPLIER = 1e18;
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();
beaconChainOracle = new BeaconChainOracleMock();
/**
* 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), ""))
);
slasher = Slasher(
address(new TransparentUpgradeableProxy(address(emptyContract), address(proxyAdmin), ""))
);
eigenPodManager = EigenPodManager(
address(new TransparentUpgradeableProxy(address(emptyContract), address(proxyAdmin), ""))
);
delayedWithdrawalRouter = DelayedWithdrawalRouter(
address(new TransparentUpgradeableProxy(address(emptyContract), address(proxyAdmin), ""))
);
avsDirectory = AVSDirectory(
address(new TransparentUpgradeableProxy(address(emptyContract), address(proxyAdmin), ""))
);
// Deploy EigenPod Contracts
pod = new EigenPod(
ethPOSDeposit,
delayedWithdrawalRouter,
eigenPodManager,
MAX_RESTAKED_BALANCE_GWEI_PER_VALIDATOR,
0
);
eigenPodBeacon = new UpgradeableBeacon(address(pod));
// Second, deploy the *implementation* contracts, using the *proxy contracts* as inputs
DelegationManager delegationImplementation = new DelegationManager(strategyManager, slasher, eigenPodManager);
StrategyManager strategyManagerImplementation = new StrategyManager(delegationManager, eigenPodManager, slasher);
Slasher slasherImplementation = new Slasher(strategyManager, delegationManager);
EigenPodManager eigenPodManagerImplementation = new EigenPodManager(
ethPOSDeposit,
eigenPodBeacon,
strategyManager,
slasher,
delegationManager
);
DelayedWithdrawalRouter delayedWithdrawalRouterImplementation = new DelayedWithdrawalRouter(eigenPodManager);
AVSDirectory avsDirectoryImplemntation = new AVSDirectory(delegationManager);
// 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
pauserRegistry,
0 /* initialPausedStatus */,
minWithdrawalDelayBlocks,
initializeStrategiesToSetDelayBlocks,
initializeWithdrawalDelayBlocks
)
);
// StrategyManager
proxyAdmin.upgradeAndCall(
TransparentUpgradeableProxy(payable(address(strategyManager))),
address(strategyManagerImplementation),
abi.encodeWithSelector(
StrategyManager.initialize.selector,
eigenLayerReputedMultisig, //initialOwner
eigenLayerReputedMultisig, //initial whitelister
pauserRegistry,
0 // initialPausedStatus
)
);
// Slasher
proxyAdmin.upgradeAndCall(
TransparentUpgradeableProxy(payable(address(slasher))),
address(slasherImplementation),
abi.encodeWithSelector(
Slasher.initialize.selector,
eigenLayerReputedMultisig,
pauserRegistry,
0 // initialPausedStatus
)
);
// EigenPodManager
proxyAdmin.upgradeAndCall(
TransparentUpgradeableProxy(payable(address(eigenPodManager))),
address(eigenPodManagerImplementation),
abi.encodeWithSelector(
EigenPodManager.initialize.selector,
address(beaconChainOracle),
eigenLayerReputedMultisig, // initialOwner
pauserRegistry,
0 // initialPausedStatus
)
);
// Delayed Withdrawal Router
proxyAdmin.upgradeAndCall(
TransparentUpgradeableProxy(payable(address(delayedWithdrawalRouter))),
address(delayedWithdrawalRouterImplementation),
abi.encodeWithSelector(
DelayedWithdrawalRouter.initialize.selector,
eigenLayerReputedMultisig, // initialOwner
pauserRegistry,
0, // initialPausedStatus
minWithdrawalDelayBlocks
)
);
// AVSDirectory
proxyAdmin.upgradeAndCall(
TransparentUpgradeableProxy(payable(address(avsDirectory))),
address(avsDirectoryImplemntation),
abi.encodeWithSelector(
AVSDirectory.initialize.selector,
eigenLayerReputedMultisig, // initialOwner
pauserRegistry,
0 // initialPausedStatus
)
);
// Deploy and whitelist strategies
baseStrategyImplementation = new StrategyBase(strategyManager);
for (uint i = 0; i < MAX_STRATEGY_COUNT; i++) {
string memory number = uint(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),
""
)
)
);
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(IRegistryCoordinator(registryCoordinator), IDelegationManager(delegationManager));
BLSApkRegistry blsApkRegistryImplementation = new BLSApkRegistry(IRegistryCoordinator(registryCoordinator));
IndexRegistry indexRegistryImplementation = new IndexRegistry(IRegistryCoordinator(registryCoordinator));
ServiceManagerMock serviceManagerImplementation = new ServiceManagerMock(IAVSDirectory(avsDirectory), IRegistryCoordinator(registryCoordinator), stakeRegistry);
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)
);
serviceManager.initialize({initialOwner: registryCoordinatorOwner});
RegistryCoordinator registryCoordinatorImplementation = new RegistryCoordinator(serviceManager, stakeRegistry, blsApkRegistry, indexRegistry);
proxyAdmin.upgradeAndCall(
TransparentUpgradeableProxy(payable(address(registryCoordinator))),
address(registryCoordinatorImplementation),
abi.encodeWithSelector(
RegistryCoordinator.initialize.selector,
registryCoordinatorOwner,
churnApprover,
ejector,
pauserRegistry,
0/*initialPausedStatus*/,
new IRegistryCoordinator.OperatorSetParam[](0),
new uint96[](0),
new IStakeRegistry.StrategyParams[][](0)
)
);
operatorStateRetriever = new OperatorStateRetriever();
}
/// @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, uint 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, thirdPartyTransfersForbiddenValues);
// Add to allStrats
allStrats.push(strategy);
allTokens.push(underlyingToken);
}
}