diff --git a/CHANGELOG.md b/CHANGELOG.md index cffd2e07..4f14ce55 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ All notable changes to this project will be documented in this file. +## [1.6.3] +### Fixed +- Updated reference gas cost for messages in the gas limit estimator after chain upgrade v1.13 + ## [1.6.2] ### Fixed - Fixed issue in the `listen_derivative_market_updates` method in the `AsyncClient` class diff --git a/pyinjective/core/gas_limit_estimator.py b/pyinjective/core/gas_limit_estimator.py index fd99a0cd..335af501 100644 --- a/pyinjective/core/gas_limit_estimator.py +++ b/pyinjective/core/gas_limit_estimator.py @@ -12,17 +12,17 @@ tx_pb2 as injective_exchange_tx_pb, ) -SPOT_ORDER_CREATION_GAS_LIMIT = 50_000 -DERIVATIVE_ORDER_CREATION_GAS_LIMIT = 70_000 +SPOT_ORDER_CREATION_GAS_LIMIT = 52_000 +DERIVATIVE_ORDER_CREATION_GAS_LIMIT = 84_000 SPOT_ORDER_CANCELATION_GAS_LIMIT = 50_000 -DERIVATIVE_ORDER_CANCELATION_GAS_LIMIT = 60_000 +DERIVATIVE_ORDER_CANCELATION_GAS_LIMIT = 68_000 # POST ONLY orders take around 50% more gas to create than normal orders due to the required validations -SPOT_POST_ONLY_ORDER_MULTIPLIER = 0.5 -DERIVATIVE_POST_ONLY_ORDER_MULTIPLIER = 0.5 +SPOT_POST_ONLY_ORDER_MULTIPLIER = 0.62 +DERIVATIVE_POST_ONLY_ORDER_MULTIPLIER = 0.35 class GasLimitEstimator(ABC): - GENERAL_MESSAGE_GAS_LIMIT = 15_000 + GENERAL_MESSAGE_GAS_LIMIT = 25_000 BASIC_REFERENCE_GAS_LIMIT = 150_000 @classmethod @@ -183,7 +183,7 @@ def _message_class(self, message: any_pb2.Any): class BatchUpdateOrdersGasLimitEstimator(GasLimitEstimator): CANCEL_ALL_SPOT_MARKET_GAS_LIMIT = 40_000 CANCEL_ALL_DERIVATIVE_MARKET_GAS_LIMIT = 50_000 - MESSAGE_GAS_LIMIT = 15_000 + MESSAGE_GAS_LIMIT = 30_000 AVERAGE_CANCEL_ALL_AFFECTED_ORDERS = 20 @@ -246,7 +246,7 @@ def _message_class(self, message: any_pb2.Any): class ExecGasLimitEstimator(GasLimitEstimator): - DEFAULT_GAS_LIMIT = 8_000 + DEFAULT_GAS_LIMIT = 20_000 def __init__(self, message: any_pb2.Any): self._message = self._parsed_message(message=message) diff --git a/pyproject.toml b/pyproject.toml index 0a96dbaa..36aab95b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "injective-py" -version = "1.6.2" +version = "1.6.3" description = "Injective Python SDK, with Exchange API Client" authors = ["Injective Labs "] license = "Apache-2.0" diff --git a/tests/core/test_gas_limit_estimator.py b/tests/core/test_gas_limit_estimator.py index 60054430..09f50a77 100644 --- a/tests/core/test_gas_limit_estimator.py +++ b/tests/core/test_gas_limit_estimator.py @@ -1,7 +1,19 @@ from decimal import Decimal from pyinjective.composer import Composer -from pyinjective.core.gas_limit_estimator import GasLimitEstimator +from pyinjective.core.gas_limit_estimator import ( + DERIVATIVE_ORDER_CANCELATION_GAS_LIMIT, + DERIVATIVE_ORDER_CREATION_GAS_LIMIT, + SPOT_ORDER_CANCELATION_GAS_LIMIT, + SPOT_ORDER_CREATION_GAS_LIMIT, + BatchCancelDerivativeOrdersGasLimitEstimator, + BatchCancelSpotOrdersGasLimitEstimator, + BatchCreateDerivativeLimitOrdersGasLimitEstimator, + BatchCreateSpotLimitOrdersGasLimitEstimator, + BatchUpdateOrdersGasLimitEstimator, + ExecGasLimitEstimator, + GasLimitEstimator, +) from pyinjective.core.market import BinaryOptionMarket from pyinjective.proto.cosmos.gov.v1beta1 import tx_pb2 as gov_tx_pb from pyinjective.proto.cosmwasm.wasm.v1 import tx_pb2 as wasm_tx_pb @@ -44,8 +56,8 @@ def test_estimation_for_batch_create_spot_limit_orders(self): message = composer.msg_batch_create_spot_limit_orders(sender="sender", orders=orders) estimator = GasLimitEstimator.for_message(message=message) - expected_order_gas_limit = 50000 - expected_message_gas_limit = 15000 + expected_order_gas_limit = SPOT_ORDER_CREATION_GAS_LIMIT + expected_message_gas_limit = BatchCreateSpotLimitOrdersGasLimitEstimator.GENERAL_MESSAGE_GAS_LIMIT assert (expected_order_gas_limit * 2) + expected_message_gas_limit == estimator.gas_limit() @@ -72,8 +84,8 @@ def test_estimation_for_batch_cancel_spot_orders(self): message = composer.msg_batch_cancel_spot_orders(sender="sender", orders_data=orders) estimator = GasLimitEstimator.for_message(message=message) - expected_order_gas_limit = 50000 - expected_message_gas_limit = 15000 + expected_order_gas_limit = SPOT_ORDER_CANCELATION_GAS_LIMIT + expected_message_gas_limit = BatchCancelSpotOrdersGasLimitEstimator.GENERAL_MESSAGE_GAS_LIMIT assert (expected_order_gas_limit * 3) + expected_message_gas_limit == estimator.gas_limit() @@ -103,8 +115,8 @@ def test_estimation_for_batch_create_derivative_limit_orders(self): message = composer.msg_batch_create_derivative_limit_orders(sender="sender", orders=orders) estimator = GasLimitEstimator.for_message(message=message) - expected_order_gas_limit = 70_000 - expected_message_gas_limit = 15000 + expected_order_gas_limit = DERIVATIVE_ORDER_CREATION_GAS_LIMIT + expected_message_gas_limit = BatchCreateDerivativeLimitOrdersGasLimitEstimator.GENERAL_MESSAGE_GAS_LIMIT assert (expected_order_gas_limit * 2) + expected_message_gas_limit == estimator.gas_limit() @@ -131,8 +143,8 @@ def test_estimation_for_batch_cancel_derivative_orders(self): message = composer.msg_batch_cancel_derivative_orders(sender="sender", orders_data=orders) estimator = GasLimitEstimator.for_message(message=message) - expected_order_gas_limit = 60_000 - expected_message_gas_limit = 15000 + expected_order_gas_limit = DERIVATIVE_ORDER_CANCELATION_GAS_LIMIT + expected_message_gas_limit = BatchCancelDerivativeOrdersGasLimitEstimator.GENERAL_MESSAGE_GAS_LIMIT assert (expected_order_gas_limit * 3) + expected_message_gas_limit == estimator.gas_limit() @@ -166,8 +178,8 @@ def test_estimation_for_batch_update_orders_to_create_spot_orders(self): ) estimator = GasLimitEstimator.for_message(message=message) - expected_order_gas_limit = 50_000 - expected_message_gas_limit = 15_000 + expected_order_gas_limit = SPOT_ORDER_CREATION_GAS_LIMIT + expected_message_gas_limit = BatchUpdateOrdersGasLimitEstimator.MESSAGE_GAS_LIMIT assert (expected_order_gas_limit * 2) + expected_message_gas_limit == estimator.gas_limit() @@ -203,8 +215,8 @@ def test_estimation_for_batch_update_orders_to_create_derivative_orders(self): ) estimator = GasLimitEstimator.for_message(message=message) - expected_order_gas_limit = 70_000 - expected_message_gas_limit = 15_000 + expected_order_gas_limit = DERIVATIVE_ORDER_CREATION_GAS_LIMIT + expected_message_gas_limit = BatchUpdateOrdersGasLimitEstimator.MESSAGE_GAS_LIMIT assert (expected_order_gas_limit * 2) + expected_message_gas_limit == estimator.gas_limit() @@ -260,8 +272,8 @@ def test_estimation_for_batch_update_orders_to_create_binary_orders(self, usdt_t ) estimator = GasLimitEstimator.for_message(message=message) - expected_order_gas_limit = 70_000 - expected_message_gas_limit = 15_000 + expected_order_gas_limit = DERIVATIVE_ORDER_CREATION_GAS_LIMIT + expected_message_gas_limit = BatchUpdateOrdersGasLimitEstimator.MESSAGE_GAS_LIMIT assert (expected_order_gas_limit * 2) + expected_message_gas_limit == estimator.gas_limit() @@ -294,8 +306,8 @@ def test_estimation_for_batch_update_orders_to_cancel_spot_orders(self): ) estimator = GasLimitEstimator.for_message(message=message) - expected_order_gas_limit = 50_000 - expected_message_gas_limit = 15_000 + expected_order_gas_limit = SPOT_ORDER_CANCELATION_GAS_LIMIT + expected_message_gas_limit = BatchUpdateOrdersGasLimitEstimator.MESSAGE_GAS_LIMIT assert (expected_order_gas_limit * 3) + expected_message_gas_limit == estimator.gas_limit() @@ -328,8 +340,8 @@ def test_estimation_for_batch_update_orders_to_cancel_derivative_orders(self): ) estimator = GasLimitEstimator.for_message(message=message) - expected_order_gas_limit = 60_000 - expected_message_gas_limit = 15_000 + expected_order_gas_limit = DERIVATIVE_ORDER_CANCELATION_GAS_LIMIT + expected_message_gas_limit = BatchUpdateOrdersGasLimitEstimator.MESSAGE_GAS_LIMIT assert (expected_order_gas_limit * 3) + expected_message_gas_limit == estimator.gas_limit() @@ -363,8 +375,8 @@ def test_estimation_for_batch_update_orders_to_cancel_binary_orders(self): ) estimator = GasLimitEstimator.for_message(message=message) - expected_order_gas_limit = 60_000 - expected_message_gas_limit = 15_000 + expected_order_gas_limit = DERIVATIVE_ORDER_CANCELATION_GAS_LIMIT + expected_message_gas_limit = BatchUpdateOrdersGasLimitEstimator.MESSAGE_GAS_LIMIT assert (expected_order_gas_limit * 3) + expected_message_gas_limit == estimator.gas_limit() @@ -383,8 +395,8 @@ def test_estimation_for_batch_update_orders_to_cancel_all_for_spot_market(self): ) estimator = GasLimitEstimator.for_message(message=message) - expected_gas_limit = 40_000 * 20 - expected_message_gas_limit = 15_000 + expected_gas_limit = BatchUpdateOrdersGasLimitEstimator.CANCEL_ALL_SPOT_MARKET_GAS_LIMIT * 20 + expected_message_gas_limit = BatchUpdateOrdersGasLimitEstimator.MESSAGE_GAS_LIMIT assert expected_gas_limit + expected_message_gas_limit == estimator.gas_limit() @@ -403,8 +415,8 @@ def test_estimation_for_batch_update_orders_to_cancel_all_for_derivative_market( ) estimator = GasLimitEstimator.for_message(message=message) - expected_gas_limit = 50_000 * 20 - expected_message_gas_limit = 15_000 + expected_gas_limit = BatchUpdateOrdersGasLimitEstimator.CANCEL_ALL_DERIVATIVE_MARKET_GAS_LIMIT * 20 + expected_message_gas_limit = BatchUpdateOrdersGasLimitEstimator.MESSAGE_GAS_LIMIT assert expected_gas_limit + expected_message_gas_limit == estimator.gas_limit() @@ -423,8 +435,8 @@ def test_estimation_for_batch_update_orders_to_cancel_all_for_binary_options_mar ) estimator = GasLimitEstimator.for_message(message=message) - expected_gas_limit = 50_000 * 20 - expected_message_gas_limit = 15_000 + expected_gas_limit = BatchUpdateOrdersGasLimitEstimator.CANCEL_ALL_DERIVATIVE_MARKET_GAS_LIMIT * 20 + expected_message_gas_limit = BatchUpdateOrdersGasLimitEstimator.MESSAGE_GAS_LIMIT assert expected_gas_limit + expected_message_gas_limit == estimator.gas_limit() @@ -452,9 +464,9 @@ def test_estimation_for_exec_message(self): estimator = GasLimitEstimator.for_message(message=message) - expected_order_gas_limit = 50_000 - expected_inner_message_gas_limit = 15_000 - expected_exec_message_gas_limit = 8_000 + expected_order_gas_limit = SPOT_ORDER_CREATION_GAS_LIMIT + expected_inner_message_gas_limit = BatchUpdateOrdersGasLimitEstimator.MESSAGE_GAS_LIMIT + expected_exec_message_gas_limit = ExecGasLimitEstimator.DEFAULT_GAS_LIMIT assert ( expected_order_gas_limit + expected_inner_message_gas_limit + expected_exec_message_gas_limit diff --git a/tests/core/test_message_based_transaction_fee_calculator.py b/tests/core/test_message_based_transaction_fee_calculator.py index b1d774e0..5c26f06c 100644 --- a/tests/core/test_message_based_transaction_fee_calculator.py +++ b/tests/core/test_message_based_transaction_fee_calculator.py @@ -7,6 +7,12 @@ from pyinjective.async_client import AsyncClient from pyinjective.composer import Composer from pyinjective.core.broadcaster import MessageBasedTransactionFeeCalculator +from pyinjective.core.gas_limit_estimator import ( + DefaultGasLimitEstimator, + ExecGasLimitEstimator, + GenericExchangeGasLimitEstimator, + PrivilegedExecuteContractGasLimitEstimator, +) from pyinjective.core.network import Network from pyinjective.proto.cosmos.gov.v1beta1 import tx_pb2 as gov_tx_pb2 from pyinjective.proto.cosmwasm.wasm.v1 import tx_pb2 as wasm_tx_pb2 @@ -31,8 +37,10 @@ async def test_gas_fee_for_privileged_execute_contract_message(self): await calculator.configure_gas_fee_for_transaction(transaction=transaction, private_key=None, public_key=None) - expected_transaction_gas_limit = 60_000 - expected_gas_limit = math.ceil(Decimal(6) * 150_000 + expected_transaction_gas_limit) + expected_transaction_gas_limit = MessageBasedTransactionFeeCalculator.TRANSACTION_GAS_LIMIT + expected_gas_limit = math.ceil( + PrivilegedExecuteContractGasLimitEstimator.BASIC_REFERENCE_GAS_LIMIT * 6 + expected_transaction_gas_limit + ) assert expected_gas_limit == transaction.fee.gas_limit assert str(expected_gas_limit * 5_000_000) == transaction.fee.amount[0].amount @@ -57,7 +65,7 @@ async def test_gas_fee_for_execute_contract_message(self): await calculator.configure_gas_fee_for_transaction(transaction=transaction, private_key=None, public_key=None) - expected_transaction_gas_limit = 60_000 + expected_transaction_gas_limit = MessageBasedTransactionFeeCalculator.TRANSACTION_GAS_LIMIT expected_gas_limit = math.ceil(Decimal(2.5) * 150_000 + expected_transaction_gas_limit) assert expected_gas_limit == transaction.fee.gas_limit assert str(expected_gas_limit * 5_000_000) == transaction.fee.amount[0].amount @@ -79,7 +87,7 @@ async def test_gas_fee_for_wasm_message(self): await calculator.configure_gas_fee_for_transaction(transaction=transaction, private_key=None, public_key=None) - expected_transaction_gas_limit = 60_000 + expected_transaction_gas_limit = MessageBasedTransactionFeeCalculator.TRANSACTION_GAS_LIMIT expected_gas_limit = math.ceil(Decimal(1.5) * 150_000 + expected_transaction_gas_limit) assert expected_gas_limit == transaction.fee.gas_limit assert str(expected_gas_limit * 5_000_000) == transaction.fee.amount[0].amount @@ -101,7 +109,7 @@ async def test_gas_fee_for_governance_message(self): await calculator.configure_gas_fee_for_transaction(transaction=transaction, private_key=None, public_key=None) - expected_transaction_gas_limit = 60_000 + expected_transaction_gas_limit = MessageBasedTransactionFeeCalculator.TRANSACTION_GAS_LIMIT expected_gas_limit = math.ceil(Decimal(15) * 150_000 + expected_transaction_gas_limit) assert expected_gas_limit == transaction.fee.gas_limit assert str(expected_gas_limit * 5_000_000) == transaction.fee.amount[0].amount @@ -131,7 +139,7 @@ async def test_gas_fee_for_exchange_message(self): await calculator.configure_gas_fee_for_transaction(transaction=transaction, private_key=None, public_key=None) - expected_transaction_gas_limit = 60_000 + expected_transaction_gas_limit = MessageBasedTransactionFeeCalculator.TRANSACTION_GAS_LIMIT expected_gas_limit = math.ceil(Decimal(1) * 120_000 + expected_transaction_gas_limit) assert expected_gas_limit == transaction.fee.gas_limit assert str(expected_gas_limit * 5_000_000) == transaction.fee.amount[0].amount @@ -162,9 +170,9 @@ async def test_gas_fee_for_msg_exec_message(self): await calculator.configure_gas_fee_for_transaction(transaction=transaction, private_key=None, public_key=None) - expected_transaction_gas_limit = 60_000 - expected_inner_message_gas_limit = Decimal(1) * 120_000 - expected_exec_message_gas_limit = 8_000 + expected_transaction_gas_limit = MessageBasedTransactionFeeCalculator.TRANSACTION_GAS_LIMIT + expected_inner_message_gas_limit = GenericExchangeGasLimitEstimator.BASIC_REFERENCE_GAS_LIMIT + expected_exec_message_gas_limit = ExecGasLimitEstimator.DEFAULT_GAS_LIMIT expected_gas_limit = math.ceil( expected_exec_message_gas_limit + expected_inner_message_gas_limit + expected_transaction_gas_limit ) @@ -200,10 +208,10 @@ async def test_gas_fee_for_two_messages_in_one_transaction(self): await calculator.configure_gas_fee_for_transaction(transaction=transaction, private_key=None, public_key=None) - expected_transaction_gas_limit = 60_000 - expected_inner_message_gas_limit = Decimal(1) * 120_000 - expected_exec_message_gas_limit = 8_000 - expected_send_message_gas_limit = 150_000 + expected_transaction_gas_limit = MessageBasedTransactionFeeCalculator.TRANSACTION_GAS_LIMIT + expected_inner_message_gas_limit = GenericExchangeGasLimitEstimator.BASIC_REFERENCE_GAS_LIMIT + expected_exec_message_gas_limit = ExecGasLimitEstimator.DEFAULT_GAS_LIMIT + expected_send_message_gas_limit = DefaultGasLimitEstimator.DEFAULT_GAS_LIMIT expected_gas_limit = math.ceil( expected_exec_message_gas_limit + expected_inner_message_gas_limit