aboutsummaryrefslogtreecommitdiffstats
path: root/contracts/test-utils/src/formatters.ts
diff options
context:
space:
mode:
Diffstat (limited to 'contracts/test-utils/src/formatters.ts')
-rw-r--r--contracts/test-utils/src/formatters.ts68
1 files changed, 68 insertions, 0 deletions
diff --git a/contracts/test-utils/src/formatters.ts b/contracts/test-utils/src/formatters.ts
new file mode 100644
index 000000000..813eb45db
--- /dev/null
+++ b/contracts/test-utils/src/formatters.ts
@@ -0,0 +1,68 @@
+import { SignedOrder } from '@0x/types';
+import { BigNumber } from '@0x/utils';
+import * as _ from 'lodash';
+
+import { constants } from './constants';
+import { orderUtils } from './order_utils';
+import { BatchCancelOrders, BatchFillOrders, MarketBuyOrders, MarketSellOrders } from './types';
+
+export const formatters = {
+ createBatchFill(signedOrders: SignedOrder[], takerAssetFillAmounts: BigNumber[] = []): BatchFillOrders {
+ const batchFill: BatchFillOrders = {
+ orders: [],
+ signatures: [],
+ takerAssetFillAmounts,
+ };
+ _.forEach(signedOrders, signedOrder => {
+ const orderWithoutExchangeAddress = orderUtils.getOrderWithoutExchangeAddress(signedOrder);
+ batchFill.orders.push(orderWithoutExchangeAddress);
+ batchFill.signatures.push(signedOrder.signature);
+ if (takerAssetFillAmounts.length < signedOrders.length) {
+ batchFill.takerAssetFillAmounts.push(signedOrder.takerAssetAmount);
+ }
+ });
+ return batchFill;
+ },
+ createMarketSellOrders(signedOrders: SignedOrder[], takerAssetFillAmount: BigNumber): MarketSellOrders {
+ const marketSellOrders: MarketSellOrders = {
+ orders: [],
+ signatures: [],
+ takerAssetFillAmount,
+ };
+ _.forEach(signedOrders, (signedOrder, i) => {
+ const orderWithoutExchangeAddress = orderUtils.getOrderWithoutExchangeAddress(signedOrder);
+ if (i !== 0) {
+ orderWithoutExchangeAddress.takerAssetData = constants.NULL_BYTES;
+ }
+ marketSellOrders.orders.push(orderWithoutExchangeAddress);
+ marketSellOrders.signatures.push(signedOrder.signature);
+ });
+ return marketSellOrders;
+ },
+ createMarketBuyOrders(signedOrders: SignedOrder[], makerAssetFillAmount: BigNumber): MarketBuyOrders {
+ const marketBuyOrders: MarketBuyOrders = {
+ orders: [],
+ signatures: [],
+ makerAssetFillAmount,
+ };
+ _.forEach(signedOrders, (signedOrder, i) => {
+ const orderWithoutExchangeAddress = orderUtils.getOrderWithoutExchangeAddress(signedOrder);
+ if (i !== 0) {
+ orderWithoutExchangeAddress.makerAssetData = constants.NULL_BYTES;
+ }
+ marketBuyOrders.orders.push(orderWithoutExchangeAddress);
+ marketBuyOrders.signatures.push(signedOrder.signature);
+ });
+ return marketBuyOrders;
+ },
+ createBatchCancel(signedOrders: SignedOrder[]): BatchCancelOrders {
+ const batchCancel: BatchCancelOrders = {
+ orders: [],
+ };
+ _.forEach(signedOrders, signedOrder => {
+ const orderWithoutExchangeAddress = orderUtils.getOrderWithoutExchangeAddress(signedOrder);
+ batchCancel.orders.push(orderWithoutExchangeAddress);
+ });
+ return batchCancel;
+ },
+};