-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDeploy.s.sol
More file actions
165 lines (141 loc) · 6.8 KB
/
Deploy.s.sol
File metadata and controls
165 lines (141 loc) · 6.8 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
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
// SPDX-License-Identifier: MIT
// solhint-disable use-natspec, max-states-count, no-console
pragma solidity =0.8.30;
import {Script} from "forge-std/Script.sol";
import {PoRepMarket} from "../src/PoRepMarket.sol";
import {Validator} from "../src/Validator.sol";
import {ValidatorFactory} from "../src/ValidatorFactory.sol";
import {Client} from "../src/Client.sol";
import {stdJson} from "forge-std/StdJson.sol";
import {DeployUtils} from "./utils/DeployUtils.sol";
import {SLIOracle} from "../src/SLIOracle.sol";
import {SLIScorer} from "../src/SLIScorer.sol";
import {SPRegistry} from "../src/SPRegistry.sol";
import {console} from "forge-std/console.sol";
contract Deploy is Script, DeployUtils {
using stdJson for string;
address internal poRepMarket;
address internal validatorFactory;
address internal clientSmartContract;
address internal sliOracle;
address internal sliScorer;
address internal poRepMarketImpl;
address internal validatorFactoryImpl;
address internal validatorImpl;
address internal clientSmartContractImpl;
address internal sliOracleImpl;
address internal sliScorerImpl;
address internal validator;
address internal validatorBeacon;
address internal spRegistryImpl;
address internal spRegistry;
address internal filecoinPay;
address internal admin;
address internal terminationOracle;
address internal oracleAddress;
address internal poRepService;
address internal operatorAddress;
address internal metaAllocator;
function run() external {
admin = vm.addr(vm.envUint("PRIVATE_KEY"));
terminationOracle = vm.envAddress("TERMINATION_ORACLE");
filecoinPay = vm.envAddress("FILECOIN_PAY");
oracleAddress = vm.envAddress("ORACLE");
poRepService = vm.envAddress("POREP_SERVICE");
operatorAddress = vm.envOr("OPERATOR_ADDR", address(0));
metaAllocator = vm.envAddress("META_ALLOCATOR");
vm.startBroadcast(admin);
(validatorFactory, validatorFactoryImpl, validatorImpl) = _deployValidatorFactory(admin);
(spRegistry, spRegistryImpl) = _deploySPRegistry(admin);
(poRepMarket, poRepMarketImpl) = _deployPoRepMarket(admin, validatorFactory, spRegistry);
(clientSmartContract, clientSmartContractImpl) =
_deployClientSmartContract(admin, terminationOracle, poRepMarket, metaAllocator);
(sliOracle, sliOracleImpl) = _deploySLIOracle(admin, oracleAddress);
(sliScorer, sliScorerImpl) = _deploySliScorer(admin, sliOracle);
validatorBeacon = ValidatorFactory(validatorFactory).getBeacon();
// circular dependencies
PoRepMarket(poRepMarket).setClientSmartContract(clientSmartContract);
ValidatorFactory(validatorFactory)
.initialize2(poRepService, filecoinPay, sliScorer, clientSmartContract, poRepMarket, spRegistry);
SPRegistry(spRegistry).initialize2(poRepMarket);
if (operatorAddress != address(0)) {
SPRegistry(spRegistry).grantRole(SPRegistry(spRegistry).OPERATOR_ROLE(), operatorAddress);
} else {
// solhint-disable-next-line gas-small-strings
console.log("WARNING: OPERATOR_ADDR not set, skipping operator role grant");
}
vm.stopBroadcast();
_serializeAndSaveArtifact();
}
function _deployValidatorFactory(address _admin)
internal
returns (address proxy, address factoryImpl, address valImpl)
{
Validator _validatorImpl = new Validator();
ValidatorFactory _impl = new ValidatorFactory();
bytes memory init = abi.encodeCall(ValidatorFactory.initialize, (_admin, address(_validatorImpl)));
proxy = createProxy(init, address(_impl));
factoryImpl = address(_impl);
valImpl = address(_validatorImpl);
}
function _deployPoRepMarket(address _admin, address _validatorFactory, address _spRegistry)
internal
returns (address proxy, address impl)
{
PoRepMarket _impl = new PoRepMarket();
bytes memory init = abi.encodeCall(PoRepMarket.initialize, (_admin, _validatorFactory, _spRegistry));
proxy = createProxy(init, address(_impl));
impl = address(_impl);
}
function _deployClientSmartContract(
address _admin,
address _terminationOracle,
address _porepMarket,
address _metaAllocator
) internal returns (address proxy, address impl) {
Client _impl = new Client();
bytes memory init =
abi.encodeCall(Client.initialize, (_admin, _terminationOracle, _porepMarket, _metaAllocator));
proxy = createProxy(init, address(_impl));
impl = address(_impl);
}
function _deploySLIOracle(address _admin, address _oracleAddress) internal returns (address proxy, address impl) {
SLIOracle _impl = new SLIOracle();
bytes memory init = abi.encodeCall(SLIOracle.initialize, (_admin, _oracleAddress));
proxy = createProxy(init, address(_impl));
impl = address(_impl);
}
function _deploySliScorer(address _admin, address _sliOracle) internal returns (address proxy, address impl) {
SLIScorer _impl = new SLIScorer();
bytes memory init = abi.encodeCall(SLIScorer.initialize, (_admin, SLIOracle(_sliOracle)));
proxy = createProxy(init, address(_impl));
impl = address(_impl);
}
function _deploySPRegistry(address _admin) internal returns (address proxy, address impl) {
SPRegistry _impl = new SPRegistry();
bytes memory init = abi.encodeCall(SPRegistry.initialize, (_admin));
proxy = createProxy(init, address(_impl));
impl = address(_impl);
}
function _serializeAndSaveArtifact() internal {
string memory json = "deployment";
json.serialize("chainId", block.chainid);
json.serialize("block", block.number);
json.serialize("timestamp", block.timestamp);
json.serialize("deployer", admin);
serializeContract(json, "PoRepMarket", poRepMarket, poRepMarketImpl);
serializeContract(json, "ValidatorFactory", validatorFactory, validatorFactoryImpl);
serializeContract(json, "Client", clientSmartContract, clientSmartContractImpl);
serializeContract(json, "SLIOracle", sliOracle, sliOracleImpl);
serializeContract(json, "SLIScorer", sliScorer, sliScorerImpl);
serializeContract(json, "SPRegistry", spRegistry, spRegistryImpl);
json.serialize("ValidatorBeacon", validatorBeacon);
json.serialize("ValidatorImpl", validatorImpl);
json.serialize("FilecoinPay", filecoinPay);
json.serialize("PoRepService", poRepService);
json.serialize("MetaAllocator", metaAllocator);
json.serialize("SPRegistry", spRegistry);
string memory output = json.serialize("TerminationOracle", terminationOracle);
save(output);
}
}