diff --git a/py_order_utils/builders/base_builder.py b/py_order_utils/builders/base_builder.py index e9ad6cc..16e0577 100644 --- a/py_order_utils/builders/base_builder.py +++ b/py_order_utils/builders/base_builder.py @@ -1,8 +1,7 @@ -from web3 import Web3 from ..signer import Signer from ..utils import normalize_address -from eip712_structs import make_domain, EIP712Struct - +from poly_eip712_structs import make_domain, EIP712Struct +from eth_utils import keccak class BaseBuilder: def __init__( @@ -30,7 +29,7 @@ def _create_struct_hash(self, order: EIP712Struct): """ Creates an EIP712 compliant struct hash for the Order """ - return Web3.keccak(order.signable_bytes(domain=self.domain_separator)) + return "0x" + keccak(order.signable_bytes(domain=self.domain_separator)).hex() def sign(self, struct_hash): """ diff --git a/py_order_utils/builders/order_builder.py b/py_order_utils/builders/order_builder.py index f090a15..88dec6a 100644 --- a/py_order_utils/builders/order_builder.py +++ b/py_order_utils/builders/order_builder.py @@ -59,7 +59,7 @@ def build_order_signature(self, _order: Order) -> str: """ Signs the order """ - return self.sign(self._create_struct_hash(_order)) + return "0x" + self.sign(self._create_struct_hash(_order)) def build_signed_order(self, data: OrderData) -> SignedOrder: """ diff --git a/py_order_utils/model/order.py b/py_order_utils/model/order.py index 35d23ef..811068f 100644 --- a/py_order_utils/model/order.py +++ b/py_order_utils/model/order.py @@ -2,7 +2,7 @@ from ..constants import ZERO_ADDRESS from .signatures import EOA -from eip712_structs import Address, EIP712Struct, Uint +from poly_eip712_structs import Address, EIP712Struct, Uint @dataclass diff --git a/py_order_utils/utils.py b/py_order_utils/utils.py index 843012a..2756d3d 100644 --- a/py_order_utils/utils.py +++ b/py_order_utils/utils.py @@ -1,5 +1,5 @@ import math -import web3 +from eth_utils import to_checksum_address from string import punctuation from random import random from datetime import datetime, timezone @@ -15,7 +15,7 @@ def normalize(s: str) -> str: def normalize_address(address: str) -> str: - return web3.Web3.toChecksumAddress(address) + return to_checksum_address(address) def generate_seed() -> int: @@ -25,17 +25,3 @@ def generate_seed() -> int: now = datetime.now().replace(tzinfo=timezone.utc).timestamp() return round(now * random()) - -def hash_string(s: str): - return solidity_keccak("string", s) - - -def hash_bytes(b): - return solidity_keccak("bytes", b) - - -def solidity_keccak(typ, val): - return web3.Web3.solidityKeccak( - abi_types=[typ], - values=[val], - ) diff --git a/requirements.txt b/requirements.txt index a19b59a..99c1237 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,49 +1,4 @@ -aiohttp==3.8.1 -aiosignal==1.2.0 -async-timeout==4.0.2 -attrs==21.4.0 -base58==2.1.1 -bitarray==1.2.2 -certifi==2021.10.8 -charset-normalizer==2.0.10 -cytoolz==0.11.2 -eip712-structs==1.1.0 -eth-abi==2.1.1 -eth-account==0.5.6 -eth-hash==0.3.2 -eth-keyfile==0.5.1 -eth-keys==0.3.4 -eth-rlp==0.2.1 -eth-typing==2.3.0 -eth-utils==1.10.0 -frozenlist==1.3.0 -hexbytes==0.2.2 -idna==3.3 -iniconfig==1.1.1 -ipfshttpclient==0.8.0a2 -jsonschema==3.2.0 -lru-dict==1.1.7 -multiaddr==0.0.9 -multidict==6.0.2 -netaddr==0.8.0 -packaging==21.3 -parsimonious==0.8.1 -pluggy==1.0.0 -protobuf==3.19.3 -py==1.11.0 -pycryptodome==3.13.0 -pyparsing==3.0.7 -pyrsistent==0.18.1 -pysha3==1.0.2 -pytest==6.2.5 -requests==2.27.1 -rlp==2.0.1 -six==1.16.0 -toml==0.10.2 -toolz==0.11.2 -urllib3==1.26.8 -varint==1.0.2 -web3==5.26.0 -websockets==9.1 -yarl==1.7.2 -black==22.3.0 +eth-account===0.13.0 +eth-utils===4.1.1 +poly_eip712_structs==0.0.1 +pytest==8.2.2 \ No newline at end of file diff --git a/setup.py b/setup.py index ad28222..9e014de 100644 --- a/setup.py +++ b/setup.py @@ -5,7 +5,7 @@ setuptools.setup( name="py_order_utils", - version="0.3.0", + version="0.3.1", author="Polymarket Engineering", author_email="engineering@polymarket.com", maintainer="Polymarket Engineering", @@ -15,14 +15,10 @@ long_description_content_type="text/markdown", url="https://github.com/polymarket/python-order-utils", install_requires=[ - "web3>=5.0.0,<6.0.0", - "eth-account>=0.4.0,<0.6.0", - "eip712-structs", - "pytest", - "eth-abi", - "eth_typing", - "eth_utils", - "eth_utils", + "eth-utils>=4.1.1", + "eth-account>=0.13.0", + "poly-eip712-structs", + "pytest" ], package_data={ "py_order_utils": [ diff --git a/tests/test_order_builder.py b/tests/test_order_builder.py index b379757..6b96f50 100644 --- a/tests/test_order_builder.py +++ b/tests/test_order_builder.py @@ -188,7 +188,7 @@ def test_build_order_neg_risk(self): self.assertEqual(BUY, _order["side"]) self.assertEqual(EOA, _order["signatureType"]) - def test_build_prder_signature(self): + def test_build_order_signature(self): builder = OrderBuilder( amoy_contracts["exchange"], chain_id, signer, mock_salt_generator ) @@ -200,13 +200,13 @@ def test_build_prder_signature(self): "0x02ca1d1aa31103804173ad1acd70066cb6c1258a4be6dada055111f9a7ea4e55" ) struct_hash = builder._create_struct_hash(_order) - self.assertEqual(expected_struct_hash, struct_hash.hex()) + self.assertEqual(expected_struct_hash, struct_hash) expected_signature = "0x302cd9abd0b5fcaa202a344437ec0b6660da984e24ae9ad915a592a90facf5a51bb8a873cd8d270f070217fea1986531d5eec66f1162a81f66e026db653bf7ce1c" sig = builder.build_order_signature(_order) self.assertEqual(expected_signature, sig) - def test_build_prder_signature_neg_risk(self): + def test_build_order_signature_neg_risk(self): builder = OrderBuilder( amoy_contracts["negRiskExchange"], chain_id, signer, mock_salt_generator ) @@ -218,11 +218,10 @@ def test_build_prder_signature_neg_risk(self): "0xf15790d3edc4b5aed427b0b543a9206fcf4b1a13dfed016d33bfb313076263b8" ) struct_hash = builder._create_struct_hash(_order) - self.assertEqual(expected_struct_hash, struct_hash.hex()) + self.assertEqual(expected_struct_hash, struct_hash) expected_signature = "0x1b3646ef347e5bd144c65bd3357ba19c12c12abaeedae733cf8579bc51a2752c0454c3bc6b236957e393637982c769b8dc0706c0f5c399983d933850afd1cbcd1c" sig = builder.build_order_signature(_order) - print(sig) self.assertEqual(expected_signature, sig) def test_build_signed_order(self):