@@ -16,6 +16,7 @@ import {
1616 SortitionModuleUniversity ,
1717 TransactionBatcher ,
1818 KlerosCoreSnapshotProxy ,
19+ EvidenceModule ,
1920} from "../../typechain-types" ;
2021
2122export const Cores = {
@@ -26,6 +27,44 @@ export const Cores = {
2627
2728export type Core = ( typeof Cores ) [ keyof typeof Cores ] ;
2829
30+ export const getContractNames = ( coreType : Core ) => {
31+ const coreSpecificNames = {
32+ [ Cores . NEO ] : {
33+ core : "KlerosCoreNeo" ,
34+ sortition : "SortitionModuleNeo" ,
35+ disputeKitClassic : "DisputeKitClassicNeo" ,
36+ disputeResolver : "DisputeResolverNeo" ,
37+ } ,
38+ [ Cores . BASE ] : {
39+ core : "KlerosCore" ,
40+ sortition : "SortitionModule" ,
41+ disputeKitClassic : "DisputeKitClassic" ,
42+ disputeResolver : "DisputeResolver" ,
43+ } ,
44+ [ Cores . UNIVERSITY ] : {
45+ core : "KlerosCoreUniversity" ,
46+ sortition : "SortitionModuleUniversity" ,
47+ disputeKitClassic : "DisputeKitClassicUniversity" ,
48+ disputeResolver : "DisputeResolverUniversity" ,
49+ } ,
50+ } ;
51+
52+ if ( ! ( coreType in coreSpecificNames ) ) throw new Error ( "Invalid core type, must be one of BASE, NEO, or UNIVERSITY" ) ;
53+
54+ return {
55+ ...coreSpecificNames [ coreType ] ,
56+ evidence : "EvidenceModule" ,
57+ disputeTemplateRegistry : "DisputeTemplateRegistry" ,
58+ policyRegistry : "PolicyRegistry" ,
59+ batcher : "TransactionBatcher" ,
60+ chainlinkRng : "ChainlinkRNG" ,
61+ randomizerRng : "RandomizerRNG" ,
62+ blockHashRNG : "BlockHashRNG" ,
63+ pnk : "PNK" ,
64+ snapshotProxy : "KlerosCoreSnapshotProxy" ,
65+ } ;
66+ } ;
67+
2968export const getContracts = async ( hre : HardhatRuntimeEnvironment , coreType : Core ) => {
3069 const { ethers } = hre ;
3170 let core : KlerosCore | KlerosCoreNeo | KlerosCoreUniversity ;
@@ -34,40 +73,46 @@ export const getContracts = async (hre: HardhatRuntimeEnvironment, coreType: Cor
3473 let disputeResolver : DisputeResolver ;
3574 switch ( coreType ) {
3675 case Cores . NEO :
37- core = await ethers . getContract < KlerosCoreNeo > ( "KlerosCoreNeo" ) ;
38- sortition = await ethers . getContract < SortitionModuleNeo > ( "SortitionModuleNeo" ) ;
39- disputeKitClassic = await ethers . getContract < DisputeKitClassic > ( "DisputeKitClassicNeo" ) ;
40- disputeResolver = await ethers . getContract < DisputeResolver > ( "DisputeResolverNeo" ) ;
76+ core = await ethers . getContract < KlerosCoreNeo > ( getContractNames ( coreType ) . core ) ;
77+ sortition = await ethers . getContract < SortitionModuleNeo > ( getContractNames ( coreType ) . sortition ) ;
78+ disputeKitClassic = await ethers . getContract < DisputeKitClassic > ( getContractNames ( coreType ) . disputeKitClassic ) ;
79+ disputeResolver = await ethers . getContract < DisputeResolver > ( getContractNames ( coreType ) . disputeResolver ) ;
4180 break ;
4281 case Cores . BASE :
43- core = await ethers . getContract < KlerosCore > ( "KlerosCore" ) ;
44- sortition = await ethers . getContract < SortitionModule > ( "SortitionModule" ) ;
45- disputeKitClassic = await ethers . getContract < DisputeKitClassic > ( "DisputeKitClassic" ) ;
46- disputeResolver = await ethers . getContract < DisputeResolver > ( "DisputeResolver" ) ;
82+ core = await ethers . getContract < KlerosCore > ( getContractNames ( coreType ) . core ) ;
83+ sortition = await ethers . getContract < SortitionModule > ( getContractNames ( coreType ) . sortition ) ;
84+ disputeKitClassic = await ethers . getContract < DisputeKitClassic > ( getContractNames ( coreType ) . disputeKitClassic ) ;
85+ disputeResolver = await ethers . getContract < DisputeResolver > ( getContractNames ( coreType ) . disputeResolver ) ;
4786 break ;
4887 case Cores . UNIVERSITY :
49- core = await ethers . getContract < KlerosCoreUniversity > ( "KlerosCoreUniversity" ) ;
50- sortition = await ethers . getContract < SortitionModuleUniversity > ( "SortitionModuleUniversity" ) ;
51- disputeKitClassic = await ethers . getContract < DisputeKitClassic > ( "DisputeKitClassicUniversity" ) ;
52- disputeResolver = await ethers . getContract < DisputeResolver > ( "DisputeResolverUniversity" ) ;
88+ core = await ethers . getContract < KlerosCoreUniversity > ( getContractNames ( coreType ) . core ) ;
89+ sortition = await ethers . getContract < SortitionModuleUniversity > ( getContractNames ( coreType ) . sortition ) ;
90+ disputeKitClassic = await ethers . getContract < DisputeKitClassic > ( getContractNames ( coreType ) . disputeKitClassic ) ;
91+ disputeResolver = await ethers . getContract < DisputeResolver > ( getContractNames ( coreType ) . disputeResolver ) ;
5392 break ;
5493 default :
5594 throw new Error ( "Invalid core type, must be one of BASE, NEO, or UNIVERSITY" ) ;
5695 }
57- const disputeTemplateRegistry = await ethers . getContract < DisputeTemplateRegistry > ( "DisputeTemplateRegistry" ) ;
58- const policyRegistry = await ethers . getContract < PolicyRegistry > ( "PolicyRegistry" ) ;
59- const batcher = await ethers . getContract < TransactionBatcher > ( "TransactionBatcher" ) ;
60- const chainlinkRng = await ethers . getContractOrNull < ChainlinkRNG > ( "ChainlinkRNG" ) ;
61- const randomizerRng = await ethers . getContractOrNull < RandomizerRNG > ( "RandomizerRNG" ) ;
62- const blockHashRNG = await ethers . getContractOrNull < BlockHashRNG > ( "BlockHashRNG" ) ;
63- const pnk = await ethers . getContract < PNK > ( "PNK" ) ;
64- const snapshotProxy = await ethers . getContractOrNull < KlerosCoreSnapshotProxy > ( "KlerosCoreSnapshotProxy" ) ;
96+ const disputeTemplateRegistry = await ethers . getContract < DisputeTemplateRegistry > (
97+ getContractNames ( coreType ) . disputeTemplateRegistry
98+ ) ;
99+ const evidence = await ethers . getContract < EvidenceModule > ( getContractNames ( coreType ) . evidence ) ;
100+ const policyRegistry = await ethers . getContract < PolicyRegistry > ( getContractNames ( coreType ) . policyRegistry ) ;
101+ const batcher = await ethers . getContract < TransactionBatcher > ( getContractNames ( coreType ) . batcher ) ;
102+ const chainlinkRng = await ethers . getContractOrNull < ChainlinkRNG > ( getContractNames ( coreType ) . chainlinkRng ) ;
103+ const randomizerRng = await ethers . getContractOrNull < RandomizerRNG > ( getContractNames ( coreType ) . randomizerRng ) ;
104+ const blockHashRNG = await ethers . getContractOrNull < BlockHashRNG > ( getContractNames ( coreType ) . blockHashRNG ) ;
105+ const pnk = await ethers . getContract < PNK > ( getContractNames ( coreType ) . pnk ) ;
106+ const snapshotProxy = await ethers . getContractOrNull < KlerosCoreSnapshotProxy > (
107+ getContractNames ( coreType ) . snapshotProxy
108+ ) ;
65109 return {
66110 core,
67111 sortition,
68112 disputeKitClassic,
69113 disputeResolver,
70114 disputeTemplateRegistry,
115+ evidence,
71116 policyRegistry,
72117 chainlinkRng,
73118 randomizerRng,
@@ -77,3 +122,25 @@ export const getContracts = async (hre: HardhatRuntimeEnvironment, coreType: Cor
77122 snapshotProxy,
78123 } ;
79124} ;
125+
126+ export const getContractsFromNetwork = async ( hre : HardhatRuntimeEnvironment ) => {
127+ const { network } = hre ;
128+ if ( network . name === "arbitrumSepoliaDevnet" || network . name === "arbitrumSepolia" ) {
129+ return getContracts ( hre , Cores . BASE ) ;
130+ } else if ( network . name === "arbitrum" ) {
131+ return getContracts ( hre , Cores . NEO ) ;
132+ } else {
133+ throw new Error ( "Invalid network" ) ;
134+ }
135+ } ;
136+
137+ export const getContractNamesFromNetwork = async ( hre : HardhatRuntimeEnvironment ) => {
138+ const { network } = hre ;
139+ if ( network . name === "arbitrumSepoliaDevnet" || network . name === "arbitrumSepolia" ) {
140+ return getContractNames ( Cores . BASE ) ;
141+ } else if ( network . name === "arbitrum" ) {
142+ return getContractNames ( Cores . NEO ) ;
143+ } else {
144+ throw new Error ( "Invalid network" ) ;
145+ }
146+ } ;
0 commit comments