diff options
author | Brandon Millman <brandon.millman@gmail.com> | 2018-08-02 05:27:17 +0800 |
---|---|---|
committer | Brandon Millman <brandon.millman@gmail.com> | 2018-08-02 11:23:44 +0800 |
commit | 4f006fdc5c3cc24bb5d008f4c363d5225fe6728a (patch) | |
tree | 082038e292afa312d5764c47694667a440ee0a31 /packages/contract-wrappers/src/utils | |
parent | 9f7f61085c1a6989b79df575beb0b5d8f2b3652d (diff) | |
download | dexon-0x-contracts-4f006fdc5c3cc24bb5d008f4c363d5225fe6728a.tar.gz dexon-0x-contracts-4f006fdc5c3cc24bb5d008f4c363d5225fe6728a.tar.zst dexon-0x-contracts-4f006fdc5c3cc24bb5d008f4c363d5225fe6728a.zip |
Create marketBuyOrdersOptimizations
Diffstat (limited to 'packages/contract-wrappers/src/utils')
-rw-r--r-- | packages/contract-wrappers/src/utils/constants.ts | 1 | ||||
-rw-r--r-- | packages/contract-wrappers/src/utils/market_orders_optimization_utils.ts | 43 |
2 files changed, 44 insertions, 0 deletions
diff --git a/packages/contract-wrappers/src/utils/constants.ts b/packages/contract-wrappers/src/utils/constants.ts index d436efefc..2df11538c 100644 --- a/packages/contract-wrappers/src/utils/constants.ts +++ b/packages/contract-wrappers/src/utils/constants.ts @@ -2,6 +2,7 @@ import { BigNumber } from '@0xproject/utils'; export const constants = { NULL_ADDRESS: '0x0000000000000000000000000000000000000000', + NULL_BYTES: '0x', TESTRPC_NETWORK_ID: 50, INVALID_JUMP_PATTERN: 'invalid JUMP at', REVERT: 'revert', diff --git a/packages/contract-wrappers/src/utils/market_orders_optimization_utils.ts b/packages/contract-wrappers/src/utils/market_orders_optimization_utils.ts new file mode 100644 index 000000000..0041f1a64 --- /dev/null +++ b/packages/contract-wrappers/src/utils/market_orders_optimization_utils.ts @@ -0,0 +1,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; + }, +}; |