Skip to content

Conversation

@AryanGodara
Copy link
Member

@AryanGodara AryanGodara commented Dec 22, 2025

Description

Migrate the balancer V2

Changes

  • Replace ethcontract::primitives with alloy::primitives across crates:
    • driver/src/boundary/liquidity/balancerv2
    • shares/sources/balancerv2
    • solvers/src/liquidity/balancerv2
    • solvers/src/boundary/liquidity
  • Remove the now redundant intoalloy and intolegacy adapters.

How to test

  1. cargo check -p e2e --tests
  2. Run e2e tests

@AryanGodara AryanGodara self-assigned this Dec 22, 2025
@github-actions
Copy link

This pull request has been marked as stale because it has been inactive a while. Please update this pull request or it will be automatically closed.

@github-actions github-actions bot added the stale label Dec 30, 2025
@github-actions github-actions bot closed this Jan 6, 2026
@AryanGodara AryanGodara reopened this Jan 6, 2026
@AryanGodara AryanGodara force-pushed the aryan/migrate-balancer-v2-to-alloy-primitives branch from d3722e9 to b164ff1 Compare January 6, 2026 09:46
@AryanGodara AryanGodara marked this pull request as ready for review January 6, 2026 10:36
@AryanGodara AryanGodara requested a review from a team as a code owner January 6, 2026 10:36
@AryanGodara
Copy link
Member Author

/gemini review

@AryanGodara AryanGodara removed the stale label Jan 6, 2026
Copy link

@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 is a significant refactoring to migrate from ethcontract primitives to alloy primitives. The changes are extensive but mostly mechanical, and you've done a great job handling the API differences between the two libraries. My review focuses on a few areas where the new alloy types have different behavior, particularly in test helper functions and debug implementations, which could be improved for correctness and clarity. I've also suggested a small simplification for parsing a large constant. Overall, this is a solid piece of work.

Copy link

@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 migrates Balancer V2 code from ethcontract primitives to alloy primitives. The changes are extensive and mostly mechanical, replacing types like U256 and removing conversion traits. The code is generally cleaner and more consistent after these changes. I've found a few places where the removal of conversion adapters seems incomplete, leaving verbose and explicit calls to traits that are meant to be removed. My review comments focus on these inconsistencies to fully align the code with the PR's goal.

Copy link
Contributor

@jmg-duarte jmg-duarte left a comment

Choose a reason for hiding this comment

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

There are some things that need to be addressed before merging, I'd prefer keeping the code as close to the original as possible since (AFAIK) this is already a port from a smart contract of sorts


Ok(PoolInfo {
id: pool_id,
id: H256(pool_id.0),
Copy link
Contributor

Choose a reason for hiding this comment

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

Should've changed to B256. but my PR changes this, so it's ok for now

Removes unnecessary type conversions between ethcontract and alloy types in Balancer V2 pool code. The conversions are no longer needed as the codebase migrates to native alloy types. Updates affected areas:

- Remove IntoAlloy/IntoLegacy trait usage for U256, addresses, and pool data
- Convert ethcontract::U256 to alloy::primitives::U256 in tests and implementations
- Simplify type conversions in stable, weighted, composable stable, and liquidity bootstrapping pools

Signed-off-by: Aryan Godara <[email protected]>
- Replace lossy unwrap_or fallbacks with direct unwrap() in Bfp Debug impl
- Fix to_f64_lossy() to use string parsing for accurate large value conversion
- Update test helper functions to use string-based U256/f64 conversions instead of lossy casts
- Simplify into_legacy() calls by using method syntax instead of fully qualified paths
@AryanGodara AryanGodara force-pushed the aryan/migrate-balancer-v2-to-alloy-primitives branch from 70985b3 to 2d3185d Compare January 7, 2026 12:12
Copy link
Contributor

@jmg-duarte jmg-duarte left a comment

Choose a reason for hiding this comment

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

I have nits (some qualified paths and U256::from(1)) but I'll fix them in my PR

Please address the suggestion I left and IMO it's good to go

fn invariant_two_tokens_ok() {
let amp = 100.;
let amplification_parameter = U256::from_f64_lossy(amp * AMP_PRECISION.to_f64_lossy());
let amplification_parameter = u256_from_f64_lossy(amp * f64::from(*AMP_PRECISION));
Copy link
Contributor

Choose a reason for hiding this comment

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

and on the other usages

Suggested change
let amplification_parameter = u256_from_f64_lossy(amp * f64::from(*AMP_PRECISION));
let amplification_parameter = U256::from(amp * f64::from(*AMP_PRECISION));

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh, I fixed f64:from , but missed the other one, fixed now, pushing

- Replace all calls with direct U256::from() conversions for amplification parameter
Copy link
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.

G2G as is


assert_eq!(
AmplificationParameter::try_new(1.into(), 0.into())
AmplificationParameter::try_new(U256::from(1u64), U256::from(0u64))
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
AmplificationParameter::try_new(U256::from(1u64), U256::from(0u64))
AmplificationParameter::try_new(U256::ONE, U256::ZERO)

Copy link
Contributor

Choose a reason for hiding this comment

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

Will fix this on my PR

@AryanGodara AryanGodara added this pull request to the merge queue Jan 7, 2026
Merged via the queue into main with commit ef94b8d Jan 7, 2026
19 checks passed
@AryanGodara AryanGodara deleted the aryan/migrate-balancer-v2-to-alloy-primitives branch January 7, 2026 14:03
@github-actions github-actions bot locked and limited conversation to collaborators Jan 7, 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.

4 participants