-
Notifications
You must be signed in to change notification settings - Fork 1
/
wagmi.config.ts
81 lines (72 loc) · 2.04 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
import { defineConfig, loadEnv } from "@wagmi/cli";
import { fetch, actions } from "@wagmi/cli/plugins";
import fs from "fs";
type RawJson = {
[k: string]: {
[contractName: string]: string;
};
};
const env = loadEnv({
mode: process.env.NODE_ENV,
envDir: process.cwd(),
});
const rawJson: RawJson = JSON.parse(
fs.readFileSync("./scripts/download-json.json").toString(),
);
type Contracts = Array<{
name: string;
address: string;
url: string;
}>;
const ignore = env.SYNC_CONTRACTS_IGNORE.split(";");
const contracts: Contracts = [
{
name: "ERC20",
address: "0x0000000000000000000000000000000000387719", // Dummy address, will be overridden on every call
url: `https://raw.githubusercontent.com/hashgraph/hedera-accelerator-defi-eip/main/data/abis/ERC20.json`,
},
];
for (const key in rawJson) {
for (const contractName in rawJson[key]) {
!ignore.includes(contractName) &&
contracts.push({
name: contractName,
address: rawJson[key][contractName],
url: `${env.SYNC_CONTRACTS_ABI_PATH}/${contractName}.json`,
});
}
}
export default defineConfig({
out: "src/services/contracts/wagmiGenActions.ts",
plugins: [
actions(),
fetch({
cacheDuration: 1,
contracts: contracts.map((item) => ({
name: item.name,
address: item.address as `0x${string}`,
})),
async parse({ response }) {
try {
if (response.status === 404)
throw new Error("Contract abi .json file fetch failed - Not Found");
const json = await response.json();
if (json.status === "0") throw new Error(JSON.stringify(response));
return json.abi;
} catch (e) {
console.error(e);
throw new Error(JSON.stringify(e));
}
},
request(contract) {
const url = contracts.find(
(item) => item.address === contract.address,
)?.url;
if (!url) throw new Error("Cannot find url for " + contract.address);
return {
url,
};
},
}),
],
});