diff options
author | Jacob Evans <jacob@dekz.net> | 2018-06-05 09:40:07 +0800 |
---|---|---|
committer | Jacob Evans <jacob@dekz.net> | 2018-06-06 05:08:04 +0800 |
commit | a59e9f024e76122c76600d938b565ea47938b287 (patch) | |
tree | 749c1485efeca041aa319e64af64aedd579dd8d6 /packages/contracts/src/utils/order_utils.ts | |
parent | 4670cc1a5f04d61045a82b4a3bbcf56e009afd56 (diff) | |
download | dexon-sol-tools-a59e9f024e76122c76600d938b565ea47938b287.tar dexon-sol-tools-a59e9f024e76122c76600d938b565ea47938b287.tar.gz dexon-sol-tools-a59e9f024e76122c76600d938b565ea47938b287.tar.bz2 dexon-sol-tools-a59e9f024e76122c76600d938b565ea47938b287.tar.lz dexon-sol-tools-a59e9f024e76122c76600d938b565ea47938b287.tar.xz dexon-sol-tools-a59e9f024e76122c76600d938b565ea47938b287.tar.zst dexon-sol-tools-a59e9f024e76122c76600d938b565ea47938b287.zip |
Update Order utils to use eip712
Diffstat (limited to 'packages/contracts/src/utils/order_utils.ts')
-rw-r--r-- | packages/contracts/src/utils/order_utils.ts | 56 |
1 files changed, 2 insertions, 54 deletions
diff --git a/packages/contracts/src/utils/order_utils.ts b/packages/contracts/src/utils/order_utils.ts index 316350ffb..180761f2c 100644 --- a/packages/contracts/src/utils/order_utils.ts +++ b/packages/contracts/src/utils/order_utils.ts @@ -1,29 +1,8 @@ -import { Order, OrderWithoutExchangeAddress, SignedOrder, UnsignedOrder } from '@0xproject/types'; +import { OrderWithoutExchangeAddress, SignedOrder } from '@0xproject/types'; import { BigNumber } from '@0xproject/utils'; import ethUtil = require('ethereumjs-util'); -import * as _ from 'lodash'; -import { crypto } from './crypto'; -import { EIP712Utils } from './eip712_utils'; -import { CancelOrder, EIP712Schema, MatchOrder } from './types'; - -const EIP712_ORDER_SCHEMA: EIP712Schema = { - name: 'Order', - parameters: [ - { name: 'makerAddress', type: 'address' }, - { name: 'takerAddress', type: 'address' }, - { name: 'feeRecipientAddress', type: 'address' }, - { name: 'senderAddress', type: 'address' }, - { name: 'makerAssetAmount', type: 'uint256' }, - { name: 'takerAssetAmount', type: 'uint256' }, - { name: 'makerFee', type: 'uint256' }, - { name: 'takerFee', type: 'uint256' }, - { name: 'expirationTimeSeconds', type: 'uint256' }, - { name: 'salt', type: 'uint256' }, - { name: 'makerAssetData', type: 'bytes' }, - { name: 'takerAssetData', type: 'bytes' }, - ], -}; +import { CancelOrder, MatchOrder } from './types'; export const orderUtils = { createFill: (signedOrder: SignedOrder, takerAssetFillAmount?: BigNumber) => { @@ -58,37 +37,6 @@ export const orderUtils = { }; return orderStruct; }, - getOrderSchemaBuffer(): Buffer { - return EIP712Utils.compileSchema(EIP712_ORDER_SCHEMA); - }, - getOrderHashBuffer(order: SignedOrder | UnsignedOrder): Buffer { - const makerAssetDataHash = crypto.solSHA3([ethUtil.toBuffer(order.makerAssetData)]); - const takerAssetDataHash = crypto.solSHA3([ethUtil.toBuffer(order.takerAssetData)]); - - const orderParamsHashBuff = crypto.solSHA3([ - orderUtils.getOrderSchemaBuffer(), - EIP712Utils.pad32Address(order.makerAddress), - EIP712Utils.pad32Address(order.takerAddress), - EIP712Utils.pad32Address(order.feeRecipientAddress), - EIP712Utils.pad32Address(order.senderAddress), - order.makerAssetAmount, - order.takerAssetAmount, - order.makerFee, - order.takerFee, - order.expirationTimeSeconds, - order.salt, - makerAssetDataHash, - takerAssetDataHash, - ]); - const orderParamsHashHex = `0x${orderParamsHashBuff.toString('hex')}`; - const orderHashBuff = EIP712Utils.createEIP712Message(orderParamsHashHex, order.exchangeAddress); - return orderHashBuff; - }, - getOrderHashHex(order: SignedOrder | UnsignedOrder): string { - const orderHashBuff = orderUtils.getOrderHashBuffer(order); - const orderHashHex = `0x${orderHashBuff.toString('hex')}`; - return orderHashHex; - }, createMatchOrders(signedOrderLeft: SignedOrder, signedOrderRight: SignedOrder): MatchOrder { const fill = { left: orderUtils.getOrderWithoutExchangeAddress(signedOrderLeft), |