-
Notifications
You must be signed in to change notification settings - Fork 0
feat: add ERC-8004 HTX parsing/validation and consolidate contract client utilities #62
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
base: main
Are you sure you want to change the base?
Changes from all commits
4abd97b
9a59f7b
4c8b082
ec6856a
a71cdae
1f111d4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -48,4 +48,5 @@ coverage/ | |
|
|
||
| .claude/ | ||
|
|
||
| blacklight_node/ | ||
| blacklight_node/ | ||
| CLAUDE.md | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,20 +3,15 @@ use crate::{ | |
| StakingOperatorsClient, | ||
| }; | ||
| use alloy::{ | ||
| network::{Ethereum, EthereumWallet, NetworkWallet}, | ||
| primitives::{Address, B256, TxKind, U256}, | ||
| providers::{DynProvider, Provider, ProviderBuilder, WsConnect}, | ||
| rpc::types::TransactionRequest, | ||
| signers::local::PrivateKeySigner, | ||
| primitives::{Address, B256, U256}, | ||
| providers::DynProvider, | ||
| }; | ||
| use std::sync::Arc; | ||
| use tokio::sync::Mutex; | ||
| use contract_clients_common::ProviderContext; | ||
|
|
||
| /// High-level wrapper bundling all contract clients with a shared Alloy provider. | ||
| #[derive(Clone)] | ||
| pub struct BlacklightClient { | ||
| provider: DynProvider, | ||
| wallet: EthereumWallet, | ||
| ctx: ProviderContext, | ||
| pub manager: HeartbeatManagerClient<DynProvider>, | ||
| pub token: NilTokenClient<DynProvider>, | ||
| pub staking: StakingOperatorsClient<DynProvider>, | ||
|
|
@@ -25,26 +20,26 @@ pub struct BlacklightClient { | |
|
|
||
| impl BlacklightClient { | ||
| pub async fn new(config: ContractConfig, private_key: String) -> anyhow::Result<Self> { | ||
| let rpc_url = config.rpc_url.clone(); | ||
| let ws_url = rpc_url | ||
| .replace("http://", "ws://") | ||
| .replace("https://", "wss://"); | ||
| let ctx = ProviderContext::with_ws_retries( | ||
| &config.rpc_url, | ||
| &private_key, | ||
| Some(config.max_ws_retries), | ||
| ) | ||
| .await?; | ||
|
|
||
| // Build WS transport with configurable retries | ||
| let ws = WsConnect::new(ws_url).with_max_retries(config.max_ws_retries); | ||
| let signer: PrivateKeySigner = private_key.parse::<PrivateKeySigner>()?; | ||
| let wallet = EthereumWallet::from(signer); | ||
|
|
||
| // Build a provider that can sign transactions, then erase the concrete type | ||
| let provider: DynProvider = ProviderBuilder::new() | ||
| .wallet(wallet.clone()) | ||
| .with_simple_nonce_management() | ||
| .with_gas_estimation() | ||
| .connect_ws(ws) | ||
| .await? | ||
| .erased(); | ||
|
Comment on lines
-28
to
-45
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why are we changing this? Seems orthogonal to the ERC-8004 changes.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This comes related to your previous comment on removing the |
||
| Self::from_context(ctx, config).await | ||
| } | ||
|
|
||
| let tx_lock = Arc::new(Mutex::new(())); | ||
| /// Create a client from an existing [`ProviderContext`]. | ||
| /// | ||
| /// Use this when you want to share the same provider, wallet, and nonce | ||
| /// tracker across multiple clients (e.g. `BlacklightClient` and `Erc8004Client`). | ||
| pub async fn from_context( | ||
| ctx: ProviderContext, | ||
| config: ContractConfig, | ||
| ) -> anyhow::Result<Self> { | ||
| let provider = ctx.provider().clone(); | ||
| let tx_lock = ctx.tx_lock(); | ||
|
|
||
| // Instantiate contract clients using the shared provider | ||
| let manager = | ||
|
|
@@ -54,11 +49,10 @@ impl BlacklightClient { | |
|
|
||
| let protocol_config_address = staking.protocol_config().await?; | ||
| let protocol_config = | ||
| ProtocolConfigClient::new(provider.clone(), protocol_config_address, tx_lock.clone()); | ||
| ProtocolConfigClient::new(provider.clone(), protocol_config_address, tx_lock); | ||
|
|
||
| Ok(Self { | ||
| provider, | ||
| wallet, | ||
| ctx, | ||
| manager, | ||
| token, | ||
| staking, | ||
|
|
@@ -68,31 +62,21 @@ impl BlacklightClient { | |
|
|
||
| /// Get the signer address | ||
| pub fn signer_address(&self) -> Address { | ||
| <EthereumWallet as NetworkWallet<Ethereum>>::default_signer_address(&self.wallet) | ||
| self.ctx.signer_address() | ||
| } | ||
|
|
||
| /// Get the balance of the wallet | ||
| pub async fn get_balance(&self) -> anyhow::Result<U256> { | ||
| let address = self.signer_address(); | ||
| Ok(self.provider.get_balance(address).await?) | ||
| self.ctx.get_balance().await | ||
| } | ||
|
|
||
| /// Get the balance of a specific address | ||
| pub async fn get_balance_of(&self, address: Address) -> anyhow::Result<U256> { | ||
| Ok(self.provider.get_balance(address).await?) | ||
| self.ctx.get_balance_of(address).await | ||
| } | ||
|
|
||
| /// Send ETH to an address | ||
| pub async fn send_eth(&self, to: Address, amount: U256) -> anyhow::Result<B256> { | ||
| let tx = TransactionRequest { | ||
| to: Some(TxKind::Call(to)), | ||
| value: Some(amount), | ||
| max_priority_fee_per_gas: Some(0), | ||
| ..Default::default() | ||
| }; | ||
|
|
||
| let tx_hash = self.provider.send_transaction(tx).await?.watch().await?; | ||
|
|
||
| Ok(tx_hash) | ||
| self.ctx.send_eth(to, amount).await | ||
| } | ||
| } | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this unused? |
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: Won't
raw_bytesbe unused if debug isn't set? Doesn't clippy complain here? I might be wrong, not sure how tracing exptects things.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, this is solved in the follow up PR.