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 From eb393f0a6643183c784914bf3e039d1f4299247d Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Mon, 14 Jan 2019 15:53:43 +0100 Subject: Upgrade chai-bignumber --- packages/contract-wrappers/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'packages/contract-wrappers') diff --git a/packages/contract-wrappers/package.json b/packages/contract-wrappers/package.json index c4f75a5a4..45b34ab10 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": "^2.0.2", "dirty-chai": "^2.0.1", "make-promises-safe": "^1.1.0", "mocha": "^4.1.0", -- cgit From 20eab4257a58c6783cf2313b160d6df342cdc7d2 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Tue, 15 Jan 2019 12:20:54 +0100 Subject: Upgrade chai-bignumber --- packages/contract-wrappers/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'packages/contract-wrappers') diff --git a/packages/contract-wrappers/package.json b/packages/contract-wrappers/package.json index 45b34ab10..8fefbd95c 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.2", + "chai-bignumber": "^3.0.0", "dirty-chai": "^2.0.1", "make-promises-safe": "^1.1.0", "mocha": "^4.1.0", -- cgit From 4404f92b3809a1edf538a1ebda6e0afe053b5e0c Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Tue, 15 Jan 2019 17:05:51 +0100 Subject: Add CHANGELOG entries --- packages/contract-wrappers/CHANGELOG.json | 57 ++++++++++++++++++++++--------- 1 file changed, 41 insertions(+), 16 deletions(-) (limited to 'packages/contract-wrappers') diff --git a/packages/contract-wrappers/CHANGELOG.json b/packages/contract-wrappers/CHANGELOG.json index bfba8454c..5b5654067 100644 --- a/packages/contract-wrappers/CHANGELOG.json +++ b/packages/contract-wrappers/CHANGELOG.json @@ -1,4 +1,13 @@ [ + { + "version": "6.0.0", + "changes": [ + { + "note": "Upgrade the bignumber.js to v8.0.2", + "pr": 1517 + } + ] + }, { "version": "5.0.0", "changes": [ @@ -75,7 +84,8 @@ "version": "4.1.0", "changes": [ { - "note": "Add a `nonce` field for `TxOpts` so that it's now possible to re-broadcast stuck transactions with a higher gas amount", + "note": + "Add a `nonce` field for `TxOpts` so that it's now possible to re-broadcast stuck transactions with a higher gas amount", "pr": 1292 } ], @@ -103,15 +113,18 @@ "version": "4.0.0", "changes": [ { - "note": "Add signature validation, regular cancellation and `cancelledUpTo` checks to `validateOrderFillableOrThrowAsync`", + "note": + "Add signature validation, regular cancellation and `cancelledUpTo` checks to `validateOrderFillableOrThrowAsync`", "pr": 1235 }, { - "note": "Improved the errors thrown by `validateOrderFillableOrThrowAsync` by making them more descriptive", + "note": + "Improved the errors thrown by `validateOrderFillableOrThrowAsync` by making them more descriptive", "pr": 1235 }, { - "note": "Throw previously swallowed network errors when calling `validateOrderFillableOrThrowAsync` (see issue: #1218)", + "note": + "Throw previously swallowed network errors when calling `validateOrderFillableOrThrowAsync` (see issue: #1218)", "pr": 1235 } ], @@ -142,23 +155,28 @@ "pr": 1105 }, { - "note": "Default contract addresses are no longer stored in artifacts and are instead loaded from the `@0xproject/contract-addresses` package.", + "note": + "Default contract addresses are no longer stored in artifacts and are instead loaded from the `@0xproject/contract-addresses` package.", "pr": 1105 }, { - "note": "Most contract addresses are now defined at instantiation time and are available as properties (e.g., `exchangeWrapper.address`) instead of methods (e.g., `exchangeWrapper.getContractAddress()`).", + "note": + "Most contract addresses are now defined at instantiation time and are available as properties (e.g., `exchangeWrapper.address`) instead of methods (e.g., `exchangeWrapper.getContractAddress()`).", "pr": 1105 }, { - "note": "Removed `setProvider` method in top-level `ContractWrapper` class and added new `unsubscribeAll` method.", + "note": + "Removed `setProvider` method in top-level `ContractWrapper` class and added new `unsubscribeAll` method.", "pr": 1105 }, { - "note": "Some properties and methods have been renamed. For example, some methods that previously could throw no longer can, and so their names have been updated accordingly.", + "note": + "Some properties and methods have been renamed. For example, some methods that previously could throw no longer can, and so their names have been updated accordingly.", "pr": 1105 }, { - "note": "Removed ContractNotFound errors. Checking for this error was somewhat ineffecient. Relevant methods/functions now return the default error from web3-wrapper, which we feel provides enough information.", + "note": + "Removed ContractNotFound errors. Checking for this error was somewhat ineffecient. Relevant methods/functions now return the default error from web3-wrapper, which we feel provides enough information.", "pr": 1105 }, { @@ -194,11 +212,13 @@ "version": "2.0.0", "changes": [ { - "note": "Fixes dropped events in subscriptions by fetching logs by blockHash instead of blockNumber. Support for fetching by blockHash was added in Geth > v1.8.13 and Parity > v2.1.0. Infura works too.", + "note": + "Fixes dropped events in subscriptions by fetching logs by blockHash instead of blockNumber. Support for fetching by blockHash was added in Geth > v1.8.13 and Parity > v2.1.0. Infura works too.", "pr": 1080 }, { - "note": "Fix misunderstanding about blockstream interface callbacks and pass the raw JSON RPC responses to it", + "note": + "Fix misunderstanding about blockstream interface callbacks and pass the raw JSON RPC responses to it", "pr": 1080 } ], @@ -247,15 +267,18 @@ "note": "Add `OrderValidatorWrapper`" }, { - "note": "Fix bug where contracts not deployed on a network showed an `EXCHANGE_CONTRACT_DOES_NOT_EXIST` error instead of `CONTRACT_NOT_DEPLOYED_ON_NETWORK`", + "note": + "Fix bug where contracts not deployed on a network showed an `EXCHANGE_CONTRACT_DOES_NOT_EXIST` error instead of `CONTRACT_NOT_DEPLOYED_ON_NETWORK`", "pr": 1044 }, { - "note": "Export `AssetBalanceAndProxyAllowanceFetcher` and `OrderFilledCancelledFetcher` implementations", + "note": + "Export `AssetBalanceAndProxyAllowanceFetcher` and `OrderFilledCancelledFetcher` implementations", "pr": 1054 }, { - "note": "Add `validateOrderFillableOrThrowAsync` and `validateFillOrderThrowIfInvalidAsync` to ExchangeWrapper", + "note": + "Add `validateOrderFillableOrThrowAsync` and `validateFillOrderThrowIfInvalidAsync` to ExchangeWrapper", "pr": 1054 } ], @@ -274,11 +297,13 @@ "version": "1.0.1-rc.4", "changes": [ { - "note": "Export missing types: `TransactionEncoder`, `ContractAbi`, `JSONRPCRequestPayload`, `JSONRPCResponsePayload`, `JSONRPCErrorCallback`, `AbiDefinition`, `FunctionAbi`, `EventAbi`, `EventParameter`, `DecodedLogArgs`, `MethodAbi`, `ConstructorAbi`, `FallbackAbi`, `DataItem`, `ConstructorStateMutability`, `StateMutability` & `ExchangeSignatureValidatorApprovalEventArgs`", + "note": + "Export missing types: `TransactionEncoder`, `ContractAbi`, `JSONRPCRequestPayload`, `JSONRPCResponsePayload`, `JSONRPCErrorCallback`, `AbiDefinition`, `FunctionAbi`, `EventAbi`, `EventParameter`, `DecodedLogArgs`, `MethodAbi`, `ConstructorAbi`, `FallbackAbi`, `DataItem`, `ConstructorStateMutability`, `StateMutability` & `ExchangeSignatureValidatorApprovalEventArgs`", "pr": 924 }, { - "note": "Remove superfluous exported types: `ContractEvent`, `Token`, `OrderFillRequest`, `ContractEventArgs`, `LogEvent`, `OnOrderStateChangeCallback`, `ECSignature`, `OrderStateValid`, `OrderStateInvalid`, `OrderState`, `FilterObject`, `TransactionReceipt` & `TransactionReceiptWithDecodedLogs`", + "note": + "Remove superfluous exported types: `ContractEvent`, `Token`, `OrderFillRequest`, `ContractEventArgs`, `LogEvent`, `OnOrderStateChangeCallback`, `ECSignature`, `OrderStateValid`, `OrderStateInvalid`, `OrderState`, `FilterObject`, `TransactionReceipt` & `TransactionReceiptWithDecodedLogs`", "pr": 924 }, { -- cgit From 7d166dc7da23c30540fb554727a955015073286f Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Tue, 15 Jan 2019 17:34:44 +0100 Subject: Fix prettier --- packages/contract-wrappers/CHANGELOG.json | 48 +++++++++++-------------------- 1 file changed, 16 insertions(+), 32 deletions(-) (limited to 'packages/contract-wrappers') diff --git a/packages/contract-wrappers/CHANGELOG.json b/packages/contract-wrappers/CHANGELOG.json index 5b5654067..09c585cc5 100644 --- a/packages/contract-wrappers/CHANGELOG.json +++ b/packages/contract-wrappers/CHANGELOG.json @@ -84,8 +84,7 @@ "version": "4.1.0", "changes": [ { - "note": - "Add a `nonce` field for `TxOpts` so that it's now possible to re-broadcast stuck transactions with a higher gas amount", + "note": "Add a `nonce` field for `TxOpts` so that it's now possible to re-broadcast stuck transactions with a higher gas amount", "pr": 1292 } ], @@ -113,18 +112,15 @@ "version": "4.0.0", "changes": [ { - "note": - "Add signature validation, regular cancellation and `cancelledUpTo` checks to `validateOrderFillableOrThrowAsync`", + "note": "Add signature validation, regular cancellation and `cancelledUpTo` checks to `validateOrderFillableOrThrowAsync`", "pr": 1235 }, { - "note": - "Improved the errors thrown by `validateOrderFillableOrThrowAsync` by making them more descriptive", + "note": "Improved the errors thrown by `validateOrderFillableOrThrowAsync` by making them more descriptive", "pr": 1235 }, { - "note": - "Throw previously swallowed network errors when calling `validateOrderFillableOrThrowAsync` (see issue: #1218)", + "note": "Throw previously swallowed network errors when calling `validateOrderFillableOrThrowAsync` (see issue: #1218)", "pr": 1235 } ], @@ -155,28 +151,23 @@ "pr": 1105 }, { - "note": - "Default contract addresses are no longer stored in artifacts and are instead loaded from the `@0xproject/contract-addresses` package.", + "note": "Default contract addresses are no longer stored in artifacts and are instead loaded from the `@0xproject/contract-addresses` package.", "pr": 1105 }, { - "note": - "Most contract addresses are now defined at instantiation time and are available as properties (e.g., `exchangeWrapper.address`) instead of methods (e.g., `exchangeWrapper.getContractAddress()`).", + "note": "Most contract addresses are now defined at instantiation time and are available as properties (e.g., `exchangeWrapper.address`) instead of methods (e.g., `exchangeWrapper.getContractAddress()`).", "pr": 1105 }, { - "note": - "Removed `setProvider` method in top-level `ContractWrapper` class and added new `unsubscribeAll` method.", + "note": "Removed `setProvider` method in top-level `ContractWrapper` class and added new `unsubscribeAll` method.", "pr": 1105 }, { - "note": - "Some properties and methods have been renamed. For example, some methods that previously could throw no longer can, and so their names have been updated accordingly.", + "note": "Some properties and methods have been renamed. For example, some methods that previously could throw no longer can, and so their names have been updated accordingly.", "pr": 1105 }, { - "note": - "Removed ContractNotFound errors. Checking for this error was somewhat ineffecient. Relevant methods/functions now return the default error from web3-wrapper, which we feel provides enough information.", + "note": "Removed ContractNotFound errors. Checking for this error was somewhat ineffecient. Relevant methods/functions now return the default error from web3-wrapper, which we feel provides enough information.", "pr": 1105 }, { @@ -212,13 +203,11 @@ "version": "2.0.0", "changes": [ { - "note": - "Fixes dropped events in subscriptions by fetching logs by blockHash instead of blockNumber. Support for fetching by blockHash was added in Geth > v1.8.13 and Parity > v2.1.0. Infura works too.", + "note": "Fixes dropped events in subscriptions by fetching logs by blockHash instead of blockNumber. Support for fetching by blockHash was added in Geth > v1.8.13 and Parity > v2.1.0. Infura works too.", "pr": 1080 }, { - "note": - "Fix misunderstanding about blockstream interface callbacks and pass the raw JSON RPC responses to it", + "note": "Fix misunderstanding about blockstream interface callbacks and pass the raw JSON RPC responses to it", "pr": 1080 } ], @@ -267,18 +256,15 @@ "note": "Add `OrderValidatorWrapper`" }, { - "note": - "Fix bug where contracts not deployed on a network showed an `EXCHANGE_CONTRACT_DOES_NOT_EXIST` error instead of `CONTRACT_NOT_DEPLOYED_ON_NETWORK`", + "note": "Fix bug where contracts not deployed on a network showed an `EXCHANGE_CONTRACT_DOES_NOT_EXIST` error instead of `CONTRACT_NOT_DEPLOYED_ON_NETWORK`", "pr": 1044 }, { - "note": - "Export `AssetBalanceAndProxyAllowanceFetcher` and `OrderFilledCancelledFetcher` implementations", + "note": "Export `AssetBalanceAndProxyAllowanceFetcher` and `OrderFilledCancelledFetcher` implementations", "pr": 1054 }, { - "note": - "Add `validateOrderFillableOrThrowAsync` and `validateFillOrderThrowIfInvalidAsync` to ExchangeWrapper", + "note": "Add `validateOrderFillableOrThrowAsync` and `validateFillOrderThrowIfInvalidAsync` to ExchangeWrapper", "pr": 1054 } ], @@ -297,13 +283,11 @@ "version": "1.0.1-rc.4", "changes": [ { - "note": - "Export missing types: `TransactionEncoder`, `ContractAbi`, `JSONRPCRequestPayload`, `JSONRPCResponsePayload`, `JSONRPCErrorCallback`, `AbiDefinition`, `FunctionAbi`, `EventAbi`, `EventParameter`, `DecodedLogArgs`, `MethodAbi`, `ConstructorAbi`, `FallbackAbi`, `DataItem`, `ConstructorStateMutability`, `StateMutability` & `ExchangeSignatureValidatorApprovalEventArgs`", + "note": "Export missing types: `TransactionEncoder`, `ContractAbi`, `JSONRPCRequestPayload`, `JSONRPCResponsePayload`, `JSONRPCErrorCallback`, `AbiDefinition`, `FunctionAbi`, `EventAbi`, `EventParameter`, `DecodedLogArgs`, `MethodAbi`, `ConstructorAbi`, `FallbackAbi`, `DataItem`, `ConstructorStateMutability`, `StateMutability` & `ExchangeSignatureValidatorApprovalEventArgs`", "pr": 924 }, { - "note": - "Remove superfluous exported types: `ContractEvent`, `Token`, `OrderFillRequest`, `ContractEventArgs`, `LogEvent`, `OnOrderStateChangeCallback`, `ECSignature`, `OrderStateValid`, `OrderStateInvalid`, `OrderState`, `FilterObject`, `TransactionReceipt` & `TransactionReceiptWithDecodedLogs`", + "note": "Remove superfluous exported types: `ContractEvent`, `Token`, `OrderFillRequest`, `ContractEventArgs`, `LogEvent`, `OnOrderStateChangeCallback`, `ECSignature`, `OrderStateValid`, `OrderStateInvalid`, `OrderState`, `FilterObject`, `TransactionReceipt` & `TransactionReceiptWithDecodedLogs`", "pr": 924 }, { -- cgit