@@ -16,8 +16,36 @@ import {
16
16
sortitionModuleUniversityConfig as devnetSortitionUniversityConfig ,
17
17
disputeKitClassicUniversityConfig as devnetDkcUniversityConfig ,
18
18
disputeResolverUniversityConfig as devnetDrUniversityConfig ,
19
- klerosCoreUniversityProxyConfig as devnetCoreUniversityProxyConfig ,
20
19
} from "./devnet.viem" ;
20
+ import {
21
+ klerosCoreConfig as testnetCoreConfig ,
22
+ sortitionModuleConfig as testnetSortitionConfig ,
23
+ disputeKitClassicConfig as testnetDkcConfig ,
24
+ disputeResolverConfig as testnetDrConfig ,
25
+ disputeTemplateRegistryConfig as testnetDtrConfig ,
26
+ evidenceModuleConfig as testnetEvidenceConfig ,
27
+ policyRegistryConfig as testnetPolicyRegistryConfig ,
28
+ transactionBatcherConfig as testnetBatcherConfig ,
29
+ chainlinkRngConfig as testnetChainlinkRngConfig ,
30
+ blockHashRngConfig as testnetBlockHashRngConfig ,
31
+ pnkConfig as testnetPnkConfig ,
32
+ klerosCoreSnapshotProxyConfig as testnetSnapshotProxyConfig ,
33
+ } from "./testnet.viem" ;
34
+ import {
35
+ klerosCoreNeoConfig as mainnetCoreConfig ,
36
+ sortitionModuleNeoConfig as mainnetSortitionConfig ,
37
+ disputeKitClassicNeoConfig as mainnetDkcConfig ,
38
+ disputeResolverNeoConfig as mainnetDrConfig ,
39
+ disputeTemplateRegistryConfig as mainnetDtrConfig ,
40
+ evidenceModuleConfig as mainnetEvidenceConfig ,
41
+ policyRegistryConfig as mainnetPolicyRegistryConfig ,
42
+ transactionBatcherConfig as mainnetBatcherConfig ,
43
+ chainlinkRngConfig as mainnetChainlinkRngConfig ,
44
+ randomizerRngConfig as mainnetRandomizerRngConfig ,
45
+ blockHashRngConfig as mainnetBlockHashRngConfig ,
46
+ pnkConfig as mainnetPnkConfig ,
47
+ klerosCoreSnapshotProxyConfig as mainnetSnapshotProxyConfig ,
48
+ } from "./mainnet.viem" ;
21
49
import { type PublicClient , type WalletClient , getContract } from "viem" ;
22
50
23
51
const deployments = {
@@ -42,11 +70,25 @@ type ContractConfig = {
42
70
abi : readonly any [ ] ;
43
71
} ;
44
72
45
- type ContractConfigs = {
46
- klerosCore ?: {
47
- address : `0x${string } `;
48
- abi : readonly any [ ] ;
49
- } ;
73
+ type ContractInstance = {
74
+ address : `0x${string } `;
75
+ abi : readonly any [ ] ;
76
+ } ;
77
+
78
+ type ContractInstances = {
79
+ klerosCore : ContractInstance ;
80
+ sortition : ContractInstance ;
81
+ disputeKitClassic : ContractInstance ;
82
+ disputeResolver : ContractInstance ;
83
+ disputeTemplateRegistry : ContractInstance ;
84
+ evidence : ContractInstance ;
85
+ policyRegistry : ContractInstance ;
86
+ transactionBatcher : ContractInstance ;
87
+ chainlinkRng ?: ContractInstance ;
88
+ randomizerRng ?: ContractInstance ;
89
+ blockHashRng : ContractInstance ;
90
+ pnk : ContractInstance ;
91
+ klerosCoreSnapshotProxy : ContractInstance ;
50
92
} ;
51
93
52
94
function getAddress ( config : ContractConfig , chainId : number ) : `0x${string } ` {
@@ -55,22 +97,134 @@ function getAddress(config: ContractConfig, chainId: number): `0x${string}` {
55
97
return address ;
56
98
}
57
99
58
- export const getConfigs = ( { deployment } : { deployment : DeploymentName } ) : ContractConfigs => {
100
+ function getContractConfig ( { config, chainId } : { config : ContractConfig ; chainId : number } ) : ContractInstance {
101
+ return {
102
+ address : getAddress ( config , chainId ) ,
103
+ abi : config . abi ,
104
+ } ;
105
+ }
106
+
107
+ function getCommonConfigs ( {
108
+ chainId,
109
+ configs,
110
+ } : {
111
+ chainId : number ;
112
+ configs : {
113
+ klerosCore : ContractConfig ;
114
+ sortition : ContractConfig ;
115
+ disputeKitClassic : ContractConfig ;
116
+ disputeResolver : ContractConfig ;
117
+ disputeTemplateRegistry : ContractConfig ;
118
+ evidence : ContractConfig ;
119
+ policyRegistry : ContractConfig ;
120
+ transactionBatcher : ContractConfig ;
121
+ blockHashRng : ContractConfig ;
122
+ pnk : ContractConfig ;
123
+ klerosCoreSnapshotProxy : ContractConfig ;
124
+ chainlinkRng ?: ContractConfig ;
125
+ randomizerRng ?: ContractConfig ;
126
+ } ;
127
+ } ) : ContractInstances {
128
+ const base : ContractInstances = {
129
+ klerosCore : getContractConfig ( { config : configs . klerosCore , chainId } ) ,
130
+ sortition : getContractConfig ( { config : configs . sortition , chainId } ) ,
131
+ disputeKitClassic : getContractConfig ( { config : configs . disputeKitClassic , chainId } ) ,
132
+ disputeResolver : getContractConfig ( { config : configs . disputeResolver , chainId } ) ,
133
+ disputeTemplateRegistry : getContractConfig ( { config : configs . disputeTemplateRegistry , chainId } ) ,
134
+ evidence : getContractConfig ( { config : configs . evidence , chainId } ) ,
135
+ policyRegistry : getContractConfig ( { config : configs . policyRegistry , chainId } ) ,
136
+ transactionBatcher : getContractConfig ( { config : configs . transactionBatcher , chainId } ) ,
137
+ blockHashRng : getContractConfig ( { config : configs . blockHashRng , chainId } ) ,
138
+ pnk : getContractConfig ( { config : configs . pnk , chainId } ) ,
139
+ klerosCoreSnapshotProxy : getContractConfig ( { config : configs . klerosCoreSnapshotProxy , chainId } ) ,
140
+ } ;
141
+
142
+ if ( configs . chainlinkRng ) base . chainlinkRng = getContractConfig ( { config : configs . chainlinkRng , chainId } ) ;
143
+
144
+ if ( configs . randomizerRng ) base . randomizerRng = getContractConfig ( { config : configs . randomizerRng , chainId } ) ;
145
+
146
+ return base ;
147
+ }
148
+
149
+ export const getConfigs = ( { deployment } : { deployment : DeploymentName } ) : ContractInstances => {
59
150
const { chainId } = deployments [ deployment ] ;
60
- let contractConfigs : ContractConfigs = { } ;
61
151
switch ( deployment ) {
62
152
case "devnet" :
63
- contractConfigs = {
64
- klerosCore : {
65
- address : getAddress ( devnetCoreConfig , chainId ) ,
66
- abi : devnetCoreConfig . abi ,
153
+ return getCommonConfigs ( {
154
+ chainId,
155
+ configs : {
156
+ klerosCore : devnetCoreConfig ,
157
+ sortition : devnetSortitionConfig ,
158
+ disputeKitClassic : devnetDkcConfig ,
159
+ disputeResolver : devnetDrConfig ,
160
+ disputeTemplateRegistry : devnetDtrConfig ,
161
+ evidence : devnetEvidenceConfig ,
162
+ policyRegistry : devnetPolicyRegistryConfig ,
163
+ transactionBatcher : devnetBatcherConfig ,
164
+ blockHashRng : devnetBlockHashRngConfig ,
165
+ pnk : devnetPnkConfig ,
166
+ klerosCoreSnapshotProxy : devnetSnapshotProxyConfig ,
167
+ chainlinkRng : devnetChainlinkRngConfig ,
67
168
} ,
169
+ } ) ;
170
+
171
+ case "university" :
172
+ return {
173
+ klerosCore : getContractConfig ( { config : devnetCoreUniversityConfig , chainId } ) ,
174
+ sortition : getContractConfig ( { config : devnetSortitionUniversityConfig , chainId } ) ,
175
+ disputeKitClassic : getContractConfig ( { config : devnetDkcUniversityConfig , chainId } ) ,
176
+ disputeResolver : getContractConfig ( { config : devnetDrUniversityConfig , chainId } ) ,
177
+ disputeTemplateRegistry : getContractConfig ( { config : devnetDtrConfig , chainId } ) , // FIXME: should not be shared with devnet
178
+ evidence : getContractConfig ( { config : devnetEvidenceConfig , chainId } ) , // Not arbitrator specific
179
+ policyRegistry : getContractConfig ( { config : devnetPolicyRegistryConfig , chainId } ) , // Not arbitrator specific
180
+ transactionBatcher : getContractConfig ( { config : devnetBatcherConfig , chainId } ) , // Not arbitrator specific
181
+ blockHashRng : getContractConfig ( { config : devnetBlockHashRngConfig , chainId } ) , // Not used in university
182
+ pnk : getContractConfig ( { config : devnetPnkConfig , chainId } ) , // Not arbitrator specific
183
+ klerosCoreSnapshotProxy : getContractConfig ( { config : devnetSnapshotProxyConfig , chainId } ) , // Not used in university
68
184
} ;
69
- break ;
185
+
186
+ case "testnet" :
187
+ return getCommonConfigs ( {
188
+ chainId,
189
+ configs : {
190
+ klerosCore : testnetCoreConfig ,
191
+ sortition : testnetSortitionConfig ,
192
+ disputeKitClassic : testnetDkcConfig ,
193
+ disputeResolver : testnetDrConfig ,
194
+ disputeTemplateRegistry : testnetDtrConfig ,
195
+ evidence : testnetEvidenceConfig ,
196
+ policyRegistry : testnetPolicyRegistryConfig ,
197
+ transactionBatcher : testnetBatcherConfig ,
198
+ blockHashRng : testnetBlockHashRngConfig ,
199
+ pnk : testnetPnkConfig ,
200
+ klerosCoreSnapshotProxy : testnetSnapshotProxyConfig ,
201
+ chainlinkRng : testnetChainlinkRngConfig ,
202
+ } ,
203
+ } ) ;
204
+
205
+ case "mainnetNeo" :
206
+ return getCommonConfigs ( {
207
+ chainId,
208
+ configs : {
209
+ klerosCore : mainnetCoreConfig ,
210
+ sortition : mainnetSortitionConfig ,
211
+ disputeKitClassic : mainnetDkcConfig ,
212
+ disputeResolver : mainnetDrConfig ,
213
+ disputeTemplateRegistry : mainnetDtrConfig ,
214
+ evidence : mainnetEvidenceConfig ,
215
+ policyRegistry : mainnetPolicyRegistryConfig ,
216
+ transactionBatcher : mainnetBatcherConfig ,
217
+ blockHashRng : mainnetBlockHashRngConfig ,
218
+ pnk : mainnetPnkConfig ,
219
+ klerosCoreSnapshotProxy : mainnetSnapshotProxyConfig ,
220
+ chainlinkRng : mainnetChainlinkRngConfig ,
221
+ randomizerRng : mainnetRandomizerRngConfig ,
222
+ } ,
223
+ } ) ;
224
+
70
225
default :
71
226
throw new Error ( `Unsupported deployment: ${ deployment } ` ) ;
72
227
}
73
- return contractConfigs ;
74
228
} ;
75
229
76
230
export const getContracts = ( {
@@ -88,20 +242,76 @@ export const getContracts = ({
88
242
wallet : walletClient ,
89
243
} ,
90
244
} ;
91
- let klerosCore ;
92
- switch ( deployment ) {
93
- case "devnet" :
94
- const contractConfigs = getConfigs ( { deployment } ) ;
95
- if ( ! contractConfigs . klerosCore ) throw new Error ( "KlerosCore config not found" ) ;
96
- klerosCore = getContract ( {
97
- ...contractConfigs . klerosCore ,
245
+ const contractConfigs = getConfigs ( { deployment } ) ;
246
+ const klerosCore = getContract ( {
247
+ ...contractConfigs . klerosCore ,
248
+ ...clientConfig ,
249
+ } ) ;
250
+ const sortition = getContract ( {
251
+ ...contractConfigs . sortition ,
252
+ ...clientConfig ,
253
+ } ) ;
254
+ const disputeKitClassic = getContract ( {
255
+ ...contractConfigs . disputeKitClassic ,
256
+ ...clientConfig ,
257
+ } ) ;
258
+ const disputeResolver = getContract ( {
259
+ ...contractConfigs . disputeResolver ,
260
+ ...clientConfig ,
261
+ } ) ;
262
+ const disputeTemplateRegistry = getContract ( {
263
+ ...contractConfigs . disputeTemplateRegistry ,
264
+ ...clientConfig ,
265
+ } ) ;
266
+ const evidence = getContract ( {
267
+ ...contractConfigs . evidence ,
268
+ ...clientConfig ,
269
+ } ) ;
270
+ const policyRegistry = getContract ( {
271
+ ...contractConfigs . policyRegistry ,
272
+ ...clientConfig ,
273
+ } ) ;
274
+ const transactionBatcher = getContract ( {
275
+ ...contractConfigs . transactionBatcher ,
276
+ ...clientConfig ,
277
+ } ) ;
278
+ const chainlinkRng = contractConfigs . chainlinkRng
279
+ ? getContract ( {
280
+ ...contractConfigs . chainlinkRng ,
98
281
...clientConfig ,
99
- } ) ;
100
- break ;
101
- default :
102
- throw new Error ( `Unsupported deployment: ${ deployment } ` ) ;
103
- }
282
+ } )
283
+ : undefined ;
284
+ const randomizerRng = contractConfigs . randomizerRng
285
+ ? getContract ( {
286
+ ...contractConfigs . randomizerRng ,
287
+ ...clientConfig ,
288
+ } )
289
+ : undefined ;
290
+ const blockHashRng = getContract ( {
291
+ ...contractConfigs . blockHashRng ,
292
+ ...clientConfig ,
293
+ } ) ;
294
+ const pnk = getContract ( {
295
+ ...contractConfigs . pnk ,
296
+ ...clientConfig ,
297
+ } ) ;
298
+ const klerosCoreSnapshotProxy = getContract ( {
299
+ ...contractConfigs . klerosCoreSnapshotProxy ,
300
+ ...clientConfig ,
301
+ } ) ;
104
302
return {
105
303
klerosCore,
304
+ sortition,
305
+ disputeKitClassic,
306
+ disputeResolver,
307
+ disputeTemplateRegistry,
308
+ evidence,
309
+ policyRegistry,
310
+ transactionBatcher,
311
+ chainlinkRng,
312
+ randomizerRng,
313
+ blockHashRng,
314
+ pnk,
315
+ klerosCoreSnapshotProxy,
106
316
} ;
107
317
} ;
0 commit comments