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: migrate erc20 token pair #783

Merged
merged 2 commits into from
Oct 25, 2024
Merged

chore: migrate erc20 token pair #783

merged 2 commits into from
Oct 25, 2024

Conversation

zakir-code
Copy link
Contributor

@zakir-code zakir-code commented Oct 25, 2024

Summary by CodeRabbit

  • New Features

    • Enhanced migration logic for handling token pairs, improving the robustness of the migration process.
  • Bug Fixes

    • Improved error handling during token migration operations.
  • Refactor

    • Updated variable naming for clarity and streamlined method signatures.
    • Removed legacy function for checking native ERC20 tokens, transitioning to a more direct approach.
  • Chores

    • Cleaned up unnecessary import statements in the migration files.

Copy link

coderabbitai bot commented Oct 25, 2024

Walkthrough

The changes in this pull request enhance the migration functionality within the v8 package of the ERC20 module. A new method, migrateTokenPair, is introduced to manage the migration of token pairs, including error handling for missing metadata. The migrateKeys method is updated to incorporate this new functionality. Additionally, the LegacyIsNativeERC20 function is removed, and several method signatures in migrate.go are modified for clarity and parameter reordering. These updates streamline the migration process and improve the handling of ERC20 tokens.

Changes

File Path Change Summary
x/erc20/migrations/v8/keys.go - Added method migrateTokenPair for migrating token pairs.
- Updated import statements.
- Modified migrateKeys to include migrateTokenPair.
x/erc20/migrations/v8/legacy.go - Removed imports: storetypes, codec, sdk, and types.
- Deleted LegacyIsNativeERC20 function.
x/erc20/migrations/v8/migrate.go - Renamed variable baseDenom to newBaseDenom.
- Streamlined addToken method signature.
- Updated addIBCToken parameter order.
- Introduced variable erc20Token in addBridgeToken.

Possibly related PRs

🐰 In the meadow where tokens play,
A new path for pairs has come to stay.
With metadata checked and errors in sight,
The migrator hops, making things right.
Old functions gone, new names in the fray,
Hooray for the changes, hip-hip-hooray! 🌼


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 (2)
x/erc20/migrations/v8/keys.go (2)

72-75: Provide more context in the error message for missing metadata

When metadata is not found (line 74), the error returned indicates the denomination that was not found. Consider providing additional context to help diagnose the issue more effectively, such as suggesting possible reasons or next steps.

Consider updating the error message as follows:

-       return sdkerrors.ErrKeyNotFound.Wrapf("metadata not found: %s", tokenPair.GetDenom())
+       return sdkerrors.ErrKeyNotFound.Wrapf("metadata not found for denomination '%s'. Ensure that the denomination is registered and metadata is properly set.", tokenPair.GetDenom())

66-89: Add unit tests for migrateTokenPair to ensure migration correctness

The new migrateTokenPair function is pivotal to the migration process. Adding unit tests for this function will help ensure that it behaves correctly under various scenarios, such as when metadata is missing, or denominations have different cases.

Would you like assistance in creating unit tests for migrateTokenPair to improve test coverage?

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between b4ac384 and a08a11b.

📒 Files selected for processing (3)
  • x/erc20/migrations/v8/keys.go (3 hunks)
  • x/erc20/migrations/v8/legacy.go (0 hunks)
  • x/erc20/migrations/v8/migrate.go (3 hunks)
💤 Files with no reviewable changes (1)
  • x/erc20/migrations/v8/legacy.go
🔇 Additional comments (6)
x/erc20/migrations/v8/migrate.go (5)

24-41: LGTM! Variable renaming improves clarity.

The change from baseDenom to newBaseDenom makes the code more self-documenting, while maintaining the correct token exclusion logic and special case handling for PUNDIX.


Line range hint 46-51: LGTM! Method maintains correct routing logic.

The method correctly determines whether to handle IBC or bridge tokens based on the alias prefix.


86-89: LGTM! Improved error handling for ERC20 token retrieval.

The addition of explicit error handling for GetERC20Token improves the robustness of the code.


59-59: Verify parameter ordering in AddIBCToken call.

Please ensure that the parameter order (channel, base, alias) matches the keeper's AddIBCToken method signature to prevent runtime errors.

✅ Verification successful

Parameter order in AddIBCToken call is incorrect

The keeper's AddIBCToken method signature in x/erc20/keeper/ibc_token.go is:

func (k Keeper) AddIBCToken(ctx context.Context, channel, baseDenom, ibcDenom string)

But the call in the migration code uses:

m.keeper.AddIBCToken(ctx, channel, base, alias)

The parameter order should be:

  • ctx (correct)
  • channel (correct)
  • base as baseDenom (correct)
  • alias as ibcDenom (correct)
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for the AddIBCToken method definition to verify parameter order
ast-grep --pattern 'func $_AddIBCToken($$$) {
  $$$
}'

Length of output: 63


Script:

#!/bin/bash
# Let's try a different approach to find the AddIBCToken method definition
# First, let's use ripgrep to find the method definition
rg "func.*AddIBCToken" -A 5

# Also search for any interface definitions that might contain this method
rg "interface.*\{" -A 10 -B 2 | rg -A 10 "AddIBCToken"

Length of output: 462


91-94: Verify the impact of removing LegacyIsNativeERC20.

The change from LegacyIsNativeERC20 to direct IsNativeERC20 check looks correct, but we should verify there are no remaining references to the legacy method.

✅ Verification successful

No remaining references to LegacyIsNativeERC20 found, migration is correct

The verification confirms:

  1. No references to LegacyIsNativeERC20 exist in the codebase
  2. The IsNativeERC20() method is consistently implemented in x/erc20/types/token.go and used correctly in:
    • Migration code (x/erc20/migrations/v8/migrate.go)
    • Convert logic (x/erc20/keeper/convert.go)
    • Crosschain precompile (x/crosschain/precompile/keeper.go)
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for any remaining references to LegacyIsNativeERC20
rg "LegacyIsNativeERC20"

# Search for IsNativeERC20 usage to ensure consistent implementation
ast-grep --pattern 'IsNativeERC20()'

Length of output: 63


Script:

#!/bin/bash
# Search for any remaining references to LegacyIsNativeERC20 with case insensitive flag
rg -i "legacyisnativeerc20"

# Search for IsNativeERC20 method implementations and usages with context
rg -A 3 "IsNativeERC20"

# Look for any legacy references in migration files
fd -e go . x/erc20/migrations | xargs cat

Length of output: 14641

x/erc20/migrations/v8/keys.go (1)

82-82: Confirm the correctness of modifying tokenPair.Denom directly

In line 82, tokenPair.Denom is modified by setting it to strings.ToLower(md.Symbol). Ensure that changing the Denom field directly does not have unintended side effects elsewhere in the codebase, especially if tokenPair is used after this modification.

To verify if tokenPair.Denom modification is safe, please review the usage of tokenPair after this assignment.

x/erc20/migrations/v8/keys.go Show resolved Hide resolved
x/erc20/migrations/v8/keys.go Show resolved Hide resolved
x/erc20/migrations/v8/keys.go Show resolved Hide resolved
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

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between a08a11b and ebae607.

📒 Files selected for processing (1)
  • x/erc20/migrations/v8/keys.go (3 hunks)
🔇 Additional comments (5)
x/erc20/migrations/v8/keys.go (5)

4-5: LGTM! Import changes align with new functionality.

The added imports for strings and sdkerrors are necessary for the new token pair migration logic.

Also applies to: 9-11


21-23: LGTM! Migration order and error handling are appropriate.

The addition of migrateTokenPair maintains consistent error handling and follows a logical migration sequence.


71-71: Previous review comment is still valid: Handle unmarshaling errors safely.

Using MustUnmarshal can cause panics. The previous suggestion to use Unmarshal with proper error handling should be implemented.


76-81: Previous review comment is still valid: Ensure consistent store cleanup.

The store cleanup inconsistency noted in the previous review remains - the old key should be deleted in both branches to prevent data inconsistency.


66-88: Consider adding validation for the token pair structure.

The function should validate the token pair structure after unmarshaling to ensure all required fields are present and valid.

Let's verify the token pair structure requirements:

x/erc20/migrations/v8/keys.go Show resolved Hide resolved
@nulnut nulnut merged commit c1b00aa into main Oct 25, 2024
10 checks passed
@nulnut nulnut deleted the nulnut/migrate-token-pair branch October 25, 2024 08:38
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