Skip to content

Cp 235/update gas estimator for fixed exchange gas #375

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

Merged
merged 17 commits into from
Apr 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
68759f3
feat: updated changelog and version number for v1.9.0 release
aarmoa Feb 13, 2025
b09a7a0
Merge pull request #371 from InjectiveLabs/feat/release_v1_9_0
aarmoa Feb 13, 2025
65ce48e
fix: updated the oracle stream prices script to send the oracle type …
aarmoa Feb 17, 2025
a9b3c79
Merge pull request #372 from InjectiveLabs/fix/fix_stream_prices_exam…
aarmoa Feb 17, 2025
7074685
fix: added quantization in the functions that convert notional values…
aarmoa Mar 3, 2025
0416c2a
Merge pull request #374 from InjectiveLabs/fix/add_notional_quantization
aarmoa Mar 3, 2025
a054d14
cp-235: updated the gas limit estimator logic to reflect the new logi…
aarmoa Mar 17, 2025
41dda82
cp-235: updated all proto definitions with the candidate indexer and …
aarmoa Mar 17, 2025
fd60afc
Merge branch 'master' of https://github.com/InjectiveLabs/sdk-python …
aarmoa Mar 17, 2025
45b98d2
feat: added a new message based fee calculator supporting the Exchang…
aarmoa Mar 24, 2025
f675e2a
fix: fix broadcaster creation example scripts
aarmoa Mar 24, 2025
02165b5
fix: pointed to the correct injective-core branch for the proto gener…
aarmoa Mar 25, 2025
1418b58
fix: updated gas heuristics per message gas cost to sync with latest …
aarmoa Apr 3, 2025
14909ae
fix: added cleanup code in AsyncClient for the object destruction phase
aarmoa Apr 4, 2025
9f2062c
feat: updated proto definitions for chain v1.15 upgrade and Indexer v…
aarmoa Apr 7, 2025
25b01df
feat: made the gas calculator using gas heuristics the default one fo…
aarmoa Apr 8, 2025
104d176
fix: fixed gas calculation using heuristics to not duplicate the requ…
aarmoa Apr 8, 2025
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
10 changes: 9 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,15 @@

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

## [1.9.0] - 9999-99-99
## [1.10.0] - 9999-99-99
### Changed
- Update in the implementation of the gas limit estimator to use the same values as the chain for the fixed gas messages

## [1.9.1] - 2025-03-03
### Fixed
- Added quantization in the functions that convert notional values to chain format

## [1.9.0] - 2025-02-13
### Added
- Added support for all new queries and messages from the new Permissions module

Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ clean-all:
$(call clean_repos)

clone-injective-indexer:
git clone https://github.com/InjectiveLabs/injective-indexer.git -b v1.13.117_RC1 --depth 1 --single-branch
git clone https://github.com/InjectiveLabs/injective-indexer.git -b v1.14.48 --depth 1 --single-branch

clone-all: clone-injective-indexer

Expand Down
14 changes: 7 additions & 7 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.9-inj-2
tag: v0.50.9-inj-4
- git_repo: https://github.com/InjectiveLabs/ibc-go
tag: v8.3.2-inj-0
tag: v8.6.1-inj
- git_repo: https://github.com/InjectiveLabs/wasmd
tag: v0.53.2-inj-1
tag: v0.53.2-inj.2
# - 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: testnet
tag: v1.15.0-beta.2
subdir: proto
# - git_repo: https://github.com/InjectiveLabs/injective-core
# branch: release/v1.15.x
# subdir: proto
- directory: proto
20 changes: 16 additions & 4 deletions examples/chain_client/1_LocalOrderHash.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import dotenv

from pyinjective.async_client import AsyncClient
from pyinjective.constant import GAS_FEE_BUFFER_AMOUNT, GAS_PRICE
from pyinjective.constant import GAS_FEE_BUFFER_AMOUNT
from pyinjective.core.network import Network
from pyinjective.orderhash import OrderHashManager
from pyinjective.transaction import Transaction
Expand Down Expand Up @@ -111,7 +111,11 @@ async def main() -> None:
.with_account_num(client.get_number())
.with_chain_id(network.chain_id)
)
gas_price = GAS_PRICE

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)

base_gas = 85000
gas_limit = base_gas + GAS_FEE_BUFFER_AMOUNT # add buffer for gas fee computation
gas_fee = "{:.18f}".format((gas_price * gas_limit) / pow(10, 18)).rstrip("0")
Expand Down Expand Up @@ -148,7 +152,11 @@ async def main() -> None:
.with_account_num(client.get_number())
.with_chain_id(network.chain_id)
)
gas_price = GAS_PRICE

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)

base_gas = 85000
gas_limit = base_gas + GAS_FEE_BUFFER_AMOUNT # add buffer for gas fee computation
gas_fee = "{:.18f}".format((gas_price * gas_limit) / pow(10, 18)).rstrip("0")
Expand Down Expand Up @@ -240,7 +248,11 @@ async def main() -> None:
.with_account_num(client.get_number())
.with_chain_id(network.chain_id)
)
gas_price = GAS_PRICE

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)

base_gas = 85000
gas_limit = base_gas + GAS_FEE_BUFFER_AMOUNT # add buffer for gas fee computation
gas_fee = "{:.18f}".format((gas_price * gas_limit) / pow(10, 18)).rstrip("0")
Expand Down
21 changes: 18 additions & 3 deletions examples/chain_client/3_MessageBroadcaster.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import asyncio
import json
import os
import uuid
from decimal import Decimal

import dotenv

from pyinjective.composer import Composer as ProtoMsgComposer
from pyinjective.async_client import AsyncClient
from pyinjective.core.broadcaster import MsgBroadcasterWithPk
from pyinjective.core.network import Network
from pyinjective.wallet import PrivateKey
Expand All @@ -17,11 +18,20 @@ async def main() -> None:

# select network: local, testnet, mainnet
network = Network.testnet()
composer = ProtoMsgComposer(network=network.string())

client = AsyncClient(network)
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=private_key_in_hexa,
gas_price=gas_price,
client=client,
composer=composer,
)

priv_key = PrivateKey.from_hex(private_key_in_hexa)
Expand Down Expand Up @@ -64,7 +74,12 @@ async def main() -> None:
# broadcast the transaction
result = await message_broadcaster.broadcast([msg])
print("---Transaction Response---")
print(result)
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__":
Expand Down
18 changes: 15 additions & 3 deletions examples/chain_client/4_MessageBroadcasterWithGranteeAccount.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import asyncio
import json
import os
import uuid
from decimal import Decimal

import dotenv

from pyinjective.async_client import AsyncClient
from pyinjective.composer import Composer as ProtoMsgComposer
from pyinjective.core.broadcaster import MsgBroadcasterWithPk
from pyinjective.core.network import Network
from pyinjective.wallet import Address, PrivateKey
Expand All @@ -19,20 +19,27 @@ async def main() -> None:

# select network: local, testnet, mainnet
network = Network.testnet()
composer = ProtoMsgComposer(network=network.string())

# initialize grpc client
client = AsyncClient(network)
composer = await client.composer()
await client.sync_timeout_height()

# load account
priv_key = PrivateKey.from_hex(private_key_in_hexa)
pub_key = priv_key.to_public_key()
address = pub_key.to_address()

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_for_grantee_account_using_simulation(
network=network,
grantee_private_key=private_key_in_hexa,
gas_price=gas_price,
client=client,
composer=composer,
)

# prepare tx msg
Expand All @@ -55,7 +62,12 @@ async def main() -> None:
# broadcast the transaction
result = await message_broadcaster.broadcast([msg])
print("---Transaction Response---")
print(result)
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__":
Expand Down
22 changes: 19 additions & 3 deletions examples/chain_client/5_MessageBroadcasterWithoutSimulation.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import asyncio
import json
import os
import uuid
from decimal import Decimal

import dotenv

from pyinjective.composer import Composer as ProtoMsgComposer
from pyinjective.async_client import AsyncClient
from pyinjective.core.broadcaster import MsgBroadcasterWithPk
from pyinjective.core.network import Network
from pyinjective.wallet import PrivateKey
Expand All @@ -17,11 +18,21 @@ async def main() -> None:

# select network: local, testnet, mainnet
network = Network.testnet()
composer = ProtoMsgComposer(network=network.string())

client = AsyncClient(network)
composer = await client.composer()
await client.sync_timeout_height()

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_without_simulation(
network=network,
private_key=private_key_in_hexa,
gas_price=gas_price,
client=client,
composer=composer,
)

priv_key = PrivateKey.from_hex(private_key_in_hexa)
Expand Down Expand Up @@ -64,7 +75,12 @@ async def main() -> None:
# broadcast the transaction
result = await message_broadcaster.broadcast([msg])
print("---Transaction Response---")
print(result)
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__":
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import asyncio
import json
import os
import uuid
from decimal import Decimal

import dotenv

from pyinjective.async_client import AsyncClient
from pyinjective.composer import Composer as ProtoMsgComposer
from pyinjective.core.broadcaster import MsgBroadcasterWithPk
from pyinjective.core.network import Network
from pyinjective.wallet import Address, PrivateKey
Expand All @@ -19,20 +19,26 @@ async def main() -> None:

# select network: local, testnet, mainnet
network = Network.testnet()
composer = ProtoMsgComposer(network=network.string())

# initialize grpc client
client = AsyncClient(network)
await client.sync_timeout_height()
composer = await client.composer()

# load account
priv_key = PrivateKey.from_hex(private_key_in_hexa)
pub_key = priv_key.to_public_key()
address = pub_key.to_address()

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_for_grantee_account_without_simulation(
network=network,
grantee_private_key=private_key_in_hexa,
gas_price=gas_price,
client=client,
composer=composer,
)

# prepare tx msg
Expand All @@ -54,7 +60,12 @@ async def main() -> None:
# broadcast the transaction
result = await message_broadcaster.broadcast([msg])
print("---Transaction Response---")
print(result)
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__":
Expand Down
7 changes: 5 additions & 2 deletions examples/chain_client/auction/1_MsgBid.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from grpc import RpcError

from pyinjective.async_client import AsyncClient
from pyinjective.constant import GAS_FEE_BUFFER_AMOUNT, GAS_PRICE
from pyinjective.constant import GAS_FEE_BUFFER_AMOUNT
from pyinjective.core.network import Network
from pyinjective.transaction import Transaction
from pyinjective.wallet import PrivateKey
Expand Down Expand Up @@ -52,7 +52,10 @@ async def main() -> None:
return

# build tx
gas_price = GAS_PRICE
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)

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 = [
Expand Down
7 changes: 5 additions & 2 deletions examples/chain_client/authz/1_MsgGrant.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from grpc import RpcError

from pyinjective.async_client import AsyncClient
from pyinjective.constant import GAS_FEE_BUFFER_AMOUNT, GAS_PRICE
from pyinjective.constant import GAS_FEE_BUFFER_AMOUNT
from pyinjective.core.network import Network
from pyinjective.transaction import Transaction
from pyinjective.wallet import PrivateKey
Expand Down Expand Up @@ -72,7 +72,10 @@ async def main() -> None:
return

# build tx
gas_price = GAS_PRICE
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)

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 = [
Expand Down
7 changes: 5 additions & 2 deletions examples/chain_client/authz/2_MsgExec.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from grpc import RpcError

from pyinjective.async_client import AsyncClient
from pyinjective.constant import GAS_FEE_BUFFER_AMOUNT, GAS_PRICE
from pyinjective.constant import GAS_FEE_BUFFER_AMOUNT
from pyinjective.core.network import Network
from pyinjective.transaction import Transaction
from pyinjective.wallet import Address, PrivateKey
Expand Down Expand Up @@ -79,7 +79,10 @@ async def main() -> None:
print(unpacked_msg_res)

# build tx
gas_price = GAS_PRICE
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)

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 = [
Expand Down
7 changes: 5 additions & 2 deletions examples/chain_client/authz/3_MsgRevoke.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from grpc import RpcError

from pyinjective.async_client import AsyncClient
from pyinjective.constant import GAS_FEE_BUFFER_AMOUNT, GAS_PRICE
from pyinjective.constant import GAS_FEE_BUFFER_AMOUNT
from pyinjective.core.network import Network
from pyinjective.transaction import Transaction
from pyinjective.wallet import PrivateKey
Expand Down Expand Up @@ -57,7 +57,10 @@ async def main() -> None:
return

# build tx
gas_price = GAS_PRICE
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)

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 = [
Expand Down
Loading
Loading