|
| 1 | +import { ethers } from "ethers"; |
| 2 | +import { |
| 3 | + klerosCoreConfig as devnetCoreConfig, |
| 4 | + sortitionModuleConfig as devnetSortitionConfig, |
| 5 | + disputeKitClassicConfig as devnetDkcConfig, |
| 6 | + disputeResolverConfig as devnetDrConfig, |
| 7 | + disputeTemplateRegistryConfig as devnetDtrConfig, |
| 8 | + evidenceModuleConfig as devnetEvidenceConfig, |
| 9 | + policyRegistryConfig as devnetPolicyRegistryConfig, |
| 10 | + transactionBatcherConfig as devnetBatcherConfig, |
| 11 | + chainlinkRngConfig as devnetChainlinkRngConfig, |
| 12 | + blockHashRngConfig as devnetBlockHashRngConfig, |
| 13 | + pnkConfig as devnetPnkConfig, |
| 14 | + klerosCoreSnapshotProxyConfig as devnetSnapshotProxyConfig, |
| 15 | + klerosCoreUniversityConfig as devnetCoreUniversityConfig, |
| 16 | + sortitionModuleUniversityConfig as devnetSortitionUniversityConfig, |
| 17 | + disputeKitClassicUniversityConfig as devnetDkcUniversityConfig, |
| 18 | + disputeResolverUniversityConfig as devnetDrUniversityConfig, |
| 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"; |
| 49 | +import { |
| 50 | + KlerosCore, |
| 51 | + KlerosCore__factory, |
| 52 | + SortitionModule, |
| 53 | + SortitionModule__factory, |
| 54 | + DisputeKitClassic, |
| 55 | + DisputeKitClassic__factory, |
| 56 | + DisputeResolver, |
| 57 | + DisputeResolver__factory, |
| 58 | + DisputeTemplateRegistry, |
| 59 | + DisputeTemplateRegistry__factory, |
| 60 | + EvidenceModule, |
| 61 | + EvidenceModule__factory, |
| 62 | + PolicyRegistry, |
| 63 | + PolicyRegistry__factory, |
| 64 | + TransactionBatcher, |
| 65 | + TransactionBatcher__factory, |
| 66 | + ChainlinkRNG, |
| 67 | + ChainlinkRNG__factory, |
| 68 | + RandomizerRNG, |
| 69 | + RandomizerRNG__factory, |
| 70 | + BlockHashRNG, |
| 71 | + BlockHashRNG__factory, |
| 72 | + PNK, |
| 73 | + PNK__factory, |
| 74 | + KlerosCoreSnapshotProxy, |
| 75 | + KlerosCoreSnapshotProxy__factory, |
| 76 | + KlerosCoreUniversity, |
| 77 | + KlerosCoreUniversity__factory, |
| 78 | + SortitionModuleUniversity, |
| 79 | + SortitionModuleUniversity__factory, |
| 80 | + KlerosCoreNeo, |
| 81 | + KlerosCoreNeo__factory, |
| 82 | + SortitionModuleNeo, |
| 83 | + SortitionModuleNeo__factory, |
| 84 | +} from "../typechain-types"; |
| 85 | +import { type ContractConfig, type DeploymentName, deployments, getAddress } from "./utils"; |
| 86 | + |
| 87 | +type CommonFactoriesConfigs = { |
| 88 | + dkcConfig: ContractConfig; |
| 89 | + drConfig: ContractConfig; |
| 90 | + dtrConfig: ContractConfig; |
| 91 | + evidenceConfig: ContractConfig; |
| 92 | + policyRegistryConfig: ContractConfig; |
| 93 | + batcherConfig: ContractConfig; |
| 94 | + chainlinkRngConfig?: ContractConfig; |
| 95 | + randomizerRngConfig?: ContractConfig; |
| 96 | + blockHashRngConfig: ContractConfig; |
| 97 | + pnkConfig: ContractConfig; |
| 98 | + snapshotProxyConfig: ContractConfig; |
| 99 | +}; |
| 100 | + |
| 101 | +type CommonFactories = { |
| 102 | + disputeKitClassic: DisputeKitClassic; |
| 103 | + disputeResolver: DisputeResolver; |
| 104 | + disputeTemplateRegistry: DisputeTemplateRegistry; |
| 105 | + evidence: EvidenceModule; |
| 106 | + policyRegistry: PolicyRegistry; |
| 107 | + transactionBatcher: TransactionBatcher; |
| 108 | + chainlinkRng: ChainlinkRNG | null; |
| 109 | + randomizerRng: RandomizerRNG | null; |
| 110 | + blockHashRng: BlockHashRNG; |
| 111 | + pnk: PNK; |
| 112 | + klerosCoreSnapshotProxy: KlerosCoreSnapshotProxy; |
| 113 | +}; |
| 114 | + |
| 115 | +function getCommonFactories( |
| 116 | + configs: CommonFactoriesConfigs, |
| 117 | + provider: ethers.Provider, |
| 118 | + chainId: number |
| 119 | +): CommonFactories { |
| 120 | + return { |
| 121 | + disputeKitClassic: DisputeKitClassic__factory.connect(getAddress(configs.dkcConfig, chainId), provider), |
| 122 | + disputeResolver: DisputeResolver__factory.connect(getAddress(configs.drConfig, chainId), provider), |
| 123 | + disputeTemplateRegistry: DisputeTemplateRegistry__factory.connect(getAddress(configs.dtrConfig, chainId), provider), |
| 124 | + evidence: EvidenceModule__factory.connect(getAddress(configs.evidenceConfig, chainId), provider), |
| 125 | + policyRegistry: PolicyRegistry__factory.connect(getAddress(configs.policyRegistryConfig, chainId), provider), |
| 126 | + transactionBatcher: TransactionBatcher__factory.connect(getAddress(configs.batcherConfig, chainId), provider), |
| 127 | + chainlinkRng: configs.chainlinkRngConfig |
| 128 | + ? ChainlinkRNG__factory.connect(getAddress(configs.chainlinkRngConfig, chainId), provider) |
| 129 | + : null, |
| 130 | + randomizerRng: configs.randomizerRngConfig |
| 131 | + ? RandomizerRNG__factory.connect(getAddress(configs.randomizerRngConfig, chainId), provider) |
| 132 | + : null, |
| 133 | + blockHashRng: BlockHashRNG__factory.connect(getAddress(configs.blockHashRngConfig, chainId), provider), |
| 134 | + pnk: PNK__factory.connect(getAddress(configs.pnkConfig, chainId), provider), |
| 135 | + klerosCoreSnapshotProxy: KlerosCoreSnapshotProxy__factory.connect( |
| 136 | + getAddress(configs.snapshotProxyConfig, chainId), |
| 137 | + provider |
| 138 | + ), |
| 139 | + }; |
| 140 | +} |
| 141 | + |
| 142 | +export const getContracts = async (provider: ethers.Provider, deployment: DeploymentName) => { |
| 143 | + const { chainId } = deployments[deployment]; |
| 144 | + let klerosCore: KlerosCore | KlerosCoreNeo | KlerosCoreUniversity; |
| 145 | + let sortition: SortitionModule | SortitionModuleNeo | SortitionModuleUniversity; |
| 146 | + let commonFactories: CommonFactories; |
| 147 | + |
| 148 | + switch (deployment) { |
| 149 | + case "devnet": { |
| 150 | + klerosCore = KlerosCore__factory.connect(getAddress(devnetCoreConfig, chainId), provider); |
| 151 | + sortition = SortitionModule__factory.connect(getAddress(devnetSortitionConfig, chainId), provider); |
| 152 | + commonFactories = getCommonFactories( |
| 153 | + { |
| 154 | + dkcConfig: devnetDkcConfig, |
| 155 | + drConfig: devnetDrConfig, |
| 156 | + dtrConfig: devnetDtrConfig, |
| 157 | + evidenceConfig: devnetEvidenceConfig, |
| 158 | + policyRegistryConfig: devnetPolicyRegistryConfig, |
| 159 | + batcherConfig: devnetBatcherConfig, |
| 160 | + chainlinkRngConfig: devnetChainlinkRngConfig, |
| 161 | + blockHashRngConfig: devnetBlockHashRngConfig, |
| 162 | + pnkConfig: devnetPnkConfig, |
| 163 | + snapshotProxyConfig: devnetSnapshotProxyConfig, |
| 164 | + }, |
| 165 | + provider, |
| 166 | + chainId |
| 167 | + ); |
| 168 | + break; |
| 169 | + } |
| 170 | + case "university": { |
| 171 | + klerosCore = KlerosCoreUniversity__factory.connect(getAddress(devnetCoreUniversityConfig, chainId), provider); |
| 172 | + sortition = SortitionModuleUniversity__factory.connect( |
| 173 | + getAddress(devnetSortitionUniversityConfig, chainId), |
| 174 | + provider |
| 175 | + ); |
| 176 | + commonFactories = getCommonFactories( |
| 177 | + { |
| 178 | + dkcConfig: devnetDkcUniversityConfig, |
| 179 | + drConfig: devnetDrUniversityConfig, |
| 180 | + dtrConfig: devnetDtrConfig, |
| 181 | + evidenceConfig: devnetEvidenceConfig, |
| 182 | + policyRegistryConfig: devnetPolicyRegistryConfig, |
| 183 | + batcherConfig: devnetBatcherConfig, |
| 184 | + chainlinkRngConfig: devnetChainlinkRngConfig, |
| 185 | + blockHashRngConfig: devnetBlockHashRngConfig, |
| 186 | + pnkConfig: devnetPnkConfig, |
| 187 | + snapshotProxyConfig: devnetSnapshotProxyConfig, |
| 188 | + }, |
| 189 | + provider, |
| 190 | + chainId |
| 191 | + ); |
| 192 | + break; |
| 193 | + } |
| 194 | + case "testnet": |
| 195 | + klerosCore = KlerosCore__factory.connect(getAddress(testnetCoreConfig, chainId), provider); |
| 196 | + sortition = SortitionModule__factory.connect(getAddress(testnetSortitionConfig, chainId), provider); |
| 197 | + commonFactories = getCommonFactories( |
| 198 | + { |
| 199 | + dkcConfig: testnetDkcConfig, |
| 200 | + drConfig: testnetDrConfig, |
| 201 | + dtrConfig: testnetDtrConfig, |
| 202 | + evidenceConfig: testnetEvidenceConfig, |
| 203 | + policyRegistryConfig: testnetPolicyRegistryConfig, |
| 204 | + batcherConfig: testnetBatcherConfig, |
| 205 | + chainlinkRngConfig: testnetChainlinkRngConfig, |
| 206 | + blockHashRngConfig: testnetBlockHashRngConfig, |
| 207 | + pnkConfig: testnetPnkConfig, |
| 208 | + snapshotProxyConfig: testnetSnapshotProxyConfig, |
| 209 | + }, |
| 210 | + provider, |
| 211 | + chainId |
| 212 | + ); |
| 213 | + break; |
| 214 | + case "mainnetNeo": |
| 215 | + klerosCore = KlerosCoreNeo__factory.connect(getAddress(mainnetCoreConfig, chainId), provider); |
| 216 | + sortition = SortitionModuleNeo__factory.connect(getAddress(mainnetSortitionConfig, chainId), provider); |
| 217 | + commonFactories = getCommonFactories( |
| 218 | + { |
| 219 | + dkcConfig: mainnetDkcConfig, |
| 220 | + drConfig: mainnetDrConfig, |
| 221 | + dtrConfig: mainnetDtrConfig, |
| 222 | + evidenceConfig: mainnetEvidenceConfig, |
| 223 | + policyRegistryConfig: mainnetPolicyRegistryConfig, |
| 224 | + batcherConfig: mainnetBatcherConfig, |
| 225 | + chainlinkRngConfig: mainnetChainlinkRngConfig, |
| 226 | + randomizerRngConfig: mainnetRandomizerRngConfig, |
| 227 | + blockHashRngConfig: mainnetBlockHashRngConfig, |
| 228 | + pnkConfig: mainnetPnkConfig, |
| 229 | + snapshotProxyConfig: mainnetSnapshotProxyConfig, |
| 230 | + }, |
| 231 | + provider, |
| 232 | + chainId |
| 233 | + ); |
| 234 | + break; |
| 235 | + default: |
| 236 | + throw new Error(`Unsupported deployment: ${deployment}`); |
| 237 | + } |
| 238 | + return { klerosCore, sortition, ...commonFactories }; |
| 239 | +}; |
0 commit comments