aboutsummaryrefslogtreecommitdiffstats
path: root/packages/utils
diff options
context:
space:
mode:
authorBrandon Millman <brandon.millman@gmail.com>2018-10-05 07:06:05 +0800
committerBrandon Millman <brandon.millman@gmail.com>2018-10-05 07:06:05 +0800
commite5153737d8386380675f28dd7cda70deeb1ea37c (patch)
tree81b061d2fa1af5952acc5abb41003f043ff8fce1 /packages/utils
parent88766a02c7e6688e72d5c4c69ce68028b322f154 (diff)
parentb04b649ec044b05f5c37bec214b7f992feb5998e (diff)
downloaddexon-0x-contracts-e5153737d8386380675f28dd7cda70deeb1ea37c.tar
dexon-0x-contracts-e5153737d8386380675f28dd7cda70deeb1ea37c.tar.gz
dexon-0x-contracts-e5153737d8386380675f28dd7cda70deeb1ea37c.tar.bz2
dexon-0x-contracts-e5153737d8386380675f28dd7cda70deeb1ea37c.tar.lz
dexon-0x-contracts-e5153737d8386380675f28dd7cda70deeb1ea37c.tar.xz
dexon-0x-contracts-e5153737d8386380675f28dd7cda70deeb1ea37c.tar.zst
dexon-0x-contracts-e5153737d8386380675f28dd7cda70deeb1ea37c.zip
Merge branch 'development'
* development: (939 commits) Add asset-buyer to published packages section in README Publish Updated CHANGELOGS Update BuyQuote interface force re-build Add website build to instructions Revert format and re-add changes Build website in parallel with other tests since no other test relies on it being built to run Add back sourceMap support for both dev/prod Upgrade webpack Add missing default options Remove unused constants Add fee order with a takerFee Add additional order factory methods and refactor test to use them Add comments about buy quote calculation Update CHANGELOG Fix linter Add additional test for slippage Add buy_quote_calculator_test Add 0x Instant to bundle analysis ...
Diffstat (limited to 'packages/utils')
-rw-r--r--packages/utils/CHANGELOG.json87
-rw-r--r--packages/utils/CHANGELOG.md37
-rw-r--r--packages/utils/package.json31
-rw-r--r--packages/utils/src/abi_decoder.ts37
-rw-r--r--packages/utils/src/abi_utils.ts15
-rw-r--r--packages/utils/src/fetch_async.ts (renamed from packages/utils/src/fetchAsync.ts)0
-rw-r--r--packages/utils/src/index.ts2
-rw-r--r--packages/utils/src/monorepo_scripts/postpublish.ts8
-rw-r--r--packages/utils/tsconfig.json3
9 files changed, 181 insertions, 39 deletions
diff --git a/packages/utils/CHANGELOG.json b/packages/utils/CHANGELOG.json
index 3e3e1125b..237ebeecc 100644
--- a/packages/utils/CHANGELOG.json
+++ b/packages/utils/CHANGELOG.json
@@ -1,10 +1,97 @@
[
{
+ "timestamp": 1538693146,
+ "version": "2.0.2",
+ "changes": [
+ {
+ "note": "Dependencies updated"
+ }
+ ]
+ },
+ {
+ "timestamp": 1538475601,
+ "version": "2.0.1",
+ "changes": [
+ {
+ "note": "Dependencies updated"
+ }
+ ]
+ },
+ {
+ "version": "2.0.0",
+ "changes": [
+ {
+ "note": "Make abi_decoder compatible with ethers ^4.0.0",
+ "pr": 1069
+ }
+ ],
+ "timestamp": 1538157789
+ },
+ {
+ "timestamp": 1537907159,
+ "version": "1.0.11",
+ "changes": [
+ {
+ "note": "Dependencies updated"
+ }
+ ]
+ },
+ {
+ "timestamp": 1537875740,
+ "version": "1.0.10",
+ "changes": [
+ {
+ "note": "Dependencies updated"
+ }
+ ]
+ },
+ {
+ "timestamp": 1537541580,
+ "version": "1.0.9",
+ "changes": [
+ {
+ "note": "Dependencies updated"
+ }
+ ]
+ },
+ {
+ "timestamp": 1536142250,
+ "version": "1.0.8",
+ "changes": [
+ {
+ "note": "Dependencies updated"
+ }
+ ]
+ },
+ {
+ "timestamp": 1535377027,
+ "version": "1.0.7",
+ "changes": [
+ {
+ "note": "Dependencies updated"
+ }
+ ]
+ },
+ {
+ "timestamp": 1535133899,
+ "version": "1.0.6",
+ "changes": [
+ {
+ "note": "Dependencies updated"
+ }
+ ]
+ },
+ {
"version": "1.0.5",
"changes": [
{
"note": "Increased BigNumber decimal precision from 20 to 78",
"pr": 807
+ },
+ {
+ "note":
+ "Store different ABIs for events with same function signature and different amount of indexed arguments",
+ "pr": 933
}
],
"timestamp": 1534210131
diff --git a/packages/utils/CHANGELOG.md b/packages/utils/CHANGELOG.md
index bdde2687d..fa731ecf0 100644
--- a/packages/utils/CHANGELOG.md
+++ b/packages/utils/CHANGELOG.md
@@ -5,9 +5,46 @@ Edit the package's CHANGELOG.json file only.
CHANGELOG
+## v2.0.2 - _October 4, 2018_
+
+ * Dependencies updated
+
+## v2.0.1 - _October 2, 2018_
+
+ * Dependencies updated
+
+## v2.0.0 - _September 28, 2018_
+
+ * Make abi_decoder compatible with ethers ^4.0.0 (#1069)
+
+## v1.0.11 - _September 25, 2018_
+
+ * Dependencies updated
+
+## v1.0.10 - _September 25, 2018_
+
+ * Dependencies updated
+
+## v1.0.9 - _September 21, 2018_
+
+ * Dependencies updated
+
+## v1.0.8 - _September 5, 2018_
+
+ * Dependencies updated
+
+## v1.0.7 - _August 27, 2018_
+
+ * Dependencies updated
+
+## v1.0.6 - _August 24, 2018_
+
+ * Dependencies updated
+
## v1.0.5 - _August 13, 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)
## v1.0.4 - _July 26, 2018_
diff --git a/packages/utils/package.json b/packages/utils/package.json
index 0fd925715..f1017f84d 100644
--- a/packages/utils/package.json
+++ b/packages/utils/package.json
@@ -1,6 +1,6 @@
{
"name": "@0xproject/utils",
- "version": "1.0.5",
+ "version": "2.0.2",
"engines": {
"node": ">=6.12"
},
@@ -8,16 +8,15 @@
"main": "lib/src/index.js",
"types": "lib/src/index.d.ts",
"scripts": {
- "watch_without_deps": "tsc -w",
- "build": "tsc && copyfiles -u 2 './lib/monorepo_scripts/**/*' ./scripts",
- "clean": "shx rm -rf lib scripts",
+ "build": "tsc -b",
+ "build:ci": "yarn build",
+ "clean": "shx rm -rf lib",
+ "lint": "tslint --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",
"test:coverage": "nyc npm run test --all && yarn coverage:report:lcov",
- "coverage:report:lcov": "nyc report --reporter=text-lcov > coverage/lcov.info",
- "lint": "tslint --project .",
- "manual:postpublish": "yarn build; node ./scripts/postpublish.js"
+ "coverage:report:lcov": "nyc report --reporter=text-lcov > coverage/lcov.info"
},
"license": "Apache-2.0",
"repository": {
@@ -29,29 +28,29 @@
},
"homepage": "https://github.com/0xProject/0x-monorepo/packages/utils/README.md",
"devDependencies": {
- "@0xproject/monorepo-scripts": "^1.0.5",
- "@0xproject/tslint-config": "^1.0.5",
+ "@0xproject/tslint-config": "^1.0.8",
+ "@types/detect-node": "2.0.0",
"@types/lodash": "4.14.104",
"@types/mocha": "^2.2.42",
"chai": "^4.0.1",
- "copyfiles": "^1.2.0",
+ "copyfiles": "^2.0.0",
"make-promises-safe": "^1.1.0",
"mocha": "^4.1.0",
"npm-run-all": "^4.1.2",
"shx": "^0.2.2",
"tslint": "5.11.0",
- "typescript": "2.9.2"
+ "typescript": "3.0.1"
},
"dependencies": {
- "@0xproject/types": "^1.0.1-rc.4",
- "@0xproject/typescript-typings": "^1.0.4",
- "@types/node": "^8.0.53",
+ "@0xproject/types": "^1.1.4",
+ "@0xproject/typescript-typings": "^3.0.2",
+ "@types/node": "*",
"abortcontroller-polyfill": "^1.1.9",
"bignumber.js": "~4.1.0",
"detect-node": "2.0.3",
- "ethereum-types": "^1.0.4",
+ "ethereum-types": "^1.0.11",
"ethereumjs-util": "^5.1.1",
- "ethers": "3.0.22",
+ "ethers": "4.0.0-beta.14",
"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 7f93e746e..ea8c91d10 100644
--- a/packages/utils/src/abi_decoder.ts
+++ b/packages/utils/src/abi_decoder.ts
@@ -15,25 +15,39 @@ import * as _ from 'lodash';
import { addressUtils } from './address_utils';
import { BigNumber } from './configured_bignumber';
+/**
+ * AbiDecoder allows you to decode event logs given a set of supplied contract ABI's. It takes the contract's event
+ * signature from the ABI and attempts to decode the logs using it.
+ */
export class AbiDecoder {
- private readonly _methodIds: { [signatureHash: string]: EventAbi } = {};
+ private readonly _methodIds: { [signatureHash: string]: { [numIndexedArgs: number]: EventAbi } } = {};
+ /**
+ * Instantiate an AbiDecoder
+ * @param abiArrays An array of contract ABI's
+ * @return AbiDecoder instance
+ */
constructor(abiArrays: AbiDefinition[][]) {
_.forEach(abiArrays, this.addABI.bind(this));
}
- // This method can only decode logs from the 0x & ERC20 smart contracts
+ /**
+ * Attempt to decode a log given the ABI's the AbiDecoder knows about.
+ * @param log The log to attempt to decode
+ * @return The decoded log if the requisite ABI was available. Otherwise the log unaltered.
+ */
public tryToDecodeLogOrNoop<ArgsType extends DecodedLogArgs>(log: LogEntry): LogWithDecodedArgs<ArgsType> | RawLog {
const methodId = log.topics[0];
- const event = this._methodIds[methodId];
- if (_.isUndefined(event)) {
+ const numIndexedArgs = log.topics.length - 1;
+ if (_.isUndefined(this._methodIds[methodId]) || _.isUndefined(this._methodIds[methodId][numIndexedArgs])) {
return log;
}
+ const event = this._methodIds[methodId][numIndexedArgs];
const ethersInterface = new ethers.Interface([event]);
const decodedParams: DecodedLogArgs = {};
let topicsIndex = 1;
let decodedData: any[];
try {
- decodedData = ethersInterface.events[event.name].parse(log.data);
+ decodedData = ethersInterface.events[event.name].decode(log.data);
} catch (error) {
if (error.code === ethers.errors.INVALID_ARGUMENT) {
// Because we index events by Method ID, and Method IDs are derived from the method
@@ -45,7 +59,6 @@ export class AbiDecoder {
}
throw error;
}
-
let didFailToDecode = false;
_.forEach(event.inputs, (param: EventParameter, i: number) => {
// Indexed parameters are stored in topics. Non-indexed ones in decodedData
@@ -75,6 +88,10 @@ export class AbiDecoder {
};
}
}
+ /**
+ * Add additional ABI definitions to the AbiDecoder
+ * @param abiArray An array of ABI definitions to add to the AbiDecoder
+ */
public addABI(abiArray: AbiDefinition[]): void {
if (_.isUndefined(abiArray)) {
return;
@@ -82,8 +99,12 @@ export class AbiDecoder {
const ethersInterface = new ethers.Interface(abiArray);
_.map(abiArray, (abi: AbiDefinition) => {
if (abi.type === AbiType.Event) {
- const topic = ethersInterface.events[abi.name].topics[0];
- this._methodIds[topic] = abi;
+ const topic = ethersInterface.events[abi.name].topic;
+ const numIndexedArgs = _.reduce(abi.inputs, (sum, input) => (input.indexed ? sum + 1 : sum), 0);
+ this._methodIds[topic] = {
+ ...this._methodIds[topic],
+ [numIndexedArgs]: abi,
+ };
}
});
}
diff --git a/packages/utils/src/abi_utils.ts b/packages/utils/src/abi_utils.ts
index c9b70966c..598ea5fcc 100644
--- a/packages/utils/src/abi_utils.ts
+++ b/packages/utils/src/abi_utils.ts
@@ -1,14 +1,19 @@
import { AbiDefinition, AbiType, ContractAbi, DataItem, MethodAbi } from 'ethereum-types';
-import * as ethers from 'ethers';
import * as _ from 'lodash';
import { BigNumber } from './configured_bignumber';
+type ParamName = null | string | NestedParamName;
+interface NestedParamName {
+ name: string | null;
+ names: ParamName[];
+}
+
// Note(albrow): This function is unexported in ethers.js. Copying it here for
// now.
// Source: https://github.com/ethers-io/ethers.js/blob/884593ab76004a808bf8097e9753fb5f8dcc3067/contracts/interface.js#L30
-function parseEthersParams(params: DataItem[]): { names: ethers.ParamName[]; types: string[] } {
- const names: ethers.ParamName[] = [];
+function parseEthersParams(params: DataItem[]): { names: ParamName[]; types: string[] } {
+ const names: ParamName[] = [];
const types: string[] = [];
params.forEach((param: DataItem) => {
@@ -37,7 +42,7 @@ function parseEthersParams(params: DataItem[]): { names: ethers.ParamName[]; typ
// returns true if x is equal to y and false otherwise. Performs some minimal
// type conversion and data massaging for x and y, depending on type. name and
// type should typically be derived from parseEthersParams.
-function isAbiDataEqual(name: ethers.ParamName, type: string, x: any, y: any): boolean {
+function isAbiDataEqual(name: ParamName, type: string, x: any, y: any): boolean {
if (_.isUndefined(x) && _.isUndefined(y)) {
return true;
} else if (_.isUndefined(x) && !_.isUndefined(y)) {
@@ -89,7 +94,7 @@ function isAbiDataEqual(name: ethers.ParamName, type: string, x: any, y: any): b
//
const nestedName = _.isString(name.names[i])
? (name.names[i] as string)
- : ((name.names[i] as ethers.NestedParamName).name as string);
+ : ((name.names[i] as NestedParamName).name as string);
if (!isAbiDataEqual(name.names[i], types[i], x[nestedName], y[nestedName])) {
return false;
}
diff --git a/packages/utils/src/fetchAsync.ts b/packages/utils/src/fetch_async.ts
index b4c85718d..b4c85718d 100644
--- a/packages/utils/src/fetchAsync.ts
+++ b/packages/utils/src/fetch_async.ts
diff --git a/packages/utils/src/index.ts b/packages/utils/src/index.ts
index b8e0b1775..9d01e5bc5 100644
--- a/packages/utils/src/index.ts
+++ b/packages/utils/src/index.ts
@@ -8,4 +8,4 @@ export { logUtils } from './log_utils';
export { abiUtils } from './abi_utils';
export { NULL_BYTES } from './constants';
export { errorUtils } from './error_utils';
-export { fetchAsync } from './fetchAsync';
+export { fetchAsync } from './fetch_async';
diff --git a/packages/utils/src/monorepo_scripts/postpublish.ts b/packages/utils/src/monorepo_scripts/postpublish.ts
deleted file mode 100644
index dcb99d0f7..000000000
--- a/packages/utils/src/monorepo_scripts/postpublish.ts
+++ /dev/null
@@ -1,8 +0,0 @@
-import { postpublishUtils } from '@0xproject/monorepo-scripts';
-
-import * as packageJSON from '../package.json';
-import * as tsConfigJSON from '../tsconfig.json';
-
-const cwd = `${__dirname}/..`;
-// tslint:disable-next-line:no-floating-promises
-postpublishUtils.runAsync(packageJSON, tsConfigJSON, cwd);
diff --git a/packages/utils/tsconfig.json b/packages/utils/tsconfig.json
index 8b4cd47a2..718e623c7 100644
--- a/packages/utils/tsconfig.json
+++ b/packages/utils/tsconfig.json
@@ -1,7 +1,8 @@
{
"extends": "../../tsconfig",
"compilerOptions": {
- "outDir": "lib"
+ "outDir": "lib",
+ "rootDir": "."
},
"include": ["src/**/*", "test/**/*"]
}