-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsafe-deployments.ts
78 lines (70 loc) · 2.2 KB
/
safe-deployments.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
import fs from "fs";
import path from "path";
import {
fetchDeployments,
MODULE_VERSION,
SAFE_VERSION,
} from "./fetch-deployments";
// Main function to fetch and write deployment data
export async function fetchAndWriteDeployments(
outPath: string = "src/_gen",
safeVersion: string = SAFE_VERSION,
moduleVersion: string = MODULE_VERSION
): Promise<void> {
const { singleton, proxyFactory, moduleSetup, m4337, entryPoint } =
await fetchDeployments(safeVersion, moduleVersion);
try {
// Specify output file path
const outputPath = path.join(process.cwd(), outPath, "deployments.ts");
// const outputPath = path.join(
// process.cwd(),
// outPath,
// `safe_v${safeVersion}_module_v${moduleVersion}.json`
// );
// Ensure the directory exists
if (!fs.existsSync(path.dirname(outputPath))) {
fs.mkdirSync(path.dirname(outputPath), { recursive: true });
}
// Write deployment data to file
// fs.writeFileSync(outputPath, JSON.stringify(deployments, null, 2));
const tsContent = `
// Auto-generated file from build script
import { SafeDeployments } from "../types";
export const SAFE_DEPLOYMENTS: SafeDeployments = {
singleton: {
address: "${singleton.address}",
abi: ${JSON.stringify(singleton.abi, null, 2)},
},
proxyFactory: {
address: "${proxyFactory.address}",
abi: ${JSON.stringify(proxyFactory.abi, null, 2)},
},
moduleSetup: {
address: "${moduleSetup.address}",
abi: ${JSON.stringify(moduleSetup.abi, null, 2)},
},
m4337: {
address: "${m4337.address}",
abi: ${JSON.stringify(m4337.abi, null, 2)},
},
entryPoint: {
address: "${entryPoint.address}",
abi: ${JSON.stringify(entryPoint.abi, null, 2)},
},
};
`;
fs.writeFileSync(outputPath, tsContent, "utf-8");
console.log(
`TypeScript constants generated at ${path.join(outPath, "deployments.ts")}`
);
} catch (error) {
console.error("Error fetching deployments:", error);
}
}
async function main(): Promise<void> {
await fetchAndWriteDeployments();
}
main().catch((err) => {
console.error(err);
process.exitCode = 1;
});