aboutsummaryrefslogtreecommitdiffstats
path: root/packages
diff options
context:
space:
mode:
Diffstat (limited to 'packages')
-rw-r--r--packages/0x.js/src/index.ts1
-rw-r--r--packages/contract-wrappers/CHANGELOG.json8
-rw-r--r--packages/contract-wrappers/src/contract_wrappers/forwarder_wrapper.ts122
-rw-r--r--packages/contract-wrappers/test/forwarder_wrapper_test.ts48
-rw-r--r--packages/order-watcher/CHANGELOG.json9
-rw-r--r--packages/order-watcher/src/index.ts1
-rw-r--r--packages/order-watcher/src/order_watcher/order_watcher.ts10
-rw-r--r--packages/order-watcher/test/order_watcher_test.ts17
-rw-r--r--packages/types/src/index.ts4
-rw-r--r--packages/website/package.json1
-rw-r--r--packages/website/ts/utils/error_reporter.ts5
11 files changed, 185 insertions, 41 deletions
diff --git a/packages/0x.js/src/index.ts b/packages/0x.js/src/index.ts
index 6eb1fd8ee..ce3f616aa 100644
--- a/packages/0x.js/src/index.ts
+++ b/packages/0x.js/src/index.ts
@@ -78,6 +78,7 @@ export {
ERC721AssetData,
SignatureType,
OrderRelevantState,
+ Stats,
} from '@0xproject/types';
export {
diff --git a/packages/contract-wrappers/CHANGELOG.json b/packages/contract-wrappers/CHANGELOG.json
index a96cb3a59..0770b6c0d 100644
--- a/packages/contract-wrappers/CHANGELOG.json
+++ b/packages/contract-wrappers/CHANGELOG.json
@@ -1,5 +1,13 @@
[
{
+ "version": "2.1.0",
+ "changes": [
+ {
+ "note": "Add optional validation to the forwarder wrapper methods"
+ }
+ ]
+ },
+ {
"version": "2.0.2",
"changes": [
{
diff --git a/packages/contract-wrappers/src/contract_wrappers/forwarder_wrapper.ts b/packages/contract-wrappers/src/contract_wrappers/forwarder_wrapper.ts
index 906222731..c19edf188 100644
--- a/packages/contract-wrappers/src/contract_wrappers/forwarder_wrapper.ts
+++ b/packages/contract-wrappers/src/contract_wrappers/forwarder_wrapper.ts
@@ -8,10 +8,11 @@ import * as _ from 'lodash';
import { artifacts } from '../artifacts';
import { orderTxOptsSchema } from '../schemas/order_tx_opts_schema';
import { txOptsSchema } from '../schemas/tx_opts_schema';
-import { TransactionOpts } from '../types';
+import { OrderTransactionOpts } from '../types';
import { assert } from '../utils/assert';
import { calldataOptimizationUtils } from '../utils/calldata_optimization_utils';
import { constants } from '../utils/constants';
+import { decorators } from '../utils/decorators';
import { utils } from '../utils/utils';
import { ContractWrapper } from './contract_wrapper';
@@ -40,19 +41,20 @@ export class ForwarderWrapper extends ContractWrapper {
* Any ZRX required to pay fees for primary orders will automatically be purchased by this contract.
* 5% of ETH value is reserved for paying fees to order feeRecipients (in ZRX) and forwarding contract feeRecipient (in ETH).
* Any ETH not spent will be refunded to sender.
- * @param signedOrders An array of objects that conform to the SignedOrder interface. All orders must specify the same makerAsset.
- * All orders must specify WETH as the takerAsset
- * @param takerAddress The user Ethereum address who would like to fill this order. Must be available via the supplied
- * Provider provided at instantiation.
- * @param ethAmount The amount of eth to send with the transaction (in wei).
- * @param signedFeeOrders An array of objects that conform to the SignedOrder interface. All orders must specify ZRX as makerAsset and WETH as takerAsset.
- * Used to purchase ZRX for primary order fees.
- * @param feePercentage The percentage of WETH sold that will payed as fee to forwarding contract feeRecipient.
- * Defaults to 0.
- * @param feeRecipientAddress The address that will receive ETH when signedFeeOrders are filled.
- * @param txOpts Transaction parameters.
+ * @param signedOrders An array of objects that conform to the SignedOrder interface. All orders must specify the same makerAsset.
+ * All orders must specify WETH as the takerAsset
+ * @param takerAddress The user Ethereum address who would like to fill this order. Must be available via the supplied
+ * Provider provided at instantiation.
+ * @param ethAmount The amount of eth to send with the transaction (in wei).
+ * @param signedFeeOrders An array of objects that conform to the SignedOrder interface. All orders must specify ZRX as makerAsset and WETH as takerAsset.
+ * Used to purchase ZRX for primary order fees.
+ * @param feePercentage The percentage of WETH sold that will payed as fee to forwarding contract feeRecipient.
+ * Defaults to 0.
+ * @param feeRecipientAddress The address that will receive ETH when signedFeeOrders are filled.
+ * @param orderTransactionOpts Transaction parameters.
* @return Transaction hash.
*/
+ @decorators.asyncZeroExErrorHandler
public async marketSellOrdersWithEthAsync(
signedOrders: SignedOrder[],
takerAddress: string,
@@ -60,7 +62,7 @@ export class ForwarderWrapper extends ContractWrapper {
signedFeeOrders: SignedOrder[] = [],
feePercentage: number = 0,
feeRecipientAddress: string = constants.NULL_ADDRESS,
- txOpts: TransactionOpts = {},
+ orderTransactionOpts: OrderTransactionOpts = { shouldValidate: true },
): Promise<string> {
// type assertions
assert.doesConformToSchema('signedOrders', signedOrders, schemas.signedOrdersSchema);
@@ -69,7 +71,7 @@ export class ForwarderWrapper extends ContractWrapper {
assert.doesConformToSchema('signedFeeOrders', signedFeeOrders, schemas.signedOrdersSchema);
assert.isNumber('feePercentage', feePercentage);
assert.isETHAddressHex('feeRecipientAddress', feeRecipientAddress);
- assert.doesConformToSchema('txOpts', txOpts, txOptsSchema);
+ assert.doesConformToSchema('orderTransactionOpts', orderTransactionOpts, orderTxOptsSchema, [txOptsSchema]);
// other assertions
assert.ordersCanBeUsedForForwarderContract(signedOrders, this.getEtherTokenAddress());
assert.feeOrdersCanBeUsedForForwarderContract(
@@ -85,20 +87,41 @@ export class ForwarderWrapper extends ContractWrapper {
// optimize orders
const optimizedMarketOrders = calldataOptimizationUtils.optimizeForwarderOrders(signedOrders);
const optimizedFeeOrders = calldataOptimizationUtils.optimizeForwarderFeeOrders(signedFeeOrders);
- // send transaction
+ // compile signatures
+ const signatures = _.map(optimizedMarketOrders, order => order.signature);
+ const feeSignatures = _.map(optimizedFeeOrders, order => order.signature);
+ // get contract
const forwarderContractInstance = await this._getForwarderContractAsync();
+ // validate transaction
+ if (orderTransactionOpts.shouldValidate) {
+ await forwarderContractInstance.marketSellOrdersWithEth.callAsync(
+ optimizedMarketOrders,
+ signatures,
+ optimizedFeeOrders,
+ feeSignatures,
+ formattedFeePercentage,
+ feeRecipientAddress,
+ {
+ value: ethAmount,
+ from: normalizedTakerAddress,
+ gas: orderTransactionOpts.gasLimit,
+ gasPrice: orderTransactionOpts.gasPrice,
+ },
+ );
+ }
+ // send transaction
const txHash = await forwarderContractInstance.marketSellOrdersWithEth.sendTransactionAsync(
optimizedMarketOrders,
- _.map(optimizedMarketOrders, order => order.signature),
+ signatures,
optimizedFeeOrders,
- _.map(optimizedFeeOrders, order => order.signature),
+ feeSignatures,
formattedFeePercentage,
feeRecipientAddress,
{
value: ethAmount,
from: normalizedTakerAddress,
- gas: txOpts.gasLimit,
- gasPrice: txOpts.gasPrice,
+ gas: orderTransactionOpts.gasLimit,
+ gasPrice: orderTransactionOpts.gasPrice,
},
);
return txHash;
@@ -107,20 +130,21 @@ export class ForwarderWrapper extends ContractWrapper {
* Attempt to purchase makerAssetFillAmount of makerAsset by selling ethAmount provided with transaction.
* Any ZRX required to pay fees for primary orders will automatically be purchased by the contract.
* Any ETH not spent will be refunded to sender.
- * @param signedOrders An array of objects that conform to the SignedOrder interface. All orders must specify the same makerAsset.
- * All orders must specify WETH as the takerAsset
- * @param makerAssetFillAmount The amount of the order (in taker asset baseUnits) that you wish to fill.
- * @param takerAddress The user Ethereum address who would like to fill this order. Must be available via the supplied
- * Provider provided at instantiation.
- * @param ethAmount The amount of eth to send with the transaction (in wei).
- * @param signedFeeOrders An array of objects that conform to the SignedOrder interface. All orders must specify ZRX as makerAsset and WETH as takerAsset.
- * Used to purchase ZRX for primary order fees.
- * @param feePercentage The percentage of WETH sold that will payed as fee to forwarding contract feeRecipient.
- * Defaults to 0.
- * @param feeRecipientAddress The address that will receive ETH when signedFeeOrders are filled.
- * @param txOpts Transaction parameters.
+ * @param signedOrders An array of objects that conform to the SignedOrder interface. All orders must specify the same makerAsset.
+ * All orders must specify WETH as the takerAsset
+ * @param makerAssetFillAmount The amount of the order (in taker asset baseUnits) that you wish to fill.
+ * @param takerAddress The user Ethereum address who would like to fill this order. Must be available via the supplied
+ * Provider provided at instantiation.
+ * @param ethAmount The amount of eth to send with the transaction (in wei).
+ * @param signedFeeOrders An array of objects that conform to the SignedOrder interface. All orders must specify ZRX as makerAsset and WETH as takerAsset.
+ * Used to purchase ZRX for primary order fees.
+ * @param feePercentage The percentage of WETH sold that will payed as fee to forwarding contract feeRecipient.
+ * Defaults to 0.
+ * @param feeRecipientAddress The address that will receive ETH when signedFeeOrders are filled.
+ * @param orderTransactionOpts Transaction parameters.
* @return Transaction hash.
*/
+ @decorators.asyncZeroExErrorHandler
public async marketBuyOrdersWithEthAsync(
signedOrders: SignedOrder[],
makerAssetFillAmount: BigNumber,
@@ -129,7 +153,7 @@ export class ForwarderWrapper extends ContractWrapper {
signedFeeOrders: SignedOrder[] = [],
feePercentage: number = 0,
feeRecipientAddress: string = constants.NULL_ADDRESS,
- txOpts: TransactionOpts = {},
+ orderTransactionOpts: OrderTransactionOpts = { shouldValidate: true },
): Promise<string> {
// type assertions
assert.doesConformToSchema('signedOrders', signedOrders, schemas.signedOrdersSchema);
@@ -139,7 +163,7 @@ export class ForwarderWrapper extends ContractWrapper {
assert.doesConformToSchema('signedFeeOrders', signedFeeOrders, schemas.signedOrdersSchema);
assert.isNumber('feePercentage', feePercentage);
assert.isETHAddressHex('feeRecipientAddress', feeRecipientAddress);
- assert.doesConformToSchema('txOpts', txOpts, txOptsSchema);
+ assert.doesConformToSchema('orderTransactionOpts', orderTransactionOpts, orderTxOptsSchema, [txOptsSchema]);
// other assertions
assert.ordersCanBeUsedForForwarderContract(signedOrders, this.getEtherTokenAddress());
assert.feeOrdersCanBeUsedForForwarderContract(
@@ -155,21 +179,43 @@ export class ForwarderWrapper extends ContractWrapper {
// optimize orders
const optimizedMarketOrders = calldataOptimizationUtils.optimizeForwarderOrders(signedOrders);
const optimizedFeeOrders = calldataOptimizationUtils.optimizeForwarderFeeOrders(signedFeeOrders);
- // send transaction
+ // compile signatures
+ const signatures = _.map(optimizedMarketOrders, order => order.signature);
+ const feeSignatures = _.map(optimizedFeeOrders, order => order.signature);
+ // get contract
const forwarderContractInstance = await this._getForwarderContractAsync();
+ // validate transaction
+ if (orderTransactionOpts.shouldValidate) {
+ await forwarderContractInstance.marketBuyOrdersWithEth.callAsync(
+ optimizedMarketOrders,
+ makerAssetFillAmount,
+ signatures,
+ optimizedFeeOrders,
+ feeSignatures,
+ formattedFeePercentage,
+ feeRecipientAddress,
+ {
+ value: ethAmount,
+ from: normalizedTakerAddress,
+ gas: orderTransactionOpts.gasLimit,
+ gasPrice: orderTransactionOpts.gasPrice,
+ },
+ );
+ }
+ // send transaction
const txHash = await forwarderContractInstance.marketBuyOrdersWithEth.sendTransactionAsync(
optimizedMarketOrders,
makerAssetFillAmount,
- _.map(optimizedMarketOrders, order => order.signature),
+ signatures,
optimizedFeeOrders,
- _.map(optimizedFeeOrders, order => order.signature),
+ feeSignatures,
formattedFeePercentage,
feeRecipientAddress,
{
value: ethAmount,
from: normalizedTakerAddress,
- gas: txOpts.gasLimit,
- gasPrice: txOpts.gasPrice,
+ gas: orderTransactionOpts.gasLimit,
+ gasPrice: orderTransactionOpts.gasPrice,
},
);
return txHash;
diff --git a/packages/contract-wrappers/test/forwarder_wrapper_test.ts b/packages/contract-wrappers/test/forwarder_wrapper_test.ts
index f77b47337..4329e8770 100644
--- a/packages/contract-wrappers/test/forwarder_wrapper_test.ts
+++ b/packages/contract-wrappers/test/forwarder_wrapper_test.ts
@@ -17,6 +17,7 @@ chaiSetup.configure();
const expect = chai.expect;
const blockchainLifecycle = new BlockchainLifecycle(web3Wrapper);
+// tslint:disable:custom-no-magic-numbers
describe('ForwarderWrapper', () => {
const contractWrappersConfig = {
networkId: constants.TESTRPC_NETWORK_ID,
@@ -99,6 +100,25 @@ describe('ForwarderWrapper', () => {
expect(ordersInfo[0].orderStatus).to.be.equal(OrderStatus.FULLY_FILLED);
expect(ordersInfo[1].orderStatus).to.be.equal(OrderStatus.FULLY_FILLED);
});
+ it('should throw when invalid transaction and shouldValidate is true', async () => {
+ const signedOrders = [signedOrder];
+ // request more makerAsset than what is available
+ const makerAssetFillAmount = signedOrder.makerAssetAmount.plus(100);
+ return expect(
+ contractWrappers.forwarder.marketBuyOrdersWithEthAsync(
+ signedOrders,
+ makerAssetFillAmount,
+ takerAddress,
+ makerAssetFillAmount,
+ [],
+ 0,
+ constants.NULL_ADDRESS,
+ {
+ shouldValidate: true,
+ },
+ ),
+ ).to.be.rejectedWith('COMPLETE_FILL_FAILED');
+ });
});
describe('#marketSellOrdersWithEthAsync', () => {
it('should market sell orders with eth', async () => {
@@ -115,5 +135,33 @@ describe('ForwarderWrapper', () => {
expect(ordersInfo[1].orderStatus).to.be.equal(OrderStatus.FILLABLE);
expect(ordersInfo[1].orderTakerAssetFilledAmount).to.be.bignumber.equal(new BigNumber(4)); // only 95% of ETH is sold
});
+ it('should throw when invalid transaction and shouldValidate is true', async () => {
+ // create an order with fees, we try to fill it but we do not provide enough ETH to cover the fees
+ const signedOrderWithFee = await fillScenarios.createFillableSignedOrderWithFeesAsync(
+ makerAssetData,
+ takerAssetData,
+ constants.ZERO_AMOUNT,
+ new BigNumber(100),
+ makerAddress,
+ constants.NULL_ADDRESS,
+ fillableAmount,
+ constants.NULL_ADDRESS,
+ );
+ const signedOrders = [signedOrderWithFee];
+ const makerAssetFillAmount = signedOrder.makerAssetAmount;
+ return expect(
+ contractWrappers.forwarder.marketSellOrdersWithEthAsync(
+ signedOrders,
+ takerAddress,
+ makerAssetFillAmount,
+ [],
+ 0,
+ constants.NULL_ADDRESS,
+ {
+ shouldValidate: true,
+ },
+ ),
+ ).to.be.rejectedWith('COMPLETE_FILL_FAILED');
+ });
});
});
diff --git a/packages/order-watcher/CHANGELOG.json b/packages/order-watcher/CHANGELOG.json
index ce56e492c..feebb9d69 100644
--- a/packages/order-watcher/CHANGELOG.json
+++ b/packages/order-watcher/CHANGELOG.json
@@ -1,5 +1,14 @@
[
{
+ "version": "2.1.2",
+ "changes": [
+ {
+ "note": "Added getStats function and returns a Stats object",
+ "pr": 1118
+ }
+ ]
+ },
+ {
"version": "2.1.1",
"changes": [
{
diff --git a/packages/order-watcher/src/index.ts b/packages/order-watcher/src/index.ts
index d2f91eab1..8280c73a4 100644
--- a/packages/order-watcher/src/index.ts
+++ b/packages/order-watcher/src/index.ts
@@ -7,6 +7,7 @@ export {
OrderState,
ExchangeContractErrs,
OrderRelevantState,
+ Stats,
} from '@0xproject/types';
export { OnOrderStateChangeCallback, OrderWatcherConfig } from './types';
diff --git a/packages/order-watcher/src/order_watcher/order_watcher.ts b/packages/order-watcher/src/order_watcher/order_watcher.ts
index f9a63efe3..eb37bd617 100644
--- a/packages/order-watcher/src/order_watcher/order_watcher.ts
+++ b/packages/order-watcher/src/order_watcher/order_watcher.ts
@@ -30,7 +30,7 @@ import {
orderHashUtils,
OrderStateUtils,
} from '@0xproject/order-utils';
-import { AssetProxyId, ExchangeContractErrs, OrderState, SignedOrder } 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';
@@ -213,6 +213,14 @@ export class OrderWatcher {
this._expirationWatcher.unsubscribe();
intervalUtils.clearAsyncExcludingInterval(this._cleanupJobIntervalIdIfExists);
}
+ /**
+ * Gets statistics of the OrderWatcher Instance.
+ */
+ public getStats(): Stats {
+ return {
+ orderCount: _.size(this._orderByOrderHash),
+ };
+ }
private async _cleanupAsync(): Promise<void> {
for (const orderHash of _.keys(this._orderByOrderHash)) {
this._cleanupOrderRelatedState(orderHash);
diff --git a/packages/order-watcher/test/order_watcher_test.ts b/packages/order-watcher/test/order_watcher_test.ts
index 60d9069e8..4545f84bf 100644
--- a/packages/order-watcher/test/order_watcher_test.ts
+++ b/packages/order-watcher/test/order_watcher_test.ts
@@ -140,6 +140,23 @@ describe('OrderWatcher', () => {
expect(() => orderWatcher.subscribe(_.noop.bind(_))).to.throw(OrderWatcherError.SubscriptionAlreadyPresent);
});
});
+ describe('#getStats', async () => {
+ it('orderCount should increment and decrement with order additions and removals', async () => {
+ signedOrder = await fillScenarios.createFillableSignedOrderAsync(
+ makerAssetData,
+ takerAssetData,
+ makerAddress,
+ takerAddress,
+ fillableAmount,
+ );
+ const orderHash = orderHashUtils.getOrderHashHex(signedOrder);
+ expect(orderWatcher.getStats().orderCount).to.be.eq(0);
+ await orderWatcher.addOrderAsync(signedOrder);
+ expect(orderWatcher.getStats().orderCount).to.be.eq(1);
+ orderWatcher.removeOrder(orderHash);
+ expect(orderWatcher.getStats().orderCount).to.be.eq(0);
+ });
+ });
describe('tests with cleanup', async () => {
afterEach(async () => {
orderWatcher.unsubscribe();
diff --git a/packages/types/src/index.ts b/packages/types/src/index.ts
index 6bc966ba1..d33048b61 100644
--- a/packages/types/src/index.ts
+++ b/packages/types/src/index.ts
@@ -620,3 +620,7 @@ export interface EIP712TypedData {
message: EIP712Object;
primaryType: string;
}
+
+export interface Stats {
+ orderCount: number;
+}
diff --git a/packages/website/package.json b/packages/website/package.json
index 82109d95f..8f69460d6 100644
--- a/packages/website/package.json
+++ b/packages/website/package.json
@@ -59,6 +59,7 @@
"react-typist": "^2.0.4",
"redux": "^3.6.0",
"redux-devtools-extension": "^2.13.2",
+ "rollbar": "^2.4.7",
"semver-sort": "0.0.4",
"styled-components": "^3.3.0",
"thenby": "^1.2.3",
diff --git a/packages/website/ts/utils/error_reporter.ts b/packages/website/ts/utils/error_reporter.ts
index 6008fffed..bec92e829 100644
--- a/packages/website/ts/utils/error_reporter.ts
+++ b/packages/website/ts/utils/error_reporter.ts
@@ -1,4 +1,5 @@
import { logUtils } from '@0xproject/utils';
+import Rollbar = require('rollbar');
import { configs } from 'ts/utils/configs';
import { constants } from 'ts/utils/constants';
import { utils } from 'ts/utils/utils';
@@ -36,8 +37,8 @@ const rollbarConfig = {
'SecurityError (DOM Exception 18)',
],
};
-import Rollbar = require('../../public/js/rollbar.umd.min.js');
-const rollbar = Rollbar.init(rollbarConfig);
+
+const rollbar = new Rollbar(rollbarConfig);
export const errorReporter = {
report(err: Error): void {