aboutsummaryrefslogtreecommitdiffstats
path: root/src/0x.ts
diff options
context:
space:
mode:
authorLeonid <logvinov.leon@gmail.com>2017-09-20 20:59:48 +0800
committerGitHub <noreply@github.com>2017-09-20 20:59:48 +0800
commitd424933d70a0a6a210b19960451ef2796844c8d8 (patch)
tree349592a214b320b9a60e2775093639fe9ad6c278 /src/0x.ts
parentfe9f692a4f472e5decbda96aad6afaf98c10d850 (diff)
parent91679caf936d3b3df369b2339c55468b222c9a16 (diff)
downloaddexon-sol-tools-d424933d70a0a6a210b19960451ef2796844c8d8.tar
dexon-sol-tools-d424933d70a0a6a210b19960451ef2796844c8d8.tar.gz
dexon-sol-tools-d424933d70a0a6a210b19960451ef2796844c8d8.tar.bz2
dexon-sol-tools-d424933d70a0a6a210b19960451ef2796844c8d8.tar.lz
dexon-sol-tools-d424933d70a0a6a210b19960451ef2796844c8d8.tar.xz
dexon-sol-tools-d424933d70a0a6a210b19960451ef2796844c8d8.tar.zst
dexon-sol-tools-d424933d70a0a6a210b19960451ef2796844c8d8.zip
Merge pull request #165 from 0xProject/feature/configurable-addresses
Allow users to pass contract addresses as a config
Diffstat (limited to 'src/0x.ts')
-rw-r--r--src/0x.ts35
1 files changed, 30 insertions, 5 deletions
diff --git a/src/0x.ts b/src/0x.ts
index 5d5604780..e6fdf68e1 100644
--- a/src/0x.ts
+++ b/src/0x.ts
@@ -32,6 +32,7 @@ import {
TransactionReceiptWithDecodedLogs,
LogWithDecodedArgs,
} from './types';
+import {zeroExConfigSchema} from './schemas/zero_ex_config_schema';
// Customize our BigNumber instances
bigNumberConfigs.configure();
@@ -180,6 +181,9 @@ export class ZeroEx {
*/
constructor(provider: Web3Provider, config?: ZeroExConfig) {
assert.isWeb3Provider('provider', provider);
+ if (!_.isUndefined(config)) {
+ assert.doesConformToSchema('config', config, zeroExConfigSchema);
+ }
if (_.isUndefined((provider as any).sendAsync)) {
// Web3@1.0 provider doesn't support synchronous http requests,
// so it only has an async `send` method, instead of a `send` and `sendAsync` in web3@0.x.x`
@@ -194,11 +198,22 @@ export class ZeroEx {
gasPrice,
};
this._web3Wrapper = new Web3Wrapper(provider, defaults);
- this.token = new TokenWrapper(this._web3Wrapper);
- this.proxy = new TokenTransferProxyWrapper(this._web3Wrapper);
- this.exchange = new ExchangeWrapper(this._web3Wrapper, this.token);
- this.tokenRegistry = new TokenRegistryWrapper(this._web3Wrapper);
- this.etherToken = new EtherTokenWrapper(this._web3Wrapper, this.token);
+ this.token = new TokenWrapper(
+ this._web3Wrapper,
+ this._getTokenTransferProxyAddressAsync.bind(this),
+ );
+ const exchageContractAddressIfExists = _.isUndefined(config) ? undefined : config.exchangeContractAddress;
+ this.exchange = new ExchangeWrapper(this._web3Wrapper, this.token, exchageContractAddressIfExists);
+ this.proxy = new TokenTransferProxyWrapper(
+ this._web3Wrapper,
+ this._getTokenTransferProxyAddressAsync.bind(this),
+ );
+ const tokenRegistryContractAddressIfExists = _.isUndefined(config) ?
+ undefined :
+ config.tokenRegistryContractAddress;
+ this.tokenRegistry = new TokenRegistryWrapper(this._web3Wrapper, tokenRegistryContractAddressIfExists);
+ const etherTokenContractAddressIfExists = _.isUndefined(config) ? undefined : config.etherTokenContractAddress;
+ this.etherToken = new EtherTokenWrapper(this._web3Wrapper, this.token, etherTokenContractAddressIfExists);
}
/**
* Sets a new web3 provider for 0x.js. Updating the provider will stop all
@@ -306,4 +321,14 @@ export class ZeroEx {
});
return txReceiptPromise;
}
+ /*
+ * HACK: `TokenWrapper` needs a token transfer proxy address. `TokenTransferProxy` address is fetched from
+ * an `ExchangeWrapper`. `ExchangeWrapper` needs `TokenWrapper` to validate orders, creating a dependency cycle.
+ * In order to break this - we create this function here and pass it as a parameter to the `TokenWrapper`
+ * and `ProxyWrapper`.
+ */
+ private async _getTokenTransferProxyAddressAsync(): Promise<string> {
+ const tokenTransferProxyAddress = await (this.exchange as any)._getTokenTransferProxyAddressAsync();
+ return tokenTransferProxyAddress;
+ }
}