-
Notifications
You must be signed in to change notification settings - Fork 357
/
deploy-consensus-registry.ts
90 lines (77 loc) · 3.28 KB
/
deploy-consensus-registry.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
import { Command } from "commander";
import { ethers } from "ethers";
import { computeL2Create2Address, create2DeployFromL2 } from "./utils";
import { Interface } from "ethers/lib/utils";
import { ethTestConfig } from "./deploy-utils";
import * as hre from "hardhat";
import { Provider, Wallet } from "zksync-ethers";
const I_TRANSPARENT_UPGRADEABLE_PROXY_ARTIFACT = hre.artifacts.readArtifactSync("ITransparentUpgradeableProxy");
const TRANSPARENT_UPGRADEABLE_PROXY_ARTIFACT = hre.artifacts.readArtifactSync("TransparentUpgradeableProxy");
const CONSENSUS_REGISTRY_ARTIFACT = hre.artifacts.readArtifactSync("ConsensusRegistry");
const PROXY_ADMIN_ARTIFACT = hre.artifacts.readArtifactSync("ConsensusRegistry");
const CONSENSUS_REGISTRY_INTERFACE = new Interface(CONSENSUS_REGISTRY_ARTIFACT.abi);
const I_TRANSPARENT_UPGRADEABLE_PROXY_INTERFACE = new Interface(I_TRANSPARENT_UPGRADEABLE_PROXY_ARTIFACT.abi);
// Script to deploy the consensus registry contract and output its address.
// Note, that this script expects that the L2 contracts have been compiled PRIOR
// to running this script.
async function main() {
const program = new Command();
program
.version("0.1.0")
.name("deploy-consensus-registry")
.description("Deploys the consensus registry contract to L2");
program.option("--private-key <private-key>").action(async (cmd) => {
const zksProvider = new Provider(process.env.API_WEB3_JSON_RPC_HTTP_URL);
const deployWallet = cmd.privateKey
? new Wallet(cmd.privateKey, zksProvider)
: Wallet.fromMnemonic(
process.env.MNEMONIC ? process.env.MNEMONIC : ethTestConfig.mnemonic,
"m/44'/60'/0'/0/1"
).connect(zksProvider);
console.log(`Using deployer wallet: ${deployWallet.address}`);
// Deploy Consensus Registry contract
const consensusRegistryImplementation = await computeL2Create2Address(
deployWallet,
CONSENSUS_REGISTRY_ARTIFACT.bytecode,
"0x",
ethers.constants.HashZero
);
await create2DeployFromL2(deployWallet, CONSENSUS_REGISTRY_ARTIFACT.bytecode, "0x", ethers.constants.HashZero);
// Deploy Proxy Admin contract
const proxyAdminContract = await computeL2Create2Address(
deployWallet,
PROXY_ADMIN_ARTIFACT.bytecode,
"0x",
ethers.constants.HashZero
);
await create2DeployFromL2(deployWallet, PROXY_ADMIN_ARTIFACT.bytecode, "0x", ethers.constants.HashZero);
const proxyInitializationParams = CONSENSUS_REGISTRY_INTERFACE.encodeFunctionData("initialize", [
deployWallet.address,
]);
const proxyConstructor = I_TRANSPARENT_UPGRADEABLE_PROXY_INTERFACE.encodeDeploy([
consensusRegistryImplementation,
proxyAdminContract,
proxyInitializationParams,
]);
await create2DeployFromL2(
deployWallet,
TRANSPARENT_UPGRADEABLE_PROXY_ARTIFACT.bytecode,
proxyConstructor,
ethers.constants.HashZero
);
const address = computeL2Create2Address(
deployWallet,
TRANSPARENT_UPGRADEABLE_PROXY_ARTIFACT.bytecode,
proxyConstructor,
ethers.constants.HashZero
);
console.log(`CONTRACTS_L2_CONSENSUS_REGISTRY_ADDR=${address}`);
});
await program.parseAsync(process.argv);
}
main()
.then(() => process.exit(0))
.catch((err) => {
console.error("Error:", err);
process.exit(1);
});