from eth_account import Account
from eth_account.messages import encode_typed_data
PRIVATE_KEY = "0x..."
DOMAIN = {
"name": "b1nary",
"version": "1",
"chainId": 84532, # testnet; use 8453 for production
"verifyingContract": "0x766bD3aF1D102f7EbcB65a7B7bC12478C2DbA918",
}
QUOTE_TYPES = {
"Quote": [
{"name": "oToken", "type": "address"},
{"name": "bidPrice", "type": "uint256"},
{"name": "deadline", "type": "uint256"},
{"name": "quoteId", "type": "uint256"},
{"name": "maxAmount", "type": "uint256"},
{"name": "makerNonce", "type": "uint256"},
],
}
for q in quotes:
signable = encode_typed_data(
domain_data=DOMAIN,
message_types=QUOTE_TYPES,
message_data={
"oToken": q["otoken_address"],
"bidPrice": q["bid_price"],
"deadline": q["deadline"],
"quoteId": q["quote_id"],
"maxAmount": q["max_amount"],
"makerNonce": q["maker_nonce"],
},
)
signed = Account.sign_message(signable, private_key=PRIVATE_KEY)
q["signature"] = "0x" + signed.signature.hex()