diff options
author | Leonid Logvinov <logvinov.leon@gmail.com> | 2019-01-18 20:07:19 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-01-18 20:07:19 +0800 |
commit | bf653327638149816769027b0fde2d2e44a6fed0 (patch) | |
tree | 954985c17cf11eb5321b48a377523565bbf09733 /packages | |
parent | e6fe728bcbbab0c500fc7adee1439505282e8eca (diff) | |
parent | 3973dec9944a10c62ec6c3d15d973a00a6ea45a6 (diff) | |
download | dexon-sol-tools-bf653327638149816769027b0fde2d2e44a6fed0.tar dexon-sol-tools-bf653327638149816769027b0fde2d2e44a6fed0.tar.gz dexon-sol-tools-bf653327638149816769027b0fde2d2e44a6fed0.tar.bz2 dexon-sol-tools-bf653327638149816769027b0fde2d2e44a6fed0.tar.lz dexon-sol-tools-bf653327638149816769027b0fde2d2e44a6fed0.tar.xz dexon-sol-tools-bf653327638149816769027b0fde2d2e44a6fed0.tar.zst dexon-sol-tools-bf653327638149816769027b0fde2d2e44a6fed0.zip |
Merge branch 'development' into feature/new-ganache
Diffstat (limited to 'packages')
96 files changed, 441 insertions, 139 deletions
diff --git a/packages/0x.js/CHANGELOG.json b/packages/0x.js/CHANGELOG.json index 276bdd479..20778f8bb 100644 --- a/packages/0x.js/CHANGELOG.json +++ b/packages/0x.js/CHANGELOG.json @@ -1,5 +1,14 @@ [ { + "version": "4.0.0", + "changes": [ + { + "note": "Upgrade the bignumber.js to v8.0.2", + "pr": 1517 + } + ] + }, + { "timestamp": 1547747677, "version": "3.0.3", "changes": [ diff --git a/packages/0x.js/package.json b/packages/0x.js/package.json index f4f1c82e0..64054d288 100644 --- a/packages/0x.js/package.json +++ b/packages/0x.js/package.json @@ -54,7 +54,7 @@ "awesome-typescript-loader": "^5.2.1", "chai": "^4.0.1", "chai-as-promised": "^7.1.0", - "chai-bignumber": "^2.0.1", + "chai-bignumber": "^3.0.0", "copyfiles": "^2.0.0", "dirty-chai": "^2.0.1", "make-promises-safe": "^1.1.0", diff --git a/packages/abi-gen-templates/CHANGELOG.json b/packages/abi-gen-templates/CHANGELOG.json index b825c4f1f..7d444d0ca 100644 --- a/packages/abi-gen-templates/CHANGELOG.json +++ b/packages/abi-gen-templates/CHANGELOG.json @@ -1,5 +1,14 @@ [ { + "version": "2.0.0", + "changes": [ + { + "note": "Upgrade the bignumber.js to v8.0.2", + "pr": 1517 + } + ] + }, + { "timestamp": 1547561734, "version": "1.0.2", "changes": [ diff --git a/packages/abi-gen-wrappers/CHANGELOG.json b/packages/abi-gen-wrappers/CHANGELOG.json index 381b37cda..c604302b5 100644 --- a/packages/abi-gen-wrappers/CHANGELOG.json +++ b/packages/abi-gen-wrappers/CHANGELOG.json @@ -1,5 +1,14 @@ [ { + "version": "3.0.0", + "changes": [ + { + "note": "Upgrade the bignumber.js to v8.0.2", + "pr": 1517 + } + ] + }, + { "version": "2.2.0", "changes": [ { diff --git a/packages/abi-gen/CHANGELOG.json b/packages/abi-gen/CHANGELOG.json index ab516e4c6..173617b65 100644 --- a/packages/abi-gen/CHANGELOG.json +++ b/packages/abi-gen/CHANGELOG.json @@ -1,5 +1,14 @@ [ { + "version": "2.0.0", + "changes": [ + { + "note": "Upgrade the bignumber.js to v8.0.2", + "pr": 1517 + } + ] + }, + { "timestamp": 1547561734, "version": "1.0.22", "changes": [ diff --git a/packages/assert/CHANGELOG.json b/packages/assert/CHANGELOG.json index 0210f9400..278b7dfa1 100644 --- a/packages/assert/CHANGELOG.json +++ b/packages/assert/CHANGELOG.json @@ -1,5 +1,14 @@ [ { + "version": "2.0.0", + "changes": [ + { + "note": "Upgrade the bignumber.js to v8.0.2", + "pr": 1517 + } + ] + }, + { "timestamp": 1547561734, "version": "1.0.23", "changes": [ diff --git a/packages/assert/src/index.ts b/packages/assert/src/index.ts index 2d28d51e1..741bd78e1 100644 --- a/packages/assert/src/index.ts +++ b/packages/assert/src/index.ts @@ -7,12 +7,12 @@ const HEX_REGEX = /^0x[0-9A-F]*$/i; export const assert = { isBigNumber(variableName: string, value: BigNumber): void { - const isBigNumber = _.isObject(value) && (value as any).isBigNumber; + const isBigNumber = BigNumber.isBigNumber(value); assert.assert(isBigNumber, assert.typeAssertionMessage(variableName, 'BigNumber', value)); }, isValidBaseUnitAmount(variableName: string, value: BigNumber): void { assert.isBigNumber(variableName, value); - const isNegative = value.lessThan(0); + const isNegative = value.isLessThan(0); assert.assert(!isNegative, `${variableName} cannot be a negative number, found value: ${value.toNumber()}`); const hasDecimals = value.decimalPlaces() !== 0; assert.assert( diff --git a/packages/asset-buyer/CHANGELOG.json b/packages/asset-buyer/CHANGELOG.json index 3bb95fdba..2de603de0 100644 --- a/packages/asset-buyer/CHANGELOG.json +++ b/packages/asset-buyer/CHANGELOG.json @@ -1,5 +1,14 @@ [ { + "version": "5.0.0", + "changes": [ + { + "note": "Upgrade the bignumber.js to v8.0.2", + "pr": 1517 + } + ] + }, + { "version": "4.1.0", "changes": [ { diff --git a/packages/asset-buyer/package.json b/packages/asset-buyer/package.json index 454e9cc1c..0f79ac06a 100644 --- a/packages/asset-buyer/package.json +++ b/packages/asset-buyer/package.json @@ -56,7 +56,7 @@ "@types/node": "*", "chai": "^4.0.1", "chai-as-promised": "^7.1.0", - "chai-bignumber": "^2.0.1", + "chai-bignumber": "^3.0.0", "dirty-chai": "^2.0.1", "make-promises-safe": "^1.1.0", "mocha": "^4.1.0", diff --git a/packages/asset-buyer/src/utils/buy_quote_calculator.ts b/packages/asset-buyer/src/utils/buy_quote_calculator.ts index fcded6ab1..125841094 100644 --- a/packages/asset-buyer/src/utils/buy_quote_calculator.ts +++ b/packages/asset-buyer/src/utils/buy_quote_calculator.ts @@ -22,7 +22,7 @@ export const buyQuoteCalculator = { const remainingFillableMakerAssetAmounts = ordersAndFillableAmounts.remainingFillableMakerAssetAmounts; const feeOrders = feeOrdersAndFillableAmounts.orders; const remainingFillableFeeAmounts = feeOrdersAndFillableAmounts.remainingFillableMakerAssetAmounts; - const slippageBufferAmount = assetBuyAmount.mul(slippagePercentage).round(); + const slippageBufferAmount = assetBuyAmount.multipliedBy(slippagePercentage).integerValue(); // find the orders that cover the desired assetBuyAmount (with slippage) const { resultOrders, @@ -43,7 +43,9 @@ export const buyQuoteCalculator = { const multiplierNeededWithSlippage = new BigNumber(1).plus(slippagePercentage); // Given amountAvailableToFillConsideringSlippage * multiplierNeededWithSlippage = amountAbleToFill // We divide amountUnableToFill by multiplierNeededWithSlippage to determine amountAvailableToFillConsideringSlippage - const amountAvailableToFillConsideringSlippage = amountAbleToFill.div(multiplierNeededWithSlippage).floor(); + const amountAvailableToFillConsideringSlippage = amountAbleToFill + .div(multiplierNeededWithSlippage) + .integerValue(BigNumber.ROUND_FLOOR); throw new InsufficientAssetLiquidityError(amountAvailableToFillConsideringSlippage); } @@ -131,7 +133,7 @@ function calculateQuoteInfo( zrxEthAmount = findEthAmountNeededToBuyZrx(feeOrdersAndFillableAmounts, zrxAmountToBuyAsset); } // eth amount needed to buy the affiliate fee - const affiliateFeeEthAmount = assetEthAmount.mul(feePercentage).ceil(); + const affiliateFeeEthAmount = assetEthAmount.multipliedBy(feePercentage).integerValue(BigNumber.ROUND_CEIL); // eth amount needed for fees is the sum of affiliate fee and zrx fee const feeEthAmount = affiliateFeeEthAmount.plus(zrxEthAmount); // eth amount needed in total is the sum of the amount needed for the asset and the amount needed for fees @@ -168,9 +170,9 @@ function findEthAmountNeededToBuyZrx( order, makerFillAmount, ); - const extraFeeAmount = remainingFillableMakerAssetAmount.greaterThanOrEqualTo(adjustedMakerFillAmount) + const extraFeeAmount = remainingFillableMakerAssetAmount.isGreaterThanOrEqualTo(adjustedMakerFillAmount) ? constants.ZERO_AMOUNT - : adjustedMakerFillAmount.sub(makerFillAmount); + : adjustedMakerFillAmount.minus(makerFillAmount); return { totalEthAmount: totalEthAmount.plus(takerFillAmount), remainingZrxBuyAmount: BigNumber.max( diff --git a/packages/asset-buyer/src/utils/order_provider_response_processor.ts b/packages/asset-buyer/src/utils/order_provider_response_processor.ts index 4244d196c..f08cd6150 100644 --- a/packages/asset-buyer/src/utils/order_provider_response_processor.ts +++ b/packages/asset-buyer/src/utils/order_provider_response_processor.ts @@ -109,11 +109,8 @@ function getValidOrdersWithRemainingFillableMakerAssetAmountsFromOnChain( return accOrders; } // if the order IS fillable, add the order and calculate the remaining fillable amount - const transferrableAssetAmount = BigNumber.min([traderInfo.makerAllowance, traderInfo.makerBalance]); - const transferrableFeeAssetAmount = BigNumber.min([ - traderInfo.makerZrxAllowance, - traderInfo.makerZrxBalance, - ]); + const transferrableAssetAmount = BigNumber.min(traderInfo.makerAllowance, traderInfo.makerBalance); + const transferrableFeeAssetAmount = BigNumber.min(traderInfo.makerZrxAllowance, traderInfo.makerZrxBalance); const remainingTakerAssetAmount = order.takerAssetAmount.minus(orderInfo.orderTakerAssetFilledAmount); const remainingMakerAssetAmount = orderUtils.getRemainingMakerAmount(order, remainingTakerAssetAmount); const remainingFillableCalculator = new RemainingFillableCalculator( diff --git a/packages/asset-buyer/src/utils/order_utils.ts b/packages/asset-buyer/src/utils/order_utils.ts index 1cc2cf95f..3ea3cafd3 100644 --- a/packages/asset-buyer/src/utils/order_utils.ts +++ b/packages/asset-buyer/src/utils/order_utils.ts @@ -9,8 +9,8 @@ export const orderUtils = { }, willOrderExpire(order: SignedOrder, secondsFromNow: number): boolean { const millisecondsInSecond = 1000; - const currentUnixTimestampSec = new BigNumber(Date.now() / millisecondsInSecond).round(); - return order.expirationTimeSeconds.lessThan(currentUnixTimestampSec.plus(secondsFromNow)); + const currentUnixTimestampSec = new BigNumber(Date.now() / millisecondsInSecond).integerValue(); + return order.expirationTimeSeconds.isLessThan(currentUnixTimestampSec.plus(secondsFromNow)); }, isOpenOrder(order: SignedOrder): boolean { return order.takerAddress === constants.NULL_ADDRESS; @@ -20,43 +20,43 @@ export const orderUtils = { const remainingMakerAmount = remainingTakerAmount .times(order.makerAssetAmount) .div(order.takerAssetAmount) - .floor(); + .integerValue(BigNumber.ROUND_FLOOR); return remainingMakerAmount; }, // given a desired amount of makerAsset, calculate how much takerAsset is required to fill that amount getTakerFillAmount(order: SignedOrder, makerFillAmount: BigNumber): BigNumber { // Round up because exchange rate favors Maker const takerFillAmount = makerFillAmount - .mul(order.takerAssetAmount) + .multipliedBy(order.takerAssetAmount) .div(order.makerAssetAmount) - .ceil(); + .integerValue(BigNumber.ROUND_CEIL); return takerFillAmount; }, // given a desired amount of takerAsset to fill, calculate how much fee is required by the taker to fill that amount getTakerFeeAmount(order: SignedOrder, takerFillAmount: BigNumber): BigNumber { // Round down because Taker fee rate favors Taker const takerFeeAmount = takerFillAmount - .mul(order.takerFee) + .multipliedBy(order.takerFee) .div(order.takerAssetAmount) - .floor(); + .integerValue(BigNumber.ROUND_FLOOR); return takerFeeAmount; }, // given a desired amount of takerAsset to fill, calculate how much makerAsset will be filled getMakerFillAmount(order: SignedOrder, takerFillAmount: BigNumber): BigNumber { // Round down because exchange rate favors Maker const makerFillAmount = takerFillAmount - .mul(order.makerAssetAmount) + .multipliedBy(order.makerAssetAmount) .div(order.takerAssetAmount) - .floor(); + .integerValue(BigNumber.ROUND_FLOOR); return makerFillAmount; }, // given a desired amount of makerAsset, calculate how much fee is required by the maker to fill that amount getMakerFeeAmount(order: SignedOrder, makerFillAmount: BigNumber): BigNumber { // Round down because Maker fee rate favors Maker const makerFeeAmount = makerFillAmount - .mul(order.makerFee) + .multipliedBy(order.makerFee) .div(order.makerAssetAmount) - .floor(); + .integerValue(BigNumber.ROUND_FLOOR); return makerFeeAmount; }, // given a desired amount of ZRX from a fee order, calculate how much takerAsset is required to fill that amount @@ -64,9 +64,9 @@ export const orderUtils = { getTakerFillAmountForFeeOrder(order: SignedOrder, makerFillAmount: BigNumber): [BigNumber, BigNumber] { // For each unit of TakerAsset we buy (MakerAsset - TakerFee) const adjustedTakerFillAmount = makerFillAmount - .mul(order.takerAssetAmount) - .div(order.makerAssetAmount.sub(order.takerFee)) - .ceil(); + .multipliedBy(order.takerAssetAmount) + .div(order.makerAssetAmount.minus(order.takerFee)) + .integerValue(BigNumber.ROUND_CEIL); // The amount that we buy will be greater than makerFillAmount, since we buy some amount for fees. const adjustedMakerFillAmount = orderUtils.getMakerFillAmount(order, adjustedTakerFillAmount); return [adjustedTakerFillAmount, adjustedMakerFillAmount]; diff --git a/packages/asset-buyer/test/buy_quote_calculator_test.ts b/packages/asset-buyer/test/buy_quote_calculator_test.ts index 880f55180..177fd8fe6 100644 --- a/packages/asset-buyer/test/buy_quote_calculator_test.ts +++ b/packages/asset-buyer/test/buy_quote_calculator_test.ts @@ -234,7 +234,7 @@ describe('buyQuoteCalculator', () => { const expectedEthAmountForAsset = new BigNumber(50); const expectedEthAmountForZrxFees = new BigNumber(100); const expectedFillEthAmount = expectedEthAmountForAsset; - const expectedAffiliateFeeEthAmount = expectedEthAmountForAsset.mul(feePercentage); + const expectedAffiliateFeeEthAmount = expectedEthAmountForAsset.multipliedBy(feePercentage); const expectedFeeEthAmount = expectedAffiliateFeeEthAmount.plus(expectedEthAmountForZrxFees); const expectedTotalEthAmount = expectedFillEthAmount.plus(expectedFeeEthAmount); expect(buyQuote.bestCaseQuoteInfo.assetEthAmount).to.bignumber.equal(expectedFillEthAmount); @@ -272,7 +272,7 @@ describe('buyQuoteCalculator', () => { const expectedEthAmountForAsset = new BigNumber(50); const expectedEthAmountForZrxFees = new BigNumber(100); const expectedFillEthAmount = expectedEthAmountForAsset; - const expectedAffiliateFeeEthAmount = expectedEthAmountForAsset.mul(feePercentage); + const expectedAffiliateFeeEthAmount = expectedEthAmountForAsset.multipliedBy(feePercentage); const expectedFeeEthAmount = expectedAffiliateFeeEthAmount.plus(expectedEthAmountForZrxFees); const expectedTotalEthAmount = expectedFillEthAmount.plus(expectedFeeEthAmount); expect(buyQuote.bestCaseQuoteInfo.assetEthAmount).to.bignumber.equal(expectedFillEthAmount); @@ -282,7 +282,7 @@ describe('buyQuoteCalculator', () => { const expectedWorstEthAmountForAsset = new BigNumber(100); const expectedWorstEthAmountForZrxFees = new BigNumber(208); const expectedWorstFillEthAmount = expectedWorstEthAmountForAsset; - const expectedWorstAffiliateFeeEthAmount = expectedWorstEthAmountForAsset.mul(feePercentage); + const expectedWorstAffiliateFeeEthAmount = expectedWorstEthAmountForAsset.multipliedBy(feePercentage); const expectedWorstFeeEthAmount = expectedWorstAffiliateFeeEthAmount.plus(expectedWorstEthAmountForZrxFees); const expectedWorstTotalEthAmount = expectedWorstFillEthAmount.plus(expectedWorstFeeEthAmount); expect(buyQuote.worstCaseQuoteInfo.assetEthAmount).to.bignumber.equal(expectedWorstFillEthAmount); diff --git a/packages/base-contract/CHANGELOG.json b/packages/base-contract/CHANGELOG.json index 68ebe8d9e..63b1fe8f7 100644 --- a/packages/base-contract/CHANGELOG.json +++ b/packages/base-contract/CHANGELOG.json @@ -1,5 +1,14 @@ [ { + "version": "4.0.0", + "changes": [ + { + "note": "Upgrade the bignumber.js to v8.0.2", + "pr": 1517 + } + ] + }, + { "timestamp": 1547561734, "version": "3.0.13", "changes": [ diff --git a/packages/base-contract/src/index.ts b/packages/base-contract/src/index.ts index c2b7b943b..0238106f3 100644 --- a/packages/base-contract/src/index.ts +++ b/packages/base-contract/src/index.ts @@ -1,4 +1,4 @@ -import { AbiEncoder, abiUtils } from '@0x/utils'; +import { AbiEncoder, abiUtils, BigNumber } from '@0x/utils'; import { Web3Wrapper } from '@0x/web3-wrapper'; import { AbiDefinition, @@ -43,7 +43,7 @@ export class BaseContract { return type === 'address' ? value.toLowerCase() : value; } protected static _bigNumberToString(_type: string, value: any): any { - return _.isObject(value) && value.isBigNumber ? value.toString() : value; + return BigNumber.isBigNumber(value) ? value.toString() : value; } protected static _lookupConstructorAbi(abi: ContractAbi): ConstructorAbi { const constructorAbiIfExists = _.find( diff --git a/packages/connect/CHANGELOG.json b/packages/connect/CHANGELOG.json index 8fe9c562f..c2f16d96a 100644 --- a/packages/connect/CHANGELOG.json +++ b/packages/connect/CHANGELOG.json @@ -1,5 +1,14 @@ [ { + "version": "4.0.0", + "changes": [ + { + "note": "Upgrade the bignumber.js to v8.0.2", + "pr": 1517 + } + ] + }, + { "timestamp": 1547561734, "version": "3.0.13", "changes": [ diff --git a/packages/contract-wrappers/CHANGELOG.json b/packages/contract-wrappers/CHANGELOG.json index b9b910165..30199ae1d 100644 --- a/packages/contract-wrappers/CHANGELOG.json +++ b/packages/contract-wrappers/CHANGELOG.json @@ -1,5 +1,14 @@ [ { + "version": "6.0.0", + "changes": [ + { + "note": "Upgrade the bignumber.js to v8.0.2", + "pr": 1517 + } + ] + }, + { "timestamp": 1547747677, "version": "5.0.1", "changes": [ diff --git a/packages/contract-wrappers/package.json b/packages/contract-wrappers/package.json index 8cee730fe..cc7dc1a3e 100644 --- a/packages/contract-wrappers/package.json +++ b/packages/contract-wrappers/package.json @@ -49,7 +49,7 @@ "@types/web3-provider-engine": "^14.0.0", "chai": "^4.0.1", "chai-as-promised": "^7.1.0", - "chai-bignumber": "^2.0.1", + "chai-bignumber": "^3.0.0", "dirty-chai": "^2.0.1", "make-promises-safe": "^1.1.0", "mocha": "^4.1.0", diff --git a/packages/contract-wrappers/src/contract_wrappers/erc20_token_wrapper.ts b/packages/contract-wrappers/src/contract_wrappers/erc20_token_wrapper.ts index ad42cfd4f..cd79a0e5d 100644 --- a/packages/contract-wrappers/src/contract_wrappers/erc20_token_wrapper.ts +++ b/packages/contract-wrappers/src/contract_wrappers/erc20_token_wrapper.ts @@ -271,7 +271,7 @@ export class ERC20TokenWrapper extends ContractWrapper { const tokenContract = await this._getTokenContractAsync(normalizedTokenAddress); const fromAddressBalance = await this.getBalanceAsync(normalizedTokenAddress, normalizedFromAddress); - if (fromAddressBalance.lessThan(amountInBaseUnits)) { + if (fromAddressBalance.isLessThan(amountInBaseUnits)) { throw new Error(ContractWrappersError.InsufficientBalanceForTransfer); } @@ -327,12 +327,12 @@ export class ERC20TokenWrapper extends ContractWrapper { normalizedFromAddress, normalizedSenderAddress, ); - if (fromAddressAllowance.lessThan(amountInBaseUnits)) { + if (fromAddressAllowance.isLessThan(amountInBaseUnits)) { throw new Error(ContractWrappersError.InsufficientAllowanceForTransfer); } const fromAddressBalance = await this.getBalanceAsync(normalizedTokenAddress, normalizedFromAddress); - if (fromAddressBalance.lessThan(amountInBaseUnits)) { + if (fromAddressBalance.isLessThan(amountInBaseUnits)) { throw new Error(ContractWrappersError.InsufficientBalanceForTransfer); } diff --git a/packages/contract-wrappers/src/fetchers/asset_balance_and_proxy_allowance_fetcher.ts b/packages/contract-wrappers/src/fetchers/asset_balance_and_proxy_allowance_fetcher.ts index 1ff130a48..c35b24664 100644 --- a/packages/contract-wrappers/src/fetchers/asset_balance_and_proxy_allowance_fetcher.ts +++ b/packages/contract-wrappers/src/fetchers/asset_balance_and_proxy_allowance_fetcher.ts @@ -39,7 +39,7 @@ export class AssetBalanceAndProxyAllowanceFetcher implements AbstractBalanceAndP nestedAssetDataElement, userAddress, )).dividedToIntegerBy(nestedAmountElement); - if (_.isUndefined(balance) || nestedAssetBalance.lessThan(balance)) { + if (_.isUndefined(balance) || nestedAssetBalance.isLessThan(balance)) { balance = nestedAssetBalance; } } @@ -81,7 +81,7 @@ export class AssetBalanceAndProxyAllowanceFetcher implements AbstractBalanceAndP nestedAssetDataElement, userAddress, )).dividedToIntegerBy(nestedAmountElement); - if (_.isUndefined(proxyAllowance) || nestedAssetAllowance.lessThan(proxyAllowance)) { + if (_.isUndefined(proxyAllowance) || nestedAssetAllowance.isLessThan(proxyAllowance)) { proxyAllowance = nestedAssetAllowance; } } diff --git a/packages/contract-wrappers/src/utils/exchange_transfer_simulator.ts b/packages/contract-wrappers/src/utils/exchange_transfer_simulator.ts index f374d509b..4b75ea386 100644 --- a/packages/contract-wrappers/src/utils/exchange_transfer_simulator.ts +++ b/packages/contract-wrappers/src/utils/exchange_transfer_simulator.ts @@ -72,10 +72,10 @@ export class ExchangeTransferSimulator { } const balance = await this._store.getBalanceAsync(tokenAddress, from); const proxyAllowance = await this._store.getProxyAllowanceAsync(tokenAddress, from); - if (proxyAllowance.lessThan(amountInBaseUnits)) { + if (proxyAllowance.isLessThan(amountInBaseUnits)) { ExchangeTransferSimulator._throwValidationError(FailureReason.ProxyAllowance, tradeSide, transferType); } - if (balance.lessThan(amountInBaseUnits)) { + if (balance.isLessThan(amountInBaseUnits)) { ExchangeTransferSimulator._throwValidationError(FailureReason.Balance, tradeSide, transferType); } await this._decreaseProxyAllowanceAsync(tokenAddress, from, amountInBaseUnits); diff --git a/packages/contract-wrappers/src/utils/utils.ts b/packages/contract-wrappers/src/utils/utils.ts index 0b3270e78..ab69385e7 100644 --- a/packages/contract-wrappers/src/utils/utils.ts +++ b/packages/contract-wrappers/src/utils/utils.ts @@ -7,13 +7,15 @@ import { constants } from './constants'; export const utils = { getCurrentUnixTimestampSec(): BigNumber { const milisecondsInSecond = 1000; - return new BigNumber(Date.now() / milisecondsInSecond).round(); + return new BigNumber(Date.now() / milisecondsInSecond).integerValue(); }, getCurrentUnixTimestampMs(): BigNumber { return new BigNumber(Date.now()); }, numberPercentageToEtherTokenAmountPercentage(percentage: number): BigNumber { - return Web3Wrapper.toBaseUnitAmount(constants.ONE_AMOUNT, constants.ETHER_TOKEN_DECIMALS).mul(percentage); + return Web3Wrapper.toBaseUnitAmount(constants.ONE_AMOUNT, constants.ETHER_TOKEN_DECIMALS).multipliedBy( + percentage, + ); }, removeUndefinedProperties<T extends object>(obj: T): Partial<T> { return _.pickBy(obj); diff --git a/packages/contract-wrappers/test/ether_token_wrapper_test.ts b/packages/contract-wrappers/test/ether_token_wrapper_test.ts index e3efef19d..cc2419aa2 100644 --- a/packages/contract-wrappers/test/ether_token_wrapper_test.ts +++ b/packages/contract-wrappers/test/ether_token_wrapper_test.ts @@ -116,7 +116,7 @@ describe('EtherTokenWrapper', () => { const preETHBalance = await web3Wrapper.getBalanceInWeiAsync(addressWithETH); const extraETHBalance = Web3Wrapper.toWei(new BigNumber(5)); - const overETHBalanceinWei = preETHBalance.add(extraETHBalance); + const overETHBalanceinWei = preETHBalance.plus(extraETHBalance); return expect( contractWrappers.etherToken.depositAsync(wethContractAddress, overETHBalanceinWei, addressWithETH), @@ -153,7 +153,7 @@ describe('EtherTokenWrapper', () => { ); expect(postWETHBalanceInBaseUnits).to.be.bignumber.equal(0); - const expectedETHBalance = preETHBalance.add(depositWeiAmount).round(decimalPlaces); + const expectedETHBalance = preETHBalance.plus(depositWeiAmount).integerValue(decimalPlaces); gasCost = expectedETHBalance.minus(postETHBalance); expect(gasCost).to.be.bignumber.lte(MAX_REASONABLE_GAS_COST_IN_WEI); }); @@ -165,7 +165,7 @@ describe('EtherTokenWrapper', () => { expect(preWETHBalance).to.be.bignumber.equal(0); // tslint:disable-next-line:custom-no-magic-numbers - const overWETHBalance = preWETHBalance.add(999999999); + const overWETHBalance = preWETHBalance.plus(999999999); return expect( contractWrappers.etherToken.withdrawAsync(wethContractAddress, overWETHBalance, addressWithETH), diff --git a/packages/dev-utils/CHANGELOG.json b/packages/dev-utils/CHANGELOG.json index 85189d70b..d05e41d2d 100644 --- a/packages/dev-utils/CHANGELOG.json +++ b/packages/dev-utils/CHANGELOG.json @@ -1,5 +1,14 @@ [ { + "version": "2.0.0", + "changes": [ + { + "note": "Upgrade the bignumber.js to v8.0.2", + "pr": 1517 + } + ] + }, + { "timestamp": 1547561734, "version": "1.0.24", "changes": [ diff --git a/packages/ethereum-types/CHANGELOG.json b/packages/ethereum-types/CHANGELOG.json index 6265e01a1..c106d43a9 100644 --- a/packages/ethereum-types/CHANGELOG.json +++ b/packages/ethereum-types/CHANGELOG.json @@ -1,5 +1,14 @@ [ { + "version": "2.0.0", + "changes": [ + { + "note": "Upgrade the bignumber.js to v8.0.2", + "pr": 1517 + } + ] + }, + { "timestamp": 1547561734, "version": "1.1.6", "changes": [ diff --git a/packages/ethereum-types/package.json b/packages/ethereum-types/package.json index 953b323c6..bd3748058 100644 --- a/packages/ethereum-types/package.json +++ b/packages/ethereum-types/package.json @@ -37,7 +37,7 @@ }, "dependencies": { "@types/node": "*", - "bignumber.js": "~4.1.0" + "bignumber.js": "~8.0.2" }, "publishConfig": { "access": "public" diff --git a/packages/fill-scenarios/CHANGELOG.json b/packages/fill-scenarios/CHANGELOG.json index d8f2591a4..beffdd097 100644 --- a/packages/fill-scenarios/CHANGELOG.json +++ b/packages/fill-scenarios/CHANGELOG.json @@ -1,5 +1,14 @@ [ { + "version": "2.0.0", + "changes": [ + { + "note": "Upgrade the bignumber.js to v8.0.2", + "pr": 1517 + } + ] + }, + { "timestamp": 1547561734, "version": "1.1.2", "changes": [ diff --git a/packages/instant/CHANGELOG.json b/packages/instant/CHANGELOG.json index 537670584..c7348c3c0 100644 --- a/packages/instant/CHANGELOG.json +++ b/packages/instant/CHANGELOG.json @@ -1,5 +1,14 @@ [ { + "version": "3.0.0", + "changes": [ + { + "note": "Upgrade the bignumber.js to v8.0.2", + "pr": 1517 + } + ] + }, + { "version": "2.0.0", "changes": [ { diff --git a/packages/instant/src/components/order_details.tsx b/packages/instant/src/components/order_details.tsx index 4db20b13e..3ded50652 100644 --- a/packages/instant/src/components/order_details.tsx +++ b/packages/instant/src/components/order_details.tsx @@ -77,7 +77,7 @@ export class OrderDetails extends React.PureComponent<OrderDetailsProps> { } private _hadErrorFetchingUsdPrice(): boolean { - return this.props.ethUsdPrice ? this.props.ethUsdPrice.equals(BIG_NUMBER_ZERO) : false; + return this.props.ethUsdPrice ? this.props.ethUsdPrice.isEqualTo(BIG_NUMBER_ZERO) : false; } private _totalCostSecondaryValue(): React.ReactNode { @@ -156,7 +156,7 @@ export class OrderDetails extends React.PureComponent<OrderDetailsProps> { return !_.isUndefined(assetTotalInWei) && !_.isUndefined(selectedAssetUnitAmount) && !selectedAssetUnitAmount.eq(BIG_NUMBER_ZERO) - ? assetTotalInWei.div(selectedAssetUnitAmount).ceil() + ? assetTotalInWei.div(selectedAssetUnitAmount).integerValue(BigNumber.ROUND_CEIL) : undefined; } diff --git a/packages/instant/src/constants.ts b/packages/instant/src/constants.ts index bfd9e9098..d407925a3 100644 --- a/packages/instant/src/constants.ts +++ b/packages/instant/src/constants.ts @@ -21,7 +21,7 @@ export const NPM_PACKAGE_VERSION = process.env.NPM_PACKAGE_VERSION; export const DEFAULT_UNKOWN_ASSET_NAME = '???'; export const ACCOUNT_UPDATE_INTERVAL_TIME_MS = ONE_SECOND_MS * 5; export const BUY_QUOTE_UPDATE_INTERVAL_TIME_MS = ONE_SECOND_MS * 15; -export const DEFAULT_GAS_PRICE = GWEI_IN_WEI.mul(6); +export const DEFAULT_GAS_PRICE = GWEI_IN_WEI.multipliedBy(6); export const DEFAULT_ESTIMATED_TRANSACTION_TIME_MS = ONE_MINUTE_MS * 2; export const MAGIC_TRIGGER_ERROR_INPUT = '0€'; export const MAGIC_TRIGGER_ERROR_MESSAGE = 'Triggered error'; diff --git a/packages/instant/src/containers/selected_erc20_asset_amount_input.ts b/packages/instant/src/containers/selected_erc20_asset_amount_input.ts index cb9df527e..4b9993332 100644 --- a/packages/instant/src/containers/selected_erc20_asset_amount_input.ts +++ b/packages/instant/src/containers/selected_erc20_asset_amount_input.ts @@ -84,7 +84,7 @@ const mapDispatchToProps = ( // reset our buy state dispatch(actions.setBuyOrderStateNone()); - if (!_.isUndefined(value) && value.greaterThan(0) && !_.isUndefined(asset)) { + if (!_.isUndefined(value) && value.isGreaterThan(0) && !_.isUndefined(asset)) { // even if it's debounced, give them the illusion it's loading dispatch(actions.setQuoteRequestStatePending()); // tslint:disable-next-line:no-floating-promises diff --git a/packages/instant/src/redux/async_data.ts b/packages/instant/src/redux/async_data.ts index 884ab103d..f20fe319f 100644 --- a/packages/instant/src/redux/async_data.ts +++ b/packages/instant/src/redux/async_data.ts @@ -99,7 +99,7 @@ export const asyncData = { if ( !_.isUndefined(selectedAssetUnitAmount) && !_.isUndefined(selectedAsset) && - selectedAssetUnitAmount.greaterThan(BIG_NUMBER_ZERO) && + selectedAssetUnitAmount.isGreaterThan(BIG_NUMBER_ZERO) && buyOrderState.processState === OrderProcessState.None && selectedAsset.metaData.assetProxyId === AssetProxyId.ERC20 ) { diff --git a/packages/instant/src/util/asset.ts b/packages/instant/src/util/asset.ts index 709561dbc..b5c97913d 100644 --- a/packages/instant/src/util/asset.ts +++ b/packages/instant/src/util/asset.ts @@ -114,15 +114,18 @@ export const assetUtils = { const assetName = assetUtils.bestNameForAsset(asset, 'of this asset'); if ( error instanceof InsufficientAssetLiquidityError && - error.amountAvailableToFill.greaterThan(BIG_NUMBER_ZERO) + error.amountAvailableToFill.isGreaterThan(BIG_NUMBER_ZERO) ) { const unitAmountAvailableToFill = Web3Wrapper.toUnitAmount( error.amountAvailableToFill, asset.metaData.decimals, ); - const roundedUnitAmountAvailableToFill = unitAmountAvailableToFill.round(2, BigNumber.ROUND_DOWN); + const roundedUnitAmountAvailableToFill = unitAmountAvailableToFill.decimalPlaces( + 2, + BigNumber.ROUND_DOWN, + ); - if (roundedUnitAmountAvailableToFill.greaterThan(BIG_NUMBER_ZERO)) { + if (roundedUnitAmountAvailableToFill.isGreaterThan(BIG_NUMBER_ZERO)) { return `There are only ${roundedUnitAmountAvailableToFill} ${assetName} available to buy`; } } diff --git a/packages/instant/src/util/format.ts b/packages/instant/src/util/format.ts index 4adb63e21..61aeb839f 100644 --- a/packages/instant/src/util/format.ts +++ b/packages/instant/src/util/format.ts @@ -25,16 +25,16 @@ export const format = { if (_.isUndefined(ethUnitAmount)) { return defaultText; } - let roundedAmount = ethUnitAmount.round(decimalPlaces).toDigits(decimalPlaces); + let roundedAmount = ethUnitAmount.decimalPlaces(decimalPlaces).precision(decimalPlaces); - if (roundedAmount.eq(BIG_NUMBER_ZERO) && ethUnitAmount.greaterThan(BIG_NUMBER_ZERO)) { + if (roundedAmount.eq(BIG_NUMBER_ZERO) && ethUnitAmount.isGreaterThan(BIG_NUMBER_ZERO)) { // Sometimes for small ETH amounts (i.e. 0.000045) the amount rounded to 4 decimalPlaces is 0 // If that is the case, show to 1 significant digit roundedAmount = new BigNumber(ethUnitAmount.toPrecision(1)); } const displayAmount = - roundedAmount.greaterThan(BIG_NUMBER_ZERO) && roundedAmount.lessThan(minUnitAmountToDisplay) + roundedAmount.isGreaterThan(BIG_NUMBER_ZERO) && roundedAmount.isLessThan(minUnitAmountToDisplay) ? `< ${minUnitAmountToDisplay.toString()}` : roundedAmount.toString(); @@ -62,7 +62,7 @@ export const format = { if (_.isUndefined(ethUnitAmount) || _.isUndefined(ethUsdPrice)) { return defaultText; } - const rawUsdPrice = ethUnitAmount.mul(ethUsdPrice); + const rawUsdPrice = ethUnitAmount.multipliedBy(ethUsdPrice); const roundedUsdPrice = rawUsdPrice.toFixed(decimalPlaces); if (roundedUsdPrice === '0.00' && rawUsdPrice.gt(BIG_NUMBER_ZERO)) { return '<$0.01'; diff --git a/packages/instant/src/util/gas_price_estimator.ts b/packages/instant/src/util/gas_price_estimator.ts index 332c8d00a..9792b60ba 100644 --- a/packages/instant/src/util/gas_price_estimator.ts +++ b/packages/instant/src/util/gas_price_estimator.ts @@ -35,7 +35,7 @@ const fetchFastAmountInWeiAsync = async (): Promise<GasInfo> => { const gasPriceInGwei = new BigNumber(gasInfo.fast / 10); // Time is in minutes const estimatedTimeMs = gasInfo.fastWait * 60 * 1000; // Minutes to MS - return { gasPriceInWei: gasPriceInGwei.mul(GWEI_IN_WEI), estimatedTimeMs }; + return { gasPriceInWei: gasPriceInGwei.multipliedBy(GWEI_IN_WEI), estimatedTimeMs }; }; export class GasPriceEstimator { diff --git a/packages/instant/src/util/maybe_big_number.ts b/packages/instant/src/util/maybe_big_number.ts index 9d3746e10..f48473389 100644 --- a/packages/instant/src/util/maybe_big_number.ts +++ b/packages/instant/src/util/maybe_big_number.ts @@ -18,7 +18,7 @@ export const maybeBigNumberUtil = { }, areMaybeBigNumbersEqual: (val1: Maybe<BigNumber>, val2: Maybe<BigNumber>): boolean => { if (!_.isUndefined(val1) && !_.isUndefined(val2)) { - return val1.equals(val2); + return val1.isEqualTo(val2); } return _.isUndefined(val1) && _.isUndefined(val2); }, diff --git a/packages/json-schemas/CHANGELOG.json b/packages/json-schemas/CHANGELOG.json index 1388b4dca..66de84299 100644 --- a/packages/json-schemas/CHANGELOG.json +++ b/packages/json-schemas/CHANGELOG.json @@ -1,5 +1,14 @@ [ { + "version": "3.0.0", + "changes": [ + { + "note": "Upgrade the bignumber.js to v8.0.2", + "pr": 1517 + } + ] + }, + { "timestamp": 1547561734, "version": "2.1.7", "changes": [ diff --git a/packages/metacoin/package.json b/packages/metacoin/package.json index 4bd2bc66f..3b082f075 100644 --- a/packages/metacoin/package.json +++ b/packages/metacoin/package.json @@ -53,7 +53,7 @@ "@0x/sol-compiler": "^2.0.2", "chai": "^4.0.1", "chai-as-promised": "^7.1.0", - "chai-bignumber": "^2.0.1", + "chai-bignumber": "^3.0.0", "dirty-chai": "^2.0.1", "make-promises-safe": "^1.1.0", "npm-run-all": "^4.1.2", diff --git a/packages/migrations/CHANGELOG.json b/packages/migrations/CHANGELOG.json index 5962a9886..64ae94b14 100644 --- a/packages/migrations/CHANGELOG.json +++ b/packages/migrations/CHANGELOG.json @@ -1,5 +1,14 @@ [ { + "version": "3.0.0", + "changes": [ + { + "note": "Upgrade the bignumber.js to v8.0.2", + "pr": 1517 + } + ] + }, + { "version": "2.4.0", "changes": [ { diff --git a/packages/monorepo-scripts/CHANGELOG.json b/packages/monorepo-scripts/CHANGELOG.json index cebe7ec72..a71bfbd6d 100644 --- a/packages/monorepo-scripts/CHANGELOG.json +++ b/packages/monorepo-scripts/CHANGELOG.json @@ -1,5 +1,14 @@ [ { + "version": "2.0.0", + "changes": [ + { + "note": "Upgrade the bignumber.js to v8.0.2", + "pr": 1517 + } + ] + }, + { "version": "1.0.6", "changes": [ { diff --git a/packages/order-utils/CHANGELOG.json b/packages/order-utils/CHANGELOG.json index ace3656c4..08d88da5b 100644 --- a/packages/order-utils/CHANGELOG.json +++ b/packages/order-utils/CHANGELOG.json @@ -1,5 +1,14 @@ [ { + "version": "4.0.0", + "changes": [ + { + "note": "Upgrade the bignumber.js to v8.0.2", + "pr": 1517 + } + ] + }, + { "timestamp": 1547561734, "version": "3.1.2", "changes": [ diff --git a/packages/order-utils/package.json b/packages/order-utils/package.json index bdcbd2dfc..7a4d4aa84 100644 --- a/packages/order-utils/package.json +++ b/packages/order-utils/package.json @@ -41,7 +41,7 @@ "@types/lodash": "4.14.104", "chai": "^4.0.1", "chai-as-promised": "^7.1.0", - "chai-bignumber": "^2.0.1", + "chai-bignumber": "^3.0.0", "dirty-chai": "^2.0.1", "make-promises-safe": "^1.1.0", "mocha": "^4.1.0", diff --git a/packages/order-utils/src/crypto.ts b/packages/order-utils/src/crypto.ts index 0f1504a72..8b835ff48 100644 --- a/packages/order-utils/src/crypto.ts +++ b/packages/order-utils/src/crypto.ts @@ -1,3 +1,4 @@ +import { BigNumber } from '@0x/utils'; import BN = require('bn.js'); import ABI = require('ethereumjs-abi'); import ethUtil = require('ethereumjs-util'); @@ -24,7 +25,7 @@ export const crypto = { const isNumber = _.isFinite(arg); if (isNumber) { argTypes.push('uint8'); - } else if (arg.isBigNumber) { + } else if (BigNumber.isBigNumber(arg)) { argTypes.push('uint256'); const base = 10; args[i] = new BN(arg.toString(base), base); diff --git a/packages/order-utils/src/exchange_transfer_simulator.ts b/packages/order-utils/src/exchange_transfer_simulator.ts index 06621fd9e..922ae8e17 100644 --- a/packages/order-utils/src/exchange_transfer_simulator.ts +++ b/packages/order-utils/src/exchange_transfer_simulator.ts @@ -88,14 +88,14 @@ export class ExchangeTransferSimulator { } const balance = await this._store.getBalanceAsync(assetData, from); const proxyAllowance = await this._store.getProxyAllowanceAsync(assetData, from); - if (proxyAllowance.lessThan(amountInBaseUnits)) { + if (proxyAllowance.isLessThan(amountInBaseUnits)) { ExchangeTransferSimulator._throwValidationError( FailureReason.ProxyAllowance, tradeSide, transferType, ); } - if (balance.lessThan(amountInBaseUnits)) { + if (balance.isLessThan(amountInBaseUnits)) { ExchangeTransferSimulator._throwValidationError(FailureReason.Balance, tradeSide, transferType); } await this._decreaseProxyAllowanceAsync(assetData, from, amountInBaseUnits); diff --git a/packages/order-utils/src/market_utils.ts b/packages/order-utils/src/market_utils.ts index fa32f1413..9042551fa 100644 --- a/packages/order-utils/src/market_utils.ts +++ b/packages/order-utils/src/market_utils.ts @@ -52,7 +52,7 @@ export const marketUtils = { const result = _.reduce( orders, ({ resultOrders, remainingFillAmount, ordersRemainingFillableMakerAssetAmounts }, order, index) => { - if (remainingFillAmount.lessThanOrEqualTo(constants.ZERO_AMOUNT)) { + if (remainingFillAmount.isLessThanOrEqualTo(constants.ZERO_AMOUNT)) { return { resultOrders, remainingFillAmount: constants.ZERO_AMOUNT, @@ -137,7 +137,7 @@ export const marketUtils = { (accFees, order, index) => { const makerAssetAmountAvailable = remainingFillableMakerAssetAmounts[index]; const feeToFillMakerAssetAmountAvailable = makerAssetAmountAvailable - .mul(order.takerFee) + .multipliedBy(order.takerFee) .dividedToIntegerBy(order.makerAssetAmount); return accFees.plus(feeToFillMakerAssetAmountAvailable); }, diff --git a/packages/order-utils/src/order_state_utils.ts b/packages/order-utils/src/order_state_utils.ts index 389419587..430178b5d 100644 --- a/packages/order-utils/src/order_state_utils.ts +++ b/packages/order-utils/src/order_state_utils.ts @@ -214,10 +214,10 @@ export class OrderStateUtils { const remainingFillableTakerAssetAmountGivenTakersStatus = orderRelevantTakerState.remainingFillableAssetAmount; // The min of these two in the actualy max fillable by either party - const fillableTakerAssetAmount = BigNumber.min([ + const fillableTakerAssetAmount = BigNumber.min( remainingFillableTakerAssetAmountGivenMakersStatus, remainingFillableTakerAssetAmountGivenTakersStatus, - ]); + ); return fillableTakerAssetAmount; } @@ -260,8 +260,8 @@ export class OrderStateUtils { traderAddress, ); - const transferrableTraderAssetAmount = BigNumber.min([traderProxyAllowance, traderBalance]); - const transferrableFeeAssetAmount = BigNumber.min([traderFeeProxyAllowance, traderFeeBalance]); + const transferrableTraderAssetAmount = BigNumber.min(traderProxyAllowance, traderBalance); + const transferrableFeeAssetAmount = BigNumber.min(traderFeeProxyAllowance, traderFeeBalance); const orderHash = orderHashUtils.getOrderHashHex(signedOrder); const filledTakerAssetAmount = await this._orderFilledCancelledFetcher.getFilledTakerAmountAsync(orderHash); @@ -312,7 +312,7 @@ export class OrderStateUtils { const tokenAddress = decodedAssetData.tokenAddress; balances[tokenAddress] = _.isUndefined(initialBalances[tokenAddress]) ? balance - : balances[tokenAddress].add(balance); + : balances[tokenAddress].plus(balance); } else if (assetDataUtils.isMultiAssetData(decodedAssetData)) { for (const assetDataElement of decodedAssetData.nestedAssetData) { balances = await this._getAssetBalancesAsync(assetDataElement, traderAddress, balances); @@ -335,7 +335,7 @@ export class OrderStateUtils { const tokenAddress = decodedAssetData.tokenAddress; allowances[tokenAddress] = _.isUndefined(initialAllowances[tokenAddress]) ? allowance - : allowances[tokenAddress].add(allowance); + : allowances[tokenAddress].plus(allowance); } else if (assetDataUtils.isMultiAssetData(decodedAssetData)) { for (const assetDataElement of decodedAssetData.nestedAssetData) { allowances = await this._getAssetBalancesAsync(assetDataElement, traderAddress, allowances); diff --git a/packages/order-utils/src/order_validation_utils.ts b/packages/order-utils/src/order_validation_utils.ts index ae4291ea8..95215d918 100644 --- a/packages/order-utils/src/order_validation_utils.ts +++ b/packages/order-utils/src/order_validation_utils.ts @@ -31,13 +31,13 @@ export class OrderValidationUtils { if (denominator.eq(0)) { throw new Error('denominator cannot be 0'); } - const remainder = target.mul(numerator).mod(denominator); + const remainder = target.multipliedBy(numerator).mod(denominator); if (remainder.eq(0)) { return false; // no rounding error } // tslint:disable-next-line:custom-no-magic-numbers - const errPercentageTimes1000000 = remainder.mul(1000000).div(numerator.mul(target)); + const errPercentageTimes1000000 = remainder.multipliedBy(1000000).div(numerator.multipliedBy(target)); // tslint:disable-next-line:custom-no-magic-numbers const isError = errPercentageTimes1000000.gt(1000); return isError; @@ -108,7 +108,7 @@ export class OrderValidationUtils { } private static _validateOrderNotExpiredOrThrow(expirationTimeSeconds: BigNumber): void { const currentUnixTimestampSec = utils.getCurrentUnixTimestampSec(); - if (expirationTimeSeconds.lessThan(currentUnixTimestampSec)) { + if (expirationTimeSeconds.isLessThan(currentUnixTimestampSec)) { throw new Error(RevertReason.OrderUnfillable); } } @@ -216,7 +216,7 @@ export class OrderValidationUtils { } OrderValidationUtils._validateOrderNotExpiredOrThrow(signedOrder.expirationTimeSeconds); const remainingTakerTokenAmount = signedOrder.takerAssetAmount.minus(filledTakerTokenAmount); - const desiredFillTakerTokenAmount = remainingTakerTokenAmount.lessThan(fillTakerAssetAmount) + const desiredFillTakerTokenAmount = remainingTakerTokenAmount.isLessThan(fillTakerAssetAmount) ? remainingTakerTokenAmount : fillTakerAssetAmount; try { diff --git a/packages/order-utils/src/rate_utils.ts b/packages/order-utils/src/rate_utils.ts index 416e00c67..dacdbd5a2 100644 --- a/packages/order-utils/src/rate_utils.ts +++ b/packages/order-utils/src/rate_utils.ts @@ -22,7 +22,7 @@ export const rateUtils = { feeRate.gte(constants.ZERO_AMOUNT), `Expected feeRate: ${feeRate} to be greater than or equal to 0`, ); - const takerAssetAmountNeededToPayForFees = order.takerFee.mul(feeRate); + const takerAssetAmountNeededToPayForFees = order.takerFee.multipliedBy(feeRate); const totalTakerAssetAmount = takerAssetAmountNeededToPayForFees.plus(order.takerAssetAmount); const rate = totalTakerAssetAmount.div(order.makerAssetAmount); return rate; @@ -35,9 +35,9 @@ export const rateUtils = { */ getFeeAdjustedRateOfFeeOrder(feeOrder: Order): BigNumber { assert.doesConformToSchema('feeOrder', feeOrder, schemas.orderSchema); - const zrxAmountAfterFees = feeOrder.makerAssetAmount.sub(feeOrder.takerFee); + const zrxAmountAfterFees = feeOrder.makerAssetAmount.minus(feeOrder.takerFee); assert.assert( - zrxAmountAfterFees.greaterThan(constants.ZERO_AMOUNT), + zrxAmountAfterFees.isGreaterThan(constants.ZERO_AMOUNT), `Expected takerFee: ${JSON.stringify(feeOrder.takerFee)} to be less than makerAssetAmount: ${JSON.stringify( feeOrder.makerAssetAmount, )}`, diff --git a/packages/order-utils/src/remaining_fillable_calculator.ts b/packages/order-utils/src/remaining_fillable_calculator.ts index 052eafa1d..92ffc8e80 100644 --- a/packages/order-utils/src/remaining_fillable_calculator.ts +++ b/packages/order-utils/src/remaining_fillable_calculator.ts @@ -39,15 +39,15 @@ export class RemainingFillableCalculator { private _hasSufficientFundsForFeeAndTransferAmount(): boolean { if (this._isTraderAssetZRX) { const totalZRXTransferAmountRequired = this._remainingOrderAssetAmount.plus(this._remainingOrderFeeAmount); - const hasSufficientFunds = this._transferrableAssetAmount.greaterThanOrEqualTo( + const hasSufficientFunds = this._transferrableAssetAmount.isGreaterThanOrEqualTo( totalZRXTransferAmountRequired, ); return hasSufficientFunds; } else { - const hasSufficientFundsForTransferAmount = this._transferrableAssetAmount.greaterThanOrEqualTo( + const hasSufficientFundsForTransferAmount = this._transferrableAssetAmount.isGreaterThanOrEqualTo( this._remainingOrderAssetAmount, ); - const hasSufficientFundsForFeeAmount = this._transferrableFeeAmount.greaterThanOrEqualTo( + const hasSufficientFundsForFeeAmount = this._transferrableFeeAmount.isGreaterThanOrEqualTo( this._remainingOrderFeeAmount, ); const hasSufficientFunds = hasSufficientFundsForTransferAmount && hasSufficientFundsForFeeAmount; diff --git a/packages/order-utils/src/salt.ts b/packages/order-utils/src/salt.ts index ff47ab5d2..95df66c99 100644 --- a/packages/order-utils/src/salt.ts +++ b/packages/order-utils/src/salt.ts @@ -13,6 +13,6 @@ export function generatePseudoRandomSalt(): BigNumber { // Source: https://mikemcl.github.io/bignumber.js/#random const randomNumber = BigNumber.random(MAX_DIGITS_IN_UNSIGNED_256_INT); const factor = new BigNumber(10).pow(MAX_DIGITS_IN_UNSIGNED_256_INT - 1); - const salt = randomNumber.times(factor).round(); + const salt = randomNumber.times(factor).integerValue(); return salt; } diff --git a/packages/order-utils/src/utils.ts b/packages/order-utils/src/utils.ts index 6b2261001..64195dbed 100644 --- a/packages/order-utils/src/utils.ts +++ b/packages/order-utils/src/utils.ts @@ -10,13 +10,13 @@ export const utils = { }, getCurrentUnixTimestampSec(): BigNumber { const milisecondsInSecond = 1000; - return new BigNumber(Date.now() / milisecondsInSecond).round(); + return new BigNumber(Date.now() / milisecondsInSecond).integerValue(); }, getPartialAmountFloor(numerator: BigNumber, denominator: BigNumber, target: BigNumber): BigNumber { const fillMakerTokenAmount = numerator - .mul(target) + .multipliedBy(target) .div(denominator) - .round(0); + .integerValue(0); return fillMakerTokenAmount; }, }; diff --git a/packages/order-utils/test/remaining_fillable_calculator_test.ts b/packages/order-utils/test/remaining_fillable_calculator_test.ts index c55a76def..affad8f1c 100644 --- a/packages/order-utils/test/remaining_fillable_calculator_test.ts +++ b/packages/order-utils/test/remaining_fillable_calculator_test.ts @@ -162,7 +162,7 @@ describe('RemainingFillableCalculator', () => { remainingMakeAssetAmount, ); const calculatedFillableAmount = calculator.computeRemainingFillable(); - expect(calculatedFillableAmount.lessThanOrEqualTo(transferrableMakeAssetAmount)).to.be.true(); + expect(calculatedFillableAmount.isLessThanOrEqualTo(transferrableMakeAssetAmount)).to.be.true(); expect(calculatedFillableAmount).to.be.bignumber.greaterThan(new BigNumber(0)); const orderToFeeRatio = signedOrder.makerAssetAmount.dividedBy(signedOrder.makerFee); const calculatedFeeAmount = calculatedFillableAmount.dividedBy(orderToFeeRatio); diff --git a/packages/order-utils/test/signature_utils_test.ts b/packages/order-utils/test/signature_utils_test.ts index 84e5559a9..937382056 100644 --- a/packages/order-utils/test/signature_utils_test.ts +++ b/packages/order-utils/test/signature_utils_test.ts @@ -132,10 +132,10 @@ describe('Signature utils', () => { }); it('generates salt in range [0..2^256)', () => { const salt = generatePseudoRandomSalt(); - expect(salt.greaterThanOrEqualTo(0)).to.be.true(); + expect(salt.isGreaterThanOrEqualTo(0)).to.be.true(); // tslint:disable-next-line:custom-no-magic-numbers const twoPow256 = new BigNumber(2).pow(256); - expect(salt.lessThan(twoPow256)).to.be.true(); + expect(salt.isLessThan(twoPow256)).to.be.true(); }); }); describe('#ecSignOrderAsync', () => { diff --git a/packages/order-watcher/CHANGELOG.json b/packages/order-watcher/CHANGELOG.json index 29fe4e723..585bb48e6 100644 --- a/packages/order-watcher/CHANGELOG.json +++ b/packages/order-watcher/CHANGELOG.json @@ -1,5 +1,14 @@ [ { + "version": "3.0.0", + "changes": [ + { + "note": "Upgrade the bignumber.js to v8.0.2", + "pr": 1517 + } + ] + }, + { "timestamp": 1547747677, "version": "2.4.3", "changes": [ diff --git a/packages/order-watcher/package.json b/packages/order-watcher/package.json index 0f2464eae..895c64813 100644 --- a/packages/order-watcher/package.json +++ b/packages/order-watcher/package.json @@ -49,7 +49,7 @@ "@types/sinon": "^2.2.2", "chai": "^4.0.1", "chai-as-promised": "^7.1.0", - "chai-bignumber": "^2.0.1", + "chai-bignumber": "^3.0.0", "dirty-chai": "^2.0.1", "make-promises-safe": "^1.1.0", "mocha": "^4.1.0", diff --git a/packages/order-watcher/src/order_watcher/expiration_watcher.ts b/packages/order-watcher/src/order_watcher/expiration_watcher.ts index ad20a6e3f..82590efde 100644 --- a/packages/order-watcher/src/order_watcher/expiration_watcher.ts +++ b/packages/order-watcher/src/order_watcher/expiration_watcher.ts @@ -73,7 +73,7 @@ export class ExpirationWatcher { break; } const nextOrderHashToExpire = this._orderHashByExpirationRBTree.min(); - const hasNoExpiredOrders = this._expiration[nextOrderHashToExpire].greaterThan( + const hasNoExpiredOrders = this._expiration[nextOrderHashToExpire].isGreaterThan( currentUnixTimestampMs.plus(this._expirationMarginMs), ); const isSubscriptionActive = _.isUndefined(this._orderExpirationCheckingIntervalIdIfExists); diff --git a/packages/order-watcher/src/utils/utils.ts b/packages/order-watcher/src/utils/utils.ts index a7d10aaf9..9c3849ff1 100644 --- a/packages/order-watcher/src/utils/utils.ts +++ b/packages/order-watcher/src/utils/utils.ts @@ -3,7 +3,7 @@ import { BigNumber } from '@0x/utils'; export const utils = { getCurrentUnixTimestampSec(): BigNumber { const milisecondsInASecond = 1000; - return new BigNumber(Date.now() / milisecondsInASecond).round(); + return new BigNumber(Date.now() / milisecondsInASecond).integerValue(); }, getCurrentUnixTimestampMs(): BigNumber { return new BigNumber(Date.now()); diff --git a/packages/order-watcher/test/order_watcher_test.ts b/packages/order-watcher/test/order_watcher_test.ts index 41dc884d5..28b564b32 100644 --- a/packages/order-watcher/test/order_watcher_test.ts +++ b/packages/order-watcher/test/order_watcher_test.ts @@ -317,7 +317,7 @@ describe('OrderWatcher', () => { const validOrderState = orderState as OrderStateValid; expect(validOrderState.orderHash).to.be.equal(orderHash); const orderRelevantState = validOrderState.orderRelevantState; - const remainingMakerBalance = makerBalance.sub(fillAmountInBaseUnits); + const remainingMakerBalance = makerBalance.minus(fillAmountInBaseUnits); const remainingFillable = fillableAmount.minus(fillAmountInBaseUnits); expect(orderRelevantState.remainingFillableMakerAssetAmount).to.be.bignumber.equal( remainingFillable, @@ -434,7 +434,7 @@ describe('OrderWatcher', () => { ); const remainingAmount = Web3Wrapper.toBaseUnitAmount(new BigNumber(1), decimals); - const transferAmount = makerBalance.sub(remainingAmount); + const transferAmount = makerBalance.minus(remainingAmount); await orderWatcher.addOrderAsync(signedOrder); const callback = callbackErrorReporter.reportNodeCallbackErrors(done)((orderState: OrderState) => { @@ -475,7 +475,7 @@ describe('OrderWatcher', () => { const remainingFeeAmount = Web3Wrapper.toBaseUnitAmount(new BigNumber(3), decimals); const remainingTokenAmount = Web3Wrapper.toBaseUnitAmount(new BigNumber(4), decimals); - const transferTokenAmount = makerFee.sub(remainingTokenAmount); + const transferTokenAmount = makerFee.minus(remainingTokenAmount); await orderWatcher.addOrderAsync(signedOrder); const callback = callbackErrorReporter.reportNodeCallbackErrors(done)((orderState: OrderState) => { diff --git a/packages/pipeline/package.json b/packages/pipeline/package.json index 988dd8b74..908734687 100644 --- a/packages/pipeline/package.json +++ b/packages/pipeline/package.json @@ -32,7 +32,7 @@ "@types/ramda": "^0.25.38", "chai": "^4.1.2", "chai-as-promised": "^7.1.1", - "chai-bignumber": "^2.0.2", + "chai-bignumber": "^3.0.0", "dirty-chai": "^2.0.1", "mocha": "^5.2.0", "tslint": "5.11.0", diff --git a/packages/pipeline/src/utils/transformers/number_to_bigint.ts b/packages/pipeline/src/utils/transformers/number_to_bigint.ts index 9736d7c18..8fbd52093 100644 --- a/packages/pipeline/src/utils/transformers/number_to_bigint.ts +++ b/packages/pipeline/src/utils/transformers/number_to_bigint.ts @@ -19,7 +19,7 @@ export class NumberToBigIntTransformer implements ValueTransformer { // tslint:disable-next-line:prefer-function-over-method public from(value: string): number { - if (new BigNumber(value).greaterThan(Number.MAX_SAFE_INTEGER)) { + if (new BigNumber(value).isGreaterThan(Number.MAX_SAFE_INTEGER)) { throw new Error( `Attempted to convert PostgreSQL bigint value (${value}) to JavaScript number type but it is too big to safely convert`, ); diff --git a/packages/react-docs/CHANGELOG.json b/packages/react-docs/CHANGELOG.json index 101da65c7..8b418fc11 100644 --- a/packages/react-docs/CHANGELOG.json +++ b/packages/react-docs/CHANGELOG.json @@ -1,5 +1,14 @@ [ { + "version": "2.0.0", + "changes": [ + { + "note": "Upgrade the bignumber.js to v8.0.2", + "pr": 1517 + } + ] + }, + { "timestamp": 1547561734, "version": "1.0.25", "changes": [ diff --git a/packages/react-shared/CHANGELOG.json b/packages/react-shared/CHANGELOG.json index a6d2c4fa0..99a8779ac 100644 --- a/packages/react-shared/CHANGELOG.json +++ b/packages/react-shared/CHANGELOG.json @@ -1,5 +1,14 @@ [ { + "version": "2.0.0", + "changes": [ + { + "note": "Upgrade the bignumber.js to v8.0.2", + "pr": 1517 + } + ] + }, + { "timestamp": 1547561734, "version": "1.1.2", "changes": [ diff --git a/packages/sol-compiler/CHANGELOG.json b/packages/sol-compiler/CHANGELOG.json index d7dd5a454..672939a4a 100644 --- a/packages/sol-compiler/CHANGELOG.json +++ b/packages/sol-compiler/CHANGELOG.json @@ -1,5 +1,14 @@ [ { + "version": "3.0.0", + "changes": [ + { + "note": "Upgrade the bignumber.js to v8.0.2", + "pr": 1517 + } + ] + }, + { "timestamp": 1547561734, "version": "2.0.2", "changes": [ diff --git a/packages/sol-compiler/package.json b/packages/sol-compiler/package.json index 26c8e8833..0b53cffd5 100644 --- a/packages/sol-compiler/package.json +++ b/packages/sol-compiler/package.json @@ -51,7 +51,7 @@ "@types/semver": "^5.5.0", "chai": "^4.0.1", "chai-as-promised": "^7.1.0", - "chai-bignumber": "^2.0.2", + "chai-bignumber": "^3.0.0", "copyfiles": "^2.0.0", "dirty-chai": "^2.0.1", "make-promises-safe": "^1.1.0", diff --git a/packages/sol-coverage/CHANGELOG.json b/packages/sol-coverage/CHANGELOG.json index d2ad03030..550ca2feb 100644 --- a/packages/sol-coverage/CHANGELOG.json +++ b/packages/sol-coverage/CHANGELOG.json @@ -1,5 +1,14 @@ [ { + "version": "2.0.0", + "changes": [ + { + "note": "Upgrade the bignumber.js to v8.0.2", + "pr": 1517 + } + ] + }, + { "timestamp": 1547747677, "version": "1.0.3", "changes": [ diff --git a/packages/sol-doc/CHANGELOG.json b/packages/sol-doc/CHANGELOG.json index f95702ee4..662915faf 100644 --- a/packages/sol-doc/CHANGELOG.json +++ b/packages/sol-doc/CHANGELOG.json @@ -1,5 +1,14 @@ [ { + "version": "2.0.0", + "changes": [ + { + "note": "Upgrade the bignumber.js to v8.0.2", + "pr": 1517 + } + ] + }, + { "timestamp": 1547561734, "version": "1.0.14", "changes": [ diff --git a/packages/sol-doc/package.json b/packages/sol-doc/package.json index dee6ef2e5..179f45e81 100644 --- a/packages/sol-doc/package.json +++ b/packages/sol-doc/package.json @@ -37,7 +37,7 @@ "@0x/tslint-config": "^2.0.2", "chai": "^4.1.2", "chai-as-promised": "^7.1.0", - "chai-bignumber": "^2.0.2", + "chai-bignumber": "^3.0.0", "dirty-chai": "^2.0.1", "make-promises-safe": "^1.1.0", "mocha": "^5.2.0", diff --git a/packages/sol-profiler/CHANGELOG.json b/packages/sol-profiler/CHANGELOG.json index d2ad03030..550ca2feb 100644 --- a/packages/sol-profiler/CHANGELOG.json +++ b/packages/sol-profiler/CHANGELOG.json @@ -1,5 +1,14 @@ [ { + "version": "2.0.0", + "changes": [ + { + "note": "Upgrade the bignumber.js to v8.0.2", + "pr": 1517 + } + ] + }, + { "timestamp": 1547747677, "version": "1.0.3", "changes": [ diff --git a/packages/sol-resolver/CHANGELOG.json b/packages/sol-resolver/CHANGELOG.json index e5f4a8ac1..f5a005fd4 100644 --- a/packages/sol-resolver/CHANGELOG.json +++ b/packages/sol-resolver/CHANGELOG.json @@ -1,5 +1,14 @@ [ { + "version": "2.0.0", + "changes": [ + { + "note": "Upgrade the bignumber.js to v8.0.2", + "pr": 1517 + } + ] + }, + { "timestamp": 1547561734, "version": "1.2.3", "changes": [ diff --git a/packages/sol-trace/CHANGELOG.json b/packages/sol-trace/CHANGELOG.json index d2ad03030..550ca2feb 100644 --- a/packages/sol-trace/CHANGELOG.json +++ b/packages/sol-trace/CHANGELOG.json @@ -1,5 +1,14 @@ [ { + "version": "2.0.0", + "changes": [ + { + "note": "Upgrade the bignumber.js to v8.0.2", + "pr": 1517 + } + ] + }, + { "timestamp": 1547747677, "version": "1.0.3", "changes": [ diff --git a/packages/sol-tracing-utils/CHANGELOG.json b/packages/sol-tracing-utils/CHANGELOG.json index 7e98003f7..ef96dc69b 100644 --- a/packages/sol-tracing-utils/CHANGELOG.json +++ b/packages/sol-tracing-utils/CHANGELOG.json @@ -1,5 +1,14 @@ [ { + "version": "5.0.0", + "changes": [ + { + "note": "Upgrade the bignumber.js to v8.0.2", + "pr": 1517 + } + ] + }, + { "version": "4.0.1", "changes": [ { diff --git a/packages/sra-spec/CHANGELOG.json b/packages/sra-spec/CHANGELOG.json index 3f2a9fbc1..e22a3b0e4 100644 --- a/packages/sra-spec/CHANGELOG.json +++ b/packages/sra-spec/CHANGELOG.json @@ -1,5 +1,14 @@ [ { + "version": "2.0.0", + "changes": [ + { + "note": "Upgrade the bignumber.js to v8.0.2", + "pr": 1517 + } + ] + }, + { "timestamp": 1547561734, "version": "1.0.16", "changes": [ diff --git a/packages/subproviders/CHANGELOG.json b/packages/subproviders/CHANGELOG.json index 5f7a2744e..ffb9740cd 100644 --- a/packages/subproviders/CHANGELOG.json +++ b/packages/subproviders/CHANGELOG.json @@ -1,8 +1,12 @@ [ { - "version": "2.1.12", + "version": "3.0.0", "changes": [ { + "note": "Upgrade the bignumber.js to v8.0.2", + "pr": 1517 + }, + { "note": "Update ganache-core to v2.3.3", "pr": 1518 } diff --git a/packages/testnet-faucets/src/ts/dispense_asset_tasks.ts b/packages/testnet-faucets/src/ts/dispense_asset_tasks.ts index 32f5cb623..58caeeeaa 100644 --- a/packages/testnet-faucets/src/ts/dispense_asset_tasks.ts +++ b/packages/testnet-faucets/src/ts/dispense_asset_tasks.ts @@ -19,7 +19,7 @@ export const dispenseAssetTasks = { logUtils.log(`Processing ETH ${recipientAddress}`); const userBalance = await web3Wrapper.getBalanceInWeiAsync(recipientAddress); const maxAmountInWei = Web3Wrapper.toWei(new BigNumber(DISPENSE_MAX_AMOUNT_ETHER)); - if (userBalance.greaterThanOrEqualTo(maxAmountInWei)) { + if (userBalance.isGreaterThanOrEqualTo(maxAmountInWei)) { logUtils.log( `User exceeded ETH balance maximum (${maxAmountInWei}) ${recipientAddress} ${userBalance} `, ); @@ -55,7 +55,7 @@ export const dispenseAssetTasks = { new BigNumber(DISPENSE_MAX_AMOUNT_TOKEN), tokenIfExists.decimals, ); - if (userBalanceBaseUnits.greaterThanOrEqualTo(maxAmountBaseUnits)) { + if (userBalanceBaseUnits.isGreaterThanOrEqualTo(maxAmountBaseUnits)) { logUtils.log( `User exceeded token balance maximum (${maxAmountBaseUnits}) ${recipientAddress} ${userBalanceBaseUnits} `, ); diff --git a/packages/testnet-faucets/src/ts/handler.ts b/packages/testnet-faucets/src/ts/handler.ts index 8f642d4b0..533e1f8b3 100644 --- a/packages/testnet-faucets/src/ts/handler.ts +++ b/packages/testnet-faucets/src/ts/handler.ts @@ -178,8 +178,10 @@ export class Handler { exchangeAddress: networkConfig.contractWrappers.exchange.address, feeRecipientAddress: NULL_ADDRESS, senderAddress: NULL_ADDRESS, - // tslint:disable-next-line:custom-no-magic-numbers - expirationTimeSeconds: new BigNumber(Date.now() + FIVE_DAYS_IN_MS).div(1000).floor(), + expirationTimeSeconds: new BigNumber(Date.now() + FIVE_DAYS_IN_MS) + // tslint:disable-next-line:custom-no-magic-numbers + .div(1000) + .integerValue(BigNumber.ROUND_FLOOR), }; const orderHash = orderHashUtils.getOrderHashHex(order); const signature = await signatureUtils.ecSignHashAsync( diff --git a/packages/tslint-config/CHANGELOG.json b/packages/tslint-config/CHANGELOG.json index fe34592fd..34ea6aa6b 100644 --- a/packages/tslint-config/CHANGELOG.json +++ b/packages/tslint-config/CHANGELOG.json @@ -1,5 +1,14 @@ [ { + "version": "3.0.0", + "changes": [ + { + "note": "Upgrade the bignumber.js to v8.0.2", + "pr": 1517 + } + ] + }, + { "timestamp": 1547561734, "version": "2.0.2", "changes": [ diff --git a/packages/types/CHANGELOG.json b/packages/types/CHANGELOG.json index 40a46ac84..7a6d205ee 100644 --- a/packages/types/CHANGELOG.json +++ b/packages/types/CHANGELOG.json @@ -1,5 +1,14 @@ [ { + "version": "2.0.0", + "changes": [ + { + "note": "Upgrade the bignumber.js to v8.0.2", + "pr": 1517 + } + ] + }, + { "timestamp": 1547561734, "version": "1.5.2", "changes": [ diff --git a/packages/types/package.json b/packages/types/package.json index 2fea809bc..440f05423 100644 --- a/packages/types/package.json +++ b/packages/types/package.json @@ -31,7 +31,7 @@ }, "dependencies": { "@types/node": "*", - "bignumber.js": "~4.1.0", + "bignumber.js": "~8.0.2", "ethereum-types": "^1.1.6" }, "publishConfig": { diff --git a/packages/typescript-typings/CHANGELOG.json b/packages/typescript-typings/CHANGELOG.json index cc7ef7fa4..e3ae60231 100644 --- a/packages/typescript-typings/CHANGELOG.json +++ b/packages/typescript-typings/CHANGELOG.json @@ -1,5 +1,14 @@ [ { + "version": "4.0.0", + "changes": [ + { + "note": "Upgrade the bignumber.js to v8.0.2", + "pr": 1517 + } + ] + }, + { "timestamp": 1547561734, "version": "3.0.8", "changes": [ diff --git a/packages/typescript-typings/package.json b/packages/typescript-typings/package.json index 6640760e4..01cab8c63 100644 --- a/packages/typescript-typings/package.json +++ b/packages/typescript-typings/package.json @@ -26,7 +26,7 @@ "dependencies": { "@types/bn.js": "^4.11.0", "@types/react": "*", - "bignumber.js": "~4.1.0", + "bignumber.js": "~8.0.2", "ethereum-types": "^1.1.6", "popper.js": "1.14.3" }, diff --git a/packages/utils/CHANGELOG.json b/packages/utils/CHANGELOG.json index 851c106d8..0fb199e58 100644 --- a/packages/utils/CHANGELOG.json +++ b/packages/utils/CHANGELOG.json @@ -1,5 +1,14 @@ [ { + "version": "4.0.0", + "changes": [ + { + "note": "Upgrade the bignumber.js to v8.0.2", + "pr": 1517 + } + ] + }, + { "timestamp": 1547561734, "version": "3.0.1", "changes": [ diff --git a/packages/utils/package.json b/packages/utils/package.json index 315f5a08f..b6be39210 100644 --- a/packages/utils/package.json +++ b/packages/utils/package.json @@ -34,7 +34,7 @@ "@types/mocha": "^2.2.42", "chai": "^4.0.1", "chai-as-promised": "^7.1.0", - "chai-bignumber": "^2.0.1", + "chai-bignumber": "^3.0.0", "dirty-chai": "^2.0.1", "make-promises-safe": "^1.1.0", "mocha": "^4.1.0", @@ -48,7 +48,7 @@ "@0x/typescript-typings": "^3.0.8", "@types/node": "*", "abortcontroller-polyfill": "^1.1.9", - "bignumber.js": "~4.1.0", + "bignumber.js": "~8.0.2", "chalk": "^2.4.1", "detect-node": "2.0.3", "ethereum-types": "^1.1.6", diff --git a/packages/utils/src/abi_decoder.ts b/packages/utils/src/abi_decoder.ts index 2da46db35..28b6418d8 100644 --- a/packages/utils/src/abi_decoder.ts +++ b/packages/utils/src/abi_decoder.ts @@ -69,7 +69,7 @@ export class AbiDecoder { } if (param.type === SolidityTypes.Address) { const baseHex = 16; - value = addressUtils.padZeros(new BigNumber(value).toString(baseHex)); + value = addressUtils.padZeros(new BigNumber((value as string).toLowerCase()).toString(baseHex)); } else if (param.type === SolidityTypes.Uint256 || param.type === SolidityTypes.Uint) { value = new BigNumber(value); } else if (param.type === SolidityTypes.Uint8) { diff --git a/packages/utils/src/abi_encoder/evm_data_types/bool.ts b/packages/utils/src/abi_encoder/evm_data_types/bool.ts index 7f91f34e6..23298bc88 100644 --- a/packages/utils/src/abi_encoder/evm_data_types/bool.ts +++ b/packages/utils/src/abi_encoder/evm_data_types/bool.ts @@ -37,11 +37,11 @@ export class BoolDataType extends AbstractBlobDataType { const valueBuf = calldata.popWord(); const valueHex = ethUtil.bufferToHex(valueBuf); const valueNumber = new BigNumber(valueHex, constants.HEX_BASE); - if (!(valueNumber.equals(0) || valueNumber.equals(1))) { + if (!(valueNumber.isEqualTo(0) || valueNumber.isEqualTo(1))) { throw new Error(`Failed to decode boolean. Expected 0x0 or 0x1, got ${valueHex}`); } /* tslint:disable boolean-naming */ - const value: boolean = !valueNumber.equals(0); + const value: boolean = !valueNumber.isEqualTo(0); /* tslint:enable boolean-naming */ return value; } diff --git a/packages/utils/src/abi_encoder/evm_data_types/int.ts b/packages/utils/src/abi_encoder/evm_data_types/int.ts index cc3164b18..f8be1f778 100644 --- a/packages/utils/src/abi_encoder/evm_data_types/int.ts +++ b/packages/utils/src/abi_encoder/evm_data_types/int.ts @@ -38,8 +38,8 @@ export class IntDataType extends AbstractBlobDataType { throw new Error(`Tried to instantiate Int with bad input: ${dataItem}`); } this._width = IntDataType._decodeWidthFromType(dataItem.type); - this._minValue = new BigNumber(2).toPower(this._width - 1).times(-1); - this._maxValue = new BigNumber(2).toPower(this._width - 1).sub(1); + this._minValue = new BigNumber(2).exponentiatedBy(this._width - 1).times(-1); + this._maxValue = new BigNumber(2).exponentiatedBy(this._width - 1).minus(1); } public encodeValue(value: BigNumber | string | number): Buffer { diff --git a/packages/utils/src/abi_encoder/evm_data_types/uint.ts b/packages/utils/src/abi_encoder/evm_data_types/uint.ts index 8e382e8dc..a82aa789e 100644 --- a/packages/utils/src/abi_encoder/evm_data_types/uint.ts +++ b/packages/utils/src/abi_encoder/evm_data_types/uint.ts @@ -38,7 +38,7 @@ export class UIntDataType extends AbstractBlobDataType { throw new Error(`Tried to instantiate UInt with bad input: ${dataItem}`); } this._width = UIntDataType._decodeWidthFromType(dataItem.type); - this._maxValue = new BigNumber(2).toPower(this._width).sub(1); + this._maxValue = new BigNumber(2).exponentiatedBy(this._width).minus(1); } public encodeValue(value: BigNumber | string | number): Buffer { diff --git a/packages/utils/src/abi_encoder/utils/math.ts b/packages/utils/src/abi_encoder/utils/math.ts index d84983c5b..a2a79e2a8 100644 --- a/packages/utils/src/abi_encoder/utils/math.ts +++ b/packages/utils/src/abi_encoder/utils/math.ts @@ -1,7 +1,7 @@ -import BigNumber from 'bignumber.js'; import * as ethUtil from 'ethereumjs-util'; import * as _ from 'lodash'; +import { BigNumber } from '../../configured_bignumber'; import { constants } from '../utils/constants'; function sanityCheckBigNumberRange( @@ -10,10 +10,12 @@ function sanityCheckBigNumberRange( maxValue: BigNumber, ): void { const value = new BigNumber(value_, 10); - if (value.greaterThan(maxValue)) { + if (value.isGreaterThan(maxValue)) { throw new Error(`Tried to assign value of ${value}, which exceeds max value of ${maxValue}`); - } else if (value.lessThan(minValue)) { + } else if (value.isLessThan(minValue)) { throw new Error(`Tried to assign value of ${value}, which exceeds min value of ${minValue}`); + } else if (value.isNaN()) { + throw new Error(`Tried to assign NaN value`); } } function bigNumberToPaddedBuffer(value: BigNumber): Buffer { @@ -30,7 +32,7 @@ function bigNumberToPaddedBuffer(value: BigNumber): Buffer { export function encodeNumericValue(value_: BigNumber | string | number): Buffer { const value = new BigNumber(value_, 10); // Case 1/2: value is non-negative - if (value.greaterThanOrEqualTo(0)) { + if (value.isGreaterThanOrEqualTo(0)) { const encodedPositiveValue = bigNumberToPaddedBuffer(value); return encodedPositiveValue; } @@ -74,7 +76,7 @@ export function decodeNumericValue(encodedValue: Buffer, minValue: BigNumber): B const valueHex = ethUtil.bufferToHex(encodedValue); // Case 1/3: value is definitely non-negative because of numeric boundaries const value = new BigNumber(valueHex, constants.HEX_BASE); - if (!minValue.lessThan(0)) { + if (!minValue.isLessThan(0)) { return value; } // Case 2/3: value is non-negative because there is no leading 1 (encoded as two's-complement) diff --git a/packages/utils/src/sign_typed_data_utils.ts b/packages/utils/src/sign_typed_data_utils.ts index 6963b9084..adb66622d 100644 --- a/packages/utils/src/sign_typed_data_utils.ts +++ b/packages/utils/src/sign_typed_data_utils.ts @@ -1,8 +1,9 @@ +import { EIP712Object, EIP712ObjectValue, EIP712TypedData, EIP712Types } from '@0x/types'; import * as ethUtil from 'ethereumjs-util'; import * as ethers from 'ethers'; import * as _ from 'lodash'; -import { EIP712Object, EIP712ObjectValue, EIP712TypedData, EIP712Types } from '@0x/types'; +import { BigNumber } from './configured_bignumber'; export const signTypedDataUtils = { /** @@ -70,7 +71,7 @@ export const signTypedDataUtils = { return ethers.utils.defaultAbiCoder.encode(encodedTypes, encodedValues); }, _normalizeValue(type: string, value: any): EIP712ObjectValue { - const normalizedValue = type === 'uint256' && _.isObject(value) && value.isBigNumber ? value.toString() : value; + const normalizedValue = type === 'uint256' && BigNumber.isBigNumber(value) ? value.toString() : value; return normalizedValue; }, _typeHash(primaryType: string, types: EIP712Types): Buffer { diff --git a/packages/utils/test/abi_encoder/evm_data_types_test.ts b/packages/utils/test/abi_encoder/evm_data_types_test.ts index 54d536a7e..4814ce28b 100644 --- a/packages/utils/test/abi_encoder/evm_data_types_test.ts +++ b/packages/utils/test/abi_encoder/evm_data_types_test.ts @@ -205,7 +205,7 @@ describe('ABI Encoder: EVM Data Type Encoding/Decoding', () => { // Encode Args and validate result expect(() => { dataType.encode(args, encodingRules); - }).to.throw(); + }).to.throw('Tried to assign NaN value'); }); }); diff --git a/packages/web3-wrapper/CHANGELOG.json b/packages/web3-wrapper/CHANGELOG.json index 99eced094..4a639f662 100644 --- a/packages/web3-wrapper/CHANGELOG.json +++ b/packages/web3-wrapper/CHANGELOG.json @@ -1,8 +1,12 @@ [ { - "version": "3.2.5", + "version": "4.0.0", "changes": [ { + "note": "Upgrade the bignumber.js to v8.0.2", + "pr": 1517 + }, + { "note": "Update ganache-core to v2.3.3", "pr": 1518 } diff --git a/packages/web3-wrapper/package.json b/packages/web3-wrapper/package.json index da5186f14..f28cc36ca 100644 --- a/packages/web3-wrapper/package.json +++ b/packages/web3-wrapper/package.json @@ -41,7 +41,7 @@ "@types/lodash": "4.14.104", "chai": "^4.0.1", "chai-as-promised": "^7.1.0", - "chai-bignumber": "^2.0.1", + "chai-bignumber": "^3.0.0", "dirty-chai": "^2.0.1", "ganache-core": "^2.3.3", "make-promises-safe": "^1.1.0", diff --git a/packages/web3-wrapper/src/utils.ts b/packages/web3-wrapper/src/utils.ts index c68587632..1aba3c75a 100644 --- a/packages/web3-wrapper/src/utils.ts +++ b/packages/web3-wrapper/src/utils.ts @@ -2,10 +2,6 @@ import { BigNumber } from '@0x/utils'; import * as _ from 'lodash'; export const utils = { - isBigNumber(value: any): boolean { - const isBigNumber = _.isObject(value) && value.isBigNumber; - return isBigNumber; - }, convertHexToNumber(value: string): number { const valueBigNumber = new BigNumber(value); const valueNumber = valueBigNumber.toNumber(); @@ -20,7 +16,7 @@ export const utils = { }, convertAmountToBigNumber(value: string | number | BigNumber): BigNumber { const num = value || 0; - const isBigNumber = utils.isBigNumber(num); + const isBigNumber = BigNumber.isBigNumber(num); if (isBigNumber) { return num as BigNumber; } @@ -37,7 +33,7 @@ export const utils = { const hexBase = 16; const valueHex = valueBigNumber.toString(hexBase); - return valueBigNumber.lessThan(0) ? `-0x${valueHex.substr(1)}` : `0x${valueHex}`; + return valueBigNumber.isLessThan(0) ? `-0x${valueHex.substr(1)}` : `0x${valueHex}`; }, numberToHex(value: number): string { if (!isFinite(value) && !utils.isHexStrict(value)) { diff --git a/packages/web3-wrapper/test/web3_wrapper_test.ts b/packages/web3-wrapper/test/web3_wrapper_test.ts index 32628422e..c4ee91d3d 100644 --- a/packages/web3-wrapper/test/web3_wrapper_test.ts +++ b/packages/web3-wrapper/test/web3_wrapper_test.ts @@ -1,10 +1,10 @@ +import { BigNumber } from '@0x/utils'; import * as chai from 'chai'; import { BlockParamLiteral, JSONRPCErrorCallback, JSONRPCRequestPayload, TransactionReceipt } from 'ethereum-types'; import * as Ganache from 'ganache-core'; import * as _ from 'lodash'; import 'mocha'; -import { utils } from '../src/utils'; import { Web3Wrapper } from '../src/web3_wrapper'; import { chaiSetup } from './utils/chai_setup'; @@ -118,7 +118,7 @@ describe('Web3Wrapper tests', () => { throw new Error('Expected block to exist'); } expect(blockIfExists.number).to.be.equal(0); - expect(utils.isBigNumber(blockIfExists.difficulty)).to.equal(true); + expect(BigNumber.isBigNumber(blockIfExists.difficulty)).to.equal(true); expect(_.isNumber(blockIfExists.gasLimit)).to.equal(true); }); it('gets block when supplied a block number', async () => { @@ -151,7 +151,7 @@ describe('Web3Wrapper tests', () => { const blockParamLiteral = BlockParamLiteral.Earliest; const block = await web3Wrapper.getBlockWithTransactionDataAsync(blockParamLiteral); expect(block.number).to.be.equal(0); - expect(utils.isBigNumber(block.difficulty)).to.equal(true); + expect(BigNumber.isBigNumber(block.difficulty)).to.equal(true); expect(_.isNumber(block.gasLimit)).to.equal(true); }); it('should throw if supplied invalid blockParam value', async () => { diff --git a/packages/website/ts/blockchain.ts b/packages/website/ts/blockchain.ts index 37f746f7c..ea5a59340 100644 --- a/packages/website/ts/blockchain.ts +++ b/packages/website/ts/blockchain.ts @@ -944,7 +944,7 @@ export class Blockchain { try { const gasInfo = await backendClient.getGasInfoAsync(); const gasPriceInGwei = new BigNumber(gasInfo.fast / 10); - const gasPriceInWei = gasPriceInGwei.mul(1000000000); + const gasPriceInWei = gasPriceInGwei.multipliedBy(1000000000); this._defaultGasPrice = gasPriceInWei; } catch (err) { return; diff --git a/packages/website/ts/components/fill_order.tsx b/packages/website/ts/components/fill_order.tsx index 7fee8c4df..95a3671c4 100644 --- a/packages/website/ts/components/fill_order.tsx +++ b/packages/website/ts/components/fill_order.tsx @@ -205,7 +205,7 @@ export class FillOrder extends React.Component<FillOrderProps, FillOrderState> { amount: orderMakerAmount .times(takerAssetToken.amount) .div(orderTakerAmount) - .floor(), + .integerValue(BigNumber.ROUND_FLOOR), symbol: makerToken.symbol, }; const fillAssetToken = { @@ -219,7 +219,7 @@ export class FillOrder extends React.Component<FillOrderProps, FillOrderState> { const orderReceiveAmountBigNumber = orderMakerAmount .times(this.props.orderFillAmount) .dividedBy(orderTakerAmount) - .floor(); + .integerValue(BigNumber.ROUND_FLOOR); orderReceiveAmount = this._formatCurrencyAmount(orderReceiveAmountBigNumber, makerToken.decimals); } const isUserMaker = diff --git a/packages/website/ts/utils/utils.ts b/packages/website/ts/utils/utils.ts index 890f1553a..e84f9d0cc 100644 --- a/packages/website/ts/utils/utils.ts +++ b/packages/website/ts/utils/utils.ts @@ -394,7 +394,7 @@ export const utils = { }, getUsdValueFormattedAmount(amount: BigNumber, decimals: number, price: BigNumber): string { const unitAmount = Web3Wrapper.toUnitAmount(amount, decimals); - const value = unitAmount.mul(price); + const value = unitAmount.multipliedBy(price); return utils.format(value, constants.NUMERAL_USD_FORMAT); }, openUrl(url: string): void { |