Skip to content

Commit 3131ef8

Browse files
committed
feat: Created v2 versions for AsyncClient and Composer to support the Exchange module V2 queries and types. Updated examples and tests.
1 parent 7aba4d2 commit 3131ef8

25 files changed

+528
-289
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ All notable changes to this project will be documented in this file.
1010
- Updated all chain exchange module examples to use the new Exchange V2 proto queries and types
1111
- Added examples for ERC20 queries and messages
1212
- Added examples for EVM queries
13-
- Created a new AsyncClient in the pyinjective.async_client_v2 module. This new AsyncClient provides support for the newe v2 exchange endpoints. AsyncClient in pyinjective.async_client module still provides access to the v1 exchange endpoints.
13+
- Created a new AsyncClient in the pyinjective.async_client_v2 module. This new AsyncClient provides support for the new v2 exchange endpoints. AsyncClient in pyinjective.async_client module still provides access to the v1 exchange endpoints.
1414
- Created a new Composer in the pyinjective.composer_v2 module. This new Composer provides support to create exchange v2 objects. Composer in pyinjective.composer module still provides access to the v1 exchange objects.
1515
- Created the IndexerClient class to have all indexer queries. AsyncClient v2 now does not include any logic related to the indexer endpoints. The original AsyncClient still does support indexer endpoints (for backwards compatibility) but it does that by using an instance of the IndexerClient
1616

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ clean-all:
3131
$(call clean_repos)
3232

3333
clone-injective-indexer:
34-
git clone https://github.com/InjectiveLabs/injective-indexer.git -b v1.16.3 --depth 1 --single-branch
34+
git clone https://github.com/InjectiveLabs/injective-indexer.git -b v1.16.20 --depth 1 --single-branch
3535

3636
clone-all: clone-injective-indexer
3737

README.md

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,62 @@ Upgrade `pip` to the latest version, if you see these warnings:
7070
poetry run pytest -v
7171
```
7272

73+
---
74+
75+
## Choose Exchange V1 or Exchange V2 queries
76+
77+
The Injective Python SDK provides two different clients for interacting with the exchange:
78+
79+
1. **Exchange V1 Client** (`async_client` module):
80+
- Use this client if you need to interact with the original Injective Exchange API
81+
- Import using: `from injective.async_client import AsyncClient`
82+
- Suitable for applications that need to maintain compatibility with the original exchange interface
83+
- Example:
84+
```python
85+
from injective.async_client import AsyncClient
86+
from injective.network import Network
87+
88+
async def main():
89+
# Initialize client with mainnet
90+
client = AsyncClient(network=Network.mainnet())
91+
# Or use testnet
92+
# client = AsyncClient(network=Network.testnet())
93+
# Use V1 exchange queries here
94+
```
95+
96+
2. **Exchange V2 Client** (`async_client_v2` module):
97+
- Use this client for the latest exchange features and improvements
98+
- Import using: `from injective.async_client_v2 import AsyncClient`
99+
- Recommended for new applications and when you need access to the latest exchange features
100+
- Example:
101+
```python
102+
from injective.async_client_v2 import AsyncClient
103+
from injective.network import Network
104+
105+
async def main():
106+
# Initialize client with mainnet
107+
client = AsyncClient(network=Network.mainnet())
108+
# Or use testnet
109+
# client = AsyncClient(network=Network.testnet())
110+
# Use V2 exchange queries here
111+
```
112+
113+
Both clients provide similar interfaces but with different underlying implementations. Choose V2 for new projects unless you have specific requirements for V1 compatibility.
114+
115+
> **Market Format Differences**:
116+
> - V1 AsyncClient: Markets are initialized with values in chain format (raw blockchain values)
117+
> - V2 AsyncClient: Markets are initialized with values in human-readable format (converted to standard decimal numbers)
118+
>
119+
> **Exchange Endpoint Format Differences**:
120+
> - V1 Exchange endpoints: All values (amounts, prices, margins, notionals) are returned in chain format
121+
> - V2 Exchange endpoints:
122+
> - Human-readable format for: amounts, prices, margins, and notionals
123+
> - Chain format for: deposit-related information (to maintain consistency with the Bank module)
124+
>
125+
> **Important Note**: The ChainClient (V1) will not receive any new endpoints added to the Exchange module. If you need access to new exchange-related endpoints or features, you should migrate to the V2 client. The V2 client ensures you have access to all the latest exchange functionality and improvements.
126+
127+
___
128+
73129
## License
74130

75131
Copyright © 2021 - 2025 Injective Labs Inc. (https://injectivelabs.org/)

buf.gen.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ inputs:
1414
- git_repo: https://github.com/InjectiveLabs/ibc-go
1515
tag: v8.7.0-evm-comet1-inj
1616
- git_repo: https://github.com/InjectiveLabs/wasmd
17-
tag: v0.53.2-evm-comet1-inj
17+
tag: v0.53.3-evm-comet1-inj
1818
- git_repo: https://github.com/InjectiveLabs/cometbft
1919
tag: v1.0.1-inj.2
2020
- git_repo: https://github.com/InjectiveLabs/cosmos-sdk
@@ -23,7 +23,7 @@ inputs:
2323
# branch: v0.51.x-inj
2424
# subdir: proto
2525
- git_repo: https://github.com/InjectiveLabs/injective-core
26-
tag: v1.16.0-beta.2
26+
tag: v1.16.0-beta.3
2727
subdir: proto
2828
# - git_repo: https://github.com/InjectiveLabs/injective-core
2929
# branch: master

examples/chain_client/erc20/query/1_AllTokenPairs.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
from pyinjective import PrivateKey
88
from pyinjective.async_client_v2 import AsyncClient
9+
from pyinjective.client.model.pagination import PaginationOption
910
from pyinjective.core.network import Network
1011

1112

@@ -25,7 +26,12 @@ async def main() -> None:
2526
address = pub_key.to_address()
2627
await client.fetch_account(address.to_acc_bech32())
2728

28-
pairs = await client.fetch_erc20_all_token_pairs()
29+
pairs = await client.fetch_erc20_all_token_pairs(
30+
pagination=PaginationOption(
31+
skip=0,
32+
limit=100,
33+
),
34+
)
2935
print(json.dumps(pairs, indent=2))
3036

3137

pyinjective/async_client.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -986,12 +986,14 @@ async def fetch_contract_txs_v2(
986986
address: str,
987987
height: Optional[int] = None,
988988
token: Optional[str] = None,
989+
status: Optional[str] = None,
989990
pagination: Optional[PaginationOption] = None,
990991
) -> Dict[str, Any]:
991992
return await self.indexer_client.fetch_contract_txs_v2(
992993
address=address,
993994
height=height,
994995
token=token,
996+
status=status,
995997
pagination=pagination,
996998
)
997999

@@ -1124,12 +1126,16 @@ async def fetch_wasm_contracts(
11241126
code_id: Optional[int] = None,
11251127
assets_only: Optional[bool] = None,
11261128
label: Optional[str] = None,
1129+
token: Optional[str] = None,
1130+
lookup: Optional[str] = None,
11271131
pagination: Optional[PaginationOption] = None,
11281132
) -> Dict[str, Any]:
11291133
return await self.indexer_client.fetch_wasm_contracts(
11301134
code_id=code_id,
11311135
assets_only=assets_only,
11321136
label=label,
1137+
token=token,
1138+
lookup=lookup,
11331139
pagination=pagination,
11341140
)
11351141

pyinjective/async_client_v2.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1187,8 +1187,8 @@ async def fetch_eip_base_fee(self) -> Dict[str, Any]:
11871187

11881188
# -------------------------
11891189
# region Chain ERC20 module
1190-
async def fetch_erc20_all_token_pairs(self) -> Dict[str, Any]:
1191-
return await self.chain_erc20_api.fetch_all_token_pairs()
1190+
async def fetch_erc20_all_token_pairs(self, pagination: Optional[PaginationOption] = None) -> Dict[str, Any]:
1191+
return await self.chain_erc20_api.fetch_all_token_pairs(pagination=pagination)
11921192

11931193
async def fetch_erc20_token_pair_by_denom(self, bank_denom: str) -> Dict[str, Any]:
11941194
return await self.chain_erc20_api.fetch_token_pair_by_denom(bank_denom=bank_denom)

pyinjective/client/chain/grpc/chain_grpc_erc20_api.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
from typing import Any, Callable, Dict
1+
from typing import Any, Callable, Dict, Optional
22

33
from grpc.aio import Channel
44

5+
from pyinjective.client.model.pagination import PaginationOption
56
from pyinjective.core.network import CookieAssistant
67
from pyinjective.proto.injective.erc20.v1beta1 import query_pb2 as erc20_query_pb, query_pb2_grpc as erc20_query_grpc
78
from pyinjective.utils.grpc_api_request_assistant import GrpcApiRequestAssistant
@@ -18,8 +19,16 @@ async def fetch_erc20_params(self) -> Dict[str, Any]:
1819

1920
return response
2021

21-
async def fetch_all_token_pairs(self) -> Dict[str, Any]:
22-
request = erc20_query_pb.QueryAllTokenPairsRequest()
22+
async def fetch_all_token_pairs(
23+
self,
24+
pagination: Optional[PaginationOption] = None,
25+
) -> Dict[str, Any]:
26+
pagination_request = None
27+
if pagination is not None:
28+
pagination_request = pagination.create_pagination_request()
29+
request = erc20_query_pb.QueryAllTokenPairsRequest(
30+
pagination=pagination_request,
31+
)
2332
response = await self._execute_call(call=self._stub.AllTokenPairs, request=request)
2433

2534
return response

pyinjective/client/indexer/grpc/indexer_grpc_explorer_api.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ async def fetch_contract_txs_v2(
7373
address: str,
7474
height: Optional[int] = None,
7575
token: Optional[str] = None,
76+
status: Optional[str] = None,
7677
pagination: Optional[PaginationOption] = None,
7778
) -> Dict[str, Any]:
7879
pagination = pagination or PaginationOption()
@@ -85,7 +86,9 @@ async def fetch_contract_txs_v2(
8586
if pagination is not None:
8687
setattr(request, "from", pagination.start_time)
8788
request.to = pagination.end_time
88-
request.limit = pagination.limit
89+
request.per_page = pagination.limit
90+
if status is not None:
91+
request.status = status
8992

9093
response = await self._execute_call(call=self._stub.GetContractTxsV2, request=request)
9194

@@ -265,6 +268,8 @@ async def fetch_wasm_contracts(
265268
code_id: Optional[int] = None,
266269
assets_only: Optional[bool] = None,
267270
label: Optional[str] = None,
271+
token: Optional[str] = None,
272+
lookup: Optional[str] = None,
268273
pagination: Optional[PaginationOption] = None,
269274
) -> Dict[str, Any]:
270275
pagination = pagination or PaginationOption()
@@ -276,6 +281,8 @@ async def fetch_wasm_contracts(
276281
assets_only=assets_only,
277282
skip=pagination.skip,
278283
label=label,
284+
token=token,
285+
lookup=lookup,
279286
)
280287

281288
response = await self._execute_call(call=self._stub.GetWasmContracts, request=request)

pyinjective/indexer_client.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -989,12 +989,14 @@ async def fetch_contract_txs_v2(
989989
address: str,
990990
height: Optional[int] = None,
991991
token: Optional[str] = None,
992+
status: Optional[str] = None,
992993
pagination: Optional[PaginationOption] = None,
993994
) -> Dict[str, Any]:
994995
return await self.explorer_api.fetch_contract_txs_v2(
995996
address=address,
996997
height=height,
997998
token=token,
999+
status=status,
9981000
pagination=pagination,
9991001
)
10001002

@@ -1103,12 +1105,16 @@ async def fetch_wasm_contracts(
11031105
code_id: Optional[int] = None,
11041106
assets_only: Optional[bool] = None,
11051107
label: Optional[str] = None,
1108+
token: Optional[str] = None,
1109+
lookup: Optional[str] = None,
11061110
pagination: Optional[PaginationOption] = None,
11071111
) -> Dict[str, Any]:
11081112
return await self.explorer_api.fetch_wasm_contracts(
11091113
code_id=code_id,
11101114
assets_only=assets_only,
11111115
label=label,
1116+
token=token,
1117+
lookup=lookup,
11121118
pagination=pagination,
11131119
)
11141120

0 commit comments

Comments
 (0)