Polymarket.Clob.OrderSigner (Polymarket v0.1.1)

Copy Markdown View Source

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:

  1. eip712_hash_struct/1 — hash the order's eleven signed fields;
  2. domain_separator/2 — the domain for the V2 exchange on the target chain (selected by chain_id and the market's neg_risk? flag);
  3. signing_digest/3keccak256(0x1901 ‖ domainSeparator ‖ hashStruct);
  4. 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-1271 TypedDataSign envelope, signed by the deposit wallet's owner key and validated on-chain by the wallet contract (EIP-1271). Here maker and signer are the deposit wallet (the "funder") address and private_key is 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

domain_separator(chain_id, neg_risk?)

@spec domain_separator(integer(), boolean()) ::
  {:ok, <<_::256>>} | {:error, :unsupported_chain}

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.

eip712_hash_struct(order)

@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.

sign(order, private_key, chain_id, neg_risk?)

@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.

signing_digest(order, chain_id, neg_risk?)

@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?.