Skip to content

Conversation

@aarmoa
Copy link
Collaborator

@aarmoa aarmoa commented Jun 25, 2025

  • added the calculated unique symbol to the Token class

Summary by CodeRabbit

  • New Features

    • Added a new attribute, unique_symbol, to tokens for improved identification and handling across the platform.
  • Tests

    • Updated and expanded tests to verify the presence and correct assignment of the unique_symbol attribute in tokens.
  • Chores

    • Updated the supported Python versions in automated testing to include Python 3.12 and removed Windows from the test environments.
    • Bumped the project version to 1.11.0-rc5.

@aarmoa aarmoa requested a review from Copilot June 25, 2025 02:52
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jun 25, 2025

Walkthrough

The changes introduce a new unique_symbol attribute to the Token dataclass and ensure it is consistently assigned and managed throughout the codebase, particularly within token initialization and loading logic. Related tests and fixtures are updated to account for this new attribute. The GitHub Actions workflow is updated to add Python 3.12 support and remove Windows testing. The project version is incremented.

Changes

File(s) Change Summary
.github/workflows/run-tests.yml Added Python 3.12 to test matrix; removed Windows from OS list.
pyproject.toml Updated version from 1.11.0-rc4 to 1.11.0-rc5.
pyinjective/core/token.py Added unique_symbol: str field to Token dataclass.
pyinjective/core/tokens_file_loader.py Set unique_symbol to "" when creating Token in load_json.
pyinjective/async_client.py
pyinjective/async_client_v2.py
Added computation and assignment of unique_symbol to Token instances in token management methods.
tests/core/test_tokens_file_loader.py Added assertions to check unique_symbol == "" for loaded tokens in tests.
tests/model_fixtures/markets_v2_fixtures.py Set unique_symbol in Token instances within test fixtures.

Sequence Diagram(s)

sequenceDiagram
    participant Loader as TokensFileLoader
    participant Token as Token
    participant Client as AsyncClient/AsyncClientV2

    Loader->>Token: Create Token (unique_symbol: "")
    Client->>Token: Create Token (unique_symbol: computed value)
    Client->>Client: Store Token by unique_symbol in dictionaries
Loading

Poem

A token now with symbols rare,
Unique and clear, beyond compare.
From tests to fixtures, all align,
With Python’s latest in the line.
A hop, a skip, a version leap—
The code grows strong, the rabbits keep!
🐇✨

✨ 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 introduces a new unique_symbol property on Token and propagates its value through model loaders, async clients, fixtures, and tests.

  • Added unique_symbol field to the Token model and initialized it in the JSON loader and both async clients.
  • Updated tests and fixtures to include assertions and values for unique_symbol.
  • Bumped the package version and updated the CI matrix to Python 3.12 (removed Windows).

Reviewed Changes

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

Show a summary per file
File Description
tests/model_fixtures/markets_v2_fixtures.py Added unique_symbol values to market fixtures
tests/core/test_tokens_file_loader.py Added assertions for default unique_symbol
pyproject.toml Bumped version to 1.11.0-rc5
pyinjective/core/tokens_file_loader.py Initialized unique_symbol in load_json
pyinjective/core/token.py Added unique_symbol field to Token model
pyinjective/async_client_v2.py Populated unique_symbol in initialize_tokens_from_chain_denoms, _token_representation, and _tokens_from_official_lists
pyinjective/async_client.py Same updates as above for sync async client
.github/workflows/run-tests.yml Added Python 3.12; removed Windows from OS matrix
Comments suppressed due to low confidence (2)

pyinjective/async_client_v2.py:1287

  • There are no tests verifying that unique_symbol is correctly computed and assigned in initialize_tokens_from_chain_denoms. Consider adding unit tests to cover this new behavior.
                    unique_symbol=unique_symbol,

.github/workflows/run-tests.yml:12

  • [nitpick] Windows has been removed from the test matrix. If cross-platform support includes Windows, re-add windows-latest to ensure test coverage on that OS.
        os: [ubuntu-latest, macos-latest]

decimals=token_info["decimals"],
logo=token_info["logo"],
updated=-1,
unique_symbol="",
Copy link

Copilot AI Jun 25, 2025

Choose a reason for hiding this comment

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

The loader currently hardcodes unique_symbol to an empty string. To preserve any unique_symbol provided in the source JSON, use something like unique_symbol=token_info.get('unique_symbol', '').

Suggested change
unique_symbol="",
unique_symbol=token_info.get("unique_symbol", ""),

Copilot uses AI. Check for mistakes.

tokens_by_denom[token.denom] = token
tokens_by_symbol[unique_symbol] = token
new_token = Token(
Copy link

Copilot AI Jun 25, 2025

Choose a reason for hiding this comment

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

[nitpick] The token-instantiation block is duplicated in both clients (async_client.py and async_client_v2.py). Consider extracting a shared factory or helper method to reduce duplication.

Suggested change
new_token = Token(
new_token = self._create_token(

Copilot uses AI. Check for mistakes.
Copy link
Contributor

@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: 0

🔭 Outside diff range comments (1)
pyinjective/async_client.py (1)

2262-2266: Excellent implementation of unique_symbol feature with opportunity for refactoring.

The unique_symbol calculation logic is consistently implemented across all three token initialization methods. The fallback strategy (denom → symbol → name) ensures uniqueness while providing meaningful identifiers.

The unique_symbol calculation logic is duplicated in three places. Extract this into a private helper method to improve maintainability:

+    def _calculate_unique_symbol(
+        self, 
+        denom: str, 
+        symbol: str, 
+        name: str, 
+        tokens_by_symbol: Dict[str, Token]
+    ) -> str:
+        """Calculate a unique symbol for the token, using fallback logic."""
+        unique_symbol = denom
+        for symbol_candidate in [symbol, name]:
+            if symbol_candidate not in tokens_by_symbol:
+                unique_symbol = symbol_candidate
+                break
+        return unique_symbol

Then replace the duplicated logic in all three methods with calls to this helper method.

Also applies to: 2401-2405, 2435-2439

🧹 Nitpick comments (2)
pyinjective/async_client.py (2)

2268-2280: LGTM: Token creation with unique_symbol is correctly implemented.

The unique_symbol calculation logic and Token constructor call are properly implemented. The fallback logic from denom → symbol → name ensures uniqueness.

Consider extracting the unique_symbol calculation logic into a helper method since it's duplicated across multiple methods:

+    def _calculate_unique_symbol(self, denom: str, symbol: str, name: str, tokens_by_symbol: Dict[str, Token]) -> str:
+        unique_symbol = denom
+        for symbol_candidate in [symbol, name]:
+            if symbol_candidate not in tokens_by_symbol:
+                unique_symbol = symbol_candidate
+                break
+        return unique_symbol

2407-2420: LGTM: Consistent implementation of unique_symbol logic.

The Token creation with unique_symbol parameter is correctly implemented and follows the same pattern as other methods.

This method duplicates the unique_symbol calculation logic from initialize_tokens_from_chain_denoms. Consider using the helper method suggested earlier to eliminate this duplication.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 9286d63 and 8429dc8.

📒 Files selected for processing (8)
  • .github/workflows/run-tests.yml (1 hunks)
  • pyinjective/async_client.py (3 hunks)
  • pyinjective/async_client_v2.py (3 hunks)
  • pyinjective/core/token.py (1 hunks)
  • pyinjective/core/tokens_file_loader.py (1 hunks)
  • pyproject.toml (1 hunks)
  • tests/core/test_tokens_file_loader.py (2 hunks)
  • tests/model_fixtures/markets_v2_fixtures.py (3 hunks)
🔇 Additional comments (11)
pyinjective/core/token.py (1)

16-16: Breaking change handled consistently across codebase.

Adding a required field to the dataclass is a breaking change, but based on the AI summary, this appears to be properly coordinated with updates to token initialization throughout the codebase.

.github/workflows/run-tests.yml (1)

11-12: Good addition of Python 3.12 support.

Adding Python 3.12 to the test matrix ensures compatibility with the latest Python version. Note that Windows testing has been removed - ensure this aligns with your platform support strategy.

pyproject.toml (1)

3-3: Appropriate version bump for new feature.

The increment from rc4 to rc5 is suitable for the addition of the unique_symbol feature.

pyinjective/core/tokens_file_loader.py (1)

22-22: Proper initialization of new required field.

Initializing unique_symbol to an empty string is appropriate since the JSON data doesn't contain this field. This suggests the unique symbol will be computed/assigned elsewhere in the token processing pipeline.

tests/core/test_tokens_file_loader.py (2)

50-50: Good test coverage for new field.

The assertion properly verifies that unique_symbol is initialized to an empty string as expected from the loader.


100-100: Consistent test coverage maintained.

The test properly verifies the new field behavior in the async loading scenario as well.

tests/model_fixtures/markets_v2_fixtures.py (1)

19-19: LGTM! Test fixtures correctly updated for the new unique_symbol field.

The fixtures properly demonstrate the unique_symbol usage pattern - using the symbol when it's unique ("INJ", "USDT") and falling back to the denom for disambiguation (usdt_perp_token uses the denom to differentiate from the regular USDT token).

Also applies to: 35-35, 51-51

pyinjective/async_client_v2.py (3)

1273-1278: Well-implemented unique symbol determination logic.

The logic correctly ensures uniqueness by checking symbol availability first, then name, and finally falling back to denom. This approach prioritizes human-readable identifiers while guaranteeing uniqueness in the tokens_by_symbol dictionary.

Also applies to: 1287-1287


1412-1416: Consistent unique symbol logic in _token_representation method.

The implementation mirrors the logic in initialize_tokens_from_chain_denoms, maintaining consistency across different token creation paths.

Also applies to: 1426-1426


1446-1450: Proper unique symbol handling for tokens from official lists.

The method correctly determines unique symbols and creates new Token instances with the additional unique_symbol field. The logic is consistent with other token initialization methods.

Also applies to: 1452-1464

pyinjective/async_client.py (1)

2441-2453: LGTM: Comprehensive Token creation and storage implementation.

The Token creation with all parameters including unique_symbol is correctly implemented. The dictionary storage uses appropriate keys (denom for tokens_by_denom and unique_symbol for tokens_by_symbol).

The variable naming with new_token is clear and the implementation maintains consistency with the established patterns.

@aarmoa aarmoa merged commit 28f1854 into dev Jun 25, 2025
12 checks passed
@aarmoa aarmoa deleted the feat/add_unique_token_symbol branch June 25, 2025 02:56
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