aboutsummaryrefslogtreecommitdiffstats
path: root/packages/contract-wrappers/src/contract_wrappers
diff options
context:
space:
mode:
Diffstat (limited to 'packages/contract-wrappers/src/contract_wrappers')
-rw-r--r--packages/contract-wrappers/src/contract_wrappers/contract_wrapper.ts8
-rw-r--r--packages/contract-wrappers/src/contract_wrappers/erc20_proxy_wrapper.ts13
-rw-r--r--packages/contract-wrappers/src/contract_wrappers/erc20_token_wrapper.ts10
-rw-r--r--packages/contract-wrappers/src/contract_wrappers/erc721_proxy_wrapper.ts13
-rw-r--r--packages/contract-wrappers/src/contract_wrappers/erc721_token_wrapper.ts10
-rw-r--r--packages/contract-wrappers/src/contract_wrappers/ether_token_wrapper.ts9
-rw-r--r--packages/contract-wrappers/src/contract_wrappers/exchange_wrapper.ts23
-rw-r--r--packages/contract-wrappers/src/contract_wrappers/forwarder_wrapper.ts36
-rw-r--r--packages/contract-wrappers/src/contract_wrappers/order_validator_wrapper.ts12
9 files changed, 96 insertions, 38 deletions
diff --git a/packages/contract-wrappers/src/contract_wrappers/contract_wrapper.ts b/packages/contract-wrappers/src/contract_wrappers/contract_wrapper.ts
index aed9d44db..30095e002 100644
--- a/packages/contract-wrappers/src/contract_wrappers/contract_wrapper.ts
+++ b/packages/contract-wrappers/src/contract_wrappers/contract_wrapper.ts
@@ -1,3 +1,4 @@
+import { ContractAddresses, getContractAddressesForNetwork } from '@0xproject/contract-addresses';
import { AbiDecoder, intervalUtils, logUtils } from '@0xproject/utils';
import { marshaller, Web3Wrapper } from '@0xproject/web3-wrapper';
import {
@@ -25,6 +26,7 @@ import { filterUtils } from '../utils/filter_utils';
export abstract class ContractWrapper {
public abstract abi: ContractAbi;
+ protected _networkId: number;
protected _web3Wrapper: Web3Wrapper;
private _blockAndLogStreamerIfExists: BlockAndLogStreamer<Block, Log> | undefined;
private _blockPollingIntervalMs: number;
@@ -42,8 +44,9 @@ export abstract class ContractWrapper {
logUtils.warn(err);
}
}
- constructor(web3Wrapper: Web3Wrapper, blockPollingIntervalMs?: number) {
+ constructor(web3Wrapper: Web3Wrapper, networkId: number, blockPollingIntervalMs?: number) {
this._web3Wrapper = web3Wrapper;
+ this._networkId = networkId;
this._blockPollingIntervalMs = _.isUndefined(blockPollingIntervalMs)
? constants.DEFAULT_BLOCK_POLLING_INTERVAL
: blockPollingIntervalMs;
@@ -109,6 +112,9 @@ export abstract class ContractWrapper {
const logWithDecodedArgs = abiDecoder.tryToDecodeLogOrNoop(log);
return logWithDecodedArgs;
}
+ protected _getDefaultContractAddresses(): ContractAddresses {
+ return getContractAddressesForNetwork(this._networkId);
+ }
private _onLogStateChanged<ArgsType extends ContractEventArgs>(isRemoved: boolean, rawLog: RawLogEntry): void {
const log: LogEntry = marshaller.unmarshalLog(rawLog);
_.forEach(this._filters, (filter: FilterObject, filterToken: string) => {
diff --git a/packages/contract-wrappers/src/contract_wrappers/erc20_proxy_wrapper.ts b/packages/contract-wrappers/src/contract_wrappers/erc20_proxy_wrapper.ts
index 205a5ed10..605646256 100644
--- a/packages/contract-wrappers/src/contract_wrappers/erc20_proxy_wrapper.ts
+++ b/packages/contract-wrappers/src/contract_wrappers/erc20_proxy_wrapper.ts
@@ -19,13 +19,14 @@ export class ERC20ProxyWrapper extends ContractWrapper {
/**
* Instantiate ERC20ProxyWrapper
* @param web3Wrapper Web3Wrapper instance to use
- * @param address The address of the ERC20Proxy contract
+ * @param networkId Desired networkId
+ * @param address (Optional) The address of the ERC20Proxy contract. If
+ * undefined, will default to the known address corresponding to the
+ * networkId.
*/
- // TODO(albrow): Make address optional and default to looking up the address
- // based in a hard-coded mapping based on web3Wrapper network id.
- constructor(web3Wrapper: Web3Wrapper, address: string) {
- super(web3Wrapper);
- this.address = address;
+ constructor(web3Wrapper: Web3Wrapper, networkId: number, address?: string) {
+ super(web3Wrapper, networkId);
+ this.address = _.isUndefined(address) ? this._getDefaultContractAddresses().erc20Proxy : address;
}
/**
* Get the 4 bytes ID of this asset proxy
diff --git a/packages/contract-wrappers/src/contract_wrappers/erc20_token_wrapper.ts b/packages/contract-wrappers/src/contract_wrappers/erc20_token_wrapper.ts
index 68928e71f..2db0165bc 100644
--- a/packages/contract-wrappers/src/contract_wrappers/erc20_token_wrapper.ts
+++ b/packages/contract-wrappers/src/contract_wrappers/erc20_token_wrapper.ts
@@ -37,11 +37,17 @@ export class ERC20TokenWrapper extends ContractWrapper {
/**
* Instantiate ERC20TokenWrapper
* @param web3Wrapper Web3Wrapper instance to use
+ * @param networkId Desired networkId
* @param erc20ProxyWrapper The ERC20ProxyWrapper instance to use
* @param blockPollingIntervalMs The block polling interval to use for active subscriptions
*/
- constructor(web3Wrapper: Web3Wrapper, erc20ProxyWrapper: ERC20ProxyWrapper, blockPollingIntervalMs?: number) {
- super(web3Wrapper, blockPollingIntervalMs);
+ constructor(
+ web3Wrapper: Web3Wrapper,
+ networkId: number,
+ erc20ProxyWrapper: ERC20ProxyWrapper,
+ blockPollingIntervalMs?: number,
+ ) {
+ super(web3Wrapper, networkId, blockPollingIntervalMs);
this._tokenContractsByAddress = {};
this._erc20ProxyWrapper = erc20ProxyWrapper;
}
diff --git a/packages/contract-wrappers/src/contract_wrappers/erc721_proxy_wrapper.ts b/packages/contract-wrappers/src/contract_wrappers/erc721_proxy_wrapper.ts
index 963d5b40f..b1b026a3a 100644
--- a/packages/contract-wrappers/src/contract_wrappers/erc721_proxy_wrapper.ts
+++ b/packages/contract-wrappers/src/contract_wrappers/erc721_proxy_wrapper.ts
@@ -19,13 +19,14 @@ export class ERC721ProxyWrapper extends ContractWrapper {
/**
* Instantiate ERC721ProxyWrapper
* @param web3Wrapper Web3Wrapper instance to use
- * @param address The address of the ERC721Proxy contract
+ * @param networkId Desired networkId
+ * @param address (Optional) The address of the ERC721Proxy contract. If
+ * undefined, will default to the known address corresponding to the
+ * networkId.
*/
- // TODO(albrow): Make address optional and default to looking up the address
- // based in a hard-coded mapping based on web3Wrapper network id.
- constructor(web3Wrapper: Web3Wrapper, address: string) {
- super(web3Wrapper);
- this.address = address;
+ constructor(web3Wrapper: Web3Wrapper, networkId: number, address?: string) {
+ super(web3Wrapper, networkId);
+ this.address = _.isUndefined(address) ? this._getDefaultContractAddresses().erc721Proxy : address;
}
/**
* Get the 4 bytes ID of this asset proxy
diff --git a/packages/contract-wrappers/src/contract_wrappers/erc721_token_wrapper.ts b/packages/contract-wrappers/src/contract_wrappers/erc721_token_wrapper.ts
index 3d58908d8..b18692964 100644
--- a/packages/contract-wrappers/src/contract_wrappers/erc721_token_wrapper.ts
+++ b/packages/contract-wrappers/src/contract_wrappers/erc721_token_wrapper.ts
@@ -36,11 +36,17 @@ export class ERC721TokenWrapper extends ContractWrapper {
/**
* Instantiate ERC721TokenWrapper
* @param web3Wrapper Web3Wrapper instance to use
+ * @param networkId Desired networkId
* @param erc721ProxyWrapper The ERC721ProxyWrapper instance to use
* @param blockPollingIntervalMs The block polling interval to use for active subscriptions
*/
- constructor(web3Wrapper: Web3Wrapper, erc721ProxyWrapper: ERC721ProxyWrapper, blockPollingIntervalMs?: number) {
- super(web3Wrapper, blockPollingIntervalMs);
+ constructor(
+ web3Wrapper: Web3Wrapper,
+ networkId: number,
+ erc721ProxyWrapper: ERC721ProxyWrapper,
+ blockPollingIntervalMs?: number,
+ ) {
+ super(web3Wrapper, networkId, blockPollingIntervalMs);
this._tokenContractsByAddress = {};
this._erc721ProxyWrapper = erc721ProxyWrapper;
}
diff --git a/packages/contract-wrappers/src/contract_wrappers/ether_token_wrapper.ts b/packages/contract-wrappers/src/contract_wrappers/ether_token_wrapper.ts
index a6f2fd81e..2586401bc 100644
--- a/packages/contract-wrappers/src/contract_wrappers/ether_token_wrapper.ts
+++ b/packages/contract-wrappers/src/contract_wrappers/ether_token_wrapper.ts
@@ -31,8 +31,13 @@ export class EtherTokenWrapper extends ContractWrapper {
* @param erc20TokenWrapper The ERC20TokenWrapper instance to use
* @param blockPollingIntervalMs The block polling interval to use for active subscriptions
*/
- constructor(web3Wrapper: Web3Wrapper, erc20TokenWrapper: ERC20TokenWrapper, blockPollingIntervalMs?: number) {
- super(web3Wrapper, blockPollingIntervalMs);
+ constructor(
+ web3Wrapper: Web3Wrapper,
+ networkId: number,
+ erc20TokenWrapper: ERC20TokenWrapper,
+ blockPollingIntervalMs?: number,
+ ) {
+ super(web3Wrapper, networkId, blockPollingIntervalMs);
this._erc20TokenWrapper = erc20TokenWrapper;
}
/**
diff --git a/packages/contract-wrappers/src/contract_wrappers/exchange_wrapper.ts b/packages/contract-wrappers/src/contract_wrappers/exchange_wrapper.ts
index 6b3694bc5..b185b7e0c 100644
--- a/packages/contract-wrappers/src/contract_wrappers/exchange_wrapper.ts
+++ b/packages/contract-wrappers/src/contract_wrappers/exchange_wrapper.ts
@@ -50,26 +50,33 @@ export class ExchangeWrapper extends ContractWrapper {
/**
* Instantiate ExchangeWrapper
* @param web3Wrapper Web3Wrapper instance to use.
+ * @param networkId Desired networkId.
* @param erc20TokenWrapper ERC20TokenWrapper instance to use.
* @param erc721TokenWrapper ERC721TokenWrapper instance to use.
- * @param address The address of the Exchange contract.
- * @param zrxTokenAddress The address of the ZRX Token contract.
+ * @param address (Optional) The address of the Exchange contract. If
+ * undefined, will default to the known address corresponding to the
+ * networkId.
+ * @param zrxTokenAddress (Optional) The address of the ZRXToken contract.
+ * If undefined, will default to the known address corresponding to the
+ * networkId.
* @param blockPollingIntervalMs The block polling interval to use for active subscriptions.
*/
constructor(
web3Wrapper: Web3Wrapper,
+ networkId: number,
erc20TokenWrapper: ERC20TokenWrapper,
erc721TokenWrapper: ERC721TokenWrapper,
- // TODO(albrow): Make address optional?
- address: string,
- zrxTokenAddress: string,
+ address?: string,
+ zrxTokenAddress?: string,
blockPollingIntervalMs?: number,
) {
- super(web3Wrapper, blockPollingIntervalMs);
+ super(web3Wrapper, networkId, blockPollingIntervalMs);
this._erc20TokenWrapper = erc20TokenWrapper;
this._erc721TokenWrapper = erc721TokenWrapper;
- this.address = address;
- this.zrxTokenAddress = zrxTokenAddress;
+ this.address = _.isUndefined(address) ? this._getDefaultContractAddresses().exchange : address;
+ this.zrxTokenAddress = _.isUndefined(zrxTokenAddress)
+ ? this._getDefaultContractAddresses().zrxToken
+ : zrxTokenAddress;
}
/**
* Retrieve the address of an asset proxy by signature.
diff --git a/packages/contract-wrappers/src/contract_wrappers/forwarder_wrapper.ts b/packages/contract-wrappers/src/contract_wrappers/forwarder_wrapper.ts
index 22fc916e2..b72a77e8b 100644
--- a/packages/contract-wrappers/src/contract_wrappers/forwarder_wrapper.ts
+++ b/packages/contract-wrappers/src/contract_wrappers/forwarder_wrapper.ts
@@ -27,12 +27,36 @@ export class ForwarderWrapper extends ContractWrapper {
public zrxTokenAddress: string;
public etherTokenAddress: string;
private _forwarderContractIfExists?: ForwarderContract;
- // TODO(albrow): Make addresses optional?
- constructor(web3Wrapper: Web3Wrapper, address: string, zrxTokenAddress: string, etherTokenAddress: string) {
- super(web3Wrapper);
- this.address = address;
- this.zrxTokenAddress = zrxTokenAddress;
- this.etherTokenAddress = etherTokenAddress;
+
+ /**
+ * Instantiate ForwarderWrapper
+ * @param web3Wrapper Web3Wrapper instance to use.
+ * @param networkId Desired networkId.
+ * @param address (Optional) The address of the Exchange contract. If
+ * undefined, will default to the known address corresponding to the
+ * networkId.
+ * @param zrxTokenAddress (Optional) The address of the ZRXToken contract.
+ * If undefined, will default to the known address corresponding to the
+ * networkId.
+ * @param etherTokenAddress (Optional) The address of a WETH (Ether token)
+ * contract. If undefined, will default to the known address corresponding
+ * to the networkId.
+ */
+ constructor(
+ web3Wrapper: Web3Wrapper,
+ networkId: number,
+ address?: string,
+ zrxTokenAddress?: string,
+ etherTokenAddress?: string,
+ ) {
+ super(web3Wrapper, networkId);
+ this.address = _.isUndefined(address) ? this._getDefaultContractAddresses().exchange : address;
+ this.zrxTokenAddress = _.isUndefined(zrxTokenAddress)
+ ? this._getDefaultContractAddresses().zrxToken
+ : zrxTokenAddress;
+ this.etherTokenAddress = _.isUndefined(etherTokenAddress)
+ ? this._getDefaultContractAddresses().etherToken
+ : etherTokenAddress;
}
/**
* Purchases as much of orders' makerAssets as possible by selling up to 95% of transaction's ETH value.
diff --git a/packages/contract-wrappers/src/contract_wrappers/order_validator_wrapper.ts b/packages/contract-wrappers/src/contract_wrappers/order_validator_wrapper.ts
index cb67d57f7..b7bdfb149 100644
--- a/packages/contract-wrappers/src/contract_wrappers/order_validator_wrapper.ts
+++ b/packages/contract-wrappers/src/contract_wrappers/order_validator_wrapper.ts
@@ -22,12 +22,14 @@ export class OrderValidatorWrapper extends ContractWrapper {
/**
* Instantiate OrderValidatorWrapper
* @param web3Wrapper Web3Wrapper instance to use.
- * @param address The address of the OrderValidator contract.
+ * @param networkId Desired networkId.
+ * @param address (Optional) The address of the OrderValidator contract. If
+ * undefined, will default to the known address corresponding to the
+ * networkId.
*/
- // TODO(albrow): Make address optional?
- constructor(web3Wrapper: Web3Wrapper, address: string) {
- super(web3Wrapper);
- this.address = address;
+ constructor(web3Wrapper: Web3Wrapper, networkId: number, address?: string) {
+ super(web3Wrapper, networkId);
+ this.address = _.isUndefined(address) ? this._getDefaultContractAddresses().exchange : address;
}
/**
* Get an object conforming to OrderAndTraderInfo containing on-chain information of the provided order and address