Skip to content

Remove ethcontract+web3+primitive-types#4106

Merged
jmg-duarte merged 4 commits intomainfrom
jmgd/alloy/removal
Feb 3, 2026
Merged

Remove ethcontract+web3+primitive-types#4106
jmg-duarte merged 4 commits intomainfrom
jmgd/alloy/removal

Conversation

@jmg-duarte
Copy link
Copy Markdown
Contributor

@jmg-duarte jmg-duarte commented Jan 29, 2026

Completes the Alloy migration by removing the last remaining legacy Ethereum libraries: ethcontract, web3, and primitive-types. These dependencies are no longer needed and can be fully removed, simplifying the dependency tree.

Key change: The labelling layer for observability now operates at the Web3 wrapper level instead of directly on DynProvider, ensuring the wallet state is properly preserved when creating labeled provider instances.

Changes

  • Remove ethcontract, web3, and primitive-types from workspace dependencies
  • Delete unused legacy ethrpc implementations (buffered.rs, http.rs, instrumented.rs, alloy/conversions.rs)
  • Migrate ProviderLabelingExt from DynProvider to Web3 wrapper, preserving wallet state across labeled instances
  • Clean up ethrpc module structure and simplify exports
  • Update imports across affected crates to use Alloy types only
  • Remove legacy references from contract vendoring script and test setup

How to test

Existing tests

@jmg-duarte jmg-duarte requested a review from a team as a code owner January 29, 2026 15:03
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request completes the migration from ethcontract, web3, and primitive-types to alloy. The changes are extensive, removing the legacy libraries and refactoring the codebase to use alloy APIs. One critical issue was found where a f64 to U256 conversion could lead to a panic due to not handling infinite values, a case that was previously covered by the removed primitive-types library. The suggested fix addresses the non-finite values, but a potential overflow risk for large finite values remains.

Comment thread crates/shared/src/price_estimation/competition/quote.rs Outdated
@jmg-duarte jmg-duarte marked this pull request as draft January 29, 2026 17:05
@jmg-duarte jmg-duarte marked this pull request as ready for review January 30, 2026 15:41
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request completes the Alloy migration by removing the legacy ethcontract, web3, and primitive-types dependencies. The changes are extensive and primarily involve removing old code and adapting to the Alloy library. A key change is moving the observability labeling to the Web3 wrapper to preserve wallet state. My review identified a critical issue in the implementation of the new labeling logic that could lead to incorrect nonce management and transaction failures.

Comment thread crates/ethrpc/src/alloy/instrumentation.rs
Copy link
Copy Markdown
Contributor

@MartinquaXD MartinquaXD left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Image

@@ -1,7 +1,3 @@
//! This script is used to vendor Truffle JSON artifacts to be used for code
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can happen in a different PR but I think it's okay to remove the vendor thingy completely. Seems cleaner to just copy the artifacts that you need.

Comment thread crates/ethrpc/src/lib.rs Outdated
Comment thread crates/ethrpc/src/lib.rs Outdated
Comment on lines 75 to 82
(0 | 1, 0) => {
let (alloy, wallet) = alloy::unbuffered_provider(url.as_str(), label);
(alloy, wallet)
}
None => {
let legacy = Web3Transport::new(http);
let (alloy, wallet) = alloy::unbuffered_provider(url.as_str());
(legacy, alloy, wallet)
_ => {
let (alloy, wallet) = alloy::provider(url.as_str(), args, label);
(alloy, wallet)
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
(0 | 1, 0) => {
let (alloy, wallet) = alloy::unbuffered_provider(url.as_str(), label);
(alloy, wallet)
}
None => {
let legacy = Web3Transport::new(http);
let (alloy, wallet) = alloy::unbuffered_provider(url.as_str());
(legacy, alloy, wallet)
_ => {
let (alloy, wallet) = alloy::provider(url.as_str(), args, label);
(alloy, wallet)
}
(0 | 1, 0) => alloy::unbuffered_provider(url.as_str(), label),
_ => alloy::provider(url.as_str(), args, label),

Alternatively those function might as well already return the fully built Web3 instance.

Copy link
Copy Markdown
Contributor Author

@jmg-duarte jmg-duarte Feb 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alternatively those function might as well already return the fully built Web3 instance.

They're used in more places and I tried to keep the diff simple, we can clean this up further later

Comment on lines +151 to +154
// Note on truncation: previously we used primitive_types::U256::from_f64_lossy which
// truncated the floating point, while alloy is slightly more faithful to the original
// value and rounds to closest integer: [0, 0.5) => 0, [0.5, 1] => 1
v => U256::from(v.trunc()),
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unless this caused issues in tests I think we can gloss over this minor difference (considering the magnitude of values we work with).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it did cause issues in tests

Copy link
Copy Markdown
Contributor

@squadgazzz squadgazzz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -167,8 +167,6 @@ impl Contracts {

#[derive(Debug, Error)]
pub enum Error {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems like this enum is useless now.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Its actually exported, it can be cleaned up and just simplified but lets leave this for a follow up too

Comment thread crates/ethrpc/src/lib.rs
pub struct Web3<T: Transport = DynTransport> {
pub legacy: web3::Web3<T>,
pub struct Web3 {
pub alloy: AlloyProvider,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe now we can give it a more meaningful name.

Suggested change
pub alloy: AlloyProvider,
pub provider: AlloyProvider,

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This leads to ~78 changes, I'll rename in a follow up PR just to keep the already reviewed diff minimal

@jmg-duarte jmg-duarte added this pull request to the merge queue Feb 3, 2026
Merged via the queue into main with commit e68c266 Feb 3, 2026
19 checks passed
@jmg-duarte jmg-duarte deleted the jmgd/alloy/removal branch February 3, 2026 12:50
@github-actions github-actions bot locked and limited conversation to collaborators Feb 3, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants