You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
ComposerV2 Generates Invalid Decimal Strings for Order Parameters, Causing math/big: cannot unmarshal Error on Chain #394
Description:
When creating derivative orders using ComposerV2 in pyinjective==1.11.0, the composer incorrectly formats Decimal values for price, quantity, and margin. It produces strings with decimal points (e.g., "86485364514190.08618266573839"), which are then passed into the transaction message.
However, the Injective Chain node expects these values to be marshaled as large integers (*big.Int) and cannot parse strings containing decimal points. This results in a transaction decoding failure at the node level, making it impossible to submit derivative orders using ComposerV2.
The issue lies in the _basic_derivative_order method within pyinjective/composer_v2.py. The method uses Token.convert_value_to_extended_decimal_format, which correctly scales the decimal value but does not convert it to an integer string. The subsequent f-string formatting (f"{...normalize():f}") retains the decimal point.
File: pyinjective/composer_v2.py
Method: _basic_derivative_order (lines 1823-1859)
Incorrect Code Snippet (e.g., line 1840):
This generates a string like "100000000000000.0".
In contrast, the legacy composer.py correctly uses market-specific decimal information (market.price_to_chain_format) to produce an integer string (e.g., "100000000000000"), which the chain can correctly unmarshal.
The transaction will fail with the math/big: cannot unmarshal error from the node.
I have a similar error when calculating. A good way to fix it now is to run stuff = stuff.quantize(Decimal("1e-15")) before passing it on to messages, this makes sure to avoid the .0 at the end.
Activity
peterwilli commentedon Sep 22, 2025
I have a similar error when calculating. A good way to fix it now is to run
stuff = stuff.quantize(Decimal("1e-15"))before passing it on to messages, this makes sure to avoid the .0 at the end.