-
Notifications
You must be signed in to change notification settings - Fork 43
/
wagmi.config.ts
114 lines (99 loc) · 3.75 KB
/
wagmi.config.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
import { readdir, readFile } from "fs/promises";
import { parse, join } from "path";
import { Chain } from "@wagmi/chains";
import { type Config, type ContractConfig, defineConfig } from "@wagmi/cli";
import { react, actions } from "@wagmi/cli/plugins";
import dotenv from "dotenv";
import { type Abi } from "viem";
import IArbitrableV2 from "@kleros/kleros-v2-contracts/artifacts/src/arbitration/interfaces/IArbitrableV2.sol/IArbitrableV2.json" assert { type: "json" };
import IHomeGateway from "@kleros/kleros-v2-contracts/artifacts/src/gateway/interfaces/IHomeGateway.sol/IHomeGateway.json" assert { type: "json" };
import { ArbitratorTypes, getArbitratorType } from "consts/arbitratorTypes";
dotenv.config();
type ArtifactPartial = {
abi: Abi;
};
const getAbi = (artifact: any) => {
return (artifact as ArtifactPartial).abi;
};
const readArtifacts = async (type: ArbitratorTypes, viemChainName: string, hardhatChainName?: string) => {
const artifactSuffix =
type === ArbitratorTypes.vanilla
? ""
: ArbitratorTypes[type].toString().charAt(0).toUpperCase() + ArbitratorTypes[type].toString().slice(1);
const vanillaArtifacts = ["KlerosCore", "DisputeKitClassic", "SortitionModule", "DisputeResolver"];
const typeSpecificArtifacts = vanillaArtifacts.map((artifact) => `${artifact}${artifactSuffix}`);
const chains = await import("wagmi/chains");
const chain = chains[viemChainName] as Chain;
if (!chain) {
throw new Error(`Viem chain ${viemChainName} not found`);
}
const directoryPath = `../contracts/deployments/${hardhatChainName ?? viemChainName}`;
const files = await readdir(directoryPath);
const results: ContractConfig[] = [];
for (const file of files) {
const { name, ext } = parse(file);
if (ext === ".json") {
let nameWithoutSuffix = name;
if (vanillaArtifacts.some((artifact) => name.startsWith(artifact))) {
if (!typeSpecificArtifacts.includes(name)) {
// console.debug(`Skipping ${name} for deployment type ${ArbitratorTypes[type]}`);
continue;
}
if (type !== ArbitratorTypes.vanilla) {
nameWithoutSuffix = name.slice(0, -artifactSuffix.length);
// console.debug(`Using ${nameWithoutSuffix} instead of ${name}`);
}
}
const filePath = join(directoryPath, file);
const fileContent = await readFile(filePath, "utf-8");
const jsonContent = JSON.parse(fileContent);
results.push({
name: nameWithoutSuffix,
address: {
[chain.id]: jsonContent.address as `0x{string}`,
},
abi: jsonContent.abi,
});
}
}
return results;
};
const getConfig = async (): Promise<Config> => {
const deployment = process.env.REACT_APP_DEPLOYMENT ?? "testnet";
const type = getArbitratorType(process.env.REACT_APP_ARBITRATOR_TYPE?.toLowerCase() as keyof typeof ArbitratorTypes);
let viemNetwork: string;
let hardhatNetwork: string;
switch (deployment) {
case "devnet":
viemNetwork = "arbitrumSepolia";
hardhatNetwork = "arbitrumSepoliaDevnet";
break;
case "testnet":
viemNetwork = "arbitrumSepolia";
hardhatNetwork = "arbitrumSepolia";
break;
case "mainnet":
viemNetwork = "arbitrum";
hardhatNetwork = "arbitrum";
break;
default:
throw new Error(`Unknown deployment ${deployment}`);
}
const deploymentContracts = await readArtifacts(type, viemNetwork, hardhatNetwork);
return {
out: "src/hooks/contracts/generated.ts",
contracts: [
...deploymentContracts,
{
name: "IHomeGateway",
abi: getAbi(IHomeGateway),
},
{
name: "IArbitrableV2",
abi: getAbi(IArbitrableV2),
},
],
plugins: [react(), actions()],
};
};
export default defineConfig(getConfig);