-
Notifications
You must be signed in to change notification settings - Fork 32
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
Conversation
New and removed dependencies detected. Learn more about Socket for GitHub ↗︎
🚮 Removed packages: pypi/pyyaml@6.0.1, pypi/pyyaml@6.0.1, pypi/pyyaml@6.0.1, pypi/pyyaml@6.0.1 |
WalkthroughThe recent updates focus on enhancing the Changes
Poem
TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Additionally, you can add CodeRabbit Configration File (
|
There was a problem hiding this 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
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 forsentry
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.
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 |
There was a problem hiding this comment.
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.
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] |
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) |
There was a problem hiding this comment.
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.
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
There was a problem hiding this 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
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 theofficial_tokens_list_url
is correctly utilized in theNetwork
constructor.
44-44
: Verify that theofficial_tokens_list_url
parameter is correctly passed and utilized in theNetwork.custom
method.README.md (2)
19-19
: Update the macOS dependencies to includebufbuild/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 theofficial_tokens_list_url
is correctly utilized in the test setup for loading tokens. Verify that theaioresponses
mock is properly configured to simulate the network responses.
Line range hint
151-174
: Added a test for initializing tokens from chain denominations using theofficial_tokens_list_url
. Ensure that the test correctly handles different scenarios and edge cases.
Codecov ReportAttention: Patch coverage is
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. |
There was a problem hiding this 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
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 methodtest_initialize_tokens_and_markets
correctly simulates token and market initialization.
144-211
: LGTM! The test methodtest_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 methodtest_initialize_tokens_from_chain_denoms
correctly simulates token initialization from chain denominations.
Solves CHAIN-100
Summary by CodeRabbit
New Features
TokensFileLoader
.Refactor
Documentation
Tests
Chores