Skip to content

Conversation

@jmg-duarte
Copy link
Contributor

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

Description

Migrates Balancer V2 sources module from ethcontract to alloy primitives, continuing the project-wide modernization
effort. This simplifies the codebase and improves type safety across pool fetching, pool implementations, and swap math
calculations.

Changes

  • Replace ethcontract contract bindings with alloy types in pool fetching
  • Add alloy block support to recent_block_cache.rs
  • Migrate all pool types (Weighted, Stable, Composable Stable, LBP) to alloy
  • Convert swap math modules to use alloy primitives
  • Update pool storage, registry, and boundary liquidity handlers
  • Remove ethcontract-specific workarounds from sources/mod.rs

How to test

Existing tests

@jmg-duarte jmg-duarte requested a review from a team as a code owner January 6, 2026 11:39
@gemini-code-assist
Copy link

Summary of Changes

Hello @jmg-duarte, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request represents a significant internal refactoring effort, transitioning the Balancer V2 liquidity source implementation to leverage the alloy library's modern primitive types and utilities. This modernization streamlines the codebase by adopting a more consistent and up-to-date Ethereum ecosystem library, impacting data structures, contract interactions, and core mathematical operations. The changes also simplify the configuration of Balancer V2 factories, indicating an evolution in how these components are managed within the system.

Highlights

  • Alloy Migration: This pull request performs an extensive migration of Balancer V2 related code to utilize the alloy library's primitive types and utilities, replacing older ethcontract and web3::types constructs.
  • Type System Modernization: Key data types such as 256-bit hashes (H256 to B256), unsigned integers (U256), Ethereum addresses (Address), and block identifiers (BlockId) have been updated to their alloy::primitives and alloy::eips equivalents, removing the need for explicit conversion traits like IntoLegacy and IntoAlloy.
  • Refactored Balancer Factory Handling: The mechanism for configuring and instantiating Balancer V2 factories has been simplified, with the removal of the BalancerFactoryKind enum and associated command-line arguments, suggesting a more streamlined internal management approach.
  • Updated Arithmetic Operations: Fixed-point arithmetic (Bfp) and other mathematical operations have been adjusted to align with alloy's U256 methods, ensuring compatibility and leveraging alloy's optimized implementations.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@jmg-duarte jmg-duarte marked this pull request as draft January 6, 2026 11:40
@jmg-duarte
Copy link
Contributor Author

/gemini review

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 and well-executed refactoring to migrate Balancer V2 sources from ethcontract types to alloy types. The changes span across multiple crates, including driver, shared, solver, and solvers, consistently replacing types like H256, U256, and BlockId with their alloy equivalents. The removal of BalancerFactoryKind from command-line arguments and its associated logic is a good simplification. The test suite has been diligently updated to reflect these type changes. Overall, the migration appears to be thorough and correct, improving type consistency across the codebase.

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 the Balancer V2 liquidity sources from ethcontract types to alloy types. This is a significant refactoring that touches many files across driver, shared, solver, and solvers crates. The changes primarily involve replacing ethcontract::{H256, U256} with their alloy counterparts (B256, U256), removing the IntoAlloy/IntoLegacy conversion traits, and updating contract calls and tests to use alloy idioms. Additionally, the configuration of Balancer factories has been refactored, removing the BalancerFactoryKind enum in favor of direct address configuration.

Overall, the migration is well-executed and improves code clarity by using alloy's more idiomatic constants and methods. The changes are consistent across the codebase.

I have one comment regarding a change that seems out of scope for this PR.

I am having trouble creating individual review comments. Click here to see my feedback.

crates/shared/src/sources/mod.rs (79-98)

medium

The removal of PoolAggregator and its PoolFetching implementation seems unrelated to the PR's goal of migrating Balancer V2 sources to Alloy. This logic is for Uniswap V2 pools. Was this removal intentional? If so, it might be better to move it to a separate PR to keep this one focused. If it was not intentional, it should be reverted.

@jmg-duarte
Copy link
Contributor Author

/gemini review

Comment on lines -179 to -193
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq, ValueEnum)]
#[clap(rename_all = "verbatim")]
pub enum BalancerFactoryKind {
Weighted,
WeightedV3,
WeightedV4,
Weighted2Token,
StableV2,
LiquidityBootstrapping,
NoProtocolFeeLiquidityBootstrapping,
ComposableStable,
ComposableStableV3,
ComposableStableV4,
ComposableStableV5,
ComposableStableV6,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was unused

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Also unused, on the infra repo too

@jmg-duarte jmg-duarte changed the title [NEEDS #4002] Migrate balancer v2 sources to alloy Migrate balancer v2 sources to alloy Jan 7, 2026
@jmg-duarte jmg-duarte marked this pull request as ready for review January 7, 2026 15:07
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 successfully migrates the Balancer V2 sources module from ethcontract to alloy primitives, which is a great step forward in modernizing the codebase. The changes simplify the code and improve type safety across various components like pool fetching, pool implementations, and swap math. The refactoring is well-executed and the code is much cleaner. The identified minor issues, such as a typo in a comment and duplicated test assertions, can be addressed for further improvement.

Copy link
Contributor

@m-sz m-sz left a comment

Choose a reason for hiding this comment

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

Small typo, otherwise LGTM!

@jmg-duarte jmg-duarte added this pull request to the merge queue Jan 7, 2026
Merged via the queue into main with commit b9ff845 Jan 7, 2026
19 checks passed
@jmg-duarte jmg-duarte deleted the jmgd/alloy/sources branch January 7, 2026 16:29
@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