From f4a2e227e1a7224fbbe9c99d9aa033d176a9c4de Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Sun, 29 Jul 2018 21:58:39 +0200 Subject: Remove all in-package monorepo-scripts by adding doc gen/upload and aggregate release note publishing to publish script --- packages/utils/src/monorepo_scripts/postpublish.ts | 8 -------- 1 file changed, 8 deletions(-) delete mode 100644 packages/utils/src/monorepo_scripts/postpublish.ts (limited to 'packages/utils/src') 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); -- cgit v1.2.3 From c00c477307e305e2d380779bb74fa29b31072c4c Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Tue, 21 Aug 2018 17:39:35 +0100 Subject: Add doc comments to AbiDecoder --- packages/utils/src/abi_decoder.ts | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) (limited to 'packages/utils/src') diff --git a/packages/utils/src/abi_decoder.ts b/packages/utils/src/abi_decoder.ts index 7f93e746e..58a58dea2 100644 --- a/packages/utils/src/abi_decoder.ts +++ b/packages/utils/src/abi_decoder.ts @@ -15,12 +15,25 @@ 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 } = {}; + /** + * 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(log: LogEntry): LogWithDecodedArgs | RawLog { const methodId = log.topics[0]; const event = this._methodIds[methodId]; @@ -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; -- cgit v1.2.3 From 5b6c91bb3f0b5a1d0586b7e772ad96f3eab1f911 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Thu, 13 Sep 2018 14:04:13 +0200 Subject: Fixes for the breaking changes in ethers --- packages/utils/src/abi_decoder.ts | 4 ++-- packages/utils/src/abi_utils.ts | 14 ++++++++++---- 2 files changed, 12 insertions(+), 6 deletions(-) (limited to 'packages/utils/src') diff --git a/packages/utils/src/abi_decoder.ts b/packages/utils/src/abi_decoder.ts index 265eb105e..ea8c91d10 100644 --- a/packages/utils/src/abi_decoder.ts +++ b/packages/utils/src/abi_decoder.ts @@ -47,7 +47,7 @@ export class AbiDecoder { 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 @@ -99,7 +99,7 @@ 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]; + 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], diff --git a/packages/utils/src/abi_utils.ts b/packages/utils/src/abi_utils.ts index c9b70966c..b5ab28ba2 100644 --- a/packages/utils/src/abi_utils.ts +++ b/packages/utils/src/abi_utils.ts @@ -4,11 +4,17 @@ 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 +43,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 +95,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; } -- cgit v1.2.3 From 3167bfde1a426e567de1b2f9809062217bb19b6b Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Fri, 21 Sep 2018 11:47:30 +0200 Subject: Remove unused import --- packages/utils/src/abi_utils.ts | 1 - 1 file changed, 1 deletion(-) (limited to 'packages/utils/src') diff --git a/packages/utils/src/abi_utils.ts b/packages/utils/src/abi_utils.ts index b5ab28ba2..598ea5fcc 100644 --- a/packages/utils/src/abi_utils.ts +++ b/packages/utils/src/abi_utils.ts @@ -1,5 +1,4 @@ import { AbiDefinition, AbiType, ContractAbi, DataItem, MethodAbi } from 'ethereum-types'; -import * as ethers from 'ethers'; import * as _ from 'lodash'; import { BigNumber } from './configured_bignumber'; -- cgit v1.2.3 From 2a82ff48c061eacb3b6f9fb36eeae7f515b6d11d Mon Sep 17 00:00:00 2001 From: Jacob Evans Date: Thu, 4 Oct 2018 17:12:35 +1000 Subject: Move SignTypedData to utils package --- packages/utils/src/index.ts | 1 + packages/utils/src/sign_typed_data_utils.ts | 81 +++++++++++++++++++++++++++++ 2 files changed, 82 insertions(+) create mode 100644 packages/utils/src/sign_typed_data_utils.ts (limited to 'packages/utils/src') diff --git a/packages/utils/src/index.ts b/packages/utils/src/index.ts index 9d01e5bc5..0723e5788 100644 --- a/packages/utils/src/index.ts +++ b/packages/utils/src/index.ts @@ -9,3 +9,4 @@ export { abiUtils } from './abi_utils'; export { NULL_BYTES } from './constants'; export { errorUtils } from './error_utils'; export { fetchAsync } from './fetch_async'; +export { signTypedDataUtils } from './sign_typed_data_utils'; diff --git a/packages/utils/src/sign_typed_data_utils.ts b/packages/utils/src/sign_typed_data_utils.ts new file mode 100644 index 000000000..902d8530c --- /dev/null +++ b/packages/utils/src/sign_typed_data_utils.ts @@ -0,0 +1,81 @@ +import * as ethUtil from 'ethereumjs-util'; +import * as ethers from 'ethers'; + +export interface EIP712Parameter { + name: string; + type: string; +} + +export interface EIP712Types { + [key: string]: EIP712Parameter[]; +} +export interface EIP712TypedData { + types: EIP712Types; + domain: any; + message: any; + primaryType: string; +} + +export const signTypedDataUtils = { + findDependencies(primaryType: string, types: EIP712Types, found: string[] = []): string[] { + if (found.includes(primaryType) || types[primaryType] === undefined) { + return found; + } + found.push(primaryType); + for (const field of types[primaryType]) { + for (const dep of signTypedDataUtils.findDependencies(field.type, types, found)) { + if (!found.includes(dep)) { + found.push(dep); + } + } + } + return found; + }, + encodeType(primaryType: string, types: EIP712Types): string { + let deps = signTypedDataUtils.findDependencies(primaryType, types); + deps = deps.filter(d => d !== primaryType); + deps = [primaryType].concat(deps.sort()); + let result = ''; + for (const dep of deps) { + result += `${dep}(${types[dep].map(({ name, type }) => `${type} ${name}`).join(',')})`; + } + return result; + }, + encodeData(primaryType: string, data: any, types: EIP712Types): string { + const encodedTypes = ['bytes32']; + const encodedValues = [signTypedDataUtils.typeHash(primaryType, types)]; + for (const field of types[primaryType]) { + let value = data[field.name]; + if (field.type === 'string' || field.type === 'bytes') { + value = ethUtil.sha3(value); + encodedTypes.push('bytes32'); + encodedValues.push(value); + } else if (types[field.type] !== undefined) { + encodedTypes.push('bytes32'); + value = ethUtil.sha3(signTypedDataUtils.encodeData(field.type, value, types)); + encodedValues.push(value); + } else if (field.type.lastIndexOf(']') === field.type.length - 1) { + throw new Error('Arrays currently unimplemented in encodeData'); + } else { + encodedTypes.push(field.type); + encodedValues.push(value); + } + } + return ethers.utils.defaultAbiCoder.encode(encodedTypes, encodedValues); + }, + typeHash(primaryType: string, types: EIP712Types): Buffer { + return ethUtil.sha3(signTypedDataUtils.encodeType(primaryType, types)); + }, + structHash(primaryType: string, data: any, types: EIP712Types): Buffer { + return ethUtil.sha3(signTypedDataUtils.encodeData(primaryType, data, types)); + }, + signTypedDataHash(typedData: EIP712TypedData): Buffer { + return ethUtil.sha3( + Buffer.concat([ + Buffer.from('1901', 'hex'), + signTypedDataUtils.structHash('EIP712Domain', typedData.domain, typedData.types), + signTypedDataUtils.structHash(typedData.primaryType, typedData.message, typedData.types), + ]), + ); + }, +}; -- cgit v1.2.3 From 3e2fe40a11919f09f1f454c71f02aaa147b46b0c Mon Sep 17 00:00:00 2001 From: Jacob Evans Date: Thu, 4 Oct 2018 17:32:54 +1000 Subject: Add eth_signTypedData support to our wallet subproviders --- packages/utils/src/sign_typed_data_utils.ts | 60 +++++++++++++---------------- 1 file changed, 26 insertions(+), 34 deletions(-) (limited to 'packages/utils/src') diff --git a/packages/utils/src/sign_typed_data_utils.ts b/packages/utils/src/sign_typed_data_utils.ts index 902d8530c..b72fd099b 100644 --- a/packages/utils/src/sign_typed_data_utils.ts +++ b/packages/utils/src/sign_typed_data_utils.ts @@ -1,29 +1,30 @@ import * as ethUtil from 'ethereumjs-util'; import * as ethers from 'ethers'; -export interface EIP712Parameter { - name: string; - type: string; -} - -export interface EIP712Types { - [key: string]: EIP712Parameter[]; -} -export interface EIP712TypedData { - types: EIP712Types; - domain: any; - message: any; - primaryType: string; -} +import { EIP712TypedData, EIP712Types } from '@0xproject/types'; export const signTypedDataUtils = { - findDependencies(primaryType: string, types: EIP712Types, found: string[] = []): string[] { + /** + * Computes the Sign Typed Data hash + * @param typedData An object that conforms to the EIP712TypedData interface + * @return A Buffer containing the hash of the sign typed data. + */ + signTypedDataHash(typedData: EIP712TypedData): Buffer { + return ethUtil.sha3( + Buffer.concat([ + Buffer.from('1901', 'hex'), + signTypedDataUtils._structHash('EIP712Domain', typedData.domain, typedData.types), + signTypedDataUtils._structHash(typedData.primaryType, typedData.message, typedData.types), + ]), + ); + }, + _findDependencies(primaryType: string, types: EIP712Types, found: string[] = []): string[] { if (found.includes(primaryType) || types[primaryType] === undefined) { return found; } found.push(primaryType); for (const field of types[primaryType]) { - for (const dep of signTypedDataUtils.findDependencies(field.type, types, found)) { + for (const dep of signTypedDataUtils._findDependencies(field.type, types, found)) { if (!found.includes(dep)) { found.push(dep); } @@ -31,8 +32,8 @@ export const signTypedDataUtils = { } return found; }, - encodeType(primaryType: string, types: EIP712Types): string { - let deps = signTypedDataUtils.findDependencies(primaryType, types); + _encodeType(primaryType: string, types: EIP712Types): string { + let deps = signTypedDataUtils._findDependencies(primaryType, types); deps = deps.filter(d => d !== primaryType); deps = [primaryType].concat(deps.sort()); let result = ''; @@ -41,9 +42,9 @@ export const signTypedDataUtils = { } return result; }, - encodeData(primaryType: string, data: any, types: EIP712Types): string { + _encodeData(primaryType: string, data: any, types: EIP712Types): string { const encodedTypes = ['bytes32']; - const encodedValues = [signTypedDataUtils.typeHash(primaryType, types)]; + const encodedValues = [signTypedDataUtils._typeHash(primaryType, types)]; for (const field of types[primaryType]) { let value = data[field.name]; if (field.type === 'string' || field.type === 'bytes') { @@ -52,7 +53,7 @@ export const signTypedDataUtils = { encodedValues.push(value); } else if (types[field.type] !== undefined) { encodedTypes.push('bytes32'); - value = ethUtil.sha3(signTypedDataUtils.encodeData(field.type, value, types)); + value = ethUtil.sha3(signTypedDataUtils._encodeData(field.type, value, types)); encodedValues.push(value); } else if (field.type.lastIndexOf(']') === field.type.length - 1) { throw new Error('Arrays currently unimplemented in encodeData'); @@ -63,19 +64,10 @@ export const signTypedDataUtils = { } return ethers.utils.defaultAbiCoder.encode(encodedTypes, encodedValues); }, - typeHash(primaryType: string, types: EIP712Types): Buffer { - return ethUtil.sha3(signTypedDataUtils.encodeType(primaryType, types)); + _typeHash(primaryType: string, types: EIP712Types): Buffer { + return ethUtil.sha3(signTypedDataUtils._encodeType(primaryType, types)); }, - structHash(primaryType: string, data: any, types: EIP712Types): Buffer { - return ethUtil.sha3(signTypedDataUtils.encodeData(primaryType, data, types)); - }, - signTypedDataHash(typedData: EIP712TypedData): Buffer { - return ethUtil.sha3( - Buffer.concat([ - Buffer.from('1901', 'hex'), - signTypedDataUtils.structHash('EIP712Domain', typedData.domain, typedData.types), - signTypedDataUtils.structHash(typedData.primaryType, typedData.message, typedData.types), - ]), - ); + _structHash(primaryType: string, data: any, types: EIP712Types): Buffer { + return ethUtil.sha3(signTypedDataUtils._encodeData(primaryType, data, types)); }, }; -- cgit v1.2.3 From 75d274f330dc0c18577e764ca77ffb36d5a3f27e Mon Sep 17 00:00:00 2001 From: Jacob Evans Date: Fri, 5 Oct 2018 11:45:53 +1000 Subject: Return SignedOrder from signing utils. Create a helper back in EIP712Utils for code cleanup. Moved constants in order-utils into the constants object --- packages/utils/src/sign_typed_data_utils.ts | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) (limited to 'packages/utils/src') diff --git a/packages/utils/src/sign_typed_data_utils.ts b/packages/utils/src/sign_typed_data_utils.ts index b72fd099b..657a59ed0 100644 --- a/packages/utils/src/sign_typed_data_utils.ts +++ b/packages/utils/src/sign_typed_data_utils.ts @@ -1,7 +1,8 @@ import * as ethUtil from 'ethereumjs-util'; import * as ethers from 'ethers'; +import * as _ from 'lodash'; -import { EIP712TypedData, EIP712Types } from '@0xproject/types'; +import { EIP712Object, EIP712ObjectValue, EIP712TypedData, EIP712Types } from '@0xproject/types'; export const signTypedDataUtils = { /** @@ -42,32 +43,40 @@ export const signTypedDataUtils = { } return result; }, - _encodeData(primaryType: string, data: any, types: EIP712Types): string { + _encodeData(primaryType: string, data: EIP712Object, types: EIP712Types): string { const encodedTypes = ['bytes32']; - const encodedValues = [signTypedDataUtils._typeHash(primaryType, types)]; + const encodedValues: Array = [signTypedDataUtils._typeHash(primaryType, types)]; for (const field of types[primaryType]) { - let value = data[field.name]; + const value = data[field.name]; if (field.type === 'string' || field.type === 'bytes') { - value = ethUtil.sha3(value); + const hashValue = ethUtil.sha3(value as string); encodedTypes.push('bytes32'); - encodedValues.push(value); + encodedValues.push(hashValue); } else if (types[field.type] !== undefined) { encodedTypes.push('bytes32'); - value = ethUtil.sha3(signTypedDataUtils._encodeData(field.type, value, types)); - encodedValues.push(value); + const hashValue = ethUtil.sha3( + // tslint:disable-next-line:no-unnecessary-type-assertion + signTypedDataUtils._encodeData(field.type, value as EIP712Object, types), + ); + encodedValues.push(hashValue); } else if (field.type.lastIndexOf(']') === field.type.length - 1) { throw new Error('Arrays currently unimplemented in encodeData'); } else { encodedTypes.push(field.type); - encodedValues.push(value); + const normalizedValue = signTypedDataUtils._normalizeValue(field.type, value); + encodedValues.push(normalizedValue); } } return ethers.utils.defaultAbiCoder.encode(encodedTypes, encodedValues); }, + _normalizeValue(type: string, value: any): EIP712ObjectValue { + const normalizedValue = type === 'uint256' && _.isObject(value) && value.isBigNumber ? value.toString() : value; + return normalizedValue; + }, _typeHash(primaryType: string, types: EIP712Types): Buffer { return ethUtil.sha3(signTypedDataUtils._encodeType(primaryType, types)); }, - _structHash(primaryType: string, data: any, types: EIP712Types): Buffer { + _structHash(primaryType: string, data: EIP712Object, types: EIP712Types): Buffer { return ethUtil.sha3(signTypedDataUtils._encodeData(primaryType, data, types)); }, }; -- cgit v1.2.3 From 9e8031d5e3cf94cabe07685be510397367e90413 Mon Sep 17 00:00:00 2001 From: Jacob Evans Date: Tue, 9 Oct 2018 18:26:13 +1100 Subject: Throw and handle errors from Providers. In web3 wrapper when a response contains an error field we throw this rather than return response.result which is often undefined. In Signature Utils we handle the error thrown when a user rejects the signing dialogue to prevent double signing. Exposed the ZeroExTransaction JSON schema. In Website only use the MetamaskSubprovider if we can detect the provider is Metamask --- packages/utils/src/sign_typed_data_utils.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'packages/utils/src') diff --git a/packages/utils/src/sign_typed_data_utils.ts b/packages/utils/src/sign_typed_data_utils.ts index 657a59ed0..cd5bcb42f 100644 --- a/packages/utils/src/sign_typed_data_utils.ts +++ b/packages/utils/src/sign_typed_data_utils.ts @@ -6,11 +6,11 @@ import { EIP712Object, EIP712ObjectValue, EIP712TypedData, EIP712Types } from '@ export const signTypedDataUtils = { /** - * Computes the Sign Typed Data hash + * Generates the EIP712 Typed Data hash for signing * @param typedData An object that conforms to the EIP712TypedData interface - * @return A Buffer containing the hash of the sign typed data. + * @return A Buffer containing the hash of the typed data. */ - signTypedDataHash(typedData: EIP712TypedData): Buffer { + generateTypedDataHash(typedData: EIP712TypedData): Buffer { return ethUtil.sha3( Buffer.concat([ Buffer.from('1901', 'hex'), -- cgit v1.2.3 From 22160df2d2d5aef63c3e2c3f502ac15119b18e07 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Tue, 9 Oct 2018 12:55:10 +0200 Subject: Fix ethers build issue --- packages/utils/src/abi_decoder.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'packages/utils/src') diff --git a/packages/utils/src/abi_decoder.ts b/packages/utils/src/abi_decoder.ts index ea8c91d10..836037f30 100644 --- a/packages/utils/src/abi_decoder.ts +++ b/packages/utils/src/abi_decoder.ts @@ -9,7 +9,8 @@ import { RawLog, SolidityTypes, } from 'ethereum-types'; -import * as ethers from 'ethers'; +import { ethers } from 'ethers'; +import { Interface } from 'ethers/utils/interface'; import * as _ from 'lodash'; import { addressUtils } from './address_utils'; @@ -41,7 +42,7 @@ export class AbiDecoder { return log; } const event = this._methodIds[methodId][numIndexedArgs]; - const ethersInterface = new ethers.Interface([event]); + const ethersInterface = new Interface([event]); const decodedParams: DecodedLogArgs = {}; let topicsIndex = 1; @@ -96,7 +97,7 @@ export class AbiDecoder { if (_.isUndefined(abiArray)) { return; } - const ethersInterface = new ethers.Interface(abiArray); + const ethersInterface = new Interface(abiArray); _.map(abiArray, (abi: AbiDefinition) => { if (abi.type === AbiType.Event) { const topic = ethersInterface.events[abi.name].topic; -- cgit v1.2.3 From f93774f855d5735aff975cdb87c61aad624b4c9a Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Tue, 9 Oct 2018 15:46:13 +0200 Subject: Stop accesing ethers private methods --- packages/utils/src/abi_decoder.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'packages/utils/src') diff --git a/packages/utils/src/abi_decoder.ts b/packages/utils/src/abi_decoder.ts index 836037f30..ac3e54efb 100644 --- a/packages/utils/src/abi_decoder.ts +++ b/packages/utils/src/abi_decoder.ts @@ -10,7 +10,6 @@ import { SolidityTypes, } from 'ethereum-types'; import { ethers } from 'ethers'; -import { Interface } from 'ethers/utils/interface'; import * as _ from 'lodash'; import { addressUtils } from './address_utils'; @@ -42,7 +41,7 @@ export class AbiDecoder { return log; } const event = this._methodIds[methodId][numIndexedArgs]; - const ethersInterface = new Interface([event]); + const ethersInterface = new ethers.utils.Interface([event]); const decodedParams: DecodedLogArgs = {}; let topicsIndex = 1; @@ -97,7 +96,7 @@ export class AbiDecoder { if (_.isUndefined(abiArray)) { return; } - const ethersInterface = new 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; -- cgit v1.2.3 From 852f50d1a0e2d7f6c95231406c8604f9e56dc1dc Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Wed, 17 Oct 2018 17:09:35 +0100 Subject: chore: Re-cast to EventAbi after checking the the type is set to 'event' --- packages/utils/src/abi_decoder.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'packages/utils/src') diff --git a/packages/utils/src/abi_decoder.ts b/packages/utils/src/abi_decoder.ts index ac3e54efb..9cc863909 100644 --- a/packages/utils/src/abi_decoder.ts +++ b/packages/utils/src/abi_decoder.ts @@ -99,11 +99,12 @@ export class AbiDecoder { 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); + 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, }; } }); -- cgit v1.2.3 From bdae4ba2a2c9b7b3b41c352c628cb11cd4a1f295 Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Wed, 17 Oct 2018 18:23:06 +0100 Subject: chore: tslint fix --- packages/utils/src/abi_decoder.ts | 1 + 1 file changed, 1 insertion(+) (limited to 'packages/utils/src') diff --git a/packages/utils/src/abi_decoder.ts b/packages/utils/src/abi_decoder.ts index 9cc863909..c0b2c7950 100644 --- a/packages/utils/src/abi_decoder.ts +++ b/packages/utils/src/abi_decoder.ts @@ -99,6 +99,7 @@ export class AbiDecoder { const ethersInterface = new ethers.utils.Interface(abiArray); _.map(abiArray, (abi: AbiDefinition) => { if (abi.type === AbiType.Event) { + // 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); -- cgit v1.2.3 From 9f924e459c43c023e35ab7222cd9824cc0e67411 Mon Sep 17 00:00:00 2001 From: Jacob Evans Date: Thu, 18 Oct 2018 21:51:56 +1100 Subject: chore: change package org from 0xproject to 0x --- packages/utils/src/sign_typed_data_utils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'packages/utils/src') 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 = { /** -- cgit v1.2.3 From aa4a474e1dc79ec4da299663b20e56f6cf01518a Mon Sep 17 00:00:00 2001 From: Jacob Evans Date: Thu, 18 Oct 2018 23:11:56 +1100 Subject: chore: update ethers import in utils --- packages/utils/src/abi_decoder.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'packages/utils/src') diff --git a/packages/utils/src/abi_decoder.ts b/packages/utils/src/abi_decoder.ts index c0b2c7950..2da46db35 100644 --- a/packages/utils/src/abi_decoder.ts +++ b/packages/utils/src/abi_decoder.ts @@ -9,7 +9,7 @@ import { RawLog, SolidityTypes, } from 'ethereum-types'; -import { ethers } from 'ethers'; +import * as ethers from 'ethers'; import * as _ from 'lodash'; import { addressUtils } from './address_utils'; -- cgit v1.2.3