Skip to content

Commit

Permalink
Merge pull request #342 from InjectiveLabs/feat/sync_dec_with_master_…
Browse files Browse the repository at this point in the history
…v1_6_1

feat/sync_dec_with_master_v1_6_1
  • Loading branch information
aarmoa committed Aug 7, 2024
2 parents ea5c929 + 01ee3f9 commit 206383b
Show file tree
Hide file tree
Showing 343 changed files with 2,686 additions and 4,284 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,6 @@ jobs:
poetry run pytest --cov --cov-report=xml
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
uses: codecov/codecov-action@v4
with:
env_vars: OS,PYTHON
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@

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

## [1.6.1] - 2024-08-07
### Added
- Added support for the following messages in the chain "exchange" module:
- MsgDecreasePositionMargin
- MsgUpdateSpotMarket
- MsgUpdateDerivativeMarket
- MsgAuthorizeStakeGrants
- MsgActivateStakeGrant

## [1.6.0] - 2024-07-30
### Added
- Support for all queries in the chain "tendermint" module
Expand Down
4 changes: 2 additions & 2 deletions buf.gen.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ version: v2
managed:
enabled: true
plugins:
- remote: buf.build/protocolbuffers/python
- remote: buf.build/protocolbuffers/python:v26.1
out: ./pyinjective/proto/
- remote: buf.build/grpc/python
- remote: buf.build/grpc/python:v1.65.4
out: ./pyinjective/proto/
inputs:
- module: buf.build/cosmos/cosmos-proto
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,14 @@ async def main() -> None:
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)
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(
Expand Down
56 changes: 56 additions & 0 deletions examples/chain_client/exchange/23_MsgDecreasePositionMargin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import asyncio
import os
from decimal import Decimal

import dotenv

from pyinjective.async_client 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)
composer = await client.composer()
await client.sync_timeout_height()

message_broadcaster = MsgBroadcasterWithPk.new_using_simulation(
network=network,
private_key=configured_private_key,
)

# 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())
subaccount_id = address.get_subaccount_id(index=0)

# prepare trade info
market_id = "0x17ef48032cb24375ba7c2e39f384e56433bcab20cbee9a7357e4cba2eb00abe6"

# prepare tx msg
msg = composer.msg_decrease_position_margin(
sender=address.to_acc_bech32(),
market_id=market_id,
source_subaccount_id=subaccount_id,
destination_subaccount_id=subaccount_id,
amount=Decimal(2),
)

# broadcast the transaction
result = await message_broadcaster.broadcast([msg])
print("---Transaction Response---")
print(result)


if __name__ == "__main__":
asyncio.get_event_loop().run_until_complete(main())
54 changes: 54 additions & 0 deletions examples/chain_client/exchange/24_MsgUpdateSpotMarket.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import asyncio
import os
from decimal import Decimal

import dotenv

from pyinjective.async_client 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()
await client.sync_timeout_height()

message_broadcaster = MsgBroadcasterWithPk.new_using_simulation(
network=network,
private_key=configured_private_key,
)

# 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())

# prepare tx msg
message = composer.msg_update_spot_market(
admin=address.to_acc_bech32(),
market_id="0x215970bfdea5c94d8e964a759d3ce6eae1d113900129cc8428267db5ccdb3d1a",
new_ticker="INJ/USDC 2",
new_min_price_tick_size=Decimal("0.01"),
new_min_quantity_tick_size=Decimal("0.01"),
new_min_notional=Decimal("2"),
)

# broadcast the transaction
result = await message_broadcaster.broadcast([message])
print("---Transaction Response---")
print(result)


if __name__ == "__main__":
asyncio.get_event_loop().run_until_complete(main())
56 changes: 56 additions & 0 deletions examples/chain_client/exchange/25_MsgUpdateDerivativeMarket.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import asyncio
import os
from decimal import Decimal

import dotenv

from pyinjective.async_client 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()
await client.sync_timeout_height()

message_broadcaster = MsgBroadcasterWithPk.new_using_simulation(
network=network,
private_key=configured_private_key,
)

# 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())

# prepare tx msg
message = composer.msg_update_derivative_market(
admin=address.to_acc_bech32(),
market_id="0x17ef48032cb24375ba7c2e39f384e56433bcab20cbee9a7357e4cba2eb00abe6",
new_ticker="INJ/USDT PERP 2",
new_min_price_tick_size=Decimal("1"),
new_min_quantity_tick_size=Decimal("1"),
new_min_notional=Decimal("2"),
new_initial_margin_ratio=Decimal("0.40"),
new_maintenance_margin_ratio=Decimal("0.085"),
)

# broadcast the transaction
result = await message_broadcaster.broadcast([message])
print("---Transaction Response---")
print(result)


if __name__ == "__main__":
asyncio.get_event_loop().run_until_complete(main())
51 changes: 51 additions & 0 deletions examples/chain_client/exchange/26_MsgAuthorizeStakeGrants.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import asyncio
import os
from decimal import Decimal

import dotenv

from pyinjective.async_client 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()
await client.sync_timeout_height()

message_broadcaster = MsgBroadcasterWithPk.new_using_simulation(
network=network,
private_key=configured_private_key,
)

# 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())

# prepare tx msg
grant_authorization = composer.create_grant_authorization(
grantee="inj1hkhdaj2a2clmq5jq6mspsggqs32vynpk228q3r",
amount=Decimal("1"),
)
message = composer.msg_authorize_stake_grants(sender=address.to_acc_bech32(), grants=[grant_authorization])

# broadcast the transaction
result = await message_broadcaster.broadcast([message])
print("---Transaction Response---")
print(result)


if __name__ == "__main__":
asyncio.get_event_loop().run_until_complete(main())
48 changes: 48 additions & 0 deletions examples/chain_client/exchange/27_MsgActivateStakeGrant.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import asyncio
import os

import dotenv

from pyinjective.async_client 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()
await client.sync_timeout_height()

message_broadcaster = MsgBroadcasterWithPk.new_using_simulation(
network=network,
private_key=configured_private_key,
)

# 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())

# prepare tx msg
message = composer.msg_activate_stake_grant(
sender=address.to_acc_bech32(), granter="inj1hkhdaj2a2clmq5jq6mspsggqs32vynpk228q3r"
)

# broadcast the transaction
result = await message_broadcaster.broadcast([message])
print("---Transaction Response---")
print(result)


if __name__ == "__main__":
asyncio.get_event_loop().run_until_complete(main())
Loading

0 comments on commit 206383b

Please sign in to comment.