@@ -4,17 +4,69 @@ import { readdir, readFile } from "fs/promises";
4
4
import { parse , join } from "path" ;
5
5
import { Chain } from "wagmi/chains" ;
6
6
import dotenv from "dotenv" ;
7
+ import {
8
+ arbitrumSepoliaDevnet as arbitratorDevnet ,
9
+ arbitrumSepolia as arbitratorTestnet ,
10
+ arbitrum as arbitratorMainnet ,
11
+ } from "@kleros/kleros-v2-contracts/cjs/deployments" ;
7
12
8
13
dotenv . config ( ) ;
9
14
10
- const readArtifacts = async ( viemChainName : string , hardhatChainName ?: string ) => {
15
+ type ArbitratorContracts = {
16
+ default : {
17
+ contracts : {
18
+ KlerosCore : {
19
+ address : `0x${string } `;
20
+ abi : any [ ] ;
21
+ } ;
22
+ SortitionModule : {
23
+ address : `0x${string } `;
24
+ abi : any [ ] ;
25
+ } ;
26
+ EvidenceModule : {
27
+ address : `0x${string } `;
28
+ abi : any [ ] ;
29
+ } ;
30
+ DisputeTemplateRegistry : {
31
+ address : `0x${string } `;
32
+ abi : any [ ] ;
33
+ } ;
34
+ } ;
35
+ } ;
36
+ } ;
37
+
38
+ const addArbitratorContract = ( {
39
+ results,
40
+ chain,
41
+ name,
42
+ contract,
43
+ } : {
44
+ results : ContractConfig [ ] ;
45
+ chain : Chain ;
46
+ name : string ;
47
+ contract : { address : `0x${string } `; abi : any [ ] } ;
48
+ } ) => {
49
+ results . push ( {
50
+ name,
51
+ address : {
52
+ [ chain . id ] : contract . address as `0x{string}`,
53
+ } ,
54
+ abi : contract . abi ,
55
+ } ) ;
56
+ } ;
57
+
58
+ const readArtifacts = async (
59
+ viemChainName : string ,
60
+ hardhatChainName : string ,
61
+ arbitratorContracts : ArbitratorContracts
62
+ ) => {
11
63
const chains = await import ( "wagmi/chains" ) ;
12
64
const chain = chains [ viemChainName ] as Chain ;
13
65
if ( ! chain ) {
14
66
throw new Error ( `Viem chain ${ viemChainName } not found` ) ;
15
67
}
16
68
17
- const directoryPath = `../contracts/deployments/${ hardhatChainName ?? viemChainName } ` ;
69
+ const directoryPath = `../contracts/deployments/${ hardhatChainName } ` ;
18
70
const files = await readdir ( directoryPath ) ;
19
71
20
72
const results : ContractConfig [ ] = [ ] ;
@@ -34,53 +86,47 @@ const readArtifacts = async (viemChainName: string, hardhatChainName?: string) =
34
86
}
35
87
}
36
88
37
- // read external contracts, Ex :- KlerosCore, EvidenceModule
38
- const externalContractsdirectoryPath = `../node_modules/@kleros/kleros-v2-contracts/deployments/${
39
- hardhatChainName ?? viemChainName
40
- } `;
41
- const externalfiles = await readdir ( externalContractsdirectoryPath ) ;
42
- for ( const file of externalfiles ) {
43
- const { name, ext } = parse ( file ) ;
44
- if ( ext === ".json" ) {
45
- const filePath = join ( externalContractsdirectoryPath , file ) ;
46
- const fileContent = await readFile ( filePath , "utf-8" ) ;
47
- const jsonContent = JSON . parse ( fileContent ) ;
48
- results . push ( {
49
- name,
50
- address : {
51
- [ chain . id ] : jsonContent . address as `0x{string}`,
52
- } ,
53
- abi : jsonContent . abi ,
54
- } ) ;
55
- }
56
- }
89
+ const { KlerosCore, SortitionModule, EvidenceModule, DisputeTemplateRegistry } =
90
+ arbitratorContracts . default . contracts ;
91
+
92
+ const arbitratorContractConfigs = [
93
+ { name : "KlerosCore" , contract : KlerosCore } ,
94
+ { name : "SortitionModule" , contract : SortitionModule } ,
95
+ { name : "EvidenceModule" , contract : EvidenceModule } ,
96
+ { name : "DisputeTemplateRegistry" , contract : DisputeTemplateRegistry } ,
97
+ ] ;
98
+
99
+ arbitratorContractConfigs . forEach ( ( { name, contract } ) => addArbitratorContract ( { results, chain, name, contract } ) ) ;
57
100
58
101
return results ;
59
102
} ;
60
103
61
104
const getConfig = async ( ) : Promise < Config > => {
62
105
const deployment = process . env . REACT_APP_DEPLOYMENT ?? "devnet" ;
63
-
64
106
let viemNetwork : string ;
65
107
let hardhatNetwork : string ;
108
+ let arbitratorContracts ;
66
109
switch ( deployment ) {
67
110
case "devnet" :
68
111
viemNetwork = "arbitrumSepolia" ;
69
112
hardhatNetwork = "arbitrumSepoliaDevnet" ;
113
+ arbitratorContracts = arbitratorDevnet ;
70
114
break ;
71
115
case "testnet" :
72
116
viemNetwork = "arbitrumSepolia" ;
73
117
hardhatNetwork = "arbitrumSepolia" ;
118
+ arbitratorContracts = arbitratorTestnet ;
74
119
break ;
75
120
case "mainnet" :
76
121
viemNetwork = "arbitrum" ;
77
122
hardhatNetwork = "arbitrum" ;
123
+ arbitratorContracts = arbitratorMainnet ;
78
124
break ;
79
125
default :
80
126
throw new Error ( `Unknown deployment ${ deployment } ` ) ;
81
127
}
82
128
83
- const deploymentContracts = await readArtifacts ( viemNetwork , hardhatNetwork ) ;
129
+ const deploymentContracts = await readArtifacts ( viemNetwork , hardhatNetwork , arbitratorContracts ) ;
84
130
85
131
return {
86
132
out : "src/hooks/contracts/generated.ts" ,
0 commit comments