forked from chainbound/bolt
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli.rs
More file actions
630 lines (550 loc) · 21.1 KB
/
cli.rs
File metadata and controls
630 lines (550 loc) · 21.1 KB
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
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
use std::path::PathBuf;
use alloy::{
primitives::{Address, FixedBytes, B256, U256},
providers::Provider,
transports::Transport,
};
use clap::{
builder::styling::{AnsiColor, Color, Style},
Parser, Subcommand, ValueEnum,
};
use reqwest::Url;
use crate::common::{keystore::DEFAULT_KEYSTORE_PASSWORD, parse_ether_value};
/// `bolt` is a CLI tool to interact with bolt Protocol ✨
#[derive(Parser, Debug, Clone)]
#[command(author, version, styles = cli_styles(), about, arg_required_else_help(true))]
pub struct Opts {
/// The subcommand to run.
#[clap(subcommand)]
pub command: Cmd,
}
#[derive(Subcommand, Debug, Clone)]
pub enum Cmd {
/// Generate BLS delegation or revocation messages.
Delegate(DelegateCommand),
/// Output a list of pubkeys in JSON format.
Pubkeys(PubkeysCommand),
/// Send a preconfirmation request to a bolt proposer.
Send(Box<SendCommand>),
/// Handle validators in the bolt network.
Validators(ValidatorsCommand),
/// Handle operators in the bolt network.
Operators(OperatorsCommand),
/// Useful data generation commands.
Generate(GenerateCommand),
/// Output the pubkey hash of a BLS public key.
#[clap(hide = true)]
PubkeyHash(PubkeyHashCommand),
}
impl Cmd {
/// Run the command.
pub async fn run(self) -> eyre::Result<()> {
match self {
Self::Delegate(cmd) => cmd.run().await,
Self::Pubkeys(cmd) => cmd.run().await,
Self::Send(cmd) => cmd.run().await,
Self::Validators(cmd) => cmd.run().await,
Self::Operators(cmd) => cmd.run().await,
Self::Generate(cmd) => cmd.run(),
Self::PubkeyHash(cmd) => cmd.run(),
}
}
}
/// Command for generating BLS delegation or revocation messages.
#[derive(Debug, Clone, Parser)]
pub struct DelegateCommand {
/// The BLS public key to which the delegation message should be signed.
#[clap(long, env = "DELEGATEE_PUBKEY")]
pub delegatee_pubkey: String,
/// The output file for the delegations.
#[clap(long, env = "OUTPUT_FILE_PATH", default_value = "delegations.json")]
pub out: String,
/// The chain for which the delegation message is intended.
#[clap(long, env = "CHAIN")]
pub chain: Chain,
/// The action to perform. The tool can be used to generate
/// delegation or revocation messages (default: delegate).
#[clap(long, env = "ACTION", default_value = "delegate")]
pub action: Action,
/// The source of the private key.
#[clap(subcommand)]
pub source: KeysSource,
}
/// Command for outputting a list of pubkeys in JSON format.
#[derive(Debug, Clone, Parser)]
pub struct PubkeysCommand {
/// The output file for the pubkeys.
#[clap(long, env = "OUTPUT_FILE_PATH", default_value = "pubkeys.json")]
pub out: String,
/// The source of the private keys from which to extract the pubkeys.
#[clap(subcommand)]
pub source: KeysSource,
}
/// Command for sending a preconfirmation request to a bolt proposer.
#[derive(Debug, Clone, Parser)]
pub struct SendCommand {
/// bolt RPC URL to send requests to and fetch lookahead info from.
///
/// Leaving this empty will default to the canonical bolt RPC URL, which
/// automatically manages increasing nonces on preconfirmed state.
#[clap(long, env = "BOLT_RPC_URL", default_value = "https://rpc.holesky.boltprotocol.xyz")]
pub bolt_rpc_url: Url,
/// The private key to sign the transaction with.
#[clap(long, env = "PRIVATE_KEY", hide_env_values = true)]
pub private_key: String,
/// The bolt Sidecar URL to send requests to. If provided, this will override
/// the canonical bolt RPC URL and disregard any registration information.
///
/// This is useful for testing and development purposes.
#[clap(long, env = "OVERRIDE_BOLT_SIDECAR_URL")]
pub override_bolt_sidecar_url: Option<Url>,
/// How many transactions to send.
#[clap(long, env = "TRANSACTION_COUNT", default_value = "1")]
pub count: u32,
/// If set, the transaction will be blob-carrying (type 3)
#[clap(long, env = "BLOB", default_value = "false")]
pub blob: bool,
/// The max fee per gas in gwei.
#[clap(long, env = "MAX_FEE")]
pub max_fee: Option<u128>,
/// The max priority fee per gas in gwei.
#[clap(long, env = "PRIORITY_FEE", default_value = "2")]
pub priority_fee: u128,
/// If set, the transaction will target the devnet environment.
/// This is only used in Kurtosis for internal testing purposes
#[clap(long, hide = true, env = "DEVNET", default_value = "false")]
pub devnet: bool,
/// The URL of the devnet execution client for filling transactions
#[clap(long = "devnet.execution_url", hide = true)]
pub devnet_execution_url: Option<Url>,
/// The URL of the devnet beacon node for fetching slot numbers
#[clap(long = "devnet.beacon_url", hide = true)]
pub devnet_beacon_url: Option<Url>,
/// The URL of the devnet sidecar for sending transactions
#[clap(long = "devnet.sidecar_url", hide = true)]
pub devnet_sidecar_url: Option<Url>,
/// Toggle for using `eth_sendRawTransaction` instead of `bolt_requestInclusion`
#[clap(long, env = "RAW", default_value_t = false)]
pub raw: bool,
}
#[derive(Debug, Clone, Parser)]
pub struct ValidatorsCommand {
#[clap(subcommand)]
pub subcommand: ValidatorsSubcommand,
}
#[derive(Debug, Clone, Parser)]
pub enum ValidatorsSubcommand {
/// Register a batch of validators.
Register {
/// The URL of the RPC to broadcast the transaction.
#[clap(long, env = "RPC_URL")]
rpc_url: Url,
/// The max gas limit the validator is willing to reserve to commitments.
#[clap(long, env = "MAX_COMMITTED_GAS_LIMIT")]
max_committed_gas_limit: u32,
/// The authorized operator for the validator.
#[clap(long, env = "AUTHORIZED_OPERATOR")]
authorized_operator: Address,
/// The path to the JSON pubkeys file, containing an array of BLS public keys.
#[clap(long, env = "PUBKEYS_PATH", default_value = "pubkeys.json")]
pubkeys_path: PathBuf,
/// The private key to sign the transactions with.
#[clap(long, env = "ADMIN_PRIVATE_KEY")]
admin_private_key: B256,
/// Run the command in "dry run" mode, run all steps without broadcast.
/// Useful for testing and debugging purposes.
#[clap(short, long, env = "DRY_RUN", default_value = "false")]
dry_run: bool,
},
/// Check the status of a validator (batch).
Status {
/// The URL of the RPC to broadcast the transaction.
#[clap(long, env = "RPC_URL")]
rpc_url: Url,
/// The path to the JSON pubkeys file, containing an array of BLS public keys.
#[clap(long, env = "PUBKEYS_PATH", conflicts_with = "pubkeys")]
pubkeys_path: Option<PathBuf>,
/// The validator public key to check the status of.
#[clap(long, env = "PUBKEYS", conflicts_with = "pubkeys_path")]
pubkeys: Vec<FixedBytes<48>>,
},
}
#[derive(Debug, Clone, Parser)]
pub struct OperatorsCommand {
#[clap(subcommand)]
pub subcommand: OperatorsSubcommand,
}
#[derive(Debug, Clone, Parser)]
pub enum OperatorsSubcommand {
/// Commands to interact with EigenLayer and bolt.
#[clap(name = "eigenlayer", alias = "el")]
EigenLayer {
#[clap(subcommand)]
subcommand: EigenLayerSubcommand,
},
/// Commands to interact with Symbiotic and bolt.
#[clap(alias = "symb")]
Symbiotic {
#[clap(subcommand)]
subcommand: SymbioticSubcommand,
},
}
#[derive(Debug, Clone, Parser)]
pub enum EigenLayerSubcommand {
/// Deposit into a strategy.
Deposit {
/// The URL of the RPC to broadcast the transaction.
#[clap(long, env = "RPC_URL")]
rpc_url: Url,
/// The private key of the operator.
#[clap(long, env = "OPERATOR_PRIVATE_KEY")]
operator_private_key: B256,
/// The name of the strategy to deposit into.
#[clap(long, env = "EIGENLAYER_STRATEGY")]
strategy: Address,
/// The amount to deposit into the strategy, in units (e.g. '1ether', '10gwei').
#[clap(long, env = "EIGENLAYER_STRATEGY_DEPOSIT_AMOUNT", value_parser = parse_ether_value)]
amount: U256,
/// Run the command in "dry run" mode, run all steps without broadcast.
/// Useful for testing and debugging purposes.
#[clap(short, long, env = "DRY_RUN", default_value = "false")]
dry_run: bool,
},
/// Register an operator into the bolt AVS.
Register {
/// The URL of the RPC to broadcast the transaction.
#[clap(long, env = "RPC_URL")]
rpc_url: Url,
/// The private key of the operator.
#[clap(long, env = "OPERATOR_PRIVATE_KEY")]
operator_private_key: B256,
/// The URL of the operator RPC.
/// If not provided, the "bolt RPC" URL is used, which is
/// consistent with bolt-sidecars running in "firewall delegation" mode.
#[clap(long, env = "OPERATOR_RPC")]
operator_rpc: Option<Url>,
/// The operator's extra data string to be stored in the registry.
#[clap(long, env = "OPERATOR_EXTRA_DATA")]
extra_data: String,
/// The salt for the operator signature, to prevent replay attacks.
/// If not provided, a random value is used.
#[clap(long, env = "OPERATOR_SIGNATURE_SALT")]
salt: Option<B256>,
/// Run the command in "dry run" mode, run all steps without broadcast.
/// Useful for testing and debugging purposes.
#[clap(short, long, env = "DRY_RUN", default_value = "false")]
dry_run: bool,
},
/// Deregister an EigenLayer operator from the bolt AVS.
Deregister {
/// The URL of the RPC to broadcast the transaction.
#[clap(long, env = "RPC_URL")]
rpc_url: Url,
/// The private key of the operator.
#[clap(long, env = "OPERATOR_PRIVATE_KEY")]
operator_private_key: B256,
/// Run the command in "dry run" mode, run all steps without broadcast.
/// Useful for testing and debugging purposes.
#[clap(short, long, env = "DRY_RUN", default_value = "false")]
dry_run: bool,
},
/// Update the operator RPC.
UpdateRpc {
/// The URL of the RPC to broadcast the transaction.
#[clap(long, env = "RPC_URL")]
rpc_url: Url,
/// The private key of the operator.
#[clap(long, env = "OPERATOR_PRIVATE_KEY")]
operator_private_key: B256,
/// The URL of the operator RPC.
#[clap(long, env = "OPERATOR_RPC")]
operator_rpc: Url,
/// Run the command in "dry run" mode, run all steps without broadcast.
/// Useful for testing and debugging purposes.
#[clap(short, long, env = "DRY_RUN", default_value = "false")]
dry_run: bool,
},
/// Check the status of an operator in the bolt AVS.
Status {
/// The URL of the RPC to read data from
#[clap(long, env = "RPC_URL")]
rpc_url: Url,
/// The address of the operator to check.
#[clap(long, env = "OPERATOR_ADDRESS")]
address: Address,
},
/// List all whitelisted EigenLayer strategies
ListStrategies {
/// The URL of the RPC to read data from
#[clap(long, env = "RPC_URL")]
rpc_url: Url,
},
}
#[derive(Debug, Clone, Parser)]
pub enum SymbioticSubcommand {
/// Register into the bolt manager contract as a Symbiotic operator.
Register {
/// The URL of the RPC to broadcast the transaction.
#[clap(long, env = "RPC_URL")]
rpc_url: Url,
/// The private key of the operator.
#[clap(long, env = "OPERATOR_PRIVATE_KEY")]
operator_private_key: B256,
/// The URL of the operator RPC.
/// If not provided, the "bolt RPC" URL is used, which is
/// consistent with bolt-sidecars running in "firewall delegation" mode.
#[clap(long, env = "OPERATOR_RPC")]
operator_rpc: Option<Url>,
/// The operator's extra data string to be stored in the registry.
#[clap(long, env = "OPERATOR_EXTRA_DATA")]
extra_data: String,
/// Run the command in "dry run" mode, run all steps without broadcast.
/// Useful for testing and debugging purposes.
#[clap(short, long, env = "DRY_RUN", default_value = "false")]
dry_run: bool,
},
/// Deregister a Symbiotic operator from bolt.
Deregister {
/// The URL of the RPC to broadcast the transaction.
#[clap(long, env = "RPC_URL")]
rpc_url: Url,
/// The private key of the operator.
#[clap(long, env = "OPERATOR_PRIVATE_KEY")]
operator_private_key: B256,
/// Run the command in "dry run" mode, run all steps without broadcast.
/// Useful for testing and debugging purposes.
#[clap(short, long, env = "DRY_RUN", default_value = "false")]
dry_run: bool,
},
/// Update the operator RPC.
UpdateRpc {
/// The URL of the RPC to broadcast the transaction.
#[clap(long, env = "RPC_URL")]
rpc_url: Url,
/// The private key of the operator.
#[clap(long, env = "OPERATOR_PRIVATE_KEY")]
operator_private_key: B256,
/// The URL of the operator RPC.
#[clap(long, env = "OPERATOR_RPC")]
operator_rpc: Url,
/// Run the command in "dry run" mode, run all steps without broadcast.
/// Useful for testing and debugging purposes.
#[clap(short, long, env = "DRY_RUN", default_value = "false")]
dry_run: bool,
},
/// Check the status of a Symbiotic operator.
Status {
/// The URL of the RPC to broadcast the transaction.
#[clap(long, env = "RPC_URL")]
rpc_url: Url,
/// The address of the operator to check.
#[clap(long, env = "OPERATOR_ADDRESS")]
address: Address,
},
/// List all whitelisted Symbiotic vaults
ListVaults {
/// The URL of the RPC to read data from
#[clap(long, env = "RPC_URL")]
rpc_url: Url,
},
}
#[derive(Debug, Clone, Parser)]
pub struct GenerateCommand {
#[clap(subcommand)]
pub generate: GenerateSubcommand,
}
#[derive(Debug, Clone, Subcommand)]
pub enum GenerateSubcommand {
/// Generate a BLS keypair.
Bls,
}
#[derive(Debug, Clone, Parser)]
pub struct PubkeyHashCommand {
/// The BLS public key to hash.
#[clap(value_parser, env = "KEY")]
pub key: String,
}
/// The action to perform.
#[derive(Debug, Clone, Copy, ValueEnum)]
#[clap(rename_all = "kebab_case")]
pub enum Action {
/// Create a delegation message.
Delegate,
/// Create a revocation message.
Revoke,
}
#[derive(Debug, Clone, Parser)]
pub enum KeysSource {
/// Use local secret keys to generate the signed messages.
SecretKeys {
/// The private key in hex format.
/// Multiple secret keys must be seperated by commas.
#[clap(long, env = "SECRET_KEYS", value_delimiter = ',', hide_env_values = true)]
secret_keys: Vec<String>,
},
/// Use an EIP-2335 filesystem keystore directory to generate the signed messages.
LocalKeystore {
/// The options for reading the keystore directory.
#[clap(flatten)]
opts: LocalKeystoreOpts,
},
/// Use a remote DIRK keystore to generate the signed messages.
Dirk {
/// The options for connecting to the DIRK keystore.
#[clap(flatten)]
opts: DirkOpts,
},
/// Use a remote Web3Signer keystore to generate the signed messages.
#[clap(name = "web3signer")]
Web3Signer {
#[clap(flatten)]
opts: Web3SignerOpts,
},
}
/// Options for reading a keystore folder.
#[derive(Debug, Clone, Parser)]
pub struct LocalKeystoreOpts {
/// The path to the keystore file.
#[clap(long, env = "KEYSTORE_PATH", default_value = "validators")]
pub path: String,
/// The password for the keystore files in the path.
/// Assumes all keystore files have the same password.
#[clap(
long,
env = "KEYSTORE_PASSWORD",
hide_env_values = true,
default_value = DEFAULT_KEYSTORE_PASSWORD,
conflicts_with = "password_path"
)]
pub password: Option<String>,
#[clap(
long,
env = "KEYSTORE_PASSWORD_PATH",
default_value = "secrets",
conflicts_with = "password"
)]
pub password_path: Option<String>,
}
/// Options for connecting to a DIRK keystore.
#[derive(Debug, Clone, Parser)]
pub struct DirkOpts {
/// The URL of the DIRK keystore.
#[clap(long, env = "DIRK_URL")]
pub url: String,
/// The path of the wallets in the DIRK keystore.
#[clap(long, env = "DIRK_WALLET_PATH")]
pub wallet_path: String,
/// The passphrases to unlock the wallet in the DIRK keystore.
/// If multiple are provided, they are tried in order until one works.
#[clap(long, env = "DIRK_PASSPHRASES", value_delimiter = ',', hide_env_values = true)]
pub passphrases: Option<Vec<String>>,
/// The TLS credentials for connecting to the DIRK keystore.
#[clap(flatten)]
pub tls_credentials: DirkTlsCredentials,
}
/// Options for connecting to a Web3Signer keystore.
#[derive(Debug, Clone, Parser)]
pub struct Web3SignerOpts {
/// The URL of the Web3Signer keystore.
#[clap(long, env = "WEB3SIGNER_URL")]
pub url: String,
/// The TLS credentials for connecting to the Web3Signer keystore.
#[clap(flatten)]
pub tls_credentials: Web3SignerTlsCredentials,
}
/// TLS credentials for connecting to a remote Web3Signer server.
#[derive(Debug, Clone, PartialEq, Eq, Parser)]
pub struct Web3SignerTlsCredentials {
/// Path to the CA certificate file. (.crt)
#[clap(long, env = "CA_CERT_PATH")]
pub ca_cert_path: String,
/// Path to the PEM encoded private key and certificate file. (.pem)
#[clap(long, env = "CLIENT_COMBINED_PEM_PATH")]
pub combined_pem_path: String,
}
/// TLS credentials for connecting to a remote Dirk server.
#[derive(Debug, Clone, PartialEq, Eq, Parser)]
pub struct DirkTlsCredentials {
/// Path to the client certificate file. (.crt)
#[clap(long, env = "CLIENT_CERT_PATH")]
pub client_cert_path: String,
/// Path to the client key file. (.key)
#[clap(long, env = "CLIENT_KEY_PATH")]
pub client_key_path: String,
/// Path to the CA certificate file. (.crt)
#[clap(long, env = "CA_CERT_PATH")]
pub ca_cert_path: Option<String>,
}
/// Supported chains for the CLI
#[derive(Debug, Clone, Copy, ValueEnum, Hash, PartialEq, Eq)]
#[clap(rename_all = "kebab_case")]
pub enum Chain {
Mainnet,
Holesky,
Helder,
Kurtosis,
}
impl Chain {
/// Get the fork version for the given chain.
pub fn fork_version(&self) -> [u8; 4] {
match self {
Self::Mainnet => [0, 0, 0, 0],
Self::Holesky => [1, 1, 112, 0],
Self::Helder => [16, 0, 0, 0],
Self::Kurtosis => [16, 0, 0, 56],
}
}
/// Get the bolt RPC URL for the given chain.
///
/// Returns None if bolt RPC is not deployed for the chain.
pub fn bolt_rpc(&self) -> Option<Url> {
match self {
Self::Mainnet => Some(Url::parse("https://rpc.boltprotocol.xyz").unwrap()),
Self::Holesky => Some(Url::parse("https://rpc.holesky.boltprotocol.xyz").unwrap()),
_ => None,
}
}
/// Get the chain ID for the given chain. Returns `None` if the chain ID is not supported.
pub fn from_id(id: u64) -> Option<Self> {
match id {
1 => Some(Self::Mainnet),
17000 => Some(Self::Holesky),
3151908 => Some(Self::Kurtosis),
7014190335 => Some(Self::Helder),
_ => None,
}
}
/// Get the chain ID for the given chain. Returns an error if the chain ID is not supported.
pub fn try_from_id(id: u64) -> eyre::Result<Self> {
Self::from_id(id).ok_or_else(|| eyre::eyre!("chain id {} not supported", id))
}
/// Tries to get the chain ID from an online provider.
pub async fn try_from_provider<T, P>(provider: &P) -> eyre::Result<Self>
where
T: Transport + Clone,
P: Provider<T>,
{
let chain_id = provider.get_chain_id().await?;
Self::try_from_id(chain_id)
}
}
/// Styles for the CLI application.
const fn cli_styles() -> clap::builder::Styles {
clap::builder::Styles::styled()
.usage(Style::new().bold().underline().fg_color(Some(Color::Ansi(AnsiColor::Yellow))))
.header(Style::new().bold().underline().fg_color(Some(Color::Ansi(AnsiColor::Yellow))))
.literal(Style::new().fg_color(Some(Color::Ansi(AnsiColor::Green))))
.invalid(Style::new().bold().fg_color(Some(Color::Ansi(AnsiColor::Red))))
.error(Style::new().bold().fg_color(Some(Color::Ansi(AnsiColor::Red))))
.valid(Style::new().bold().underline().fg_color(Some(Color::Ansi(AnsiColor::Green))))
.placeholder(Style::new().fg_color(Some(Color::Ansi(AnsiColor::White))))
}
#[cfg(test)]
mod tests {
use super::Opts;
#[test]
pub fn verify_cli() {
use clap::CommandFactory;
Opts::command().debug_assert()
}
}