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 | 9e2f8bead9a51a4c30b77781ae3b39bed31c36ee (patch) | |
tree | 5f593087ce3eeb643dfcb16b139cc6f23a2fd471 /packages/contracts | |
parent | 942867179c05e901450a7a08872dd523122a2f81 (diff) | |
download | dexon-sol-tools-9e2f8bead9a51a4c30b77781ae3b39bed31c36ee.tar dexon-sol-tools-9e2f8bead9a51a4c30b77781ae3b39bed31c36ee.tar.gz dexon-sol-tools-9e2f8bead9a51a4c30b77781ae3b39bed31c36ee.tar.bz2 dexon-sol-tools-9e2f8bead9a51a4c30b77781ae3b39bed31c36ee.tar.lz dexon-sol-tools-9e2f8bead9a51a4c30b77781ae3b39bed31c36ee.tar.xz dexon-sol-tools-9e2f8bead9a51a4c30b77781ae3b39bed31c36ee.tar.zst dexon-sol-tools-9e2f8bead9a51a4c30b77781ae3b39bed31c36ee.zip |
Merge development
Diffstat (limited to 'packages/contracts')
-rw-r--r-- | packages/contracts/test/exchange/core.ts | 17 | ||||
-rw-r--r-- | packages/contracts/util/exchange_wrapper.ts | 6 | ||||
-rw-r--r-- | packages/contracts/util/formatters.ts | 8 | ||||
-rw-r--r-- | packages/contracts/util/order.ts | 105 | ||||
-rw-r--r-- | packages/contracts/util/types.ts | 2 |
5 files changed, 15 insertions, 123 deletions
diff --git a/packages/contracts/test/exchange/core.ts b/packages/contracts/test/exchange/core.ts index d8d83711e..4fd837d51 100644 --- a/packages/contracts/test/exchange/core.ts +++ b/packages/contracts/test/exchange/core.ts @@ -441,11 +441,10 @@ describe('Exchange', () => { expect(signedOrder.feeRecipient).to.be.equal(logArgs.feeRecipient); expect(signedOrder.makerTokenAddress).to.be.equal(logArgs.makerToken); expect(signedOrder.takerTokenAddress).to.be.equal(logArgs.takerToken); - expect(expectedFilledMakerTokenAmount).to.be.bignumber.equal(logArgs.filledMakerTokenAmount); - expect(expectedFilledTakerTokenAmount).to.be.bignumber.equal(logArgs.filledTakerTokenAmount); + expect(expectedFilledMakerTokenAmount).to.be.bignumber.equal(logArgs.makerTokenFilledAmount); + expect(expectedFilledTakerTokenAmount).to.be.bignumber.equal(logArgs.takerTokenFilledAmount); expect(expectedFeeMPaid).to.be.bignumber.equal(logArgs.makerFeePaid); expect(expectedFeeTPaid).to.be.bignumber.equal(logArgs.takerFeePaid); - expect(expectedTokens).to.be.equal(logArgs.tokens); expect(ZeroEx.getOrderHashHex(signedOrder)).to.be.equal(logArgs.orderHash); }); @@ -472,11 +471,10 @@ describe('Exchange', () => { expect(signedOrder.feeRecipient).to.be.equal(logArgs.feeRecipient); expect(signedOrder.makerTokenAddress).to.be.equal(logArgs.makerToken); expect(signedOrder.takerTokenAddress).to.be.equal(logArgs.takerToken); - expect(expectedFilledMakerTokenAmount).to.be.bignumber.equal(logArgs.filledMakerTokenAmount); - expect(expectedFilledTakerTokenAmount).to.be.bignumber.equal(logArgs.filledTakerTokenAmount); + expect(expectedFilledMakerTokenAmount).to.be.bignumber.equal(logArgs.makerTokenFilledAmount); + expect(expectedFilledTakerTokenAmount).to.be.bignumber.equal(logArgs.takerTokenFilledAmount); expect(expectedFeeMPaid).to.be.bignumber.equal(logArgs.makerFeePaid); expect(expectedFeeTPaid).to.be.bignumber.equal(logArgs.takerFeePaid); - expect(expectedTokens).to.be.equal(logArgs.tokens); expect(ZeroEx.getOrderHashHex(signedOrder)).to.be.equal(logArgs.orderHash); }); @@ -764,7 +762,7 @@ describe('Exchange', () => { takerTokenFillAmount: signedOrder.takerTokenAmount, }); const log = res.logs[0] as LogWithDecodedArgs<LogFillContractEventArgs>; - expect(log.args.filledTakerTokenAmount).to.be.bignumber.equal( + expect(log.args.takerTokenFilledAmount).to.be.bignumber.equal( signedOrder.takerTokenAmount.minus(takerTokenCancelAmount), ); @@ -819,9 +817,8 @@ describe('Exchange', () => { expect(signedOrder.feeRecipient).to.be.equal(logArgs.feeRecipient); expect(signedOrder.makerTokenAddress).to.be.equal(logArgs.makerToken); expect(signedOrder.takerTokenAddress).to.be.equal(logArgs.takerToken); - expect(expectedCancelledMakerTokenAmount).to.be.bignumber.equal(logArgs.cancelledMakerTokenAmount); - expect(expectedCancelledTakerTokenAmount).to.be.bignumber.equal(logArgs.cancelledTakerTokenAmount); - expect(expectedTokens).to.be.equal(logArgs.tokens); + expect(expectedCancelledMakerTokenAmount).to.be.bignumber.equal(logArgs.makerTokenCancelledAmount); + expect(expectedCancelledTakerTokenAmount).to.be.bignumber.equal(logArgs.takerTokenCancelledAmount); expect(ZeroEx.getOrderHashHex(signedOrder)).to.be.equal(logArgs.orderHash); }); diff --git a/packages/contracts/util/exchange_wrapper.ts b/packages/contracts/util/exchange_wrapper.ts index 90744367a..d51efc025 100644 --- a/packages/contracts/util/exchange_wrapper.ts +++ b/packages/contracts/util/exchange_wrapper.ts @@ -144,13 +144,13 @@ export class ExchangeWrapper { public async batchCancelOrdersAsync( orders: SignedOrder[], from: string, - opts: { cancelTakerTokenAmounts?: BigNumber[] } = {}, + opts: { takerTokenCancelAmounts?: BigNumber[] } = {}, ): Promise<TransactionReceiptWithDecodedLogs> { - const params = formatters.createBatchCancel(orders, opts.cancelTakerTokenAmounts); + const params = formatters.createBatchCancel(orders, opts.takerTokenCancelAmounts); const txHash = await this._exchange.batchCancelOrders.sendTransactionAsync( params.orderAddresses, params.orderValues, - params.cancelTakerTokenAmounts, + params.takerTokenCancelAmounts, { from }, ); const tx = await this._zeroEx.awaitTransactionMinedAsync(txHash); diff --git a/packages/contracts/util/formatters.ts b/packages/contracts/util/formatters.ts index e3080af15..88e12a6b4 100644 --- a/packages/contracts/util/formatters.ts +++ b/packages/contracts/util/formatters.ts @@ -76,11 +76,11 @@ export const formatters = { }); return marketFillOrders; }, - createBatchCancel(signedOrders: SignedOrder[], cancelTakerTokenAmounts: BigNumber[] = []) { + createBatchCancel(signedOrders: SignedOrder[], takerTokenCancelAmounts: BigNumber[] = []) { const batchCancel: BatchCancelOrders = { orderAddresses: [], orderValues: [], - cancelTakerTokenAmounts, + takerTokenCancelAmounts, }; signedOrders.forEach(signedOrder => { batchCancel.orderAddresses.push([ @@ -98,8 +98,8 @@ export const formatters = { signedOrder.expirationUnixTimestampSec, signedOrder.salt, ]); - if (cancelTakerTokenAmounts.length < signedOrders.length) { - batchCancel.cancelTakerTokenAmounts.push(signedOrder.takerTokenAmount); + if (takerTokenCancelAmounts.length < signedOrders.length) { + batchCancel.takerTokenCancelAmounts.push(signedOrder.takerTokenAmount); } }); return batchCancel; 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; - } -} diff --git a/packages/contracts/util/types.ts b/packages/contracts/util/types.ts index a06e99532..2ffc84f04 100644 --- a/packages/contracts/util/types.ts +++ b/packages/contracts/util/types.ts @@ -32,7 +32,7 @@ export interface MarketFillOrders { export interface BatchCancelOrders { orderAddresses: string[][]; orderValues: BigNumber[][]; - cancelTakerTokenAmounts: BigNumber[]; + takerTokenCancelAmounts: BigNumber[]; } export interface DefaultOrderParams { |