aboutsummaryrefslogtreecommitdiffstats
path: root/packages/0x.js
diff options
context:
space:
mode:
authorLeonid Logvinov <logvinov.leon@gmail.com>2018-02-28 04:01:12 +0800
committerLeonid Logvinov <logvinov.leon@gmail.com>2018-02-28 04:07:58 +0800
commit8fe844bcc9e4298cc3ced58c1abcee78de4193b3 (patch)
tree6b3fb63fb53fd6d51287b9b8a599c3eae5f46057 /packages/0x.js
parenta0390956a91b2e15052d1b5ca43ef6d85d64234e (diff)
downloaddexon-0x-contracts-8fe844bcc9e4298cc3ced58c1abcee78de4193b3.tar
dexon-0x-contracts-8fe844bcc9e4298cc3ced58c1abcee78de4193b3.tar.gz
dexon-0x-contracts-8fe844bcc9e4298cc3ced58c1abcee78de4193b3.tar.bz2
dexon-0x-contracts-8fe844bcc9e4298cc3ced58c1abcee78de4193b3.tar.lz
dexon-0x-contracts-8fe844bcc9e4298cc3ced58c1abcee78de4193b3.tar.xz
dexon-0x-contracts-8fe844bcc9e4298cc3ced58c1abcee78de4193b3.tar.zst
dexon-0x-contracts-8fe844bcc9e4298cc3ced58c1abcee78de4193b3.zip
Move BaseContract to web3Wrapper
Diffstat (limited to 'packages/0x.js')
-rw-r--r--packages/0x.js/package.json1
-rw-r--r--packages/0x.js/src/contract_wrappers/generated/.gitignore7
-rw-r--r--packages/0x.js/src/contract_wrappers/generated/base_contract.ts70
3 files changed, 1 insertions, 77 deletions
diff --git a/packages/0x.js/package.json b/packages/0x.js/package.json
index 92710ad2d..f8f4f064c 100644
--- a/packages/0x.js/package.json
+++ b/packages/0x.js/package.json
@@ -92,7 +92,6 @@
"ethereumjs-abi": "^0.6.4",
"ethereumjs-blockstream": "^2.0.6",
"ethereumjs-util": "^5.1.1",
- "ethers-contracts": "^2.2.1",
"js-sha3": "^0.7.0",
"lodash": "^4.17.4",
"uuid": "^3.1.0",
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 9086fe7b3..000000000
--- a/packages/0x.js/src/contract_wrappers/generated/base_contract.ts
+++ /dev/null
@@ -1,70 +0,0 @@
-import { TxData, TxDataPayable } from '@0xproject/types';
-import { Web3Wrapper } from '@0xproject/web3-wrapper';
-import * as ethersContracts from 'ethers-contracts';
-import * as _ from 'lodash';
-import * as Web3 from 'web3';
-
-export class BaseContract {
- protected _ethersInterface: ethersContracts.Interface;
- protected _web3Wrapper: Web3Wrapper;
- public abi: Web3.ContractAbi;
- public address: string;
- protected static _transformABIData(
- abis: Web3.DataItem[],
- values: any[],
- transformation: (type: string, value: any) => any,
- ): any {
- return _.map(values, (value: any, i: number) =>
- BaseContract._transformTypedData(abis[i].type, value, transformation),
- );
- }
- protected static _lowercaseAddress(type: string, value: string): string {
- return type === 'address' ? value.toLowerCase() : value;
- }
- protected static _bigNumberToString(type: string, value: string): string {
- return _.isObject(value) && (value as any).isBigNumber ? value.toString() : value;
- }
- private static _transformTypedData(
- type: string,
- values: any,
- transformation: (type: string, value: any) => any,
- ): any {
- const trailingArrayRegex = /\[\d*\]$/;
- if (type.match(trailingArrayRegex)) {
- const arrayItemType = type.replace(trailingArrayRegex, '');
- return _.map(values, value =>
- this._transformTypedData(arrayItemType, value, transformation),
- );
- } else {
- return transformation(type, values);
- }
- }
- protected async _applyDefaultsToTxDataAsync<T extends Partial<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 = {
- to: this.address,
- ...removeUndefinedProperties(this._web3Wrapper.getContractDefaults()),
- ...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(web3Wrapper: Web3Wrapper, abi: Web3.ContractAbi, address: string) {
- this._web3Wrapper = web3Wrapper;
- this.abi = abi;
- this.address = address;
- this._ethersInterface = new ethersContracts.Interface(abi);
- }
-}