aboutsummaryrefslogtreecommitdiffstats
path: root/packages/utils
diff options
context:
space:
mode:
authorBrandon Millman <brandon.millman@gmail.com>2018-03-30 01:02:46 +0800
committerBrandon Millman <brandon.millman@gmail.com>2018-03-30 01:02:46 +0800
commit665011174bab7cfc6ec53e0044d60e1463222aee (patch)
tree44bc55bd390044d6cbfe8e0f7dddb621a8be7249 /packages/utils
parentd106079d9b69191d9cdc6d9323dbae3e4b45daf2 (diff)
parentc4dd9658e791a9f821ea3b6eb4326bcba53b081a (diff)
downloaddexon-0x-contracts-665011174bab7cfc6ec53e0044d60e1463222aee.tar.gz
dexon-0x-contracts-665011174bab7cfc6ec53e0044d60e1463222aee.tar.zst
dexon-0x-contracts-665011174bab7cfc6ec53e0044d60e1463222aee.zip
Merge branch 'development' into feature/website/wallet-wrap
* development: (35 commits) Fix CHANGELOG Update Yarn.lock Standardize changelog dates and format Fix stubbing of a non-existent property Remove redundant cast Move common types out of web3 types Add monorepo_scripts to npmignore Add typeRoots Add clean-state tests Remove nested .gitignore files since `yarn publish` gets confused by them and ignores their contents on the top-level scope Remove WETH hack now that updated WETH address is in TokenRegistry Revert TokenRegistry address on Kovan Improve rounding error message Portal fill with mixed decimals Add error popover if TokenRegistry on network user is browsing on don't include the requisite default tokens for 0x Portal to function Set timeout for compiler tests Remove redundant types Add missing param comments Fix a comment Add a comment ...
Diffstat (limited to 'packages/utils')
-rw-r--r--packages/utils/.npmignore1
-rw-r--r--packages/utils/README.md8
-rw-r--r--packages/utils/package.json5
-rw-r--r--packages/utils/src/abi_decoder.ts27
-rw-r--r--packages/utils/tsconfig.json6
5 files changed, 26 insertions, 21 deletions
diff --git a/packages/utils/.npmignore b/packages/utils/.npmignore
index ad5ffcd56..24e65ad5b 100644
--- a/packages/utils/.npmignore
+++ b/packages/utils/.npmignore
@@ -3,3 +3,4 @@ yarn-error.log
/scripts/
/src/
tsconfig.json
+/lib/monorepo_scripts/
diff --git a/packages/utils/README.md b/packages/utils/README.md
index 22de85f4a..fde0780a9 100644
--- a/packages/utils/README.md
+++ b/packages/utils/README.md
@@ -10,10 +10,10 @@ yarn add @0xproject/utils
If your project is in [TypeScript](https://www.typescriptlang.org/), add the following to your `tsconfig.json`:
-```
-"include": [
- "./node_modules/web3-typescript-typings/index.d.ts",
-]
+```json
+"compilerOptions": {
+ "typeRoots": ["node_modules/@0xproject/typescript-typings/types", "node_modules/@types"],
+}
```
## Usage
diff --git a/packages/utils/package.json b/packages/utils/package.json
index ffdd7fe2e..bc869fe1e 100644
--- a/packages/utils/package.json
+++ b/packages/utils/package.json
@@ -31,14 +31,13 @@
},
"dependencies": {
"@0xproject/types": "^0.4.1",
+ "@0xproject/typescript-typings": "^0.0.1",
"@types/node": "^8.0.53",
"bignumber.js": "~4.1.0",
"ethers-contracts": "^2.2.1",
- "ethers-typescript-typings": "^0.0.4",
"js-sha3": "^0.7.0",
"lodash": "^4.17.4",
- "web3": "^0.20.0",
- "web3-typescript-typings": "^0.10.2"
+ "web3": "^0.20.0"
},
"publishConfig": {
"access": "public"
diff --git a/packages/utils/src/abi_decoder.ts b/packages/utils/src/abi_decoder.ts
index 2b496eb17..d49906cfb 100644
--- a/packages/utils/src/abi_decoder.ts
+++ b/packages/utils/src/abi_decoder.ts
@@ -1,13 +1,22 @@
-import { AbiType, DecodedLogArgs, LogWithDecodedArgs, RawLog, SolidityTypes } from '@0xproject/types';
+import {
+ AbiDefinition,
+ AbiType,
+ DecodedLogArgs,
+ EventAbi,
+ EventParameter,
+ LogEntry,
+ LogWithDecodedArgs,
+ RawLog,
+ SolidityTypes,
+} from '@0xproject/types';
import * as ethersContracts from 'ethers-contracts';
import * as _ from 'lodash';
-import * as Web3 from 'web3';
import { BigNumber } from './configured_bignumber';
export class AbiDecoder {
- private _savedABIs: Web3.AbiDefinition[] = [];
- private _methodIds: { [signatureHash: string]: Web3.EventAbi } = {};
+ private _savedABIs: AbiDefinition[] = [];
+ private _methodIds: { [signatureHash: string]: EventAbi } = {};
private static _padZeros(address: string) {
let formatted = address;
if (_.startsWith(formatted, '0x')) {
@@ -17,11 +26,11 @@ export class AbiDecoder {
formatted = _.padStart(formatted, 40, '0');
return `0x${formatted}`;
}
- constructor(abiArrays: Web3.AbiDefinition[][]) {
+ constructor(abiArrays: AbiDefinition[][]) {
_.forEach(abiArrays, this._addABI.bind(this));
}
// This method can only decode logs from the 0x & ERC20 smart contracts
- public tryToDecodeLogOrNoop<ArgsType>(log: Web3.LogEntry): LogWithDecodedArgs<ArgsType> | RawLog {
+ public tryToDecodeLogOrNoop<ArgsType>(log: LogEntry): LogWithDecodedArgs<ArgsType> | RawLog {
const methodId = log.topics[0];
const event = this._methodIds[methodId];
if (_.isUndefined(event)) {
@@ -37,7 +46,7 @@ export class AbiDecoder {
const decodedData = ethersInterface.events[event.name].parse(log.data);
let failedToDecode = false;
- _.forEach(event.inputs, (param: Web3.EventParameter, i: number) => {
+ _.forEach(event.inputs, (param: EventParameter, i: number) => {
// Indexed parameters are stored in topics. Non-indexed ones in decodedData
let value: BigNumber | string | number = param.indexed ? log.topics[topicsIndex++] : decodedData[i];
if (_.isUndefined(value)) {
@@ -64,12 +73,12 @@ export class AbiDecoder {
};
}
}
- private _addABI(abiArray: Web3.AbiDefinition[]): void {
+ private _addABI(abiArray: AbiDefinition[]): void {
if (_.isUndefined(abiArray)) {
return;
}
const ethersInterface = new ethersContracts.Interface(abiArray);
- _.map(abiArray, (abi: Web3.AbiDefinition) => {
+ _.map(abiArray, (abi: AbiDefinition) => {
if (abi.type === AbiType.Event) {
const topic = ethersInterface.events[abi.name].topic;
this._methodIds[topic] = abi;
diff --git a/packages/utils/tsconfig.json b/packages/utils/tsconfig.json
index 8114d99cd..c56d255d5 100644
--- a/packages/utils/tsconfig.json
+++ b/packages/utils/tsconfig.json
@@ -3,9 +3,5 @@
"compilerOptions": {
"outDir": "lib"
},
- "include": [
- "./src/**/*",
- "../../node_modules/web3-typescript-typings/index.d.ts",
- "../../node_modules/ethers-typescript-typings/index.d.ts"
- ]
+ "include": ["./src/**/*"]
}