diff options
author | Brandon Millman <brandon.millman@gmail.com> | 2018-08-03 07:02:58 +0800 |
---|---|---|
committer | Brandon Millman <brandon.millman@gmail.com> | 2018-08-03 07:03:19 +0800 |
commit | 82092ab50a73e15e167f387380cd75ac52581e88 (patch) | |
tree | bce674d1e668299c131f30f8c808a9167ac3167b /packages/contract-wrappers/src/utils/calldata_optimization_utils.ts | |
parent | c3e6be7956adf4fabcc8dfffe081515562a1dde0 (diff) | |
download | dexon-sol-tools-82092ab50a73e15e167f387380cd75ac52581e88.tar dexon-sol-tools-82092ab50a73e15e167f387380cd75ac52581e88.tar.gz dexon-sol-tools-82092ab50a73e15e167f387380cd75ac52581e88.tar.bz2 dexon-sol-tools-82092ab50a73e15e167f387380cd75ac52581e88.tar.lz dexon-sol-tools-82092ab50a73e15e167f387380cd75ac52581e88.tar.xz dexon-sol-tools-82092ab50a73e15e167f387380cd75ac52581e88.tar.zst dexon-sol-tools-82092ab50a73e15e167f387380cd75ac52581e88.zip |
Rename to calldata utils
Diffstat (limited to 'packages/contract-wrappers/src/utils/calldata_optimization_utils.ts')
-rw-r--r-- | packages/contract-wrappers/src/utils/calldata_optimization_utils.ts | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/packages/contract-wrappers/src/utils/calldata_optimization_utils.ts b/packages/contract-wrappers/src/utils/calldata_optimization_utils.ts new file mode 100644 index 000000000..3172cf531 --- /dev/null +++ b/packages/contract-wrappers/src/utils/calldata_optimization_utils.ts @@ -0,0 +1,44 @@ +import { SignedOrder } from '@0xproject/types'; +import * as _ from 'lodash'; + +import { constants } from './constants'; + +export const calldataOptimizationUtils = { + /** + * 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 + */ + optimizeForwarderOrders(orders: SignedOrder[]): SignedOrder[] { + const optimizedOrders = _.map(orders, (order, index) => + transformOrder(order, { + makerAssetData: index === 0 ? order.makerAssetData : constants.NULL_BYTES, + takerAssetData: constants.NULL_BYTES, + }), + ); + 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 + */ + optimizeForwarderFeeOrders(orders: SignedOrder[]): SignedOrder[] { + const optimizedOrders = _.map(orders, (order, index) => + transformOrder(order, { + makerAssetData: constants.NULL_BYTES, + takerAssetData: constants.NULL_BYTES, + }), + ); + return optimizedOrders; + }, +}; + +const transformOrder = (order: SignedOrder, partialOrder: Partial<SignedOrder>) => { + return { + ...order, + ...partialOrder, + }; +}; |