Skip to content

Commit

Permalink
Merge pull request #292 from InjectiveLabs/feat/add_chain_values_conv…
Browse files Browse the repository at this point in the history
…erters

Feat/add chain values converters
  • Loading branch information
aarmoa authored Jan 16, 2024
2 parents ccffe81 + 7dc40e5 commit c389b5b
Show file tree
Hide file tree
Showing 12 changed files with 438 additions and 94 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@

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

## [1.1.0] - 2024-01-15
### Added
- Added new functions in all Market classes to convert values from extended chain format (the ones provided by chain streams) into human-readable format

### Changed
- Updated proto definitions for Indexer node using version v1.12.79.1
- Updated market and tokens INI configuration files


## [1.0.1] - 2024-01-08
### Added
- Added low level API components for all modules (chain, exchain and explorer) to make the Python SDK compatible with the TypeScript SDK.
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 @@ clone-injective-core:
git clone https://github.com/InjectiveLabs/injective-core.git -b v1.12.0 --depth 1 --single-branch

clone-injective-indexer:
git clone https://github.com/InjectiveLabs/injective-indexer.git -b v1.12.72 --depth 1 --single-branch
git clone https://github.com/InjectiveLabs/injective-indexer.git -b v1.12.79.1 --depth 1 --single-branch

clone-cometbft:
git clone https://github.com/InjectiveLabs/cometbft.git -b v0.37.2-inj --depth 1 --single-branch
Expand Down
36 changes: 36 additions & 0 deletions pyinjective/core/market.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,15 @@ def price_from_chain_format(self, chain_value: Decimal) -> Decimal:
decimals = self.base_token.decimals - self.quote_token.decimals
return chain_value * Decimal(f"1e{decimals}")

def quantity_from_extended_chain_format(self, chain_value: Decimal) -> Decimal:
return self._from_extended_chain_format(chain_value=self.quantity_from_chain_format(chain_value=chain_value))

def price_from_extended_chain_format(self, chain_value: Decimal) -> Decimal:
return self._from_extended_chain_format(chain_value=self.price_from_chain_format(chain_value=chain_value))

def _from_extended_chain_format(self, chain_value: Decimal) -> Decimal:
return chain_value / Decimal(f"1e{ADDITIONAL_CHAIN_FORMAT_DECIMALS}")


@dataclass(eq=True, frozen=True)
class DerivativeMarket:
Expand Down Expand Up @@ -107,6 +116,18 @@ def price_from_chain_format(self, chain_value: Decimal) -> Decimal:
def margin_from_chain_format(self, chain_value: Decimal) -> Decimal:
return chain_value * Decimal(f"1e-{self.quote_token.decimals}")

def quantity_from_extended_chain_format(self, chain_value: Decimal) -> Decimal:
return self._from_extended_chain_format(chain_value=self.quantity_from_chain_format(chain_value=chain_value))

def price_from_extended_chain_format(self, chain_value: Decimal) -> Decimal:
return self._from_extended_chain_format(chain_value=self.price_from_chain_format(chain_value=chain_value))

def margin_from_extended_chain_format(self, chain_value: Decimal) -> Decimal:
return self._from_extended_chain_format(chain_value=self.margin_from_chain_format(chain_value=chain_value))

def _from_extended_chain_format(self, chain_value: Decimal) -> Decimal:
return chain_value / Decimal(f"1e{ADDITIONAL_CHAIN_FORMAT_DECIMALS}")


@dataclass(eq=True, frozen=True)
class BinaryOptionMarket:
Expand Down Expand Up @@ -179,3 +200,18 @@ def quantity_from_chain_format(self, chain_value: Decimal, special_denom: Option
def price_from_chain_format(self, chain_value: Decimal, special_denom: Optional[Denom] = None) -> Decimal:
decimals = self.quote_token.decimals if special_denom is None else special_denom.quote
return chain_value * Decimal(f"1e-{decimals}")

def quantity_from_extended_chain_format(
self, chain_value: Decimal, special_denom: Optional[Denom] = None
) -> Decimal:
return self._from_extended_chain_format(
chain_value=self.quantity_from_chain_format(chain_value=chain_value, special_denom=special_denom)
)

def price_from_extended_chain_format(self, chain_value: Decimal, special_denom: Optional[Denom] = None) -> Decimal:
return self._from_extended_chain_format(
chain_value=self.price_from_chain_format(chain_value=chain_value, special_denom=special_denom)
)

def _from_extended_chain_format(self, chain_value: Decimal) -> Decimal:
return chain_value / Decimal(f"1e{ADDITIONAL_CHAIN_FORMAT_DECIMALS}")
13 changes: 13 additions & 0 deletions pyinjective/denoms_devnet.ini
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,15 @@ min_display_price_tick_size = 0.001
min_quantity_tick_size = 10000000000000
min_display_quantity_tick_size = 0.00001

[0xdf9317eac1739a23bc385e264afde5d480c0b3d2322660b5efd206071d4e70b7]
description = 'Devnet Spot NINJA/INJ'
base = 6
quote = 18
min_price_tick_size = 1000000
min_display_price_tick_size = 0.000001
min_quantity_tick_size = 10000000
min_display_quantity_tick_size = 10

[0x1422a13427d5eabd4d8de7907c8340f7e58cb15553a9fd4ad5c90406561886f9]
description = 'Devnet Derivative COMP/USDT PERP'
base = 0
Expand Down Expand Up @@ -299,6 +308,10 @@ decimals = 18
peggy_denom = peggy0x7D1AfA7B718fb893dB30A3aBc0Cfc608AaCfeBB0
decimals = 18

[NINJA]
peggy_denom = factory/inj1xtel2knkt8hmc9dnzpjz6kdmacgcfmlv5f308w/ninja
decimals = 6

[PROJ]
peggy_denom = proj
decimals = 18
Expand Down
122 changes: 74 additions & 48 deletions pyinjective/denoms_mainnet.ini
Original file line number Diff line number Diff line change
Expand Up @@ -558,12 +558,12 @@ min_display_quantity_tick_size = 1

[0x75f6a79b552dac417df219ab384be19cb13b53dec7cf512d73a965aee8bc83af]
description = 'Mainnet Spot USDY/USDT'
base = 6
base = 18
quote = 6
min_price_tick_size = 0.0000000000000001
min_display_price_tick_size = 0.0000000000000001
min_display_price_tick_size = 0.0001
min_quantity_tick_size = 100000000000000000
min_display_quantity_tick_size = 100000000000
min_display_quantity_tick_size = 0.1

[0x689ea50a30b0aeaf162e57100fefe5348a00099774f1c1ebcd90c4b480fda46a]
description = 'Mainnet Spot WHALE/USDT'
Expand All @@ -587,10 +587,10 @@ min_display_quantity_tick_size = 0.01
description = 'Mainnet Spot KIRA/INJ'
base = 6
quote = 18
min_price_tick_size = 1000000
min_display_price_tick_size = 0.000001
min_quantity_tick_size = 10000000
min_display_quantity_tick_size = 10
min_price_tick_size = 10000
min_display_price_tick_size = 0.00000001
min_quantity_tick_size = 1000000000
min_display_quantity_tick_size = 1000

[0xdf9317eac1739a23bc385e264afde5d480c0b3d2322660b5efd206071d4e70b7]
description = 'Mainnet Spot NINJA/INJ'
Expand All @@ -605,10 +605,10 @@ min_display_quantity_tick_size = 10
description = 'Mainnet Spot KATANA/INJ'
base = 6
quote = 18
min_price_tick_size = 1000000
min_display_price_tick_size = 0.000001
min_quantity_tick_size = 10000000
min_display_quantity_tick_size = 10
min_price_tick_size = 10000
min_display_price_tick_size = 0.00000001
min_quantity_tick_size = 1000000000
min_display_quantity_tick_size = 1000

[0x23983c260fc8a6627befa50cfc0374feef834dc1dc90835238c8559cc073e08f]
description = 'Mainnet Spot BRETT/INJ'
Expand All @@ -619,6 +619,15 @@ min_display_price_tick_size = 0.000001
min_quantity_tick_size = 10000000
min_display_quantity_tick_size = 10

[0x6de141d12691dd13fffcc4e3ceeb09191ff445e1f10dfbecedc63a1e365fb6cd]
description = 'Mainnet Spot ZIG/INJ'
base = 18
quote = 18
min_price_tick_size = 0.000001
min_display_price_tick_size = 0.000001
min_quantity_tick_size = 10000000000000000000
min_display_quantity_tick_size = 10

[0x02b56c5e6038f0dd795efb521718b33412126971608750538409f4b81ab5da2f]
description = 'Mainnet Spot nINJ/INJ'
base = 18
Expand All @@ -628,6 +637,42 @@ min_display_price_tick_size = 0.0001
min_quantity_tick_size = 1000000000000000
min_display_quantity_tick_size = 0.001

[0x9b13c89f8f10386b61dd3a58aae56d5c7995133534ed65ac9835bb8d54890961]
description = 'Mainnet Spot SNOWY/INJ'
base = 6
quote = 18
min_price_tick_size = 1000000
min_display_price_tick_size = 0.000001
min_quantity_tick_size = 1000000
min_display_quantity_tick_size = 1

[0xb3f38c081a1817bb0fc717bf869e93f5557c10851db4e15922e1d9d2297bd802]
description = 'Mainnet Spot AUTISM/INJ'
base = 6
quote = 18
min_price_tick_size = 1000000
min_display_price_tick_size = 0.000001
min_quantity_tick_size = 10000000
min_display_quantity_tick_size = 10

[0xd0ba680312852ffb0709446fff518e6c4d798fb70cfd2699aba3717a2517cfd5]
description = 'Mainnet Spot APP/INJ'
base = 18
quote = 6
min_price_tick_size = 0.000000000000000001
min_display_price_tick_size = 0.000001
min_quantity_tick_size = 10000000000000000000
min_display_quantity_tick_size = 10

[0x05288e393771f09c923d1189e4265b7c2646b6699f08971fd2adf0bfd4b1ce7a]
description = 'Mainnet Spot APP/INJ '
base = 18
quote = 18
min_price_tick_size = 0.000001
min_display_price_tick_size = 0.000001
min_quantity_tick_size = 10000000000000000000
min_display_quantity_tick_size = 10

[0x4ca0f92fc28be0c9761326016b5a1a2177dd6375558365116b5bdda9abc229ce]
description = 'Mainnet Derivative BTC/USDT PERP'
base = 0
Expand Down Expand Up @@ -682,15 +727,6 @@ min_display_price_tick_size = 0.001
min_quantity_tick_size = 0.01
min_display_quantity_tick_size = 0.01

[0xcf18525b53e54ad7d27477426ade06d69d8d56d2f3bf35fe5ce2ad9eb97c2fbc]
description = 'Mainnet Derivative OSMO/USDT PERP'
base = 0
quote = 6
min_price_tick_size = 1000
min_display_price_tick_size = 0.001
min_quantity_tick_size = 0.01
min_display_quantity_tick_size = 0.01

[0x06c5a306492ddc2b8dc56969766959163287ed68a6b59baa2f42330dda0aebe0]
description = 'Mainnet Derivative SOL/USDT PERP'
base = 0
Expand Down Expand Up @@ -727,24 +763,6 @@ min_display_price_tick_size = 0.0001
min_quantity_tick_size = 1
min_display_quantity_tick_size = 1

[0x332230109e7afb839b4750d4cf961666b608071ecb64dac55662dac37529639e]
description = 'Mainnet Derivative BTC/USDTkv PERP'
base = 0
quote = 6
min_price_tick_size = 1000000
min_display_price_tick_size = 1
min_quantity_tick_size = 0.0001
min_display_quantity_tick_size = 0.0001

[0xca3682d053e8c804ea9cd322cfc0476d9016b99210fe42774a61b06e8868fef3]
description = 'Mainnet Derivative ETH/USDTkv PERP'
base = 0
quote = 6
min_price_tick_size = 100000
min_display_price_tick_size = 0.1
min_quantity_tick_size = 0.0001
min_display_quantity_tick_size = 0.0001

[0x4fe7aff4dd27be7cbb924336e7fe2d160387bb1750811cf165ce58d4c612aebb]
description = 'Mainnet Derivative AXL/USDT PERP'
base = 0
Expand Down Expand Up @@ -780,6 +798,10 @@ decimals = 18
peggy_denom = peggy0x4d224452801ACEd8B2F0aebE155379bb5D594381
decimals = 18

[APP]
peggy_denom = peggy0xC5d27F27F08D1FD1E3EbBAa50b3442e6c0D50439
decimals = 18

[ARB]
peggy_denom = factory/inj14ejqjyq8um4p3xfqj74yld5waqljf88f9eneuk/inj1d5vz0uzwlpfvgwrwulxg6syy82axa58y4fuszd
decimals = 8
Expand All @@ -788,6 +810,10 @@ decimals = 8
peggy_denom = ibc/C4CFF46FD6DE35CA4CF4CE031E643C8FDC9BA4B99AE598E9B0ED98FE3A2319F9
decimals = 6

[AUTISM]
peggy_denom = factory/inj14lf8xm6fcvlggpa7guxzjqwjmtr24gnvf56hvz/autism
decimals = 6

[AXS]
peggy_denom = peggy0xBB0E17EF65F82Ab018d8EDd776e8DD940327B28b
decimals = 18
Expand Down Expand Up @@ -853,8 +879,8 @@ peggy_denom = ibc/9A115B56E769B92621FFF90567E2D60EFD146E86E867491DB69EEDA9ADC362
decimals = 6

[LDO]
peggy_denom = factory/inj14ejqjyq8um4p3xfqj74yld5waqljf88f9eneuk/inj1q6zlut7gtkzknkk773jecujwsdkgq882akqksk
decimals = 6
peggy_denom = factory/inj14ejqjyq8um4p3xfqj74yld5waqljf88f9eneuk/inj1me6t602jlndzxgv2d7ekcnkjuqdp7vfh4txpyy
decimals = 8

[LINK]
peggy_denom = peggy0x514910771AF9Ca656af840dff83E8264EcF986CA
Expand All @@ -864,10 +890,6 @@ decimals = 18
peggy_denom = ibc/B8AF5D92165F35AB31F3FC7C7B444B9D240760FA5D406C49D24862BD0284E395
decimals = 6

[Lido DAO]
peggy_denom = factory/inj14ejqjyq8um4p3xfqj74yld5waqljf88f9eneuk/inj1me6t602jlndzxgv2d7ekcnkjuqdp7vfh4txpyy
decimals = 8

[MATIC]
peggy_denom = peggy0x7D1AfA7B718fb893dB30A3aBc0Cfc608AaCfeBB0
decimals = 18
Expand Down Expand Up @@ -896,6 +918,10 @@ decimals = 6
peggy_denom = peggy0x4a220E6096B25EADb88358cb44068A3248254675
decimals = 18

[SNOWY]
peggy_denom = factory/inj1ml33x7lkxk6x2x95d3alw4h84evlcdz2gnehmk/SNOWY
decimals = 6

[SNX]
peggy_denom = peggy0xC011a73ee8576Fb46F5E1c5751cA3B9Fe0af2a6F
decimals = 18
Expand Down Expand Up @@ -944,10 +970,6 @@ decimals = 6
peggy_denom = peggy0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48
decimals = 6

[USDCet]
peggy_denom = factory/inj14ejqjyq8um4p3xfqj74yld5waqljf88f9eneuk/inj1q6zlut7gtkzknkk773jecujwsdkgq882akqksk
decimals = 6

[USDCso]
peggy_denom = factory/inj14ejqjyq8um4p3xfqj74yld5waqljf88f9eneuk/inj12pwnhtv7yat2s30xuf4gdk9qm85v4j3e60dgvu
decimals = 6
Expand Down Expand Up @@ -992,6 +1014,10 @@ decimals = 18
peggy_denom = ibc/B786E7CBBF026F6F15A8DA248E0F18C62A0F7A70CB2DABD9239398C8B5150ABB
decimals = 6

[ZIG]
peggy_denom = peggy0xb2617246d0c6c0087f18703d576831899ca94f01
decimals = 18

[axlUSDC]
peggy_denom = ibc/7E1AF94AD246BE522892751046F0C959B768642E5671CC3742264068D49553C0
decimals = 6
Expand Down
20 changes: 4 additions & 16 deletions pyinjective/denoms_testnet.ini
Original file line number Diff line number Diff line change
Expand Up @@ -393,10 +393,6 @@ decimals = 18
peggy_denom = factory/inj17vytdwqczqz72j65saukplrktd4gyfme5agf6c/atom
decimals = 8

[Cosmos]
peggy_denom = factory/inj17vytdwqczqz72j65saukplrktd4gyfme5agf6c/atom
decimals = 8

[INJ]
peggy_denom = inj
decimals = 18
Expand All @@ -405,10 +401,6 @@ decimals = 18
peggy_denom = factory/inj17gkuet8f6pssxd8nycm3qr9d9y699rupv6397z/mitotest1
decimals = 18

[MT1]
peggy_denom = factory/inj17gkuet8f6pssxd8nycm3qr9d9y699rupv6397z/mitotest1
decimals = 18

[PROJ]
peggy_denom = factory/inj17gkuet8f6pssxd8nycm3qr9d9y699rupv6397z/proj
decimals = 18
Expand Down Expand Up @@ -441,14 +433,10 @@ decimals = 8
peggy_denom = factory/inj17gkuet8f6pssxd8nycm3qr9d9y699rupv6397z/zen
decimals = 18

[factory/inj17gkuet8f6pssxd8nycm3qr9d9y699rupv6397z/uzen]
peggy_denom = factory/inj17gkuet8f6pssxd8nycm3qr9d9y699rupv6397z/uzen
decimals = 18

[stINJ]
peggy_denom = factory/inj17gkuet8f6pssxd8nycm3qr9d9y699rupv6397z/stinj
decimals = 18

[wBTC]
peggy_denom = factory/inj17vytdwqczqz72j65saukplrktd4gyfme5agf6c/wbtc
decimals = 8

[wETH]
peggy_denom = factory/inj17vytdwqczqz72j65saukplrktd4gyfme5agf6c/weth
decimals = 8
Loading

0 comments on commit c389b5b

Please sign in to comment.