import sys
import datetime
sys.path.append('J:\\Softwareprojekte\\Polytrader\\venv\\Lib\\site-packages')
from py_clob_client.signing.eip712 import get_clob_auth_domain, MSG_TO_SIGN
from py_clob_client.signing.model import ClobAuth
from eth_utils import keccak

domain = get_clob_auth_domain(137)
target_msg_hash = bytes.fromhex("68eff3a266838ca5dd9049f4dba0b95170871d2a1a16478443df0515e5c3f606")

# The timestamp of the log was 16:06:52. Let's guess unix time for 2026-03-26.
# Let's just brute force a wide range of timestamps.
# 2026-03-26 15:00:00 UTC is ~1774537200
base = 1774537200

found = False
for t in range(base - 10000, base + 10000):
    clob_auth_msg = ClobAuth(
        address="0x628914CF1e96A9D1Ab8F0489A9f64be5633bac41",
        timestamp=str(t),
        nonce=0,
        message=MSG_TO_SIGN,
    )
    # The message hash is the keccak hash of the ABI encoded ClobAuth type struct.
    # signable_bytes returns 1901 + domainHash + messageHash
    signable = clob_auth_msg.signable_bytes(domain)
    # the last 32 bytes is the message Hash
    msg_hash = signable[34:]
    if msg_hash == target_msg_hash:
        print("MATCH FOUND FOR TIMESTAMP:", t)
        found = True
        break

if not found:
    print("NO MATCH FOUND.")
