diff options
author | Leonid Logvinov <logvinov.leon@gmail.com> | 2018-02-07 20:41:30 +0800 |
---|---|---|
committer | Leonid Logvinov <logvinov.leon@gmail.com> | 2018-02-07 20:41:30 +0800 |
commit | 568e4d33f29db2f5c0195585438e18ab4b2aea18 (patch) | |
tree | 4f2372dc040f4354d51cfb2229391cfd7c033264 /packages/contracts/util/order_factory.ts | |
parent | fd004032cb23998184a78ac4a0a486ef1bd04c25 (diff) | |
download | dexon-0x-contracts-568e4d33f29db2f5c0195585438e18ab4b2aea18.tar dexon-0x-contracts-568e4d33f29db2f5c0195585438e18ab4b2aea18.tar.gz dexon-0x-contracts-568e4d33f29db2f5c0195585438e18ab4b2aea18.tar.bz2 dexon-0x-contracts-568e4d33f29db2f5c0195585438e18ab4b2aea18.tar.lz dexon-0x-contracts-568e4d33f29db2f5c0195585438e18ab4b2aea18.tar.xz dexon-0x-contracts-568e4d33f29db2f5c0195585438e18ab4b2aea18.tar.zst dexon-0x-contracts-568e4d33f29db2f5c0195585438e18ab4b2aea18.zip |
Use Order and SignedOrder type from 0x.js
Diffstat (limited to 'packages/contracts/util/order_factory.ts')
-rw-r--r-- | packages/contracts/util/order_factory.ts | 44 |
1 files changed, 24 insertions, 20 deletions
diff --git a/packages/contracts/util/order_factory.ts b/packages/contracts/util/order_factory.ts index 788f60a88..8ba5df24a 100644 --- a/packages/contracts/util/order_factory.ts +++ b/packages/contracts/util/order_factory.ts @@ -1,33 +1,37 @@ -import { ZeroEx } from '0x.js'; +import { Order, SignedOrder, ZeroEx } from '0x.js'; import { BigNumber } from '@0xproject/utils'; import { Web3Wrapper } from '@0xproject/web3-wrapper'; import * as _ from 'lodash'; -import { Order } from './order'; -import { SignedOrder } from './signed_order'; -import { DefaultOrderParams, OptionalOrderParams, OrderParams } from './types'; +import { DefaultOrderParams } from './types'; export class OrderFactory { - private _defaultOrderParams: DefaultOrderParams; - private _web3Wrapper: Web3Wrapper; - constructor(web3Wrapper: Web3Wrapper, defaultOrderParams: DefaultOrderParams) { + private _defaultOrderParams: Partial<Order>; + private _zeroEx: ZeroEx; + constructor(zeroEx: ZeroEx, defaultOrderParams: Partial<Order>) { this._defaultOrderParams = defaultOrderParams; - this._web3Wrapper = web3Wrapper; + this._zeroEx = zeroEx; } - public async newSignedOrderAsync(customOrderParams: OptionalOrderParams = {}): Promise<SignedOrder> { + public async newSignedOrderAsync(customOrderParams: Partial<Order> = {}): Promise<SignedOrder> { const randomExpiration = new BigNumber(Math.floor((Date.now() + Math.random() * 100000000000) / 1000)); - const orderParams: OrderParams = _.assign( - {}, - { - expirationTimestampInSec: randomExpiration, - salt: ZeroEx.generatePseudoRandomSalt(), - taker: ZeroEx.NULL_ADDRESS, - }, - this._defaultOrderParams, - customOrderParams, + const order = ({ + expirationUnixTimestampSec: randomExpiration, + salt: ZeroEx.generatePseudoRandomSalt(), + taker: ZeroEx.NULL_ADDRESS, + ...this._defaultOrderParams, + ...customOrderParams, + } as any) as Order; + const orderHashHex = ZeroEx.getOrderHashHex(order); + const shouldAddPersonalMessagePrefix = false; + const ecSignature = await this._zeroEx.signOrderHashAsync( + orderHashHex, + order.maker, + shouldAddPersonalMessagePrefix, ); - const order = new Order(this._web3Wrapper, orderParams); - const signedOrder = await order.signAsync(); + const signedOrder = { + ...order, + ecSignature, + }; return signedOrder; } } |