diff options
author | Amir Bandeali <abandeali1@gmail.com> | 2018-02-09 09:48:06 +0800 |
---|---|---|
committer | Amir Bandeali <abandeali1@gmail.com> | 2018-04-21 04:56:16 +0800 |
commit | 5fd378e4ceec96ae69085b5962a3e1b03c60246d (patch) | |
tree | 594b4a8cd220c34e750903aa72e382647efe7851 /packages/contracts | |
parent | 382f24c55643f1a7b3d1d7c9879785abeeda7095 (diff) | |
download | dexon-sol-tools-5fd378e4ceec96ae69085b5962a3e1b03c60246d.tar dexon-sol-tools-5fd378e4ceec96ae69085b5962a3e1b03c60246d.tar.gz dexon-sol-tools-5fd378e4ceec96ae69085b5962a3e1b03c60246d.tar.bz2 dexon-sol-tools-5fd378e4ceec96ae69085b5962a3e1b03c60246d.tar.lz dexon-sol-tools-5fd378e4ceec96ae69085b5962a3e1b03c60246d.tar.xz dexon-sol-tools-5fd378e4ceec96ae69085b5962a3e1b03c60246d.tar.zst dexon-sol-tools-5fd378e4ceec96ae69085b5962a3e1b03c60246d.zip |
Merge development
Diffstat (limited to 'packages/contracts')
-rw-r--r-- | packages/contracts/util/order.ts | 105 |
1 files changed, 0 insertions, 105 deletions
diff --git a/packages/contracts/util/order.ts b/packages/contracts/util/order.ts deleted file mode 100644 index b42149d38..000000000 --- a/packages/contracts/util/order.ts +++ /dev/null @@ -1,105 +0,0 @@ -import { BigNumber } from '@0xproject/utils'; -import { Web3Wrapper } from '@0xproject/web3-wrapper'; -import ethUtil = require('ethereumjs-util'); -import * as _ from 'lodash'; - -import { crypto } from './crypto'; -import { OrderParams } from './types'; - -export class Order { - public params: OrderParams; - private _web3Wrapper: Web3Wrapper; - constructor(web3Wrapper: Web3Wrapper, params: OrderParams) { - this.params = params; - this._web3Wrapper = web3Wrapper; - } - public isValidSignature() { - const { v, r, s } = this.params; - if (_.isUndefined(v) || _.isUndefined(r) || _.isUndefined(s)) { - throw new Error('Cannot call isValidSignature on unsigned order'); - } - const orderHash = this._getOrderHash(); - const msgHash = ethUtil.hashPersonalMessage(ethUtil.toBuffer(orderHash)); - try { - const pubKey = ethUtil.ecrecover(msgHash, v, ethUtil.toBuffer(r), ethUtil.toBuffer(s)); - const recoveredAddress = ethUtil.bufferToHex(ethUtil.pubToAddress(pubKey)); - return recoveredAddress === this.params.maker; - } catch (err) { - return false; - } - } - public async signAsync() { - const orderHash = this._getOrderHash(); - const signature = await this._web3Wrapper.signTransactionAsync(this.params.maker, orderHash); - const { v, r, s } = ethUtil.fromRpcSig(signature); - this.params = _.assign(this.params, { - orderHashHex: orderHash, - v, - r: ethUtil.bufferToHex(r), - s: ethUtil.bufferToHex(s), - }); - } - public createFill(takerTokenFillAmount?: BigNumber) { - const fill = { - orderAddresses: [ - this.params.maker, - this.params.taker, - this.params.makerToken, - this.params.takerToken, - this.params.feeRecipient, - ], - orderValues: [ - this.params.makerTokenAmount, - this.params.takerTokenAmount, - this.params.makerFee, - this.params.takerFee, - this.params.expirationTimestampInSec, - this.params.salt, - ], - takerTokenFillAmount: takerTokenFillAmount || this.params.takerTokenAmount, - v: this.params.v, - r: this.params.r, - s: this.params.s, - }; - return fill; - } - public createCancel(takerTokenCancelAmount?: BigNumber) { - const cancel = { - orderAddresses: [ - this.params.maker, - this.params.taker, - this.params.makerToken, - this.params.takerToken, - this.params.feeRecipient, - ], - orderValues: [ - this.params.makerTokenAmount, - this.params.takerTokenAmount, - this.params.makerFee, - this.params.takerFee, - this.params.expirationTimestampInSec, - this.params.salt, - ], - takerTokenCancelAmount: takerTokenCancelAmount || this.params.takerTokenAmount, - }; - return cancel; - } - private _getOrderHash(): string { - const orderHash = crypto.solSHA3([ - this.params.exchangeContractAddress, - this.params.maker, - this.params.taker, - this.params.makerToken, - this.params.takerToken, - this.params.feeRecipient, - this.params.makerTokenAmount, - this.params.takerTokenAmount, - this.params.makerFee, - this.params.takerFee, - this.params.expirationTimestampInSec, - this.params.salt, - ]); - const orderHashHex = ethUtil.bufferToHex(orderHash); - return orderHashHex; - } -} |