Skip to content

Conversation

@aarmoa
Copy link
Collaborator

@aarmoa aarmoa commented May 27, 2025

  • Added support for the new evm and erc20 modules queries.
  • Added examples for the new queries and messages.

Solves CP-395

Summary by CodeRabbit

  • New Features

    • Added support for querying ERC20 and EVM modules, including fetching token pairs, EVM account details, balances, storage, contract code, and base fee.
    • Introduced example programs demonstrating how to create and delete ERC20 token pairs, and how to query ERC20 and EVM data on the Injective testnet.
  • Tests

    • Expanded mock client support for ERC20 and EVM query operations to facilitate testing.
  • Chores

    • Updated dependencies and module replacements to newer versions for improved compatibility and performance.
  • Style

    • Updated package import aliases for consistency in example code.

…d examples for the new queries and messages.
@aarmoa aarmoa requested a review from Copilot May 27, 2025 17:54
@coderabbitai
Copy link

coderabbitai bot commented May 27, 2025

Walkthrough

The update introduces new ERC20 and EVM query methods to the chain client, expands the mock client for testing these features, and adds multiple example programs demonstrating their usage. Dependency versions are upgraded in go.mod, and the Makefile is updated to clone a newer branch of the injective-indexer. Minor alias adjustments are made in an example.

Changes

File(s) Change Summary
client/chain/chain.go Adds ERC20 and EVM query methods to the chain client, updates interface and struct, and implements these methods.
client/chain/chain_test_support.go Adds mock implementations for new ERC20 and EVM query methods to the mock chain client.
examples/chain/erc20/1_CreateTokenPair/example.go New example: demonstrates creating an ERC20 token pair.
examples/chain/erc20/2_DeleteTokenPair/example.go New example: demonstrates deleting an ERC20 token pair.
examples/chain/erc20/query/1_AllTokenPairs/example.go New example: queries all ERC20 token pairs.
examples/chain/erc20/query/2_TokenPairByDenom/example.go New example: queries a token pair by denomination.
examples/chain/erc20/query/3_TokenPairByERC20Address/example.go New example: queries a token pair by ERC20 address.
examples/chain/evm/query/1_Account/example.go New example: queries an EVM account.
examples/chain/evm/query/2_CosmosAccount/example.go New example: queries a Cosmos account by EVM address.
examples/chain/evm/query/3_ValidatorAccount/example.go New example: queries an EVM validator account.
examples/chain/evm/query/4_Balance/example.go New example: queries EVM balance.
examples/chain/evm/query/5_Storage/example.go New example: queries EVM storage.
examples/chain/evm/query/6_Code/example.go New example: queries EVM bytecode.
examples/chain/evm/query/7_BaseFee/example.go New example: queries EVM base fee.
examples/chain/12_ChainStream/example.go Changes import alias for stream types from chainStreamModule to chainstreamv2.
go.mod Updates dependency versions and replace directives.
Makefile Updates clone-injective-indexer target to clone from branch v1.16.3 instead of v1.16.0-rc2.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant ChainClient
    participant ERC20Module
    participant EVMModule

    User->>ChainClient: FetchAllTokenPairs()
    ChainClient->>ERC20Module: QueryAllTokenPairs
    ERC20Module-->>ChainClient: AllTokenPairsResponse
    ChainClient-->>User: AllTokenPairsResponse

    User->>ChainClient: FetchEVMAccount(address)
    ChainClient->>EVMModule: QueryAccount(address)
    EVMModule-->>ChainClient: AccountResponse
    ChainClient-->>User: AccountResponse
Loading

Poem

A whisk of code, a hop, a leap—
New queries now, both wide and deep!
ERC20, EVM, all in tow,
With shiny examples, watch them go.
Dependencies fresh, the indexer too—
Rabbits rejoice in what you can do!
🐇✨

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 golangci-lint (1.64.8)

Error: you are using a configuration file for golangci-lint v2 with golangci-lint v1: please use golangci-lint v2
Failed executing command with error: you are using a configuration file for golangci-lint v2 with golangci-lint v1: please use golangci-lint v2

✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 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.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 explain its main purpose.
    • @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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this 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.

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

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds support for v1.16 by integrating new queries for the evm and erc20 modules along with corresponding example programs.

  • Adds example programs for various evm queries (e.g., base fee, code, storage, accounts).
  • Introduces example programs for erc20 queries (e.g., token pair by denom and by ERC20 address, all token pairs, create/delete token pair).
  • Updates client packages to support the new query functions for ERC20 and evm modules.

Reviewed Changes

Copilot reviewed 17 out of 19 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
examples/chain/evm/query/7_BaseFee/example.go Adds an example for fetching the EVM base fee.
examples/chain/evm/query/6_Code/example.go Adds an example for fetching EVM code.
examples/chain/evm/query/5_Storage/example.go Adds an example for fetching EVM storage data.
examples/chain/evm/query/4_Balance/example.go Adds an example for fetching an EVM account balance.
examples/chain/evm/query/3_ValidatorAccount/example.go Adds an example for fetching EVM validator account details.
examples/chain/evm/query/2_CosmosAccount/example.go Adds an example for fetching EVMCosmos account data.
examples/chain/evm/query/1_Account/example.go Adds an example for fetching a general EVM account.
examples/chain/erc20/query/3_TokenPairByERC20Address/example.go Adds an example for querying token pair by ERC20 address.
examples/chain/erc20/query/2_TokenPairByDenom/example.go Adds an example for querying token pair by bank denom.
examples/chain/erc20/query/1_AllTokenPairs/example.go Adds an example for querying all token pairs.
examples/chain/erc20/2_DeleteTokenPair/example.go Adds an example for deleting an ERC20 token pair.
examples/chain/erc20/1_CreateTokenPair/example.go Adds an example for creating an ERC20 token pair.
examples/chain/12_ChainStream/example.go Updates the chain stream example to use the new v2 module imports.
client/chain/chain_test_support.go Introduces new dummy functions for ERC20 and evm module queries in test support.
client/chain/chain.go Integrates new query functions for ERC20 and evm modules into the chain client.
Files not reviewed (2)
  • Makefile: Language not supported
  • go.mod: Language not supported

fmt.Println(err)
}

str, _ := json.MarshalIndent(res, "", " ")
Copy link

Copilot AI May 27, 2025

Choose a reason for hiding this comment

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

[nitpick] Consider handling the error from json.MarshalIndent instead of ignoring it to avoid silent failures.

Suggested change
str, _ := json.MarshalIndent(res, "", " ")
str, err := json.MarshalIndent(res, "", " ")
if err != nil {
fmt.Printf("Error marshaling JSON: %v\n", err)
return
}

Copilot uses AI. Check for mistakes.
Comment on lines +85 to +88
gasPrice = chainClient.CurrentChainGasPrice()
// adjust gas price to make it valid even if it changes between the time it is requested and the TX is broadcasted
gasPrice = int64(float64(gasPrice) * 1.1)
chainClient.SetGasPrice(gasPrice)
Copy link

Copilot AI May 27, 2025

Choose a reason for hiding this comment

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

[nitpick] Consider refactoring the repeated gas price adjustment logic into a helper function to reduce duplication and improve maintainability.

Suggested change
gasPrice = chainClient.CurrentChainGasPrice()
// adjust gas price to make it valid even if it changes between the time it is requested and the TX is broadcasted
gasPrice = int64(float64(gasPrice) * 1.1)
chainClient.SetGasPrice(gasPrice)
adjustAndSetGasPrice(chainClient)

Copilot uses AI. Check for mistakes.
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: 2

♻️ Duplicate comments (3)
examples/chain/evm/query/7_BaseFee/example.go (1)

66-66: Handle the error from json.MarshalIndent.

Consider handling the error from json.MarshalIndent instead of ignoring it to avoid silent failures.

-	str, _ := json.MarshalIndent(res, "", " ")
+	str, err := json.MarshalIndent(res, "", " ")
+	if err != nil {
+		fmt.Printf("Error marshaling JSON: %v\n", err)
+		return
+	}
examples/chain/erc20/1_CreateTokenPair/example.go (1)

55-58: Refactor duplicated gas price adjustment logic

The gas price adjustment logic is duplicated in two places. Consider extracting this into a helper function to improve maintainability and reduce code duplication.

This matches a previous review comment about refactoring the repeated gas price adjustment logic.

Also applies to: 89-92

examples/chain/erc20/2_DeleteTokenPair/example.go (1)

55-58: Refactor duplicated gas price adjustment logic

The same gas price adjustment duplication issue exists here as in the CreateTokenPair example.

This matches the previous review comment about refactoring the repeated gas price adjustment logic into a helper function.

Also applies to: 85-88

🧹 Nitpick comments (12)
examples/chain/evm/query/7_BaseFee/example.go (1)

29-29: Consider using a placeholder or warning comment for the private key.

The hard-coded private key in examples could pose a security risk if users copy this code without understanding the implications. Consider using a clearly marked placeholder or adding a warning comment.

-		"5d386fbdbf11f1141010f81a46b40f94887367562bd33b452bbaa6ce1cd1381e", // keyring will be used if pk not provided
+		"5d386fbdbf11f1141010f81a46b40f94887367562bd33b452bbaa6ce1cd1381e", // WARNING: Replace with your own private key in production
examples/chain/evm/query/5_Storage/example.go (2)

29-29: Consider using a placeholder or warning comment for the private key.

The hard-coded private key in examples could pose a security risk if users copy this code without understanding the implications. Consider using a clearly marked placeholder or adding a warning comment.

-		"5d386fbdbf11f1141010f81a46b40f94887367562bd33b452bbaa6ce1cd1381e", // keyring will be used if pk not provided
+		"5d386fbdbf11f1141010f81a46b40f94887367562bd33b452bbaa6ce1cd1381e", // WARNING: Replace with your own private key in production

68-68: Handle the error from json.MarshalIndent.

Consider handling the error from json.MarshalIndent instead of ignoring it to avoid silent failures.

-	str, _ := json.MarshalIndent(res, "", " ")
+	str, err := json.MarshalIndent(res, "", " ")
+	if err != nil {
+		fmt.Printf("Error marshaling JSON: %v\n", err)
+		return
+	}
examples/chain/evm/query/1_Account/example.go (2)

67-68: Handle JSON marshaling error.

The JSON marshaling error is currently ignored, which could lead to silent failures.

-	str, _ := json.MarshalIndent(res, "", " ")
-	fmt.Print(string(str))
+	str, err := json.MarshalIndent(res, "", " ")
+	if err != nil {
+		fmt.Printf("Error marshaling response: %v\n", err)
+		return
+	}
+	fmt.Print(string(str))

23-31: Consider documenting test credentials.

The hardcoded private key and credentials are appropriate for examples, but consider adding a comment to clarify these are test credentials.

	senderAddress, cosmosKeyring, err := chainclient.InitCosmosKeyring(
		os.Getenv("HOME")+"/.injectived",
		"injectived",
		"file",
		"inj-user",
		"12345678",
-		"5d386fbdbf11f1141010f81a46b40f94887367562bd33b452bbaa6ce1cd1381e", // keyring will be used if pk not provided
+		"5d386fbdbf11f1141010f81a46b40f94887367562bd33b452bbaa6ce1cd1381e", // test private key for example - keyring will be used if pk not provided
		false,
	)
examples/chain/erc20/query/2_TokenPairByDenom/example.go (1)

66-67: Handle JSON marshaling error.

The JSON marshaling error is currently ignored, which could lead to silent failures.

-	str, _ := json.MarshalIndent(res, "", " ")
-	fmt.Print(string(str))
+	str, err := json.MarshalIndent(res, "", " ")
+	if err != nil {
+		fmt.Printf("Error marshaling response: %v\n", err)
+		return
+	}
+	fmt.Print(string(str))
examples/chain/evm/query/4_Balance/example.go (1)

67-68: Handle JSON marshaling error.

The JSON marshaling error is currently ignored, which could lead to silent failures.

-	str, _ := json.MarshalIndent(res, "", " ")
-	fmt.Print(string(str))
+	str, err := json.MarshalIndent(res, "", " ")
+	if err != nil {
+		fmt.Printf("Error marshaling response: %v\n", err)
+		return
+	}
+	fmt.Print(string(str))
examples/chain/evm/query/6_Code/example.go (1)

67-68: Handle JSON marshaling error.

The JSON marshaling error is currently ignored, which could lead to silent failures.

-	str, _ := json.MarshalIndent(res, "", " ")
-	fmt.Print(string(str))
+	str, err := json.MarshalIndent(res, "", " ")
+	if err != nil {
+		fmt.Printf("Error marshaling response: %v\n", err)
+		return
+	}
+	fmt.Print(string(str))
examples/chain/erc20/1_CreateTokenPair/example.go (2)

22-30: Security concern: Hardcoded credentials and private key

This example contains hardcoded sensitive information including keyring password and private key. While this is acceptable for example/demo purposes, it should be clearly documented as such to prevent accidental production usage.

Consider adding a comment to clarify this is for demo purposes only:

+	// NOTE: This example uses hardcoded credentials for demonstration purposes only.
+	// In production, use secure credential management practices.
	senderAddress, cosmosKeyring, err := chainclient.InitCosmosKeyring(
		os.Getenv("HOME")+"/.injectived",
		"injectived",
		"file",
		"inj-user",
		"12345678",
		"5d386fbdbf11f1141010f81a46b40f94887367562bd33b452bbaa6ce1cd1381e", // keyring will be used if pk not provided
		false,
	)

78-78: Consider more robust transaction confirmation

Using a fixed 5-second sleep is not ideal for production code as transaction confirmation times can vary. Consider implementing proper transaction status polling instead.

For production code, consider implementing transaction status polling:

-	time.Sleep(time.Second * 5)
+	// Poll for transaction confirmation instead of fixed sleep
+	// Example: implement a retry mechanism with exponential backoff
examples/chain/erc20/2_DeleteTokenPair/example.go (2)

22-30: Security concern: Hardcoded credentials and private key

Same security concern as in the CreateTokenPair example. This example also contains hardcoded sensitive information.

Consider adding the same security disclaimer comment as suggested for the CreateTokenPair example to maintain consistency across examples.


74-74: Consider more robust transaction confirmation

Same fixed sleep issue as in the CreateTokenPair example.

Consider implementing the same transaction status polling approach suggested for the CreateTokenPair example.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 7d8fb1f and 07a2d52.

⛔ Files ignored due to path filters (2)
  • exchange/derivative_exchange_rpc/pb/goadesign_goagen_injective_derivative_exchange_rpc.pb.go is excluded by !**/*.pb.go
  • go.sum is excluded by !**/*.sum
📒 Files selected for processing (17)
  • Makefile (1 hunks)
  • client/chain/chain.go (5 hunks)
  • client/chain/chain_test_support.go (2 hunks)
  • examples/chain/12_ChainStream/example.go (2 hunks)
  • examples/chain/erc20/1_CreateTokenPair/example.go (1 hunks)
  • examples/chain/erc20/2_DeleteTokenPair/example.go (1 hunks)
  • examples/chain/erc20/query/1_AllTokenPairs/example.go (1 hunks)
  • examples/chain/erc20/query/2_TokenPairByDenom/example.go (1 hunks)
  • examples/chain/erc20/query/3_TokenPairByERC20Address/example.go (1 hunks)
  • examples/chain/evm/query/1_Account/example.go (1 hunks)
  • examples/chain/evm/query/2_CosmosAccount/example.go (1 hunks)
  • examples/chain/evm/query/3_ValidatorAccount/example.go (1 hunks)
  • examples/chain/evm/query/4_Balance/example.go (1 hunks)
  • examples/chain/evm/query/5_Storage/example.go (1 hunks)
  • examples/chain/evm/query/6_Code/example.go (1 hunks)
  • examples/chain/evm/query/7_BaseFee/example.go (1 hunks)
  • go.mod (6 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (2)
examples/chain/erc20/query/2_TokenPairByDenom/example.go (6)
client/common/network.go (1)
  • LoadNetwork (53-202)
client/chain/keys.go (1)
  • InitCosmosKeyring (28-164)
client/chain/context.go (1)
  • NewClientContext (129-215)
client/chain/chain.go (1)
  • NewChainClient (531-654)
client/common/options.go (1)
  • OptionGasPrices (36-47)
client/constants.go (1)
  • DefaultGasPriceWithDenom (6-6)
examples/chain/erc20/query/3_TokenPairByERC20Address/example.go (6)
client/common/network.go (1)
  • LoadNetwork (53-202)
client/chain/keys.go (1)
  • InitCosmosKeyring (28-164)
client/chain/context.go (1)
  • NewClientContext (129-215)
client/chain/chain.go (1)
  • NewChainClient (531-654)
client/common/options.go (1)
  • OptionGasPrices (36-47)
client/constants.go (1)
  • DefaultGasPriceWithDenom (6-6)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: lint
🔇 Additional comments (26)
Makefile (1)

4-4:

Details

❓ Verification inconclusive

Verify the updated branch version exists.

The branch update from v1.16.0-rc2 to v1.16.3 aligns with the PR's objective of adding v1.16 support. This change from a release candidate to a stable version is positive.

Please verify that the v1.16.3 branch exists in the injective-indexer repository:


🏁 Script executed:

#!/bin/bash
# Description: Verify that the v1.16.3 branch exists in the injective-indexer repository
git ls-remote --heads https://github.com/InjectiveLabs/injective-indexer.git | grep "v1.16.3"

Length of output: 209


🏁 Script executed:

#!/bin/bash
# List all repositories in the InjectiveLabs organization and filter for names containing "indexer"
curl -s https://api.github.com/orgs/InjectiveLabs/repos?per_page=200 \
  | jq -r '.[] | select(.name | test("(?i)indexer")) | "\(.name) -> \(.clone_url)"'

Length of output: 154


Confirm repository URL and branch existence.

The clone command for https://github.com/InjectiveLabs/injective-indexer.git returns “repository not found.” Please verify:

  • The correct GitHub repository path for the indexer.
  • That a branch or tag named v1.16.3 exists in that repository.
examples/chain/12_ChainStream/example.go (2)

8-8: LGTM! Improved naming consistency.

The alias change from chainStreamModule to chainstreamv2 improves clarity by explicitly indicating this is version 2 of the chain stream types.


42-78: LGTM! Consistent usage of the updated alias.

All type references have been consistently updated to use the new chainstreamv2 alias, maintaining code coherency.

examples/chain/evm/query/7_BaseFee/example.go (1)

61-64: LGTM! Proper usage of the new EVM base fee query.

The example correctly demonstrates the usage of the new FetchEVMBaseFee method with appropriate error handling.

examples/chain/evm/query/5_Storage/example.go (1)

61-66: LGTM! Proper usage of the new EVM storage query.

The example correctly demonstrates the usage of the new FetchEVMStorage method with appropriate parameters and error handling.

examples/chain/erc20/query/3_TokenPairByERC20Address/example.go (1)

16-60: Example setup and error handling look good.

The initialization code follows the standard pattern for SDK examples with appropriate testnet configuration. The hardcoded credentials are acceptable for demonstration purposes.

Also applies to: 63-70

examples/chain/evm/query/2_CosmosAccount/example.go (1)

16-70: LGTM! Proper implementation of EVM Cosmos account query.

The example correctly demonstrates the FetchEVMCosmosAccount method with appropriate setup and error handling. The EVM address format and method call are consistent with the example's purpose.

examples/chain/erc20/query/1_AllTokenPairs/example.go (1)

16-69: LGTM! Clean implementation of all token pairs query.

The example properly demonstrates the FetchAllTokenPairs method with standard setup code and appropriate error handling. The implementation aligns perfectly with the filename and intended functionality.

examples/chain/evm/query/3_ValidatorAccount/example.go (1)

16-70: LGTM! Correct implementation of EVM validator account query.

The example properly demonstrates the FetchEVMValidatorAccount method using a valid consensus address format. The setup and error handling follow the established pattern for SDK examples.

examples/chain/evm/query/4_Balance/example.go (1)

61-62: Good consistency with other examples.

Using the same EVM address across related examples provides consistency and makes it easier to compare results across different query types.

examples/chain/evm/query/6_Code/example.go (1)

16-70: Well-structured example demonstrating EVM code query.

The example follows consistent patterns with other EVM query examples and properly demonstrates the usage of the new FetchEVMCode functionality. The client initialization, error handling, and output formatting are appropriate for an example program.

examples/chain/erc20/1_CreateTokenPair/example.go (1)

60-68: LGTM: Token pair configuration

The token pair configuration with USDT denomination and ERC20 address is correctly structured and follows the expected pattern for the MsgCreateTokenPair message.

examples/chain/erc20/2_DeleteTokenPair/example.go (1)

62-65: LGTM: Delete token pair message structure

The MsgDeleteTokenPair message is correctly constructed with the appropriate sender and bank denomination fields.

go.mod (4)

14-14: LGTM: CosmWasm dependency update

The upgrade to CosmWasm/wasmd v0.53.2 aligns with supporting the new EVM and ERC20 module features.


24-24: LGTM: IBC-go version update

The update to cosmos/ibc-go/v8 v8.6.1 is appropriate for the new module support.


240-256: LGTM: Coordinated Injective cosmos-sdk updates

The systematic update of all InjectiveLabs cosmos-sdk modules from -inj.2 to -inj.3 indicates a coordinated upgrade to support the new EVM and ERC20 functionality.


273-273:

Details

✅ Verification successful

New replace directive for go-bip39

A new replace directive has been added for github.com/tyler-smith/go-bip39 pointing to the InjectiveLabs fork. This suggests there may be custom modifications needed.

Please verify that the InjectiveLabs fork of go-bip39 is necessary and properly maintained:


🏁 Script executed:

#!/bin/bash
# Check if the InjectiveLabs go-bip39 fork exists and get its details
curl -s https://api.github.com/repos/InjectiveLabs/go-bip39 | jq '{name, description, updated_at, default_branch}'

# Check for any obvious differences in recent commits
curl -s https://api.github.com/repos/InjectiveLabs/go-bip39/commits?per_page=5 | jq '.[].commit.message'
curl -s https://api.github.com/repos/tyler-smith/go-bip39/commits?per_page=5 | jq '.[].commit.message'

Length of output: 581


🏁 Script executed:

#!/bin/bash
# Retrieve recent commit messages for the original tyler-smith go-bip39
curl -sL https://api.github.com/repos/tyler-smith/go-bip39/commits?per_page=5 | jq '.[].commit.message'

# List tags of the original tyler-smith go-bip39
echo "tyler-smith/go-bip39 tags:"
curl -s https://api.github.com/repos/tyler-smith/go-bip39/tags | jq '.[].name'

# List tags of the InjectiveLabs go-bip39 fork
echo "InjectiveLabs/go-bip39 tags:"
curl -s https://api.github.com/repos/InjectiveLabs/go-bip39/tags | jq '.[].name'

Length of output: 542


Confirmed: InjectiveLabs go-bip39 fork is required and maintained
The original tyler-smith/go-bip39 repo appears to be removed (GitHub API returns “Not Found”), while the InjectiveLabs fork:

  • Is live (last updated 2025-05-21) on branch main
  • Publishes a v1.1.0 tag matching the version in your replace directive
  • Contains the recovery commit (“Recover the package (gh got nuked).”)

The replace directive is both necessary (original is deleted) and correctly points to an actively maintained fork.

client/chain/chain_test_support.go (3)

27-28: LGTM: Import statements for new modules

The addition of import statements for ERC20 and EVM types is correctly placed and follows the existing import organization pattern.


1170-1182: LGTM: ERC20 module mock implementations

The mock methods for ERC20 queries are well-structured and follow the established pattern of returning empty responses with nil errors. All three core ERC20 query methods are covered:

  • FetchAllTokenPairs
  • FetchTokenPairByDenom
  • FetchTokenPairByERC20Address

1183-1211: LGTM: EVM module mock implementations

The mock methods for EVM queries comprehensively cover all the new EVM functionality:

  • Account queries (FetchEVMAccount, FetchEVMCosmosAccount, FetchEVMValidatorAccount)
  • Balance query (FetchEVMBalance)
  • Storage and code queries (FetchEVMStorage, FetchEVMCode)
  • Base fee query (FetchEVMBaseFee)

All methods follow the consistent mock pattern and provide the necessary test infrastructure.

client/chain/chain.go (6)

42-43: LGTM! Clean import additions for new module support.

The imports for ERC20 and EVM types are properly added and follow the existing import structure conventions.


457-470: Excellent interface extension for ERC20 and EVM queries.

The new method signatures are well-designed and consistent with the existing interface patterns:

  • All methods follow the standard (ctx context.Context, ...) (*Response, error) signature
  • Method names are descriptive and follow the Fetch prefix convention
  • ERC20 methods cover comprehensive token pair queries (all pairs, by denom, by ERC20 address)
  • EVM methods provide complete account and blockchain data access (accounts, balances, storage, code, base fee)

511-512: Proper addition of query clients to the struct.

The new query client fields are appropriately named and positioned within the existing query client grouping in the struct definition.


617-618: Correct initialization of new query clients.

The query clients are properly initialized using NewQueryClient(conn) following the exact same pattern as all other query clients in the constructor.


3609-3635: Well-implemented ERC20 query methods.

All three ERC20 query methods are correctly implemented:

  • FetchAllTokenPairs: Properly handles empty request for fetching all pairs
  • FetchTokenPairByDenom: Correctly sets the BankDenom field from parameter
  • FetchTokenPairByERC20Address: Properly sets the Erc20Address field from parameter

Each method follows the established pattern of creating request, calling common.ExecuteCall, and returning the response.


3636-3696: Comprehensive and well-structured EVM query implementations.

All EVM query methods are excellently implemented with proper patterns:

  • Account-related queries (FetchEVMAccount, FetchEVMCosmosAccount, FetchEVMValidatorAccount) correctly handle address parameters
  • FetchEVMBalance properly sets the address field
  • FetchEVMStorage includes appropriate conditional logic for the optional key parameter
  • FetchEVMCode correctly handles address parameter
  • FetchEVMBaseFee properly creates an empty request for base fee queries

The conditional key handling in FetchEVMStorage (lines 3675-3677) is particularly well done, using a pointer to handle the optional parameter appropriately.

Comment on lines +61 to +62
usdtERC20 := "0xdAC17F958D2ee523a2206206994597C13D831ec7"
res, err := chainClient.FetchTokenPairByDenom(ctx, usdtERC20)
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Critical: Wrong method called for ERC20 address query.

The filename and variable name suggest this example should demonstrate querying by ERC20 address, but it's calling FetchTokenPairByDenom instead of FetchTokenPairByERC20Address. The variable contains an ERC20 address (0xdAC17F958D2ee523a2206206994597C13D831ec7), not a denomination.

Apply this fix:

-	res, err := chainClient.FetchTokenPairByDenom(ctx, usdtERC20)
+	res, err := chainClient.FetchTokenPairByERC20Address(ctx, usdtERC20)
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
usdtERC20 := "0xdAC17F958D2ee523a2206206994597C13D831ec7"
res, err := chainClient.FetchTokenPairByDenom(ctx, usdtERC20)
usdtERC20 := "0xdAC17F958D2ee523a2206206994597C13D831ec7"
- res, err := chainClient.FetchTokenPairByDenom(ctx, usdtERC20)
+ res, err := chainClient.FetchTokenPairByERC20Address(ctx, usdtERC20)
🤖 Prompt for AI Agents
In examples/chain/erc20/query/3_TokenPairByERC20Address/example.go at lines
61-62, the code incorrectly calls FetchTokenPairByDenom with an ERC20 address
variable. Replace the method call with FetchTokenPairByERC20Address to correctly
query using the ERC20 address stored in usdtERC20.


ctx := context.Background()

res, err := chainClient.FetchTokenPairByERC20Address(ctx, "usdt")
Copy link

Choose a reason for hiding this comment

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

💡 Verification agent

🧩 Analysis chain

Verify method name and parameter consistency.

There appears to be a mismatch between the method name FetchTokenPairByERC20Address and the parameter "usdt". The method name suggests it expects an ERC20 address, but "usdt" appears to be a token symbol/denomination rather than an address.

Please verify if this should be:

  1. FetchTokenPairByDenom(ctx, "usdt") - if querying by denomination
  2. FetchTokenPairByERC20Address(ctx, "0x...") - if querying by ERC20 address

🏁 Script executed:

#!/bin/bash
# Search for the actual method signatures to verify the correct usage
ast-grep --pattern 'func ($$$) FetchTokenPairByERC20Address($$$) $$$'
ast-grep --pattern 'func ($$$) FetchTokenPairByDenom($$$) $$$'

Length of output: 1955


Use the Denomination-based Query Method

The example is invoking the ERC20‐address variant with a token denomination. To query by “usdt” (a bank denom), switch to FetchTokenPairByDenom.

Files needing update:

  • examples/chain/erc20/query/2_TokenPairByDenom/example.go: line 61

Suggested diff:

-   res, err := chainClient.FetchTokenPairByERC20Address(ctx, "usdt")
+   res, err := chainClient.FetchTokenPairByDenom(ctx, "usdt")
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
res, err := chainClient.FetchTokenPairByERC20Address(ctx, "usdt")
res, err := chainClient.FetchTokenPairByDenom(ctx, "usdt")
🤖 Prompt for AI Agents
In examples/chain/erc20/query/2_TokenPairByDenom/example.go at line 61, the
method FetchTokenPairByERC20Address is incorrectly called with a token
denomination "usdt". Replace this call with FetchTokenPairByDenom passing "usdt"
as the parameter to correctly query by denomination instead of ERC20 address.

@aarmoa aarmoa merged commit 1a0a621 into dev May 27, 2025
6 checks passed
@aarmoa aarmoa deleted the cp-395/add_support_for_v1_16 branch May 27, 2025 18:02
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