Skip to content

Commit 0d50fc2

Browse files
committed
Merge branch 'dev' of https://github.com/InjectiveLabs/sdk-python into feat/add_support_exchange_v2
2 parents c9cfcc0 + c78af17 commit 0d50fc2

File tree

150 files changed

+6807
-2552
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

150 files changed

+6807
-2552
lines changed

.github/workflows/pre-commit.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ jobs:
1212
uses: actions/checkout@v4
1313
- name: Install Python
1414
uses: actions/setup-python@v5
15-
15+
with:
16+
python-version: '>=3.9 <3.12'
1617
- name: Install poetry
1718
run: python -m pip install poetry
1819
- name: Cache the virtualenv

.github/workflows/run-tests.yml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ jobs:
99
strategy:
1010
matrix:
1111
python: ["3.9", "3.10", "3.11"]
12-
os: [ubuntu-latest, macos-13, windows-latest]
12+
os: [ubuntu-latest, macos-latest, windows-latest]
1313
runs-on: ${{ matrix.os }}
1414
env:
1515
OS: ${{ matrix.os }}
@@ -22,8 +22,13 @@ jobs:
2222
with:
2323
python-version: ${{ matrix.python }}
2424

25+
- name: Set ARCHFLAGS for macOS
26+
if: runner.os == 'macOS'
27+
run: echo "ARCHFLAGS=-arch arm64" >> $GITHUB_ENV
28+
2529
- name: Install poetry
2630
run: python -m pip install poetry
31+
2732
- name: Cache the virtualenv
2833
id: cache-venv
2934
uses: actions/cache@v4
@@ -37,7 +42,7 @@ jobs:
3742

3843
- name: Run tests and Generate coverage
3944
run: |
40-
poetry run pytest --cov --cov-report=xml
45+
poetry run pytest --cov --cov-report=xml -v --full-trace
4146
4247
- name: Upload coverage to Codecov
4348
uses: codecov/codecov-action@v4

CHANGELOG.md

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,38 @@
22

33
All notable changes to this project will be documented in this file.
44

5-
## [1.9.0] - 9999-99-99
5+
## [Unreleased] - 9999-99-99
66
### Added
77
- Added support for Exchange V2 proto queries and types
88
- Updated all chain exchange module examples to use the new Exchange V2 proto queries and types
99

1010
### Removed
1111
- Removed all methods marked as deprecated in AsyncClient and Composer
1212

13+
## [1.10.0] - 2025-04-16
14+
### Added
15+
- Added support for the queries in the new TXFees module
16+
17+
### Changed
18+
- Update in the implementation of the gas limit estimator to use the same values as the chain for the fixed gas messages
19+
- Updated all compiled protos for compatibility with Injective core v1.15 and Indexer v1.15.6
20+
21+
## [1.9.1] - 2025-03-03
22+
### Fixed
23+
- Added quantization in the functions that convert notional values to chain format
24+
25+
## [1.9.0] - 2025-02-13
26+
### Added
27+
- Added support for all new queries and messages from the new Permissions module
28+
29+
## [1.8.2] - 2024-12-13
30+
### Changed
31+
- Updated `protobuf` dependency version to make it more flexible
32+
33+
## [1.8.1] - 2024-12-04
34+
### Changed
35+
- Updated OFAC list link and contents
36+
1337
## [1.8.0] - 2024-11-14
1438
### Changed
1539
- The markets initialization in AsyncClient has been modified to get markets information from the chain endpoints instead of the Indexer endpoints

README.md

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,11 @@ $ poetry install
3535

3636
# connecting to Injective Exchange API
3737
# and listening for new orders from a specific spot market
38-
$ poetry run python examples/exchange_client/spot_exchange_rpc/8_StreamOrders.py
38+
$ poetry run python examples/exchange_client/spot_exchange_rpc/8_StreamOrderbookUpdate.py
3939

4040
# sending a msg with bank transfer
4141
# signs and posts a transaction to the Injective Chain
42-
$ poetry run python examples/chain_client/1_MsgSend.py
42+
$ poetry run python examples/chain_client/bank/1_MsgSend.py
4343
```
4444
Upgrade `pip` to the latest version, if you see these warnings:
4545
```
@@ -65,21 +65,14 @@ Upgrade `pip` to the latest version, if you see these warnings:
6565
pip install injective-py
6666
```
6767

68-
3. Fetch latest denom config
69-
```
70-
poetry run python pyinjective/utils/fetch_metadata.py
71-
```
72-
73-
Note that the [sync client](https://github.com/InjectiveLabs/sdk-python/blob/master/pyinjective/client.py) has been deprecated as of April 18, 2022. If you are using the sync client please make sure to transition to the [async client](https://github.com/InjectiveLabs/sdk-python/blob/master/pyinjective/async_client.py), for more information read [here](https://github.com/InjectiveLabs/sdk-python/issues/101)
74-
75-
4. Run all unit tests in a development environment
68+
3. Run all unit tests in a development environment
7669
```
7770
poetry run pytest -v
7871
```
7972

8073
## License
8174

82-
Copyright © 2021 - 2022 Injective Labs Inc. (https://injectivelabs.org/)
75+
Copyright © 2021 - 2025 Injective Labs Inc. (https://injectivelabs.org/)
8376

8477
<a href="https://drive.google.com/uc?export=view&id=1-fPQRh_D_dnun2yTtSsPW5MypVBOVYJP"><img src="https://drive.google.com/uc?export=view&id=1-fPQRh_D_dnun2yTtSsPW5MypVBOVYJP" style="width: 300px; max-width: 100%; height: auto" />
8578

buf.gen.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ managed:
44
plugins:
55
- remote: buf.build/protocolbuffers/python:v26.1
66
out: ./pyinjective/proto/
7-
- remote: buf.build/grpc/python:v1.65.4
7+
- remote: buf.build/grpc/python:v1.65.5
88
out: ./pyinjective/proto/
99
inputs:
1010
- module: buf.build/cosmos/cosmos-proto
@@ -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.13.0
26+
# tag: v1.15.0
2727
# subdir: proto
2828
- git_repo: https://github.com/InjectiveLabs/injective-core
2929
branch: master

examples/chain_client/1_LocalOrderHash.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import dotenv
77

88
from pyinjective.async_client import AsyncClient
9-
from pyinjective.constant import GAS_FEE_BUFFER_AMOUNT, GAS_PRICE
9+
from pyinjective.constant import GAS_FEE_BUFFER_AMOUNT
1010
from pyinjective.core.network import Network
1111
from pyinjective.orderhash import OrderHashManager
1212
from pyinjective.transaction import Transaction
@@ -111,7 +111,11 @@ async def main() -> None:
111111
.with_account_num(client.get_number())
112112
.with_chain_id(network.chain_id)
113113
)
114-
gas_price = GAS_PRICE
114+
115+
gas_price = await client.current_chain_gas_price()
116+
# adjust gas price to make it valid even if it changes between the time it is requested and the TX is broadcasted
117+
gas_price = int(gas_price * 1.1)
118+
115119
base_gas = 85000
116120
gas_limit = base_gas + GAS_FEE_BUFFER_AMOUNT # add buffer for gas fee computation
117121
gas_fee = "{:.18f}".format((gas_price * gas_limit) / pow(10, 18)).rstrip("0")
@@ -148,7 +152,11 @@ async def main() -> None:
148152
.with_account_num(client.get_number())
149153
.with_chain_id(network.chain_id)
150154
)
151-
gas_price = GAS_PRICE
155+
156+
gas_price = await client.current_chain_gas_price()
157+
# adjust gas price to make it valid even if it changes between the time it is requested and the TX is broadcasted
158+
gas_price = int(gas_price * 1.1)
159+
152160
base_gas = 85000
153161
gas_limit = base_gas + GAS_FEE_BUFFER_AMOUNT # add buffer for gas fee computation
154162
gas_fee = "{:.18f}".format((gas_price * gas_limit) / pow(10, 18)).rstrip("0")
@@ -240,7 +248,11 @@ async def main() -> None:
240248
.with_account_num(client.get_number())
241249
.with_chain_id(network.chain_id)
242250
)
243-
gas_price = GAS_PRICE
251+
252+
gas_price = await client.current_chain_gas_price()
253+
# adjust gas price to make it valid even if it changes between the time it is requested and the TX is broadcasted
254+
gas_price = int(gas_price * 1.1)
255+
244256
base_gas = 85000
245257
gas_limit = base_gas + GAS_FEE_BUFFER_AMOUNT # add buffer for gas fee computation
246258
gas_fee = "{:.18f}".format((gas_price * gas_limit) / pow(10, 18)).rstrip("0")

examples/chain_client/3_MessageBroadcaster.py

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import asyncio
2+
import json
23
import os
34
import uuid
45
from decimal import Decimal
56

67
import dotenv
78

8-
from pyinjective.composer import Composer as ProtoMsgComposer
9+
from pyinjective.async_client import AsyncClient
910
from pyinjective.core.broadcaster import MsgBroadcasterWithPk
1011
from pyinjective.core.network import Network
1112
from pyinjective.wallet import PrivateKey
@@ -17,11 +18,20 @@ async def main() -> None:
1718

1819
# select network: local, testnet, mainnet
1920
network = Network.testnet()
20-
composer = ProtoMsgComposer(network=network.string())
21+
22+
client = AsyncClient(network)
23+
composer = await client.composer()
24+
25+
gas_price = await client.current_chain_gas_price()
26+
# adjust gas price to make it valid even if it changes between the time it is requested and the TX is broadcasted
27+
gas_price = int(gas_price * 1.1)
2128

2229
message_broadcaster = MsgBroadcasterWithPk.new_using_simulation(
2330
network=network,
2431
private_key=private_key_in_hexa,
32+
gas_price=gas_price,
33+
client=client,
34+
composer=composer,
2535
)
2636

2737
priv_key = PrivateKey.from_hex(private_key_in_hexa)
@@ -64,7 +74,12 @@ async def main() -> None:
6474
# broadcast the transaction
6575
result = await message_broadcaster.broadcast([msg])
6676
print("---Transaction Response---")
67-
print(result)
77+
print(json.dumps(result, indent=2))
78+
79+
gas_price = await client.current_chain_gas_price()
80+
# adjust gas price to make it valid even if it changes between the time it is requested and the TX is broadcasted
81+
gas_price = int(gas_price * 1.1)
82+
message_broadcaster.update_gas_price(gas_price=gas_price)
6883

6984

7085
if __name__ == "__main__":

examples/chain_client/4_MessageBroadcasterWithGranteeAccount.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import asyncio
2+
import json
23
import os
34
import uuid
45
from decimal import Decimal
56

67
import dotenv
78

89
from pyinjective.async_client import AsyncClient
9-
from pyinjective.composer import Composer as ProtoMsgComposer
1010
from pyinjective.core.broadcaster import MsgBroadcasterWithPk
1111
from pyinjective.core.network import Network
1212
from pyinjective.wallet import Address, PrivateKey
@@ -19,20 +19,27 @@ async def main() -> None:
1919

2020
# select network: local, testnet, mainnet
2121
network = Network.testnet()
22-
composer = ProtoMsgComposer(network=network.string())
2322

2423
# initialize grpc client
2524
client = AsyncClient(network)
25+
composer = await client.composer()
2626
await client.sync_timeout_height()
2727

2828
# load account
2929
priv_key = PrivateKey.from_hex(private_key_in_hexa)
3030
pub_key = priv_key.to_public_key()
3131
address = pub_key.to_address()
3232

33+
gas_price = await client.current_chain_gas_price()
34+
# adjust gas price to make it valid even if it changes between the time it is requested and the TX is broadcasted
35+
gas_price = int(gas_price * 1.1)
36+
3337
message_broadcaster = MsgBroadcasterWithPk.new_for_grantee_account_using_simulation(
3438
network=network,
3539
grantee_private_key=private_key_in_hexa,
40+
gas_price=gas_price,
41+
client=client,
42+
composer=composer,
3643
)
3744

3845
# prepare tx msg
@@ -55,7 +62,12 @@ async def main() -> None:
5562
# broadcast the transaction
5663
result = await message_broadcaster.broadcast([msg])
5764
print("---Transaction Response---")
58-
print(result)
65+
print(json.dumps(result, indent=2))
66+
67+
gas_price = await client.current_chain_gas_price()
68+
# adjust gas price to make it valid even if it changes between the time it is requested and the TX is broadcasted
69+
gas_price = int(gas_price * 1.1)
70+
message_broadcaster.update_gas_price(gas_price=gas_price)
5971

6072

6173
if __name__ == "__main__":

examples/chain_client/5_MessageBroadcasterWithoutSimulation.py

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import asyncio
2+
import json
23
import os
34
import uuid
45
from decimal import Decimal
56

67
import dotenv
78

8-
from pyinjective.composer import Composer as ProtoMsgComposer
9+
from pyinjective.async_client import AsyncClient
910
from pyinjective.core.broadcaster import MsgBroadcasterWithPk
1011
from pyinjective.core.network import Network
1112
from pyinjective.wallet import PrivateKey
@@ -17,11 +18,21 @@ async def main() -> None:
1718

1819
# select network: local, testnet, mainnet
1920
network = Network.testnet()
20-
composer = ProtoMsgComposer(network=network.string())
21+
22+
client = AsyncClient(network)
23+
composer = await client.composer()
24+
await client.sync_timeout_height()
25+
26+
gas_price = await client.current_chain_gas_price()
27+
# adjust gas price to make it valid even if it changes between the time it is requested and the TX is broadcasted
28+
gas_price = int(gas_price * 1.1)
2129

2230
message_broadcaster = MsgBroadcasterWithPk.new_without_simulation(
2331
network=network,
2432
private_key=private_key_in_hexa,
33+
gas_price=gas_price,
34+
client=client,
35+
composer=composer,
2536
)
2637

2738
priv_key = PrivateKey.from_hex(private_key_in_hexa)
@@ -64,7 +75,12 @@ async def main() -> None:
6475
# broadcast the transaction
6576
result = await message_broadcaster.broadcast([msg])
6677
print("---Transaction Response---")
67-
print(result)
78+
print(json.dumps(result, indent=2))
79+
80+
gas_price = await client.current_chain_gas_price()
81+
# adjust gas price to make it valid even if it changes between the time it is requested and the TX is broadcasted
82+
gas_price = int(gas_price * 1.1)
83+
message_broadcaster.update_gas_price(gas_price=gas_price)
6884

6985

7086
if __name__ == "__main__":

0 commit comments

Comments
 (0)