Skip to content

Commit

Permalink
Upgrades web3.py version in requirements
Browse files Browse the repository at this point in the history
  • Loading branch information
konichuvak committed Mar 15, 2023
1 parent d9be2be commit e31dc16
Show file tree
Hide file tree
Showing 13 changed files with 32 additions and 32 deletions.
2 changes: 1 addition & 1 deletion dydx3/dydx_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion dydx3/eth_signing/eth_prive_action.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
2 changes: 1 addition & 1 deletion dydx3/eth_signing/onboarding_action.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
4 changes: 2 additions & 2 deletions dydx3/eth_signing/sign_off_chain_action.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def get_eip712_message(
}

def get_eip712_hash(self, struct_hash):
return Web3.solidityKeccak(
return Web3.solidity_keccak(
[
'bytes2',
'bytes32',
Expand All @@ -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',
Expand Down
4 changes: 2 additions & 2 deletions dydx3/eth_signing/signers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Expand Down
10 changes: 5 additions & 5 deletions dydx3/eth_signing/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -104,4 +104,4 @@ def addresses_are_equal(


def hash_string(input):
return Web3.solidityKeccak(['string'], [input])
return Web3.solidity_keccak(['string'], [input])
20 changes: 10 additions & 10 deletions dydx3/modules/eth.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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(
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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:
Expand All @@ -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]

Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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'),
),
)

Expand Down Expand Up @@ -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,
Expand Down
6 changes: 3 additions & 3 deletions dydx3/modules/onboarding.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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]

Expand Down
2 changes: 1 addition & 1 deletion dydx3/starkex/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ def get_transfer_erc20_fact(
token_decimals,
)
)
hex_bytes = Web3.solidityKeccak(
hex_bytes = Web3.solidity_keccak(
[
'address',
'uint256',
Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions requirements-test.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit e31dc16

Please sign in to comment.