Skip to content

Conversation

@jmg-duarte
Copy link
Contributor

@jmg-duarte jmg-duarte commented Nov 26, 2025

Simple despite being huge

Description

This PR continues the migration from the ethcontract library to the alloy library by

  • replacing instances of ethcontract::H160 and primitive_types::H160 with alloy::primitives::Address
  • replacing instances of ethcontract::U256 and primitives_types::U256 with alloy::primitives::U256
    There are plenty left, the current commit has a focus on some structures are related code, however some of the structures only got a partial migration to avoid an even more complex PR

This migration simplifies the codebase by reducing the need for type conversions and aligns the entire codebase with alloy's native types.

Changes

  • Replace H160 with Address
  • Replace ethcontract::U256 with alloy::primitives::U256
  • Remove unnecessary .into_alloy() and .into_legacy() conversion calls
  • Update function signatures across all affected crates
  • Simplify bad token detection code
  • Update liquidity source implementations (Balancer V2, Uniswap V2/V3)
  • Update baseline solver and price estimation modules
  • Simplify token owner finder implementations
  • Update Cargo dependencies

How to test

Existing tests

@jmg-duarte jmg-duarte requested a review from a team as a code owner November 26, 2025 19:29
@squadgazzz
Copy link
Contributor

I converted it to a draft to avoid notifications noise until all the issues with this PR are solved.

@squadgazzz squadgazzz marked this pull request as draft November 27, 2025 09:04
Base automatically changed from jmgd/alloy/models to main November 27, 2025 12:49
@jmg-duarte jmg-duarte marked this pull request as ready for review November 27, 2025 19:20
Copy link
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.

The PR description claims all instances of H160 would be replaced but there are still 714 remaining. I'm fine with doing partial migrations but this should then be stated in the description. Do you want to continue with this as a partial migration or update the PR to replace the remaining instances of H160 as well?

@jmg-duarte
Copy link
Contributor Author

The PR description claims all instances of H160 would be replaced but there are still 714 remaining. I'm fine with doing partial migrations but this should then be stated in the description.

My fault, I had Claude write the PR description. I'll update

Do you want to continue with this as a partial migration or update the PR to replace the remaining instances of H160 as well?

Partial migration, the instances you highlighted are plentiful and I suspect they require changing a bunch of code alone

for (spender, token, allowance) in results {
let allowance = match allowance {
Ok(value) => U256::from(value.0.as_slice()),
Ok(allowance) => U256::from_be_slice(&allowance.0),
Copy link
Contributor

Choose a reason for hiding this comment

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

If the future that produces this value uses Erc20Instance::allowance() instead of web3.eth().call() alloy would do the right conversion for us and we wouldn't have to guess the endinanness here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I converted this piece, but the issue is that it would not pass by the web3 mock. This is just a "I forgot what the original code was" moment, I'll fix the mock issue right after this PR

@jmg-duarte jmg-duarte enabled auto-merge November 28, 2025 10:29
@jmg-duarte jmg-duarte added this pull request to the merge queue Nov 28, 2025
Merged via the queue into main with commit 66a5e28 Nov 28, 2025
18 checks passed
@jmg-duarte jmg-duarte deleted the jmgd/alloy/h160_contract branch November 28, 2025 10:56
@github-actions github-actions bot locked and limited conversation to collaborators Nov 28, 2025
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.

4 participants