aboutsummaryrefslogtreecommitdiffstats
path: root/packages/contract-wrappers
diff options
context:
space:
mode:
authorBryan Stitt <bryan@stitthappens.com>2018-11-13 01:10:40 +0800
committerGitHub <noreply@github.com>2018-11-13 01:10:40 +0800
commit789f57345298f2700a56f329ba0873c1f623ce8b (patch)
tree51b04785b13a9945ffdd15d0b67f564163a146d0 /packages/contract-wrappers
parent22f217807d44e364cad6ebe90560326a755cdd11 (diff)
parent0ebbbdfca49028f196853bbfb082a1378c09f441 (diff)
downloaddexon-sol-tools-789f57345298f2700a56f329ba0873c1f623ce8b.tar
dexon-sol-tools-789f57345298f2700a56f329ba0873c1f623ce8b.tar.gz
dexon-sol-tools-789f57345298f2700a56f329ba0873c1f623ce8b.tar.bz2
dexon-sol-tools-789f57345298f2700a56f329ba0873c1f623ce8b.tar.lz
dexon-sol-tools-789f57345298f2700a56f329ba0873c1f623ce8b.tar.xz
dexon-sol-tools-789f57345298f2700a56f329ba0873c1f623ce8b.tar.zst
dexon-sol-tools-789f57345298f2700a56f329ba0873c1f623ce8b.zip
Merge branch 'development' into patch-1
Diffstat (limited to 'packages/contract-wrappers')
-rw-r--r--packages/contract-wrappers/CHANGELOG.json21
-rw-r--r--packages/contract-wrappers/CHANGELOG.md6
-rw-r--r--packages/contract-wrappers/package.json20
-rw-r--r--packages/contract-wrappers/src/contract_wrappers/exchange_wrapper.ts8
-rw-r--r--packages/contract-wrappers/src/fetchers/order_filled_cancelled_fetcher.ts16
-rw-r--r--packages/contract-wrappers/src/schemas/validate_order_fillable_opts_schema.ts7
-rw-r--r--packages/contract-wrappers/test/exchange_wrapper_test.ts15
7 files changed, 77 insertions, 16 deletions
diff --git a/packages/contract-wrappers/CHANGELOG.json b/packages/contract-wrappers/CHANGELOG.json
index 0346b79b2..425c33643 100644
--- a/packages/contract-wrappers/CHANGELOG.json
+++ b/packages/contract-wrappers/CHANGELOG.json
@@ -1,5 +1,26 @@
[
{
+ "version": "4.0.0",
+ "changes": [
+ {
+ "note":
+ "Add signature validation, regular cancellation and `cancelledUpTo` checks to `validateOrderFillableOrThrowAsync`",
+ "pr": 1235
+ },
+ {
+ "note":
+ "Improved the errors thrown by `validateOrderFillableOrThrowAsync` by making them more descriptive",
+ "pr": 1235
+ },
+ {
+ "note":
+ "Throw previously swallowed network errors when calling `validateOrderFillableOrThrowAsync` (see issue: #1218)",
+ "pr": 1235
+ }
+ ],
+ "timestamp": 1542028948
+ },
+ {
"version": "3.0.1",
"changes": [
{
diff --git a/packages/contract-wrappers/CHANGELOG.md b/packages/contract-wrappers/CHANGELOG.md
index 1fe903dd9..52c3fece6 100644
--- a/packages/contract-wrappers/CHANGELOG.md
+++ b/packages/contract-wrappers/CHANGELOG.md
@@ -5,6 +5,12 @@ Edit the package's CHANGELOG.json file only.
CHANGELOG
+## v4.0.0 - _November 12, 2018_
+
+ * Add signature validation, regular cancellation and `cancelledUpTo` checks to `validateOrderFillableOrThrowAsync` (#1235)
+ * Improved the errors thrown by `validateOrderFillableOrThrowAsync` by making them more descriptive (#1235)
+ * Throw previously swallowed network errors when calling `validateOrderFillableOrThrowAsync` (see issue: #1218) (#1235)
+
## v3.0.1 - _November 9, 2018_
* Fix bug in `ForwarderWrapper` where `feeRecipientAddress` was not correctly normalized. (#1178)
diff --git a/packages/contract-wrappers/package.json b/packages/contract-wrappers/package.json
index cb69bbd33..ab316c586 100644
--- a/packages/contract-wrappers/package.json
+++ b/packages/contract-wrappers/package.json
@@ -1,6 +1,6 @@
{
"name": "@0x/contract-wrappers",
- "version": "3.0.1",
+ "version": "4.0.0",
"description": "Smart TS wrappers for 0x smart contracts",
"keywords": [
"0xproject",
@@ -37,9 +37,9 @@
"node": ">=6.0.0"
},
"devDependencies": {
- "@0x/dev-utils": "^1.0.14",
- "@0x/migrations": "^2.0.1",
- "@0x/subproviders": "^2.1.1",
+ "@0x/dev-utils": "^1.0.15",
+ "@0x/migrations": "^2.0.2",
+ "@0x/subproviders": "^2.1.2",
"@0x/tslint-config": "^1.0.10",
"@types/lodash": "4.14.104",
"@types/mocha": "^2.2.42",
@@ -65,17 +65,17 @@
"web3-provider-engine": "14.0.6"
},
"dependencies": {
- "@0x/abi-gen-wrappers": "^1.0.2",
- "@0x/assert": "^1.0.15",
+ "@0x/abi-gen-wrappers": "^1.0.3",
+ "@0x/assert": "^1.0.16",
"@0x/contract-addresses": "^1.1.0",
"@0x/contract-artifacts": "^1.1.0",
- "@0x/fill-scenarios": "^1.0.9",
- "@0x/json-schemas": "^2.0.1",
- "@0x/order-utils": "^2.0.1",
+ "@0x/fill-scenarios": "^1.0.10",
+ "@0x/json-schemas": "^2.1.0",
+ "@0x/order-utils": "^3.0.0",
"@0x/types": "^1.2.1",
"@0x/typescript-typings": "^3.0.4",
"@0x/utils": "^2.0.4",
- "@0x/web3-wrapper": "^3.1.1",
+ "@0x/web3-wrapper": "^3.1.2",
"ethereum-types": "^1.1.2",
"ethereumjs-blockstream": "6.0.0",
"ethereumjs-util": "^5.1.1",
diff --git a/packages/contract-wrappers/src/contract_wrappers/exchange_wrapper.ts b/packages/contract-wrappers/src/contract_wrappers/exchange_wrapper.ts
index 2e978f35b..c76e51eee 100644
--- a/packages/contract-wrappers/src/contract_wrappers/exchange_wrapper.ts
+++ b/packages/contract-wrappers/src/contract_wrappers/exchange_wrapper.ts
@@ -18,6 +18,7 @@ import { OrderFilledCancelledFetcher } from '../fetchers/order_filled_cancelled_
import { methodOptsSchema } from '../schemas/method_opts_schema';
import { orderTxOptsSchema } from '../schemas/order_tx_opts_schema';
import { txOptsSchema } from '../schemas/tx_opts_schema';
+import { validateOrderFillableOptsSchema } from '../schemas/validate_order_fillable_opts_schema';
import {
BlockRange,
EventCallback,
@@ -1114,6 +1115,9 @@ export class ExchangeWrapper extends ContractWrapper {
signedOrder: SignedOrder,
opts: ValidateOrderFillableOpts = {},
): Promise<void> {
+ assert.doesConformToSchema('signedOrder', signedOrder, schemas.signedOrderSchema);
+ assert.doesConformToSchema('opts', opts, validateOrderFillableOptsSchema);
+
const balanceAllowanceFetcher = new AssetBalanceAndProxyAllowanceFetcher(
this._erc20TokenWrapper,
this._erc721TokenWrapper,
@@ -1124,7 +1128,7 @@ export class ExchangeWrapper extends ContractWrapper {
const expectedFillTakerTokenAmountIfExists = opts.expectedFillTakerTokenAmount;
const filledCancelledFetcher = new OrderFilledCancelledFetcher(this, BlockParamLiteral.Latest);
- const orderValidationUtils = new OrderValidationUtils(filledCancelledFetcher);
+ const orderValidationUtils = new OrderValidationUtils(filledCancelledFetcher, this._web3Wrapper.getProvider());
await orderValidationUtils.validateOrderFillableOrThrowAsync(
exchangeTradeSimulator,
signedOrder,
@@ -1152,7 +1156,7 @@ export class ExchangeWrapper extends ContractWrapper {
const exchangeTradeSimulator = new ExchangeTransferSimulator(balanceAllowanceStore);
const filledCancelledFetcher = new OrderFilledCancelledFetcher(this, BlockParamLiteral.Latest);
- const orderValidationUtils = new OrderValidationUtils(filledCancelledFetcher);
+ const orderValidationUtils = new OrderValidationUtils(filledCancelledFetcher, this._web3Wrapper.getProvider());
await orderValidationUtils.validateFillOrderThrowIfInvalidAsync(
exchangeTradeSimulator,
this._web3Wrapper.getProvider(),
diff --git a/packages/contract-wrappers/src/fetchers/order_filled_cancelled_fetcher.ts b/packages/contract-wrappers/src/fetchers/order_filled_cancelled_fetcher.ts
index acf7038fa..5d350916c 100644
--- a/packages/contract-wrappers/src/fetchers/order_filled_cancelled_fetcher.ts
+++ b/packages/contract-wrappers/src/fetchers/order_filled_cancelled_fetcher.ts
@@ -1,5 +1,6 @@
// tslint:disable:no-unnecessary-type-assertion
-import { AbstractOrderFilledCancelledFetcher } from '@0x/order-utils';
+import { AbstractOrderFilledCancelledFetcher, orderHashUtils } from '@0x/order-utils';
+import { SignedOrder } from '@0x/types';
import { BigNumber } from '@0x/utils';
import { BlockParamLiteral } from 'ethereum-types';
@@ -18,9 +19,18 @@ export class OrderFilledCancelledFetcher implements AbstractOrderFilledCancelled
});
return filledTakerAmount;
}
- public async isOrderCancelledAsync(orderHash: string): Promise<boolean> {
+ public async isOrderCancelledAsync(signedOrder: SignedOrder): Promise<boolean> {
+ const orderHash = orderHashUtils.getOrderHashHex(signedOrder);
const isCancelled = await this._exchange.isCancelledAsync(orderHash);
- return isCancelled;
+ const orderEpoch = await this._exchange.getOrderEpochAsync(
+ signedOrder.makerAddress,
+ signedOrder.senderAddress,
+ {
+ defaultBlock: this._stateLayer,
+ },
+ );
+ const isCancelledByOrderEpoch = orderEpoch > signedOrder.salt;
+ return isCancelled || isCancelledByOrderEpoch;
}
public getZRXAssetData(): string {
const zrxAssetData = this._exchange.getZRXAssetData();
diff --git a/packages/contract-wrappers/src/schemas/validate_order_fillable_opts_schema.ts b/packages/contract-wrappers/src/schemas/validate_order_fillable_opts_schema.ts
new file mode 100644
index 000000000..2e111af04
--- /dev/null
+++ b/packages/contract-wrappers/src/schemas/validate_order_fillable_opts_schema.ts
@@ -0,0 +1,7 @@
+export const validateOrderFillableOptsSchema = {
+ id: '/ValidateOrderFillableOpts',
+ properties: {
+ expectedFillTakerTokenAmount: { $ref: '/wholeNumberSchema' },
+ },
+ type: 'object',
+};
diff --git a/packages/contract-wrappers/test/exchange_wrapper_test.ts b/packages/contract-wrappers/test/exchange_wrapper_test.ts
index 0e537bd83..73ce6c743 100644
--- a/packages/contract-wrappers/test/exchange_wrapper_test.ts
+++ b/packages/contract-wrappers/test/exchange_wrapper_test.ts
@@ -1,7 +1,7 @@
import { BlockchainLifecycle, callbackErrorReporter } from '@0x/dev-utils';
import { FillScenarios } from '@0x/fill-scenarios';
import { assetDataUtils, orderHashUtils } from '@0x/order-utils';
-import { DoneCallback, SignedOrder } from '@0x/types';
+import { DoneCallback, RevertReason, SignedOrder } from '@0x/types';
import { BigNumber } from '@0x/utils';
import * as chai from 'chai';
import { BlockParamLiteral } from 'ethereum-types';
@@ -282,6 +282,19 @@ describe('ExchangeWrapper', () => {
expect(ordersInfo[1].orderHash).to.be.equal(anotherOrderHash);
});
});
+ describe('#validateOrderFillableOrThrowAsync', () => {
+ it('should throw if signature is invalid', async () => {
+ const signedOrderWithInvalidSignature = {
+ ...signedOrder,
+ signature:
+ '0x1b61a3ed31b43c8780e905a260a35faefcc527be7516aa11c0256729b5b351bc3340349190569279751135161d22529dc25add4f6069af05be04cacbda2ace225403',
+ };
+
+ expect(
+ contractWrappers.exchange.validateOrderFillableOrThrowAsync(signedOrderWithInvalidSignature),
+ ).to.eventually.to.be.rejectedWith(RevertReason.InvalidOrderSignature);
+ });
+ });
describe('#isValidSignature', () => {
it('should check if the signature is valid', async () => {
const orderHash = orderHashUtils.getOrderHashHex(signedOrder);