Skip to content
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

chore: refactor ChainAddresses and add new network addresses #84

Merged
merged 1 commit into from
Oct 6, 2024

Conversation

shuhuiluo
Copy link
Collaborator

@shuhuiluo shuhuiluo commented Oct 6, 2024

Simplify the ChainAddresses struct by making mandatory fields non-optional and adding support for new networks like Worldchain and Astrochain Sepolia. This change ensures consistency in the data structure and simplifies usage across the codebase.

Summary by CodeRabbit

  • New Features

    • Added support for new blockchain networks: ZKSYNC, WORLDCHAIN, and ASTROCHAIN_SEPOLIA.
    • Enhanced WETH token mappings to include additional chain IDs for better compatibility.
  • Bug Fixes

    • Updated address mappings to ensure required fields are accurately reflected.
  • Documentation

    • Improved visibility of the addresses module by making it accessible through the prelude.

Simplify the `ChainAddresses` struct by making mandatory fields non-optional and adding support for new networks like Worldchain and Astrochain Sepolia. This change ensures consistency in the data structure and simplifies usage across the codebase.
@shuhuiluo shuhuiluo requested a review from malik672 October 6, 2024 07:52
Copy link

coderabbitai bot commented Oct 6, 2024

Walkthrough

The changes introduce several modifications across multiple files, primarily focusing on the ChainAddresses struct in src/addresses.rs, which now includes new mandatory and optional fields. The ChainId enum in src/chains.rs has been expanded with new variants representing additional chains. The WETH9 struct in src/entities/weth9.rs has been updated to support new Ethereum chain IDs. Additionally, a new public export for the addresses module has been added to src/prelude.rs, enhancing module visibility.

Changes

File Change Summary
src/addresses.rs Updated ChainAddresses struct to include new mandatory and optional fields; modified constants and mappings for new chains.
src/chains.rs Added new variants ZKSYNC, WORLDCHAIN, and ASTROCHAIN_SEPOLIA to ChainId enum; updated SUPPORTED_CHAINS constant.
src/entities/weth9.rs Expanded WETH9 struct to support additional chain IDs in new and on_chain methods.
src/prelude.rs Added public export for addresses::* to enhance visibility of the addresses module.

Poem

In the meadow where addresses bloom,
New chains arrive, dispelling the gloom.
WETH hops in with a gleeful cheer,
While ChainIds dance, bringing new gear.
Oh, what joy in this code we weave,
A tapestry bright, in which we believe! 🐇✨


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🧹 Outside diff range and nitpick comments (3)
src/chains.rs (1)

40-40: LGTM: SUPPORTED_CHAINS updated correctly

The SUPPORTED_CHAINS constant has been correctly updated to include the new chain IDs, and the array size has been adjusted from 21 to 24. This change is consistent with the enum modifications and aligns with the PR objectives.

For improved maintainability, consider using a macro or const function to automatically determine the array size based on the number of enum variants. This would eliminate the need to manually update the array size when adding or removing chain IDs in the future.

Also applies to: 62-64

src/entities/weth9.rs (2)

42-54: LGTM! Consider grouping chain IDs for better readability.

The additions of new chain IDs and their corresponding WETH tokens are consistent with the existing pattern and align with the PR objectives.

For improved readability, consider grouping the chain IDs by network or purpose. For example:

let tokens = FxHashMap::from_iter(vec![
    // Ethereum and test networks
    (1, Self::on_chain(1).unwrap()),
    (3, Self::on_chain(3).unwrap()),
    (4, Self::on_chain(4).unwrap()),
    (5, Self::on_chain(5).unwrap()),
    (42, Self::on_chain(42).unwrap()),
    
    // Layer 2 and sidechains
    (10, Self::on_chain(10).unwrap()),
    (42161, Self::on_chain(42161).unwrap()),
    (421611, Self::on_chain(421611).unwrap()),
    (421614, Self::on_chain(421614).unwrap()),
    (8453, Self::on_chain(8453).unwrap()),
    (324, Self::on_chain(324).unwrap()),
    
    // Other networks
    (56, Self::on_chain(56).unwrap()),
    (137, Self::on_chain(137).unwrap()),
    (43114, Self::on_chain(43114).unwrap()),
    
    // Newly added networks
    (11155420, Self::on_chain(11155420).unwrap()),
    (7777777, Self::on_chain(7777777).unwrap()),
    (81457, Self::on_chain(81457).unwrap()),
    (480, Self::on_chain(480).unwrap()),
    (1301, Self::on_chain(1301).unwrap()),
]);

This grouping can make it easier to maintain and understand the different networks supported.


175-188: LGTM! New chain IDs 7777777 and 81457 added correctly. Consider adding comments for clarity.

The additions of chain IDs 7777777 (Zora mainnet) and 81457 (Blast Sepolia testnet) are implemented correctly and consistently with other entries. The token addresses, names, and decimals are appropriate for WETH.

For improved clarity, consider adding comments to identify these networks:

// Zora mainnet
7777777 => Some(token!(
    7777777,
    "4200000000000000000000000000000000000006",
    18,
    "WETH",
    "Wrapped Ether"
)),
// Blast Sepolia testnet
81457 => Some(token!(
    81457,
    "4300000000000000000000000000000000000004",
    18,
    "WETH",
    "Wrapped Ether"
)),

This will help other developers quickly identify which network each chain ID corresponds to.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between ce6fcf6 and 7c62f9b.

📒 Files selected for processing (4)
  • src/addresses.rs (6 hunks)
  • src/chains.rs (2 hunks)
  • src/entities/weth9.rs (4 hunks)
  • src/prelude.rs (1 hunks)
🧰 Additional context used
🔇 Additional comments (15)
src/prelude.rs (1)

2-2: LGTM: Addition of addresses module export.

The addition of addresses::* to the public exports aligns with the PR objectives of refactoring ChainAddresses. This change makes the addresses module publicly accessible, which should simplify its usage throughout the codebase.

However, be cautious with wildcard imports (*) as they can potentially introduce naming conflicts and make it harder to track which items are being used. Consider explicitly listing the items you want to export if there aren't too many.

Let's verify the existence and contents of the addresses module:

✅ Verification successful

LGTM: Addition of addresses module export.

The inclusion of addresses::* in the public exports aligns with the PR's objective of refactoring ChainAddresses, making the addresses module accessible across the codebase.

However, using wildcard imports (*) can lead to potential naming conflicts and reduce code clarity. If feasible, consider explicitly specifying the exported items to enhance maintainability.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the existence and contents of the addresses module

# Test 1: Check if the addresses module file exists
fd --type f --glob '*addresses*.rs' src

# Test 2: If it exists, display its contents
fd --type f --glob '*addresses*.rs' src --exec cat {}

Length of output: 26856

src/chains.rs (2)

31-33: LGTM: New chain IDs added correctly

The new variants ZKSYNC, WORLDCHAIN, and ASTROCHAIN_SEPOLIA have been added to the ChainId enum with their respective chain IDs. This aligns with the PR objective of adding support for new networks.


Line range hint 1-64: Verify PR completeness and ZKSYNC addition

The changes in this file align with the PR objective of adding support for new networks, specifically Worldchain and Astrochain Sepolia. However, there are two points to consider:

  1. The PR objectives mention refactoring ChainAddresses, but there's no evidence of this refactoring in the chains.rs file. Please ensure that this refactoring is present in other files of this PR or clarify if it's no longer part of the scope.

  2. The ZKSYNC chain has been added, which wasn't explicitly mentioned in the PR objectives. While this addition seems beneficial, it would be good to update the PR description to include this change for clarity.

Could you please clarify these points and update the PR description if necessary?

src/entities/weth9.rs (3)

119-125: LGTM! New chain ID 11155420 added correctly.

The addition of chain ID 11155420 (OP Sepolia) is implemented correctly and consistently with other entries. The token address, name, and decimals are appropriate for WETH.


140-146: LGTM! New chain ID 421614 added correctly.

The addition of chain ID 421614 (Arbitrum Sepolia) is implemented correctly and consistently with other entries. The token address, name, and decimals are appropriate for WETH.


Line range hint 1-231: Overall, the changes look good and align with the PR objectives.

The modifications to the WETH9 struct successfully add support for new networks, including Worldchain and Astrochain Sepolia, as well as other relevant networks. The implementations are consistent with existing patterns and follow best practices.

A few suggestions have been made to improve readability and clarity:

  1. Grouping chain IDs in the new method for better organization.
  2. Adding comments to identify networks in the on_chain method.
  3. Verifying the correctness of WETH addresses for new networks.

These minor improvements will enhance the maintainability of the code without affecting its functionality.

src/addresses.rs (9)

12-12: Update to nonfungible_position_manager_address field is acceptable

Changing nonfungible_position_manager_address from an Option<Address> to Address makes it a mandatory field, simplifying the struct and ensuring consistency across usage.


15-16: Addition of mixed_route_quoter_v2_address field

Adding mixed_route_quoter_v2_address enhances support for version 2 of the Mixed Route Quoter, allowing for improved functionality.


18-19: Introduction of v4_pool_manager_address and v4_position_manager_address fields

Including v4_pool_manager_address and v4_position_manager_address prepares the struct for upcoming version 4 features, promoting future scalability.


94-95: Added V2_FACTORY_ADDRESS entries for new networks

The inclusion of (ChainId::WORLDCHAIN as u64, V2_FACTORY_ADDRESS) and (ChainId::ASTROCHAIN_SEPOLIA as u64, V2_FACTORY_ADDRESS) ensures that these new networks are supported in the V2 Factory Addresses map.


135-142: Added V2_ROUTER_ADDRESSES entries for new networks

Adding router addresses for WORLDCHAIN and ASTROCHAIN_SEPOLIA extends compatibility with these networks, facilitating seamless operations on them.


170-175: Verify addresses for MAINNET and GOERLI

Please ensure that the mixed_route_quoter_v1_address values for MAINNET_ADDRESSES and GOERLI_ADDRESSES are correct and correspond to the deployed contracts on those networks.


494-500: Update NONFUNGIBLE_POSITION_MANAGER_ADDRESSES mapping

With nonfungible_position_manager_address now being mandatory, ensure that all entries in NONFUNGIBLE_POSITION_MANAGER_ADDRESSES are present and correctly mapped for each supported chain.


355-365: ⚠️ Potential issue

Confirm correctness of WORLDCHAIN_ADDRESSES

The addresses provided for WORLDCHAIN_ADDRESSES need to be verified to ensure they match the actual deployed contract addresses on the WORLDCHAIN network.


366-374: ⚠️ Potential issue

Confirm correctness of ASTROCHAIN_SEPOLIA_ADDRESSES

Similarly, please verify that the addresses listed under ASTROCHAIN_SEPOLIA_ADDRESSES correspond to the correct contracts on the ASTROCHAIN Sepolia network.

src/entities/weth9.rs Show resolved Hide resolved
src/addresses.rs Show resolved Hide resolved
src/addresses.rs Show resolved Hide resolved
Copy link
Owner

@malik672 malik672 left a comment

Choose a reason for hiding this comment

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

I don't know about the comments removal though?

@shuhuiluo
Copy link
Collaborator Author

I don't know about the comments removal though?

They are useless AI comments which aren't even correct. What's "The address for the Uniswap V2 Factory Address claim contract"? The code is self-explanatory.

@shuhuiluo shuhuiluo merged commit 6fd1059 into master Oct 6, 2024
3 checks passed
@shuhuiluo shuhuiluo deleted the address branch October 6, 2024 08:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants