aboutsummaryrefslogtreecommitdiffstats
path: root/packages
diff options
context:
space:
mode:
authorAlex Browne <stephenalexbrowne@gmail.com>2018-10-10 14:10:33 +0800
committerAlex Browne <stephenalexbrowne@gmail.com>2018-10-16 04:38:33 +0800
commit1e9ea09f087c7b3120e758d931a88812b655da08 (patch)
treeb0da3efc0733d566356ed2a938d18eb08192f674 /packages
parentfa346d94613a43034e1cdaf6b7a3d2de270c58fc (diff)
downloaddexon-0x-contracts-1e9ea09f087c7b3120e758d931a88812b655da08.tar.gz
dexon-0x-contracts-1e9ea09f087c7b3120e758d931a88812b655da08.tar.zst
dexon-0x-contracts-1e9ea09f087c7b3120e758d931a88812b655da08.zip
Introduce new contract-addresses package and use it everywhere
Diffstat (limited to 'packages')
-rw-r--r--packages/asset-buyer/package.json1
-rw-r--r--packages/asset-buyer/src/asset_buyer.ts13
-rw-r--r--packages/contract-addresses/package.json37
-rw-r--r--packages/contract-addresses/src/index.ts64
-rw-r--r--packages/contract-addresses/tsconfig.json8
-rw-r--r--packages/contract-addresses/tslint.json3
-rw-r--r--packages/contract-wrappers/package.json1
-rw-r--r--packages/contract-wrappers/src/contract_wrappers.ts50
-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
-rw-r--r--packages/contract-wrappers/src/types.ts12
-rw-r--r--packages/contract-wrappers/test/erc20_wrapper_test.ts3
-rw-r--r--packages/contract-wrappers/test/ether_token_wrapper_test.ts4
-rw-r--r--packages/contract-wrappers/test/order_validator_wrapper_test.ts3
-rw-r--r--packages/contract-wrappers/test/utils/migrate.ts2
-rw-r--r--packages/contracts/src/artifacts/index.ts1
-rw-r--r--packages/contracts/src/wrappers/index.ts1
-rw-r--r--packages/migrations/package.json1
-rw-r--r--packages/migrations/src/migration.ts2
-rw-r--r--packages/order-watcher/package.json1
-rw-r--r--packages/order-watcher/src/order_watcher/order_watcher.ts17
-rw-r--r--packages/order-watcher/test/utils/migrate.ts2
-rw-r--r--packages/testnet-faucets/package.json1
-rw-r--r--packages/testnet-faucets/src/ts/handler.ts13
-rw-r--r--packages/website/package.json1
-rw-r--r--packages/website/ts/blockchain.ts13
33 files changed, 276 insertions, 112 deletions
diff --git a/packages/asset-buyer/package.json b/packages/asset-buyer/package.json
index 8c8f3c92c..c2797c6ce 100644
--- a/packages/asset-buyer/package.json
+++ b/packages/asset-buyer/package.json
@@ -37,6 +37,7 @@
"dependencies": {
"@0xproject/assert": "^1.0.13",
"@0xproject/connect": "^3.0.1",
+ "@0xproject/contract-addresses": "^1.0.0",
"@0xproject/contract-wrappers": "^2.0.2",
"@0xproject/json-schemas": "^1.0.7",
"@0xproject/order-utils": "^1.0.7",
diff --git a/packages/asset-buyer/src/asset_buyer.ts b/packages/asset-buyer/src/asset_buyer.ts
index 5863ce5d5..f7b59c1a1 100644
--- a/packages/asset-buyer/src/asset_buyer.ts
+++ b/packages/asset-buyer/src/asset_buyer.ts
@@ -1,3 +1,4 @@
+import { getContractAddressesForNetwork } from '@0xproject/contract-addresses';
import { ContractWrappers } from '@0xproject/contract-wrappers';
import { schemas } from '@0xproject/json-schemas';
import { SignedOrder } from '@0xproject/order-utils';
@@ -109,17 +110,7 @@ export class AssetBuyer {
this.expiryBufferSeconds = expiryBufferSeconds;
this._contractWrappers = new ContractWrappers(this.provider, {
networkId,
- // TODO(albrow): Load in real contract addresses here.
- contractAddresses: {
- erc20Proxy: '',
- erc721Proxy: '',
- zrxToken: '',
- etherToken: '',
- exchange: '',
- assetProxyOwner: '',
- forwarder: '',
- orderValidator: '',
- },
+ contractAddresses: getContractAddressesForNetwork(networkId),
});
}
/**
diff --git a/packages/contract-addresses/package.json b/packages/contract-addresses/package.json
new file mode 100644
index 000000000..8875430c7
--- /dev/null
+++ b/packages/contract-addresses/package.json
@@ -0,0 +1,37 @@
+{
+ "name": "@0xproject/contract-addresses",
+ "version": "1.0.0",
+ "engines": {
+ "node": ">=6.12"
+ },
+ "description": "Addresses of deployed 0x contracts on Ethereum mainnet and testnets",
+ "main": "lib/src/index.js",
+ "directories": {
+ "test": "test"
+ },
+ "scripts": {
+ "build": "yarn tsc -b",
+ "build:ci": "yarn build",
+ "clean": "shx rm -rf lib"
+ },
+ "repository": {
+ "type": "git",
+ "url": "https://github.com/0xProject/0x-monorepo.git"
+ },
+ "license": "Apache-2.0",
+ "bugs": {
+ "url": "https://github.com/0xProject/0x-monorepo/issues"
+ },
+ "homepage": "https://github.com/0xProject/0x-monorepo/packages/contract-addresses/README.md",
+ "devDependencies": {
+ "typescript": "3.0.1",
+ "shx": "^0.2.2"
+ },
+ "dependencies": {
+ "@0xproject/types": "1.1.4",
+ "lodash": "^4.17.5"
+ },
+ "publishConfig": {
+ "access": "public"
+ }
+}
diff --git a/packages/contract-addresses/src/index.ts b/packages/contract-addresses/src/index.ts
new file mode 100644
index 000000000..a39130c11
--- /dev/null
+++ b/packages/contract-addresses/src/index.ts
@@ -0,0 +1,64 @@
+import * as _ from 'lodash';
+
+export interface ContractAddresses {
+ erc20Proxy: string;
+ erc721Proxy: string;
+ zrxToken: string;
+ etherToken: string;
+ exchange: string;
+ assetProxyOwner: string;
+ forwarder: string;
+ orderValidator: string;
+}
+
+export enum NetworkId {
+ Mainnet = 1,
+ Ropsten = 3,
+ Kovan = 42,
+}
+
+const networkToAddresses: { [networkId: number]: ContractAddresses } = {
+ 1: {
+ erc20Proxy: '0x2240dab907db71e64d3e0dba4800c83b5c502d4e',
+ erc721Proxy: '0x208e41fb445f1bb1b6780d58356e81405f3e6127',
+ zrxToken: '0xe41d2489571d322189246dafa5ebde1f4699f498',
+ etherToken: '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
+ exchange: '0x4f833a24e1f95d70f028921e27040ca56e09ab0b',
+ assetProxyOwner: '0x17992e4ffb22730138e4b62aaa6367fa9d3699a6',
+ forwarder: '0x7afc2d5107af94c462a194d2c21b5bdd238709d6',
+ orderValidator: '0x9463e518dea6810309563c81d5266c1b1d149138',
+ },
+ 3: {
+ erc20Proxy: '0xb1408f4c245a23c31b98d2c626777d4c0d766caa',
+ erc721Proxy: '0xe654aac058bfbf9f83fcaee7793311dd82f6ddb4',
+ zrxToken: '0xff67881f8d12f372d91baae9752eb3631ff0ed00',
+ etherToken: '0xc778417e063141139fce010982780140aa0cd5ab',
+ exchange: '0x4530c0483a1633c7a1c97d2c53721caff2caaaaf',
+ assetProxyOwner: '0xf5fa5b5fed2727a0e44ac67f6772e97977aa358b',
+ forwarder: '0x3983e204b12b3c02fb0638caf2cd406a62e0ead3',
+ orderValidator: '0x90431a90516ab49af23a0530e04e8c7836e7122f',
+ },
+ 42: {
+ erc20Proxy: '0xf1ec01d6236d3cd881a0bf0130ea25fe4234003e',
+ erc721Proxy: '0x2a9127c745688a165106c11cd4d647d2220af821',
+ zrxToken: '0x2002d3812f58e35f0ea1ffbf80a75a38c32175fa',
+ etherToken: '0xd0a1e359811322d97991e03f863a0c30c2cf029c',
+ exchange: '0x35dd2932454449b14cee11a94d3674a936d5d7b2',
+ assetProxyOwner: '0x2c824d2882baa668e0d5202b1e7f2922278703f8',
+ forwarder: '0xd85e2fa7e7e252b27b01bf0d65c946959d2f45b8',
+ orderValidator: '0xb389da3d204b412df2f75c6afb3d0a7ce0bc283d',
+ },
+};
+
+/**
+ * Used to get addresses of contracts that have been deployed to either the
+ * Ethereum mainnet or a supported testnet.
+ * @returns The set of addresses for contracts which have been deployed on the
+ * given networkId.
+ */
+export function getContractAddressesForNetwork(networkId: NetworkId): ContractAddresses {
+ if (_.isUndefined(networkToAddresses[networkId])) {
+ throw new Error(`Unknown network id (${networkId}). No known 0x contracts have been deployed on this network.`);
+ }
+ return networkToAddresses[networkId];
+}
diff --git a/packages/contract-addresses/tsconfig.json b/packages/contract-addresses/tsconfig.json
new file mode 100644
index 000000000..233008d61
--- /dev/null
+++ b/packages/contract-addresses/tsconfig.json
@@ -0,0 +1,8 @@
+{
+ "extends": "../../tsconfig",
+ "compilerOptions": {
+ "outDir": "lib",
+ "rootDir": "."
+ },
+ "include": ["./src/**/*"]
+}
diff --git a/packages/contract-addresses/tslint.json b/packages/contract-addresses/tslint.json
new file mode 100644
index 000000000..ffaefe83a
--- /dev/null
+++ b/packages/contract-addresses/tslint.json
@@ -0,0 +1,3 @@
+{
+ "extends": ["@0xproject/tslint-config"]
+}
diff --git a/packages/contract-wrappers/package.json b/packages/contract-wrappers/package.json
index 37cf34898..46ae15647 100644
--- a/packages/contract-wrappers/package.json
+++ b/packages/contract-wrappers/package.json
@@ -68,6 +68,7 @@
"@0xproject/abi-gen-wrappers": "^1.0.0",
"@0xproject/assert": "^1.0.13",
"@0xproject/base-contract": "^3.0.1",
+ "@0xproject/contract-addresses": "^1.0.0",
"@0xproject/contract-artifacts": "^1.0.0",
"@0xproject/fill-scenarios": "^1.0.7",
"@0xproject/json-schemas": "^1.0.7",
diff --git a/packages/contract-wrappers/src/contract_wrappers.ts b/packages/contract-wrappers/src/contract_wrappers.ts
index 359307da4..25acf823d 100644
--- a/packages/contract-wrappers/src/contract_wrappers.ts
+++ b/packages/contract-wrappers/src/contract_wrappers.ts
@@ -1,3 +1,4 @@
+import { getContractAddressesForNetwork } from '@0xproject/contract-addresses';
import {
ERC20Proxy,
ERC20Token,
@@ -100,29 +101,50 @@ export class ContractWrappers {
const blockPollingIntervalMs = _.isUndefined(config.blockPollingIntervalMs)
? constants.DEFAULT_BLOCK_POLLING_INTERVAL
: config.blockPollingIntervalMs;
- if (_.isUndefined(config.contractAddresses.erc20Proxy)) {
- throw new Error('config.contractAddresses.erc20Proxy is required for testing');
- }
- this.erc20Proxy = new ERC20ProxyWrapper(this._web3Wrapper, config.contractAddresses.erc20Proxy);
- this.erc721Proxy = new ERC721ProxyWrapper(this._web3Wrapper, config.contractAddresses.erc721Proxy);
- this.erc20Token = new ERC20TokenWrapper(this._web3Wrapper, this.erc20Proxy, blockPollingIntervalMs);
- this.erc721Token = new ERC721TokenWrapper(this._web3Wrapper, this.erc721Proxy, blockPollingIntervalMs);
- this.etherToken = new EtherTokenWrapper(this._web3Wrapper, this.erc20Token, blockPollingIntervalMs);
+ const contractAddresses = _.isUndefined(config.contractAddresses)
+ ? getContractAddressesForNetwork(config.networkId)
+ : config.contractAddresses;
+ this.erc20Proxy = new ERC20ProxyWrapper(this._web3Wrapper, config.networkId, contractAddresses.erc20Proxy);
+ this.erc721Proxy = new ERC721ProxyWrapper(this._web3Wrapper, config.networkId, contractAddresses.erc721Proxy);
+ 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,
this.erc20Token,
this.erc721Token,
- config.contractAddresses.exchange,
- config.contractAddresses.zrxToken,
+ contractAddresses.exchange,
+ contractAddresses.zrxToken,
blockPollingIntervalMs,
);
this.forwarder = new ForwarderWrapper(
this._web3Wrapper,
- config.contractAddresses.forwarder,
- config.contractAddresses.zrxToken,
- config.contractAddresses.etherToken,
+ config.networkId,
+ contractAddresses.forwarder,
+ contractAddresses.zrxToken,
+ contractAddresses.etherToken,
+ );
+ this.orderValidator = new OrderValidatorWrapper(
+ this._web3Wrapper,
+ config.networkId,
+ contractAddresses.orderValidator,
);
- this.orderValidator = new OrderValidatorWrapper(this._web3Wrapper, config.contractAddresses.orderValidator);
}
/**
* Sets a new web3 provider for 0x.js. Updating the provider will stop all
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
diff --git a/packages/contract-wrappers/src/types.ts b/packages/contract-wrappers/src/types.ts
index b06a6b914..e70adb991 100644
--- a/packages/contract-wrappers/src/types.ts
+++ b/packages/contract-wrappers/src/types.ts
@@ -8,7 +8,8 @@ import {
WETH9EventArgs,
WETH9Events,
} from '@0xproject/abi-gen-wrappers';
-import { ContractAddresses, OrderState, SignedOrder } from '@0xproject/types';
+import { ContractAddresses } from '@0xproject/contract-addresses';
+import { OrderState, SignedOrder } from '@0xproject/types';
import { BigNumber } from '@0xproject/utils';
import { BlockParam, ContractEventArg, DecodedLogArgs, LogEntryEvent, LogWithDecodedArgs } from 'ethereum-types';
@@ -110,18 +111,13 @@ export type SyncMethod = (...args: any[]) => any;
/**
* networkId: The id of the underlying ethereum network your provider is connected to. (1-mainnet, 3-ropsten, 4-rinkeby, 42-kovan, 50-testrpc)
* gasPrice: Gas price to use with every transaction
- * exchangeContractAddress: The address of an exchange contract to use
- * zrxContractAddress: The address of the ZRX contract to use
- * erc20ProxyContractAddress: The address of the erc20 token transfer proxy contract to use
- * erc721ProxyContractAddress: The address of the erc721 token transfer proxy contract to use
- * forwarderContractAddress: The address of the forwarder contract to use
- * orderWatcherConfig: All the configs related to the orderWatcher
+ * contractAddresses: The address of all contracts to use. Defaults to the known addresses based on networkId.
* blockPollingIntervalMs: The interval to use for block polling in event watching methods (defaults to 1000)
*/
export interface ContractWrappersConfig {
networkId: number;
gasPrice?: BigNumber;
- contractAddresses: ContractAddresses;
+ contractAddresses?: ContractAddresses;
blockPollingIntervalMs?: number;
}
diff --git a/packages/contract-wrappers/test/erc20_wrapper_test.ts b/packages/contract-wrappers/test/erc20_wrapper_test.ts
index a42650a63..37a824120 100644
--- a/packages/contract-wrappers/test/erc20_wrapper_test.ts
+++ b/packages/contract-wrappers/test/erc20_wrapper_test.ts
@@ -1,6 +1,7 @@
+import { ContractAddresses } from '@0xproject/contract-addresses';
import { BlockchainLifecycle, callbackErrorReporter } from '@0xproject/dev-utils';
import { EmptyWalletSubprovider, Web3ProviderEngine } from '@0xproject/subproviders';
-import { ContractAddresses, DoneCallback } from '@0xproject/types';
+import { DoneCallback } from '@0xproject/types';
import { BigNumber } from '@0xproject/utils';
import * as chai from 'chai';
import { Provider } from 'ethereum-types';
diff --git a/packages/contract-wrappers/test/ether_token_wrapper_test.ts b/packages/contract-wrappers/test/ether_token_wrapper_test.ts
index 1a53e2757..1fb6d2d42 100644
--- a/packages/contract-wrappers/test/ether_token_wrapper_test.ts
+++ b/packages/contract-wrappers/test/ether_token_wrapper_test.ts
@@ -1,5 +1,6 @@
+import { ContractAddresses } from '@0xproject/contract-addresses';
import { BlockchainLifecycle, callbackErrorReporter } from '@0xproject/dev-utils';
-import { ContractAddresses, DoneCallback } from '@0xproject/types';
+import { DoneCallback } from '@0xproject/types';
import { BigNumber } from '@0xproject/utils';
import { Web3Wrapper } from '@0xproject/web3-wrapper';
import * as chai from 'chai';
@@ -16,7 +17,6 @@ import {
WETH9TransferEventArgs,
WETH9WithdrawalEventArgs,
} from '../src';
-
import { DecodedLogEvent } from '../src/types';
import { chaiSetup } from './utils/chai_setup';
diff --git a/packages/contract-wrappers/test/order_validator_wrapper_test.ts b/packages/contract-wrappers/test/order_validator_wrapper_test.ts
index 482b4dfe0..636aa9a50 100644
--- a/packages/contract-wrappers/test/order_validator_wrapper_test.ts
+++ b/packages/contract-wrappers/test/order_validator_wrapper_test.ts
@@ -1,7 +1,8 @@
+import { ContractAddresses } from '@0xproject/contract-addresses';
import { BlockchainLifecycle } from '@0xproject/dev-utils';
import { FillScenarios } from '@0xproject/fill-scenarios';
import { assetDataUtils } from '@0xproject/order-utils';
-import { ContractAddresses, SignedOrder } from '@0xproject/types';
+import { SignedOrder } from '@0xproject/types';
import { BigNumber } from '@0xproject/utils';
import * as chai from 'chai';
import * as _ from 'lodash';
diff --git a/packages/contract-wrappers/test/utils/migrate.ts b/packages/contract-wrappers/test/utils/migrate.ts
index 26412d246..53319a383 100644
--- a/packages/contract-wrappers/test/utils/migrate.ts
+++ b/packages/contract-wrappers/test/utils/migrate.ts
@@ -1,6 +1,6 @@
+import { ContractAddresses } from '@0xproject/contract-addresses';
import { devConstants } from '@0xproject/dev-utils';
import { runMigrationsOnceAsync } from '@0xproject/migrations';
-import { ContractAddresses } from '@0xproject/types';
import { provider } from './web3_wrapper';
diff --git a/packages/contracts/src/artifacts/index.ts b/packages/contracts/src/artifacts/index.ts
index 1522ba77a..a9cd31ea2 100644
--- a/packages/contracts/src/artifacts/index.ts
+++ b/packages/contracts/src/artifacts/index.ts
@@ -37,7 +37,6 @@ import * as WETH9 from '../../generated-artifacts/WETH9.json';
import * as Whitelist from '../../generated-artifacts/Whitelist.json';
import * as ZRXToken from '../../generated-artifacts/ZRXToken.json';
-// TODO(albrow): Do we need to export all of these?
export const artifacts = {
AssetProxyOwner: (AssetProxyOwner as any) as ContractArtifact,
DummyERC20Token: (DummyERC20Token as any) as ContractArtifact,
diff --git a/packages/contracts/src/wrappers/index.ts b/packages/contracts/src/wrappers/index.ts
index 64f1dc6a3..9ca676b56 100644
--- a/packages/contracts/src/wrappers/index.ts
+++ b/packages/contracts/src/wrappers/index.ts
@@ -1,4 +1,3 @@
-// TODO(albrow): Do we need to export all of these?
export * from '../../generated-wrappers/asset_proxy_owner';
export * from '../../generated-wrappers/dummy_erc20_token';
export * from '../../generated-wrappers/dummy_erc721_receiver';
diff --git a/packages/migrations/package.json b/packages/migrations/package.json
index c21d5b56b..44737e227 100644
--- a/packages/migrations/package.json
+++ b/packages/migrations/package.json
@@ -31,6 +31,7 @@
"dependencies": {
"@0xproject/abi-gen-wrappers": "^1.0.0",
"@0xproject/base-contract": "^3.0.1",
+ "@0xproject/contract-addresses": "^1.0.0",
"@0xproject/contract-artifacts": "^1.0.0",
"@0xproject/order-utils": "^1.0.7",
"@0xproject/sol-compiler": "^1.1.7",
diff --git a/packages/migrations/src/migration.ts b/packages/migrations/src/migration.ts
index fc5f390ad..0ee5b6975 100644
--- a/packages/migrations/src/migration.ts
+++ b/packages/migrations/src/migration.ts
@@ -1,7 +1,7 @@
import * as wrappers from '@0xproject/abi-gen-wrappers';
+import { ContractAddresses } from '@0xproject/contract-addresses';
import * as artifacts from '@0xproject/contract-artifacts';
import { assetDataUtils } from '@0xproject/order-utils';
-import { ContractAddresses } from '@0xproject/types';
import { BigNumber } from '@0xproject/utils';
import { Web3Wrapper } from '@0xproject/web3-wrapper';
import { Provider, TxData } from 'ethereum-types';
diff --git a/packages/order-watcher/package.json b/packages/order-watcher/package.json
index ca352b754..a3f7b1fc7 100644
--- a/packages/order-watcher/package.json
+++ b/packages/order-watcher/package.json
@@ -60,6 +60,7 @@
"@0xproject/abi-gen-wrappers": "^1.0.0",
"@0xproject/assert": "^1.0.13",
"@0xproject/base-contract": "^3.0.1",
+ "@0xproject/contract-addresses": "^1.0.0",
"@0xproject/contract-artifacts": "^1.0.0",
"@0xproject/contract-wrappers": "^2.0.2",
"@0xproject/fill-scenarios": "^1.0.7",
diff --git a/packages/order-watcher/src/order_watcher/order_watcher.ts b/packages/order-watcher/src/order_watcher/order_watcher.ts
index 8afed3924..2f0dd2f2d 100644
--- a/packages/order-watcher/src/order_watcher/order_watcher.ts
+++ b/packages/order-watcher/src/order_watcher/order_watcher.ts
@@ -1,4 +1,5 @@
// tslint:disable:no-unnecessary-type-assertion
+import { ContractAddresses } from '@0xproject/contract-addresses';
import * as artifacts from '@0xproject/contract-artifacts';
import {
AssetBalanceAndProxyAllowanceFetcher,
@@ -31,14 +32,7 @@ import {
orderHashUtils,
OrderStateUtils,
} from '@0xproject/order-utils';
-import {
- AssetProxyId,
- ContractAddresses,
- ExchangeContractErrs,
- OrderState,
- SignedOrder,
- Stats,
-} from '@0xproject/types';
+import { AssetProxyId, ExchangeContractErrs, OrderState, SignedOrder, Stats } from '@0xproject/types';
import { errorUtils, intervalUtils } from '@0xproject/utils';
import { BlockParamLiteral, LogEntryEvent, LogWithDecodedArgs, Provider } from 'ethereum-types';
import * as _ from 'lodash';
@@ -98,12 +92,14 @@ export class OrderWatcher {
* Instantiate a new OrderWatcher
* @param provider Web3 provider to use for JSON RPC calls
* @param networkId NetworkId to watch orders on
+ * @param contractAddresses Optional contract addresses. Defaults to known
+ * addresses based on networkId.
* @param partialConfig Optional configurations
*/
constructor(
provider: Provider,
networkId: number,
- contractAddresses: ContractAddresses,
+ contractAddresses?: ContractAddresses,
partialConfig: Partial<OrderWatcherConfig> = DEFAULT_ORDER_WATCHER_CONFIG,
) {
assert.isWeb3Provider('provider', provider);
@@ -122,7 +118,8 @@ export class OrderWatcher {
);
const contractWrappers = new ContractWrappers(provider, {
networkId,
- // TODO(albrow): Make contract addresses optional.
+ // Note(albrow): We let the contract-wrappers package handle
+ // default values for contractAddresses.
contractAddresses,
});
this._eventWatcher = new EventWatcher(provider, config.eventPollingIntervalMs, STATE_LAYER, config.isVerbose);
diff --git a/packages/order-watcher/test/utils/migrate.ts b/packages/order-watcher/test/utils/migrate.ts
index 26412d246..53319a383 100644
--- a/packages/order-watcher/test/utils/migrate.ts
+++ b/packages/order-watcher/test/utils/migrate.ts
@@ -1,6 +1,6 @@
+import { ContractAddresses } from '@0xproject/contract-addresses';
import { devConstants } from '@0xproject/dev-utils';
import { runMigrationsOnceAsync } from '@0xproject/migrations';
-import { ContractAddresses } from '@0xproject/types';
import { provider } from './web3_wrapper';
diff --git a/packages/testnet-faucets/package.json b/packages/testnet-faucets/package.json
index a113889cc..cd56c1395 100644
--- a/packages/testnet-faucets/package.json
+++ b/packages/testnet-faucets/package.json
@@ -19,6 +19,7 @@
"license": "Apache-2.0",
"dependencies": {
"0x.js": "^1.0.8",
+ "@0xproject/contract-addresses": "^1.0.0",
"@0xproject/subproviders": "^2.0.7",
"@0xproject/typescript-typings": "^3.0.2",
"@0xproject/utils": "^2.0.2",
diff --git a/packages/testnet-faucets/src/ts/handler.ts b/packages/testnet-faucets/src/ts/handler.ts
index b2d2226f4..262f6d889 100644
--- a/packages/testnet-faucets/src/ts/handler.ts
+++ b/packages/testnet-faucets/src/ts/handler.ts
@@ -11,6 +11,7 @@ import {
SignedOrder,
Web3ProviderEngine,
} from '0x.js';
+import { getContractAddressesForNetwork } from '@0xproject/contract-addresses';
import { NonceTrackerSubprovider, PrivateKeyWalletSubprovider } from '@0xproject/subproviders';
import { logUtils } from '@0xproject/utils';
import { Web3Wrapper } from '@0xproject/web3-wrapper';
@@ -67,17 +68,7 @@ export class Handler {
const networkId = parseInt(networkIdString, 10);
const contractWrappersConfig = {
networkId,
- // TODO(albrow): Load in real contract addresses here.
- contractAddresses: {
- erc20Proxy: '',
- erc721Proxy: '',
- zrxToken: '',
- etherToken: '',
- exchange: '',
- assetProxyOwner: '',
- forwarder: '',
- orderValidator: '',
- },
+ contractAddresses: getContractAddressesForNetwork(networkId),
};
const contractWrappers = new ContractWrappers(providerObj, contractWrappersConfig);
const dispatchQueue = new DispatchQueue();
diff --git a/packages/website/package.json b/packages/website/package.json
index efab95c80..f6da39666 100644
--- a/packages/website/package.json
+++ b/packages/website/package.json
@@ -20,6 +20,7 @@
"license": "Apache-2.0",
"dependencies": {
"0x.js": "^0.38.6",
+ "@0xproject/contract-addresses": "^1.0.0",
"@0xproject/contract-wrappers": "^2.0.2",
"@0xproject/json-schemas": "^1.0.7",
"@0xproject/order-utils": "^1.0.7",
diff --git a/packages/website/ts/blockchain.ts b/packages/website/ts/blockchain.ts
index 14ab73531..8a2489e07 100644
--- a/packages/website/ts/blockchain.ts
+++ b/packages/website/ts/blockchain.ts
@@ -1,4 +1,5 @@
import { ZeroEx } from '0x.js';
+import { getContractAddressesForNetwork } from '@0xproject/contract-addresses';
import {
BlockRange,
ContractWrappers,
@@ -863,17 +864,7 @@ export class Blockchain {
} else {
const contractWrappersConfig = {
networkId,
- // TODO(albrow): Load in real contract addresses here.
- contractAddresses: {
- erc20Proxy: '',
- erc721Proxy: '',
- zrxToken: '',
- etherToken: '',
- exchange: '',
- assetProxyOwner: '',
- forwarder: '',
- orderValidator: '',
- },
+ contractAddresses: getContractAddressesForNetwork(networkId),
};
this._contractWrappers = new ContractWrappers(provider, contractWrappersConfig);
}