From c3afc13dd660348e99b727c2dd01930eec8d99c3 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Mon, 14 Jan 2019 15:50:32 +0100 Subject: Upgrade bignumber.js version --- packages/assert/src/index.ts | 2 +- .../asset-buyer/src/utils/buy_quote_calculator.ts | 10 ++++---- .../src/utils/order_provider_response_processor.ts | 7 ++---- packages/asset-buyer/src/utils/order_utils.ts | 28 +++++++++++----------- .../asset-buyer/test/buy_quote_calculator_test.ts | 6 ++--- .../src/contract_wrappers/erc20_token_wrapper.ts | 6 ++--- .../asset_balance_and_proxy_allowance_fetcher.ts | 4 ++-- .../src/utils/exchange_transfer_simulator.ts | 4 ++-- packages/contract-wrappers/src/utils/utils.ts | 6 +++-- .../test/ether_token_wrapper_test.ts | 6 ++--- packages/ethereum-types/package.json | 2 +- packages/instant/src/components/order_details.tsx | 4 ++-- packages/instant/src/constants.ts | 2 +- .../selected_erc20_asset_amount_input.ts | 2 +- packages/instant/src/redux/async_data.ts | 2 +- packages/instant/src/util/asset.ts | 11 +++++---- packages/instant/src/util/format.ts | 8 +++---- packages/instant/src/util/gas_price_estimator.ts | 2 +- packages/instant/src/util/maybe_big_number.ts | 2 +- .../order-utils/src/exchange_transfer_simulator.ts | 4 ++-- packages/order-utils/src/market_utils.ts | 4 ++-- packages/order-utils/src/order_state_utils.ts | 12 +++++----- packages/order-utils/src/order_validation_utils.ts | 8 +++---- packages/order-utils/src/rate_utils.ts | 6 ++--- .../src/remaining_fillable_calculator.ts | 6 ++--- packages/order-utils/src/salt.ts | 2 +- packages/order-utils/src/utils.ts | 6 ++--- .../test/remaining_fillable_calculator_test.ts | 2 +- packages/order-utils/test/signature_utils_test.ts | 4 ++-- .../src/order_watcher/expiration_watcher.ts | 2 +- packages/order-watcher/src/utils/utils.ts | 2 +- packages/order-watcher/test/order_watcher_test.ts | 6 ++--- .../src/utils/transformers/number_to_bigint.ts | 2 +- .../testnet-faucets/src/ts/dispense_asset_tasks.ts | 4 ++-- packages/testnet-faucets/src/ts/handler.ts | 2 +- packages/types/package.json | 2 +- packages/typescript-typings/package.json | 2 +- packages/utils/package.json | 2 +- .../utils/src/abi_encoder/evm_data_types/bool.ts | 4 ++-- .../utils/src/abi_encoder/evm_data_types/int.ts | 4 ++-- .../utils/src/abi_encoder/evm_data_types/uint.ts | 2 +- packages/utils/src/abi_encoder/utils/math.ts | 8 +++---- packages/web3-wrapper/src/utils.ts | 2 +- packages/website/ts/blockchain.ts | 2 +- packages/website/ts/components/fill_order.tsx | 4 ++-- packages/website/ts/utils/utils.ts | 2 +- 46 files changed, 110 insertions(+), 110 deletions(-) (limited to 'packages') diff --git a/packages/assert/src/index.ts b/packages/assert/src/index.ts index 2d28d51e1..b9a04686a 100644 --- a/packages/assert/src/index.ts +++ b/packages/assert/src/index.ts @@ -12,7 +12,7 @@ export const assert = { }, 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/src/utils/buy_quote_calculator.ts b/packages/asset-buyer/src/utils/buy_quote_calculator.ts index fcded6ab1..9205678e7 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,7 @@ 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 +131,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 +168,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 fdc17ef25..cf443bef3 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/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(obj: T): Partial { 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/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/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 { } 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 { 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..a6fd77d5a 100644 --- a/packages/instant/src/util/asset.ts +++ b/packages/instant/src/util/asset.ts @@ -104,8 +104,9 @@ export const assetUtils = { return assetDataGroupIfExists[Network.Mainnet]; }, getERC20AssetsFromAssets: (assets: Asset[]): ERC20Asset[] => { - const erc20sOrUndefined = _.map(assets, asset => - asset.metaData.assetProxyId === AssetProxyId.ERC20 ? (asset as ERC20Asset) : undefined, + const erc20sOrUndefined = _.map( + assets, + asset => (asset.metaData.assetProxyId === AssetProxyId.ERC20 ? (asset as ERC20Asset) : undefined), ); return _.compact(erc20sOrUndefined); }, @@ -114,15 +115,15 @@ 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.integerValue(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..eef332d3c 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.integerValue(decimalPlaces).toDigits(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 => { 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, val2: Maybe): boolean => { if (!_.isUndefined(val1) && !_.isUndefined(val2)) { - return val1.equals(val2); + return val1.isEqualTo(val2); } return _.isUndefined(val1) && _.isUndefined(val2); }, 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/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/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/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..54387749f 100644 --- a/packages/testnet-faucets/src/ts/handler.ts +++ b/packages/testnet-faucets/src/ts/handler.ts @@ -179,7 +179,7 @@ export class Handler { 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).div(1000).integerValue(BigNumber.ROUND_FLOOR), }; const orderHash = orderHashUtils.getOrderHashHex(order); const signature = await signatureUtils.ecSignHashAsync( 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/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/package.json b/packages/utils/package.json index 315f5a08f..3b16550a5 100644 --- a/packages/utils/package.json +++ b/packages/utils/package.json @@ -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_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 8d98e195b..b7e0d9f4e 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..b2fa5fe7d 100644 --- a/packages/utils/src/abi_encoder/utils/math.ts +++ b/packages/utils/src/abi_encoder/utils/math.ts @@ -10,9 +10,9 @@ 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}`); } } @@ -30,7 +30,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 +74,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/web3-wrapper/src/utils.ts b/packages/web3-wrapper/src/utils.ts index c68587632..1b67518b1 100644 --- a/packages/web3-wrapper/src/utils.ts +++ b/packages/web3-wrapper/src/utils.ts @@ -37,7 +37,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/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 { 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 { 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 { -- cgit v1.2.3