-
Notifications
You must be signed in to change notification settings - Fork 33
Feat/refactor markets tokens initialization #355
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,25 +1,7 @@ | ||
| import os | ||
| from configparser import ConfigParser | ||
|
|
||
| GAS_PRICE = 160_000_000 | ||
| GAS_FEE_BUFFER_AMOUNT = 25_000 | ||
| MAX_MEMO_CHARACTERS = 256 | ||
| ADDITIONAL_CHAIN_FORMAT_DECIMALS = 18 | ||
| TICKER_TOKENS_SEPARATOR = "/" | ||
| INJ_DENOM = "inj" | ||
| INJ_DECIMALS = 18 | ||
|
|
||
| devnet_config = ConfigParser() | ||
| devnet_config.read(os.path.join(os.path.dirname(__file__), "denoms_devnet.ini")) | ||
|
|
||
| testnet_config = ConfigParser() | ||
| testnet_config.read(os.path.join(os.path.dirname(__file__), "denoms_testnet.ini")) | ||
|
|
||
| mainnet_config = ConfigParser() | ||
| mainnet_config.read(os.path.join(os.path.dirname(__file__), "denoms_mainnet.ini")) | ||
|
|
||
| CONFIGS = { | ||
| "devnet": devnet_config, | ||
| "testnet": testnet_config, | ||
| "mainnet": mainnet_config, | ||
| } |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,6 +1,8 @@ | ||||||||||||||||||||||
| from dataclasses import dataclass | ||||||||||||||||||||||
| from decimal import Decimal | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| from pyinjective.constant import ADDITIONAL_CHAIN_FORMAT_DECIMALS | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
|
|
||||||||||||||||||||||
| @dataclass(eq=True, frozen=True) | ||||||||||||||||||||||
| class Token: | ||||||||||||||||||||||
|
|
@@ -12,5 +14,13 @@ class Token: | |||||||||||||||||||||
| logo: str | ||||||||||||||||||||||
| updated: int | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| @staticmethod | ||||||||||||||||||||||
| def convert_value_to_extended_decimal_format(value: Decimal) -> Decimal: | ||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. for me these methods names seem too long since they're commonly used across the sdk |
||||||||||||||||||||||
| return value * Decimal(f"1e{ADDITIONAL_CHAIN_FORMAT_DECIMALS}") | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| @staticmethod | ||||||||||||||||||||||
| def convert_value_from_extended_decimal_format(value: Decimal) -> Decimal: | ||||||||||||||||||||||
| return value / Decimal(f"1e{ADDITIONAL_CHAIN_FORMAT_DECIMALS}") | ||||||||||||||||||||||
|
Comment on lines
+21
to
+23
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Add documentation and optimize the implementation
@staticmethod
def convert_value_from_extended_decimal_format(value: Decimal) -> Decimal:
+ """
+ Converts a value from extended decimal format by removing additional chain format decimals.
+ This differs from chain_formatted_value which handles token-specific decimal places.
+ """
- return value / Decimal(f"1e{ADDITIONAL_CHAIN_FORMAT_DECIMALS}")
+ return value.shift(-ADDITIONAL_CHAIN_FORMAT_DECIMALS)📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||
|
|
||||||||||||||||||||||
| def chain_formatted_value(self, human_readable_value: Decimal) -> Decimal: | ||||||||||||||||||||||
| return human_readable_value * Decimal(f"1e{self.decimals}") | ||||||||||||||||||||||
Uh oh!
There was an error while loading. Please reload this page.