diff options
author | Leonid Logvinov <logvinov.leon@gmail.com> | 2018-07-03 21:04:58 +0800 |
---|---|---|
committer | Leonid Logvinov <logvinov.leon@gmail.com> | 2018-07-05 21:56:32 +0800 |
commit | 714f9ed207305c77ca2ff22bc4c4624822d7d31c (patch) | |
tree | 73e0352b16732013ddde8aa1985ffdc74eedad82 /packages/contract-wrappers/src/contract_wrappers.ts | |
parent | ccccaf8e1284ec2065e822b1210c1544de407e76 (diff) | |
download | dexon-0x-contracts-714f9ed207305c77ca2ff22bc4c4624822d7d31c.tar.gz dexon-0x-contracts-714f9ed207305c77ca2ff22bc4c4624822d7d31c.tar.zst dexon-0x-contracts-714f9ed207305c77ca2ff22bc4c4624822d7d31c.zip |
Add Exchange contract wrapper
Diffstat (limited to 'packages/contract-wrappers/src/contract_wrappers.ts')
-rw-r--r-- | packages/contract-wrappers/src/contract_wrappers.ts | 40 |
1 files changed, 37 insertions, 3 deletions
diff --git a/packages/contract-wrappers/src/contract_wrappers.ts b/packages/contract-wrappers/src/contract_wrappers.ts index 72c953421..8010242c5 100644 --- a/packages/contract-wrappers/src/contract_wrappers.ts +++ b/packages/contract-wrappers/src/contract_wrappers.ts @@ -2,12 +2,15 @@ import { Web3Wrapper } from '@0xproject/web3-wrapper'; import { Provider } from 'ethereum-types'; import * as _ from 'lodash'; +import { constants } from './utils/constants'; + import { artifacts } from './artifacts'; import { ERC20ProxyWrapper } from './contract_wrappers/erc20_proxy_wrapper'; import { ERC20TokenWrapper } from './contract_wrappers/erc20_token_wrapper'; import { ERC721ProxyWrapper } from './contract_wrappers/erc721_proxy_wrapper'; import { ERC721TokenWrapper } from './contract_wrappers/erc721_token_wrapper'; import { EtherTokenWrapper } from './contract_wrappers/ether_token_wrapper'; +import { ExchangeWrapper } from './contract_wrappers/exchange_wrapper'; import { ContractWrappersConfigSchema } from './schemas/contract_wrappers_config_schema'; import { contractWrappersPrivateNetworkConfigSchema } from './schemas/contract_wrappers_private_network_config_schema'; import { contractWrappersPublicNetworkConfigSchema } from './schemas/contract_wrappers_public_network_config_schema'; @@ -18,6 +21,10 @@ import { assert } from './utils/assert'; */ export class ContractWrappers { /** + * An instance of the ExchangeWrapper class containing methods for interacting with the 0x Exchange smart contract. + */ + public exchange: ExchangeWrapper; + /** * An instance of the ERC20TokenWrapper class containing methods for interacting with any ERC20 token smart contract. */ public erc20Token: ERC20TokenWrapper; @@ -63,15 +70,40 @@ export class ContractWrappers { _.forEach(abiArrays, abi => { this._web3Wrapper.abiDecoder.addABI(abi); }); + const blockPollingIntervalMs = _.isUndefined(config.blockPollingIntervalMs) + ? constants.DEFAULT_BLOCK_POLLING_INTERVAL + : config.blockPollingIntervalMs; this.erc20Proxy = new ERC20ProxyWrapper(this._web3Wrapper, config.networkId, config.erc20ProxyContractAddress); this.erc721Proxy = new ERC721ProxyWrapper( this._web3Wrapper, config.networkId, config.erc721ProxyContractAddress, ); - this.erc20Token = new ERC20TokenWrapper(this._web3Wrapper, config.networkId, this.erc20Proxy); - this.erc721Token = new ERC721TokenWrapper(this._web3Wrapper, config.networkId, this.erc721Proxy); - this.etherToken = new EtherTokenWrapper(this._web3Wrapper, config.networkId, this.erc20Token); + this.erc20Token = new ERC20TokenWrapper( + this._web3Wrapper, + config.networkId, + this.erc20Proxy, + blockPollingIntervalMs, + ); + this.erc721Token = new ERC721TokenWrapper( + this._web3Wrapper, + config.networkId, + this.erc721Proxy, + blockPollingIntervalMs, + ); + this.etherToken = new EtherTokenWrapper( + this._web3Wrapper, + config.networkId, + this.erc20Token, + blockPollingIntervalMs, + ); + this.exchange = new ExchangeWrapper( + this._web3Wrapper, + config.networkId, + config.exchangeContractAddress, + config.zrxContractAddress, + blockPollingIntervalMs, + ); } /** * Sets a new web3 provider for 0x.js. Updating the provider will stop all @@ -81,6 +113,8 @@ export class ContractWrappers { */ public setProvider(provider: Provider, networkId: number): void { this._web3Wrapper.setProvider(provider); + (this.exchange as any)._invalidateContractInstances(); + (this.exchange as any)._setNetworkId(networkId); (this.erc20Token as any)._invalidateContractInstances(); (this.erc20Token as any)._setNetworkId(networkId); (this.erc20Proxy as any)._invalidateContractInstance(); |