aboutsummaryrefslogtreecommitdiffstats
path: root/packages/utils
diff options
context:
space:
mode:
Diffstat (limited to 'packages/utils')
-rw-r--r--packages/utils/CHANGELOG.json27
-rw-r--r--packages/utils/CHANGELOG.md14
-rw-r--r--packages/utils/README.md12
-rw-r--r--packages/utils/package.json17
-rw-r--r--packages/utils/src/abi_decoder.ts12
-rw-r--r--packages/utils/src/configured_bignumber.ts23
-rw-r--r--packages/utils/src/sign_typed_data_utils.ts2
-rw-r--r--packages/utils/test/sign_typed_data_utils_test.ts23
-rw-r--r--packages/utils/tslint.json2
9 files changed, 109 insertions, 23 deletions
diff --git a/packages/utils/CHANGELOG.json b/packages/utils/CHANGELOG.json
index 237ebeecc..1ef16e112 100644
--- a/packages/utils/CHANGELOG.json
+++ b/packages/utils/CHANGELOG.json
@@ -1,5 +1,32 @@
[
{
+ "timestamp": 1542208198,
+ "version": "2.0.5",
+ "changes": [
+ {
+ "note": "Dependencies updated"
+ }
+ ]
+ },
+ {
+ "version": "2.0.4",
+ "changes": [
+ {
+ "note": "Dependencies updated"
+ }
+ ],
+ "timestamp": 1541740904
+ },
+ {
+ "timestamp": 1539871071,
+ "version": "2.0.3",
+ "changes": [
+ {
+ "note": "Dependencies updated"
+ }
+ ]
+ },
+ {
"timestamp": 1538693146,
"version": "2.0.2",
"changes": [
diff --git a/packages/utils/CHANGELOG.md b/packages/utils/CHANGELOG.md
index fa731ecf0..9846dd344 100644
--- a/packages/utils/CHANGELOG.md
+++ b/packages/utils/CHANGELOG.md
@@ -5,6 +5,18 @@ Edit the package's CHANGELOG.json file only.
CHANGELOG
+## v2.0.5 - _November 14, 2018_
+
+ * Dependencies updated
+
+## v2.0.4 - _November 9, 2018_
+
+ * Dependencies updated
+
+## v2.0.3 - _October 18, 2018_
+
+ * Dependencies updated
+
## v2.0.2 - _October 4, 2018_
* Dependencies updated
@@ -41,7 +53,7 @@ CHANGELOG
* Dependencies updated
-## v1.0.5 - _August 13, 2018_
+## v1.0.5 - _August 14, 2018_
* Increased BigNumber decimal precision from 20 to 78 (#807)
* Store different ABIs for events with same function signature and different amount of indexed arguments (#933)
diff --git a/packages/utils/README.md b/packages/utils/README.md
index c9a2f5846..0b15f00c5 100644
--- a/packages/utils/README.md
+++ b/packages/utils/README.md
@@ -1,25 +1,25 @@
-## @0xproject/utils
+## @0x/utils
Utils to be shared across 0x projects and packages
## Installation
```bash
-yarn add @0xproject/utils
+yarn add @0x/utils
```
If your project is in [TypeScript](https://www.typescriptlang.org/), add the following to your `tsconfig.json`:
```json
"compilerOptions": {
- "typeRoots": ["node_modules/@0xproject/typescript-typings/types", "node_modules/@types"],
+ "typeRoots": ["node_modules/@0x/typescript-typings/types", "node_modules/@types"],
}
```
## Usage
```javascript
-import { addressUtils, bigNumberConfigs, classUtils, intervalUtils, promisify } from '@0xproject/utils';
+import { addressUtils, bigNumberConfigs, classUtils, intervalUtils, promisify } from '@0x/utils';
```
## Troubleshooting
@@ -62,13 +62,13 @@ yarn install
To build this package and all other monorepo packages that it depends on, run the following from the monorepo root directory:
```bash
-PKG=@0xproject/utils yarn build
+PKG=@0x/utils yarn build
```
Or continuously rebuild on change:
```bash
-PKG=@0xproject/utils yarn watch
+PKG=@0x/utils yarn watch
```
### Clean
diff --git a/packages/utils/package.json b/packages/utils/package.json
index f1017f84d..4b924226f 100644
--- a/packages/utils/package.json
+++ b/packages/utils/package.json
@@ -1,6 +1,6 @@
{
- "name": "@0xproject/utils",
- "version": "2.0.2",
+ "name": "@0x/utils",
+ "version": "2.0.5",
"engines": {
"node": ">=6.12"
},
@@ -11,7 +11,7 @@
"build": "tsc -b",
"build:ci": "yarn build",
"clean": "shx rm -rf lib",
- "lint": "tslint --project .",
+ "lint": "tslint --format stylish --project .",
"test": "yarn run_mocha",
"test:circleci": "yarn test:coverage",
"run_mocha": "mocha --require source-map-support/register --require make-promises-safe lib/test/**/*_test.js --bail --exit",
@@ -28,12 +28,11 @@
},
"homepage": "https://github.com/0xProject/0x-monorepo/packages/utils/README.md",
"devDependencies": {
- "@0xproject/tslint-config": "^1.0.8",
+ "@0x/tslint-config": "^1.0.10",
"@types/detect-node": "2.0.0",
"@types/lodash": "4.14.104",
"@types/mocha": "^2.2.42",
"chai": "^4.0.1",
- "copyfiles": "^2.0.0",
"make-promises-safe": "^1.1.0",
"mocha": "^4.1.0",
"npm-run-all": "^4.1.2",
@@ -42,15 +41,15 @@
"typescript": "3.0.1"
},
"dependencies": {
- "@0xproject/types": "^1.1.4",
- "@0xproject/typescript-typings": "^3.0.2",
+ "@0x/types": "^1.2.1",
+ "@0x/typescript-typings": "^3.0.4",
"@types/node": "*",
"abortcontroller-polyfill": "^1.1.9",
"bignumber.js": "~4.1.0",
"detect-node": "2.0.3",
- "ethereum-types": "^1.0.11",
+ "ethereum-types": "^1.1.2",
"ethereumjs-util": "^5.1.1",
- "ethers": "4.0.0-beta.14",
+ "ethers": "~4.0.4",
"isomorphic-fetch": "^2.2.1",
"js-sha3": "^0.7.0",
"lodash": "^4.17.5"
diff --git a/packages/utils/src/abi_decoder.ts b/packages/utils/src/abi_decoder.ts
index ea8c91d10..2da46db35 100644
--- a/packages/utils/src/abi_decoder.ts
+++ b/packages/utils/src/abi_decoder.ts
@@ -41,7 +41,7 @@ export class AbiDecoder {
return log;
}
const event = this._methodIds[methodId][numIndexedArgs];
- const ethersInterface = new ethers.Interface([event]);
+ const ethersInterface = new ethers.utils.Interface([event]);
const decodedParams: DecodedLogArgs = {};
let topicsIndex = 1;
@@ -96,14 +96,16 @@ export class AbiDecoder {
if (_.isUndefined(abiArray)) {
return;
}
- const ethersInterface = new ethers.Interface(abiArray);
+ const ethersInterface = new ethers.utils.Interface(abiArray);
_.map(abiArray, (abi: AbiDefinition) => {
if (abi.type === AbiType.Event) {
- const topic = ethersInterface.events[abi.name].topic;
- const numIndexedArgs = _.reduce(abi.inputs, (sum, input) => (input.indexed ? sum + 1 : sum), 0);
+ // tslint:disable-next-line:no-unnecessary-type-assertion
+ const eventAbi = abi as EventAbi;
+ const topic = ethersInterface.events[eventAbi.name].topic;
+ const numIndexedArgs = _.reduce(eventAbi.inputs, (sum, input) => (input.indexed ? sum + 1 : sum), 0);
this._methodIds[topic] = {
...this._methodIds[topic],
- [numIndexedArgs]: abi,
+ [numIndexedArgs]: eventAbi,
};
}
});
diff --git a/packages/utils/src/configured_bignumber.ts b/packages/utils/src/configured_bignumber.ts
index 2b22b6938..34b57d303 100644
--- a/packages/utils/src/configured_bignumber.ts
+++ b/packages/utils/src/configured_bignumber.ts
@@ -11,4 +11,27 @@ BigNumber.config({
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 };
diff --git a/packages/utils/src/sign_typed_data_utils.ts b/packages/utils/src/sign_typed_data_utils.ts
index cd5bcb42f..6963b9084 100644
--- a/packages/utils/src/sign_typed_data_utils.ts
+++ b/packages/utils/src/sign_typed_data_utils.ts
@@ -2,7 +2,7 @@ import * as ethUtil from 'ethereumjs-util';
import * as ethers from 'ethers';
import * as _ from 'lodash';
-import { EIP712Object, EIP712ObjectValue, EIP712TypedData, EIP712Types } from '@0xproject/types';
+import { EIP712Object, EIP712ObjectValue, EIP712TypedData, EIP712Types } from '@0x/types';
export const signTypedDataUtils = {
/**
diff --git a/packages/utils/test/sign_typed_data_utils_test.ts b/packages/utils/test/sign_typed_data_utils_test.ts
index dcba08b04..3d2cb2496 100644
--- a/packages/utils/test/sign_typed_data_utils_test.ts
+++ b/packages/utils/test/sign_typed_data_utils_test.ts
@@ -136,5 +136,28 @@ describe('signTypedDataUtils', () => {
const hashHex = `0x${hash}`;
expect(hashHex).to.be.eq(orderSignTypedDataHashHex);
});
+ it('creates a hash of an uninitialized order', () => {
+ const uninitializedOrder = {
+ ...orderSignTypedData,
+ message: {
+ makerAddress: '0x0000000000000000000000000000000000000000',
+ takerAddress: '0x0000000000000000000000000000000000000000',
+ makerAssetAmount: 0,
+ takerAssetAmount: 0,
+ expirationTimeSeconds: 0,
+ makerFee: 0,
+ takerFee: 0,
+ feeRecipientAddress: '0x0000000000000000000000000000000000000000',
+ senderAddress: '0x0000000000000000000000000000000000000000',
+ salt: 0,
+ makerAssetData: '0x0000000000000000000000000000000000000000',
+ takerAssetData: '0x0000000000000000000000000000000000000000',
+ exchangeAddress: '0x0000000000000000000000000000000000000000',
+ },
+ };
+ const hash = signTypedDataUtils.generateTypedDataHash(uninitializedOrder).toString('hex');
+ const hashHex = `0x${hash}`;
+ expect(hashHex).to.be.eq('0xfaa49b35faeb9197e9c3ba7a52075e6dad19739549f153b77dfcf59408a4b422');
+ });
});
});
diff --git a/packages/utils/tslint.json b/packages/utils/tslint.json
index ffaefe83a..dd9053357 100644
--- a/packages/utils/tslint.json
+++ b/packages/utils/tslint.json
@@ -1,3 +1,3 @@
{
- "extends": ["@0xproject/tslint-config"]
+ "extends": ["@0x/tslint-config"]
}