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 7 commits into
base: dev
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
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/update_chain_stream_for_exchange_v2
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_v2_spot_order(
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_v2_spot_order(
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_v2_derivative_order(
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_v2_derivative_order(
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_v2_spot_order(
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_v2_spot_order(
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_v2_spot_order(
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_v2_spot_order(
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
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"),
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
7 changes: 3 additions & 4 deletions examples/chain_client/exchange/17_MsgSubaccountTransfer.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import asyncio
import os
from decimal import Decimal

import dotenv
from grpc import RpcError
Expand Down Expand Up @@ -33,12 +32,12 @@ async def main() -> None:
dest_subaccount_id = address.get_subaccount_id(index=1)

# prepare tx msg
msg = composer.msg_subaccount_transfer(
msg = composer.msg_subaccount_transfer_v2(
sender=address.to_acc_bech32(),
source_subaccount_id=subaccount_id,
destination_subaccount_id=dest_subaccount_id,
amount=Decimal(100),
denom="INJ",
amount=100,
denom="inj",
)

# build sim tx
Expand Down
7 changes: 3 additions & 4 deletions examples/chain_client/exchange/18_MsgExternalTransfer.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import asyncio
import os
from decimal import Decimal

import dotenv
from grpc import RpcError
Expand Down Expand Up @@ -33,12 +32,12 @@ async def main() -> None:
dest_subaccount_id = "0xaf79152ac5df276d9a8e1e2e22822f9713474902000000000000000000000000"

# prepare tx msg
msg = composer.msg_external_transfer(
msg = composer.msg_external_transfer_v2(
sender=address.to_acc_bech32(),
source_subaccount_id=subaccount_id,
destination_subaccount_id=dest_subaccount_id,
amount=Decimal(100),
denom="INJ",
amount=100,
denom="inj",
)

# build sim tx
Expand Down
4 changes: 2 additions & 2 deletions examples/chain_client/exchange/19_MsgLiquidatePosition.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ async def main() -> None:
fee_recipient = "inj1hkhdaj2a2clmq5jq6mspsggqs32vynpk228q3r"
cid = str(uuid.uuid4())

order = composer.derivative_order(
order = composer.create_v2_derivative_order(
market_id=market_id,
subaccount_id=subaccount_id,
fee_recipient=fee_recipient,
Expand All @@ -51,7 +51,7 @@ async def main() -> None:
)

# prepare tx msg
msg = composer.msg_liquidate_position(
msg = composer.msg_liquidate_position_v2(
sender=address.to_acc_bech32(),
subaccount_id="0x156df4d5bc8e7dd9191433e54bd6a11eeb390921000000000000000000000000",
market_id=market_id,
Expand Down
Loading
Loading