From 86e1f28ee21361f96be77296117a08f32629a460 Mon Sep 17 00:00:00 2001 From: JonathanAmenechi <7217608+JonathanAmenechi@users.noreply.github.com> Date: Thu, 18 Jul 2024 11:50:14 -0400 Subject: [PATCH 1/4] fix: restrict requirements, upgrade to latest prod web3 --- py_order_utils/utils.py | 2 +- requirements.txt | 50 ++----------------------------------- setup.py | 11 +++----- tests/test_order_builder.py | 5 ++-- 4 files changed, 8 insertions(+), 60 deletions(-) diff --git a/py_order_utils/utils.py b/py_order_utils/utils.py index 843012a..7e96d91 100644 --- a/py_order_utils/utils.py +++ b/py_order_utils/utils.py @@ -15,7 +15,7 @@ def normalize(s: str) -> str: def normalize_address(address: str) -> str: - return web3.Web3.toChecksumAddress(address) + return web3.Web3.to_checksum_address(address) def generate_seed() -> int: diff --git a/requirements.txt b/requirements.txt index a19b59a..b6ff1a9 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,49 +1,3 @@ -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 +pytest==8.2.2 +web3==6.20.0 diff --git a/setup.py b/setup.py index 5daa8f3..a3549a3 100644 --- a/setup.py +++ b/setup.py @@ -5,7 +5,7 @@ setuptools.setup( name="py_order_utils", - version="0.2.0", + version="0.2.1", author="Polymarket Engineering", author_email="engineering@polymarket.com", maintainer="Polymarket Engineering", @@ -15,14 +15,9 @@ 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", + "web3>=6.20.0", "eip712-structs", - "pytest", - "eth-abi", - "eth_typing", - "eth_utils", - "eth_utils", + "pytest" ], package_data={ "py_order_utils": [ diff --git a/tests/test_order_builder.py b/tests/test_order_builder.py index 62d3676..2c68eb5 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( mumbai_contracts["exchange"], chain_id, signer, mock_salt_generator ) @@ -206,7 +206,7 @@ def test_build_prder_signature(self): 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( mumbai_contracts["negRiskExchange"], chain_id, signer, mock_salt_generator ) @@ -222,7 +222,6 @@ def test_build_prder_signature_neg_risk(self): expected_signature = "0xb47e588cfb8630ffa255d1a04a4bb2b996967c2143fc107ab443282ed7dcc123288842968fa29e6f2e789e39ea02f13654d4dd55002b8672e9a91e2ba9045aa21b" sig = builder.build_order_signature(_order) - print(sig) self.assertEqual(expected_signature, sig) def test_build_signed_order(self): From 92df98c2d1f456cfabb010089176cca5dd1e3192 Mon Sep 17 00:00:00 2001 From: JonathanAmenechi <7217608+JonathanAmenechi@users.noreply.github.com> Date: Thu, 18 Jul 2024 11:52:12 -0400 Subject: [PATCH 2/4] fix: version bump --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 67ac1e9..5269d70 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", From 99fb4262aed969af0628fdffc7163f928481a9ed Mon Sep 17 00:00:00 2001 From: JonathanAmenechi <7217608+JonathanAmenechi@users.noreply.github.com> Date: Thu, 18 Jul 2024 13:33:09 -0400 Subject: [PATCH 3/4] fix: drop web3, use eth-utils and eth-account --- py_order_utils/builders/base_builder.py | 5 ++--- py_order_utils/builders/order_builder.py | 2 +- py_order_utils/utils.py | 18 ++---------------- requirements.txt | 5 +++-- setup.py | 3 ++- tests/test_order_builder.py | 4 ++-- 6 files changed, 12 insertions(+), 25 deletions(-) diff --git a/py_order_utils/builders/base_builder.py b/py_order_utils/builders/base_builder.py index e9ad6cc..d6b95b1 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 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/utils.py b/py_order_utils/utils.py index 7e96d91..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.to_checksum_address(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 b6ff1a9..3f33bdc 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,4 @@ eip712-structs==1.1.0 -pytest==8.2.2 -web3==6.20.0 +eth-account===0.13.0 +eth-utils===4.1.1 +pytest==8.2.2 \ No newline at end of file diff --git a/setup.py b/setup.py index 5269d70..e020b2f 100644 --- a/setup.py +++ b/setup.py @@ -15,7 +15,8 @@ long_description_content_type="text/markdown", url="https://github.com/polymarket/python-order-utils", install_requires=[ - "web3>=6.20.0", + "eth-utils>=4.1.1", + "eth-account>=0.13.0", "eip712-structs", "pytest" ], diff --git a/tests/test_order_builder.py b/tests/test_order_builder.py index dd9accc..6b96f50 100644 --- a/tests/test_order_builder.py +++ b/tests/test_order_builder.py @@ -200,7 +200,7 @@ def test_build_order_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) @@ -218,7 +218,7 @@ def test_build_order_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) From eb5168dd4a07981d3b447427f567012a06cbe58e Mon Sep 17 00:00:00 2001 From: JonathanAmenechi <7217608+JonathanAmenechi@users.noreply.github.com> Date: Thu, 18 Jul 2024 15:46:37 -0400 Subject: [PATCH 4/4] fix: use poly eip712 lib --- py_order_utils/builders/base_builder.py | 2 +- py_order_utils/model/order.py | 2 +- requirements.txt | 2 +- setup.py | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/py_order_utils/builders/base_builder.py b/py_order_utils/builders/base_builder.py index d6b95b1..16e0577 100644 --- a/py_order_utils/builders/base_builder.py +++ b/py_order_utils/builders/base_builder.py @@ -1,6 +1,6 @@ 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: 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/requirements.txt b/requirements.txt index 3f33bdc..99c1237 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,4 @@ -eip712-structs==1.1.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 e020b2f..9e014de 100644 --- a/setup.py +++ b/setup.py @@ -17,7 +17,7 @@ install_requires=[ "eth-utils>=4.1.1", "eth-account>=0.13.0", - "eip712-structs", + "poly-eip712-structs", "pytest" ], package_data={