-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAddKeyperSet.gnosh.s.sol
More file actions
87 lines (75 loc) · 3.05 KB
/
Copy pathAddKeyperSet.gnosh.s.sol
File metadata and controls
87 lines (75 loc) · 3.05 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
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.22;
import "forge-std/Script.sol";
import {KeyperSet} from "../src/common/KeyperSet.sol";
import {KeyperSetManager} from "../src/common/KeyperSetManager.sol";
import {KeyBroadcastContract} from "../src/common/KeyBroadcastContract.sol";
import {EonKeyPublish} from "../src/common/EonKeyPublish.sol";
error ActivationDeltaTooLow();
error ThresholdExceedsKeyperSetSize(uint256 threshold, uint256 keyperSetSize);
error UnexpectedKeyperSet(
uint256 index,
address expectedKeyperSet,
address actualKeyperSet
);
contract AddKeyperSet is Script {
function run() public {
uint256 deployerPrivateKey = vm.envUint("PRIVATE_KEY");
address deployerAddress = vm.addr(deployerPrivateKey);
console.log("deployer:", deployerAddress);
vm.startBroadcast(deployerPrivateKey);
uint256 activationDelta = vm.envOr("ACTIVATION_DELTA", uint256(1));
if (activationDelta < 1) {
revert ActivationDeltaTooLow();
}
address keyperSetManagerAddress = vm.envAddress(
"KEYPERSETMANAGER_ADDRESS"
);
KeyperSetManager keyperSetManager = KeyperSetManager(
keyperSetManagerAddress
);
address keyBroadcastContractAddress = vm.envAddress(
"KEYBROADCAST_ADDRESS"
);
KeyBroadcastContract keyBroadcastContract = KeyBroadcastContract(
keyBroadcastContractAddress
);
address dkgContract = vm.envOr("DKG_CONTRACT_ADDRESS", address(0));
address[] memory keypers = vm.envAddress("KEYPER_ADDRESSES", ",");
uint256 threshold = vm.envUint("THRESHOLD");
if (threshold > keypers.length) {
revert ThresholdExceedsKeyperSetSize(threshold, keypers.length);
}
uint64 keyperSetIndex = keyperSetManager.getNumKeyperSets();
KeyperSet keyperSet = new KeyperSet();
EonKeyPublish eonKeyPublish = new EonKeyPublish(
address(keyperSet),
address(keyBroadcastContract),
keyperSetIndex
);
keyperSet.addMembers(keypers);
keyperSet.setThreshold(uint64(threshold));
keyperSet.setPublisher(address(eonKeyPublish));
if (dkgContract != address(0)) {
keyperSet.setDKGContract(dkgContract);
}
keyperSet.setFinalized();
console.log("keyperSet:", address(keyperSet));
console.log("eonKeyPublish:", address(eonKeyPublish));
uint64 activationBlock = uint64(block.number + activationDelta);
keyperSetManager.addKeyperSet(activationBlock, address(keyperSet));
console.log("activationBlock:", activationBlock);
console.log("keyperSetIndex:", keyperSetIndex);
address actualKeyperSet = keyperSetManager.getKeyperSetAddress(
keyperSetIndex
);
if (actualKeyperSet != address(keyperSet)) {
revert UnexpectedKeyperSet(
keyperSetIndex,
address(keyperSet),
actualKeyperSet
);
}
vm.stopBroadcast();
}
}