Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bolt-cli: Add dry-run flag for developmental/testing #731

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions bolt-cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,8 @@ Commands:
help Print this message or the help of the given subcommand(s)

Options:
-h, --help Print help
-h, --help Print help
-d, --dry-run Simulate without making on-chain changes (e.g Opt to using Anvil fork rather than RPC connection)
```

</details>
Expand All @@ -329,7 +330,8 @@ Commands:
help Print this message or the help of the given subcommand(s)

Options:
-h, --help Print help
-h, --help Print help
-d, --dry-run Simulate without making on-chain changes (e.g Opt to using Anvil fork rather than RPC connection)

❯ bolt operators eigenlayer --help
Commands to interact with EigenLayer and bolt
Expand All @@ -345,7 +347,8 @@ Commands:
help Print this message or the help of the given subcommand(s)

Options:
-h, --help Print help
-h, --help Print help
-d, --dry-run Simulate without making on-chain changes (e.g Opt to using Anvil fork rather than RPC connection)

❯ bolt operators symbiotic --help
Commands to interact with Symbiotic and bolt
Expand All @@ -360,7 +363,8 @@ Commands:
help Print this message or the help of the given subcommand(s)

Options:
-h, --help Print help
-h, --help Print help
-d, --dry-run Simulate without making on-chain changes (e.g Opt to using Anvil fork rather than RPC connection)
```

</details>
Expand Down
40 changes: 40 additions & 0 deletions bolt-cli/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,11 @@ pub enum ValidatorsSubcommand {
/// 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 {
Expand Down Expand Up @@ -245,6 +250,11 @@ pub enum EigenLayerSubcommand {
/// 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,

/// 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.
Expand All @@ -261,6 +271,11 @@ pub enum EigenLayerSubcommand {
/// The salt for the operator signature.
#[clap(long, env = "OPERATOR_SIGNATURE_SALT")]
salt: 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.
Expand All @@ -271,6 +286,11 @@ pub enum EigenLayerSubcommand {
/// 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.
Expand All @@ -284,6 +304,11 @@ pub enum EigenLayerSubcommand {
/// 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.
Expand All @@ -310,6 +335,11 @@ pub enum SymbioticSubcommand {
/// 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,
},

/// Deregister a Symbiotic operator from bolt.
Expand All @@ -320,6 +350,11 @@ pub enum SymbioticSubcommand {
/// 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.
Expand All @@ -333,6 +368,11 @@ pub enum SymbioticSubcommand {
/// 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.
Expand Down
77 changes: 54 additions & 23 deletions bolt-cli/src/commands/operators/eigenlayer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use crate::{
cli::{Chain, EigenLayerSubcommand},
common::{
bolt_manager::BoltManagerContract::{self, BoltManagerContractErrors},
request_confirmation, try_parse_contract_error,
handle_rpc_dry_run, request_confirmation, shutdown_anvil, try_parse_contract_error,
},
contracts::{
bolt::{
Expand All @@ -38,15 +38,17 @@ impl EigenLayerSubcommand {
/// Run the EigenLayer subcommand.
pub async fn run(self) -> eyre::Result<()> {
match self {
Self::Deposit { rpc_url, strategy, amount, operator_private_key } => {
Self::Deposit { rpc_url, strategy, amount, operator_private_key, dry_run } => {
let signer = PrivateKeySigner::from_bytes(&operator_private_key)
.wrap_err("valid private key")?;
let operator = signer.address();

let (rpc, anvil) = handle_rpc_dry_run(rpc_url, dry_run)?;

let provider = ProviderBuilder::new()
.with_recommended_fillers()
.wallet(EthereumWallet::from(signer))
.on_http(rpc_url);
.on_http(rpc);

let chain = Chain::try_from_provider(&provider).await?;

Expand Down Expand Up @@ -91,19 +93,23 @@ impl EigenLayerSubcommand {
eyre::bail!("Transaction failed: {:?}", receipt)
}

info!("Succesfully deposited collateral into strategy");
info!("Successfully deposited collateral into strategy");

shutdown_anvil(anvil);

Ok(())
}

Self::Register { rpc_url, operator_rpc, salt, operator_private_key } => {
Self::Register { rpc_url, operator_rpc, salt, operator_private_key, dry_run } => {
let signer = PrivateKeySigner::from_bytes(&operator_private_key)
.wrap_err("valid private key")?;

let (rpc, anvil) = handle_rpc_dry_run(rpc_url, dry_run)?;

let provider = ProviderBuilder::new()
.with_recommended_fillers()
.wallet(EthereumWallet::from(signer.clone()))
.on_http(rpc_url);
.on_http(rpc);

let chain = Chain::try_from_provider(&provider).await?;

Expand Down Expand Up @@ -138,7 +144,7 @@ impl EigenLayerSubcommand {
Bytes::from(signer.sign_hash_sync(&signature_digest_hash)?.as_bytes());
let signature = SignatureWithSaltAndExpiry { signature, expiry, salt };

match bolt_eigenlayer_middleware
let result = match bolt_eigenlayer_middleware
.registerOperator(operator_rpc.to_string(), signature)
.send()
.await
Expand All @@ -154,7 +160,9 @@ impl EigenLayerSubcommand {
eyre::bail!("Transaction failed: {:?}", receipt)
}

info!("Succesfully registered EigenLayer operator");
info!("Successfully registered EigenLayer operator");

Ok(())
}
Err(e) => {
match try_parse_contract_error::<BoltEigenLayerMiddlewareErrors>(e)? {
Expand All @@ -173,20 +181,24 @@ impl EigenLayerSubcommand {
),
}
}
}
};

Ok(())
shutdown_anvil(anvil);

result
}

Self::Deregister { rpc_url, operator_private_key } => {
Self::Deregister { rpc_url, operator_private_key, dry_run } => {
let signer = PrivateKeySigner::from_bytes(&operator_private_key)
.wrap_err("valid private key")?;
let address = signer.address();

let (rpc, anvil) = handle_rpc_dry_run(rpc_url, dry_run)?;

let provider = ProviderBuilder::new()
.with_recommended_fillers()
.wallet(EthereumWallet::from(signer))
.on_http(rpc_url);
.on_http(rpc);

let chain = Chain::try_from_provider(&provider).await?;

Expand All @@ -200,7 +212,7 @@ impl EigenLayerSubcommand {
let bolt_eigenlayer_middleware =
BoltEigenLayerMiddleware::new(bolt_avs_address, provider);

match bolt_eigenlayer_middleware.deregisterOperator().send().await {
let result = match bolt_eigenlayer_middleware.deregisterOperator().send().await {
Ok(pending) => {
info!(
hash = ?pending.tx_hash(),
Expand All @@ -212,7 +224,9 @@ impl EigenLayerSubcommand {
eyre::bail!("Transaction failed: {:?}", receipt)
}

info!("Succesfully deregistered EigenLayer operator");
info!("Successfully deregistered EigenLayer operator");

Ok(())
}
Err(e) => {
match try_parse_contract_error::<BoltEigenLayerMiddlewareErrors>(e)? {
Expand All @@ -225,20 +239,24 @@ impl EigenLayerSubcommand {
),
}
}
}
};

Ok(())
shutdown_anvil(anvil);

result
}

Self::UpdateRpc { rpc_url, operator_private_key, operator_rpc } => {
Self::UpdateRpc { rpc_url, operator_private_key, operator_rpc, dry_run } => {
let signer = PrivateKeySigner::from_bytes(&operator_private_key)
.wrap_err("valid private key")?;
let address = signer.address();

let (rpc, anvil) = handle_rpc_dry_run(rpc_url, dry_run)?;

let provider = ProviderBuilder::new()
.with_recommended_fillers()
.wallet(EthereumWallet::from(signer))
.on_http(rpc_url);
.on_http(rpc);

let chain = Chain::try_from_provider(&provider).await?;

Expand All @@ -257,7 +275,11 @@ impl EigenLayerSubcommand {
return Ok(());
}

match bolt_manager.updateOperatorRPC(operator_rpc.to_string()).send().await {
let result = match bolt_manager
.updateOperatorRPC(operator_rpc.to_string())
.send()
.await
{
Ok(pending) => {
info!(
hash = ?pending.tx_hash(),
Expand All @@ -269,7 +291,9 @@ impl EigenLayerSubcommand {
eyre::bail!("Transaction failed: {:?}", receipt)
}

info!("Succesfully updated EigenLayer operator RPC");
info!("Successfully updated EigenLayer operator RPC");

Ok(())
}
Err(e) => match try_parse_contract_error::<BoltManagerContractErrors>(e)? {
BoltManagerContractErrors::OperatorNotRegistered(_) => {
Expand All @@ -279,8 +303,11 @@ impl EigenLayerSubcommand {
unreachable!("Unexpected error with selector {:?}", other.selector())
}
},
}
Ok(())
};

shutdown_anvil(anvil);

result
}

Self::Status { rpc_url: rpc, address } => {
Expand All @@ -295,7 +322,7 @@ impl EigenLayerSubcommand {
info!(?address, "EigenLayer operator is registered");
} else {
warn!(?address, "Operator not registered");
return Ok(())
return Ok(());
}

match bolt_manager.getOperatorData(address).call().await {
Expand Down Expand Up @@ -444,6 +471,7 @@ mod tests {
operator_private_key: secret_key,
strategy: EigenLayerStrategy::WEth,
amount: U256::from(1),
dry_run: false,
},
},
};
Expand All @@ -459,6 +487,7 @@ mod tests {
operator_private_key: secret_key,
operator_rpc: "https://bolt.chainbound.io/rpc".parse().expect("valid url"),
salt: B256::ZERO,
dry_run: false,
},
},
};
Expand All @@ -483,6 +512,7 @@ mod tests {
rpc_url: anvil_url.clone(),
operator_private_key: secret_key,
operator_rpc: "https://boooooolt.chainbound.io/rpc".parse().expect("valid url"),
dry_run: false,
},
},
};
Expand All @@ -505,6 +535,7 @@ mod tests {
subcommand: EigenLayerSubcommand::Deregister {
rpc_url: anvil_url.clone(),
operator_private_key: secret_key,
dry_run: false,
},
},
};
Expand Down
Loading
Loading