forked from matter-labs/zksync
-
Notifications
You must be signed in to change notification settings - Fork 0
/
upgrade-testnet.ts
136 lines (121 loc) · 5.19 KB
/
upgrade-testnet.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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
import { ArgumentParser } from 'argparse';
import { ethers, Wallet } from 'ethers';
import { Deployer } from '../src.ts/deploy';
import { formatUnits, parseUnits } from 'ethers/lib/utils';
import * as fs from 'fs';
import * as path from 'path';
import { web3Provider } from './utils';
const provider = web3Provider();
const testConfigPath = path.join(process.env.ZKSYNC_HOME as string, `etc/test_config/constant`);
const ethTestConfig = JSON.parse(fs.readFileSync(`${testConfigPath}/eth.json`, { encoding: 'utf-8' }));
(async () => {
const parser = new ArgumentParser({
version: '0.1.0',
addHelp: true,
description: 'Deploy new contracts and upgrade testnet proxy Tesseracts'
});
parser.addArgument('--deployerPrivateKey', { required: false, help: 'Wallet used to deploy contracts.' });
parser.addArgument('--governor', { required: false, help: 'governor address' });
parser.addArgument('--contracts', {
required: false,
help: 'Contracts to upgrade (one or more comma-separated): Governance,Verifier,ZkSync, or all by default.',
defaultValue: 'Governance,Verifier,ZkSync'
});
parser.addArgument('--initArgs', {
required: false,
help:
'Upgrade function parameters comma-separated, RLP serialized in hex (Governance,Verifier,ZkSync): 0xaa..aa,0xbb..bb,0xcc..c or zero by default.',
defaultValue: '0x,0x,0x'
});
parser.addArgument('--cancelPreviousUpgrade', {
required: false,
help: 'cancels pending upgrade',
action: 'storeTrue'
});
parser.addArgument('--gasPrice', { required: false, help: 'Gas price in GWei.' });
parser.addArgument('--nonce', { required: false, help: 'nonce (requires --contract argument)' });
const args = parser.parseArgs(process.argv.slice(2));
const wallet = args.deployerPrivateKey
? new Wallet(args.deployerPrivateKey, provider)
: Wallet.fromMnemonic(ethTestConfig.mnemonic, "m/44'/60'/0'/0/1").connect(provider);
const gasPrice = args.gasPrice ? parseUnits(args.gasPrice, 'gwei') : await provider.getGasPrice();
console.info(`Using gas price: ${formatUnits(gasPrice, 'gwei')} gwei`);
if (args.nonce) {
console.info(`Using nonce: ${args.nonce}`);
}
const governorAddress = args.governor ? args.governor : wallet.address;
console.info(`Deploying for governor: ${governorAddress}`);
const deployer = new Deployer({ deployWallet: wallet, governorAddress, verbose: true });
console.info(`Upgrading ${args.contracts} contracts`);
const upgradeTargets = [ethers.constants.AddressZero, ethers.constants.AddressZero, ethers.constants.AddressZero];
for (const contract of args.contracts.split(',')) {
if (contract !== 'Governance' && contract !== 'Verifier' && contract !== 'ZkSync') {
console.error(`Unknow upgrade target: ${contract}`);
process.exit(1);
}
if (contract === 'Governance') {
await deployer.deployGovernanceTarget({ gasPrice, nonce: args.nonce });
if (args.nonce != null) {
++args.nonce;
}
upgradeTargets[0] = deployer.addresses.GovernanceTarget;
}
if (contract === 'Verifier') {
await deployer.deployVerifierTarget({ gasPrice, nonce: args.nonce });
if (args.nonce != null) {
++args.nonce;
}
upgradeTargets[1] = deployer.addresses.VerifierTarget;
}
if (contract === 'ZkSync') {
await deployer.deployZkSyncTarget({ gasPrice, nonce: args.nonce });
if (args.nonce != null) {
++args.nonce;
}
upgradeTargets[2] = deployer.addresses.ZkSyncTarget;
}
}
const upgradeGatekeeper = deployer.upgradeGatekeeperContract(wallet);
if (args.cancelPreviousUpgrade) {
const cancelUpgradeTx = await upgradeGatekeeper.cancelUpgrade({
gasPrice,
gasLimit: 500000,
nonce: args.nonce
});
if (args.nonce != null) {
++args.nonce;
}
console.info(`Canceling pending upgrade: ${cancelUpgradeTx.hash}`);
await cancelUpgradeTx.wait();
console.info('Pending upgrade canceled');
}
const startUpgradeTx = await upgradeGatekeeper.startUpgrade(upgradeTargets, {
gasPrice,
gasLimit: 500000,
nonce: args.nonce
});
if (args.nonce != null) {
++args.nonce;
}
console.info(`Upgrade started: ${startUpgradeTx.hash}`);
await startUpgradeTx.wait();
const startPreparationUpgradeTx = await upgradeGatekeeper.startPreparation({
gasPrice,
gasLimit: 500000,
nonce: args.nonce
});
if (args.nonce != null) {
++args.nonce;
}
console.info(`Upgrade preparation tx: ${startPreparationUpgradeTx.hash}`);
await startPreparationUpgradeTx.wait();
const initArgs = args.initArgs.split(',');
const finishUpgradeTx = await upgradeGatekeeper.finishUpgrade(initArgs, {
gasPrice,
gasLimit: 500000,
nonce: args.nonce
});
console.info(`Upgrade finish tx: ${finishUpgradeTx.hash}`);
await finishUpgradeTx.wait();
console.info('Upgrade successful');
})();