Skip to content

Commit 8429dc8

Browse files
committed
feat: added the calculated unique symbol to the Token class
1 parent 9286d63 commit 8429dc8

File tree

8 files changed

+40
-7
lines changed

8 files changed

+40
-7
lines changed

.github/workflows/run-tests.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ jobs:
88
run-tests:
99
strategy:
1010
matrix:
11-
python: ["3.9", "3.10", "3.11"]
12-
os: [ubuntu-latest, macos-latest, windows-latest]
11+
python: ["3.9", "3.10", "3.11", "3.12"]
12+
os: [ubuntu-latest, macos-latest]
1313
runs-on: ${{ matrix.os }}
1414
env:
1515
OS: ${{ matrix.os }}

pyinjective/async_client.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2273,6 +2273,7 @@ async def initialize_tokens_from_chain_denoms(self):
22732273
decimals=decimals,
22742274
logo=token_metadata["uri"],
22752275
updated=-1,
2276+
unique_symbol=unique_symbol,
22762277
)
22772278

22782279
self._tokens_by_denom[denom] = token
@@ -2411,6 +2412,7 @@ def _token_representation(
24112412
decimals=token_meta["decimals"],
24122413
logo=token_meta["logo"],
24132414
updated=int(token_meta["updatedAt"]),
2415+
unique_symbol=unique_symbol,
24142416
)
24152417

24162418
tokens_by_denom[denom] = token
@@ -2436,8 +2438,19 @@ async def _tokens_from_official_lists(
24362438
unique_symbol = symbol_candidate
24372439
break
24382440

2439-
tokens_by_denom[token.denom] = token
2440-
tokens_by_symbol[unique_symbol] = token
2441+
new_token = Token(
2442+
name=token.name,
2443+
symbol=token.symbol,
2444+
denom=token.denom,
2445+
address=token.address,
2446+
decimals=token.decimals,
2447+
logo=token.logo,
2448+
updated=token.updated,
2449+
unique_symbol=unique_symbol,
2450+
)
2451+
2452+
tokens_by_denom[new_token.denom] = new_token
2453+
tokens_by_symbol[unique_symbol] = new_token
24412454

24422455
return tokens_by_symbol, tokens_by_denom
24432456

pyinjective/async_client_v2.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1284,6 +1284,7 @@ async def initialize_tokens_from_chain_denoms(self):
12841284
decimals=decimals,
12851285
logo=token_metadata["uri"],
12861286
updated=-1,
1287+
unique_symbol=unique_symbol,
12871288
)
12881289

12891290
self._tokens_by_denom[denom] = token
@@ -1422,6 +1423,7 @@ def _token_representation(
14221423
decimals=token_meta["decimals"],
14231424
logo=token_meta["logo"],
14241425
updated=int(token_meta["updatedAt"]),
1426+
unique_symbol=unique_symbol,
14251427
)
14261428

14271429
tokens_by_denom[denom] = token
@@ -1447,8 +1449,19 @@ async def _tokens_from_official_lists(
14471449
unique_symbol = symbol_candidate
14481450
break
14491451

1450-
tokens_by_denom[token.denom] = token
1451-
tokens_by_symbol[unique_symbol] = token
1452+
new_token = Token(
1453+
name=token.name,
1454+
symbol=token.symbol,
1455+
denom=token.denom,
1456+
address=token.address,
1457+
decimals=token.decimals,
1458+
logo=token.logo,
1459+
updated=token.updated,
1460+
unique_symbol=unique_symbol,
1461+
)
1462+
1463+
tokens_by_denom[new_token.denom] = new_token
1464+
tokens_by_symbol[unique_symbol] = new_token
14521465

14531466
return tokens_by_symbol, tokens_by_denom
14541467

pyinjective/core/token.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ class Token:
1313
decimals: int
1414
logo: str
1515
updated: int
16+
unique_symbol: str
1617

1718
@staticmethod
1819
def convert_value_to_extended_decimal_format(value: Decimal) -> Decimal:

pyinjective/core/tokens_file_loader.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ def load_json(self, json: List[Dict]) -> List[Token]:
1919
decimals=token_info["decimals"],
2020
logo=token_info["logo"],
2121
updated=-1,
22+
unique_symbol="",
2223
)
2324

2425
loaded_tokens.append(token)

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "injective-py"
3-
version = "1.11.0-rc4"
3+
version = "1.11.0-rc5"
44
description = "Injective Python SDK, with Exchange API Client"
55
authors = ["Injective Labs <contact@injectivelabs.org>"]
66
license = "Apache-2.0"

tests/core/test_tokens_file_loader.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ def test_load_tokens(self):
4747
assert token.address == token_info["address"]
4848
assert token.decimals == token_info["decimals"]
4949
assert token.logo == token_info["logo"]
50+
assert token.unique_symbol == ""
5051

5152
@pytest.mark.asyncio
5253
async def test_load_tokens_from_url(self, aioresponses):
@@ -96,6 +97,7 @@ async def test_load_tokens_from_url(self, aioresponses):
9697
assert token.address == token_info["address"]
9798
assert token.decimals == token_info["decimals"]
9899
assert token.logo == token_info["logo"]
100+
assert token.unique_symbol == ""
99101

100102
@pytest.mark.asyncio
101103
async def test_load_tokens_from_url_returns_nothing_when_request_fails(self, aioresponses):

tests/model_fixtures/markets_v2_fixtures.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ def inj_token():
1616
decimals=18,
1717
logo="https://static.alchemyapi.io/images/assets/7226.png",
1818
updated=1681739137644,
19+
unique_symbol="INJ",
1920
)
2021

2122
return token
@@ -31,6 +32,7 @@ def usdt_token():
3132
decimals=6,
3233
logo="https://static.alchemyapi.io/images/assets/825.png",
3334
updated=1681739137645,
35+
unique_symbol="USDT",
3436
)
3537

3638
return token
@@ -46,6 +48,7 @@ def usdt_perp_token():
4648
decimals=6,
4749
logo="https://static.alchemyapi.io/images/assets/825.png",
4850
updated=1681739137645,
51+
unique_symbol="peggy0xdAC17F958D2ee523a2206206994597C13D831ec7",
4952
)
5053

5154
return token

0 commit comments

Comments
 (0)