-
Notifications
You must be signed in to change notification settings - Fork 327
/
Copy pathindex.ts
411 lines (392 loc) · 14.7 KB
/
index.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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
import { EthAddress } from '@aztec/foundation/eth-address';
import { type DebugLogger, type LogFn } from '@aztec/foundation/log';
import { type Command, Option } from 'commander';
import {
ETHEREUM_HOST,
PRIVATE_KEY,
l1ChainIdOption,
makePxeOption,
parseAztecAddress,
parseBigint,
parseEthereumAddress,
pxeOption,
} from '../../utils/commands.js';
export function injectCommands(program: Command, log: LogFn, debugLogger: DebugLogger) {
const { BB_BINARY_PATH, BB_WORKING_DIRECTORY } = process.env;
program
.command('deploy-l1-contracts')
.description('Deploys all necessary Ethereum contracts for Aztec.')
.requiredOption(
'-u, --rpc-url <string>',
'Url of the ethereum host. Chain identifiers localhost and testnet can be used',
ETHEREUM_HOST,
)
.option('-pk, --private-key <string>', 'The private key to use for deployment', PRIVATE_KEY)
.option('--validators <string>', 'Comma separated list of validators')
.option(
'-m, --mnemonic <string>',
'The mnemonic to use in deployment',
'test test test test test test test test test test test junk',
)
.addOption(l1ChainIdOption)
.option('--salt <number>', 'The optional salt to use in deployment', arg => parseInt(arg))
.option('--json', 'Output the contract addresses in JSON format')
.action(async options => {
const { deployL1Contracts } = await import('./deploy_l1_contracts.js');
const initialValidators =
options.validators?.split(',').map((validator: string) => EthAddress.fromString(validator)) || [];
await deployL1Contracts(
options.rpcUrl,
options.l1ChainId,
options.privateKey,
options.mnemonic,
options.salt,
options.json,
initialValidators,
log,
debugLogger,
);
});
program
.command('generate-l1-account')
.description('Generates a new private key for an account on L1.')
.option('--json', 'Output the private key in JSON format')
.action(async () => {
const { generateL1Account } = await import('./update_l1_validators.js');
const account = generateL1Account();
log(JSON.stringify(account, null, 2));
});
program
.command('add-l1-validator')
.description('Adds a validator to the L1 rollup contract.')
.requiredOption(
'-u, --rpc-url <string>',
'Url of the ethereum host. Chain identifiers localhost and testnet can be used',
ETHEREUM_HOST,
)
.option('-pk, --private-key <string>', 'The private key to use for deployment', PRIVATE_KEY)
.option(
'-m, --mnemonic <string>',
'The mnemonic to use in deployment',
'test test test test test test test test test test test junk',
)
.addOption(l1ChainIdOption)
.option('--validator <addresse>', 'ethereum address of the validator', parseEthereumAddress)
.option('--rollup <address>', 'ethereum address of the rollup contract', parseEthereumAddress)
.action(async options => {
const { addL1Validator } = await import('./update_l1_validators.js');
await addL1Validator({
rpcUrl: options.rpcUrl,
chainId: options.l1ChainId,
privateKey: options.privateKey,
mnemonic: options.mnemonic,
validatorAddress: options.validator,
rollupAddress: options.rollup,
log,
debugLogger,
});
});
program
.command('remove-l1-validator')
.description('Removes a validator to the L1 rollup contract.')
.requiredOption(
'-u, --rpc-url <string>',
'Url of the ethereum host. Chain identifiers localhost and testnet can be used',
ETHEREUM_HOST,
)
.option('-pk, --private-key <string>', 'The private key to use for deployment', PRIVATE_KEY)
.option(
'-m, --mnemonic <string>',
'The mnemonic to use in deployment',
'test test test test test test test test test test test junk',
)
.addOption(l1ChainIdOption)
.option('--validator <address>', 'ethereum address of the validator', parseEthereumAddress)
.option('--rollup <address>', 'ethereum address of the rollup contract', parseEthereumAddress)
.action(async options => {
const { removeL1Validator } = await import('./update_l1_validators.js');
await removeL1Validator({
rpcUrl: options.rpcUrl,
chainId: options.l1ChainId,
privateKey: options.privateKey,
mnemonic: options.mnemonic,
validatorAddress: options.validator,
rollupAddress: options.rollup,
log,
debugLogger,
});
});
program
.command('fast-forward-epochs')
.description('Fast forwards the epoch of the L1 rollup contract.')
.requiredOption(
'-u, --rpc-url <string>',
'Url of the ethereum host. Chain identifiers localhost and testnet can be used',
ETHEREUM_HOST,
)
.addOption(l1ChainIdOption)
.option('--rollup <address>', 'ethereum address of the rollup contract', parseEthereumAddress)
.option('--count <number>', 'The number of epochs to fast forward', arg => BigInt(parseInt(arg)), 1n)
.action(async options => {
const { fastForwardEpochs } = await import('./update_l1_validators.js');
await fastForwardEpochs({
rpcUrl: options.rpcUrl,
chainId: options.l1ChainId,
rollupAddress: options.rollup,
numEpochs: options.count,
log,
debugLogger,
});
});
program
.command('debug-rollup')
.description('Debugs the rollup contract.')
.requiredOption(
'-u, --rpc-url <string>',
'Url of the ethereum host. Chain identifiers localhost and testnet can be used',
ETHEREUM_HOST,
)
.addOption(l1ChainIdOption)
.option('--rollup <address>', 'ethereum address of the rollup contract', parseEthereumAddress)
.action(async options => {
const { debugRollup } = await import('./update_l1_validators.js');
await debugRollup({
rpcUrl: options.rpcUrl,
chainId: options.l1ChainId,
privateKey: options.privateKey,
mnemonic: options.mnemonic,
rollupAddress: options.rollup,
log,
debugLogger,
});
});
program
.command('prune-rollup')
.description('Prunes the pending chain on the rollup contract.')
.requiredOption(
'-u, --rpc-url <string>',
'Url of the ethereum host. Chain identifiers localhost and testnet can be used',
ETHEREUM_HOST,
)
.option('-pk, --private-key <string>', 'The private key to use for deployment', PRIVATE_KEY)
.option(
'-m, --mnemonic <string>',
'The mnemonic to use in deployment',
'test test test test test test test test test test test junk',
)
.addOption(l1ChainIdOption)
.option('--rollup <address>', 'ethereum address of the rollup contract', parseEthereumAddress)
.action(async options => {
const { pruneRollup } = await import('./update_l1_validators.js');
await pruneRollup({
rpcUrl: options.rpcUrl,
chainId: options.l1ChainId,
privateKey: options.privateKey,
mnemonic: options.mnemonic,
rollupAddress: options.rollup,
log,
debugLogger,
});
});
program
.command('deploy-l1-verifier')
.description('Deploys the rollup verifier contract')
.requiredOption(
'--l1-rpc-url <string>',
'Url of the ethereum host. Chain identifiers localhost and testnet can be used',
ETHEREUM_HOST,
)
.addOption(
new Option('--l1-chain-id <string>', 'The chain id of the L1 network')
.env('L1_CHAIN_ID')
.default('31337')
.makeOptionMandatory(true),
)
.addOption(makePxeOption(false).conflicts('rollup-address'))
.addOption(
new Option('--rollup-address <string>', 'The address of the rollup contract')
.env('ROLLUP_CONTRACT_ADDRESS')
.argParser(parseEthereumAddress)
.conflicts('rpc-url'),
)
.option('--l1-private-key <string>', 'The L1 private key to use for deployment', PRIVATE_KEY)
.option(
'-m, --mnemonic <string>',
'The mnemonic to use in deployment',
'test test test test test test test test test test test junk',
)
.requiredOption('--verifier <verifier>', 'Either mock or real', 'real')
.option('--bb <path>', 'Path to bb binary', BB_BINARY_PATH)
.option('--bb-working-dir <path>', 'Path to bb working directory', BB_WORKING_DIRECTORY)
.action(async options => {
const { deployMockVerifier, deployUltraHonkVerifier } = await import('./deploy_l1_verifier.js');
if (options.verifier === 'mock') {
await deployMockVerifier(
options.rollupAddress?.toString(),
options.l1RpcUrl,
options.l1ChainId,
options.l1PrivateKey,
options.mnemonic,
options.rpcUrl,
log,
debugLogger,
);
} else {
await deployUltraHonkVerifier(
options.rollupAddress?.toString(),
options.l1RpcUrl,
options.l1ChainId,
options.l1PrivateKey,
options.mnemonic,
options.rpcUrl,
options.bb,
options.bbWorkingDir,
log,
debugLogger,
);
}
});
program
.command('bridge-erc20')
.description('Bridges ERC20 tokens to L2.')
.argument('<amount>', 'The amount of Fee Juice to mint and bridge.', parseBigint)
.argument('<recipient>', 'Aztec address of the recipient.', parseAztecAddress)
.requiredOption(
'--l1-rpc-url <string>',
'Url of the ethereum host. Chain identifiers localhost and testnet can be used',
ETHEREUM_HOST,
)
.option(
'-m, --mnemonic <string>',
'The mnemonic to use for deriving the Ethereum address that will mint and bridge',
'test test test test test test test test test test test junk',
)
.option('--mint', 'Mint the tokens on L1', false)
.option('--private', 'If the bridge should use the private flow', false)
.addOption(l1ChainIdOption)
.requiredOption('-t, --token <string>', 'The address of the token to bridge', parseEthereumAddress)
.requiredOption('-p, --portal <string>', 'The address of the portal contract', parseEthereumAddress)
.option('--l1-private-key <string>', 'The private key to use for deployment', PRIVATE_KEY)
.option('--json', 'Output the claim in JSON format')
.action(async (amount, recipient, options) => {
const { bridgeERC20 } = await import('./bridge_erc20.js');
await bridgeERC20(
amount,
recipient,
options.l1RpcUrl,
options.l1ChainId,
options.l1PrivateKey,
options.mnemonic,
options.token,
options.portal,
options.private,
options.mint,
options.json,
log,
debugLogger,
);
});
program
.command('create-l1-account')
.option('--json', 'Output the account in JSON format')
.action(async options => {
const { createL1Account } = await import('./create_l1_account.js');
createL1Account(options.json, log);
});
program
.command('get-l1-balance')
.description('Gets the balance of an ERC token in L1 for the given Ethereum address.')
.argument('<who>', 'Ethereum address to check.', parseEthereumAddress)
.requiredOption(
'--l1-rpc-url <string>',
'Url of the ethereum host. Chain identifiers localhost and testnet can be used',
ETHEREUM_HOST,
)
.option('-t, --token <string>', 'The address of the token to check the balance of', parseEthereumAddress)
.addOption(l1ChainIdOption)
.option('--json', 'Output the balance in JSON format')
.action(async (who, options) => {
const { getL1Balance } = await import('./get_l1_balance.js');
await getL1Balance(who, options.token, options.l1RpcUrl, options.l1ChainId, options.json, log);
});
program
.command('set-proven-through', { hidden: true })
.description(
'Instructs the L1 rollup contract to assume all blocks until the given number are automatically proven.',
)
.argument('[blockNumber]', 'The target block number, defaults to the latest pending block number.', parseBigint)
.requiredOption(
'--l1-rpc-url <string>',
'Url of the ethereum host. Chain identifiers localhost and testnet can be used',
ETHEREUM_HOST,
)
.addOption(pxeOption)
.option(
'-m, --mnemonic <string>',
'The mnemonic to use for deriving the Ethereum address that will mint and bridge',
'test test test test test test test test test test test junk',
)
.addOption(l1ChainIdOption)
.option('--l1-private-key <string>', 'The private key to use for deployment', PRIVATE_KEY)
.action(async (blockNumber, options) => {
const { assumeProvenThrough } = await import('./assume_proven_through.js');
await assumeProvenThrough(
blockNumber,
options.l1RpcUrl,
options.rpcUrl,
options.l1ChainId,
options.l1PrivateKey,
options.mnemonic,
log,
);
});
program
.command('advance-epoch')
.description('Use L1 cheat codes to warp time until the next epoch.')
.requiredOption(
'--l1-rpc-url <string>',
'Url of the ethereum host. Chain identifiers localhost and testnet can be used',
ETHEREUM_HOST,
)
.addOption(pxeOption)
.action(async options => {
const { advanceEpoch } = await import('./advance_epoch.js');
await advanceEpoch(options.l1RpcUrl, options.rpcUrl, log);
});
program
.command('prover-stats', { hidden: true })
.requiredOption(
'--l1-rpc-url <string>',
'Url of the ethereum host. Chain identifiers localhost and testnet can be used',
ETHEREUM_HOST,
)
.addOption(l1ChainIdOption)
.option('--start-block <number>', 'The L1 block number to start from', parseBigint, 1n)
.option('--end-block <number>', 'The last L1 block number to query', parseBigint)
.option('--batch-size <number>', 'The number of blocks to query in each batch', parseBigint, 100n)
.option('--proving-timeout <number>', 'Cutoff for proving time to consider a block', parseBigint)
.option('--l1-rollup-address <string>', 'Address of the rollup contract (required if node URL is not set)')
.option(
'--node-url <string>',
'JSON RPC URL of an Aztec node to retrieve the rollup contract address (required if L1 rollup address is not set)',
)
.option('--raw-logs', 'Output raw logs instead of aggregated stats')
.action(async options => {
const { proverStats } = await import('./prover_stats.js');
const { l1RpcUrl, chainId, l1RollupAddress, startBlock, endBlock, batchSize, nodeUrl, provingTimeout, rawLogs } =
options;
await proverStats({
l1RpcUrl,
chainId,
l1RollupAddress,
startBlock,
endBlock,
batchSize,
nodeUrl,
provingTimeout,
rawLogs,
log,
});
});
return program;
}