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

Feat/load official tokens list #327

Merged
merged 6 commits into from
May 8, 2024
Merged

Conversation

aarmoa
Copy link
Collaborator

@aarmoa aarmoa commented May 6, 2024

Summary by CodeRabbit

  • New Features

    • Enhanced token management by integrating official token lists for different network types (devnet, testnet, mainnet).
    • Updated the network initialization to accept URLs for official token lists.
    • Added functionality to load tokens asynchronously from specified URLs in TokensFileLoader.
  • Refactor

    • Streamlined cookies management across all gRPC calls.
    • Refactored token initialization in the async client to leverage new token loading methods.
  • Documentation

    • Updated installation instructions and script paths in the README for improved clarity.
  • Tests

    • Added new test cases for token loading functionalities.
    • Introduced tests to handle deprecation warnings in network configurations.
  • Chores

    • Updated project dependencies, removing unused libraries and adding necessary ones for testing.

@aarmoa aarmoa requested a review from nicolasbaum May 6, 2024 19:36
Copy link

socket-security bot commented May 6, 2024

New and removed dependencies detected. Learn more about Socket for GitHub ↗︎

Package New capabilities Transitives Size Publisher
pypi/aioresponses@0.7.6 environment, network 0 131 kB pawel.nuckowski
pypi/pytest-aioresponses@0.2.0 environment 0 11.4 kB pheanex

🚮 Removed packages: pypi/pyyaml@6.0.1, pypi/pyyaml@6.0.1, pypi/pyyaml@6.0.1, pypi/pyyaml@6.0.1

View full report↗︎

Copy link
Contributor

coderabbitai bot commented May 6, 2024

Walkthrough

The recent updates focus on enhancing the pyinjective library by integrating a new way to initialize tokens via official lists and refining the cookie management across gRPC calls. Key changes include the introduction of the TokensFileLoader class for loading token data, updates to network configurations to handle different environments, and adjustments in dependencies to optimize testing.

Changes

Files Changes
pyinjective/async_client.py, pyinjective/core/network.py Added functionality for token initialization from official lists, updated network parameters to include URLs for token lists.
pyinjective/core/tokens_file_loader.py, tests/core/test_tokens_file_loader.py Introduced TokensFileLoader for asynchronous token loading from URLs and added corresponding tests.
pyproject.toml Updated dependencies: removed coincurve and urllib3, added pytest-aioresponses.

Poem

🐇 Hop, hop, hop goes the CodeRabbit, 🚀
Through the fields of code, quite a habit!
With a flick and a flash, new tokens load,
Across networks wide, on the blockchain road.
Cheers to the devs, with each commit,
A better world of code, bit by bit! 🌍✨


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>.
    • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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.

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 as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

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

@aarmoa aarmoa marked this pull request as draft May 6, 2024 19:40
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: 2

Review Details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits Files that changed from the base of the PR and between 1d35d8d and 89b0f01.
Files ignored due to path filters (1)
  • poetry.lock is excluded by !**/*.lock
Files selected for processing (6)
  • CHANGELOG.md (1 hunks)
  • pyinjective/async_client.py (3 hunks)
  • pyinjective/core/network.py (9 hunks)
  • pyinjective/core/tokens_file_loader.py (1 hunks)
  • pyproject.toml (3 hunks)
  • tests/core/test_tokens_file_loader.py (1 hunks)
Files not reviewed due to errors (3)
  • tests/core/test_tokens_file_loader.py (no review received)
  • CHANGELOG.md (no review received)
  • pyinjective/core/network.py (no review received)
Files skipped from review due to trivial changes (1)
  • pyproject.toml
Additional Context Used
LanguageTool (7)
CHANGELOG.md (7)

Near line 35: Possible typo: you repeated a word
Context: ...ed methods ## [1.4.0] - 2024-03-11 ### Added - Added support for all queries and messages in...


Near line 59: Possible typo: you repeated a word
Context: ...n` message ## [1.1.0] - 2024-01-15 ### Added - Added new functions in all Market classes to ...


Near line 68: Possible typo: you repeated a word
Context: ...ion files ## [1.0.1] - 2024-01-08 ### Added - Added low level API components for all module...


Near line 69: If this is a compound adjective that modifies the following noun, use a hyphen.
Context: ... [1.0.1] - 2024-01-08 ### Added - Added low level API components for all modules (chain, ...


Near line 75: If this is a compound adjective that modifies the following noun, use a hyphen.
Context: ... chain, exchange and explorer using the low level API components - Marked old function si...


Near line 80: Possible typo: you repeated a word
Context: ...nt functions ## [1.0] - 2023-11-01 ### Added - Added logic to support use of Client Order ID...


Near line 85: Possible missing preposition found.
Context: ...New chain stream support ### Changed - Remove support for sentry nodes in mainnet n...

Additional comments not posted (2)
pyinjective/async_client.py (2)

3268-3268: Integration of official tokens list in market initialization looks correct.


3403-3425: Proper implementation of token loading from official lists.

Comment on lines +9 to +25
def load_json(self, json: List[Dict]) -> List[Token]:
loaded_tokens = []

for token_info in json:
token = Token(
name=token_info["name"],
symbol=token_info["symbol"],
denom=token_info["denom"],
address=token_info["address"],
decimals=token_info["decimals"],
logo=token_info["logo"],
updated=-1,
)

loaded_tokens.append(token)

return loaded_tokens
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider using list comprehension to optimize the load_json method.

- loaded_tokens = []
- for token_info in json:
-     token = Token(
-         name=token_info["name"],
-         symbol=token_info["symbol"],
-         denom=token_info["denom"],
-         address=token_info["address"],
-         decimals=token_info["decimals"],
-         logo=token_info["logo"],
-         updated=-1,
-     )
-     loaded_tokens.append(token)
- return loaded_tokens
+ return [Token(
+     name=token_info["name"],
+     symbol=token_info["symbol"],
+     denom=token_info["denom"],
+     address=token_info["address"],
+     decimals=token_info["decimals"],
+     logo=token_info["logo"],
+     updated=-1,
+ ) for token_info in json]

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.

Suggested change
def load_json(self, json: List[Dict]) -> List[Token]:
loaded_tokens = []
for token_info in json:
token = Token(
name=token_info["name"],
symbol=token_info["symbol"],
denom=token_info["denom"],
address=token_info["address"],
decimals=token_info["decimals"],
logo=token_info["logo"],
updated=-1,
)
loaded_tokens.append(token)
return loaded_tokens
def load_json(self, json: List[Dict]) -> List[Token]:
return [Token(
name=token_info["name"],
symbol=token_info["symbol"],
denom=token_info["denom"],
address=token_info["address"],
decimals=token_info["decimals"],
logo=token_info["logo"],
updated=-1,
) for token_info in json]

Comment on lines 27 to 34
async def load_tokens(self, tokens_file_url: str) -> List[Token]:
tokens_list = []
async with aiohttp.ClientSession() as session:
async with session.get(tokens_file_url) as response:
if response.ok:
tokens_list = await response.json(content_type=None)

return self.load_json(tokens_list)
Copy link
Contributor

Choose a reason for hiding this comment

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

Add error handling for the HTTP request and JSON parsing in load_tokens.

+ try:
      async with aiohttp.ClientSession() as session:
          async with session.get(tokens_file_url) as response:
              if response.ok:
                  tokens_list = await response.json(content_type=None)
+             else:
+                 raise Exception(f"Failed to fetch tokens: {response.status}")
+ except Exception as e:
+     logging.error(f"Error loading tokens: {e}")
+     return []
  return self.load_json(tokens_list)
+ except json.JSONDecodeError:
+     logging.error("Failed to parse JSON from response.")
+     return []

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.

Suggested change
async def load_tokens(self, tokens_file_url: str) -> List[Token]:
tokens_list = []
async with aiohttp.ClientSession() as session:
async with session.get(tokens_file_url) as response:
if response.ok:
tokens_list = await response.json(content_type=None)
return self.load_json(tokens_list)
async def load_tokens(self, tokens_file_url: str) -> List[Token]:
tokens_list = []
try:
async with aiohttp.ClientSession() as session:
async with session.get(tokens_file_url) as response:
if response.ok:
tokens_list = await response.json(content_type=None)
else:
raise Exception(f"Failed to fetch tokens: {response.status}")
except Exception as e:
logging.error(f"Error loading tokens: {e}")
return []
except json.JSONDecodeError:
logging.error("Failed to parse JSON from response.")
return []
return self.load_json(tokens_list)

…ing the AsyncClient initialization when getting the official tokens list from GitHub
@aarmoa aarmoa marked this pull request as ready for review May 7, 2024 23:23
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

Review Details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits Files that changed from the base of the PR and between 89b0f01 and 0d41383.
Files selected for processing (4)
  • README.md (2 hunks)
  • pyinjective/core/tokens_file_loader.py (1 hunks)
  • tests/core/test_network_deprecation_warnings.py (2 hunks)
  • tests/test_async_client.py (4 hunks)
Files skipped from review as they are similar to previous changes (1)
  • pyinjective/core/tokens_file_loader.py
Additional Context Used
LanguageTool (5)
README.md (5)

Near line 30: Unpaired symbol: ‘]’ seems to be missing
Context: ...y` following the steps described in the [documentation](https://python-poetry.org...


Near line 73: It seems that a comma is missing.
Context: ..., 2022. If you are using the sync client please make sure to transition to the [async c...


Near line 73: Unpaired symbol: ‘]’ seems to be missing
Context: ...c_client.py), for more information read [here](https://github.com/InjectiveLabs/s...


Near line 82: If you want to indicate numerical ranges or time ranges, consider using an en dash.
Context: ...est -v ``` ## License Copyright © 2021 - 2022 Injective Labs Inc. (https://inject...


Near line 86: Do not use a colon (:) before a series that is introduced by a preposition (‘under’). Remove the colon or add a noun or a noun phrase after the preposition.
Context: ...ginally released by Injective Labs Inc. under:
Apache License
Version 2....

Ruff (5)
tests/test_async_client.py (5)

86-86: Redefinition of unused inj_usdt_spot_market_meta from line 19


87-87: Redefinition of unused ape_usdt_spot_market_meta from line 15


88-88: Redefinition of unused btc_usdt_perp_market_meta from line 16


89-89: Redefinition of unused first_match_bet_market_meta from line 17


150-150: Redefinition of unused smart_denom_metadata from line 20

Additional comments not posted (6)
tests/core/test_network_deprecation_warnings.py (2)

19-19: Ensure the official_tokens_list_url is correctly utilized in the Network constructor.


44-44: Verify that the official_tokens_list_url parameter is correctly passed and utilized in the Network.custom method.

README.md (2)

19-19: Update the macOS dependencies to include bufbuild/buf/buf. Ensure this is the correct package and version needed for the SDK.


70-70: Added a new command under the Development section to fetch the latest denom config. Verify that this script is correctly implemented and documented.

tests/test_async_client.py (2)

Line range hint 90-108: Ensure the official_tokens_list_url is correctly utilized in the test setup for loading tokens. Verify that the aioresponses mock is properly configured to simulate the network responses.


Line range hint 151-174: Added a test for initializing tokens from chain denominations using the official_tokens_list_url. Ensure that the test correctly handles different scenarios and edge cases.

Copy link

codecov bot commented May 7, 2024

Codecov Report

Attention: Patch coverage is 71.79487% with 11 lines in your changes are missing coverage. Please review.

Project coverage is 77.41%. Comparing base (1fae35f) to head (9e8fc8a).
Report is 33 commits behind head on dev.

❗ Current head 9e8fc8a differs from pull request most recent head 355c3a9. Consider uploading reports for the commit 355c3a9 to get more accurate results

Files Patch % Lines
pyinjective/async_client.py 47.05% 8 Missing and 1 partial ⚠️
pyinjective/core/tokens_file_loader.py 90.47% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##              dev     #327      +/-   ##
==========================================
+ Coverage   76.98%   77.41%   +0.42%     
==========================================
  Files          51       56       +5     
  Lines        4145     4502     +357     
  Branches      309      333      +24     
==========================================
+ Hits         3191     3485     +294     
- Misses        874      924      +50     
- Partials       80       93      +13     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

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

Review Details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits Files that changed from the base of the PR and between 0d41383 and 355c3a9.
Files ignored due to path filters (1)
  • poetry.lock is excluded by !**/*.lock
Files selected for processing (1)
  • tests/test_async_client.py (4 hunks)
Additional Context Used
Ruff (9)
tests/test_async_client.py (9)

86-86: Redefinition of unused inj_usdt_spot_market_meta from line 19


87-87: Redefinition of unused ape_usdt_spot_market_meta from line 15


88-88: Redefinition of unused btc_usdt_perp_market_meta from line 16


89-89: Redefinition of unused first_match_bet_market_meta from line 17


149-149: Redefinition of unused inj_usdt_spot_market_meta from line 19


150-150: Redefinition of unused ape_usdt_spot_market_meta from line 15


151-151: Redefinition of unused btc_usdt_perp_market_meta from line 16


152-152: Redefinition of unused first_match_bet_market_meta from line 17


218-218: Redefinition of unused smart_denom_metadata from line 20

Additional comments not posted (3)
tests/test_async_client.py (3)

Line range hint 90-108: LGTM! The test method test_initialize_tokens_and_markets correctly simulates token and market initialization.


144-211: LGTM! The test method test_tokens_and_markets_initialization_read_tokens_from_official_list effectively validates the integration of the official token list.


Line range hint 219-242: LGTM! The test method test_initialize_tokens_from_chain_denoms correctly simulates token initialization from chain denominations.

@aarmoa aarmoa merged commit 822bc90 into dev May 8, 2024
12 checks passed
@aarmoa aarmoa deleted the feat/load_official_tokens_list branch May 8, 2024 08:39
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