diff options
author | Brandon Millman <brandon.millman@gmail.com> | 2018-09-15 20:47:44 +0800 |
---|---|---|
committer | Brandon Millman <brandon.millman@gmail.com> | 2018-09-15 20:47:44 +0800 |
commit | af40989f5f6b606172370d8e878c51ce2e7382eb (patch) | |
tree | 129b0d3d54d1b803a49d7119aa9fb5ec6b47e34c /packages/asset-buyer/src/utils/assert.ts | |
parent | d57619b5db8d4b5a8d31f095d8dfef04faef44c9 (diff) | |
download | dexon-sol-tools-af40989f5f6b606172370d8e878c51ce2e7382eb.tar.gz dexon-sol-tools-af40989f5f6b606172370d8e878c51ce2e7382eb.tar.zst dexon-sol-tools-af40989f5f6b606172370d8e878c51ce2e7382eb.zip |
Add factory method on AssetBuyer for provided orders
Diffstat (limited to 'packages/asset-buyer/src/utils/assert.ts')
-rw-r--r-- | packages/asset-buyer/src/utils/assert.ts | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/packages/asset-buyer/src/utils/assert.ts b/packages/asset-buyer/src/utils/assert.ts index 0085ca41e..edc90608c 100644 --- a/packages/asset-buyer/src/utils/assert.ts +++ b/packages/asset-buyer/src/utils/assert.ts @@ -1,5 +1,6 @@ import { assert as sharedAssert } from '@0xproject/assert'; import { schemas } from '@0xproject/json-schemas'; +import { SignedOrder } from '@0xproject/types'; import * as _ from 'lodash'; import { BuyQuote, OrderFetcher, OrderFetcherRequest } from '../types'; @@ -25,4 +26,19 @@ export const assert = { sharedAssert.isHexString(`${variableName}.takerAssetData`, orderFetcherRequest.takerAssetData); sharedAssert.isNumber(`${variableName}.networkId`, orderFetcherRequest.networkId); }, + areValidProvidedOrders(variableName: string, orders: SignedOrder[]): void { + if (orders.length === 0) { + return; + } + const makerAssetData = orders[0].makerAssetData; + const takerAssetData = orders[0].takerAssetData; + const filteredOrders = _.filter( + orders, + order => order.makerAssetData === makerAssetData && order.takerAssetData === takerAssetData, + ); + sharedAssert.assert( + orders.length === filteredOrders.length, + `Expected all orders in ${variableName} to have the same makerAssetData and takerAssetData.`, + ); + }, }; |