Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rpc: Upgrade BigNumber.js version used by Mesh TS Client to ~9.0.0 #527

Merged
merged 7 commits into from Nov 14, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Expand Up @@ -2,6 +2,10 @@

This changelog is a work in progress and may contain notes for versions which have not actually been released. Check the [Releases](https://github.com/0xProject/0x-mesh/releases) page to see full release notes and more information about the latest released versions.

## v7.0.3-beta-0xv3

- Upgrade BigNumber dep used by `@0x/mesh-rpc-client` to `~9.0.0` ([#527](https://github.com/0xProject/0x-mesh/pull/527))

## v7.0.2-beta-0xv3

### Bug fixes 🐞
Expand Down
4 changes: 3 additions & 1 deletion rpc/clients/typescript/package.json
Expand Up @@ -34,8 +34,9 @@
"@0x/order-utils": "8.5.0-beta.1",
"@0x/types": "2.5.0-beta.1",
"@0x/typescript-typings": "4.4.0-beta.1",
"@0x/utils": "^4.6.0-beta.1",
"@0x/web3-providers-fork": "0.0.7",
"bignumber.js": "~9.0.0",
"detect-node": "2.0.3",
"uuid": "^3.3.2",
"websocket": "^1.0.29"
},
Expand All @@ -46,6 +47,7 @@
"@types/mocha": "^2.2.42",
"@types/uuid": "^3.4.3",
"@types/websocket": "^0.0.40",
"@types/detect-node": "2.0.0",
"chai": "^4.0.1",
"chai-as-promised": "^7.1.0",
"chai-bignumber": "^3.0.0",
Expand Down
39 changes: 39 additions & 0 deletions rpc/clients/typescript/src/configured_bignumber.ts
@@ -0,0 +1,39 @@
import { BigNumber } from 'bignumber.js';

// HACK(fabio): This is copied from `@0x/utils`. Once we've updated it to BigNumber.js ~9.0.0,
// we should remove this and go back to using the library
BigNumber.config({
// By default BigNumber's `toString` method converts to exponential notation if the value has
// more then 20 digits. We want to avoid this behavior, so we set EXPONENTIAL_AT to a high number
EXPONENTIAL_AT: 1000,
// Note(albrow): This is the lowest value for which
// `x.div(y).floor() === x.divToInt(y)`
// for all values of x and y <= MAX_UINT256, where MAX_UINT256 is the
// maximum number represented by the uint256 type in Solidity (2^256-1).
DECIMAL_PLACES: 78,
});

// Set a debug print function for NodeJS
// Upstream issue: https://github.com/MikeMcl/bignumber.js/issues/188
import isNode = require('detect-node');
if (isNode) {
// Dynamically load a NodeJS specific module.
// TypeScript requires all imports to be global, so we need to use
// `const` here and disable the tslint warning.
// tslint:disable-next-line: no-var-requires
const util = require('util');

// Set a custom util.inspect function
// HACK: We add a function to the BigNumber class by assigning to the
// prototype. The function name is a symbol provided by Node.
(BigNumber.prototype as any)[util.inspect.custom] = function(): string {
// HACK: When executed, `this` will refer to the BigNumber instance.
// This is also why we need a function expression instead of an
// arrow function, as the latter does not have a `this`.
// Return the readable string representation
// tslint:disable-next-line: no-invalid-this
return this.toString();
};
}

export { BigNumber };
2 changes: 1 addition & 1 deletion rpc/clients/typescript/src/index.ts
Expand Up @@ -16,4 +16,4 @@ export {
GetStatsResponse,
} from './types';
export { SignedOrder } from '@0x/types';
export { BigNumber } from '@0x/utils';
export { BigNumber } from './configured_bignumber';
3 changes: 2 additions & 1 deletion rpc/clients/typescript/src/types.ts
@@ -1,5 +1,6 @@
import { SignedOrder } from '@0x/types';
import { BigNumber } from '@0x/utils';
fabioberger marked this conversation as resolved.
Show resolved Hide resolved

import { BigNumber } from './configured_bignumber';

/**
* WebSocketClient configs
Expand Down
2 changes: 1 addition & 1 deletion rpc/clients/typescript/src/ws_client.ts
@@ -1,11 +1,11 @@
import { assert } from '@0x/assert';
import { orderParsingUtils } from '@0x/order-utils';
import { ObjectMap, SignedOrder } from '@0x/types';
import { BigNumber } from '@0x/utils';
import * as Web3Providers from '@0x/web3-providers-fork';
import { v4 as uuid } from 'uuid';
import * as WebSocket from 'websocket';

import { BigNumber } from './configured_bignumber';
import {
AcceptedOrderInfo,
ContractEvent,
Expand Down
4 changes: 2 additions & 2 deletions rpc/clients/typescript/test/utils/mock_ws_server.ts
@@ -1,4 +1,3 @@
import { logUtils } from '@0x/utils';
import * as http from 'http';
import * as WebSocket from 'websocket';

Expand Down Expand Up @@ -45,6 +44,7 @@ export function stopServer(): void {
wsServer.shutDown();
server.close();
} catch (e) {
logUtils.log('stopServer threw', e);
// tslint:disable-next-line:no-console
console.log('stopServer threw', e);
}
}
12 changes: 6 additions & 6 deletions rpc/clients/typescript/test/ws_client_test.ts
Expand Up @@ -160,18 +160,18 @@ describe('WSClient', () => {
{
makerAddress: '0xa3ece5d5b6319fa785efc10d3112769a46c6e149',
takerAddress: '0x0000000000000000000000000000000000000000',
makerAssetAmount: new BigNumber('1000000000000000000'),
takerAssetAmount: new BigNumber('10000000000000000000000'),
expirationTimeSeconds: new BigNumber('1586340602'),
makerFee: new BigNumber('0'),
takerFee: new BigNumber('0'),
makerAssetAmount: new BigNumber('1000000000000000000') as any,
takerAssetAmount: new BigNumber('10000000000000000000000') as any,
expirationTimeSeconds: new BigNumber('1586340602') as any,
makerFee: new BigNumber('0') as any,
takerFee: new BigNumber('0') as any,
feeRecipientAddress: '0x0000000000000000000000000000000000000000',
senderAddress: '0x0000000000000000000000000000000000000000',
exchangeAddress: '0x080bf510fcbf18b91105470639e9561022937712',
chainId: 1,
salt: new BigNumber(
'41253767178111694375645046549067933145709740457131351457334397888365956743955',
),
) as any,
makerAssetData: '0xf47261b0000000000000000000000000e41d2489571d322189246dafa5ebde1f4699f498',
makerFeeAssetData: '0x',
takerAssetData: '0xf47261b0000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
Expand Down
10 changes: 10 additions & 0 deletions rpc/clients/typescript/yarn.lock
Expand Up @@ -356,6 +356,11 @@
dependencies:
"@types/node" "*"

"@types/detect-node@2.0.0":
version "2.0.0"
resolved "https://registry.yarnpkg.com/@types/detect-node/-/detect-node-2.0.0.tgz#696e024ddd105c72bbc6a2e3f97902a2886f2c3f"
integrity sha512-+BozjlbPTACYITf1PWf62HLtDV79HbmZosUN1mv1gGrnjDCRwBXkDKka1sf6YQJvspmfPXVcy+X6tFW62KteeQ==

"@types/ethereum-protocol@*":
version "1.0.0"
resolved "https://registry.yarnpkg.com/@types/ethereum-protocol/-/ethereum-protocol-1.0.0.tgz#416e3827d5fdfa4658b0045b35a008747871b271"
Expand Down Expand Up @@ -1354,6 +1359,11 @@ bignumber.js@~8.0.2:
resolved "https://registry.yarnpkg.com/bignumber.js/-/bignumber.js-8.0.2.tgz#d8c4e1874359573b1ef03011a2d861214aeef137"
integrity sha512-EiuvFrnbv0jFixEQ9f58jo7X0qI2lNGIr/MxntmVzQc5JUweDSh8y8hbTCAomFtqwUPIOWcLXP0VEOSZTG7FFw==

bignumber.js@~9.0.0:
version "9.0.0"
resolved "https://registry.yarnpkg.com/bignumber.js/-/bignumber.js-9.0.0.tgz#805880f84a329b5eac6e7cb6f8274b6d82bdf075"
integrity sha512-t/OYhhJ2SD+YGBQcjY8GzzDHEk9f3nerxjtfa6tlMXfe7frs/WozhvCNoGvpM0P3bNf3Gq5ZRMlGr5f3r4/N8A==

binary-extensions@^1.0.0:
version "1.13.1"
resolved "https://registry.yarnpkg.com/binary-extensions/-/binary-extensions-1.13.1.tgz#598afe54755b2868a5330d2aff9d4ebb53209b65"
Expand Down