|
1 | 1 | import { arbitrum, arbitrumSepolia } from "viem/chains"; |
2 | | -import { disputeTemplateRegistryConfig as devnetDtrConfig, klerosCoreConfig as devnetCoreConfig } from "./devnet.viem"; |
3 | 2 | import { |
4 | | - disputeTemplateRegistryConfig as mainnetDtrConfig, |
5 | | - klerosCoreNeoConfig as mainnetCoreConfig, |
6 | | -} from "./mainnet.viem"; |
7 | | -import { type PublicClient, type WalletClient } from "viem"; |
| 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 | + klerosCoreUniversityProxyConfig as devnetCoreUniversityProxyConfig, |
| 20 | +} from "./devnet.viem"; |
| 21 | +import { type PublicClient, type WalletClient, getContract } from "viem"; |
8 | 22 |
|
9 | | -export const Cores = { |
10 | | - BASE: "BASE", |
11 | | - NEO: "NEO", |
12 | | - UNIVERSITY: "UNIVERSITY", |
| 23 | +const deployments = { |
| 24 | + devnet: { |
| 25 | + chainId: arbitrumSepolia.id, |
| 26 | + }, |
| 27 | + university: { |
| 28 | + chainId: arbitrumSepolia.id, |
| 29 | + }, |
| 30 | + testnet: { |
| 31 | + chainId: arbitrumSepolia.id, |
| 32 | + }, |
| 33 | + mainnetNeo: { |
| 34 | + chainId: arbitrum.id, |
| 35 | + }, |
13 | 36 | } as const; |
14 | 37 |
|
15 | | -export type Core = (typeof Cores)[keyof typeof Cores]; |
| 38 | +type DeploymentName = keyof typeof deployments; |
| 39 | + |
| 40 | +type ContractConfig = { |
| 41 | + address: Record<number, `0x${string}`>; |
| 42 | + abi: readonly any[]; |
| 43 | +}; |
| 44 | + |
| 45 | +type ContractConfigs = { |
| 46 | + klerosCore?: { |
| 47 | + address: `0x${string}`; |
| 48 | + abi: readonly any[]; |
| 49 | + }; |
| 50 | +}; |
| 51 | + |
| 52 | +function getAddress(config: ContractConfig, chainId: number): `0x${string}` { |
| 53 | + const address = config.address[chainId]; |
| 54 | + if (!address) throw new Error(`No address found for chainId ${chainId}`); |
| 55 | + return address; |
| 56 | +} |
| 57 | + |
| 58 | +export const getConfigs = ({ deployment }: { deployment: DeploymentName }): ContractConfigs => { |
| 59 | + const { chainId } = deployments[deployment]; |
| 60 | + let contractConfigs: ContractConfigs = {}; |
| 61 | + switch (deployment) { |
| 62 | + case "devnet": |
| 63 | + contractConfigs = { |
| 64 | + klerosCore: { |
| 65 | + address: getAddress(devnetCoreConfig, chainId), |
| 66 | + abi: devnetCoreConfig.abi, |
| 67 | + }, |
| 68 | + }; |
| 69 | + break; |
| 70 | + default: |
| 71 | + throw new Error(`Unsupported deployment: ${deployment}`); |
| 72 | + } |
| 73 | + return contractConfigs; |
| 74 | +}; |
16 | 75 |
|
17 | 76 | export const getContracts = ({ |
18 | 77 | publicClient, |
19 | 78 | walletClient, |
20 | | - chainId, |
21 | | - coreType, |
| 79 | + deployment, |
22 | 80 | }: { |
23 | 81 | publicClient: PublicClient; |
24 | 82 | walletClient?: WalletClient; |
25 | | - chainId: number; |
26 | | - coreType: Core; |
| 83 | + deployment: DeploymentName; |
27 | 84 | }) => { |
28 | | - throw new Error("Not implemented"); |
29 | | - switch (chainId) { |
30 | | - case arbitrum.id: |
31 | | - return { |
32 | | - disputeTemplateRegistry: { |
33 | | - address: mainnetDtrConfig.address[chainId], |
34 | | - publicClient, |
35 | | - walletClient, |
36 | | - abi: mainnetDtrConfig.abi, |
37 | | - }, |
38 | | - klerosCore: { |
39 | | - address: mainnetCoreConfig.address[chainId], |
40 | | - publicClient, |
41 | | - walletClient, |
42 | | - abi: mainnetCoreConfig.abi, |
43 | | - }, |
44 | | - }; |
45 | | - case arbitrumSepolia.id: |
46 | | - return { |
47 | | - disputeTemplateRegistry: { |
48 | | - address: devnetDtrConfig.address[chainId], |
49 | | - publicClient, |
50 | | - walletClient, |
51 | | - abi: devnetDtrConfig.abi, |
52 | | - }, |
53 | | - klerosCore: { |
54 | | - address: devnetCoreConfig.address[chainId], |
55 | | - publicClient, |
56 | | - walletClient, |
57 | | - abi: devnetCoreConfig.abi, |
58 | | - }, |
59 | | - }; |
| 85 | + const clientConfig = { |
| 86 | + client: { |
| 87 | + public: publicClient, |
| 88 | + wallet: walletClient, |
| 89 | + }, |
| 90 | + }; |
| 91 | + let klerosCore; |
| 92 | + switch (deployment) { |
| 93 | + case "devnet": |
| 94 | + const contractConfigs = getConfigs({ deployment }); |
| 95 | + if (!contractConfigs.klerosCore) throw new Error("KlerosCore config not found"); |
| 96 | + klerosCore = getContract({ |
| 97 | + ...contractConfigs.klerosCore, |
| 98 | + ...clientConfig, |
| 99 | + }); |
| 100 | + break; |
60 | 101 | default: |
61 | | - throw new Error(`Unsupported chainId: ${chainId}`); |
| 102 | + throw new Error(`Unsupported deployment: ${deployment}`); |
62 | 103 | } |
| 104 | + return { |
| 105 | + klerosCore, |
| 106 | + }; |
63 | 107 | }; |
64 | | - |
65 | | -// TODO: do the same for Viem ? |
|
0 commit comments