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

fix(token): migrate ERC20 token on testnet #865

Merged
merged 1 commit into from
Jan 3, 2025

Conversation

zakir-code
Copy link
Contributor

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

Summary by CodeRabbit

  • New Features

    • Enhanced ERC20 token migration and validation during testnet upgrade process
    • Improved tracking and indexing of ERC20 token addresses and denominations
  • Bug Fixes

    • Added robust error handling for ERC20 token migrations
    • Ensured correct mapping of ERC20 addresses to denominations
  • Tests

    • Added new validation function to check ERC20 token existence and indexing after upgrade

Copy link

coderabbitai bot commented Jan 3, 2025

Walkthrough

The pull request introduces enhancements to the ERC20 token migration and validation process during the application upgrade. A new function checkErc20Token is added to the test suite to validate the existence and indexing of ERC20 tokens. In the upgrade handler, a new function migrateTestnetErc20Token is implemented to handle ERC20 token migration for the testnet. Additionally, modifications are made to the migrateTokenPair function to ensure proper denomination indexing for ERC20 tokens.

Changes

File Change Summary
app/upgrade_test.go Added checkErc20Token function to validate ERC20 tokens during upgrade testing
app/upgrades/v8/upgrade.go Introduced migrateTestnetErc20Token function for ERC20 token migration in testnet
x/erc20/migrations/v8/keys.go Enhanced migrateTokenPair with additional denomination index setting

Sequence Diagram

sequenceDiagram
    participant Upgrade Handler
    participant ERC20 Keeper
    participant Token Migrator

    Upgrade Handler->>ERC20 Keeper: migrateTestnetErc20Token()
    ERC20 Keeper->>Token Migrator: Iterate through tokens
    Token Migrator-->>ERC20 Keeper: Retrieve token pairs
    ERC20 Keeper->>ERC20 Keeper: Set DenomIndex for each token
Loading

Possibly related PRs

Poem

🐰 Tokens hopping through the chain,
Migrations dance, no trace of pain.
ERC20s indexed with care,
Upgrade complete, beyond compare!
Rabbit's code hops with glee! 🚀


📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 171f571 and 4d0ea72.

📒 Files selected for processing (3)
  • app/upgrade_test.go (3 hunks)
  • app/upgrades/v8/upgrade.go (3 hunks)
  • x/erc20/migrations/v8/keys.go (2 hunks)
🔇 Additional comments (7)
x/erc20/migrations/v8/keys.go (2)

93-95: Likewise set DenomIndex for fallback scenario.
Storing the updated tokenPair.Denom is a good fallback to maintain correct mappings. Just confirm that no external function expects a different form or casing.


80-82: Ensure DenomIndex consistency.
The code snippet correctly sets the DenomIndex to md.Base, ensuring references remain consistent. Please verify that other references and usage in the codebase properly interpret this index, especially if an ERC20 address maps to multiple denominations in other scenarios.

✅ Verification successful

DenomIndex usage is consistent across the codebase

The verification shows that the DenomIndex is used consistently throughout the codebase:

  • It's a collections.Map that maps bridgeDenom/erc20_contract/ibc_denom to baseDenom (defined in keeper.go)
  • All usages properly maintain this mapping:
    • In erc20_token.go: Sets and retrieves ERC20 token to base denom mappings
    • In ibc_token.go: Maps IBC denoms to base denoms
    • In bridge_token.go: Handles bridge token to base denom mappings
    • In grpc_query.go: Consistently retrieves base denoms for token queries
    • In the v8 migration: Correctly sets ERC20 address to base denom mappings

The code in question follows the same pattern as other parts of the codebase, maintaining the expected mapping between ERC20 addresses and base denominations.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Searching for references to m.keeper.DenomIndex usage within codebase
rg -A 5 "DenomIndex" 

Length of output: 4524

app/upgrade_test.go (2)

86-86: Good to see ERC20 token checks in Test_UpgradeTestnet.
This extends test coverage to ERC20 tokens.


308-328: Comprehensive ERC20 indexing verification.
The new checkErc20Token function ensures that each ERC20 token’s address is properly mapped in the DenomIndex. This is essential for data consistency.

app/upgrades/v8/upgrade.go (3)

54-56: Sequential migration approach.
Calling migrateTestnetErc20Token after migrateTestnetBridgeToken is sensible to ensure tokens are updated in the correct order.


487-487: Ensure iterator closure in testnet migration.
The defer iter.Close() usage is correct to avoid resource leaks while proceeding with the migration.


511-532: Set DenomIndex for testnet ERC20 tokens.
The migration sets DenomIndex for every ERC20 token. Confirm that any placeholders or placeholders outside testnet usage won’t be affected incorrectly.

✅ Verification successful

Let me gather more information about the context and usage of DenomIndex.


Let me gather more specific information about the ERC20 token migration.


Based on the gathered information, I can now provide the final response:

DenomIndex migration is safely scoped to testnet environment
The migration function migrateTestnetErc20Token is only executed when ChainID() == fxtypes.TestnetChainId, ensuring that the DenomIndex updates are strictly limited to testnet tokens. The function iterates through existing ERC20 tokens and sets their corresponding DenomIndex mappings, which is a safe operation as it maintains the existing token-to-denom relationships without affecting any placeholders.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify that no non-testnet usage of DenomIndex references the newly set values

rg "DenomIndex\.Set"

Length of output: 685


Script:

#!/bin/bash
# Check the implementation and usage of DenomIndex
ast-grep --pattern 'type DenomIndex struct {
  $$$
}'

# Check for any testnet specific conditions or checks
rg -B2 -A2 "DenomIndex"

# Look for any testnet related configurations or constants
rg "testnet" -i

Length of output: 32814


Script:

#!/bin/bash
# Check the implementation of ERC20Token and related migrations
ast-grep --pattern 'type ERC20Token struct {
  $$$
}'

# Look for any testnet specific migrations or conditions
rg -B3 -A3 "migrateTestnet"

# Check the usage of ERC20Token.Iterate
rg -B2 -A2 "ERC20Token\.Iterate"

Length of output: 5380


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.

@fx0x55 fx0x55 merged commit 1ef9e49 into main Jan 3, 2025
13 checks passed
@fx0x55 fx0x55 deleted the nulnut/erc20-token-migrate branch January 3, 2025 04:11
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.

3 participants