From 8429dc809e1d7d6ddac3973790d4f8bcca18b0de Mon Sep 17 00:00:00 2001 From: Abel Armoa <30988000+aarmoa@users.noreply.github.com> Date: Tue, 24 Jun 2025 23:51:08 -0300 Subject: [PATCH] feat: added the calculated unique symbol to the Token class --- .github/workflows/run-tests.yml | 4 ++-- pyinjective/async_client.py | 17 +++++++++++++++-- pyinjective/async_client_v2.py | 17 +++++++++++++++-- pyinjective/core/token.py | 1 + pyinjective/core/tokens_file_loader.py | 1 + pyproject.toml | 2 +- tests/core/test_tokens_file_loader.py | 2 ++ tests/model_fixtures/markets_v2_fixtures.py | 3 +++ 8 files changed, 40 insertions(+), 7 deletions(-) diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index 68bce37a..6ca6fe40 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -8,8 +8,8 @@ jobs: run-tests: strategy: matrix: - python: ["3.9", "3.10", "3.11"] - os: [ubuntu-latest, macos-latest, windows-latest] + python: ["3.9", "3.10", "3.11", "3.12"] + os: [ubuntu-latest, macos-latest] runs-on: ${{ matrix.os }} env: OS: ${{ matrix.os }} diff --git a/pyinjective/async_client.py b/pyinjective/async_client.py index 7aaa4847..31f41a9d 100644 --- a/pyinjective/async_client.py +++ b/pyinjective/async_client.py @@ -2273,6 +2273,7 @@ async def initialize_tokens_from_chain_denoms(self): decimals=decimals, logo=token_metadata["uri"], updated=-1, + unique_symbol=unique_symbol, ) self._tokens_by_denom[denom] = token @@ -2411,6 +2412,7 @@ def _token_representation( decimals=token_meta["decimals"], logo=token_meta["logo"], updated=int(token_meta["updatedAt"]), + unique_symbol=unique_symbol, ) tokens_by_denom[denom] = token @@ -2436,8 +2438,19 @@ async def _tokens_from_official_lists( unique_symbol = symbol_candidate break - tokens_by_denom[token.denom] = token - tokens_by_symbol[unique_symbol] = token + new_token = Token( + name=token.name, + symbol=token.symbol, + denom=token.denom, + address=token.address, + decimals=token.decimals, + logo=token.logo, + updated=token.updated, + unique_symbol=unique_symbol, + ) + + tokens_by_denom[new_token.denom] = new_token + tokens_by_symbol[unique_symbol] = new_token return tokens_by_symbol, tokens_by_denom diff --git a/pyinjective/async_client_v2.py b/pyinjective/async_client_v2.py index 6716801e..b46d71be 100644 --- a/pyinjective/async_client_v2.py +++ b/pyinjective/async_client_v2.py @@ -1284,6 +1284,7 @@ async def initialize_tokens_from_chain_denoms(self): decimals=decimals, logo=token_metadata["uri"], updated=-1, + unique_symbol=unique_symbol, ) self._tokens_by_denom[denom] = token @@ -1422,6 +1423,7 @@ def _token_representation( decimals=token_meta["decimals"], logo=token_meta["logo"], updated=int(token_meta["updatedAt"]), + unique_symbol=unique_symbol, ) tokens_by_denom[denom] = token @@ -1447,8 +1449,19 @@ async def _tokens_from_official_lists( unique_symbol = symbol_candidate break - tokens_by_denom[token.denom] = token - tokens_by_symbol[unique_symbol] = token + new_token = Token( + name=token.name, + symbol=token.symbol, + denom=token.denom, + address=token.address, + decimals=token.decimals, + logo=token.logo, + updated=token.updated, + unique_symbol=unique_symbol, + ) + + tokens_by_denom[new_token.denom] = new_token + tokens_by_symbol[unique_symbol] = new_token return tokens_by_symbol, tokens_by_denom diff --git a/pyinjective/core/token.py b/pyinjective/core/token.py index bdeace85..c41b643f 100644 --- a/pyinjective/core/token.py +++ b/pyinjective/core/token.py @@ -13,6 +13,7 @@ class Token: decimals: int logo: str updated: int + unique_symbol: str @staticmethod def convert_value_to_extended_decimal_format(value: Decimal) -> Decimal: diff --git a/pyinjective/core/tokens_file_loader.py b/pyinjective/core/tokens_file_loader.py index 0e84bebd..7097e65c 100644 --- a/pyinjective/core/tokens_file_loader.py +++ b/pyinjective/core/tokens_file_loader.py @@ -19,6 +19,7 @@ def load_json(self, json: List[Dict]) -> List[Token]: decimals=token_info["decimals"], logo=token_info["logo"], updated=-1, + unique_symbol="", ) loaded_tokens.append(token) diff --git a/pyproject.toml b/pyproject.toml index 2f60aed7..db5ad10d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "injective-py" -version = "1.11.0-rc4" +version = "1.11.0-rc5" description = "Injective Python SDK, with Exchange API Client" authors = ["Injective Labs "] license = "Apache-2.0" diff --git a/tests/core/test_tokens_file_loader.py b/tests/core/test_tokens_file_loader.py index 60999f6e..8ae8138d 100644 --- a/tests/core/test_tokens_file_loader.py +++ b/tests/core/test_tokens_file_loader.py @@ -47,6 +47,7 @@ def test_load_tokens(self): assert token.address == token_info["address"] assert token.decimals == token_info["decimals"] assert token.logo == token_info["logo"] + assert token.unique_symbol == "" @pytest.mark.asyncio async def test_load_tokens_from_url(self, aioresponses): @@ -96,6 +97,7 @@ async def test_load_tokens_from_url(self, aioresponses): assert token.address == token_info["address"] assert token.decimals == token_info["decimals"] assert token.logo == token_info["logo"] + assert token.unique_symbol == "" @pytest.mark.asyncio async def test_load_tokens_from_url_returns_nothing_when_request_fails(self, aioresponses): diff --git a/tests/model_fixtures/markets_v2_fixtures.py b/tests/model_fixtures/markets_v2_fixtures.py index fc87d5a2..76840843 100644 --- a/tests/model_fixtures/markets_v2_fixtures.py +++ b/tests/model_fixtures/markets_v2_fixtures.py @@ -16,6 +16,7 @@ def inj_token(): decimals=18, logo="https://static.alchemyapi.io/images/assets/7226.png", updated=1681739137644, + unique_symbol="INJ", ) return token @@ -31,6 +32,7 @@ def usdt_token(): decimals=6, logo="https://static.alchemyapi.io/images/assets/825.png", updated=1681739137645, + unique_symbol="USDT", ) return token @@ -46,6 +48,7 @@ def usdt_perp_token(): decimals=6, logo="https://static.alchemyapi.io/images/assets/825.png", updated=1681739137645, + unique_symbol="peggy0xdAC17F958D2ee523a2206206994597C13D831ec7", ) return token