1+ // SPDX-License-Identifier: MIT
2+ pragma solidity ^ 0.8.22 ;
3+
4+ import "forge-std/Script.sol " ;
5+ import {KeyperSet} from "../src/common/KeyperSet.sol " ;
6+ import {KeyperSetManager} from "../src/common/KeyperSetManager.sol " ;
7+ import {KeyBroadcastContract} from "../src/common/KeyBroadcastContract.sol " ;
8+ import {EonKeyPublish} from "../src/common/EonKeyPublish.sol " ;
9+
10+ error ActivationDeltaTooLow ();
11+ error ActivationBlockNumberTooLow ();
12+ error ActivationBlockSmallerThanCurrentBlock ();
13+ error ThresholdExceedsKeyperSetSize (uint256 threshold , uint256 keyperSetSize );
14+ error UnexpectedKeyperSet (
15+ uint256 index ,
16+ address expectedKeyperSet ,
17+ address actualKeyperSet
18+ );
19+
20+ contract AddKeyperSetWithActivationBlock is Script {
21+ function run () public {
22+ uint256 deployerPrivateKey = vm.envUint ("PRIVATE_KEY " );
23+ address deployerAddress = vm.addr (deployerPrivateKey);
24+ console.log ("deployer: " , deployerAddress);
25+ vm.startBroadcast (deployerPrivateKey);
26+
27+ uint256 activationBlockNumber = vm.envOr ("ACTIVATION_BLOCK_NUMBER " , uint256 (1 ));
28+ if (activationBlockNumber <= 1 ) {
29+ revert ActivationBlockNumberTooLow ();
30+ }
31+
32+ if (activationBlockNumber < block .number ) {
33+ revert ActivationBlockSmallerThanCurrentBlock ();
34+ }
35+
36+
37+ address keyperSetManagerAddress = vm.envAddress (
38+ "KEYPERSETMANAGER_ADDRESS "
39+ );
40+ KeyperSetManager keyperSetManager = KeyperSetManager (
41+ keyperSetManagerAddress
42+ );
43+
44+ address keyBroadcastContractAddress = vm.envAddress (
45+ "KEYBROADCAST_ADDRESS "
46+ );
47+ KeyBroadcastContract keyBroadcastContract = KeyBroadcastContract (
48+ keyBroadcastContractAddress
49+ );
50+
51+ address [] memory keypers = vm.envAddress ("KEYPER_ADDRESSES " , ", " );
52+ uint256 threshold = vm.envUint ("THRESHOLD " );
53+ if (threshold > keypers.length ) {
54+ revert ThresholdExceedsKeyperSetSize (threshold, keypers.length );
55+ }
56+
57+ uint64 keyperSetIndex = keyperSetManager.getNumKeyperSets ();
58+ KeyperSet keyperSet = new KeyperSet ();
59+ EonKeyPublish eonKeyPublish = new EonKeyPublish (
60+ address (keyperSet),
61+ address (keyBroadcastContract),
62+ keyperSetIndex
63+ );
64+ keyperSet.addMembers (keypers);
65+ keyperSet.setThreshold (uint64 (threshold));
66+ keyperSet.setPublisher (address (eonKeyPublish));
67+ keyperSet.setFinalized ();
68+ console.log ("keyperSet: " , address (keyperSet));
69+ console.log ("eonKeyPublish: " , address (eonKeyPublish));
70+
71+ keyperSetManager.addKeyperSet (uint64 (activationBlockNumber), address (keyperSet));
72+ console.log ("activationBlock: " , activationBlockNumber);
73+ console.log ("keyperSetIndex: " , keyperSetIndex);
74+
75+ address actualKeyperSet = keyperSetManager.getKeyperSetAddress (
76+ keyperSetIndex
77+ );
78+ if (actualKeyperSet != address (keyperSet)) {
79+ revert UnexpectedKeyperSet (
80+ keyperSetIndex,
81+ address (keyperSet),
82+ actualKeyperSet
83+ );
84+ }
85+
86+ vm.stopBroadcast ();
87+ }
88+ }
0 commit comments