forked from taikoxyz/taiko-mono
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.ts
83 lines (68 loc) · 2.37 KB
/
main.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
import { Config } from "./interface";
const fs = require("fs");
const path = require("path");
const { ethers } = require("ethers");
const { deployTaikoL2 } = require("./taikoL2");
const { deployERC20 } = require("./erc20");
// Generate a L2 genesis JSON based on the given configurations.
// ref: https://docs.soliditylang.org/en/latest/internals/layout_in_storage.html
async function main() {
if (process.argv.length < 3) {
throw new Error("missing config json");
}
const config: Config = require(path.isAbsolute(process.argv[2])
? process.argv[2]
: path.join(process.cwd(), process.argv[2]));
const contractOwner = config.contractOwner;
const chainId = config.chainId;
const seedAccounts = config.seedAccounts;
const predeployERC20 = config.predeployERC20;
if (
!ethers.utils.isAddress(contractOwner) ||
!Number.isInteger(chainId) ||
!Array.isArray(seedAccounts) ||
!seedAccounts.every((seedAccount) => {
return (
Object.keys(seedAccount).length === 1 &&
ethers.utils.isAddress(Object.keys(seedAccount)[0]) &&
Number.isInteger(Object.values(seedAccount)[0])
);
}) ||
typeof predeployERC20 !== "boolean"
) {
throw new Error(
`invalid input: ${JSON.stringify({
contractOwner,
chainId,
seedAccounts,
})}`
);
}
console.log("config: %o", config);
console.log("start deploy ProxiedTaikoL2 contract");
let result = await deployTaikoL2(config, {
alloc: {},
storageLayouts: {},
});
if (config.predeployERC20) {
console.log("start deploy an ERC-20 token");
result = await deployERC20(config, result);
}
const allocSavedPath = path.join(
__dirname,
"../../deployments/genesis_alloc.json"
);
fs.writeFileSync(allocSavedPath, JSON.stringify(result.alloc, null, 2));
const layoutSavedPath = path.join(
__dirname,
"../../deployments/genesis_storage_layout.json"
);
fs.writeFileSync(
layoutSavedPath,
JSON.stringify(result.storageLayouts, null, 2)
);
console.log("done");
console.log(`alloc JSON saved to ${allocSavedPath}`);
console.log(`layout JSON saved to ${layoutSavedPath}`);
}
main().catch(console.error);