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/create api components #277

Merged
merged 31 commits into from
Dec 4, 2023
Merged
Show file tree
Hide file tree
Changes from 30 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
ac12ca4
(feat) Created the API component for the auction module (with the uni…
Jun 21, 2023
cf4dc61
(feat) Created the API class for the bank module (with its unit tests)
Jun 22, 2023
011b9ee
(feat) Created the API component for the auth module. Created also th…
Jun 23, 2023
a5040cd
(feat) Created the API component for the auction module (with the uni…
Jun 21, 2023
df4436d
(feat) Created the API class for the bank module (with its unit tests)
Jun 22, 2023
42c3cb4
(feat) Created the API component for the auth module. Created also th…
Jun 23, 2023
cb666b3
Merge branch 'feat/create_api_components' of https://github.com/Injec…
Oct 11, 2023
d4b51d1
(fix) Fix Network imports in tests after synchronizing the refactorin…
Oct 11, 2023
ba7c0ab
(feat) Implemented Indexer Account low level API component. Created n…
Oct 20, 2023
45a4b7e
(feat) Implemented the AuthZ low level API component
Oct 20, 2023
f49d7c5
(feat) Implemented low level API component for Transactions module. A…
Oct 24, 2023
78612f6
(fix) Update urllib3 requirement to solve dependabot issue
Oct 24, 2023
125c94b
(feat) Created Indexer Meta API components. Created new functions in …
Oct 30, 2023
58ee139
(feat) Implemented the low level API component for Indexer Oracle mod…
Oct 31, 2023
7801216
(feat) Implemented low level API components for Indexer Insurance mod…
Oct 31, 2023
bd46412
(feat) Implemented the low level API components for the Indexer Aucti…
Oct 31, 2023
e080b0f
(feat) Started implementing the Indexer Spot Exchange low level API c…
Nov 3, 2023
caaec5d
Merge branch 'dev' of https://github.com/InjectiveLabs/sdk-python int…
Nov 9, 2023
c7c1b53
(feat) Implemented request endpoints for spot exchange in the low lev…
Nov 13, 2023
675d71f
(feat) Implemented low level API for all stream endpoints of the spot…
Nov 15, 2023
d89245a
Merge branch 'fix/use_injective_forks_proto_definitions' of https://g…
Nov 15, 2023
a549e62
(feat) Added exchange derivative module gRPC requests to the low leve…
Nov 17, 2023
0edbb81
(feat) Added low level API component for exchange derivative streams.…
Nov 27, 2023
cfb507e
(feat) Added low level API components for the exchange portfolio modu…
Nov 29, 2023
25adca0
(feat) Added low level API components for the exchange explorer modu…
Dec 1, 2023
d65cb2e
(feat) Added low level API component for exchange explorer streams. A…
Dec 1, 2023
f32ec5e
(feat) Added low level API component for chain stream. Added unit tes…
Dec 2, 2023
8e2a66e
Merge branch 'dev' of https://github.com/InjectiveLabs/sdk-python int…
Dec 3, 2023
4de1701
(fix) Fixed failing deprecation warning tests
Dec 4, 2023
e72eedf
(fix) Updated coverage requirement from 50% to 65%
Dec 4, 2023
7672c35
(fix) Fixed scripts still referencing deprecated functions in AsyncCl…
Dec 4, 2023
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: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,15 @@

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

## [1.0.1] - 2023-11-07
## [1.0.1] - 2023-12-11
### Added
- Added low level API components for all modules (chain, exchain and explorer) to make the Python SDK compatible with the TypeScript SDK.

### Changed
- Updated proto definitions to injective-core v1.12.2-testnet and injective-indexer v1.12.45-rc3
- Added new functions in AsyncClient to interact with chain, exchange and explorer using the low level API components
- Marked old function sin AsyncClient as deprecated (the functions will be removed in a future version)
- Updated all API examples to use the new AsyncClient functions

## [1.0] - 2023-11-01
### Added
Expand Down
8 changes: 4 additions & 4 deletions examples/chain_client/0_LocalOrderHash.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ async def main() -> None:
priv_key = PrivateKey.from_hex("f9db9bf330e23cb7839039e944adef6e9df447b90b503d5b4464c90bea9022f3")
pub_key = priv_key.to_public_key()
address = pub_key.to_address()
await client.get_account(address.to_acc_bech32())
await client.fetch_account(address.to_acc_bech32())
subaccount_id = address.get_subaccount_id(index=0)
subaccount_id_2 = address.get_subaccount_id(index=1)

Expand Down Expand Up @@ -118,7 +118,7 @@ async def main() -> None:
tx_raw_bytes = tx.get_tx_data(sig, pub_key)

# broadcast tx: send_tx_async_mode, send_tx_sync_mode, send_tx_block_mode
res = await client.send_tx_sync_mode(tx_raw_bytes)
res = await client.broadcast_tx_sync_mode(tx_raw_bytes)
print(res)
print("gas wanted: {}".format(gas_limit))
print("gas fee: {} INJ".format(gas_fee))
Expand Down Expand Up @@ -155,7 +155,7 @@ async def main() -> None:
tx_raw_bytes = tx.get_tx_data(sig, pub_key)

# broadcast tx: send_tx_async_mode, send_tx_sync_mode, send_tx_block_mode
res = await client.send_tx_sync_mode(tx_raw_bytes)
res = await client.broadcast_tx_sync_mode(tx_raw_bytes)
print(res)
print("gas wanted: {}".format(gas_limit))
print("gas fee: {} INJ".format(gas_fee))
Expand Down Expand Up @@ -245,7 +245,7 @@ async def main() -> None:
tx_raw_bytes = tx.get_tx_data(sig, pub_key)

# broadcast tx: send_tx_async_mode, send_tx_sync_mode, send_tx_block_mode
res = await client.send_tx_sync_mode(tx_raw_bytes)
res = await client.broadcast_tx_sync_mode(tx_raw_bytes)
print(res)
print("gas wanted: {}".format(gas_limit))
print("gas fee: {} INJ".format(gas_fee))
Expand Down
15 changes: 9 additions & 6 deletions examples/chain_client/13_MsgIncreasePositionMargin.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import asyncio

from grpc import RpcError

from pyinjective.async_client import AsyncClient
from pyinjective.constant import GAS_FEE_BUFFER_AMOUNT, GAS_PRICE
from pyinjective.core.network import Network
Expand All @@ -20,7 +22,7 @@ async def main() -> None:
priv_key = PrivateKey.from_hex("f9db9bf330e23cb7839039e944adef6e9df447b90b503d5b4464c90bea9022f3")
pub_key = priv_key.to_public_key()
address = pub_key.to_address()
await client.get_account(address.to_acc_bech32())
await client.fetch_account(address.to_acc_bech32())
subaccount_id = address.get_subaccount_id(index=0)

# prepare trade info
Expand Down Expand Up @@ -48,14 +50,15 @@ async def main() -> None:
sim_tx_raw_bytes = tx.get_tx_data(sim_sig, pub_key)

# simulate tx
(sim_res, success) = await client.simulate_tx(sim_tx_raw_bytes)
if not success:
print(sim_res)
try:
sim_res = await client.simulate(sim_tx_raw_bytes)
except RpcError as ex:
print(ex)
return

# build tx
gas_price = GAS_PRICE
gas_limit = sim_res.gas_info.gas_used + GAS_FEE_BUFFER_AMOUNT # add buffer for gas fee computation
gas_limit = int(sim_res["gasInfo"]["gasUsed"]) + GAS_FEE_BUFFER_AMOUNT # add buffer for gas fee computation
gas_fee = "{:.18f}".format((gas_price * gas_limit) / pow(10, 18)).rstrip("0")
fee = [
composer.Coin(
Expand All @@ -69,7 +72,7 @@ async def main() -> None:
tx_raw_bytes = tx.get_tx_data(sig, pub_key)

# broadcast tx: send_tx_async_mode, send_tx_sync_mode, send_tx_block_mode
res = await client.send_tx_sync_mode(tx_raw_bytes)
res = await client.broadcast_tx_sync_mode(tx_raw_bytes)
print(res)
print("gas wanted: {}".format(gas_limit))
print("gas fee: {} INJ".format(gas_fee))
Expand Down
15 changes: 9 additions & 6 deletions examples/chain_client/15_MsgWithdraw.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import asyncio

from grpc import RpcError

from pyinjective.async_client import AsyncClient
from pyinjective.constant import GAS_FEE_BUFFER_AMOUNT, GAS_PRICE
from pyinjective.core.network import Network
Expand All @@ -20,7 +22,7 @@ async def main() -> None:
priv_key = PrivateKey.from_hex("f9db9bf330e23cb7839039e944adef6e9df447b90b503d5b4464c90bea9022f3")
pub_key = priv_key.to_public_key()
address = pub_key.to_address()
await client.get_account(address.to_acc_bech32())
await client.fetch_account(address.to_acc_bech32())
subaccount_id = address.get_subaccount_id(index=0)

# prepare tx msg
Expand All @@ -39,14 +41,15 @@ async def main() -> None:
sim_tx_raw_bytes = tx.get_tx_data(sim_sig, pub_key)

# simulate tx
(sim_res, success) = await client.simulate_tx(sim_tx_raw_bytes)
if not success:
print(sim_res)
try:
sim_res = await client.simulate(sim_tx_raw_bytes)
except RpcError as ex:
print(ex)
return

# build tx
gas_price = GAS_PRICE
gas_limit = sim_res.gas_info.gas_used + GAS_FEE_BUFFER_AMOUNT # add buffer for gas fee computation
gas_limit = int(sim_res["gasInfo"]["gasUsed"]) + GAS_FEE_BUFFER_AMOUNT # add buffer for gas fee computation
gas_fee = "{:.18f}".format((gas_price * gas_limit) / pow(10, 18)).rstrip("0")
fee = [
composer.Coin(
Expand All @@ -60,7 +63,7 @@ async def main() -> None:
tx_raw_bytes = tx.get_tx_data(sig, pub_key)

# broadcast tx: send_tx_async_mode, send_tx_sync_mode, send_tx_block_mode
res = await client.send_tx_sync_mode(tx_raw_bytes)
res = await client.broadcast_tx_sync_mode(tx_raw_bytes)
print(res)
print("gas wanted: {}".format(gas_limit))
print("gas fee: {} INJ".format(gas_fee))
Expand Down
15 changes: 9 additions & 6 deletions examples/chain_client/16_MsgSubaccountTransfer.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import asyncio

from grpc import RpcError

from pyinjective.async_client import AsyncClient
from pyinjective.constant import GAS_FEE_BUFFER_AMOUNT, GAS_PRICE
from pyinjective.core.network import Network
Expand All @@ -20,7 +22,7 @@ async def main() -> None:
priv_key = PrivateKey.from_hex("f9db9bf330e23cb7839039e944adef6e9df447b90b503d5b4464c90bea9022f3")
pub_key = priv_key.to_public_key()
address = pub_key.to_address()
await client.get_account(address.to_acc_bech32())
await client.fetch_account(address.to_acc_bech32())
subaccount_id = address.get_subaccount_id(index=0)
dest_subaccount_id = address.get_subaccount_id(index=1)

Expand All @@ -46,14 +48,15 @@ async def main() -> None:
sim_tx_raw_bytes = tx.get_tx_data(sim_sig, pub_key)

# simulate tx
(sim_res, success) = await client.simulate_tx(sim_tx_raw_bytes)
if not success:
print(sim_res)
try:
sim_res = await client.simulate(sim_tx_raw_bytes)
except RpcError as ex:
print(ex)
return

# build tx
gas_price = GAS_PRICE
gas_limit = sim_res.gas_info.gas_used + GAS_FEE_BUFFER_AMOUNT # add buffer for gas fee computation
gas_limit = int(sim_res["gasInfo"]["gasUsed"]) + GAS_FEE_BUFFER_AMOUNT # add buffer for gas fee computation
gas_fee = "{:.18f}".format((gas_price * gas_limit) / pow(10, 18)).rstrip("0")
fee = [
composer.Coin(
Expand All @@ -67,7 +70,7 @@ async def main() -> None:
tx_raw_bytes = tx.get_tx_data(sig, pub_key)

# broadcast tx: send_tx_async_mode, send_tx_sync_mode, send_tx_block_mode
res = await client.send_tx_sync_mode(tx_raw_bytes)
res = await client.broadcast_tx_sync_mode(tx_raw_bytes)
print(res)
print("gas wanted: {}".format(gas_limit))
print("gas fee: {} INJ".format(gas_fee))
Expand Down
17 changes: 10 additions & 7 deletions examples/chain_client/17_MsgBatchUpdateOrders.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import asyncio
import uuid

from grpc import RpcError

from pyinjective.async_client import AsyncClient
from pyinjective.constant import GAS_FEE_BUFFER_AMOUNT, GAS_PRICE
from pyinjective.core.network import Network
Expand All @@ -21,7 +23,7 @@ async def main() -> None:
priv_key = PrivateKey.from_hex("f9db9bf330e23cb7839039e944adef6e9df447b90b503d5b4464c90bea9022f3")
pub_key = priv_key.to_public_key()
address = pub_key.to_address()
await client.get_account(address.to_acc_bech32())
await client.fetch_account(address.to_acc_bech32())
subaccount_id = address.get_subaccount_id(index=0)

# prepare trade info
Expand Down Expand Up @@ -131,18 +133,19 @@ async def main() -> None:
sim_tx_raw_bytes = tx.get_tx_data(sim_sig, pub_key)

# simulate tx
(sim_res, success) = await client.simulate_tx(sim_tx_raw_bytes)
if not success:
print(sim_res)
try:
sim_res = await client.simulate(sim_tx_raw_bytes)
except RpcError as ex:
print(ex)
return

sim_res_msg = composer.MsgResponses(sim_res, simulation=True)
sim_res_msg = sim_res["result"]["msgResponses"]
print("---Simulation Response---")
print(sim_res_msg)

# build tx
gas_price = GAS_PRICE
gas_limit = sim_res.gas_info.gas_used + GAS_FEE_BUFFER_AMOUNT # add buffer for gas fee computation
gas_limit = int(sim_res["gasInfo"]["gasUsed"]) + GAS_FEE_BUFFER_AMOUNT # add buffer for gas fee computation
gas_fee = "{:.18f}".format((gas_price * gas_limit) / pow(10, 18)).rstrip("0")
fee = [
composer.Coin(
Expand All @@ -156,7 +159,7 @@ async def main() -> None:
tx_raw_bytes = tx.get_tx_data(sig, pub_key)

# broadcast tx: send_tx_async_mode, send_tx_sync_mode, send_tx_block_mode
res = await client.send_tx_sync_mode(tx_raw_bytes)
res = await client.broadcast_tx_sync_mode(tx_raw_bytes)
print("---Transaction Response---")
print(res)
print("gas wanted: {}".format(gas_limit))
Expand Down
15 changes: 9 additions & 6 deletions examples/chain_client/18_MsgBid.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import asyncio

from grpc import RpcError

from pyinjective.async_client import AsyncClient
from pyinjective.constant import GAS_FEE_BUFFER_AMOUNT, GAS_PRICE
from pyinjective.core.network import Network
Expand All @@ -20,7 +22,7 @@ async def main() -> None:
priv_key = PrivateKey.from_hex("f9db9bf330e23cb7839039e944adef6e9df447b90b503d5b4464c90bea9022f3")
pub_key = priv_key.to_public_key()
address = pub_key.to_address()
await client.get_account(address.to_acc_bech32())
await client.fetch_account(address.to_acc_bech32())

# prepare tx msg
msg = composer.MsgBid(sender=address.to_acc_bech32(), round=16250, bid_amount=1)
Expand All @@ -38,14 +40,15 @@ async def main() -> None:
sim_tx_raw_bytes = tx.get_tx_data(sim_sig, pub_key)

# simulate tx
(sim_res, success) = await client.simulate_tx(sim_tx_raw_bytes)
if not success:
print(sim_res)
try:
sim_res = await client.simulate(sim_tx_raw_bytes)
except RpcError as ex:
print(ex)
return

# build tx
gas_price = GAS_PRICE
gas_limit = sim_res.gas_info.gas_used + GAS_FEE_BUFFER_AMOUNT # add buffer for gas fee computation
gas_limit = int(sim_res["gasInfo"]["gasUsed"]) + GAS_FEE_BUFFER_AMOUNT # add buffer for gas fee computation
gas_fee = "{:.18f}".format((gas_price * gas_limit) / pow(10, 18)).rstrip("0")
fee = [
composer.Coin(
Expand All @@ -59,7 +62,7 @@ async def main() -> None:
tx_raw_bytes = tx.get_tx_data(sig, pub_key)

# broadcast tx: send_tx_async_mode, send_tx_sync_mode, send_tx_block_mode
res = await client.send_tx_sync_mode(tx_raw_bytes)
res = await client.broadcast_tx_sync_mode(tx_raw_bytes)
print(res)
print("gas wanted: {}".format(gas_limit))
print("gas fee: {} INJ".format(gas_fee))
Expand Down
15 changes: 9 additions & 6 deletions examples/chain_client/19_MsgGrant.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import asyncio

from grpc import RpcError

from pyinjective.async_client import AsyncClient
from pyinjective.constant import GAS_FEE_BUFFER_AMOUNT, GAS_PRICE
from pyinjective.core.network import Network
Expand All @@ -20,7 +22,7 @@ async def main() -> None:
priv_key = PrivateKey.from_hex("f9db9bf330e23cb7839039e944adef6e9df447b90b503d5b4464c90bea9022f3")
pub_key = priv_key.to_public_key()
address = pub_key.to_address()
await client.get_account(address.to_acc_bech32())
await client.fetch_account(address.to_acc_bech32())
# subaccount_id = address.get_subaccount_id(index=0)
# market_ids = ["0x0511ddc4e6586f3bfe1acb2dd905f8b8a82c97e1edaef654b12ca7e6031ca0fa"]

Expand Down Expand Up @@ -57,14 +59,15 @@ async def main() -> None:
sim_tx_raw_bytes = tx.get_tx_data(sim_sig, pub_key)

# simulate tx
(sim_res, success) = await client.simulate_tx(sim_tx_raw_bytes)
if not success:
print(sim_res)
try:
sim_res = await client.simulate(sim_tx_raw_bytes)
except RpcError as ex:
print(ex)
return

# build tx
gas_price = GAS_PRICE
gas_limit = sim_res.gas_info.gas_used + GAS_FEE_BUFFER_AMOUNT # add buffer for gas fee computation
gas_limit = int(sim_res["gasInfo"]["gasUsed"]) + GAS_FEE_BUFFER_AMOUNT # add buffer for gas fee computation
gas_fee = "{:.18f}".format((gas_price * gas_limit) / pow(10, 18)).rstrip("0")
fee = [
composer.Coin(
Expand All @@ -78,7 +81,7 @@ async def main() -> None:
tx_raw_bytes = tx.get_tx_data(sig, pub_key)

# broadcast tx: send_tx_async_mode, send_tx_sync_mode, send_tx_block_mode
res = await client.send_tx_sync_mode(tx_raw_bytes)
res = await client.broadcast_tx_sync_mode(tx_raw_bytes)
print(res)
print("gas wanted: {}".format(gas_limit))
print("gas fee: {} INJ".format(gas_fee))
Expand Down
15 changes: 9 additions & 6 deletions examples/chain_client/1_MsgSend.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import asyncio

from grpc import RpcError

from pyinjective.async_client import AsyncClient
from pyinjective.constant import GAS_FEE_BUFFER_AMOUNT, GAS_PRICE
from pyinjective.core.network import Network
Expand All @@ -20,7 +22,7 @@ async def main() -> None:
priv_key = PrivateKey.from_hex("f9db9bf330e23cb7839039e944adef6e9df447b90b503d5b4464c90bea9022f3")
pub_key = priv_key.to_public_key()
address = pub_key.to_address()
await client.get_account(address.to_acc_bech32())
await client.fetch_account(address.to_acc_bech32())

# prepare tx msg
msg = composer.MsgSend(
Expand All @@ -43,14 +45,15 @@ async def main() -> None:
sim_tx_raw_bytes = tx.get_tx_data(sim_sig, pub_key)

# simulate tx
(sim_res, success) = await client.simulate_tx(sim_tx_raw_bytes)
if not success:
print(sim_res)
try:
sim_res = await client.simulate(sim_tx_raw_bytes)
except RpcError as ex:
print(ex)
return

# build tx
gas_price = GAS_PRICE
gas_limit = sim_res.gas_info.gas_used + GAS_FEE_BUFFER_AMOUNT # add buffer for gas fee computation
gas_limit = int(sim_res["gasInfo"]["gasUsed"]) + GAS_FEE_BUFFER_AMOUNT # add buffer for gas fee computation
gas_fee = "{:.18f}".format((gas_price * gas_limit) / pow(10, 18)).rstrip("0")
fee = [
composer.Coin(
Expand All @@ -64,7 +67,7 @@ async def main() -> None:
tx_raw_bytes = tx.get_tx_data(sig, pub_key)

# broadcast tx: send_tx_async_mode, send_tx_sync_mode, send_tx_block_mode
res = await client.send_tx_sync_mode(tx_raw_bytes)
res = await client.broadcast_tx_sync_mode(tx_raw_bytes)
print(res)
print("gas wanted: {}".format(gas_limit))
print("gas fee: {} INJ".format(gas_fee))
Expand Down
Loading
Loading