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