aboutsummaryrefslogtreecommitdiffstats
path: root/packages/order-watcher
diff options
context:
space:
mode:
Diffstat (limited to 'packages/order-watcher')
-rw-r--r--packages/order-watcher/.npmignore1
-rw-r--r--packages/order-watcher/CHANGELOG.json7
-rw-r--r--packages/order-watcher/package.json21
-rw-r--r--packages/order-watcher/src/artifacts.ts13
-rw-r--r--packages/order-watcher/src/globals.d.ts6
-rw-r--r--packages/order-watcher/src/index.ts1
-rw-r--r--packages/order-watcher/src/order_watcher/order_watcher.ts15
-rw-r--r--packages/order-watcher/test/expiration_watcher_test.ts19
-rw-r--r--packages/order-watcher/test/global_hooks.ts13
-rw-r--r--packages/order-watcher/test/order_watcher_test.ts24
-rw-r--r--packages/order-watcher/test/utils/migrate.ts18
-rw-r--r--packages/order-watcher/test/utils/token_utils.ts34
12 files changed, 64 insertions, 108 deletions
diff --git a/packages/order-watcher/.npmignore b/packages/order-watcher/.npmignore
index c5be1b302..ac4ab11f2 100644
--- a/packages/order-watcher/.npmignore
+++ b/packages/order-watcher/.npmignore
@@ -7,4 +7,3 @@ test/
/_bundles/
/generated_docs/
/scripts/
-/lib/src/monorepo_scripts/
diff --git a/packages/order-watcher/CHANGELOG.json b/packages/order-watcher/CHANGELOG.json
index feebb9d69..1fa0b3bc9 100644
--- a/packages/order-watcher/CHANGELOG.json
+++ b/packages/order-watcher/CHANGELOG.json
@@ -1,10 +1,15 @@
[
{
- "version": "2.1.2",
+ "version": "2.2.0",
"changes": [
{
"note": "Added getStats function and returns a Stats object",
"pr": 1118
+ },
+ {
+ "note":
+ "Updated to use new modularized artifacts and the latest version of @0xproject/contract-wrappers. Constructor has a new optional `contractAddresses` parameter.",
+ "pr": 1105
}
]
},
diff --git a/packages/order-watcher/package.json b/packages/order-watcher/package.json
index 9bdaef5b1..a3f7b1fc7 100644
--- a/packages/order-watcher/package.json
+++ b/packages/order-watcher/package.json
@@ -12,28 +12,18 @@
"main": "lib/src/index.js",
"types": "lib/src/index.d.ts",
"scripts": {
- "build": "yarn pre_build && tsc -b",
+ "build": "yarn tsc -b",
"build:ci": "yarn build",
- "pre_build": "run-s update_artifacts copy_artifacts generate_contract_wrappers",
- "lint": "tslint --project . --exclude **/src/generated_contract_wrappers/**/*",
- "generate_contract_wrappers": "abi-gen --abis 'src/artifacts/@(Exchange|Token|TokenTransferProxy|EtherToken).json' --template ../contract_templates/contract.handlebars --partials '../contract_templates/partials/**/*.handlebars' --output src/generated_contract_wrappers --backend ethers",
+ "lint": "tslint --project .",
"test:circleci": "run-s test:coverage",
"test": "yarn run_mocha",
"rebuild_and_test": "run-s build test",
"test:coverage": "nyc npm run test --all && yarn coverage:report:lcov",
"coverage:report:lcov": "nyc report --reporter=text-lcov > coverage/lcov.info",
- "copy_artifacts": "copyfiles -u 2 './src/artifacts/**/*.json' ./lib/src/artifacts",
- "update_artifacts": "for i in ${npm_package_config_contracts_v2}; do copyfiles -u 4 ../migrations/artifacts/2.0.0-trimmed/$i.json src/artifacts; done;",
- "clean": "shx rm -rf _bundles lib test_temp test/artifacts src/generated_contract_wrappers generated_docs",
+ "clean": "shx rm -rf _bundles lib test_temp generated_docs",
"run_mocha": "mocha --require source-map-support/register --require make-promises-safe lib/test/**/*_test.js lib/test/global_hooks.js --timeout 10000 --bail --exit",
"docs:json": "typedoc --excludePrivate --excludeExternals --target ES5 --tsconfig typedoc-tsconfig.json --json $JSON_FILE_PATH $PROJECT_FILES"
},
- "config": {
- "contracts_v2": "AssetProxyOwner ERC20Proxy ERC20Token ERC721Proxy ERC721Token Exchange Forwarder OrderValidator WETH9 ZRXToken",
- "postpublish": {
- "assets": []
- }
- },
"repository": {
"type": "git",
"url": "https://github.com/0xProject/0x-monorepo"
@@ -43,7 +33,6 @@
"node": ">=6.0.0"
},
"devDependencies": {
- "@0xproject/abi-gen": "^1.0.13",
"@0xproject/dev-utils": "^1.0.12",
"@0xproject/migrations": "^1.0.14",
"@0xproject/tslint-config": "^1.0.8",
@@ -55,7 +44,6 @@
"chai": "^4.0.1",
"chai-as-promised": "^7.1.0",
"chai-bignumber": "^2.0.1",
- "copyfiles": "^2.0.0",
"dirty-chai": "^2.0.1",
"make-promises-safe": "^1.1.0",
"mocha": "^4.1.0",
@@ -69,8 +57,11 @@
"typescript": "3.0.1"
},
"dependencies": {
+ "@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",
"@0xproject/json-schemas": "^1.0.7",
diff --git a/packages/order-watcher/src/artifacts.ts b/packages/order-watcher/src/artifacts.ts
deleted file mode 100644
index 520066a24..000000000
--- a/packages/order-watcher/src/artifacts.ts
+++ /dev/null
@@ -1,13 +0,0 @@
-import { ContractArtifact } from 'ethereum-types';
-
-import * as ERC20Token from './artifacts/ERC20Token.json';
-import * as ERC721Token from './artifacts/ERC721Token.json';
-import * as Exchange from './artifacts/Exchange.json';
-import * as WETH9 from './artifacts/WETH9.json';
-
-export const artifacts = {
- ERC20Token: (ERC20Token as any) as ContractArtifact,
- ERC721Token: (ERC721Token as any) as ContractArtifact,
- Exchange: (Exchange as any) as ContractArtifact,
- EtherToken: (WETH9 as any) as ContractArtifact,
-};
diff --git a/packages/order-watcher/src/globals.d.ts b/packages/order-watcher/src/globals.d.ts
deleted file mode 100644
index 94e63a32d..000000000
--- a/packages/order-watcher/src/globals.d.ts
+++ /dev/null
@@ -1,6 +0,0 @@
-declare module '*.json' {
- const json: any;
- /* tslint:disable */
- export default json;
- /* tslint:enable */
-}
diff --git a/packages/order-watcher/src/index.ts b/packages/order-watcher/src/index.ts
index 8280c73a4..6e862a427 100644
--- a/packages/order-watcher/src/index.ts
+++ b/packages/order-watcher/src/index.ts
@@ -12,6 +12,7 @@ export {
export { OnOrderStateChangeCallback, OrderWatcherConfig } from './types';
+export { ContractAddresses } from '@0xproject/contract-addresses';
export { SignedOrder } from '@0xproject/types';
export {
JSONRPCRequestPayload,
diff --git a/packages/order-watcher/src/order_watcher/order_watcher.ts b/packages/order-watcher/src/order_watcher/order_watcher.ts
index eb37bd617..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,6 @@
// tslint:disable:no-unnecessary-type-assertion
+import { ContractAddresses } from '@0xproject/contract-addresses';
+import * as artifacts from '@0xproject/contract-artifacts';
import {
AssetBalanceAndProxyAllowanceFetcher,
ContractWrappers,
@@ -35,7 +37,6 @@ import { errorUtils, intervalUtils } from '@0xproject/utils';
import { BlockParamLiteral, LogEntryEvent, LogWithDecodedArgs, Provider } from 'ethereum-types';
import * as _ from 'lodash';
-import { artifacts } from '../artifacts';
import { orderWatcherPartialConfigSchema } from '../schemas/order_watcher_partial_config_schema';
import { OnOrderStateChangeCallback, OrderWatcherConfig, OrderWatcherError } from '../types';
import { assert } from '../utils/assert';
@@ -91,11 +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,
partialConfig: Partial<OrderWatcherConfig> = DEFAULT_ORDER_WATCHER_CONFIG,
) {
assert.isWeb3Provider('provider', provider);
@@ -110,9 +114,14 @@ export class OrderWatcher {
this._collisionResistantAbiDecoder = new CollisionResistanceAbiDecoder(
artifacts.ERC20Token.compilerOutput.abi,
artifacts.ERC721Token.compilerOutput.abi,
- [artifacts.EtherToken.compilerOutput.abi, artifacts.Exchange.compilerOutput.abi],
+ [artifacts.WETH9.compilerOutput.abi, artifacts.Exchange.compilerOutput.abi],
);
- const contractWrappers = new ContractWrappers(provider, { networkId });
+ const contractWrappers = new ContractWrappers(provider, {
+ networkId,
+ // 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);
const balanceAndProxyAllowanceFetcher = new AssetBalanceAndProxyAllowanceFetcher(
contractWrappers.erc20Token,
diff --git a/packages/order-watcher/test/expiration_watcher_test.ts b/packages/order-watcher/test/expiration_watcher_test.ts
index ea9923487..17be625bc 100644
--- a/packages/order-watcher/test/expiration_watcher_test.ts
+++ b/packages/order-watcher/test/expiration_watcher_test.ts
@@ -1,4 +1,3 @@
-import { ContractWrappers } from '@0xproject/contract-wrappers';
import { tokenUtils } from '@0xproject/contract-wrappers/lib/test/utils/token_utils';
import { BlockchainLifecycle, callbackErrorReporter } from '@0xproject/dev-utils';
import { FillScenarios } from '@0xproject/fill-scenarios';
@@ -14,7 +13,7 @@ import { ExpirationWatcher } from '../src/order_watcher/expiration_watcher';
import { utils } from '../src/utils/utils';
import { chaiSetup } from './utils/chai_setup';
-import { constants } from './utils/constants';
+import { migrateOnceAsync } from './utils/migrate';
import { provider, web3Wrapper } from './utils/web3_wrapper';
chaiSetup.configure();
@@ -23,14 +22,8 @@ const blockchainLifecycle = new BlockchainLifecycle(web3Wrapper);
const MILISECONDS_IN_SECOND = 1000;
describe('ExpirationWatcher', () => {
- const config = {
- networkId: constants.TESTRPC_NETWORK_ID,
- };
- const contractWrappers = new ContractWrappers(provider, config);
let userAddresses: string[];
- let zrxTokenAddress: string;
let fillScenarios: FillScenarios;
- const exchangeContractAddress = contractWrappers.exchange.getContractAddress();
let makerAssetData: string;
let takerAssetData: string;
let coinbase: string;
@@ -42,16 +35,16 @@ describe('ExpirationWatcher', () => {
let timer: Sinon.SinonFakeTimers;
let expirationWatcher: ExpirationWatcher;
before(async () => {
+ const contractAddresses = await migrateOnceAsync();
await blockchainLifecycle.startAsync();
userAddresses = await web3Wrapper.getAvailableAddressesAsync();
- zrxTokenAddress = tokenUtils.getProtocolTokenAddress();
fillScenarios = new FillScenarios(
provider,
userAddresses,
- zrxTokenAddress,
- exchangeContractAddress,
- contractWrappers.erc20Proxy.getContractAddress(),
- contractWrappers.erc721Proxy.getContractAddress(),
+ contractAddresses.zrxToken,
+ contractAddresses.exchange,
+ contractAddresses.erc20Proxy,
+ contractAddresses.erc721Proxy,
);
[coinbase, makerAddress, takerAddress, feeRecipient] = userAddresses;
const [makerTokenAddress, takerTokenAddress] = tokenUtils.getDummyERC20TokenAddresses();
diff --git a/packages/order-watcher/test/global_hooks.ts b/packages/order-watcher/test/global_hooks.ts
index 99df04a51..26c37158f 100644
--- a/packages/order-watcher/test/global_hooks.ts
+++ b/packages/order-watcher/test/global_hooks.ts
@@ -1,17 +1,6 @@
-import { devConstants } from '@0xproject/dev-utils';
-import { runV2MigrationsAsync } from '@0xproject/migrations';
-
-import { provider } from './utils/web3_wrapper';
-
-before('migrate contracts', async function(): Promise<void> {
+before('set up mocha', async function(): Promise<void> {
// HACK: Since the migrations take longer then our global mocha timeout limit
// we manually increase it for this before hook.
const mochaTestTimeoutMs = 25000;
this.timeout(mochaTestTimeoutMs); // tslint:disable-line:no-invalid-this
- const txDefaults = {
- gas: devConstants.GAS_LIMIT,
- from: devConstants.TESTRPC_FIRST_ADDRESS,
- };
- const artifactsDir = `src/artifacts`;
- await runV2MigrationsAsync(provider, artifactsDir, txDefaults);
});
diff --git a/packages/order-watcher/test/order_watcher_test.ts b/packages/order-watcher/test/order_watcher_test.ts
index 4545f84bf..e13d44396 100644
--- a/packages/order-watcher/test/order_watcher_test.ts
+++ b/packages/order-watcher/test/order_watcher_test.ts
@@ -27,6 +27,7 @@ import { OrderWatcherError } from '../src/types';
import { chaiSetup } from './utils/chai_setup';
import { constants } from './utils/constants';
+import { migrateOnceAsync } from './utils/migrate';
import { provider, web3Wrapper } from './utils/web3_wrapper';
const TIMEOUT_MS = 150;
@@ -36,13 +37,10 @@ const expect = chai.expect;
const blockchainLifecycle = new BlockchainLifecycle(web3Wrapper);
describe('OrderWatcher', () => {
- const networkId = constants.TESTRPC_NETWORK_ID;
- const config = { networkId };
- const contractWrappers = new ContractWrappers(provider, config);
+ let contractWrappers: ContractWrappers;
let fillScenarios: FillScenarios;
let userAddresses: string[];
let zrxTokenAddress: string;
- let exchangeContractAddress: string;
let makerAssetData: string;
let takerAssetData: string;
let makerTokenAddress: string;
@@ -56,17 +54,23 @@ describe('OrderWatcher', () => {
const decimals = constants.ZRX_DECIMALS;
const fillableAmount = Web3Wrapper.toBaseUnitAmount(new BigNumber(5), decimals);
before(async () => {
+ const contractAddresses = await migrateOnceAsync();
await blockchainLifecycle.startAsync();
+ const networkId = constants.TESTRPC_NETWORK_ID;
+ const config = {
+ networkId,
+ contractAddresses,
+ };
+ contractWrappers = new ContractWrappers(provider, config);
userAddresses = await web3Wrapper.getAvailableAddressesAsync();
- zrxTokenAddress = tokenUtils.getProtocolTokenAddress();
- exchangeContractAddress = contractWrappers.exchange.getContractAddress();
+ zrxTokenAddress = contractAddresses.zrxToken;
fillScenarios = new FillScenarios(
provider,
userAddresses,
zrxTokenAddress,
- exchangeContractAddress,
- contractWrappers.erc20Proxy.getContractAddress(),
- contractWrappers.erc721Proxy.getContractAddress(),
+ contractAddresses.exchange,
+ contractAddresses.erc20Proxy,
+ contractAddresses.erc721Proxy,
);
[coinbase, makerAddress, takerAddress, feeRecipient] = userAddresses;
[makerTokenAddress, takerTokenAddress] = tokenUtils.getDummyERC20TokenAddresses();
@@ -75,7 +79,7 @@ describe('OrderWatcher', () => {
assetDataUtils.encodeERC20AssetData(takerTokenAddress),
];
const orderWatcherConfig = {};
- orderWatcher = new OrderWatcher(provider, networkId, orderWatcherConfig);
+ orderWatcher = new OrderWatcher(provider, networkId, contractAddresses, orderWatcherConfig);
});
after(async () => {
await blockchainLifecycle.revertAsync();
diff --git a/packages/order-watcher/test/utils/migrate.ts b/packages/order-watcher/test/utils/migrate.ts
new file mode 100644
index 000000000..53319a383
--- /dev/null
+++ b/packages/order-watcher/test/utils/migrate.ts
@@ -0,0 +1,18 @@
+import { ContractAddresses } from '@0xproject/contract-addresses';
+import { devConstants } from '@0xproject/dev-utils';
+import { runMigrationsOnceAsync } from '@0xproject/migrations';
+
+import { provider } from './web3_wrapper';
+
+/**
+ * Configures and runs the migrations exactly once. Any subsequent times this is
+ * called, it returns the cached addresses.
+ * @returns The addresses of contracts that were deployed during the migrations.
+ */
+export async function migrateOnceAsync(): Promise<ContractAddresses> {
+ const txDefaults = {
+ gas: devConstants.GAS_LIMIT,
+ from: devConstants.TESTRPC_FIRST_ADDRESS,
+ };
+ return runMigrationsOnceAsync(provider, txDefaults);
+}
diff --git a/packages/order-watcher/test/utils/token_utils.ts b/packages/order-watcher/test/utils/token_utils.ts
deleted file mode 100644
index f91b3797f..000000000
--- a/packages/order-watcher/test/utils/token_utils.ts
+++ /dev/null
@@ -1,34 +0,0 @@
-import { Token } from '@0xproject/types';
-import * as _ from 'lodash';
-
-import { InternalOrderWatcherError } from '../../src/types';
-
-const PROTOCOL_TOKEN_SYMBOL = 'ZRX';
-const WETH_TOKEN_SYMBOL = 'WETH';
-
-export class TokenUtils {
- private readonly _tokens: Token[];
- constructor(tokens: Token[]) {
- this._tokens = tokens;
- }
- public getProtocolTokenOrThrow(): Token {
- const zrxToken = _.find(this._tokens, { symbol: PROTOCOL_TOKEN_SYMBOL });
- if (_.isUndefined(zrxToken)) {
- throw new Error(InternalOrderWatcherError.ZrxNotInTokenRegistry);
- }
- return zrxToken;
- }
- public getWethTokenOrThrow(): Token {
- const wethToken = _.find(this._tokens, { symbol: WETH_TOKEN_SYMBOL });
- if (_.isUndefined(wethToken)) {
- throw new Error(InternalOrderWatcherError.WethNotInTokenRegistry);
- }
- return wethToken;
- }
- public getDummyTokens(): Token[] {
- const dummyTokens = _.filter(this._tokens, token => {
- return !_.includes([PROTOCOL_TOKEN_SYMBOL, WETH_TOKEN_SYMBOL], token.symbol);
- });
- return dummyTokens;
- }
-}