diff options
Diffstat (limited to 'packages/contract_templates')
-rw-r--r-- | packages/contract_templates/README.md | 4 | ||||
-rw-r--r-- | packages/contract_templates/contract.handlebars | 17 | ||||
-rw-r--r-- | packages/contract_templates/partials/callAsync.handlebars | 9 | ||||
-rw-r--r-- | packages/contract_templates/partials/tx.handlebars | 12 |
4 files changed, 19 insertions, 23 deletions
diff --git a/packages/contract_templates/README.md b/packages/contract_templates/README.md index e5f4b09d1..c6cc3b1b3 100644 --- a/packages/contract_templates/README.md +++ b/packages/contract_templates/README.md @@ -2,7 +2,7 @@ These templates are used with [abi-gen](https://github.com/0xProject/0x-monorepo To successfully compile the generated TypeScript contract wrappers, you must: -* Install the packages on which the main contract template directly depends: `yarn add @0xproject/base-contract @0xproject/sol-compiler @0xproject/utils @0xproject/web3-wrapper ethereum-types ethers lodash` +* Install the packages on which the main contract template directly depends: `yarn add @0x/base-contract @0x/sol-compiler @0x/utils @0x/web3-wrapper ethereum-types ethers lodash` * Install the packages on which the main contract template *in*directly depends: `yarn add @types/lodash` * Ensure that your TypeScript configuration includes the following: @@ -10,7 +10,7 @@ To successfully compile the generated TypeScript contract wrappers, you must: "compilerOptions": { "lib": ["ES2015"], "typeRoots": [ - "node_modules/@0xproject/typescript-typings/types", + "node_modules/@0x/typescript-typings/types", "node_modules/@types" ] } diff --git a/packages/contract_templates/contract.handlebars b/packages/contract_templates/contract.handlebars index 0810c4d90..9c1952ed4 100644 --- a/packages/contract_templates/contract.handlebars +++ b/packages/contract_templates/contract.handlebars @@ -1,10 +1,10 @@ // tslint:disable:no-consecutive-blank-lines ordered-imports align trailing-comma whitespace class-name // tslint:disable:no-unused-variable -import { BaseContract } from '@0xproject/base-contract'; -import { ContractArtifact } from '@0xproject/sol-compiler'; -import { BlockParam, BlockParamLiteral, CallData, ContractAbi, DataItem, DecodedLogArgs, MethodAbi, Provider, TxData, TxDataPayable } from 'ethereum-types'; -import { BigNumber, classUtils, logUtils, promisify } from '@0xproject/utils'; -import { Web3Wrapper } from '@0xproject/web3-wrapper'; +// tslint:disable:no-unbound-method +import { BaseContract } from '@0x/base-contract'; +import { BlockParam, BlockParamLiteral, CallData, ContractAbi, ContractArtifact, DecodedLogArgs, MethodAbi, Provider, TxData, TxDataPayable } from 'ethereum-types'; +import { BigNumber, classUtils, logUtils } from '@0x/utils'; +import { Web3Wrapper } from '@0x/web3-wrapper'; import * as ethers from 'ethers'; import * as _ from 'lodash'; // tslint:enable:no-unused-variable @@ -65,10 +65,12 @@ export class {{contractName}}Contract extends BaseContract { [{{> params inputs=ctor.inputs}}], BaseContract._bigNumberToString, ); - const txData = ethers.Contract.getDeployTransaction(bytecode, abi, {{> params inputs=ctor.inputs}}); + const iface = new ethers.utils.Interface(abi); + const deployInfo = iface.deployFunction; + const txData = deployInfo.encode(bytecode, [{{> params inputs=ctor.inputs}}]); const web3Wrapper = new Web3Wrapper(provider); const txDataWithDefaults = await BaseContract._applyDefaultsToTxDataAsync( - txData, + {data: txData}, txDefaults, web3Wrapper.estimateGasAsync.bind(web3Wrapper), ); @@ -85,3 +87,4 @@ export class {{contractName}}Contract extends BaseContract { classUtils.bindAll(this, ['_ethersInterfacesByFunctionSignature', 'address', 'abi', '_web3Wrapper']); } } // tslint:disable:max-file-line-count +// tslint:enable:no-unbound-method diff --git a/packages/contract_templates/partials/callAsync.handlebars b/packages/contract_templates/partials/callAsync.handlebars index 94752691d..ddbbe7508 100644 --- a/packages/contract_templates/partials/callAsync.handlebars +++ b/packages/contract_templates/partials/callAsync.handlebars @@ -8,10 +8,8 @@ async callAsync( const inputAbi = self._lookupAbi(functionSignature).inputs; [{{> params inputs=inputs}}] = BaseContract._formatABIDataItemList(inputAbi, [{{> params inputs=inputs}}], BaseContract._bigNumberToString.bind(self)); BaseContract.strictArgumentEncodingCheck(inputAbi, [{{> params inputs=inputs}}]); - const ethersFunction = self._lookupEthersInterface(functionSignature).functions.{{this.name}}( - {{> params inputs=inputs}} - ) as ethers.CallDescription; - const encodedData = ethersFunction.data; + const ethersFunction = self._lookupEthersInterface(functionSignature).functions.{{this.name}}; + const encodedData = ethersFunction.encode([{{> params inputs=inputs}}]); const callDataWithDefaults = await BaseContract._applyDefaultsToTxDataAsync( { to: self.address, @@ -21,7 +19,8 @@ async callAsync( self._web3Wrapper.getContractDefaults(), ); const rawCallResult = await self._web3Wrapper.callAsync(callDataWithDefaults, defaultBlock); - let resultArray = ethersFunction.parse(rawCallResult); + BaseContract._throwIfRevertWithReasonCallResult(rawCallResult); + let resultArray = ethersFunction.decode(rawCallResult); const outputAbi = (_.find(self.abi, {name: '{{this.name}}'}) as MethodAbi).outputs; resultArray = BaseContract._formatABIDataItemList(outputAbi, resultArray, BaseContract._lowercaseAddress.bind(this)); resultArray = BaseContract._formatABIDataItemList(outputAbi, resultArray, BaseContract._bnToBigNumber.bind(this)); diff --git a/packages/contract_templates/partials/tx.handlebars b/packages/contract_templates/partials/tx.handlebars index 4340d662e..b39156583 100644 --- a/packages/contract_templates/partials/tx.handlebars +++ b/packages/contract_templates/partials/tx.handlebars @@ -12,9 +12,7 @@ public {{this.tsName}} = { const inputAbi = self._lookupAbi('{{this.functionSignature}}').inputs; [{{> params inputs=inputs}}] = BaseContract._formatABIDataItemList(inputAbi, [{{> params inputs=inputs}}], BaseContract._bigNumberToString.bind(self)); BaseContract.strictArgumentEncodingCheck(inputAbi, [{{> params inputs=inputs}}]); - const encodedData = self._lookupEthersInterface('{{this.functionSignature}}').functions.{{this.name}}( - {{> params inputs=inputs}} - ).data; + const encodedData = self._lookupEthersInterface('{{this.functionSignature}}').functions.{{this.name}}.encode([{{> params inputs=inputs}}]); const txDataWithDefaults = await BaseContract._applyDefaultsToTxDataAsync( { to: self.address, @@ -37,9 +35,7 @@ public {{this.tsName}} = { const self = this as any as {{contractName}}Contract; const inputAbi = self._lookupAbi('{{this.functionSignature}}').inputs; [{{> params inputs=inputs}}] = BaseContract._formatABIDataItemList(inputAbi, [{{> params inputs=inputs}}], BaseContract._bigNumberToString); - const encodedData = self._lookupEthersInterface('{{this.functionSignature}}').functions.{{this.name}}( - {{> params inputs=inputs}} - ).data; + const encodedData = self._lookupEthersInterface('{{this.functionSignature}}').functions.{{this.name}}.encode([{{> params inputs=inputs}}]); const txDataWithDefaults = await BaseContract._applyDefaultsToTxDataAsync( { to: self.address, @@ -57,9 +53,7 @@ public {{this.tsName}} = { const self = this as any as {{contractName}}Contract; const inputAbi = self._lookupAbi('{{this.functionSignature}}').inputs; [{{> params inputs=inputs}}] = BaseContract._formatABIDataItemList(inputAbi, [{{> params inputs=inputs}}], BaseContract._bigNumberToString); - const abiEncodedTransactionData = self._lookupEthersInterface('{{this.functionSignature}}').functions.{{this.name}}( - {{> params inputs=inputs}} - ).data; + const abiEncodedTransactionData = self._lookupEthersInterface('{{this.functionSignature}}').functions.{{this.name}}.encode([{{> params inputs=inputs}}]); return abiEncodedTransactionData; }, {{> callAsync}} |