-
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
Open
jcabrero
wants to merge
6
commits into
main
Choose a base branch
from
feat/erc_8004_validations
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
4abd97b
feat: integrate ERC 8004 HTX parsing and validation
jcabrero 9a59f7b
refactor: extract shared contract client utilities into common crate
jcabrero 4c8b082
chore: unified simulators under a single trait
jcabrero ec6856a
chore: cleaned up htx validation for ERC-8004
jcabrero a71cdae
chore: move common contract utilities to a single crate
jcabrero 1f111d4
feat: unified contract clients
jcabrero File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -48,4 +48,5 @@ coverage/ | |
|
|
||
| .claude/ | ||
|
|
||
| blacklight_node/ | ||
| blacklight_node/ | ||
| CLAUDE.md | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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. |
||
| 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.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.