From 315e4015de71c0b829ffd20e991108084bfc7bda Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Mon, 13 Nov 2017 17:59:18 -0500 Subject: Return remainingFillableTakerAmount --- packages/0x.js/src/utils/order_state_utils.ts | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'packages/0x.js/src/utils') diff --git a/packages/0x.js/src/utils/order_state_utils.ts b/packages/0x.js/src/utils/order_state_utils.ts index f82601cae..cc4933d39 100644 --- a/packages/0x.js/src/utils/order_state_utils.ts +++ b/packages/0x.js/src/utils/order_state_utils.ts @@ -78,6 +78,9 @@ export class OrderStateUtils { .dividedToIntegerBy(totalTakerTokenAmount); const fillableMakerTokenAmount = BigNumber.min([makerProxyAllowance, makerBalance]); const remainingFillableMakerTokenAmount = BigNumber.min(fillableMakerTokenAmount, remainingMakerTokenAmount); + const remainingFillableTakerTokenAmount = remainingFillableMakerTokenAmount + .times(totalTakerTokenAmount) + .dividedToIntegerBy(totalMakerTokenAmount); // TODO: Handle edge case where maker token is ZRX with fee const orderRelevantState = { makerBalance, @@ -87,6 +90,7 @@ export class OrderStateUtils { filledTakerTokenAmount, canceledTakerTokenAmount, remainingFillableMakerTokenAmount, + remainingFillableTakerTokenAmount, }; return orderRelevantState; } -- cgit v1.2.3 From f936363440bce82f544dc50b41056e09c5bcc9fd Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Mon, 13 Nov 2017 18:09:18 -0500 Subject: Add validation for rounding error --- packages/0x.js/src/utils/order_state_utils.ts | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'packages/0x.js/src/utils') diff --git a/packages/0x.js/src/utils/order_state_utils.ts b/packages/0x.js/src/utils/order_state_utils.ts index cc4933d39..21d842a77 100644 --- a/packages/0x.js/src/utils/order_state_utils.ts +++ b/packages/0x.js/src/utils/order_state_utils.ts @@ -117,6 +117,13 @@ export class OrderStateUtils { throw new Error(ExchangeContractErrs.InsufficientMakerFeeAllowance); } } + const minimumFillableTakerTokenAmountWithingNoRoundingErrorRange = signedOrder.takerTokenAmount + .times(1000) + .dividedBy(signedOrder.makerTokenAmount); + if (orderRelevantState.remainingFillableTakerTokenAmount + .lessThan(minimumFillableTakerTokenAmountWithingNoRoundingErrorRange)) { + throw new Error(ExchangeContractErrs.OrderFillRoundingError); + } // TODO Add linear function solver when maker token is ZRX #badass // Return the max amount that's fillable } -- cgit v1.2.3 From 49898525afde7e6a761220fcc46dc16993d85c03 Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Mon, 13 Nov 2017 20:56:01 -0500 Subject: Fix tslint issue --- packages/0x.js/src/utils/abi_decoder.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'packages/0x.js/src/utils') diff --git a/packages/0x.js/src/utils/abi_decoder.ts b/packages/0x.js/src/utils/abi_decoder.ts index 840ad9be0..df0fb2d6f 100644 --- a/packages/0x.js/src/utils/abi_decoder.ts +++ b/packages/0x.js/src/utils/abi_decoder.ts @@ -34,7 +34,7 @@ export class AbiDecoder { value = this.padZeros(new BigNumber(value).toString(16)); } else if (param.type === SolidityTypes.Uint256 || param.type === SolidityTypes.Uint8 || - param.type === SolidityTypes.Uint ) { + param.type === SolidityTypes.Uint) { value = new BigNumber(value); } decodedParams[param.name] = value; -- cgit v1.2.3 From 56b5619d24b44d23f770b58b0c9e1d4a63b89aca Mon Sep 17 00:00:00 2001 From: Brandon Millman Date: Mon, 13 Nov 2017 19:32:01 -0500 Subject: Add json-schemas package to mono repo --- packages/0x.js/src/utils/assert.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'packages/0x.js/src/utils') diff --git a/packages/0x.js/src/utils/assert.ts b/packages/0x.js/src/utils/assert.ts index 4aa83ef17..63d975c03 100644 --- a/packages/0x.js/src/utils/assert.ts +++ b/packages/0x.js/src/utils/assert.ts @@ -1,7 +1,7 @@ import * as _ from 'lodash'; import * as Web3 from 'web3'; import BigNumber from 'bignumber.js'; -import {SchemaValidator, Schema} from '0x-json-schemas'; +import {SchemaValidator, Schema} from '@0xproject/json-schemas'; import {assert as sharedAssert} from '@0xproject/assert'; import {Web3Wrapper} from '../web3_wrapper'; import {signatureUtils} from '../utils/signature_utils'; -- cgit v1.2.3 From 61496d77a5d3d50d7b41a0732af375fd973fa384 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Tue, 14 Nov 2017 11:03:01 -0500 Subject: Fix namings --- packages/0x.js/src/utils/order_state_utils.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'packages/0x.js/src/utils') diff --git a/packages/0x.js/src/utils/order_state_utils.ts b/packages/0x.js/src/utils/order_state_utils.ts index 21d842a77..8f5c379cd 100644 --- a/packages/0x.js/src/utils/order_state_utils.ts +++ b/packages/0x.js/src/utils/order_state_utils.ts @@ -117,11 +117,11 @@ export class OrderStateUtils { throw new Error(ExchangeContractErrs.InsufficientMakerFeeAllowance); } } - const minimumFillableTakerTokenAmountWithingNoRoundingErrorRange = signedOrder.takerTokenAmount + const minFillableTakerTokenAmountWithinNoRoundingErrorRange = signedOrder.takerTokenAmount .times(1000) .dividedBy(signedOrder.makerTokenAmount); if (orderRelevantState.remainingFillableTakerTokenAmount - .lessThan(minimumFillableTakerTokenAmountWithingNoRoundingErrorRange)) { + .lessThan(minFillableTakerTokenAmountWithinNoRoundingErrorRange)) { throw new Error(ExchangeContractErrs.OrderFillRoundingError); } // TODO Add linear function solver when maker token is ZRX #badass -- cgit v1.2.3 From dcfe8bae1cf0dfa483ad0a3e8800dcb2b38940c7 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Tue, 14 Nov 2017 11:11:09 -0500 Subject: Name a constant --- packages/0x.js/src/utils/order_state_utils.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'packages/0x.js/src/utils') diff --git a/packages/0x.js/src/utils/order_state_utils.ts b/packages/0x.js/src/utils/order_state_utils.ts index 8f5c379cd..af6392c81 100644 --- a/packages/0x.js/src/utils/order_state_utils.ts +++ b/packages/0x.js/src/utils/order_state_utils.ts @@ -18,6 +18,8 @@ import {constants} from '../utils/constants'; import {OrderFilledCancelledLazyStore} from '../stores/order_filled_cancelled_lazy_store'; import {BalanceAndProxyAllowanceLazyStore} from '../stores/balance_proxy_allowance_lazy_store'; +const ACCEPTABLE_RELATIVE_ROUNDING_ERROR = 0.0001; + export class OrderStateUtils { private balanceAndProxyAllowanceLazyStore: BalanceAndProxyAllowanceLazyStore; private orderFilledCancelledLazyStore: OrderFilledCancelledLazyStore; @@ -118,8 +120,8 @@ export class OrderStateUtils { } } const minFillableTakerTokenAmountWithinNoRoundingErrorRange = signedOrder.takerTokenAmount - .times(1000) - .dividedBy(signedOrder.makerTokenAmount); + .dividedBy(ACCEPTABLE_RELATIVE_ROUNDING_ERROR) + .dividedBy(signedOrder.makerTokenAmount); if (orderRelevantState.remainingFillableTakerTokenAmount .lessThan(minFillableTakerTokenAmountWithinNoRoundingErrorRange)) { throw new Error(ExchangeContractErrs.OrderFillRoundingError); -- cgit v1.2.3 From 5b5c31861a9861a9863e0cf9a14eee3d34a0e425 Mon Sep 17 00:00:00 2001 From: Brandon Millman Date: Tue, 14 Nov 2017 22:23:41 -0500 Subject: Change the way 0x.js assert extends the @0xproject/assert module --- packages/0x.js/src/utils/assert.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'packages/0x.js/src/utils') diff --git a/packages/0x.js/src/utils/assert.ts b/packages/0x.js/src/utils/assert.ts index 63d975c03..55912525c 100644 --- a/packages/0x.js/src/utils/assert.ts +++ b/packages/0x.js/src/utils/assert.ts @@ -9,7 +9,8 @@ import {ECSignature} from '../types'; const HEX_REGEX = /^0x[0-9A-F]*$/i; -export const assert = _.extend({}, sharedAssert, { +export const assert = { + ...sharedAssert, isValidSignature(orderHash: string, ecSignature: ECSignature, signerAddress: string) { const isValidSignature = signatureUtils.isValidSignature(orderHash, ecSignature, signerAddress); this.assert(isValidSignature, `Expected order with hash '${orderHash}' to have a valid signature`); @@ -26,4 +27,4 @@ export const assert = _.extend({}, sharedAssert, { const availableAddresses = await web3Wrapper.getAvailableAddressesAsync(); this.assert(!_.isEmpty(availableAddresses), 'No addresses were available on the provided web3 provider'); }, -}); +}; -- cgit v1.2.3