Skip to content

[CP-126] add support exchange v2 #354

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

Merged
merged 21 commits into from
May 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
d6195a7
(fix) Removed deprecated methods
aarmoa Oct 15, 2024
efc9ec6
(feat) Updated proto definitions with exchange V2 from chain core. Fi…
aarmoa Oct 17, 2024
5e70823
(feat) Updated proto definitions with exchange V2 from chain core to …
aarmoa Oct 22, 2024
291fe99
(feat) Added methods in AsyncClient and Composer for Exchange V2 quer…
aarmoa Oct 31, 2024
cc89852
(feat) Refactored markets and tokens initialization methods in AsyncC…
aarmoa Nov 2, 2024
a05a00c
(fix) Renamed two methods to make the intent more clear
aarmoa Nov 4, 2024
7d7fc08
(fix) Removed support for chain stream V2, since it was decided we ar…
aarmoa Nov 4, 2024
4980b41
(fix) Rename all methods having v2 in the middle of the name to have …
aarmoa Nov 13, 2024
111373d
Merge branch 'dev' of https://github.com/InjectiveLabs/sdk-python int…
aarmoa Nov 13, 2024
407067a
(fix) Solved a couple of warnings
aarmoa Nov 14, 2024
321a78e
Merge branch 'dev' of https://github.com/InjectiveLabs/sdk-python int…
aarmoa Nov 14, 2024
b8beed2
(fix) Fixed issues in the V2 messages with Coin parameters, to not ad…
aarmoa Nov 15, 2024
0e6a4ca
(fix) Updated pyproject.toml version number
aarmoa Nov 15, 2024
52c798f
(feat) Added again support for chain stream V2
aarmoa Nov 19, 2024
3c3b2e4
(fix) Updated version in pyproject.toml to publish a new alpha version
aarmoa Nov 20, 2024
398e523
(fix) Updated incorrect deprecation comment
aarmoa Nov 20, 2024
c9cfcc0
chore: update proto definitions from injective-core master branch (v1…
aarmoa May 20, 2025
0d50fc2
Merge branch 'dev' of https://github.com/InjectiveLabs/sdk-python int…
aarmoa May 20, 2025
26cf36a
feat: upgraded Indexer proto to version v1.16.0-rc2. Updated gas esti…
aarmoa May 22, 2025
8febafa
chore: added unit tests for the GTB gas estimation using gas heuristics
aarmoa May 22, 2025
de24ebd
fix: excluded deprecation unit test that freezed the Windows validati…
aarmoa May 22, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
All notable changes to this project will be documented in this file.

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

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

## [1.10.0] - 2025-04-16
### Added
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ gen-client: clone-all copy-proto
$(call clean_repos)
$(MAKE) fix-generated-proto-imports

PROTO_MODULES := cosmwasm exchange gogoproto cosmos_proto cosmos testpb ibc amino tendermint injective
PROTO_MODULES := cosmwasm exchange gogoproto cosmos_proto cosmos testpb ibc amino tendermint cometbft injective

fix-generated-proto-imports:
@touch pyinjective/proto/__init__.py
Expand All @@ -31,7 +31,7 @@ clean-all:
$(call clean_repos)

clone-injective-indexer:
git clone https://github.com/InjectiveLabs/injective-indexer.git -b v1.15.6 --depth 1 --single-branch
git clone https://github.com/InjectiveLabs/injective-indexer.git -b v1.16.0-rc2 --depth 1 --single-branch

clone-all: clone-injective-indexer

Expand Down
14 changes: 8 additions & 6 deletions buf.gen.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,21 @@ inputs:
- module: buf.build/cosmos/gogo-proto
- module: buf.build/googleapis/googleapis
- module: buf.build/cosmos/ics23
- git_repo: https://github.com/InjectiveLabs/cosmos-sdk
tag: v0.50.9-inj.5
- git_repo: https://github.com/InjectiveLabs/ibc-go
tag: v8.7.0-inj
tag: v8.7.0-evm-comet1-inj
- git_repo: https://github.com/InjectiveLabs/wasmd
tag: v0.53.2-inj.2
tag: v0.53.2-evm-comet1-inj
- git_repo: https://github.com/InjectiveLabs/cometbft
tag: v1.0.1-inj
- git_repo: https://github.com/InjectiveLabs/cosmos-sdk
tag: v0.50.13-evm-comet1-inj.2
# - git_repo: https://github.com/InjectiveLabs/wasmd
# branch: v0.51.x-inj
# subdir: proto
- git_repo: https://github.com/InjectiveLabs/injective-core
tag: v1.15.0
tag: v1.16.0-beta.2
subdir: proto
# - git_repo: https://github.com/InjectiveLabs/injective-core
# branch: release/v1.15.x
# branch: master
# subdir: proto
- directory: proto
24 changes: 12 additions & 12 deletions examples/chain_client/1_LocalOrderHash.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ async def main() -> None:
fee_recipient = "inj1hkhdaj2a2clmq5jq6mspsggqs32vynpk228q3r"

spot_orders = [
composer.spot_order(
composer.create_spot_order_v2(
market_id=spot_market_id,
subaccount_id=subaccount_id,
fee_recipient=fee_recipient,
Expand All @@ -50,7 +50,7 @@ async def main() -> None:
order_type="BUY",
cid=str(uuid.uuid4()),
),
composer.spot_order(
composer.create_spot_order_v2(
market_id=spot_market_id,
subaccount_id=subaccount_id,
fee_recipient=fee_recipient,
Expand All @@ -62,7 +62,7 @@ async def main() -> None:
]

derivative_orders = [
composer.derivative_order(
composer.create_derivative_order_v2(
market_id=deriv_market_id,
subaccount_id=subaccount_id,
fee_recipient=fee_recipient,
Expand All @@ -74,7 +74,7 @@ async def main() -> None:
order_type="BUY",
cid=str(uuid.uuid4()),
),
composer.derivative_order(
composer.create_derivative_order_v2(
market_id=deriv_market_id,
subaccount_id=subaccount_id,
fee_recipient=fee_recipient,
Expand All @@ -89,9 +89,9 @@ async def main() -> None:
]

# prepare tx msg
spot_msg = composer.msg_batch_create_spot_limit_orders(sender=address.to_acc_bech32(), orders=spot_orders)
spot_msg = composer.msg_batch_create_spot_limit_orders_v2(sender=address.to_acc_bech32(), orders=spot_orders)

deriv_msg = composer.msg_batch_create_derivative_limit_orders(
deriv_msg = composer.msg_batch_create_derivative_limit_orders_v2(
sender=address.to_acc_bech32(), orders=derivative_orders
)

Expand Down Expand Up @@ -178,7 +178,7 @@ async def main() -> None:
print("gas fee: {} INJ".format(gas_fee))

spot_orders = [
composer.spot_order(
composer.create_spot_order_v2(
market_id=spot_market_id,
subaccount_id=subaccount_id_2,
fee_recipient=fee_recipient,
Expand All @@ -187,7 +187,7 @@ async def main() -> None:
order_type="BUY_PO",
cid=str(uuid.uuid4()),
),
composer.spot_order(
composer.create_spot_order_v2(
market_id=spot_market_id,
subaccount_id=subaccount_id_2,
fee_recipient=fee_recipient,
Expand All @@ -199,7 +199,7 @@ async def main() -> None:
]

derivative_orders = [
composer.derivative_order(
composer.create_derivative_order_v2(
market_id=deriv_market_id,
subaccount_id=subaccount_id_2,
fee_recipient=fee_recipient,
Expand All @@ -211,7 +211,7 @@ async def main() -> None:
order_type="BUY",
cid=str(uuid.uuid4()),
),
composer.derivative_order(
composer.create_derivative_order_v2(
market_id=deriv_market_id,
subaccount_id=subaccount_id_2,
fee_recipient=fee_recipient,
Expand All @@ -226,9 +226,9 @@ async def main() -> None:
]

# prepare tx msg
spot_msg = composer.msg_batch_create_spot_limit_orders(sender=address.to_acc_bech32(), orders=spot_orders)
spot_msg = composer.msg_batch_create_spot_limit_orders_v2(sender=address.to_acc_bech32(), orders=spot_orders)

deriv_msg = composer.msg_batch_create_derivative_limit_orders(
deriv_msg = composer.msg_batch_create_derivative_limit_orders_v2(
sender=address.to_acc_bech32(), orders=derivative_orders
)

Expand Down
8 changes: 4 additions & 4 deletions examples/chain_client/2_StreamEventOrderFail.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ async def main() -> None:
network = Network.mainnet()
event_filter = (
"tm.event='Tx' AND message.sender='inj1rwv4zn3jptsqs7l8lpa3uvzhs57y8duemete9e' "
"AND message.action='/injective.exchange.v1beta1.MsgBatchUpdateOrders' "
"AND injective.exchange.v1beta1.EventOrderFail.flags EXISTS"
"AND message.action='/injective.exchange.v2.MsgBatchUpdateOrders' "
"AND injective.exchange.v2.EventOrderFail.flags EXISTS"
)
query = json.dumps(
{
Expand All @@ -32,8 +32,8 @@ async def main() -> None:
if result == {}:
continue

failed_order_hashes = json.loads(result["events"]["injective.exchange.v1beta1.EventOrderFail.hashes"][0])
failed_order_codes = json.loads(result["events"]["injective.exchange.v1beta1.EventOrderFail.flags"][0])
failed_order_hashes = json.loads(result["events"]["injective.exchange.v2.EventOrderFail.hashes"][0])
failed_order_codes = json.loads(result["events"]["injective.exchange.v2.EventOrderFail.flags"][0])

dict = {}
for i, order_hash in enumerate(failed_order_hashes):
Expand Down
6 changes: 3 additions & 3 deletions examples/chain_client/3_MessageBroadcaster.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ async def main() -> None:
spot_market_id_create = "0x0611780ba69656949525013d947713300f56c37b6175e02f26bffa495c3208fe"

spot_orders_to_create = [
composer.spot_order(
composer.create_spot_order_v2(
market_id=spot_market_id_create,
subaccount_id=subaccount_id,
fee_recipient=fee_recipient,
Expand All @@ -54,7 +54,7 @@ async def main() -> None:
order_type="BUY",
cid=(str(uuid.uuid4())),
),
composer.spot_order(
composer.create_spot_order_v2(
market_id=spot_market_id_create,
subaccount_id=subaccount_id,
fee_recipient=fee_recipient,
Expand All @@ -66,7 +66,7 @@ async def main() -> None:
]

# prepare tx msg
msg = composer.msg_batch_update_orders(
msg = composer.msg_batch_update_orders_v2(
sender=address.to_acc_bech32(),
spot_orders_to_create=spot_orders_to_create,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ async def main() -> None:
granter_address = Address.from_acc_bech32(granter_inj_address)
granter_subaccount_id = granter_address.get_subaccount_id(index=0)

msg = composer.msg_create_spot_limit_order(
msg = composer.msg_create_spot_limit_order_v2(
market_id=market_id,
sender=granter_inj_address,
subaccount_id=granter_subaccount_id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ async def main() -> None:
spot_market_id_create = "0x0611780ba69656949525013d947713300f56c37b6175e02f26bffa495c3208fe"

spot_orders_to_create = [
composer.spot_order(
composer.create_spot_order_v2(
market_id=spot_market_id_create,
subaccount_id=subaccount_id,
fee_recipient=fee_recipient,
Expand All @@ -55,7 +55,7 @@ async def main() -> None:
order_type="BUY",
cid=str(uuid.uuid4()),
),
composer.spot_order(
composer.create_spot_order_v2(
market_id=spot_market_id_create,
subaccount_id=subaccount_id,
fee_recipient=fee_recipient,
Expand All @@ -67,7 +67,7 @@ async def main() -> None:
]

# prepare tx msg
msg = composer.msg_batch_update_orders(
msg = composer.msg_batch_update_orders_v2(
sender=address.to_acc_bech32(),
spot_orders_to_create=spot_orders_to_create,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ async def main() -> None:
granter_address = Address.from_acc_bech32(granter_inj_address)
granter_subaccount_id = granter_address.get_subaccount_id(index=0)

msg = composer.msg_create_spot_limit_order(
msg = composer.msg_create_spot_limit_order_v2(
market_id=market_id,
sender=granter_inj_address,
subaccount_id=granter_subaccount_id,
Expand Down
22 changes: 11 additions & 11 deletions examples/chain_client/7_ChainStream.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,29 +31,29 @@ async def main() -> None:
inj_usdt_market = "0x0611780ba69656949525013d947713300f56c37b6175e02f26bffa495c3208fe"
inj_usdt_perp_market = "0x17ef48032cb24375ba7c2e39f384e56433bcab20cbee9a7357e4cba2eb00abe6"

bank_balances_filter = composer.chain_stream_bank_balances_filter(
bank_balances_filter = composer.chain_stream_bank_balances_v2_filter(
accounts=["inj1hkhdaj2a2clmq5jq6mspsggqs32vynpk228q3r"]
)
subaccount_deposits_filter = composer.chain_stream_subaccount_deposits_filter(subaccount_ids=[subaccount_id])
spot_trades_filter = composer.chain_stream_trades_filter(subaccount_ids=["*"], market_ids=[inj_usdt_market])
derivative_trades_filter = composer.chain_stream_trades_filter(
subaccount_deposits_filter = composer.chain_stream_subaccount_deposits_v2_filter(subaccount_ids=[subaccount_id])
spot_trades_filter = composer.chain_stream_trades_v2_filter(subaccount_ids=["*"], market_ids=[inj_usdt_market])
derivative_trades_filter = composer.chain_stream_trades_v2_filter(
subaccount_ids=["*"], market_ids=[inj_usdt_perp_market]
)
spot_orders_filter = composer.chain_stream_orders_filter(
spot_orders_filter = composer.chain_stream_orders_v2_filter(
subaccount_ids=[subaccount_id], market_ids=[inj_usdt_market]
)
derivative_orders_filter = composer.chain_stream_orders_filter(
derivative_orders_filter = composer.chain_stream_orders_v2_filter(
subaccount_ids=[subaccount_id], market_ids=[inj_usdt_perp_market]
)
spot_orderbooks_filter = composer.chain_stream_orderbooks_filter(market_ids=[inj_usdt_market])
derivative_orderbooks_filter = composer.chain_stream_orderbooks_filter(market_ids=[inj_usdt_perp_market])
positions_filter = composer.chain_stream_positions_filter(
spot_orderbooks_filter = composer.chain_stream_orderbooks_v2_filter(market_ids=[inj_usdt_market])
derivative_orderbooks_filter = composer.chain_stream_orderbooks_v2_filter(market_ids=[inj_usdt_perp_market])
positions_filter = composer.chain_stream_positions_v2_filter(
subaccount_ids=[subaccount_id], market_ids=[inj_usdt_perp_market]
)
oracle_price_filter = composer.chain_stream_oracle_price_filter(symbols=["INJ", "USDT"])
oracle_price_filter = composer.chain_stream_oracle_price_v2_filter(symbols=["INJ", "USDT"])

task = asyncio.get_event_loop().create_task(
client.listen_chain_stream_updates(
client.listen_chain_stream_v2_updates(
callback=chain_stream_event_processor,
on_end_callback=stream_closed_processor,
on_status_callback=stream_error_processor,
Expand Down
2 changes: 1 addition & 1 deletion examples/chain_client/authz/1_MsgGrant.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ async def main() -> None:
msg = composer.MsgGrantGeneric(
granter=address.to_acc_bech32(),
grantee=grantee_public_address,
msg_type="/injective.exchange.v1beta1.MsgCreateSpotLimitOrder",
msg_type="/injective.exchange.v2.MsgCreateSpotLimitOrder",
expire_in=31536000, # 1 year
)

Expand Down
2 changes: 1 addition & 1 deletion examples/chain_client/authz/2_MsgExec.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ async def main() -> None:

granter_address = Address.from_acc_bech32(granter_inj_address)
granter_subaccount_id = granter_address.get_subaccount_id(index=0)
msg0 = composer.msg_create_spot_limit_order(
msg0 = composer.msg_create_spot_limit_order_v2(
sender=granter_inj_address,
market_id=market_id,
subaccount_id=granter_subaccount_id,
Expand Down
2 changes: 1 addition & 1 deletion examples/chain_client/authz/3_MsgRevoke.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ async def main() -> None:
msg = composer.MsgRevoke(
granter=address.to_acc_bech32(),
grantee=grantee_public_address,
msg_type="/injective.exchange.v1beta1.MsgCreateSpotLimitOrder",
msg_type="/injective.exchange.v2.MsgCreateSpotLimitOrder",
)

# build sim tx
Expand Down
2 changes: 1 addition & 1 deletion examples/chain_client/authz/query/1_Grants.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ async def main() -> None:

network = Network.testnet()
client = AsyncClient(network)
msg_type_url = "/injective.exchange.v1beta1.MsgCreateDerivativeLimitOrder"
msg_type_url = "/injective.exchange.v2.MsgCreateDerivativeLimitOrder"
authorizations = await client.fetch_grants(granter=granter, grantee=grantee, msg_type_url=msg_type_url)
print(authorizations)

Expand Down
6 changes: 3 additions & 3 deletions examples/chain_client/bank/1_MsgSend.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ async def main() -> None:
await client.fetch_account(address.to_acc_bech32())

# prepare tx msg
msg = composer.MsgSend(
msg = composer.msg_send(
from_address=address.to_acc_bech32(),
to_address="inj1hkhdaj2a2clmq5jq6mspsggqs32vynpk228q3r",
amount=0.000000000000000001,
denom="INJ",
amount=1,
denom="inj",
)

# build sim tx
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ async def main() -> None:
fee_recipient = "inj1hkhdaj2a2clmq5jq6mspsggqs32vynpk228q3r"

# prepare tx msg
msg = composer.msg_create_derivative_limit_order(
msg = composer.msg_create_derivative_limit_order_v2(
sender=address.to_acc_bech32(),
market_id=market_id,
subaccount_id=subaccount_id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ async def main() -> None:
fee_recipient = "inj1hkhdaj2a2clmq5jq6mspsggqs32vynpk228q3r"

# prepare tx msg
msg = composer.msg_create_derivative_market_order(
msg = composer.msg_create_derivative_market_order_v2(
sender=address.to_acc_bech32(),
market_id=market_id,
subaccount_id=subaccount_id,
Expand Down
10 changes: 8 additions & 2 deletions examples/chain_client/exchange/12_MsgCancelDerivativeOrder.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,14 @@ async def main() -> None:
order_hash = "0x667ee6f37f6d06bf473f4e1434e92ac98ff43c785405e2a511a0843daeca2de9"

# prepare tx msg
msg = composer.msg_cancel_derivative_order(
sender=address.to_acc_bech32(), market_id=market_id, subaccount_id=subaccount_id, order_hash=order_hash
msg = composer.msg_cancel_derivative_order_v2(
sender=address.to_acc_bech32(),
market_id=market_id,
subaccount_id=subaccount_id,
order_hash=order_hash,
is_buy=True,
is_market_order=False,
is_conditional=False,
)

# build sim tx
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ async def main() -> None:
await client.fetch_account(address.to_acc_bech32())

# prepare tx msg
message = composer.msg_instant_binary_options_market_launch(
message = composer.msg_instant_binary_options_market_launch_v2(
sender=address.to_acc_bech32(),
ticker="UFC-KHABIB-TKO-05/30/2023",
oracle_symbol="UFC-KHABIB-TKO-05/30/2023",
Expand Down
Loading
Loading