aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJacob Evans <dekz@dekz.net>2018-04-20 06:49:23 +0800
committerGitHub <noreply@github.com>2018-04-20 06:49:23 +0800
commit62a55c013516c82eb4aa26c90db7533cd72f8d1b (patch)
treea96728392d7f9890e8a8f5a8c18627acc2ea8f28
parentf6fd4281a4772c28521fa606bd37f16a21dbe23c (diff)
parent72336eb393d775817619a354d784b7dea4e243bf (diff)
downloaddexon-sol-tools-62a55c013516c82eb4aa26c90db7533cd72f8d1b.tar
dexon-sol-tools-62a55c013516c82eb4aa26c90db7533cd72f8d1b.tar.gz
dexon-sol-tools-62a55c013516c82eb4aa26c90db7533cd72f8d1b.tar.bz2
dexon-sol-tools-62a55c013516c82eb4aa26c90db7533cd72f8d1b.tar.lz
dexon-sol-tools-62a55c013516c82eb4aa26c90db7533cd72f8d1b.tar.xz
dexon-sol-tools-62a55c013516c82eb4aa26c90db7533cd72f8d1b.tar.zst
dexon-sol-tools-62a55c013516c82eb4aa26c90db7533cd72f8d1b.zip
Merge pull request #540 from 0xProject/feature/abi-gen/tuple-return-types
Support Tuples returned from functions
-rw-r--r--packages/0x.js/package.json2
-rw-r--r--packages/base-contract/CHANGELOG.json9
-rw-r--r--packages/base-contract/package.json2
-rw-r--r--packages/base-contract/src/index.ts8
-rw-r--r--packages/contract_templates/contract.handlebars2
-rw-r--r--packages/contract_templates/partials/callAsync.handlebars11
-rw-r--r--packages/contract_templates/partials/return_type.handlebars2
-rw-r--r--packages/metacoin/package.json2
-rw-r--r--packages/typescript-typings/CHANGELOG.json9
-rw-r--r--packages/typescript-typings/types/ethers/index.d.ts (renamed from packages/typescript-typings/types/ethers-contracts/index.d.ts)9
-rw-r--r--packages/utils/CHANGELOG.json9
-rw-r--r--packages/utils/package.json2
-rw-r--r--packages/utils/src/abi_decoder.ts8
-rw-r--r--packages/web3-wrapper/package.json2
-rw-r--r--yarn.lock36
15 files changed, 90 insertions, 23 deletions
diff --git a/packages/0x.js/package.json b/packages/0x.js/package.json
index dd4bd3f5c..e7cdff09e 100644
--- a/packages/0x.js/package.json
+++ b/packages/0x.js/package.json
@@ -109,7 +109,7 @@
"ethereumjs-abi": "^0.6.4",
"ethereumjs-blockstream": "^2.0.6",
"ethereumjs-util": "^5.1.1",
- "ethers-contracts": "^2.2.1",
+ "ethers": "^3.0.15",
"js-sha3": "^0.7.0",
"lodash": "^4.17.4",
"uuid": "^3.1.0",
diff --git a/packages/base-contract/CHANGELOG.json b/packages/base-contract/CHANGELOG.json
index ed3c86465..c5d467b7f 100644
--- a/packages/base-contract/CHANGELOG.json
+++ b/packages/base-contract/CHANGELOG.json
@@ -1,5 +1,14 @@
[
{
+ "version": "0.3.0",
+ "changes": [
+ {
+ "note": "Update ethers-contracts to ethers.js",
+ "pr": 540
+ }
+ ]
+ },
+ {
"timestamp": 1524044013,
"version": "0.2.1",
"changes": [
diff --git a/packages/base-contract/package.json b/packages/base-contract/package.json
index 22ae43cdc..78dcbfe7f 100644
--- a/packages/base-contract/package.json
+++ b/packages/base-contract/package.json
@@ -42,7 +42,7 @@
"@0xproject/typescript-typings": "^0.2.0",
"@0xproject/utils": "^0.5.2",
"@0xproject/web3-wrapper": "^0.6.1",
- "ethers-contracts": "^2.2.1",
+ "ethers": "^3.0.15",
"lodash": "^4.17.4"
},
"publishConfig": {
diff --git a/packages/base-contract/src/index.ts b/packages/base-contract/src/index.ts
index bfa99fac1..e95b18db6 100644
--- a/packages/base-contract/src/index.ts
+++ b/packages/base-contract/src/index.ts
@@ -10,13 +10,13 @@ import {
} from '@0xproject/types';
import { abiUtils, BigNumber } from '@0xproject/utils';
import { Web3Wrapper } from '@0xproject/web3-wrapper';
-import * as ethersContracts from 'ethers-contracts';
+import * as ethers from 'ethers';
import * as _ from 'lodash';
import { formatABIDataItem } from './utils';
export interface EthersInterfaceByFunctionSignature {
- [key: string]: ethersContracts.Interface;
+ [key: string]: ethers.Interface;
}
export class BaseContract {
@@ -62,7 +62,7 @@ export class BaseContract {
}
return txDataWithDefaults;
}
- protected _lookupEthersInterface(functionSignature: string): ethersContracts.Interface {
+ protected _lookupEthersInterface(functionSignature: string): ethers.Interface {
const ethersInterface = this._ethersInterfacesByFunctionSignature[functionSignature];
if (_.isUndefined(ethersInterface)) {
throw new Error(`Failed to lookup method with function signature '${functionSignature}'`);
@@ -92,7 +92,7 @@ export class BaseContract {
this._ethersInterfacesByFunctionSignature = {};
_.each(methodAbis, methodAbi => {
const functionSignature = abiUtils.getFunctionSignature(methodAbi);
- this._ethersInterfacesByFunctionSignature[functionSignature] = new ethersContracts.Interface([methodAbi]);
+ this._ethersInterfacesByFunctionSignature[functionSignature] = new ethers.Interface([methodAbi]);
});
}
}
diff --git a/packages/contract_templates/contract.handlebars b/packages/contract_templates/contract.handlebars
index 472452d74..cf51dad90 100644
--- a/packages/contract_templates/contract.handlebars
+++ b/packages/contract_templates/contract.handlebars
@@ -8,7 +8,7 @@ import { BaseContract } from '@0xproject/base-contract';
import { BlockParam, BlockParamLiteral, CallData, ContractAbi, DataItem, MethodAbi, Provider, TxData, TxDataPayable } from '@0xproject/types';
import { BigNumber, classUtils, promisify } from '@0xproject/utils';
import { Web3Wrapper } from '@0xproject/web3-wrapper';
-import * as ethersContracts from 'ethers-contracts';
+import * as ethers from 'ethers';
import * as _ from 'lodash';
{{#if events}}
diff --git a/packages/contract_templates/partials/callAsync.handlebars b/packages/contract_templates/partials/callAsync.handlebars
index a6f4abdf2..58fb2f09c 100644
--- a/packages/contract_templates/partials/callAsync.handlebars
+++ b/packages/contract_templates/partials/callAsync.handlebars
@@ -5,20 +5,21 @@ async callAsync(
defaultBlock?: BlockParam,
): Promise<{{> return_type outputs=outputs}}> {
const self = this as any as {{contractName}}Contract;
- const inputAbi = self._lookupAbi('{{this.functionSignature}}').inputs;
+ const functionSignature = '{{this.functionSignature}}';
+ const inputAbi = self._lookupAbi(functionSignature).inputs;
[{{> params inputs=inputs}}] = BaseContract._formatABIDataItemList(inputAbi, [{{> params inputs=inputs}}], BaseContract._bigNumberToString.bind(self));
- const encodedData = self._lookupEthersInterface('{{this.functionSignature}}').functions.{{this.name}}(
+ const ethersFunction = self._lookupEthersInterface(functionSignature).functions.{{this.name}}(
{{> params inputs=inputs}}
- ).data;
+ ) as ethers.CallDescription;
+ const encodedData = ethersFunction.data;
const callDataWithDefaults = await self._applyDefaultsToTxDataAsync(
{
data: encodedData,
}
)
const rawCallResult = await self._web3Wrapper.callAsync(callDataWithDefaults, defaultBlock);
+ let resultArray = ethersFunction.parse(rawCallResult);
const outputAbi = (_.find(self.abi, {name: '{{this.name}}'}) as MethodAbi).outputs;
- const outputParamsTypes = _.map(outputAbi, 'type');
- let resultArray = ethersContracts.Interface.decodeParams(outputParamsTypes, rawCallResult) as any;
resultArray = BaseContract._formatABIDataItemList(outputAbi, resultArray, BaseContract._lowercaseAddress.bind(this));
resultArray = BaseContract._formatABIDataItemList(outputAbi, resultArray, BaseContract._bnToBigNumber.bind(this));
return resultArray{{#singleReturnValue}}[0]{{/singleReturnValue}};
diff --git a/packages/contract_templates/partials/return_type.handlebars b/packages/contract_templates/partials/return_type.handlebars
index 9dd509953..77d96e8c4 100644
--- a/packages/contract_templates/partials/return_type.handlebars
+++ b/packages/contract_templates/partials/return_type.handlebars
@@ -1,6 +1,6 @@
{{#if outputs.length}}
{{#singleReturnValue}}
-{{#returnType outputs.0.type components}}{{/returnType}}
+{{#returnType outputs.0.type outputs.0.components}}{{/returnType}}
{{/singleReturnValue}}
{{^singleReturnValue}}
[{{#each outputs}}{{#returnType type components}}{{/returnType}}{{#unless @last}}, {{/unless}}{{/each}}]
diff --git a/packages/metacoin/package.json b/packages/metacoin/package.json
index 80bd22791..e944d725b 100644
--- a/packages/metacoin/package.json
+++ b/packages/metacoin/package.json
@@ -32,7 +32,7 @@
"@0xproject/types": "^0.6.1",
"@0xproject/utils": "^0.5.2",
"@0xproject/web3-wrapper": "^0.6.1",
- "ethers-contracts": "^2.2.1",
+ "ethers": "^3.0.15",
"lodash": "^4.17.4",
"web3-provider-engine": "^13.0.1"
},
diff --git a/packages/typescript-typings/CHANGELOG.json b/packages/typescript-typings/CHANGELOG.json
index a2f1e7615..f3f68d509 100644
--- a/packages/typescript-typings/CHANGELOG.json
+++ b/packages/typescript-typings/CHANGELOG.json
@@ -1,5 +1,14 @@
[
{
+ "version": "0.3.0",
+ "changes": [
+ {
+ "note": "Add types for `ethers.js`, removing `ethers-contracts`",
+ "pr": 540
+ }
+ ]
+ },
+ {
"version": "0.2.0",
"changes": [
{
diff --git a/packages/typescript-typings/types/ethers-contracts/index.d.ts b/packages/typescript-typings/types/ethers/index.d.ts
index e5d38819e..7e04c7dd1 100644
--- a/packages/typescript-typings/types/ethers-contracts/index.d.ts
+++ b/packages/typescript-typings/types/ethers/index.d.ts
@@ -1,4 +1,4 @@
-declare module 'ethers-contracts' {
+declare module 'ethers' {
export interface TransactionDescription {
name: string;
signature: string;
@@ -12,17 +12,20 @@ declare module 'ethers-contracts' {
(...params: any[]): TransactionDescription | CallDescription;
inputs: { names: string[]; types: string[] };
outputs: { names: string[]; types: string[] };
+ type: string;
}
export interface EventDescription {
parse: (...args: any[]) => any;
inputs: { names: string[]; types: string[] };
signature: string;
- topic: string;
+ topics: string[];
}
export class Interface {
public functions: { [functionName: string]: FunctionDescription };
public events: { [eventName: string]: EventDescription };
- public static decodeParams(types: string[], data: string): any[];
constructor(abi: any);
}
+ export class Contract {
+ constructor(address: string, abi: any, provider: any);
+ }
}
diff --git a/packages/utils/CHANGELOG.json b/packages/utils/CHANGELOG.json
index 1aeb3b457..e7f3c052c 100644
--- a/packages/utils/CHANGELOG.json
+++ b/packages/utils/CHANGELOG.json
@@ -1,5 +1,14 @@
[
{
+ "version": "0.6.0",
+ "changes": [
+ {
+ "note": "Update ethers-contracts to ethers.js",
+ "pr": 540
+ }
+ ]
+ },
+ {
"version": "0.5.2",
"changes": [
{
diff --git a/packages/utils/package.json b/packages/utils/package.json
index bbc87c53f..f309c2126 100644
--- a/packages/utils/package.json
+++ b/packages/utils/package.json
@@ -35,7 +35,7 @@
"@0xproject/typescript-typings": "^0.2.0",
"@types/node": "^8.0.53",
"bignumber.js": "~4.1.0",
- "ethers-contracts": "^2.2.1",
+ "ethers": "^3.0.15",
"js-sha3": "^0.7.0",
"lodash": "^4.17.4",
"web3": "^0.20.0"
diff --git a/packages/utils/src/abi_decoder.ts b/packages/utils/src/abi_decoder.ts
index 36c7839cf..150f74a15 100644
--- a/packages/utils/src/abi_decoder.ts
+++ b/packages/utils/src/abi_decoder.ts
@@ -9,7 +9,7 @@ import {
RawLog,
SolidityTypes,
} from '@0xproject/types';
-import * as ethersContracts from 'ethers-contracts';
+import * as ethers from 'ethers';
import * as _ from 'lodash';
import { BigNumber } from './configured_bignumber';
@@ -36,7 +36,7 @@ export class AbiDecoder {
if (_.isUndefined(event)) {
return log;
}
- const ethersInterface = new ethersContracts.Interface([event]);
+ const ethersInterface = new ethers.Interface([event]);
const logData = log.data;
const decodedParams: DecodedLogArgs = {};
let topicsIndex = 1;
@@ -77,10 +77,10 @@ export class AbiDecoder {
if (_.isUndefined(abiArray)) {
return;
}
- const ethersInterface = new ethersContracts.Interface(abiArray);
+ const ethersInterface = new ethers.Interface(abiArray);
_.map(abiArray, (abi: AbiDefinition) => {
if (abi.type === AbiType.Event) {
- const topic = ethersInterface.events[abi.name].topic;
+ const topic = ethersInterface.events[abi.name].topics[0];
this._methodIds[topic] = abi;
}
});
diff --git a/packages/web3-wrapper/package.json b/packages/web3-wrapper/package.json
index 61a886e46..118330707 100644
--- a/packages/web3-wrapper/package.json
+++ b/packages/web3-wrapper/package.json
@@ -61,7 +61,7 @@
"@0xproject/types": "^0.6.1",
"@0xproject/typescript-typings": "^0.2.0",
"@0xproject/utils": "^0.5.2",
- "ethers-contracts": "^2.2.1",
+ "ethers": "^3.0.15",
"lodash": "^4.17.4",
"web3": "^0.20.0"
},
diff --git a/yarn.lock b/yarn.lock
index 3b77af279..a62d48512 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -491,6 +491,10 @@ add-stream@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/add-stream/-/add-stream-1.0.0.tgz#6a7990437ca736d5e1288db92bd3266d5f5cb2aa"
+aes-js@3.0.0:
+ version "3.0.0"
+ resolved "https://registry.yarnpkg.com/aes-js/-/aes-js-3.0.0.tgz#e21df10ad6c2053295bcbb8dab40b09dbea87e4d"
+
aes-js@^0.2.3:
version "0.2.4"
resolved "https://registry.yarnpkg.com/aes-js/-/aes-js-0.2.4.tgz#94b881ab717286d015fa219e08fb66709dda5a3d"
@@ -3283,6 +3287,15 @@ electron-to-chromium@^1.2.7, electron-to-chromium@^1.3.30:
version "1.3.40"
resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.3.40.tgz#1fbd6d97befd72b8a6f921dc38d22413d2f6fddf"
+elliptic@6.3.3:
+ version "6.3.3"
+ resolved "https://registry.yarnpkg.com/elliptic/-/elliptic-6.3.3.tgz#5482d9646d54bcb89fd7d994fc9e2e9568876e3f"
+ dependencies:
+ bn.js "^4.4.0"
+ brorand "^1.0.1"
+ hash.js "^1.0.0"
+ inherits "^2.0.1"
+
elliptic@^6.0.0, elliptic@^6.2.3, elliptic@^6.4.0:
version "6.4.0"
resolved "https://registry.yarnpkg.com/elliptic/-/elliptic-6.4.0.tgz#cac9af8762c85836187003c8dfe193e5e2eae5df"
@@ -3688,6 +3701,21 @@ ethers-utils@^2.1.0:
js-sha3 "0.5.7"
xmlhttprequest "1.8.0"
+ethers@^3.0.15:
+ version "3.0.15"
+ resolved "https://registry.yarnpkg.com/ethers/-/ethers-3.0.15.tgz#7cdea4e23025681f69f575bf481b227315e0e7ab"
+ dependencies:
+ aes-js "3.0.0"
+ bn.js "^4.4.0"
+ elliptic "6.3.3"
+ hash.js "^1.0.0"
+ inherits "2.0.1"
+ js-sha3 "0.5.7"
+ scrypt-js "2.0.3"
+ setimmediate "1.0.4"
+ uuid "2.0.1"
+ xmlhttprequest "1.8.0"
+
ethjs-abi@0.1.8:
version "0.1.8"
resolved "https://registry.yarnpkg.com/ethjs-abi/-/ethjs-abi-0.1.8.tgz#cd288583ed628cdfadaf8adefa3ba1dbcbca6c18"
@@ -9235,6 +9263,10 @@ schema-utils@^0.4.5:
ajv "^6.1.0"
ajv-keywords "^3.1.0"
+scrypt-js@2.0.3:
+ version "2.0.3"
+ resolved "https://registry.yarnpkg.com/scrypt-js/-/scrypt-js-2.0.3.tgz#bb0040be03043da9a012a2cea9fc9f852cfc87d4"
+
scrypt.js@0.2.0, scrypt.js@^0.2.0:
version "0.2.0"
resolved "https://registry.yarnpkg.com/scrypt.js/-/scrypt.js-0.2.0.tgz#af8d1465b71e9990110bedfc593b9479e03a8ada"
@@ -9419,6 +9451,10 @@ set-value@^2.0.0:
is-plain-object "^2.0.3"
split-string "^3.0.1"
+setimmediate@1.0.4:
+ version "1.0.4"
+ resolved "https://registry.yarnpkg.com/setimmediate/-/setimmediate-1.0.4.tgz#20e81de622d4a02588ce0c8da8973cbcf1d3138f"
+
setimmediate@^1.0.4, setimmediate@^1.0.5:
version "1.0.5"
resolved "https://registry.yarnpkg.com/setimmediate/-/setimmediate-1.0.5.tgz#290cbb232e306942d7d7ea9b83732ab7856f8285"