-
Notifications
You must be signed in to change notification settings - Fork 33
[CP-652] update protos for v1.17.0 upgrade #400
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| import asyncio | ||
| import json | ||
| import os | ||
|
|
||
| import dotenv | ||
|
|
||
| from pyinjective.async_client_v2 import AsyncClient | ||
| from pyinjective.core.broadcaster import MsgBroadcasterWithPk | ||
| from pyinjective.core.network import Network | ||
| from pyinjective.wallet import PrivateKey | ||
|
|
||
|
|
||
| async def main() -> None: | ||
| dotenv.load_dotenv() | ||
| configured_private_key = os.getenv("INJECTIVE_PRIVATE_KEY") | ||
|
|
||
| # select network: local, testnet, mainnet | ||
| network = Network.testnet() | ||
|
|
||
| # initialize grpc client | ||
| client = AsyncClient(network) | ||
| await client.initialize_tokens_from_chain_denoms() | ||
| composer = await client.composer() | ||
|
|
||
| gas_price = await client.current_chain_gas_price() | ||
| # adjust gas price to make it valid even if it changes between the time it is requested and the TX is broadcasted | ||
| gas_price = int(gas_price * 1.1) | ||
|
|
||
| message_broadcaster = MsgBroadcasterWithPk.new_using_simulation( | ||
| network=network, | ||
| private_key=configured_private_key, | ||
| gas_price=gas_price, | ||
| client=client, | ||
| composer=composer, | ||
| ) | ||
|
|
||
| # load account | ||
| priv_key = PrivateKey.from_hex(configured_private_key) | ||
| pub_key = priv_key.to_public_key() | ||
| address = pub_key.to_address() | ||
| await client.fetch_account(address.to_acc_bech32()) | ||
|
|
||
| offsetting_subaccount_ids = { | ||
| "0xbdaedec95d563fb05240d6e01821008454c24c36000000000000000000000000", | ||
| "0xaf79152ac5df276d9a8e1e2e22822f9713474902000000000000000000000000", | ||
| } | ||
|
|
||
| # prepare tx msg | ||
| message = composer.msg_offset_position( | ||
| sender=address.to_acc_bech32(), | ||
| subaccount_id=address.get_subaccount_id(index=0), | ||
| market_id="0x17ef48032cb24375ba7c2e39f384e56433bcab20cbee9a7357e4cba2eb00abe6", | ||
| offsetting_subaccount_ids=offsetting_subaccount_ids, | ||
| ) | ||
|
|
||
| # broadcast the transaction | ||
| result = await message_broadcaster.broadcast([message]) | ||
| print("---Transaction Response---") | ||
| print(json.dumps(result, indent=2)) | ||
|
|
||
| gas_price = await client.current_chain_gas_price() | ||
| # adjust gas price to make it valid even if it changes between the time it is requested and the TX is broadcasted | ||
| gas_price = int(gas_price * 1.1) | ||
| message_broadcaster.update_gas_price(gas_price=gas_price) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| asyncio.get_event_loop().run_until_complete(main()) | ||
|
Comment on lines
+1
to
+68
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chainPrevent runtime errors; use list for repeated field; round gas price up.
@@
-import asyncio
+import asyncio
+import math
import json
import os
@@
dotenv.load_dotenv()
- configured_private_key = os.getenv("INJECTIVE_PRIVATE_KEY")
+ configured_private_key = os.getenv("INJECTIVE_PRIVATE_KEY")
+ if not configured_private_key:
+ raise ValueError("INJECTIVE_PRIVATE_KEY env var is required for this example.")
@@
- gas_price = int(gas_price * 1.1)
+ gas_price = math.ceil(gas_price * 1.1)
@@
- offsetting_subaccount_ids = {
+ offsetting_subaccount_ids = [
"0xbdaedec95d563fb05240d6e01821008454c24c36000000000000000000000000",
"0xaf79152ac5df276d9a8e1e2e22822f9713474902000000000000000000000000",
- }
+ ]
@@
- gas_price = int(gas_price * 1.1)
+ gas_price = math.ceil(gas_price * 1.1)
@@
-if __name__ == "__main__":
- asyncio.get_event_loop().run_until_complete(main())
+if __name__ == "__main__":
+ asyncio.run(main())Optional: document python-dotenv as a requirement for running examples. Length of output: 54 🏁 Script executed: #!/bin/bash
# Search for msg_offset_position method definition to check parameter types
rg -n "def msg_offset_position" -A 10 --type=pyLength of output: 866 🏁 Script executed: #!/bin/bash
# Check env var validation patterns in other examples
rg -n "getenv\(" examples/ -B 2 -A 2 --type=py | head -60Length of output: 4230 🏁 Script executed: #!/bin/bash
# Look for requirements or setup files documenting python-dotenv
fd -t f -E "*.pyc" "\.(txt|cfg|toml|yaml|yml)$" | xargs rg -l "python-dotenv|dotenv" 2>/dev/null | head -20Length of output: 14 🏁 Script executed: #!/bin/bash
# Check other examples for gas price calculation patterns
rg -n "gas_price.*\*|math\.ceil" examples/ -B 2 -A 2 --type=py | head -80Length of output: 7566 🏁 Script executed: #!/bin/bash
# Check for asyncio patterns - asyncio.run vs get_event_loop
rg -n "asyncio\.(run|get_event_loop)" examples/ --type=pyLength of output: 39792 Fix set-to-list conversion for repeated field; validate env var to prevent crashes. The code passes a
Optional improvements noted in original review (gas price rounding, asyncio.run) diverge from current codebase patterns but are reasonable modernizations for consistency across future examples. @@
+import math
import os
import dotenv
@@
- configured_private_key = os.getenv("INJECTIVE_PRIVATE_KEY")
+ configured_private_key = os.getenv("INJECTIVE_PRIVATE_KEY")
+ if not configured_private_key:
+ raise ValueError("INJECTIVE_PRIVATE_KEY env var is required for this example.")
@@
- offsetting_subaccount_ids = {
+ offsetting_subaccount_ids = [
"0xbdaedec95d563fb05240d6e01821008454c24c36000000000000000000000000",
"0xaf79152ac5df276d9a8e1e2e22822f9713474902000000000000000000000000",
- }
+ ]🤖 Prompt for AI Agents |
||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -104,6 +104,21 @@ async def main() -> None: | |||||||||||||||||
| ), | ||||||||||||||||||
| ] | ||||||||||||||||||
|
|
||||||||||||||||||
| derivative_market_orders_to_create = [ | ||||||||||||||||||
| composer.derivative_order( | ||||||||||||||||||
| market_id=derivative_market_id_create, | ||||||||||||||||||
| subaccount_id=subaccount_id, | ||||||||||||||||||
| fee_recipient=fee_recipient, | ||||||||||||||||||
| price=Decimal(25100), | ||||||||||||||||||
| quantity=Decimal(0.1), | ||||||||||||||||||
| margin=composer.calculate_margin( | ||||||||||||||||||
| quantity=Decimal(0.1), price=Decimal(25100), leverage=Decimal(1), is_reduce_only=False | ||||||||||||||||||
| ), | ||||||||||||||||||
|
Comment on lines
+113
to
+116
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Avoid Decimal(float); use string literal to prevent FP rounding (RUF032). - quantity=Decimal(0.1),
+ quantity=Decimal("0.1"),
@@
- quantity=Decimal(0.1), price=Decimal(25100), leverage=Decimal(1), is_reduce_only=False
+ quantity=Decimal("0.1"), price=Decimal(25100), leverage=Decimal(1), is_reduce_only=False📝 Committable suggestion
Suggested change
🧰 Tools🪛 Ruff (0.14.1)113-113: Replace with string literal (RUF032) 115-115: Replace with string literal (RUF032) 🤖 Prompt for AI Agents |
||||||||||||||||||
| order_type="BUY", | ||||||||||||||||||
| cid=str(uuid.uuid4()), | ||||||||||||||||||
| ), | ||||||||||||||||||
| ] | ||||||||||||||||||
|
|
||||||||||||||||||
| spot_orders_to_create = [ | ||||||||||||||||||
| composer.spot_order( | ||||||||||||||||||
| market_id=spot_market_id_create, | ||||||||||||||||||
|
|
@@ -125,13 +140,27 @@ async def main() -> None: | |||||||||||||||||
| ), | ||||||||||||||||||
| ] | ||||||||||||||||||
|
|
||||||||||||||||||
| spot_market_orders_to_create = [ | ||||||||||||||||||
| composer.spot_order( | ||||||||||||||||||
| market_id=spot_market_id_create, | ||||||||||||||||||
| subaccount_id=subaccount_id, | ||||||||||||||||||
| fee_recipient=fee_recipient, | ||||||||||||||||||
| price=Decimal("3.5"), | ||||||||||||||||||
| quantity=Decimal("1"), | ||||||||||||||||||
| order_type="BUY", | ||||||||||||||||||
| cid=str(uuid.uuid4()), | ||||||||||||||||||
| ), | ||||||||||||||||||
| ] | ||||||||||||||||||
|
|
||||||||||||||||||
| # prepare tx msg | ||||||||||||||||||
| msg = composer.msg_batch_update_orders( | ||||||||||||||||||
| sender=address.to_acc_bech32(), | ||||||||||||||||||
| derivative_orders_to_create=derivative_orders_to_create, | ||||||||||||||||||
| spot_orders_to_create=spot_orders_to_create, | ||||||||||||||||||
| derivative_orders_to_cancel=derivative_orders_to_cancel, | ||||||||||||||||||
| spot_orders_to_cancel=spot_orders_to_cancel, | ||||||||||||||||||
| spot_market_orders_to_create=spot_market_orders_to_create, | ||||||||||||||||||
| derivative_market_orders_to_create=derivative_market_orders_to_create, | ||||||||||||||||||
| ) | ||||||||||||||||||
|
|
||||||||||||||||||
| # broadcast the transaction | ||||||||||||||||||
|
|
||||||||||||||||||
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,24 @@ | ||||||||||||||
| import asyncio | ||||||||||||||
| import json | ||||||||||||||
|
|
||||||||||||||
| from pyinjective.async_client_v2 import AsyncClient | ||||||||||||||
| from pyinjective.core.network import Network | ||||||||||||||
|
|
||||||||||||||
|
|
||||||||||||||
| async def main() -> None: | ||||||||||||||
| """ | ||||||||||||||
| Demonstrate fetching denom min notionals using AsyncClient. | ||||||||||||||
| """ | ||||||||||||||
|
Comment on lines
+9
to
+11
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fix example docstring to match behavior. - """
- Demonstrate fetching denom min notionals using AsyncClient.
- """
+ """
+ Demonstrate fetching open interest using AsyncClient.
+ """📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||
| # Select network: choose between Network.mainnet(), Network.testnet(), or Network.devnet() | ||||||||||||||
| network = Network.testnet() | ||||||||||||||
|
|
||||||||||||||
| # Initialize the Async Client | ||||||||||||||
| client = AsyncClient(network) | ||||||||||||||
|
|
||||||||||||||
| market_id = "0x17ef48032cb24375ba7c2e39f384e56433bcab20cbee9a7357e4cba2eb00abe6" | ||||||||||||||
| open_interest = await client.fetch_open_interest(market_id=market_id) | ||||||||||||||
| print(json.dumps(open_interest, indent=2)) | ||||||||||||||
|
|
||||||||||||||
|
|
||||||||||||||
| if __name__ == "__main__": | ||||||||||||||
| asyncio.get_event_loop().run_until_complete(main()) | ||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
Verify that cleanup consolidation doesn't break the build workflow.
The removal of cosmos-sdk, ibc-go, cometbft, wasmd, and injective-core from
clean_reposappears intentional, given thatclone-allnow only clonesinjective-indexer. However, confirm that:buf.gen.yamldoes not reference the removed repos🏁 Script executed:
Length of output: 618
I found a critical inconsistency. Let me verify the build process to confirm the impact.
Now let me verify how the build process uses buf.gen.yaml:
Let me search the Makefile for how proto generation is invoked:These results don't show how the specific repository uses buf.gen.yaml in the Makefile. Let me search the Makefile more directly for the actual proto target:
[/run_scripts]
🏁 Script executed:
Length of output: 2412
buf.gen.yaml still references removed repositories—this will break the build.
The Makefile cleanup removes cloning of
cosmos-sdk,ibc-go,cometbft, andwasmd, butbuf.gen.yaml(line 7, invoked viabuf generate --template buf.gen.yaml) still contains activegit_repoentries for these same repositories:https://github.com/InjectiveLabs/ibc-gohttps://github.com/InjectiveLabs/wasmdhttps://github.com/InjectiveLabs/cometbfthttps://github.com/InjectiveLabs/cosmos-sdkAdditionally,
PROTO_MODULES(line 12) still references modules corresponding to these removed repos (cometbft,ibc,cosmos,tendermint).Either:
buf.gen.yamlto remove thegit_repoentries for these repositories, ORinjective-indexerv1.17.0-beta bundles all necessary proto files and updatebuf.gen.yamlaccordingly🤖 Prompt for AI Agents