blob: 0041f1a64ae4f0498d39060ea4e5e9e4ce93bc28 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
import { SignedOrder } from '@0xproject/types';
import * as _ from 'lodash';
import { constants } from './constants';
export const marketOrdersOptimizationUtils = {
/**
* Takes an array of orders and outputs an array of equivalent orders where all takerAssetData are '0x' and
* all makerAssetData are '0x' except for that of the first order, which retains its original value
* @param orders An array of SignedOrder objects
* @returns optimized orders
*/
optimizeMarketOrders(orders: SignedOrder[]): SignedOrder[] {
const optimizedOrders = _.map(orders, (order, index) => {
const makerAssetData = index === 0 ? order.makerAssetData : constants.NULL_BYTES;
const takerAssetData = constants.NULL_BYTES;
return {
...order,
makerAssetData,
takerAssetData,
};
});
return optimizedOrders;
},
/**
* Takes an array of orders and outputs an array of equivalent orders where all takerAssetData are '0x' and
* all makerAssetData are '0x'
* @param orders An array of SignedOrder objects
* @returns optimized orders
*/
optimizeFeeOrders(orders: SignedOrder[]): SignedOrder[] {
const optimizedOrders = _.map(orders, order => {
const makerAssetData = constants.NULL_BYTES;
const takerAssetData = constants.NULL_BYTES;
return {
...order,
makerAssetData,
takerAssetData,
};
});
return optimizedOrders;
},
};
|