diff options
Diffstat (limited to 'packages/0x.js')
-rw-r--r-- | packages/0x.js/CHANGELOG.md | 5 | ||||
-rw-r--r-- | packages/0x.js/package.json | 24 | ||||
-rw-r--r-- | packages/0x.js/src/contract_wrappers/exchange_wrapper.ts | 6 | ||||
-rw-r--r-- | packages/0x.js/test/exchange_wrapper_test.ts | 33 |
4 files changed, 51 insertions, 17 deletions
diff --git a/packages/0x.js/CHANGELOG.md b/packages/0x.js/CHANGELOG.md index ab2537879..84997389a 100644 --- a/packages/0x.js/CHANGELOG.md +++ b/packages/0x.js/CHANGELOG.md @@ -1,9 +1,10 @@ # CHANGELOG -## v0.x.x - _TBD, 2018_ +## v0.30.0 - _January 17, 2018_ * Add an error parameter to the order watcher callback (#312) - * Fix the bug making it impossible to catch some errors from awaitTransactionMinedAsync (#312) + * Fix a bug making it impossible to catch some errors from awaitTransactionMinedAsync (#312) + * Fix a bug in fillOrdersUpTo validation making it impossible to fill up to if user doesn't have enough balance to fully fill all the orders (#321) ## v0.29.1 - _January 11, 2018_ diff --git a/packages/0x.js/package.json b/packages/0x.js/package.json index f9b92f21b..1405e1bf7 100644 --- a/packages/0x.js/package.json +++ b/packages/0x.js/package.json @@ -1,6 +1,6 @@ { "name": "0x.js", - "version": "0.29.2", + "version": "0.30.0", "description": "A javascript library for interacting with the 0x protocol", "keywords": ["0x.js", "0xproject", "ethereum", "tokens", "exchange"], "main": "lib/src/index.js", @@ -38,10 +38,10 @@ "node": ">=6.0.0" }, "devDependencies": { - "@0xproject/abi-gen": "^0.1.1", - "@0xproject/dev-utils": "^0.0.4", - "@0xproject/tslint-config": "^0.4.1", - "@0xproject/types": "^0.1.3", + "@0xproject/abi-gen": "^0.1.2", + "@0xproject/dev-utils": "^0.0.5", + "@0xproject/tslint-config": "^0.4.2", + "@0xproject/types": "^0.1.4", "@types/bintrees": "^1.0.2", "@types/jsonschema": "^1.1.1", "@types/lodash": "^4.14.86", @@ -52,9 +52,9 @@ "awesome-typescript-loader": "^3.1.3", "chai": "^4.0.1", "chai-as-promised": "^7.1.0", - "chai-as-promised-typescript-typings": "^0.0.3", + "chai-as-promised-typescript-typings": "^0.0.4", "chai-bignumber": "^2.0.1", - "chai-typescript-typings": "^0.0.1", + "chai-typescript-typings": "^0.0.2", "copyfiles": "^1.2.0", "coveralls": "^3.0.0", "dirty-chai": "^2.0.1", @@ -73,14 +73,14 @@ "typedoc": "~0.8.0", "typescript": "~2.6.1", "web3-provider-engine": "^13.0.1", - "web3-typescript-typings": "^0.9.3", + "web3-typescript-typings": "^0.9.4", "webpack": "^3.1.0" }, "dependencies": { - "@0xproject/assert": "^0.0.10", - "@0xproject/json-schemas": "^0.7.2", - "@0xproject/utils": "^0.1.3", - "@0xproject/web3-wrapper": "^0.1.4", + "@0xproject/assert": "^0.0.11", + "@0xproject/json-schemas": "^0.7.3", + "@0xproject/utils": "^0.2.0", + "@0xproject/web3-wrapper": "^0.1.5", "bintrees": "^1.0.2", "bn.js": "^4.11.8", "ethereumjs-abi": "^0.6.4", diff --git a/packages/0x.js/src/contract_wrappers/exchange_wrapper.ts b/packages/0x.js/src/contract_wrappers/exchange_wrapper.ts index e1d80e01a..be88cdb20 100644 --- a/packages/0x.js/src/contract_wrappers/exchange_wrapper.ts +++ b/packages/0x.js/src/contract_wrappers/exchange_wrapper.ts @@ -258,16 +258,18 @@ export class ExchangeWrapper extends ContractWrapper { ? SHOULD_VALIDATE_BY_DEFAULT : orderTransactionOpts.shouldValidate; if (shouldValidate) { + let filledTakerTokenAmount = new BigNumber(0); const zrxTokenAddress = this.getZRXTokenAddress(); const exchangeTradeEmulator = new ExchangeTransferSimulator(this._tokenWrapper, BlockParamLiteral.Latest); for (const signedOrder of signedOrders) { - await this._orderValidationUtils.validateFillOrderThrowIfInvalidAsync( + const singleFilledTakerTokenAmount = await this._orderValidationUtils.validateFillOrderThrowIfInvalidAsync( exchangeTradeEmulator, signedOrder, - fillTakerTokenAmount, + fillTakerTokenAmount.minus(filledTakerTokenAmount), takerAddress, zrxTokenAddress, ); + filledTakerTokenAmount = filledTakerTokenAmount.plus(singleFilledTakerTokenAmount); } } diff --git a/packages/0x.js/test/exchange_wrapper_test.ts b/packages/0x.js/test/exchange_wrapper_test.ts index 39a5be61d..d2a2149a0 100644 --- a/packages/0x.js/test/exchange_wrapper_test.ts +++ b/packages/0x.js/test/exchange_wrapper_test.ts @@ -536,7 +536,7 @@ describe('ExchangeWrapper', () => { ), ).to.be.rejectedWith(ExchangeContractErrs.BatchOrdersMustHaveAtLeastOneItem); }); - it('should successfully fill up to specified amount', async () => { + it('should successfully fill up to specified amount when all orders are fully funded', async () => { const txHash = await zeroEx.exchange.fillOrdersUpToAsync( signedOrders, fillUpToAmount, @@ -550,6 +550,37 @@ describe('ExchangeWrapper', () => { const remainingFillAmount = fillableAmount.minus(1); expect(anotherFilledAmount).to.be.bignumber.equal(remainingFillAmount); }); + it('should successfully fill up to specified amount even if filling all orders would fail', async () => { + const missingBalance = new BigNumber(1); // User will still have enough balance to fill up to 9, + // but won't have 10 to fully fill all orders in a batch. + await zeroEx.token.transferAsync(makerTokenAddress, makerAddress, coinbase, missingBalance); + const txHash = await zeroEx.exchange.fillOrdersUpToAsync( + signedOrders, + fillUpToAmount, + shouldThrowOnInsufficientBalanceOrAllowance, + takerAddress, + ); + await zeroEx.awaitTransactionMinedAsync(txHash); + const filledAmount = await zeroEx.exchange.getFilledTakerAmountAsync(signedOrderHashHex); + const anotherFilledAmount = await zeroEx.exchange.getFilledTakerAmountAsync(anotherOrderHashHex); + expect(filledAmount).to.be.bignumber.equal(fillableAmount); + const remainingFillAmount = fillableAmount.minus(1); + expect(anotherFilledAmount).to.be.bignumber.equal(remainingFillAmount); + }); + }); + describe('failed batch fills', () => { + it("should fail validation if user doesn't have enough balance without fill up to", async () => { + const missingBalance = new BigNumber(2); // User will only have enough balance to fill up to 8 + await zeroEx.token.transferAsync(makerTokenAddress, makerAddress, coinbase, missingBalance); + return expect( + zeroEx.exchange.fillOrdersUpToAsync( + signedOrders, + fillUpToAmount, + shouldThrowOnInsufficientBalanceOrAllowance, + takerAddress, + ), + ).to.be.rejectedWith(ExchangeContractErrs.InsufficientMakerBalance); + }); }); describe('order transaction options', () => { const emptyFillUpToAmount = new BigNumber(0); |