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

refactor: add bridge token #912

Merged
merged 1 commit into from
Jan 16, 2025
Merged

refactor: add bridge token #912

merged 1 commit into from
Jan 16, 2025

Conversation

zakir-code
Copy link
Contributor

@zakir-code zakir-code commented Jan 16, 2025

Summary by CodeRabbit

Based on the comprehensive changes across multiple files, here are the release notes:

  • New Features

    • Added support for checking ERC20 token existence
    • Enhanced native coin registration process
    • Improved token metadata handling
  • Refactoring

    • Simplified token contract deployment logic
    • Updated method signatures for better metadata management
    • Streamlined cross-chain token operations
  • Chores

    • Removed deprecated token deployment method
    • Updated mock interfaces for testing

The changes focus on improving token management and cross-chain functionality with more robust metadata handling and error checking.

Copy link

coderabbitai bot commented Jan 16, 2025

Walkthrough

This pull request introduces significant changes to token handling across multiple components of the cross-chain and ERC20 modules. The modifications focus on standardizing token metadata management, introducing new methods for checking token existence, and simplifying token registration processes. Key changes include updating method signatures to use metadata objects, adding methods to check for ERC20 token existence, and removing deprecated token deployment methods.

Changes

File Change Summary
precompiles/bank/contract_test.go Updated SetErc20Token to use fxtypes.NewMetadata for token metadata
x/crosschain/keeper/bridge_token.go Enhanced error handling and token base denomination logic in AddBridgeTokenExecuted
x/crosschain/mock/expected_keepers_mocks.go Added mock methods HasERC20Token and RegisterNativeCoin
x/crosschain/types/expected_keepers.go Added interface methods HasERC20Token and RegisterNativeCoin
x/erc20/keeper/contract.go Removed DeployUpgradableToken method
x/erc20/keeper/erc20_token.go Updated AddERC20Token method signature, added HasERC20Token method
x/erc20/keeper/proposal.go Modified RegisterNativeCoin and RegisterNativeERC20 with new metadata handling

Sequence Diagram

sequenceDiagram
    participant Caller
    participant Keeper
    participant EVMKeeper
    participant TokenRegistry

    Caller->>Keeper: AddERC20Token(metadata)
    Keeper->>TokenRegistry: Check token existence
    TokenRegistry-->>Keeper: Token status
    alt Token does not exist
        Keeper->>EVMKeeper: Deploy contract
        EVMKeeper-->>Keeper: Contract address
        Keeper->>TokenRegistry: Register token
    end
    Keeper-->>Caller: Confirmation
Loading

Possibly related PRs

Poem

🐰 Tokens dance, metadata's new tune
Contracts leap with metadata's boon
Bridge tokens flow, errors take flight
In CodeRabbit's realm, everything's bright!
A rabbit's code, precise and clean 🌈

Finishing Touches

  • 📝 Generate Docstrings (Beta)

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 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.

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)
x/crosschain/keeper/bridge_token.go (2)

22-22: Improve clarity of the error message

The error message could be rephrased for better readability. Consider updating it to:

"%s token decimals do not match %d; expected %d"

Apply this diff to adjust the error message:

 return types.ErrInvalid.Wrapf("%s denom decimals not match %d, expect %d",
+return types.ErrInvalid.Wrapf("%s token decimals do not match %d; expected %d",
  fxtypes.DefaultSymbol, claim.Decimals, fxtypes.DenomUnit)

32-39: Check the order of operations for token registration

Currently, AddBridgeToken is called before checking if the ERC20 token exists with HasERC20Token. It might be more efficient to verify the token's existence first to avoid unnecessary processing if the token already exists.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 4801922 and 39657d4.

📒 Files selected for processing (7)
  • precompiles/bank/contract_test.go (1 hunks)
  • x/crosschain/keeper/bridge_token.go (1 hunks)
  • x/crosschain/mock/expected_keepers_mocks.go (2 hunks)
  • x/crosschain/types/expected_keepers.go (1 hunks)
  • x/erc20/keeper/contract.go (0 hunks)
  • x/erc20/keeper/erc20_token.go (2 hunks)
  • x/erc20/keeper/proposal.go (3 hunks)
💤 Files with no reviewable changes (1)
  • x/erc20/keeper/contract.go
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Mergify Merge Protections
  • GitHub Check: Summary
🔇 Additional comments (10)
x/crosschain/types/expected_keepers.go (1)

60-61: LGTM! Well-designed interface methods.

The new methods HasERC20Token and RegisterNativeCoin are well-designed, following Go naming conventions and maintaining consistency with the existing interface methods.

x/crosschain/mock/expected_keepers_mocks.go (2)

497-510: LGTM! Well-implemented mock method.

The mock implementation for HasERC20Token correctly follows the gomock patterns and provides proper test helpers.


526-539: LGTM! Well-implemented mock method.

The mock implementation for RegisterNativeCoin correctly follows the gomock patterns and provides proper test helpers.

precompiles/bank/contract_test.go (1)

50-51: LGTM! Improved token metadata handling.

The change improves token metadata handling by using fxtypes.NewMetadata to create a structured metadata object, which is a better approach than passing individual parameters.

x/erc20/keeper/erc20_token.go (2)

Line range hint 14-43: Function AddERC20Token successfully refactored to use Metadata

The method now accepts a banktypes.Metadata object, consolidating token metadata handling and simplifying the interface. The implementation properly validates the metadata and ensures that tokens are not duplicated.


47-49: New method HasERC20Token correctly implemented

The HasERC20Token method provides a convenient way to check for the existence of an ERC20 token by its base denomination. This enhances the token management capabilities of the Keeper.

x/crosschain/keeper/bridge_token.go (1)

18-24: Verify the correctness of the base denomination assignment

The logic for assigning baseDenom based on claim.Symbol may have implications for token handling:

  • When claim.Symbol matches fxtypes.DefaultSymbol, baseDenom is set to fxtypes.DefaultDenom.
  • Otherwise, baseDenom is the lowercase of claim.Symbol.

Ensure that this approach aligns with the intended token denomination mapping and does not cause conflicts with existing tokens.

x/erc20/keeper/proposal.go (3)

24-34: Refactored token registration to handle default and custom tokens appropriately

The introduction of tokenContract and metadata variables enhances the flexibility of RegisterNativeCoin. The conditional logic correctly differentiates between the default symbol and other tokens, using the appropriate contracts and metadata.


32-34: Ensure consistent handling of decimals type

While decimals is of type uint8, it is converted to uint32 when creating metadata. Confirm that this type conversion is intentional and that it does not lead to inconsistencies.


66-67: Properly creating metadata in RegisterNativeERC20

The metadata is correctly initialized using fxtypes.NewMetadata, ensuring that the token's name, symbol, and decimals are accurately represented. This aligns with the updated AddERC20Token method.

x/crosschain/keeper/bridge_token.go Show resolved Hide resolved
@zakir-code zakir-code merged commit 61bd6d0 into main Jan 16, 2025
13 checks passed
@zakir-code zakir-code deleted the zakir/add-bridge-token branch January 16, 2025 08:34
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.

1 participant