From e31dc161dea159bf8ba73ba8c87df9a130f1809b Mon Sep 17 00:00:00 2001 From: konichuvak Date: Wed, 15 Mar 2023 19:33:16 -0400 Subject: [PATCH] Upgrades web3.py version in requirements --- dydx3/dydx_client.py | 2 +- dydx3/eth_signing/eth_prive_action.py | 2 +- dydx3/eth_signing/onboarding_action.py | 2 +- dydx3/eth_signing/sign_off_chain_action.py | 4 ++-- dydx3/eth_signing/signers.py | 4 ++-- dydx3/eth_signing/util.py | 10 +++++----- dydx3/modules/eth.py | 20 +++++++++---------- dydx3/modules/onboarding.py | 6 +++--- dydx3/starkex/helpers.py | 2 +- .../{websockets.py => websockets_stream.py} | 0 requirements-test.txt | 4 ++-- requirements.txt | 4 ++-- setup.py | 4 ++-- 13 files changed, 32 insertions(+), 32 deletions(-) rename examples/{websockets.py => websockets_stream.py} (100%) diff --git a/dydx3/dydx_client.py b/dydx3/dydx_client.py index a598dd8..1479dd3 100644 --- a/dydx3/dydx_client.py +++ b/dydx3/dydx_client.py @@ -59,7 +59,7 @@ def __init__( ) self.web3 = web3 or Web3(web3_provider) self.eth_signer = SignWithWeb3(self.web3) - self.default_address = self.web3.eth.defaultAccount or None + self.default_address = self.web3.eth.default_account or None self.network_id = self.web3.net.version if eth_private_key is not None or web3_account is not None: diff --git a/dydx3/eth_signing/eth_prive_action.py b/dydx3/eth_signing/eth_prive_action.py index 65a0718..efd5178 100644 --- a/dydx3/eth_signing/eth_prive_action.py +++ b/dydx3/eth_signing/eth_prive_action.py @@ -67,5 +67,5 @@ def get_hash( util.hash_string(timestamp), ], ] - struct_hash = Web3.solidityKeccak(*data) + struct_hash = Web3.solidity_keccak(*data) return self.get_eip712_hash(struct_hash) diff --git a/dydx3/eth_signing/onboarding_action.py b/dydx3/eth_signing/onboarding_action.py index 5cbaad3..e09750d 100644 --- a/dydx3/eth_signing/onboarding_action.py +++ b/dydx3/eth_signing/onboarding_action.py @@ -82,5 +82,5 @@ def get_hash( data[0].append('bytes32') data[1].append(util.hash_string(ONLY_SIGN_ON_DOMAIN_MAINNET)) - struct_hash = Web3.solidityKeccak(*data) + struct_hash = Web3.solidity_keccak(*data) return self.get_eip712_hash(struct_hash) diff --git a/dydx3/eth_signing/sign_off_chain_action.py b/dydx3/eth_signing/sign_off_chain_action.py index ade0955..d09357d 100644 --- a/dydx3/eth_signing/sign_off_chain_action.py +++ b/dydx3/eth_signing/sign_off_chain_action.py @@ -85,7 +85,7 @@ def get_eip712_message( } def get_eip712_hash(self, struct_hash): - return Web3.solidityKeccak( + return Web3.solidity_keccak( [ 'bytes2', 'bytes32', @@ -99,7 +99,7 @@ def get_eip712_hash(self, struct_hash): ) def get_domain_hash(self): - return Web3.solidityKeccak( + return Web3.solidity_keccak( [ 'bytes32', 'bytes32', diff --git a/dydx3/eth_signing/signers.py b/dydx3/eth_signing/signers.py index 2e08ab8..233ee5f 100644 --- a/dydx3/eth_signing/signers.py +++ b/dydx3/eth_signing/signers.py @@ -43,12 +43,12 @@ def sign( message_hash, # Ignored. opt_signer_address, ): - signer_address = opt_signer_address or self.web3.eth.defaultAccount + signer_address = opt_signer_address or self.web3.eth.default_account if not signer_address: raise ValueError( 'Must set ethereum_address or web3.eth.defaultAccount', ) - raw_signature = self.web3.eth.signTypedData( + raw_signature = self.web3.eth.sign_typed_data( signer_address, eip712_message, ) diff --git a/dydx3/eth_signing/util.py b/dydx3/eth_signing/util.py index 2ea4418..658bb4d 100644 --- a/dydx3/eth_signing/util.py +++ b/dydx3/eth_signing/util.py @@ -28,24 +28,24 @@ def ec_recover_typed_signature( if sig_type == constants.SIGNATURE_TYPE_NO_PREPEND: prepended_hash = hashVal elif sig_type == constants.SIGNATURE_TYPE_DECIMAL: - prepended_hash = Web3.solidityKeccak( + prepended_hash = Web3.solidity_keccak( ['string', 'bytes32'], [PREPEND_DEC, hashVal], ) elif sig_type == constants.SIGNATURE_TYPE_HEXADECIMAL: - prepended_hash = Web3.solidityKeccak( + prepended_hash = Web3.solidity_keccak( ['string', 'bytes32'], [PREPEND_HEX, hashVal], ) else: - raise Exception('Invalid signature type: ' + sig_type) + raise Exception('Invalid signature type: ' + str(sig_type)) if not prepended_hash: raise Exception('Invalid hash: ' + hashVal) signature = typed_signature[:-2] - address = w3.eth.account.recoverHash(prepended_hash, signature=signature) + address = w3.eth.account._recover_hash(prepended_hash, signature=signature) return address @@ -104,4 +104,4 @@ def addresses_are_equal( def hash_string(input): - return Web3.solidityKeccak(['string'], [input]) + return Web3.solidity_keccak(['string'], [input]) diff --git a/dydx3/modules/eth.py b/dydx3/modules/eth.py index 0f864ba..92f9ae8 100644 --- a/dydx3/modules/eth.py +++ b/dydx3/modules/eth.py @@ -84,7 +84,7 @@ def get_exchange_contract( self.network_id, ) ) - contract_address = Web3.toChecksumAddress(contract_address) + contract_address = Web3.to_checksum_address(contract_address) return self.get_contract(contract_address, STARKWARE_PERPETUALS_ABI) def get_token_contract( @@ -101,7 +101,7 @@ def get_token_contract( self.network_id, ) ) - token_address = Web3.toChecksumAddress(token_address) + token_address = Web3.to_checksum_address(token_address) return self.get_contract(token_address, ERC20_ABI) def send_eth_transaction( @@ -123,7 +123,7 @@ def send_eth_transaction( if 'gasPrice' not in options: try: options['gasPrice'] = ( - self.web3.eth.gasPrice + DEFAULT_GAS_PRICE_ADDITION + self.web3.eth.gas_price + DEFAULT_GAS_PRICE_ADDITION ) except Exception: options['gasPrice'] = DEFAULT_GAS_PRICE @@ -140,7 +140,7 @@ def send_eth_transaction( signed = self.sign_tx(method, options) try: - tx_hash = self.web3.eth.sendRawTransaction(signed.rawTransaction) + tx_hash = self.web3.eth.send_raw_transaction(signed.rawTransaction) except ValueError as error: while ( auto_detect_nonce and @@ -152,7 +152,7 @@ def send_eth_transaction( try: options['nonce'] += 1 signed = self.sign_tx(method, options) - tx_hash = self.web3.eth.sendRawTransaction( + tx_hash = self.web3.eth.send_raw_transaction( signed.rawTransaction, ) except ValueError as inner_error: @@ -173,7 +173,7 @@ def get_next_nonce( ): if self._next_nonce_for_address.get(ethereum_address) is None: self._next_nonce_for_address[ethereum_address] = ( - self.web3.eth.getTransactionCount(ethereum_address) + self.web3.eth.get_transaction_count(ethereum_address) ) return self._next_nonce_for_address[ethereum_address] @@ -205,7 +205,7 @@ def wait_for_tx( :raises: TransactionReverted ''' - tx_receipt = self.web3.eth.waitForTransactionReceipt(tx_hash) + tx_receipt = self.web3.eth.wait_for_transaction_receipt(tx_hash) if tx_receipt['status'] == 0: raise TransactionReverted(tx_receipt) @@ -400,7 +400,7 @@ def transfer_eth( options=dict( send_options, to=to_address, - value=Web3.toWei(human_amount, 'ether'), + value=Web3.to_wei(human_amount, 'ether'), ), ) @@ -512,8 +512,8 @@ def get_eth_balance( 'owner was not provided, and no default address is set', ) - wei_balance = self.web3.eth.getBalance(owner) - return Web3.fromWei(wei_balance, 'ether') + wei_balance = self.web3.eth.get_eth_balance(owner) + return Web3.from_wei(wei_balance, 'ether') def get_token_balance( self, diff --git a/dydx3/modules/onboarding.py b/dydx3/modules/onboarding.py index 5ef9ce1..475bd95 100644 --- a/dydx3/modules/onboarding.py +++ b/dydx3/modules/onboarding.py @@ -135,7 +135,7 @@ def derive_stark_key( action=OFF_CHAIN_KEY_DERIVATION_ACTION, ) signature_int = int(signature, 16) - hashed_signature = Web3.solidityKeccak(['uint256'], [signature_int]) + hashed_signature = Web3.solidity_keccak(['uint256'], [signature_int]) private_key_int = int(hashed_signature.hex(), 16) >> 5 private_key_hex = hex(private_key_int) public_x, public_y = private_key_to_public_key_pair_hex( @@ -163,11 +163,11 @@ def recover_default_api_key_credentials( ) r_hex = signature[2:66] r_int = int(r_hex, 16) - hashed_r_bytes = bytes(Web3.solidityKeccak(['uint256'], [r_int])) + hashed_r_bytes = bytes(Web3.solidity_keccak(['uint256'], [r_int])) secret_bytes = hashed_r_bytes[:30] s_hex = signature[66:130] s_int = int(s_hex, 16) - hashed_s_bytes = bytes(Web3.solidityKeccak(['uint256'], [s_int])) + hashed_s_bytes = bytes(Web3.solidity_keccak(['uint256'], [s_int])) key_bytes = hashed_s_bytes[:16] passphrase_bytes = hashed_s_bytes[16:31] diff --git a/dydx3/starkex/helpers.py b/dydx3/starkex/helpers.py index 2febd5e..789f2e6 100644 --- a/dydx3/starkex/helpers.py +++ b/dydx3/starkex/helpers.py @@ -121,7 +121,7 @@ def get_transfer_erc20_fact( token_decimals, ) ) - hex_bytes = Web3.solidityKeccak( + hex_bytes = Web3.solidity_keccak( [ 'address', 'uint256', diff --git a/examples/websockets.py b/examples/websockets_stream.py similarity index 100% rename from examples/websockets.py rename to examples/websockets_stream.py diff --git a/requirements-test.txt b/requirements-test.txt index efba86f..383c182 100644 --- a/requirements-test.txt +++ b/requirements-test.txt @@ -3,11 +3,11 @@ cytoolz==0.12.1 dateparser==1.0.0 ecdsa>=0.16.0 eth_keys -eth-account>=0.4.0,<0.6.0 +eth-account>=0.4.0 mpmath==1.0.0 pytest>=7.0.0 requests>=2.22.0,<3.0.0 six==1.14 sympy==1.6 tox>=4.3.4 -web3>=5.0.0,<6.0.0 +web3>=5.0.0 diff --git a/requirements.txt b/requirements.txt index bc0c951..10ade8d 100644 --- a/requirements.txt +++ b/requirements.txt @@ -3,9 +3,9 @@ cytoolz==0.12.1 dateparser==1.0.0 ecdsa>=0.16.0 eth_keys -eth-account>=0.4.0,<0.6.0 +eth-account>=0.4.0 mpmath==1.0.0 requests>=2.22.0,<3.0.0 six==1.14 sympy==1.6 -web3>=5.0.0,<6.0.0 +web3>=5.31.4 diff --git a/setup.py b/setup.py index a648d5b..5aca164 100644 --- a/setup.py +++ b/setup.py @@ -8,11 +8,11 @@ 'dateparser==1.0.0', 'ecdsa>=0.16.0', 'eth_keys', - 'eth-account>=0.4.0,<0.6.0', + 'eth-account>=0.4.0', 'mpmath==1.0.0', 'requests>=2.22.0,<3.0.0', 'sympy==1.6', - 'web3>=5.0.0,<6.0.0', + 'web3>=5.31.4', ] setup(