aboutsummaryrefslogtreecommitdiffstats
path: root/packages/0x.js
diff options
context:
space:
mode:
authorLeonid Logvinov <logvinov.leon@gmail.com>2018-02-28 06:41:59 +0800
committerGitHub <noreply@github.com>2018-02-28 06:41:59 +0800
commit7aa070f9eaef734274df6e6eaa4590fe30d52899 (patch)
tree454cc4800db190b664d65609c62048a989e2d933 /packages/0x.js
parentc2ec2291e8243266f52a3b89f38ba67ce1215c22 (diff)
parentce0b92d681cfb510ede09296b60260637781f875 (diff)
downloaddexon-sol-tools-7aa070f9eaef734274df6e6eaa4590fe30d52899.tar
dexon-sol-tools-7aa070f9eaef734274df6e6eaa4590fe30d52899.tar.gz
dexon-sol-tools-7aa070f9eaef734274df6e6eaa4590fe30d52899.tar.bz2
dexon-sol-tools-7aa070f9eaef734274df6e6eaa4590fe30d52899.tar.lz
dexon-sol-tools-7aa070f9eaef734274df6e6eaa4590fe30d52899.tar.xz
dexon-sol-tools-7aa070f9eaef734274df6e6eaa4590fe30d52899.tar.zst
dexon-sol-tools-7aa070f9eaef734274df6e6eaa4590fe30d52899.zip
Merge pull request #413 from 0xProject/feature/ethers-contracts
abi-gen V2 abi and ethers-contracts
Diffstat (limited to 'packages/0x.js')
-rw-r--r--packages/0x.js/CHANGELOG.md1
-rw-r--r--packages/0x.js/contract_templates/contract.handlebars44
-rw-r--r--packages/0x.js/contract_templates/partials/call.handlebars15
-rw-r--r--packages/0x.js/contract_templates/partials/event.handlebars5
-rw-r--r--packages/0x.js/contract_templates/partials/params.handlebars3
-rw-r--r--packages/0x.js/contract_templates/partials/return_type.handlebars6
-rw-r--r--packages/0x.js/contract_templates/partials/tx.handlebars51
-rw-r--r--packages/0x.js/contract_templates/partials/typed_params.handlebars3
-rw-r--r--packages/0x.js/package.json4
-rw-r--r--packages/0x.js/src/contract_wrappers/contract_wrapper.ts8
-rw-r--r--packages/0x.js/src/contract_wrappers/ether_token_wrapper.ts4
-rw-r--r--packages/0x.js/src/contract_wrappers/exchange_wrapper.ts14
-rw-r--r--packages/0x.js/src/contract_wrappers/generated/.gitignore7
-rw-r--r--packages/0x.js/src/contract_wrappers/generated/base_contract.ts33
-rw-r--r--packages/0x.js/src/contract_wrappers/token_registry_wrapper.ts12
-rw-r--r--packages/0x.js/src/contract_wrappers/token_transfer_proxy_wrapper.ts7
-rw-r--r--packages/0x.js/src/contract_wrappers/token_wrapper.ts9
-rw-r--r--packages/0x.js/src/types.ts2
-rw-r--r--packages/0x.js/test/utils/fill_scenarios.ts6
-rw-r--r--packages/0x.js/tsconfig.json1
20 files changed, 36 insertions, 199 deletions
diff --git a/packages/0x.js/CHANGELOG.md b/packages/0x.js/CHANGELOG.md
index 2710788e0..b882a1b31 100644
--- a/packages/0x.js/CHANGELOG.md
+++ b/packages/0x.js/CHANGELOG.md
@@ -4,6 +4,7 @@
* Validate and lowercase all addresses in public methods (#373)
* Improve validation to force passing contract addresses on private networks (#385)
+ * Change `LogErrorContractEventArgs.errorId` type from `BigNumber` to `number` (#413)
* Rename all public `_unsubscribeAll` methods to `unsubscribeAll` (#415)
## v0.32.2 - _February 9, 2018_
diff --git a/packages/0x.js/contract_templates/contract.handlebars b/packages/0x.js/contract_templates/contract.handlebars
deleted file mode 100644
index 33699b8a7..000000000
--- a/packages/0x.js/contract_templates/contract.handlebars
+++ /dev/null
@@ -1,44 +0,0 @@
-/**
- * This file is auto-generated using abi-gen. Don't edit directly.
- * Templates can be found at https://github.com/0xProject/0x.js/tree/development/packages/0x.js/contract_templates.
- */
-// tslint:disable:no-consecutive-blank-lines
-// tslint:disable-next-line:no-unused-variable
-import { TxData, TxDataPayable } from '@0xproject/types';
-import { BigNumber, classUtils, promisify } from '@0xproject/utils';
-import * as Web3 from 'web3';
-
-import {BaseContract} from './base_contract';
-
-{{#if events}}
-export type {{contractName}}ContractEventArgs =
-{{#each events}}
- | {{name}}ContractEventArgs{{#if @last}};{{/if}}
-{{/each}}
-
-export enum {{contractName}}Events {
- {{#each events}}
- {{name}} = '{{name}}',
- {{/each}}
-}
-
-{{#each events}}
-{{> event}}
-
-{{/each}}
-{{/if}}
-
-export class {{contractName}}Contract extends BaseContract {
-{{#each methods}}
- {{#this.constant}}
- {{> call contractName=../contractName}}
- {{/this.constant}}
- {{^this.constant}}
- {{> tx contractName=../contractName}}
- {{/this.constant}}
-{{/each}}
- constructor(web3ContractInstance: Web3.ContractInstance, defaults: Partial<TxData>) {
- super(web3ContractInstance, defaults);
- classUtils.bindAll(this, ['_web3ContractInstance', '_defaults']);
- }
-} // tslint:disable:max-file-line-count
diff --git a/packages/0x.js/contract_templates/partials/call.handlebars b/packages/0x.js/contract_templates/partials/call.handlebars
deleted file mode 100644
index 0475136f0..000000000
--- a/packages/0x.js/contract_templates/partials/call.handlebars
+++ /dev/null
@@ -1,15 +0,0 @@
-public {{this.name}} = {
- async callAsync(
- {{> typed_params inputs=inputs}}
- defaultBlock?: Web3.BlockParam,
- ): Promise<{{> return_type outputs=outputs}}> {
- const self = this as {{contractName}}Contract;
- const result = await promisify<{{> return_type outputs=outputs}}>(
- self._web3ContractInstance.{{this.name}}.call,
- self._web3ContractInstance,
- )(
- {{> params inputs=inputs}}
- );
- return result;
- },
-};
diff --git a/packages/0x.js/contract_templates/partials/event.handlebars b/packages/0x.js/contract_templates/partials/event.handlebars
deleted file mode 100644
index 6d68d4c0f..000000000
--- a/packages/0x.js/contract_templates/partials/event.handlebars
+++ /dev/null
@@ -1,5 +0,0 @@
-export interface {{name}}ContractEventArgs {
- {{#each inputs}}
- {{name}}: {{#returnType type}}{{/returnType}};
- {{/each}}
-}
diff --git a/packages/0x.js/contract_templates/partials/params.handlebars b/packages/0x.js/contract_templates/partials/params.handlebars
deleted file mode 100644
index ac5d4ae85..000000000
--- a/packages/0x.js/contract_templates/partials/params.handlebars
+++ /dev/null
@@ -1,3 +0,0 @@
-{{#each inputs}}
-{{name}},
-{{/each}}
diff --git a/packages/0x.js/contract_templates/partials/return_type.handlebars b/packages/0x.js/contract_templates/partials/return_type.handlebars
deleted file mode 100644
index 383961a40..000000000
--- a/packages/0x.js/contract_templates/partials/return_type.handlebars
+++ /dev/null
@@ -1,6 +0,0 @@
-{{#singleReturnValue}}
-{{#returnType outputs.0.type}}{{/returnType}}
-{{/singleReturnValue}}
-{{^singleReturnValue}}
-[{{#each outputs}}{{#returnType type}}{{/returnType}}{{#unless @last}}, {{/unless}}{{/each}}]
-{{/singleReturnValue}}
diff --git a/packages/0x.js/contract_templates/partials/tx.handlebars b/packages/0x.js/contract_templates/partials/tx.handlebars
deleted file mode 100644
index 9df83266a..000000000
--- a/packages/0x.js/contract_templates/partials/tx.handlebars
+++ /dev/null
@@ -1,51 +0,0 @@
-public {{this.name}} = {
- async sendTransactionAsync(
- {{> typed_params inputs=inputs}}
- {{#this.payable}}
- txData: TxDataPayable = {},
- {{/this.payable}}
- {{^this.payable}}
- txData: TxData = {},
- {{/this.payable}}
- ): Promise<string> {
- const self = this as {{contractName}}Contract;
- const txDataWithDefaults = await self._applyDefaultsToTxDataAsync(
- txData,
- self.{{this.name}}.estimateGasAsync.bind(
- self,
- {{> params inputs=inputs}}
- ),
- );
- const txHash = await promisify<string>(
- self._web3ContractInstance.{{this.name}}, self._web3ContractInstance,
- )(
- {{> params inputs=inputs}}
- txDataWithDefaults,
- );
- return txHash;
- },
- async estimateGasAsync(
- {{> typed_params inputs=inputs}}
- txData: TxData = {},
- ): Promise<number> {
- const self = this as {{contractName}}Contract;
- const txDataWithDefaults = await self._applyDefaultsToTxDataAsync(
- txData,
- );
- const gas = await promisify<number>(
- self._web3ContractInstance.{{this.name}}.estimateGas, self._web3ContractInstance,
- )(
- {{> params inputs=inputs}}
- txDataWithDefaults,
- );
- return gas;
- },
- getABIEncodedTransactionData(
- {{> typed_params inputs=inputs}}
- txData: TxData = {},
- ): string {
- const self = this as {{contractName}}Contract;
- const abiEncodedTransactionData = self._web3ContractInstance.{{this.name}}.getData();
- return abiEncodedTransactionData;
- },
-};
diff --git a/packages/0x.js/contract_templates/partials/typed_params.handlebars b/packages/0x.js/contract_templates/partials/typed_params.handlebars
deleted file mode 100644
index 3ea4b2e95..000000000
--- a/packages/0x.js/contract_templates/partials/typed_params.handlebars
+++ /dev/null
@@ -1,3 +0,0 @@
-{{#each inputs}}
- {{name}}: {{#parameterType type}}{{/parameterType}},
-{{/each}}
diff --git a/packages/0x.js/package.json b/packages/0x.js/package.json
index 4fb0eb6ac..96ba28b75 100644
--- a/packages/0x.js/package.json
+++ b/packages/0x.js/package.json
@@ -17,7 +17,7 @@
"build": "run-p build:umd:prod build:commonjs; exit 0;",
"docs:json": "typedoc --excludePrivate --excludeExternals --target ES5 --json $JSON_FILE_PATH $PROJECT_DIR",
"upload_docs_json": "aws s3 cp generated_docs/index.json $S3_URL --profile 0xproject --grants read=uri=http://acs.amazonaws.com/groups/global/AllUsers --content-type application/json",
- "generate_contract_wrappers": "node ../abi-gen/lib/index.js --abis 'src/artifacts/@(Exchange|Token|TokenTransferProxy|EtherToken|TokenRegistry|DummyToken).json' --template contract_templates/contract.handlebars --partials 'contract_templates/partials/**/*.handlebars' --output src/contract_wrappers/generated",
+ "generate_contract_wrappers": "node ../abi-gen/lib/index.js --abis 'src/artifacts/@(Exchange|Token|TokenTransferProxy|EtherToken|TokenRegistry|DummyToken).json' --template ../contract_templates/contract.handlebars --partials '../contract_templates/partials/**/*.handlebars' --output src/contract_wrappers/generated --backend ethers && prettier --write 'src/contract_wrappers/generated/**.ts'",
"lint": "tslint --project . 'src/**/*.ts' 'test/**/*.ts'",
"test:circleci": "run-s test:coverage report_test_coverage",
"test": "run-s clean test:commonjs",
@@ -77,6 +77,7 @@
"types-bn": "^0.0.1",
"typescript": "2.7.1",
"web3-provider-engine": "^13.0.1",
+ "ethers-typescript-typings": "^0.0.1",
"web3-typescript-typings": "^0.9.11",
"webpack": "^3.1.0"
},
@@ -88,6 +89,7 @@
"@0xproject/web3-wrapper": "^0.1.14",
"bintrees": "^1.0.2",
"bn.js": "^4.11.8",
+ "ethers-contracts": "^2.2.1",
"ethereumjs-abi": "^0.6.4",
"ethereumjs-blockstream": "^2.0.6",
"ethereumjs-util": "^5.1.1",
diff --git a/packages/0x.js/src/contract_wrappers/contract_wrapper.ts b/packages/0x.js/src/contract_wrappers/contract_wrapper.ts
index b313273b5..ad7727de5 100644
--- a/packages/0x.js/src/contract_wrappers/contract_wrapper.ts
+++ b/packages/0x.js/src/contract_wrappers/contract_wrapper.ts
@@ -108,10 +108,10 @@ export class ContractWrapper {
const logWithDecodedArgs = this._abiDecoder.tryToDecodeLogOrNoop(log);
return logWithDecodedArgs;
}
- protected async _instantiateContractIfExistsAsync(
+ protected async _getContractAbiAndAddressFromArtifactsAsync(
artifact: Artifact,
addressIfExists?: string,
- ): Promise<Web3.ContractInstance> {
+ ): Promise<[Web3.ContractAbi, string]> {
let contractAddress: string;
if (_.isUndefined(addressIfExists)) {
if (_.isUndefined(artifact.networks[this._networkId])) {
@@ -125,8 +125,8 @@ export class ContractWrapper {
if (!doesContractExist) {
throw new Error(CONTRACT_NAME_TO_NOT_FOUND_ERROR[artifact.contract_name]);
}
- const contractInstance = this._web3Wrapper.getContractInstance(artifact.abi, contractAddress);
- return contractInstance;
+ const abiAndAddress: [Web3.ContractAbi, string] = [artifact.abi, contractAddress];
+ return abiAndAddress;
}
protected _getContractAddress(artifact: Artifact, addressIfExists?: string): string {
if (_.isUndefined(addressIfExists)) {
diff --git a/packages/0x.js/src/contract_wrappers/ether_token_wrapper.ts b/packages/0x.js/src/contract_wrappers/ether_token_wrapper.ts
index 4807eff33..42f8213a2 100644
--- a/packages/0x.js/src/contract_wrappers/ether_token_wrapper.ts
+++ b/packages/0x.js/src/contract_wrappers/ether_token_wrapper.ts
@@ -187,11 +187,11 @@ export class EtherTokenWrapper extends ContractWrapper {
if (!_.isUndefined(etherTokenContract)) {
return etherTokenContract;
}
- const web3ContractInstance = await this._instantiateContractIfExistsAsync(
+ const [abi, address] = await this._getContractAbiAndAddressFromArtifactsAsync(
artifacts.EtherTokenArtifact,
etherTokenAddress,
);
- const contractInstance = new EtherTokenContract(web3ContractInstance, this._web3Wrapper.getContractDefaults());
+ const contractInstance = new EtherTokenContract(this._web3Wrapper, abi, address);
etherTokenContract = contractInstance;
this._etherTokenContractsByAddress[etherTokenAddress] = etherTokenContract;
return etherTokenContract;
diff --git a/packages/0x.js/src/contract_wrappers/exchange_wrapper.ts b/packages/0x.js/src/contract_wrappers/exchange_wrapper.ts
index 6bafc84c1..20b46c6bc 100644
--- a/packages/0x.js/src/contract_wrappers/exchange_wrapper.ts
+++ b/packages/0x.js/src/contract_wrappers/exchange_wrapper.ts
@@ -108,8 +108,10 @@ export class ExchangeWrapper extends ContractWrapper {
const exchangeContract = await this._getExchangeContractAsync();
const defaultBlock = _.isUndefined(methodOpts) ? undefined : methodOpts.defaultBlock;
+ const txData = {};
let unavailableTakerTokenAmount = await exchangeContract.getUnavailableTakerTokenAmount.callAsync(
orderHash,
+ txData,
defaultBlock,
);
// Wrap BigNumbers returned from web3 with our own (later) version of BigNumber
@@ -127,7 +129,8 @@ export class ExchangeWrapper extends ContractWrapper {
const exchangeContract = await this._getExchangeContractAsync();
const defaultBlock = _.isUndefined(methodOpts) ? undefined : methodOpts.defaultBlock;
- let fillAmountInBaseUnits = await exchangeContract.filled.callAsync(orderHash, defaultBlock);
+ const txData = {};
+ let fillAmountInBaseUnits = await exchangeContract.filled.callAsync(orderHash, txData, defaultBlock);
// Wrap BigNumbers returned from web3 with our own (later) version of BigNumber
fillAmountInBaseUnits = new BigNumber(fillAmountInBaseUnits);
return fillAmountInBaseUnits;
@@ -144,7 +147,8 @@ export class ExchangeWrapper extends ContractWrapper {
const exchangeContract = await this._getExchangeContractAsync();
const defaultBlock = _.isUndefined(methodOpts) ? undefined : methodOpts.defaultBlock;
- let cancelledAmountInBaseUnits = await exchangeContract.cancelled.callAsync(orderHash, defaultBlock);
+ const txData = {};
+ let cancelledAmountInBaseUnits = await exchangeContract.cancelled.callAsync(orderHash, txData, defaultBlock);
// Wrap BigNumbers returned from web3 with our own (later) version of BigNumber
cancelledAmountInBaseUnits = new BigNumber(cancelledAmountInBaseUnits);
return cancelledAmountInBaseUnits;
@@ -858,7 +862,7 @@ export class ExchangeWrapper extends ContractWrapper {
});
if (!_.isUndefined(errLog)) {
const logArgs = (errLog as LogWithDecodedArgs<LogErrorContractEventArgs>).args;
- const errCode = logArgs.errorId.toNumber();
+ const errCode = logArgs.errorId;
const errMessage = this._exchangeContractErrCodesToMsg[errCode];
throw new Error(errMessage);
}
@@ -906,11 +910,11 @@ export class ExchangeWrapper extends ContractWrapper {
if (!_.isUndefined(this._exchangeContractIfExists)) {
return this._exchangeContractIfExists;
}
- const web3ContractInstance = await this._instantiateContractIfExistsAsync(
+ const [abi, address] = await this._getContractAbiAndAddressFromArtifactsAsync(
artifacts.ExchangeArtifact,
this._contractAddressIfExists,
);
- const contractInstance = new ExchangeContract(web3ContractInstance, this._web3Wrapper.getContractDefaults());
+ const contractInstance = new ExchangeContract(this._web3Wrapper, abi, address);
this._exchangeContractIfExists = contractInstance;
return this._exchangeContractIfExists;
}
diff --git a/packages/0x.js/src/contract_wrappers/generated/.gitignore b/packages/0x.js/src/contract_wrappers/generated/.gitignore
index 834808b48..72e8ffc0d 100644
--- a/packages/0x.js/src/contract_wrappers/generated/.gitignore
+++ b/packages/0x.js/src/contract_wrappers/generated/.gitignore
@@ -1,6 +1 @@
-dummy_token.ts
-ether_token.ts
-exchange.ts
-token_registry.ts
-token_transfer_proxy.ts
-token.ts
+*
diff --git a/packages/0x.js/src/contract_wrappers/generated/base_contract.ts b/packages/0x.js/src/contract_wrappers/generated/base_contract.ts
deleted file mode 100644
index d8fac7eea..000000000
--- a/packages/0x.js/src/contract_wrappers/generated/base_contract.ts
+++ /dev/null
@@ -1,33 +0,0 @@
-import {TxData, TxDataPayable} from '@0xproject/types';
-import * as _ from 'lodash';
-import * as Web3 from 'web3';
-
-export class BaseContract {
- protected _web3ContractInstance: Web3.ContractInstance;
- protected _defaults: Partial<TxData>;
- protected async _applyDefaultsToTxDataAsync<T extends TxData|TxDataPayable>(
- txData: T,
- estimateGasAsync?: (txData: T) => Promise<number>,
- ): Promise<TxData> {
- // Gas amount sourced with the following priorities:
- // 1. Optional param passed in to public method call
- // 2. Global config passed in at library instantiation
- // 3. Gas estimate calculation + safety margin
- const removeUndefinedProperties = _.pickBy;
- const txDataWithDefaults = {
- ...removeUndefinedProperties(this._defaults),
- ...removeUndefinedProperties(txData as any),
- // HACK: TS can't prove that T is spreadable.
- // Awaiting https://github.com/Microsoft/TypeScript/pull/13288 to be merged
- };
- if (_.isUndefined(txDataWithDefaults.gas) && !_.isUndefined(estimateGasAsync)) {
- const estimatedGas = await estimateGasAsync(txData);
- txDataWithDefaults.gas = estimatedGas;
- }
- return txDataWithDefaults;
- }
- constructor(web3ContractInstance: Web3.ContractInstance, defaults: Partial<TxData>) {
- this._web3ContractInstance = web3ContractInstance;
- this._defaults = defaults;
- }
-}
diff --git a/packages/0x.js/src/contract_wrappers/token_registry_wrapper.ts b/packages/0x.js/src/contract_wrappers/token_registry_wrapper.ts
index f0ae5f33c..e1806c6f2 100644
--- a/packages/0x.js/src/contract_wrappers/token_registry_wrapper.ts
+++ b/packages/0x.js/src/contract_wrappers/token_registry_wrapper.ts
@@ -23,7 +23,7 @@ export class TokenRegistryWrapper extends ContractWrapper {
address: metadata[0],
name: metadata[1],
symbol: metadata[2],
- decimals: metadata[3].toNumber(),
+ decimals: metadata[3],
};
return token;
}
@@ -50,7 +50,8 @@ export class TokenRegistryWrapper extends ContractWrapper {
public async getTokenAddressesAsync(): Promise<string[]> {
const tokenRegistryContract = await this._getTokenRegistryContractAsync();
const addresses = await tokenRegistryContract.getTokenAddresses.callAsync();
- return addresses;
+ const lowerCaseAddresses = _.map(addresses, address => address.toLowerCase());
+ return lowerCaseAddresses;
}
/**
* Retrieves a token by address currently listed in the Token Registry smart contract
@@ -116,14 +117,11 @@ export class TokenRegistryWrapper extends ContractWrapper {
if (!_.isUndefined(this._tokenRegistryContractIfExists)) {
return this._tokenRegistryContractIfExists;
}
- const web3ContractInstance = await this._instantiateContractIfExistsAsync(
+ const [abi, address] = await this._getContractAbiAndAddressFromArtifactsAsync(
artifacts.TokenRegistryArtifact,
this._contractAddressIfExists,
);
- const contractInstance = new TokenRegistryContract(
- web3ContractInstance,
- this._web3Wrapper.getContractDefaults(),
- );
+ const contractInstance = new TokenRegistryContract(this._web3Wrapper, abi, address);
this._tokenRegistryContractIfExists = contractInstance;
return this._tokenRegistryContractIfExists;
}
diff --git a/packages/0x.js/src/contract_wrappers/token_transfer_proxy_wrapper.ts b/packages/0x.js/src/contract_wrappers/token_transfer_proxy_wrapper.ts
index f0cbf364d..211c7dfb4 100644
--- a/packages/0x.js/src/contract_wrappers/token_transfer_proxy_wrapper.ts
+++ b/packages/0x.js/src/contract_wrappers/token_transfer_proxy_wrapper.ts
@@ -59,14 +59,11 @@ export class TokenTransferProxyWrapper extends ContractWrapper {
if (!_.isUndefined(this._tokenTransferProxyContractIfExists)) {
return this._tokenTransferProxyContractIfExists;
}
- const web3ContractInstance = await this._instantiateContractIfExistsAsync(
+ const [abi, address] = await this._getContractAbiAndAddressFromArtifactsAsync(
artifacts.TokenTransferProxyArtifact,
this._contractAddressIfExists,
);
- const contractInstance = new TokenTransferProxyContract(
- web3ContractInstance,
- this._web3Wrapper.getContractDefaults(),
- );
+ const contractInstance = new TokenTransferProxyContract(this._web3Wrapper, abi, address);
this._tokenTransferProxyContractIfExists = contractInstance;
return this._tokenTransferProxyContractIfExists;
}
diff --git a/packages/0x.js/src/contract_wrappers/token_wrapper.ts b/packages/0x.js/src/contract_wrappers/token_wrapper.ts
index 11a7670c0..0f688cb71 100644
--- a/packages/0x.js/src/contract_wrappers/token_wrapper.ts
+++ b/packages/0x.js/src/contract_wrappers/token_wrapper.ts
@@ -51,7 +51,8 @@ export class TokenWrapper extends ContractWrapper {
const tokenContract = await this._getTokenContractAsync(normalizedTokenAddress);
const defaultBlock = _.isUndefined(methodOpts) ? undefined : methodOpts.defaultBlock;
- let balance = await tokenContract.balanceOf.callAsync(normalizedOwnerAddress, defaultBlock);
+ const txData = {};
+ let balance = await tokenContract.balanceOf.callAsync(normalizedOwnerAddress, txData, defaultBlock);
// Wrap BigNumbers returned from web3 with our own (later) version of BigNumber
balance = new BigNumber(balance);
return balance;
@@ -146,9 +147,11 @@ export class TokenWrapper extends ContractWrapper {
const tokenContract = await this._getTokenContractAsync(normalizedTokenAddress);
const defaultBlock = _.isUndefined(methodOpts) ? undefined : methodOpts.defaultBlock;
+ const txData = {};
let allowanceInBaseUnits = await tokenContract.allowance.callAsync(
normalizedOwnerAddress,
normalizedSpenderAddress,
+ txData,
defaultBlock,
);
// Wrap BigNumbers returned from web3 with our own (later) version of BigNumber
@@ -419,11 +422,11 @@ export class TokenWrapper extends ContractWrapper {
if (!_.isUndefined(tokenContract)) {
return tokenContract;
}
- const web3ContractInstance = await this._instantiateContractIfExistsAsync(
+ const [abi, address] = await this._getContractAbiAndAddressFromArtifactsAsync(
artifacts.TokenArtifact,
normalizedTokenAddress,
);
- const contractInstance = new TokenContract(web3ContractInstance, this._web3Wrapper.getContractDefaults());
+ const contractInstance = new TokenContract(this._web3Wrapper, abi, address);
tokenContract = contractInstance;
this._tokenContractsByAddress[normalizedTokenAddress] = tokenContract;
return tokenContract;
diff --git a/packages/0x.js/src/types.ts b/packages/0x.js/src/types.ts
index 0a3037258..2f17e30c2 100644
--- a/packages/0x.js/src/types.ts
+++ b/packages/0x.js/src/types.ts
@@ -127,7 +127,7 @@ export interface SignedOrder extends Order {
}
// [address, name, symbol, decimals, ipfsHash, swarmHash]
-export type TokenMetadata = [string, string, string, BigNumber, string, string];
+export type TokenMetadata = [string, string, string, number, string, string];
export interface Token {
name: string;
diff --git a/packages/0x.js/test/utils/fill_scenarios.ts b/packages/0x.js/test/utils/fill_scenarios.ts
index 1a61487f4..8b1308298 100644
--- a/packages/0x.js/test/utils/fill_scenarios.ts
+++ b/packages/0x.js/test/utils/fill_scenarios.ts
@@ -35,12 +35,8 @@ export class FillScenarios {
const web3Wrapper = (this._zeroEx as any)._web3Wrapper as Web3Wrapper;
for (const token of this._tokens) {
if (token.symbol !== 'ZRX' && token.symbol !== 'WETH') {
- const contractInstance = web3Wrapper.getContractInstance(
- artifacts.DummyTokenArtifact.abi,
- token.address,
- );
const defaults = {};
- const dummyToken = new DummyTokenContract(contractInstance, defaults);
+ const dummyToken = new DummyTokenContract(web3Wrapper, artifacts.DummyTokenArtifact.abi, token.address);
const tokenSupply = ZeroEx.toBaseUnitAmount(INITIAL_COINBASE_TOKEN_SUPPLY_IN_UNITS, token.decimals);
const txHash = await dummyToken.setBalance.sendTransactionAsync(this._coinbase, tokenSupply, {
from: this._coinbase,
diff --git a/packages/0x.js/tsconfig.json b/packages/0x.js/tsconfig.json
index 117f51e83..a6b5c71c2 100644
--- a/packages/0x.js/tsconfig.json
+++ b/packages/0x.js/tsconfig.json
@@ -9,6 +9,7 @@
"./test/**/*",
"../../node_modules/types-bn/index.d.ts",
"../../node_modules/types-ethereumjs-util/index.d.ts",
+ "../../node_modules/ethers-typescript-typings/index.d.ts",
"../../node_modules/web3-typescript-typings/index.d.ts",
"../../node_modules/chai-typescript-typings/index.d.ts",
"../../node_modules/chai-as-promised-typescript-typings/index.d.ts"