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 --- .../contract-wrappers/src/contract_wrappers/erc20_token_wrapper.ts | 6 +++--- .../src/fetchers/asset_balance_and_proxy_allowance_fetcher.ts | 4 ++-- packages/contract-wrappers/src/utils/exchange_transfer_simulator.ts | 4 ++-- packages/contract-wrappers/src/utils/utils.ts | 6 ++++-- packages/contract-wrappers/test/ether_token_wrapper_test.ts | 6 +++--- 5 files changed, 14 insertions(+), 12 deletions(-) (limited to 'packages/contract-wrappers') 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), -- cgit v1.2.3