BuildOnViction/tomochain-v1

Standardize createOrder, cancelOrder API

thanhson1085 opened this issue · 2 comments

Currently, tomox does not require user sign data when cancel an order
But we have to require user to sign(order.hash + order.status), and tomox have to verify the signature. Related to #744

Create order:

{
    exchangeAddress: '0x0D3ab14BBaD3D99F4203bd7a11aCB94882050E7e',
    userAddress: '0x15e08dE16f534c890828F2a0D935433aF5B3CE0C',
    baseToken: '0x4d7ea2ce949216d6b120f3aa10164173615a2b6c',
    quoteToken: '0x0000000000000000000000000000000000000001',
    amount: '39250000000000000',
    pricepoint: '25477960000000000000000',
    side: 'SELL',
    type: 'LO',
    status: 'NEW',
    nonce: '667',
    hash:
    '0x2d80555b29a166a8631db28d595b6b6c973555338257d585e09d954adcfcc11d',
    signature:
    {
        R: '0xea56a9bd27bbe62139390dff9574a17847d45148a30e744208231ec5a4d1d66e',
        S: '0x6ac9b7c58e3f9b7e577e99dc4f1adbdb5ad35618150693864ea5ca848165edaf',
        V: 27
    } 
}

Cancel Order:

{
    exchangeAddress: '0x0D3ab14BBaD3D99F4203bd7a11aCB94882050E7e',
    userAddress: '0x15e08dE16f534c890828F2a0D935433aF5B3CE0C',
    baseToken: '0x4d7ea2ce949216d6b120f3aa10164173615a2b6c',
    quoteToken: '0x0000000000000000000000000000000000000001',
    amount: '39250000000000000',
    pricepoint: '25477960000000000000000',
    side: 'SELL',
    type: 'LO',
    status: 'CANCELED',
    nonce: '668',
    hash:
    '0x2d80555b29a166a8631db28d595b6b6c973555338257d585e09d954adcfcc11d',
    signature:
    {
        R: '0xea56a9bd27bbe62139390dff9574a17847d45148a30e744208231ec5a4d1d66e',
        S: '0x6ac9b7c58e3f9b7e577e99dc4f1adbdb5ad35618150693864ea5ca848165edaf',
        V: 27
    } 
}

user need to signed order body to create signature

function to hash order

export const getOrderHash = order => {
  return utils.solidityKeccak256(
    [
      'bytes',
      'bytes',
      'bytes',
      'bytes',
      'string',
      'string',
      'uint256',
      'uint256',
      'uint256',
      'uint256',
    ],
    [
      order.exchangeAddress,
      order.userAddress,
      order.baseToken,
      order.quoteToken,
      order.status,
      order.type,
      order.amount,
      order.pricepoint,
      order.side === 'BUY' ? '0' : '1',
      order.nonce,
    ],
  )
}