Skip to content

Commit

Permalink
(fix) Configured different extra gas cost for spot and derivative pos…
Browse files Browse the repository at this point in the history
…t only orders
  • Loading branch information
abel committed Jan 24, 2024
1 parent 6eefa4c commit 53496cf
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
22 changes: 15 additions & 7 deletions pyinjective/core/gas_limit_estimator.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@
DERIVATIVE_ORDER_CREATION_GAS_LIMIT = 70_000
SPOT_ORDER_CANCELATION_GAS_LIMIT = 50_000
DERIVATIVE_ORDER_CANCELATION_GAS_LIMIT = 60_000
# POST ONLY orders take around 50% more gas to create than normal orders, due to the validations
POST_ONLY_ORDER_MULTIPLIER = 0.5
# POST ONLY orders take around 60% (for spot) and 50% (for derivative) more gas to create than normal orders
# due to the required validations
SPOT_POST_ONLY_ORDER_MULTIPLIER = 0.6
DERIVATIVE_POST_ONLY_ORDER_MULTIPLIER = 0.5


class GasLimitEstimator(ABC):
Expand Down Expand Up @@ -109,7 +111,7 @@ def gas_limit(self) -> int:
total = 0
total += self.GENERAL_MESSAGE_GAS_LIMIT
total += len(self._message.orders) * SPOT_ORDER_CREATION_GAS_LIMIT
total += math.ceil(len(post_only_orders) * SPOT_ORDER_CREATION_GAS_LIMIT * POST_ONLY_ORDER_MULTIPLIER)
total += math.ceil(len(post_only_orders) * SPOT_ORDER_CREATION_GAS_LIMIT * SPOT_POST_ONLY_ORDER_MULTIPLIER)

return total

Expand Down Expand Up @@ -150,7 +152,9 @@ def gas_limit(self) -> int:
total = 0
total += self.GENERAL_MESSAGE_GAS_LIMIT
total += len(self._message.orders) * DERIVATIVE_ORDER_CREATION_GAS_LIMIT
total += math.ceil(len(post_only_orders) * DERIVATIVE_ORDER_CREATION_GAS_LIMIT * POST_ONLY_ORDER_MULTIPLIER)
total += math.ceil(
len(post_only_orders) * DERIVATIVE_ORDER_CREATION_GAS_LIMIT * DERIVATIVE_POST_ONLY_ORDER_MULTIPLIER
)

return total

Expand Down Expand Up @@ -204,12 +208,16 @@ def gas_limit(self) -> int:
total += len(self._message.derivative_orders_to_create) * DERIVATIVE_ORDER_CREATION_GAS_LIMIT
total += len(self._message.binary_options_orders_to_create) * DERIVATIVE_ORDER_CREATION_GAS_LIMIT

total += math.ceil(len(post_only_spot_orders) * SPOT_ORDER_CREATION_GAS_LIMIT * POST_ONLY_ORDER_MULTIPLIER)
total += math.ceil(len(post_only_spot_orders) * SPOT_ORDER_CREATION_GAS_LIMIT * SPOT_POST_ONLY_ORDER_MULTIPLIER)
total += math.ceil(
len(post_only_derivative_orders) * DERIVATIVE_ORDER_CREATION_GAS_LIMIT * POST_ONLY_ORDER_MULTIPLIER
len(post_only_derivative_orders)
* DERIVATIVE_ORDER_CREATION_GAS_LIMIT
* DERIVATIVE_POST_ONLY_ORDER_MULTIPLIER
)
total += math.ceil(
len(post_only_binary_options_orders) * DERIVATIVE_ORDER_CREATION_GAS_LIMIT * POST_ONLY_ORDER_MULTIPLIER
len(post_only_binary_options_orders)
* DERIVATIVE_ORDER_CREATION_GAS_LIMIT
* DERIVATIVE_POST_ONLY_ORDER_MULTIPLIER
)

total += len(self._message.spot_orders_to_cancel) * SPOT_ORDER_CANCELATION_GAS_LIMIT
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "injective-py"
version = "1.2.0-rc2"
version = "1.2.0-rc3"
description = "Injective Python SDK, with Exchange API Client"
authors = ["Injective Labs <[email protected]>"]
license = "Apache-2.0"
Expand Down

0 comments on commit 53496cf

Please sign in to comment.