|
1 | 1 | import { HardhatRuntimeEnvironment } from "hardhat/types"; |
2 | | -import { |
3 | | - disputeTemplateRegistryConfig as devnetDtrConfig, |
4 | | - klerosCoreConfig as devnetCoreConfig, |
5 | | -} from "@kleros/kleros-v2-contracts/deployments/devnet.viem"; |
6 | | -import { |
7 | | - disputeTemplateRegistryConfig as mainnetDtrConfig, |
8 | | - klerosCoreNeoConfig as mainnetCoreConfig, |
9 | | -} from "@kleros/kleros-v2-contracts/deployments/mainnet.viem"; |
10 | | -import { |
11 | | - KlerosCore, |
12 | | - DisputeTemplateRegistry__factory, |
13 | | - KlerosCore__factory, |
14 | | - KlerosCoreNeo__factory, |
15 | | - KlerosCoreNeo, |
16 | | - DisputeTemplateRegistry, |
17 | | -} from "@kleros/kleros-v2-contracts/typechain-types"; |
| 2 | +import { DeploymentName, getContractsEthers as _getArbitratorContracts } from "@kleros/kleros-v2-contracts"; |
18 | 3 | import { EscrowView, EscrowUniversal } from "../../typechain-types"; |
19 | 4 |
|
| 5 | +const NETWORK_TO_DEPLOYMENT: Record<string, DeploymentName> = { |
| 6 | + arbitrumSepoliaDevnet: "devnet", |
| 7 | + arbitrumSepolia: "testnet", |
| 8 | + arbitrum: "mainnetNeo", |
| 9 | +} as const; |
| 10 | + |
| 11 | +export const getArbitratorContracts = async (hre: HardhatRuntimeEnvironment) => { |
| 12 | + const { ethers, deployments } = hre; |
| 13 | + const networkName = deployments.getNetworkName(); |
| 14 | + const deploymentName = NETWORK_TO_DEPLOYMENT[networkName]; |
| 15 | + if (!deploymentName) |
| 16 | + throw new Error( |
| 17 | + `Unsupported network: ${networkName}. Supported networks: ${Object.keys(NETWORK_TO_DEPLOYMENT).join(", ")}` |
| 18 | + ); |
| 19 | + return await _getArbitratorContracts(ethers.provider, deploymentName); |
| 20 | +}; |
| 21 | + |
20 | 22 | export const getContracts = async (hre: HardhatRuntimeEnvironment) => { |
21 | | - const { getChainId, ethers, config } = hre; |
22 | | - const chainId = Number(await getChainId()); |
| 23 | + const { ethers } = hre; |
| 24 | + const { klerosCore, disputeTemplateRegistry } = await getArbitratorContracts(hre); |
23 | 25 | const escrow = await ethers.getContract<EscrowUniversal>("EscrowUniversal"); |
24 | 26 | const view = await ethers.getContract<EscrowView>("EscrowView"); |
25 | | - let disputeTemplateRegistry: DisputeTemplateRegistry; |
26 | | - let klerosCore: KlerosCore | KlerosCoreNeo; |
27 | | - switch (chainId) { |
28 | | - case config.networks.arbitrum.chainId: |
29 | | - disputeTemplateRegistry = DisputeTemplateRegistry__factory.connect( |
30 | | - mainnetDtrConfig.address[chainId], |
31 | | - ethers.provider |
32 | | - ); |
33 | | - klerosCore = KlerosCoreNeo__factory.connect(mainnetCoreConfig.address[chainId], ethers.provider); |
34 | | - break; |
35 | | - case config.networks.arbitrumSepolia.chainId: |
36 | | - disputeTemplateRegistry = DisputeTemplateRegistry__factory.connect( |
37 | | - devnetDtrConfig.address[chainId], |
38 | | - ethers.provider |
39 | | - ); |
40 | | - klerosCore = KlerosCore__factory.connect(devnetCoreConfig.address[chainId], ethers.provider); |
41 | | - break; |
42 | | - default: |
43 | | - throw new Error(`Unsupported chainId: ${chainId}`); |
44 | | - } |
45 | 27 | return { escrow, view, disputeTemplateRegistry, klerosCore }; |
46 | 28 | }; |
0 commit comments