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

feat: update factory address in wrapper contract #139

Merged
merged 1 commit into from
Jan 6, 2025
Merged

Conversation

beer-1
Copy link
Member

@beer-1 beer-1 commented Jan 6, 2025

Description

update the factory contract address in the wrapper contract whenever the factory contract is redeployed on the chain.


Author Checklist

All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.

I have...

  • included the correct type prefix in the PR title, you can find examples of the prefixes below:
  • confirmed ! in the type prefix if API or client breaking change
  • targeted the correct branch
  • provided a link to the relevant issue or specification
  • reviewed "Files changed" and left comments if necessary
  • included the necessary unit and integration tests
  • updated the relevant documentation or specification, including comments for documenting Go code
  • confirmed all CI checks have passed

Reviewers Checklist

All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.

I have...

  • confirmed the correct type prefix in the PR title
  • confirmed all author checklist items have been addressed
  • reviewed state machine logic, API design and naming, documentation is accurate, tests and test coverage

Summary by CodeRabbit

  • New Features

    • Added ability to set a new factory address for ERC20 wrapper contract
    • Enhanced ERC20 contract management with new ABI retrieval methods
  • Bug Fixes

    • Improved error handling during ERC20 contract deployment and factory address updates
  • Chores

    • Updated version from 0.6.7 to 0.6.8
    • Refactored ERC20 contract deployment and management logic
  • Tests

    • Added comprehensive test coverage for ERC20 factory and wrapper contract deployments

@beer-1 beer-1 self-assigned this Jan 6, 2025
@beer-1 beer-1 requested a review from a team as a code owner January 6, 2025 06:50
Copy link

coderabbitai bot commented Jan 6, 2025

Walkthrough

This pull request introduces updates to the ERC20 wrapper and factory contract deployment process. The changes include modifying the upgrade process in app/upgrade.go, adding a SetFactory method to the ERC20 wrapper contract, and enhancing the ERC20 keeper to support new ABI retrieval methods. The modifications aim to provide more flexibility in managing ERC20 contracts during system upgrades, with improved error handling and contract interaction capabilities.

Changes

File Change Summary
app/upgrade.go - Updated upgradeName to "0.6.8"
- Refactored ERC20 contract update logic into new updateERC20s method
x/evm/contracts/erc20_wrapper/ERC20Wrapper.go - Added SetFactory method for contract owner to modify factory address
x/evm/contracts/erc20_wrapper/ERC20Wrapper.sol - Added ERC20ACL as base contract
- Modified factory variable to be mutable
- Added setFactory function with onlyChain modifier
x/evm/keeper/erc20.go - Added ERC20WrapperABI field
- Added methods to retrieve Factory and Wrapper ABIs
x/evm/keeper/genesis.go - Enhanced error handling for ERC20 factory address deployment
x/evm/keeper/genesis_test.go - Added new test function Test_DeployERC20Factory
- Added helper function to query factory address
x/evm/types/expected_keeper.go - Added interface methods to retrieve Factory and Wrapper ABIs

Possibly related PRs

Suggested reviewers

  • Vritra4

Poem

🐰 Hop, hop, upgrade we go!
ERC20 contracts start to glow
Factory address now can change
With rabbit magic, code rearrange
A wrapper's dance of byte and might 🌟


🪧 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 generate docstrings to generate docstrings for this PR. (Beta)
  • @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.

@beer-1 beer-1 added the bug Something isn't working label Jan 6, 2025
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: 1

🧹 Nitpick comments (2)
app/upgrade.go (1)

52-58: Consider logging more details for troubleshooting.
When ignoring the vm.ErrContractAddressCollision error, it could be helpful to log or emit an event indicating the wrapper contract was already deployed. This will facilitate observability and debugging of upgrade steps.

x/evm/contracts/erc20_wrapper/ERC20Wrapper.sol (1)

32-37: Add emit event in setFactory.
Updating the factory is a significant on-chain event. Emitting an event can help off-chain clients track or respond to this change.

 function setFactory(address newFactory) external onlyChain {
     require(newFactory != address(0), "invalid factory address");
     factory = ERC20Factory(newFactory);
+    emit FactoryUpdated(newFactory);
 }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8730fd9 and eac361f.

📒 Files selected for processing (7)
  • app/upgrade.go (4 hunks)
  • x/evm/contracts/erc20_wrapper/ERC20Wrapper.go (2 hunks)
  • x/evm/contracts/erc20_wrapper/ERC20Wrapper.sol (2 hunks)
  • x/evm/keeper/erc20.go (3 hunks)
  • x/evm/keeper/genesis.go (1 hunks)
  • x/evm/keeper/genesis_test.go (2 hunks)
  • x/evm/types/expected_keeper.go (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Run test and upload codecov
🔇 Additional comments (22)
app/upgrade.go (6)

25-25: Version naming looks good.
This version bump to 0.6.8 is consistent with the workflow. No issues here.


Line range hint 59-70: Deployment sequence verification.
After deploying the ERC20 factory at line 59, the subsequent logic to update existing ERC20 contracts in line 70 is conditional upon a successful deployment. This approach helps maintain consistent state. Just ensure that any partial state updates in preceding lines are rolled back or handled properly when an error occurs.


81-85: Function documentation is clear.
The docstring accurately describes the upgrade steps for ERC20 contracts. Great clarity on each bullet point.


86-92: Validate new code references.
Line 86 references erc20.Erc20MetaData.Bin. Confirm that this artifact is updated to the correct bytecode and tested on the latest deployment.


93-95: Hashing approach is standard.
Keccak256 is appropriate for obtaining the code hash. No issues.


96-127: Solid error handling and iteration over all contracts.
This loop robustly updates each contract’s code, code hash, and code size. Error handling looks good, returning from the iteration immediately if any step fails.

x/evm/types/expected_keeper.go (1)

69-70: Adding ABI getters expands integration capabilities.
Exposing these two new methods (GetERC20FactoryABI and GetERC20WrapperABI) is beneficial for interacting with factory and wrapper contracts. Ensure thorough unit coverage for all new interface methods.

x/evm/keeper/genesis_test.go (3)

6-6: Import addition is pertinent.
You are using sdk.Context within your test, so importing the SDK is necessary and correct.


108-141: Test_DeployERC20Factory provides solid coverage.
The test appropriately verifies that the factory address is updated both before and after wrapper deployment. Good job verifying outcomes with require.Equal and require.NotEqual.


143-159: Helper function clarifies reading from wrapper.
queryFactoryAddressFromWrapper is well-crafted to retrieve the current factory address. It improves test readability and reusability.

x/evm/contracts/erc20_wrapper/ERC20Wrapper.sol (1)

13-13: Inheritance extension from ERC20ACL.
By inheriting ERC20ACL, you’ve centralized the contract’s access control logic. Ensure that the new ACL restrictions align with your security requirements.

x/evm/keeper/genesis.go (3)

65-68: Ensure robust error handling.
Storing the factory address in the keeper and checking for errors is correct. The approach is appropriate for redeployment scenarios. No further adjustments needed here.


70-81: Validate chain call to set wrapper's factory.
This logic ensures that the wrapper contract references the correct factory address. The error checks before and after packing the ABI and executing the EVM call are comprehensive. If the wrapper contract hasn’t been set yet, the code safely skips the setFactory call. The added calls and checks appear solid.


83-83: Return statement.
Returning nil maintains a clean exit pathway without any additional side effects. Looks good.

x/evm/keeper/erc20.go (6)

22-22: Added import for erc20_wrapper.
The new import references the wrapper contract definitions. It's consistent with the usage below.


33-33: New field in ERC20Keeper for ERC20WrapperABI.
Adding this ABI reference aligns with the introduced method calls. Make sure to confirm that it’s properly instantiated everywhere needed.


47-50: Load wrapper ABI gracefully.
Retrieving the ABI for the wrapper contract follows the same pattern as the existing code for the ERC20 and factory ABIs. The error handling is straightforward and appropriate.


57-57: Initialize ERC20Keeper with wrapper ABI.
Ensures the keeper has all relevant contract ABIs for future interactions. This is coherent with the usage pattern.


65-69: Expose GetERC20FactoryABI.
Providing the factory ABI for external usage is correct. Implementation is trivial and accurate.


70-74: Expose GetERC20WrapperABI.
Similarly, making the wrapper ABI accessible for other components is clean and consistent with the new code additions.

x/evm/contracts/erc20_wrapper/ERC20Wrapper.go (2)

34-35: Updated ABI and bytecode.
These changes reflect the new setFactory method. The contract metadata is consistent with the introduction of the new function signature in the ABI.


371-390: New setFactory methods.
The three new transactor/session methods allow on-chain updates of the factory address. The naming and parameters follow best practices, and the additions align with the contract's new functionality. Error handling is delegated to the standard binding's pattern, which is standard for Go-Ethereum contract calls.

Copy link

codecov bot commented Jan 6, 2025

Codecov Report

Attention: Patch coverage is 16.39344% with 51 lines in your changes missing coverage. Please review.

Project coverage is 56.97%. Comparing base (8730fd9) to head (eac361f).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
app/upgrade.go 0.00% 37 Missing ⚠️
x/evm/keeper/genesis.go 40.00% 6 Missing and 3 partials ⚠️
x/evm/keeper/erc20.go 44.44% 4 Missing and 1 partial ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #139      +/-   ##
==========================================
- Coverage   57.03%   56.97%   -0.06%     
==========================================
  Files         110      110              
  Lines       10049    10073      +24     
==========================================
+ Hits         5731     5739       +8     
- Misses       3495     3507      +12     
- Partials      823      827       +4     
Files with missing lines Coverage Δ
x/evm/keeper/erc20.go 46.05% <44.44%> (-0.19%) ⬇️
x/evm/keeper/genesis.go 48.30% <40.00%> (-0.92%) ⬇️
app/upgrade.go 3.84% <0.00%> (-0.11%) ⬇️

@beer-1 beer-1 merged commit e9af76c into main Jan 6, 2025
9 of 10 checks passed
@beer-1 beer-1 deleted the fix/wrapper-factory branch January 6, 2025 07:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant