✍️Signing Orders

Users can buy options using the asks. However in order to prove the legitimacy of an order, we need a signature that verifies the creator of the order.

In order to create signatures, you will need to sign the order data using the EIP-712 standardarrow-up-right.

Example:

import * as ethUtil from "eth-sig-util";

const poolAsk = {
  "id": 182739,
  "poolAddress": "0x1fd748b4786584da205eaf3f858744eb614b0fce",
  "optionType": "CALL",
  "strikePrice": "5500000000000000000",
  "premium": "700000000000000000",
  "expiry": 1679616000,
  "tokenId": 124,
  "orderExpiry": 1679615000
}

const typedData = {
  types: {
    EIP712Domain: [
      {name: "name", type: "string"},
      {name: "version", type: "string"},
      {name: "chainId", type: "uint256"},
      {name: "verifyingContract", type: "address"},
    ],
    PoolAsk: [
      { name: "id", type: "uint256" },
      { name: "poolAddress", type: "address" },
      { name: "optionType", type: "uint256" },
      { name: "strikePrice", type: "uint256" },
      { name: "premium", type: "uint256" },
      { name: "expiry", type: "uint256" },
      { name: "tokenId", type: "uint256" },
      { name: "orderExpiry", type: "uint256" }
    ]
  },
  primaryType: 'PoolAsk',
  domain: {
    name: 'PoolAskSignature',
    version: '1',
    chainId: 0, // 0 for Mainnet, 5 for Goerli
    verifyingContract: "0x12af..123" // Should be the poolAddress,
  },
  message: poolAsk
};

const privateKey = ""; // Your private key
const signature =
  ethUtil.signTypedData(
    Buffer.from(privateKey, "hex"),
    {
      data: typedData
    }
  );

Last updated