Skip to content
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

Feat/add support exchange v2 #354

Draft
wants to merge 16 commits into
base: dev
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@

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

## [1.9.0] - 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.8.0] - 2024-11-14
### Changed
- The markets initialization in AsyncClient has been modified to get markets information from the chain endpoints instead of the Indexer endpoints
Expand Down
12 changes: 6 additions & 6 deletions buf.gen.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,18 @@ inputs:
- module: buf.build/googleapis/googleapis
- module: buf.build/cosmos/ics23
- git_repo: https://github.com/InjectiveLabs/cosmos-sdk
tag: v0.50.8-inj-0
tag: v0.50.9-inj-2
- git_repo: https://github.com/InjectiveLabs/ibc-go
tag: v8.3.2-inj-0
- git_repo: https://github.com/InjectiveLabs/wasmd
tag: v0.51.0-inj-0
tag: v0.52.0-inj-0
# - git_repo: https://github.com/InjectiveLabs/wasmd
# branch: v0.51.x-inj
# subdir: proto
- git_repo: https://github.com/InjectiveLabs/injective-core
tag: v1.13.0
subdir: proto
# - git_repo: https://github.com/InjectiveLabs/injective-core
# branch: master
# tag: v1.13.0
# subdir: proto
- git_repo: https://github.com/InjectiveLabs/injective-core
branch: feat/add_exchange_v1_compatibility_to_chain_stream
subdir: proto
- directory: proto
16 changes: 8 additions & 8 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 @@ -218,9 +218,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 @@ -35,7 +35,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 @@ -44,7 +44,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 @@ -56,7 +56,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 @@ -41,7 +41,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 @@ -35,7 +35,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 @@ -44,7 +44,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 @@ -56,7 +56,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 @@ -40,7 +40,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 @@ -34,7 +34,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
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
from pyinjective.constant import GAS_FEE_BUFFER_AMOUNT, GAS_PRICE
from pyinjective.core.network import Network
from pyinjective.transaction import Transaction
from pyinjective.utils.denom import Denom
from pyinjective.wallet import PrivateKey


Expand All @@ -37,18 +36,8 @@ async def main() -> None:
market_id = "0x767e1542fbc111e88901e223e625a4a8eb6d630c96884bbde672e8bc874075bb"
fee_recipient = "inj1hkhdaj2a2clmq5jq6mspsggqs32vynpk228q3r"

# set custom denom to bypass ini file load (optional)
denom = Denom(
description="desc",
base=0,
quote=6,
min_price_tick_size=1000,
min_quantity_tick_size=0.0001,
min_notional=0,
)

# prepare tx msg
msg = composer.msg_create_binary_options_limit_order(
msg = composer.msg_create_binary_options_limit_order_v2(
sender=address.to_acc_bech32(),
market_id=market_id,
subaccount_id=subaccount_id,
Expand All @@ -58,7 +47,6 @@ async def main() -> None:
margin=Decimal("0.5"),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why in some places we leave Decimal and in some not?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry @PavelInjective. What do you mean with "we leave Decimal"?
Or maybe you can mention an example of those places you mean we don't leave Decimal

order_type="BUY",
cid=str(uuid.uuid4()),
denom=denom,
)

# 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_binary_options_market_order(
msg = composer.msg_create_binary_options_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/16_MsgCancelBinaryOptionsOrder.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,14 @@ async def main() -> None:
order_hash = "a975fbd72b874bdbf5caf5e1e8e2653937f33ce6dd14d241c06c8b1f7b56be46"

# prepare tx msg
msg = composer.msg_cancel_binary_options_order(
sender=address.to_acc_bech32(), market_id=market_id, subaccount_id=subaccount_id, order_hash=order_hash
msg = composer.msg_cancel_binary_options_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
tx = (
Expand Down
Loading
Loading