@@ -4,17 +4,69 @@ import { readdir, readFile } from "fs/promises";
44import { parse , join } from "path" ;
55import { Chain } from "wagmi/chains" ;
66import 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" ;
712
813dotenv . config ( ) ;
914
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+ ) => {
1163 const chains = await import ( "wagmi/chains" ) ;
1264 const chain = chains [ viemChainName ] as Chain ;
1365 if ( ! chain ) {
1466 throw new Error ( `Viem chain ${ viemChainName } not found` ) ;
1567 }
1668
17- const directoryPath = `../contracts/deployments/${ hardhatChainName ?? viemChainName } ` ;
69+ const directoryPath = `../contracts/deployments/${ hardhatChainName } ` ;
1870 const files = await readdir ( directoryPath ) ;
1971
2072 const results : ContractConfig [ ] = [ ] ;
@@ -34,53 +86,47 @@ const readArtifacts = async (viemChainName: string, hardhatChainName?: string) =
3486 }
3587 }
3688
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 } ) ) ;
57100
58101 return results ;
59102} ;
60103
61104const getConfig = async ( ) : Promise < Config > => {
62105 const deployment = process . env . REACT_APP_DEPLOYMENT ?? "devnet" ;
63-
64106 let viemNetwork : string ;
65107 let hardhatNetwork : string ;
108+ let arbitratorContracts ;
66109 switch ( deployment ) {
67110 case "devnet" :
68111 viemNetwork = "arbitrumSepolia" ;
69112 hardhatNetwork = "arbitrumSepoliaDevnet" ;
113+ arbitratorContracts = arbitratorDevnet ;
70114 break ;
71115 case "testnet" :
72116 viemNetwork = "arbitrumSepolia" ;
73117 hardhatNetwork = "arbitrumSepolia" ;
118+ arbitratorContracts = arbitratorTestnet ;
74119 break ;
75120 case "mainnet" :
76121 viemNetwork = "arbitrum" ;
77122 hardhatNetwork = "arbitrum" ;
123+ arbitratorContracts = arbitratorMainnet ;
78124 break ;
79125 default :
80126 throw new Error ( `Unknown deployment ${ deployment } ` ) ;
81127 }
82128
83- const deploymentContracts = await readArtifacts ( viemNetwork , hardhatNetwork ) ;
129+ const deploymentContracts = await readArtifacts ( viemNetwork , hardhatNetwork , arbitratorContracts ) ;
84130
85131 return {
86132 out : "src/hooks/contracts/generated.ts" ,
0 commit comments