Skip to content

Commit

Permalink
Merge pull request #580 from chainbound/chore/parse-eth-value
Browse files Browse the repository at this point in the history
chore: parse ether value with units
  • Loading branch information
thedevbirb authored Dec 16, 2024
2 parents 3e9cfa7 + 71c2524 commit 9ab2cdc
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 7 deletions.
10 changes: 7 additions & 3 deletions bolt-cli/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ use clap::{
};
use reqwest::Url;

use crate::{common::keystore::DEFAULT_KEYSTORE_PASSWORD, contracts::EigenLayerStrategy};
use crate::{
common::{keystore::DEFAULT_KEYSTORE_PASSWORD, parse_ether_value},
contracts::EigenLayerStrategy,
};

/// `bolt` is a CLI tool to interact with bolt Protocol ✨
#[derive(Parser, Debug, Clone)]
Expand Down Expand Up @@ -225,8 +228,9 @@ pub enum EigenLayerSubcommand {
/// The name of the strategy to deposit into.
#[clap(long, env = "EIGENLAYER_STRATEGY")]
strategy: EigenLayerStrategy,
/// The amount to deposit into the strategy, in ETH
#[clap(long, env = "EIGENLAYER_STRATEGY_DEPOSIT_AMOUNT")]
/// The amount to deposit into the strategy, in units (e.g. '1ether', '10gwei')
/// If no unit is provided, it is assumed to be in wei.
#[clap(long, env = "EIGENLAYER_STRATEGY_DEPOSIT_AMOUNT", value_parser = parse_ether_value)]
amount: U256,
},

Expand Down
27 changes: 25 additions & 2 deletions bolt-cli/src/common/mod.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
use std::{fs, io::Write, path::PathBuf, str::FromStr};

use alloy::{
contract::Error as ContractError, primitives::Bytes, sol_types::SolInterface,
contract::Error as ContractError,
dyn_abi::DynSolType,
primitives::{Bytes, U256},
sol_types::SolInterface,
transports::TransportError,
};
use ethereum_consensus::crypto::PublicKey as BlsPublicKey;
use eyre::{Context, Result};
use eyre::{Context, ContextCompat, Result};
use serde::Serialize;
use tracing::info;

Expand All @@ -27,6 +30,26 @@ pub mod hash;
/// Utilities for working with Consensys' Web3Signer remote keystore.
pub mod web3signer;

/// Parses an ether value from a string.
///
/// The amount can be tagged with a unit, e.g. "1ether".
///
/// If the string represents an untagged amount (e.g. "100") then
/// it is interpreted as wei.
///
/// This Snippet is copied from Foundry's Cast CLI.
/// Ref: https://github.com/foundry-rs/foundry/blob/206dab285437bd6889463ab006b6a5fb984079d8/crates/cli/src/utils/mod.rs#L137
pub fn parse_ether_value(value: &str) -> Result<U256> {
Ok(if value.starts_with("0x") {
U256::from_str_radix(value, 16)?
} else {
DynSolType::coerce_str(&DynSolType::Uint(256), value)?
.as_uint()
.wrap_err("Could not parse ether value from string")?
.0
})
}

/// Parse a BLS public key from a string
pub fn parse_bls_public_key(delegatee_pubkey: &str) -> Result<BlsPublicKey> {
let hex_pk = delegatee_pubkey.strip_prefix("0x").unwrap_or(delegatee_pubkey);
Expand Down
2 changes: 1 addition & 1 deletion testnets/holesky/QUICK_START.md
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ First, you need to install the
- `--rpc-url` is the URL of the Ethereum node to send transactions to (e.g. Geth)
- `--operator-private-key` is the private key of your registered operator address
- `--strategy` is the **NAME** of the strategy to deposit into. [possible values: st-eth, r-eth, w-eth, cb-eth, m-eth].
- `--amount` is the amount to deposit into the strategy (in ETH) (e.g. '1' for 1 ETH).
- `--amount` is the amount to deposit into the strategy (e.g. '1ether', '0.1ether', '100gwei', etc.)

3. Register into the Bolt AVS:

Expand Down
2 changes: 1 addition & 1 deletion testnets/holesky/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ Options:
--strategy <STRATEGY>
The name of the strategy to deposit into [env: EIGENLAYER_STRATEGY=] [possible values: st-eth, r-eth, w-eth, cb-eth, m-eth]
--amount <AMOUNT>
The amount to deposit into the strategy, in ETH [env: EIGENLAYER_STRATEGY_DEPOSIT_AMOUNT=]
The amount to deposit into the strategy. (examples: "1ether", "0.2ether", "100gwei") [env: EIGENLAYER_STRATEGY_DEPOSIT_AMOUNT=]
-h, --help
Print help
```
Expand Down

0 comments on commit 9ab2cdc

Please sign in to comment.