aboutsummaryrefslogtreecommitdiffstats
path: root/packages/contract-wrappers
diff options
context:
space:
mode:
Diffstat (limited to 'packages/contract-wrappers')
-rw-r--r--packages/contract-wrappers/package.json17
-rw-r--r--packages/contract-wrappers/src/abstract/abstract_balance_and_proxy_allowance_lazy_store.ts11
-rw-r--r--packages/contract-wrappers/src/contract_wrappers/contract_wrapper.ts3
-rw-r--r--packages/contract-wrappers/src/contract_wrappers/ether_token_wrapper.ts3
-rw-r--r--packages/contract-wrappers/src/contract_wrappers/exchange_wrapper.ts91
-rw-r--r--packages/contract-wrappers/src/contract_wrappers/token_registry_wrapper.ts1
-rw-r--r--packages/contract-wrappers/src/contract_wrappers/token_transfer_proxy_wrapper.ts1
-rw-r--r--packages/contract-wrappers/src/contract_wrappers/token_wrapper.ts3
-rw-r--r--packages/contract-wrappers/src/stores/balance_proxy_allowance_lazy_store.ts4
-rw-r--r--packages/contract-wrappers/src/types.ts6
-rw-r--r--packages/contract-wrappers/src/utils/assert.ts5
-rw-r--r--packages/contract-wrappers/src/utils/exchange_transfer_simulator.ts13
-rw-r--r--packages/contract-wrappers/src/utils/filter_utils.ts2
-rw-r--r--packages/contract-wrappers/src/utils/order_validation_utils.ts20
-rw-r--r--packages/contract-wrappers/src/utils/utils.ts3
-rw-r--r--packages/contract-wrappers/test/artifacts_test.ts1
-rw-r--r--packages/contract-wrappers/test/ether_token_wrapper_test.ts2
-rw-r--r--packages/contract-wrappers/test/exchange_transfer_simulator_test.ts9
-rw-r--r--packages/contract-wrappers/test/exchange_wrapper_test.ts3
-rw-r--r--packages/contract-wrappers/test/global_hooks.ts4
-rw-r--r--packages/contract-wrappers/test/order_validation_test.ts11
-rw-r--r--packages/contract-wrappers/test/subscription_test.ts2
-rw-r--r--packages/contract-wrappers/test/token_registry_wrapper_test.ts2
-rw-r--r--packages/contract-wrappers/test/token_wrapper_test.ts4
-rw-r--r--packages/contract-wrappers/test/utils/web3_wrapper.ts2
25 files changed, 143 insertions, 80 deletions
diff --git a/packages/contract-wrappers/package.json b/packages/contract-wrappers/package.json
index 61e92903f..d5d4bfbc8 100644
--- a/packages/contract-wrappers/package.json
+++ b/packages/contract-wrappers/package.json
@@ -11,18 +11,20 @@
"main": "lib/src/index.js",
"types": "lib/src/index.d.ts",
"scripts": {
- "watch": "tsc -w",
- "prebuild": "run-s clean generate_contract_wrappers",
+ "watch_without_deps": "yarn pre_build && tsc -w",
+ "build": "yarn pre_build && tsc && copyfiles -u 3 './lib/src/monorepo_scripts/**/*' ./scripts",
+ "pre_build": "run-s generate_contract_wrappers update_test_artifacts update_compact_artifacts",
"generate_contract_wrappers": "abi-gen --abis 'src/compact_artifacts/@(Exchange|Token|TokenTransferProxy|EtherToken|TokenRegistry|DummyToken).json' --template ../contract_templates/contract.handlebars --partials '../contract_templates/partials/**/*.handlebars' --output src/contract_wrappers/generated --backend ethers && prettier --write 'src/contract_wrappers/generated/**.ts'",
- "lint": "tslint --project .",
+ "lint": "tslint --project . --exclude **/src/contract_wrappers/**/* --exclude **/lib/**/*",
"test:circleci": "run-s test:coverage",
- "test": "run-s clean build run_mocha",
+ "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",
- "update_artifacts": "for i in ${npm_package_config_contracts}; do copyfiles -u 4 ../migrations/artifacts/1.0.0/$i.json test/artifacts; done;",
+ "update_compact_artifacts": "copyfiles -u 2 './src/compact_artifacts/**/*.json' ./lib/src/compact_artifacts",
+ "update_test_artifacts": "for i in ${npm_package_config_contracts}; do copyfiles -u 4 ../migrations/artifacts/1.0.0/$i.json test/artifacts; done;",
"clean": "shx rm -rf _bundles lib test_temp scripts test/artifacts src/contract_wrappers/generated",
- "build": "tsc && yarn update_artifacts && copyfiles -u 2 './src/compact_artifacts/**/*.json' ./lib/src/compact_artifacts && copyfiles -u 3 './lib/src/monorepo_scripts/**/*' ./scripts",
- "run_mocha": "mocha lib/test/**/*_test.js lib/test/global_hooks.js --timeout 10000 --bail --exit",
+ "run_mocha": "mocha --require source-map-support/register lib/test/**/*_test.js lib/test/global_hooks.js --timeout 10000 --bail --exit",
"manual:postpublish": "yarn build; node ./scripts/postpublish.js"
},
"config": {
@@ -67,7 +69,6 @@
"npm-run-all": "^4.1.2",
"nyc": "^11.0.1",
"opn-cli": "^3.1.0",
- "prettier": "^1.11.1",
"shx": "^0.2.2",
"sinon": "^4.0.0",
"source-map-support": "^0.5.0",
diff --git a/packages/contract-wrappers/src/abstract/abstract_balance_and_proxy_allowance_lazy_store.ts b/packages/contract-wrappers/src/abstract/abstract_balance_and_proxy_allowance_lazy_store.ts
new file mode 100644
index 000000000..1f139f1ef
--- /dev/null
+++ b/packages/contract-wrappers/src/abstract/abstract_balance_and_proxy_allowance_lazy_store.ts
@@ -0,0 +1,11 @@
+import { BigNumber } from '@0xproject/utils';
+
+export abstract class AbstractBalanceAndProxyAllowanceLazyStore {
+ public abstract async getBalanceAsync(tokenAddress: string, userAddress: string): Promise<BigNumber>;
+ public abstract async getProxyAllowanceAsync(tokenAddress: string, userAddress: string): Promise<BigNumber>;
+ public abstract setBalance(tokenAddress: string, userAddress: string, balance: BigNumber): void;
+ public abstract deleteBalance(tokenAddress: string, userAddress: string): void;
+ public abstract setProxyAllowance(tokenAddress: string, userAddress: string, proxyAllowance: BigNumber): void;
+ public abstract deleteProxyAllowance(tokenAddress: string, userAddress: string): void;
+ public abstract deleteAll(): void;
+}
diff --git a/packages/contract-wrappers/src/contract_wrappers/contract_wrapper.ts b/packages/contract-wrappers/src/contract_wrappers/contract_wrapper.ts
index f255ced62..e646bae78 100644
--- a/packages/contract-wrappers/src/contract_wrappers/contract_wrapper.ts
+++ b/packages/contract-wrappers/src/contract_wrappers/contract_wrapper.ts
@@ -7,7 +7,7 @@ import {
LogWithDecodedArgs,
RawLog,
} from '@0xproject/types';
-import { AbiDecoder, intervalUtils } from '@0xproject/utils';
+import { intervalUtils } from '@0xproject/utils';
import { Web3Wrapper } from '@0xproject/web3-wrapper';
import { Block, BlockAndLogStreamer } from 'ethereumjs-blockstream';
import * as _ from 'lodash';
@@ -185,6 +185,7 @@ export class ContractWrapper {
this._unsubscribe(filterToken, err);
});
}
+ // tslint:disable-next-line:no-unused-variable
private _setNetworkId(networkId: number): void {
this._networkId = networkId;
}
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 1bd65270b..713d4d3f6 100644
--- a/packages/contract-wrappers/src/contract_wrappers/ether_token_wrapper.ts
+++ b/packages/contract-wrappers/src/contract_wrappers/ether_token_wrapper.ts
@@ -1,6 +1,6 @@
import { schemas } from '@0xproject/json-schemas';
import { LogWithDecodedArgs } from '@0xproject/types';
-import { AbiDecoder, BigNumber } from '@0xproject/utils';
+import { BigNumber } from '@0xproject/utils';
import { Web3Wrapper } from '@0xproject/web3-wrapper';
import * as _ from 'lodash';
@@ -181,6 +181,7 @@ export class EtherTokenWrapper extends ContractWrapper {
: networkSpecificArtifact.address;
return contractAddressIfExists;
}
+ // tslint:disable-next-line:no-unused-variable
private _invalidateContractInstance(): void {
this.unsubscribeAll();
this._etherTokenContractsByAddress = {};
diff --git a/packages/contract-wrappers/src/contract_wrappers/exchange_wrapper.ts b/packages/contract-wrappers/src/contract_wrappers/exchange_wrapper.ts
index fc177dd42..430ce9c5e 100644
--- a/packages/contract-wrappers/src/contract_wrappers/exchange_wrapper.ts
+++ b/packages/contract-wrappers/src/contract_wrappers/exchange_wrapper.ts
@@ -8,18 +8,17 @@ import {
LogEntry,
LogWithDecodedArgs,
Order,
- OrderAddresses,
OrderState,
- OrderValues,
SignedOrder,
} from '@0xproject/types';
-import { AbiDecoder, BigNumber } from '@0xproject/utils';
+import { BigNumber } from '@0xproject/utils';
import { Web3Wrapper } from '@0xproject/web3-wrapper';
import * as _ from 'lodash';
import { artifacts } from '../artifacts';
import { SimpleBalanceAndProxyAllowanceFetcher } from '../fetchers/simple_balance_and_proxy_allowance_fetcher';
import { SimpleOrderFilledCancelledFetcher } from '../fetchers/simple_order_filled_cancelled_fetcher';
+import { BalanceAndProxyAllowanceLazyStore } from '../stores/balance_proxy_allowance_lazy_store';
import {
BlockRange,
EventCallback,
@@ -35,7 +34,6 @@ import { assert } from '../utils/assert';
import { decorators } from '../utils/decorators';
import { ExchangeTransferSimulator } from '../utils/exchange_transfer_simulator';
import { OrderValidationUtils } from '../utils/order_validation_utils';
-import { utils } from '../utils/utils';
import { ContractWrapper } from './contract_wrapper';
import {
@@ -57,7 +55,7 @@ interface ExchangeContractErrCodesToMsgs {
*/
export class ExchangeWrapper extends ContractWrapper {
private _exchangeContractIfExists?: ExchangeContract;
- private _orderValidationUtils: OrderValidationUtils;
+ private _orderValidationUtilsIfExists?: OrderValidationUtils;
private _tokenWrapper: TokenWrapper;
private _exchangeContractErrCodesToMsg: ExchangeContractErrCodesToMsgs = {
[ExchangeContractErrCodes.ERROR_FILL_EXPIRED]: ExchangeContractErrs.OrderFillExpired,
@@ -78,7 +76,6 @@ export class ExchangeWrapper extends ContractWrapper {
) {
super(web3Wrapper, networkId);
this._tokenWrapper = tokenWrapper;
- this._orderValidationUtils = new OrderValidationUtils(this);
this._contractAddressIfExists = contractAddressIfExists;
this._zrxContractAddressIfExists = zrxContractAddressIfExists;
}
@@ -180,8 +177,13 @@ export class ExchangeWrapper extends ContractWrapper {
: orderTransactionOpts.shouldValidate;
if (shouldValidate) {
const zrxTokenAddress = this.getZRXTokenAddress();
- const exchangeTradeEmulator = new ExchangeTransferSimulator(this._tokenWrapper, BlockParamLiteral.Latest);
- await this._orderValidationUtils.validateFillOrderThrowIfInvalidAsync(
+ const balanceAndProxyAllowanceLazyStore = new BalanceAndProxyAllowanceLazyStore(
+ this._tokenWrapper,
+ BlockParamLiteral.Latest,
+ );
+ const exchangeTradeEmulator = new ExchangeTransferSimulator(balanceAndProxyAllowanceLazyStore);
+ const orderValidationUtils = await this._getOrderValidationUtilsAsync();
+ await orderValidationUtils.validateFillOrderThrowIfInvalidAsync(
exchangeTradeEmulator,
signedOrder,
fillTakerTokenAmount,
@@ -255,9 +257,14 @@ export class ExchangeWrapper extends ContractWrapper {
if (shouldValidate) {
let filledTakerTokenAmount = new BigNumber(0);
const zrxTokenAddress = this.getZRXTokenAddress();
- const exchangeTradeEmulator = new ExchangeTransferSimulator(this._tokenWrapper, BlockParamLiteral.Latest);
+ const balanceAndProxyAllowanceLazyStore = new BalanceAndProxyAllowanceLazyStore(
+ this._tokenWrapper,
+ BlockParamLiteral.Latest,
+ );
+ const exchangeTradeEmulator = new ExchangeTransferSimulator(balanceAndProxyAllowanceLazyStore);
+ const orderValidationUtils = await this._getOrderValidationUtilsAsync();
for (const signedOrder of signedOrders) {
- const singleFilledTakerTokenAmount = await this._orderValidationUtils.validateFillOrderThrowIfInvalidAsync(
+ const singleFilledTakerTokenAmount = await orderValidationUtils.validateFillOrderThrowIfInvalidAsync(
exchangeTradeEmulator,
signedOrder,
fillTakerTokenAmount.minus(filledTakerTokenAmount),
@@ -348,9 +355,14 @@ export class ExchangeWrapper extends ContractWrapper {
: orderTransactionOpts.shouldValidate;
if (shouldValidate) {
const zrxTokenAddress = this.getZRXTokenAddress();
- const exchangeTradeEmulator = new ExchangeTransferSimulator(this._tokenWrapper, BlockParamLiteral.Latest);
+ const balanceAndProxyAllowanceLazyStore = new BalanceAndProxyAllowanceLazyStore(
+ this._tokenWrapper,
+ BlockParamLiteral.Latest,
+ );
+ const exchangeTradeEmulator = new ExchangeTransferSimulator(balanceAndProxyAllowanceLazyStore);
+ const orderValidationUtils = await this._getOrderValidationUtilsAsync();
for (const orderFillRequest of orderFillRequests) {
- await this._orderValidationUtils.validateFillOrderThrowIfInvalidAsync(
+ await orderValidationUtils.validateFillOrderThrowIfInvalidAsync(
exchangeTradeEmulator,
orderFillRequest.signedOrder,
orderFillRequest.takerTokenFillAmount,
@@ -424,8 +436,13 @@ export class ExchangeWrapper extends ContractWrapper {
: orderTransactionOpts.shouldValidate;
if (shouldValidate) {
const zrxTokenAddress = this.getZRXTokenAddress();
- const exchangeTradeEmulator = new ExchangeTransferSimulator(this._tokenWrapper, BlockParamLiteral.Latest);
- await this._orderValidationUtils.validateFillOrKillOrderThrowIfInvalidAsync(
+ const balanceAndProxyAllowanceLazyStore = new BalanceAndProxyAllowanceLazyStore(
+ this._tokenWrapper,
+ BlockParamLiteral.Latest,
+ );
+ const exchangeTradeEmulator = new ExchangeTransferSimulator(balanceAndProxyAllowanceLazyStore);
+ const orderValidationUtils = await this._getOrderValidationUtilsAsync();
+ await orderValidationUtils.validateFillOrKillOrderThrowIfInvalidAsync(
exchangeTradeEmulator,
signedOrder,
fillTakerTokenAmount,
@@ -486,9 +503,14 @@ export class ExchangeWrapper extends ContractWrapper {
: orderTransactionOpts.shouldValidate;
if (shouldValidate) {
const zrxTokenAddress = this.getZRXTokenAddress();
- const exchangeTradeEmulator = new ExchangeTransferSimulator(this._tokenWrapper, BlockParamLiteral.Latest);
+ const balanceAndProxyAllowanceLazyStore = new BalanceAndProxyAllowanceLazyStore(
+ this._tokenWrapper,
+ BlockParamLiteral.Latest,
+ );
+ const exchangeTradeEmulator = new ExchangeTransferSimulator(balanceAndProxyAllowanceLazyStore);
+ const orderValidationUtils = await this._getOrderValidationUtilsAsync();
for (const orderFillRequest of orderFillRequests) {
- await this._orderValidationUtils.validateFillOrKillOrderThrowIfInvalidAsync(
+ await orderValidationUtils.validateFillOrKillOrderThrowIfInvalidAsync(
exchangeTradeEmulator,
orderFillRequest.signedOrder,
orderFillRequest.takerTokenFillAmount,
@@ -736,8 +758,13 @@ export class ExchangeWrapper extends ContractWrapper {
assert.doesConformToSchema('signedOrder', signedOrder, schemas.signedOrderSchema);
const zrxTokenAddress = this.getZRXTokenAddress();
const expectedFillTakerTokenAmount = !_.isUndefined(opts) ? opts.expectedFillTakerTokenAmount : undefined;
- const exchangeTradeEmulator = new ExchangeTransferSimulator(this._tokenWrapper, BlockParamLiteral.Latest);
- await this._orderValidationUtils.validateOrderFillableOrThrowAsync(
+ const balanceAndProxyAllowanceLazyStore = new BalanceAndProxyAllowanceLazyStore(
+ this._tokenWrapper,
+ BlockParamLiteral.Latest,
+ );
+ const exchangeTradeEmulator = new ExchangeTransferSimulator(balanceAndProxyAllowanceLazyStore);
+ const orderValidationUtils = await this._getOrderValidationUtilsAsync();
+ await orderValidationUtils.validateOrderFillableOrThrowAsync(
exchangeTradeEmulator,
signedOrder,
zrxTokenAddress,
@@ -762,8 +789,13 @@ export class ExchangeWrapper extends ContractWrapper {
await assert.isSenderAddressAsync('takerAddress', takerAddress, this._web3Wrapper);
const normalizedTakerAddress = takerAddress.toLowerCase();
const zrxTokenAddress = this.getZRXTokenAddress();
- const exchangeTradeEmulator = new ExchangeTransferSimulator(this._tokenWrapper, BlockParamLiteral.Latest);
- await this._orderValidationUtils.validateFillOrderThrowIfInvalidAsync(
+ const balanceAndProxyAllowanceLazyStore = new BalanceAndProxyAllowanceLazyStore(
+ this._tokenWrapper,
+ BlockParamLiteral.Latest,
+ );
+ const exchangeTradeEmulator = new ExchangeTransferSimulator(balanceAndProxyAllowanceLazyStore);
+ const orderValidationUtils = await this._getOrderValidationUtilsAsync();
+ await orderValidationUtils.validateFillOrderThrowIfInvalidAsync(
exchangeTradeEmulator,
signedOrder,
fillTakerTokenAmount,
@@ -809,8 +841,13 @@ export class ExchangeWrapper extends ContractWrapper {
await assert.isSenderAddressAsync('takerAddress', takerAddress, this._web3Wrapper);
const normalizedTakerAddress = takerAddress.toLowerCase();
const zrxTokenAddress = this.getZRXTokenAddress();
- const exchangeTradeEmulator = new ExchangeTransferSimulator(this._tokenWrapper, BlockParamLiteral.Latest);
- await this._orderValidationUtils.validateFillOrKillOrderThrowIfInvalidAsync(
+ const balanceAndProxyAllowanceLazyStore = new BalanceAndProxyAllowanceLazyStore(
+ this._tokenWrapper,
+ BlockParamLiteral.Latest,
+ );
+ const exchangeTradeEmulator = new ExchangeTransferSimulator(balanceAndProxyAllowanceLazyStore);
+ const orderValidationUtils = await this._getOrderValidationUtilsAsync();
+ await orderValidationUtils.validateFillOrKillOrderThrowIfInvalidAsync(
exchangeTradeEmulator,
signedOrder,
fillTakerTokenAmount,
@@ -888,6 +925,7 @@ export class ExchangeWrapper extends ContractWrapper {
const contractAddress = this._getContractAddress(artifacts.ZRX, this._zrxContractAddressIfExists);
return contractAddress;
}
+ // tslint:disable:no-unused-variable
private _invalidateContractInstances(): void {
this.unsubscribeAll();
delete this._exchangeContractIfExists;
@@ -919,6 +957,15 @@ export class ExchangeWrapper extends ContractWrapper {
const orderHashHex = await exchangeInstance.getOrderHash.callAsync(orderAddresses, orderValues);
return orderHashHex;
}
+ private async _getOrderValidationUtilsAsync(): Promise<OrderValidationUtils> {
+ if (!_.isUndefined(this._orderValidationUtilsIfExists)) {
+ return this._orderValidationUtilsIfExists;
+ }
+ const exchangeContract = await this._getExchangeContractAsync();
+ this._orderValidationUtilsIfExists = new OrderValidationUtils(exchangeContract);
+ return this._orderValidationUtilsIfExists;
+ }
+ // tslint:enable:no-unused-variable
private async _getExchangeContractAsync(): Promise<ExchangeContract> {
if (!_.isUndefined(this._exchangeContractIfExists)) {
return this._exchangeContractIfExists;
diff --git a/packages/contract-wrappers/src/contract_wrappers/token_registry_wrapper.ts b/packages/contract-wrappers/src/contract_wrappers/token_registry_wrapper.ts
index e75973658..fb9396281 100644
--- a/packages/contract-wrappers/src/contract_wrappers/token_registry_wrapper.ts
+++ b/packages/contract-wrappers/src/contract_wrappers/token_registry_wrapper.ts
@@ -108,6 +108,7 @@ export class TokenRegistryWrapper extends ContractWrapper {
const contractAddress = this._getContractAddress(artifacts.TokenRegistry, this._contractAddressIfExists);
return contractAddress;
}
+ // tslint:disable-next-line:no-unused-variable
private _invalidateContractInstance(): void {
delete this._tokenRegistryContractIfExists;
}
diff --git a/packages/contract-wrappers/src/contract_wrappers/token_transfer_proxy_wrapper.ts b/packages/contract-wrappers/src/contract_wrappers/token_transfer_proxy_wrapper.ts
index 02a2e19d0..2fe3e6620 100644
--- a/packages/contract-wrappers/src/contract_wrappers/token_transfer_proxy_wrapper.ts
+++ b/packages/contract-wrappers/src/contract_wrappers/token_transfer_proxy_wrapper.ts
@@ -49,6 +49,7 @@ export class TokenTransferProxyWrapper extends ContractWrapper {
const contractAddress = this._getContractAddress(artifacts.TokenTransferProxy, this._contractAddressIfExists);
return contractAddress;
}
+ // tslint:disable-next-line:no-unused-variable
private _invalidateContractInstance(): void {
delete this._tokenTransferProxyContractIfExists;
}
diff --git a/packages/contract-wrappers/src/contract_wrappers/token_wrapper.ts b/packages/contract-wrappers/src/contract_wrappers/token_wrapper.ts
index 844318c79..7c7907fd2 100644
--- a/packages/contract-wrappers/src/contract_wrappers/token_wrapper.ts
+++ b/packages/contract-wrappers/src/contract_wrappers/token_wrapper.ts
@@ -1,6 +1,6 @@
import { schemas } from '@0xproject/json-schemas';
import { LogWithDecodedArgs } from '@0xproject/types';
-import { AbiDecoder, BigNumber } from '@0xproject/utils';
+import { BigNumber } from '@0xproject/utils';
import { Web3Wrapper } from '@0xproject/web3-wrapper';
import * as _ from 'lodash';
@@ -414,6 +414,7 @@ export class TokenWrapper extends ContractWrapper {
);
return logs;
}
+ // tslint:disable-next-line:no-unused-variable
private _invalidateContractInstances(): void {
this.unsubscribeAll();
this._tokenContractsByAddress = {};
diff --git a/packages/contract-wrappers/src/stores/balance_proxy_allowance_lazy_store.ts b/packages/contract-wrappers/src/stores/balance_proxy_allowance_lazy_store.ts
index 614195157..c0250ce7c 100644
--- a/packages/contract-wrappers/src/stores/balance_proxy_allowance_lazy_store.ts
+++ b/packages/contract-wrappers/src/stores/balance_proxy_allowance_lazy_store.ts
@@ -1,14 +1,14 @@
-import { AbstractBalanceAndProxyAllowanceFetcher } from '@0xproject/order-utils';
import { BlockParamLiteral } from '@0xproject/types';
import { BigNumber } from '@0xproject/utils';
import * as _ from 'lodash';
+import { AbstractBalanceAndProxyAllowanceLazyStore } from '../abstract/abstract_balance_and_proxy_allowance_lazy_store';
import { TokenWrapper } from '../contract_wrappers/token_wrapper';
/**
* Copy on read store for balances/proxyAllowances of tokens/accounts
*/
-export class BalanceAndProxyAllowanceLazyStore implements AbstractBalanceAndProxyAllowanceFetcher {
+export class BalanceAndProxyAllowanceLazyStore implements AbstractBalanceAndProxyAllowanceLazyStore {
private _tokenWrapper: TokenWrapper;
private _defaultBlock: BlockParamLiteral;
private _balance: {
diff --git a/packages/contract-wrappers/src/types.ts b/packages/contract-wrappers/src/types.ts
index 9a463d635..0c1c58486 100644
--- a/packages/contract-wrappers/src/types.ts
+++ b/packages/contract-wrappers/src/types.ts
@@ -2,11 +2,7 @@ import { BigNumber } from '@0xproject/utils';
import {
BlockParam,
- BlockParamLiteral,
- ContractAbi,
ContractEventArg,
- ExchangeContractErrs,
- FilterObject,
LogEntryEvent,
LogWithDecodedArgs,
Order,
@@ -158,7 +154,7 @@ export interface MethodOpts {
/**
* gasPrice: Gas price in Wei to use for a transaction
- * gasLimit: The amount of gas to send with a transaction
+ * gasLimit: The amount of gas to send with a transaction (in Gwei)
*/
export interface TransactionOpts {
gasPrice?: BigNumber;
diff --git a/packages/contract-wrappers/src/utils/assert.ts b/packages/contract-wrappers/src/utils/assert.ts
index c74ed341f..140979e7e 100644
--- a/packages/contract-wrappers/src/utils/assert.ts
+++ b/packages/contract-wrappers/src/utils/assert.ts
@@ -1,12 +1,11 @@
import { assert as sharedAssert } from '@0xproject/assert';
// We need those two unused imports because they're actually used by sharedAssert which gets injected here
-// tslint:disable-next-line:no-unused-variable
+// tslint:disable:no-unused-variable
import { Schema } from '@0xproject/json-schemas';
-// tslint:disable-next-line:no-unused-variable
import { ECSignature } from '@0xproject/types';
import { BigNumber } from '@0xproject/utils';
import { Web3Wrapper } from '@0xproject/web3-wrapper';
-import * as _ from 'lodash';
+// tslint:enable:no-unused-variable
import { isValidSignature } from '@0xproject/order-utils';
diff --git a/packages/contract-wrappers/src/utils/exchange_transfer_simulator.ts b/packages/contract-wrappers/src/utils/exchange_transfer_simulator.ts
index b575285a1..527b8575d 100644
--- a/packages/contract-wrappers/src/utils/exchange_transfer_simulator.ts
+++ b/packages/contract-wrappers/src/utils/exchange_transfer_simulator.ts
@@ -1,9 +1,8 @@
import { BlockParamLiteral, ExchangeContractErrs } from '@0xproject/types';
import { BigNumber } from '@0xproject/utils';
-import * as _ from 'lodash';
+import { AbstractBalanceAndProxyAllowanceLazyStore } from '../abstract/abstract_balance_and_proxy_allowance_lazy_store';
import { TokenWrapper } from '../contract_wrappers/token_wrapper';
-import { BalanceAndProxyAllowanceLazyStore } from '../stores/balance_proxy_allowance_lazy_store';
import { TradeSide, TransferType } from '../types';
import { constants } from '../utils/constants';
@@ -36,8 +35,7 @@ const ERR_MSG_MAPPING = {
};
export class ExchangeTransferSimulator {
- private _store: BalanceAndProxyAllowanceLazyStore;
- private _UNLIMITED_ALLOWANCE_IN_BASE_UNITS: BigNumber;
+ private _store: AbstractBalanceAndProxyAllowanceLazyStore;
private static _throwValidationError(
failureReason: FailureReason,
tradeSide: TradeSide,
@@ -46,9 +44,8 @@ export class ExchangeTransferSimulator {
const errMsg = ERR_MSG_MAPPING[failureReason][tradeSide][transferType];
throw new Error(errMsg);
}
- constructor(token: TokenWrapper, defaultBlock: BlockParamLiteral) {
- this._store = new BalanceAndProxyAllowanceLazyStore(token, defaultBlock);
- this._UNLIMITED_ALLOWANCE_IN_BASE_UNITS = token.UNLIMITED_ALLOWANCE_IN_BASE_UNITS;
+ constructor(store: AbstractBalanceAndProxyAllowanceLazyStore) {
+ this._store = store;
}
/**
* Simulates transferFrom call performed by a proxy
@@ -92,7 +89,7 @@ export class ExchangeTransferSimulator {
amountInBaseUnits: BigNumber,
): Promise<void> {
const proxyAllowance = await this._store.getProxyAllowanceAsync(tokenAddress, userAddress);
- if (!proxyAllowance.eq(this._UNLIMITED_ALLOWANCE_IN_BASE_UNITS)) {
+ if (!proxyAllowance.eq(constants.UNLIMITED_ALLOWANCE_IN_BASE_UNITS)) {
this._store.setProxyAllowance(tokenAddress, userAddress, proxyAllowance.minus(amountInBaseUnits));
}
}
diff --git a/packages/contract-wrappers/src/utils/filter_utils.ts b/packages/contract-wrappers/src/utils/filter_utils.ts
index 4ec9e256b..5256d010f 100644
--- a/packages/contract-wrappers/src/utils/filter_utils.ts
+++ b/packages/contract-wrappers/src/utils/filter_utils.ts
@@ -1,3 +1,4 @@
+// tslint:disable:no-unused-variable
import {
ConstructorAbi,
ContractAbi,
@@ -7,6 +8,7 @@ import {
LogEntry,
MethodAbi,
} from '@0xproject/types';
+// tslint:enable:no-unused-variable
import * as ethUtil from 'ethereumjs-util';
import * as jsSHA3 from 'js-sha3';
import * as _ from 'lodash';
diff --git a/packages/contract-wrappers/src/utils/order_validation_utils.ts b/packages/contract-wrappers/src/utils/order_validation_utils.ts
index 362c605de..c6ef26275 100644
--- a/packages/contract-wrappers/src/utils/order_validation_utils.ts
+++ b/packages/contract-wrappers/src/utils/order_validation_utils.ts
@@ -3,15 +3,15 @@ import { ExchangeContractErrs, Order, SignedOrder } from '@0xproject/types';
import { BigNumber } from '@0xproject/utils';
import * as _ from 'lodash';
-import { ExchangeWrapper } from '../contract_wrappers/exchange_wrapper';
-import { ContractWrappersError, TradeSide, TransferType } from '../types';
+import { ExchangeContract } from '../contract_wrappers/generated/exchange';
+import { TradeSide, TransferType } from '../types';
import { constants } from '../utils/constants';
import { utils } from '../utils/utils';
import { ExchangeTransferSimulator } from './exchange_transfer_simulator';
export class OrderValidationUtils {
- private _exchangeWrapper: ExchangeWrapper;
+ private _exchangeContract: ExchangeContract;
public static validateCancelOrderThrowIfInvalid(
order: Order,
cancelTakerTokenAmount: BigNumber,
@@ -104,8 +104,8 @@ export class OrderValidationUtils {
.round(0);
return fillMakerTokenAmount;
}
- constructor(exchangeWrapper: ExchangeWrapper) {
- this._exchangeWrapper = exchangeWrapper;
+ constructor(exchangeContract: ExchangeContract) {
+ this._exchangeContract = exchangeContract;
}
public async validateOrderFillableOrThrowAsync(
exchangeTradeEmulator: ExchangeTransferSimulator,
@@ -114,7 +114,9 @@ export class OrderValidationUtils {
expectedFillTakerTokenAmount?: BigNumber,
): Promise<void> {
const orderHash = getOrderHashHex(signedOrder);
- const unavailableTakerTokenAmount = await this._exchangeWrapper.getUnavailableTakerAmountAsync(orderHash);
+ const unavailableTakerTokenAmount = await this._exchangeContract.getUnavailableTakerTokenAmount.callAsync(
+ orderHash,
+ );
OrderValidationUtils._validateRemainingFillAmountNotZeroOrThrow(
signedOrder.takerTokenAmount,
unavailableTakerTokenAmount,
@@ -146,7 +148,9 @@ export class OrderValidationUtils {
if (!isValidSignature(orderHash, signedOrder.ecSignature, signedOrder.maker)) {
throw new Error(OrderError.InvalidSignature);
}
- const unavailableTakerTokenAmount = await this._exchangeWrapper.getUnavailableTakerAmountAsync(orderHash);
+ const unavailableTakerTokenAmount = await this._exchangeContract.getUnavailableTakerTokenAmount.callAsync(
+ orderHash,
+ );
OrderValidationUtils._validateRemainingFillAmountNotZeroOrThrow(
signedOrder.takerTokenAmount,
unavailableTakerTokenAmount,
@@ -167,7 +171,7 @@ export class OrderValidationUtils {
zrxTokenAddress,
);
- const wouldRoundingErrorOccur = await this._exchangeWrapper.isRoundingErrorAsync(
+ const wouldRoundingErrorOccur = await this._exchangeContract.isRoundingError.callAsync(
filledTakerTokenAmount,
signedOrder.takerTokenAmount,
signedOrder.makerTokenAmount,
diff --git a/packages/contract-wrappers/src/utils/utils.ts b/packages/contract-wrappers/src/utils/utils.ts
index 7cf9450a0..689a7ee0a 100644
--- a/packages/contract-wrappers/src/utils/utils.ts
+++ b/packages/contract-wrappers/src/utils/utils.ts
@@ -1,9 +1,6 @@
import { BigNumber } from '@0xproject/utils';
export const utils = {
- spawnSwitchErr(name: string, value: any): Error {
- return new Error(`Unexpected switch value: ${value} encountered for ${name}`);
- },
getCurrentUnixTimestampSec(): BigNumber {
const milisecondsInSecond = 1000;
return new BigNumber(Date.now() / milisecondsInSecond).round();
diff --git a/packages/contract-wrappers/test/artifacts_test.ts b/packages/contract-wrappers/test/artifacts_test.ts
index eaaa89c48..34e6bbde8 100644
--- a/packages/contract-wrappers/test/artifacts_test.ts
+++ b/packages/contract-wrappers/test/artifacts_test.ts
@@ -1,5 +1,4 @@
import { web3Factory } from '@0xproject/dev-utils';
-import * as fs from 'fs';
import 'make-promises-safe';
import { ContractWrappers } from '../src';
diff --git a/packages/contract-wrappers/test/ether_token_wrapper_test.ts b/packages/contract-wrappers/test/ether_token_wrapper_test.ts
index a2154c2bd..d08f26c53 100644
--- a/packages/contract-wrappers/test/ether_token_wrapper_test.ts
+++ b/packages/contract-wrappers/test/ether_token_wrapper_test.ts
@@ -1,4 +1,4 @@
-import { BlockchainLifecycle, callbackErrorReporter, devConstants, web3Factory } from '@0xproject/dev-utils';
+import { BlockchainLifecycle, callbackErrorReporter } from '@0xproject/dev-utils';
import { DoneCallback } from '@0xproject/types';
import { BigNumber } from '@0xproject/utils';
import { Web3Wrapper } from '@0xproject/web3-wrapper';
diff --git a/packages/contract-wrappers/test/exchange_transfer_simulator_test.ts b/packages/contract-wrappers/test/exchange_transfer_simulator_test.ts
index cf7520ea0..1690eb392 100644
--- a/packages/contract-wrappers/test/exchange_transfer_simulator_test.ts
+++ b/packages/contract-wrappers/test/exchange_transfer_simulator_test.ts
@@ -1,10 +1,11 @@
-import { BlockchainLifecycle, devConstants } from '@0xproject/dev-utils';
+import { BlockchainLifecycle } from '@0xproject/dev-utils';
import { BlockParamLiteral, Token } from '@0xproject/types';
import { BigNumber } from '@0xproject/utils';
import * as chai from 'chai';
import 'make-promises-safe';
import { ContractWrappers, ExchangeContractErrs } from '../src';
+import { BalanceAndProxyAllowanceLazyStore } from '../src/stores/balance_proxy_allowance_lazy_store';
import { TradeSide, TransferType } from '../src/types';
import { ExchangeTransferSimulator } from '../src/utils/exchange_transfer_simulator';
@@ -44,7 +45,11 @@ describe('ExchangeTransferSimulator', () => {
});
describe('#transferFromAsync', () => {
beforeEach(() => {
- exchangeTransferSimulator = new ExchangeTransferSimulator(contractWrappers.token, BlockParamLiteral.Latest);
+ const balanceAndProxyAllowanceLazyStore = new BalanceAndProxyAllowanceLazyStore(
+ contractWrappers.token,
+ BlockParamLiteral.Latest,
+ );
+ exchangeTransferSimulator = new ExchangeTransferSimulator(balanceAndProxyAllowanceLazyStore);
});
it("throws if the user doesn't have enough allowance", async () => {
return expect(
diff --git a/packages/contract-wrappers/test/exchange_wrapper_test.ts b/packages/contract-wrappers/test/exchange_wrapper_test.ts
index d35d2b819..a418f5f22 100644
--- a/packages/contract-wrappers/test/exchange_wrapper_test.ts
+++ b/packages/contract-wrappers/test/exchange_wrapper_test.ts
@@ -1,11 +1,10 @@
-import { BlockchainLifecycle, callbackErrorReporter, devConstants, web3Factory } from '@0xproject/dev-utils';
+import { BlockchainLifecycle, callbackErrorReporter } from '@0xproject/dev-utils';
import { FillScenarios } from '@0xproject/fill-scenarios';
import { getOrderHashHex } from '@0xproject/order-utils';
import { BlockParamLiteral, DoneCallback, OrderState } from '@0xproject/types';
import { BigNumber } from '@0xproject/utils';
import { Web3Wrapper } from '@0xproject/web3-wrapper';
import * as chai from 'chai';
-import * as _ from 'lodash';
import 'make-promises-safe';
import 'mocha';
diff --git a/packages/contract-wrappers/test/global_hooks.ts b/packages/contract-wrappers/test/global_hooks.ts
index 6d2c3219b..52a384ada 100644
--- a/packages/contract-wrappers/test/global_hooks.ts
+++ b/packages/contract-wrappers/test/global_hooks.ts
@@ -1,14 +1,12 @@
import { devConstants } from '@0xproject/dev-utils';
import { runV1MigrationsAsync } from '@0xproject/migrations';
-import * as path from 'path';
-import { constants } from './utils/constants';
import { provider } from './utils/web3_wrapper';
before('migrate contracts', 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 = 20000;
+ const mochaTestTimeoutMs = 50000;
this.timeout(mochaTestTimeoutMs);
const txDefaults = {
gas: devConstants.GAS_LIMIT,
diff --git a/packages/contract-wrappers/test/order_validation_test.ts b/packages/contract-wrappers/test/order_validation_test.ts
index a14dc24b6..b88684dd0 100644
--- a/packages/contract-wrappers/test/order_validation_test.ts
+++ b/packages/contract-wrappers/test/order_validation_test.ts
@@ -1,4 +1,4 @@
-import { BlockchainLifecycle, devConstants } from '@0xproject/dev-utils';
+import { BlockchainLifecycle } from '@0xproject/dev-utils';
import { FillScenarios } from '@0xproject/fill-scenarios';
import { OrderError } from '@0xproject/order-utils';
import { BlockParamLiteral } from '@0xproject/types';
@@ -7,7 +7,8 @@ import * as chai from 'chai';
import 'make-promises-safe';
import * as Sinon from 'sinon';
-import { ContractWrappers, ContractWrappersError, ExchangeContractErrs, SignedOrder, Token } from '../src';
+import { ContractWrappers, ExchangeContractErrs, SignedOrder, Token } from '../src';
+import { BalanceAndProxyAllowanceLazyStore } from '../src/stores/balance_proxy_allowance_lazy_store';
import { TradeSide, TransferType } from '../src/types';
import { ExchangeTransferSimulator } from '../src/utils/exchange_transfer_simulator';
import { OrderValidationUtils } from '../src/utils/order_validation_utils';
@@ -332,7 +333,11 @@ describe('OrderValidation', () => {
return Sinon.match((value: BigNumber) => value.eq(expected));
};
beforeEach('create exchangeTransferSimulator', async () => {
- exchangeTransferSimulator = new ExchangeTransferSimulator(contractWrappers.token, BlockParamLiteral.Latest);
+ const balanceAndProxyAllowanceLazyStore = new BalanceAndProxyAllowanceLazyStore(
+ contractWrappers.token,
+ BlockParamLiteral.Latest,
+ );
+ exchangeTransferSimulator = new ExchangeTransferSimulator(balanceAndProxyAllowanceLazyStore);
transferFromAsync = Sinon.spy();
exchangeTransferSimulator.transferFromAsync = transferFromAsync as any;
});
diff --git a/packages/contract-wrappers/test/subscription_test.ts b/packages/contract-wrappers/test/subscription_test.ts
index 65c76e47f..3232fd03c 100644
--- a/packages/contract-wrappers/test/subscription_test.ts
+++ b/packages/contract-wrappers/test/subscription_test.ts
@@ -1,4 +1,4 @@
-import { BlockchainLifecycle, callbackErrorReporter, devConstants } from '@0xproject/dev-utils';
+import { BlockchainLifecycle, callbackErrorReporter } from '@0xproject/dev-utils';
import { DoneCallback } from '@0xproject/types';
import { BigNumber } from '@0xproject/utils';
import * as _ from 'lodash';
diff --git a/packages/contract-wrappers/test/token_registry_wrapper_test.ts b/packages/contract-wrappers/test/token_registry_wrapper_test.ts
index 0e9ddd245..e2881d022 100644
--- a/packages/contract-wrappers/test/token_registry_wrapper_test.ts
+++ b/packages/contract-wrappers/test/token_registry_wrapper_test.ts
@@ -1,4 +1,4 @@
-import { BlockchainLifecycle, devConstants } from '@0xproject/dev-utils';
+import { BlockchainLifecycle } from '@0xproject/dev-utils';
import { schemas, SchemaValidator } from '@0xproject/json-schemas';
import * as chai from 'chai';
import * as _ from 'lodash';
diff --git a/packages/contract-wrappers/test/token_wrapper_test.ts b/packages/contract-wrappers/test/token_wrapper_test.ts
index 12bf72d85..6cb1869fc 100644
--- a/packages/contract-wrappers/test/token_wrapper_test.ts
+++ b/packages/contract-wrappers/test/token_wrapper_test.ts
@@ -1,4 +1,4 @@
-import { BlockchainLifecycle, callbackErrorReporter, devConstants } from '@0xproject/dev-utils';
+import { BlockchainLifecycle, callbackErrorReporter } from '@0xproject/dev-utils';
import { EmptyWalletSubprovider } from '@0xproject/subproviders';
import { DoneCallback, Provider } from '@0xproject/types';
import { BigNumber } from '@0xproject/utils';
@@ -218,7 +218,6 @@ describe('TokenWrapper', () => {
describe('With provider without accounts', () => {
let zeroExContractWithoutAccounts: ContractWrappers;
before(async () => {
- const hasAddresses = false;
const emptyWalletProvider = addEmptyWalletSubprovider(provider);
zeroExContractWithoutAccounts = new ContractWrappers(emptyWalletProvider, config);
});
@@ -361,7 +360,6 @@ describe('TokenWrapper', () => {
describe('With provider without accounts', () => {
let zeroExContractWithoutAccounts: ContractWrappers;
before(async () => {
- const hasAddresses = false;
const emptyWalletProvider = addEmptyWalletSubprovider(provider);
zeroExContractWithoutAccounts = new ContractWrappers(emptyWalletProvider, config);
});
diff --git a/packages/contract-wrappers/test/utils/web3_wrapper.ts b/packages/contract-wrappers/test/utils/web3_wrapper.ts
index 71a0dc1c2..f7d11f138 100644
--- a/packages/contract-wrappers/test/utils/web3_wrapper.ts
+++ b/packages/contract-wrappers/test/utils/web3_wrapper.ts
@@ -1,4 +1,4 @@
-import { devConstants, web3Factory } from '@0xproject/dev-utils';
+import { web3Factory } from '@0xproject/dev-utils';
import { Provider } from '@0xproject/types';
import { Web3Wrapper } from '@0xproject/web3-wrapper';