Skip to content

Commit

Permalink
fix: drop web3, use eth-utils and eth-account
Browse files Browse the repository at this point in the history
  • Loading branch information
JonathanAmenechi committed Jul 18, 2024
1 parent 92df98c commit 99fb426
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 25 deletions.
5 changes: 2 additions & 3 deletions py_order_utils/builders/base_builder.py
Original file line number Diff line number Diff line change
@@ -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__(
Expand Down Expand Up @@ -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):
"""
Expand Down
2 changes: 1 addition & 1 deletion py_order_utils/builders/order_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
"""
Expand Down
18 changes: 2 additions & 16 deletions py_order_utils/utils.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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:
Expand All @@ -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],
)
5 changes: 3 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -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
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
],
Expand Down
4 changes: 2 additions & 2 deletions tests/test_order_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down

0 comments on commit 99fb426

Please sign in to comment.