Skip to content

Commit 870af10

Browse files
author
abel
committed
Merge branch 'master' of https://github.com/InjectiveLabs/sdk-python into feat/replace_pipenv_with_poetry
2 parents 9b8421e + c247dbe commit 870af10

File tree

12 files changed

+765
-31
lines changed

12 files changed

+765
-31
lines changed

Pipfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ protobuf = "*"
2020
requests = "*"
2121
safe-pysha3 = "*"
2222
urllib3 = "<2"
23+
web3 = ">=6.0.0"
2324
websockets = "*"
2425

2526
[dev-packages]

Pipfile.lock

Lines changed: 251 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,22 @@ make tests
8787
```
8888

8989
### Changelogs
90+
**0.9**
91+
* Replace Pipenv with Poetry
92+
* Add pre-commit validations to the project
93+
94+
**0.8.5**
95+
* Added NEOK/USDT and ORAI/USDT spot markets to the mainnet .ini file
96+
97+
**0.8.4**
98+
* Added methods to SpotMarket, DerivativeMarket and BianaryOptionMarket to translate chain prices and quantities to human-readable format.
99+
100+
**0.8.3**
101+
* Fix dependency issue in setup.py.
102+
103+
**0.8.2**
104+
* Add web3 library as a dependency for the project.
105+
90106
**0.8.1**
91107
* Moved the configuration to use a secure or insecure connection inside the Network class. The AsyncClient's `insecure` parameter is no longer used for anything and will be removed in the future.
92108
* Made the new load balanced bare-metal node the default one for mainnet (it is called `lb`). The legacy one (load balanced k8s node) is called `lb_k8s`

examples/SendToInjective.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,6 @@
55
from pyinjective.core.network import Network
66
from pyinjective.sendtocosmos import Peggo
77

8-
import importlib.resources as pkg_resources
9-
import pyinjective
10-
118

129
async def main() -> None:
1310
# select network: testnet, mainnet
@@ -30,8 +27,9 @@ async def main() -> None:
3027
'"amount": {"denom": "inj","amount": "1000000000000000000"}}'
3128
)
3229

33-
import_peggo = pkg_resources.read_text(pyinjective, 'Peggo_ABI.json')
34-
peggo_abi = json.loads(import_peggo)
30+
with open("../pyinjective/Peggo_ABI.json") as pego_file:
31+
peggo_data = pego_file.read()
32+
peggo_abi = json.loads(peggo_data)
3533

3634
peggo_composer.sendToInjective(
3735
ethereum_endpoint=ethereum_endpoint,

examples/chain_client/48_WithdrawValidatorCommission_Rewards renamed to examples/chain_client/48_WithdrawValidatorCommissionAndRewards.py

File renamed without changes.

poetry.lock

Lines changed: 330 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyinjective/core/market.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,13 @@ def price_to_chain_format(self, human_readable_value: Decimal) -> Decimal:
3434

3535
return extended_chain_formatted_value
3636

37+
def quantity_from_chain_format(self, chain_value: Decimal) -> Decimal:
38+
return chain_value / Decimal(f"1e{self.base_token.decimals}")
39+
40+
def price_from_chain_format(self, chain_value: Decimal) -> Decimal:
41+
decimals = self.base_token.decimals - self.quote_token.decimals
42+
return chain_value * Decimal(f"1e{decimals}")
43+
3744

3845
@dataclass(eq=True, frozen=True)
3946
class DerivativeMarket:
@@ -93,6 +100,15 @@ def calculate_margin_in_chain_format(
93100

94101
return extended_chain_formatted_margin
95102

103+
def quantity_from_chain_format(self, chain_value: Decimal) -> Decimal:
104+
return chain_value
105+
106+
def price_from_chain_format(self, chain_value: Decimal) -> Decimal:
107+
return chain_value * Decimal(f"1e-{self.quote_token.decimals}")
108+
109+
def margin_from_chain_format(self, chain_value: Decimal) -> Decimal:
110+
return chain_value * Decimal(f"1e-{self.quote_token.decimals}")
111+
96112

97113
@dataclass(eq=True, frozen=True)
98114
class BinaryOptionMarket:
@@ -155,3 +171,12 @@ def calculate_margin_in_chain_format(
155171
extended_chain_formatted_margin = quantized_margin * Decimal(f"1e{ADDITIONAL_CHAIN_FORMAT_DECIMALS}")
156172

157173
return extended_chain_formatted_margin
174+
175+
def quantity_from_chain_format(self, chain_value: Decimal, special_denom: Optional[Denom] = None) -> Decimal:
176+
# Binary option markets do not have a base market to provide the number of decimals
177+
decimals = 0 if special_denom is None else special_denom.base
178+
return chain_value * Decimal(f"1e-{decimals}")
179+
180+
def price_from_chain_format(self, chain_value: Decimal, special_denom: Optional[Denom] = None) -> Decimal:
181+
decimals = self.quote_token.decimals if special_denom is None else special_denom.quote
182+
return chain_value * Decimal(f"1e-{decimals}")

pyinjective/denoms_mainnet.ini

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,24 @@ min_display_price_tick_size = 9.999999999999999e-05
394394
min_quantity_tick_size = 10000000
395395
min_display_quantity_tick_size = 0.1
396396

397+
[0xe8fe754e16233754e2811c36aca89992e35951cfd61376f1cbdc44be6ac8d3fb]
398+
description = 'Mainnet Spot NEOK/USDT'
399+
base = 18
400+
quote = 6
401+
min_price_tick_size = 0.0000000000000001
402+
min_display_price_tick_size = 9.999999999999999e-05
403+
min_quantity_tick_size = 100000000000000000
404+
min_display_quantity_tick_size = 0.1
405+
406+
[0xa04adeed0f09ed45c73b344b520d05aa31eabe2f469dcbb02a021e0d9d098715]
407+
description = 'Mainnet Spot ORAI/USDT'
408+
base = 6
409+
quote = 6
410+
min_price_tick_size = 0.0001
411+
min_display_price_tick_size = 9.999999999999999e-05
412+
min_quantity_tick_size = 100000
413+
min_display_quantity_tick_size = 0.1
414+
397415
[0x4ca0f92fc28be0c9761326016b5a1a2177dd6375558365116b5bdda9abc229ce]
398416
description = 'Mainnet Derivative BTC/USDT PERP'
399417
base = 0
@@ -680,3 +698,11 @@ decimals = 8
680698
[NBLA]
681699
peggy_denom = factory/inj1d0zfq42409a5mhdagjutl8u6u9rgcm4h8zfmfq/nbla
682700
decimals = 6
701+
702+
[NEOK]
703+
peggy_denom = ibc/F6CC233E5C0EA36B1F74AB1AF98471A2D6A80E2542856639703E908B4D93E7C4
704+
decimals = 18
705+
706+
[ORAI]
707+
peggy_denom = ibc/C20C0A822BD22B2CEF0D067400FCCFB6FAEEE9E91D360B4E0725BD522302D565
708+
decimals = 6

pyinjective/sendtocosmos.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ def sendToInjective(
1414
private_key: str,
1515
token_contract: str,
1616
receiver: str,
17-
amount: int,
17+
amount: float,
1818
maxFeePerGas: int,
1919
maxPriorityFeePerGas: int,
2020
peggo_abi: str,
@@ -29,21 +29,22 @@ def sendToInjective(
2929
peggy_proxy_address = "0x4F38F75606d046819638f909b66B112aF1095e8d"
3030
else:
3131
LoggerProvider().logger_for_class(logging_class=self.__class__).info("Network is not supported")
32+
raise RuntimeError(f"Network {self.network} not supported")
3233
web3 = Web3(Web3.HTTPProvider(ethereum_endpoint))
3334
contract = web3.eth.contract(address=peggy_proxy_address, abi=peggo_abi)
3435

35-
token_contract_address = web3.toChecksumAddress(token_contract)
36+
token_contract_address = web3.to_checksum_address(token_contract)
3637

3738
receiver_address = Address.from_acc_bech32(receiver)
3839
receiver_ethereum_address = Address.get_ethereum_address(receiver_address)
39-
receiver_address_checksum = web3.toChecksumAddress(receiver_ethereum_address)
40+
receiver_address_checksum = web3.to_checksum_address(receiver_ethereum_address)
4041
receiver_slice = receiver_address_checksum[2:]
4142
receiver_padded_address = '0x' + receiver_slice.zfill(64)
4243

43-
destination = web3.toBytes(hexstr=receiver_padded_address)
44+
destination = web3.to_bytes(hexstr=receiver_padded_address)
4445

45-
sender_ethereum_address = web3.eth.account.privateKeyToAccount(private_key).address
46-
sender_address_checksum = web3.toChecksumAddress(sender_ethereum_address)
46+
sender_ethereum_address = web3.eth.account.from_key(private_key).address
47+
sender_address_checksum = web3.to_checksum_address(sender_ethereum_address)
4748
nonce = web3.eth.get_transaction_count(sender_address_checksum)
4849

4950
amount_to_send = int(amount * pow(10, decimals))
@@ -53,13 +54,13 @@ def sendToInjective(
5354
destination,
5455
amount_to_send,
5556
data
56-
).estimateGas({'from': sender_address_checksum})
57+
).estimate_gas({'from': sender_address_checksum})
5758

5859
transaction_body = {
5960
'nonce': nonce,
6061
'gas': gas,
61-
'maxFeePerGas': web3.toWei(maxFeePerGas, 'gwei'),
62-
'maxPriorityFeePerGas': web3.toWei(maxPriorityFeePerGas, 'gwei'),
62+
'maxFeePerGas': web3.to_wei(maxFeePerGas, 'gwei'),
63+
'maxPriorityFeePerGas': web3.to_wei(maxPriorityFeePerGas, 'gwei'),
6364
}
6465

6566
tx = contract.functions.sendToInjective(

pyproject.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "injective-py"
3-
version = "0.8.1"
3+
version = "0.9.dev"
44
description = "Injective Python SDK, with Exchange API Client"
55
authors = ["Injective Labs <[email protected]>"]
66
license = "Apache Software License 2.0"
@@ -32,6 +32,7 @@ requests = "*"
3232
safe-pysha3 = "*"
3333
urllib3 = "<2"
3434
websockets = "*"
35+
web3 = "^6.0"
3536

3637
[tool.poetry.group.test.dependencies]
3738
pytest = "*"

0 commit comments

Comments
 (0)