-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathWhitelistZKMR.s.sol
118 lines (102 loc) · 3.56 KB
/
WhitelistZKMR.s.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
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.13;
import {BaseDeployer} from "../BaseDeployer.s.sol";
import {console} from "forge-std/console.sol";
import {
ETH_MAINNET, ETH_HOLESKY, isMainnet
} from "../../src/utils/Constants.sol";
interface IStakeRegistryZKMR {
function whitelist(address operator) external view returns (bool);
function addToWhitelist(address[] calldata operators) external;
}
abstract contract WhitelistBase is BaseDeployer {
function checkNetworkRequirement() internal virtual;
function isOperatorWhitelisted(address operator)
internal
virtual
returns (bool);
function addOperatorsToWhitelist(address[] memory operators)
internal
virtual;
function run() external {
checkNetworkRequirement();
string memory chainName = getChainAlias();
string memory root = vm.projectRoot();
string memory path =
string.concat(root, "/config/", chainName, "-operators.json");
string memory json = vm.readFile(path);
address[] memory operatorsToWhitelist =
abi.decode(vm.parseJson(json, "."), (address[]));
// Filter out already whitelisted operators
uint256 toWhitelistCount = 0;
address[] memory toWhitelist =
new address[](operatorsToWhitelist.length);
for (uint256 i = 0; i < operatorsToWhitelist.length; i++) {
if (!isOperatorWhitelisted(operatorsToWhitelist[i])) {
toWhitelist[toWhitelistCount] = operatorsToWhitelist[i];
toWhitelistCount++;
}
}
// Resize the array to remove empty slots
assembly {
mstore(toWhitelist, toWhitelistCount)
}
if (toWhitelistCount == 0) {
console.log("None to whitelist; skipping");
return;
}
console.log("Whitelisting %s operators", toWhitelistCount);
for (uint256 i = 0; i < toWhitelistCount; i++) {
console.log(toWhitelist[i]);
}
addOperatorsToWhitelist(toWhitelist);
}
}
contract WhitelistZKMR is WhitelistBase {
address public immutable ZKMR_STAKE_REGISTRY_ADDRESS = isMainnet()
? 0x8dcdCc50Cc00Fe898b037bF61cCf3bf9ba46f15C
: 0xf724cDC7C40fd6B59590C624E8F0E5E3843b4BE4;
function checkNetworkRequirement() internal view override {
require(
block.chainid == ETH_MAINNET || block.chainid == ETH_HOLESKY,
"The ZKMR AVS is only deployed on holesky and mainnet"
);
}
function isOperatorWhitelisted(address operator)
internal
view
override
returns (bool)
{
return
IStakeRegistryZKMR(ZKMR_STAKE_REGISTRY_ADDRESS).whitelist(operator);
}
function addOperatorsToWhitelist(address[] memory operators)
internal
override
{
if (isMainnet()) {
addOperatorsToWhitelistMainnet(operators);
} else {
addOperatorsToWhitelistHolesky(operators);
}
}
function addOperatorsToWhitelistMainnet(address[] memory operators)
internal
isBatch(address(SAFE))
{
bytes memory txn = abi.encodeWithSelector(
IStakeRegistryZKMR.addToWhitelist.selector, operators
);
addToBatch(ZKMR_STAKE_REGISTRY_ADDRESS, txn);
executeBatch(true);
}
function addOperatorsToWhitelistHolesky(address[] memory operators)
internal
broadcaster
{
IStakeRegistryZKMR(ZKMR_STAKE_REGISTRY_ADDRESS).addToWhitelist(
operators
);
}
}