EIP-712 signing for Polymarket CLOB V2 orders.
Turns a Polymarket.Schemas.Order into the 0x-prefixed signature the CLOB
expects, following the on-chain CTF Exchange V2 typed-data scheme:
eip712_hash_struct/1— hash the order's eleven signed fields;domain_separator/2— the domain for the V2 exchange on the target chain (selected bychain_idand the market'sneg_risk?flag);signing_digest/3—keccak256(0x1901 ‖ domainSeparator ‖ hashStruct);sign/4— secp256k1-sign that digest with the maker's private key.
sign/4 dispatches on the order's signature_type:
:eoa,:proxy,:gnosis_safe— a plain EIP-712 signature of the digest;:poly1271— the deposit-wallet flow: a Solady/ERC-1271TypedDataSignenvelope, signed by the deposit wallet's owner key and validated on-chain by the wallet contract (EIP-1271). Heremakerandsignerare the deposit wallet (the "funder") address andprivate_keyis the owner EOA's key.
The order's maker/signer must already be set correctly by the caller; sign/4
signs the order as given.
Summary
Functions
Computes the EIP-712 domain separator for the V2 exchange on chain_id, using
the variant selected by neg_risk?. Returns {:error, :unsupported_chain} when
no exchange is configured for that chain.
Computes the EIP-712 hashStruct of an order's eleven signed V2 fields.
Signs order with private_key, returning the 0x-prefixed signature hex the
CLOB expects.
Computes the 32-byte EIP-712 signing digest for order on chain_id/neg_risk?.
Functions
Computes the EIP-712 domain separator for the V2 exchange on chain_id, using
the variant selected by neg_risk?. Returns {:error, :unsupported_chain} when
no exchange is configured for that chain.
@spec eip712_hash_struct(Polymarket.Schemas.Order.t()) :: <<_::256>>
Computes the EIP-712 hashStruct of an order's eleven signed V2 fields.
expiration is intentionally excluded — it is not part of the V2 signed struct.
@spec sign( Polymarket.Schemas.Order.t(), Polymarket.Crypto.private_key(), integer(), boolean() ) :: {:ok, String.t()} | {:error, :unsupported_chain}
Signs order with private_key, returning the 0x-prefixed signature hex the
CLOB expects.
For :eoa/:proxy/:gnosis_safe orders this is the 65-byte r ‖ s ‖ v
signature; for :poly1271 it is the longer Solady/ERC-1271 TypedDataSign
envelope. chain_id selects the network (137 Polygon / 80002 Amoy) and
neg_risk? the exchange variant for the order's market. Returns
{:error, :unsupported_chain} for a chain with no configured exchange.
@spec signing_digest(Polymarket.Schemas.Order.t(), integer(), boolean()) :: {:ok, <<_::256>>} | {:error, :unsupported_chain}
Computes the 32-byte EIP-712 signing digest for order on chain_id/neg_risk?.