aboutsummaryrefslogtreecommitdiffstats
path: root/packages/order-utils
diff options
context:
space:
mode:
Diffstat (limited to 'packages/order-utils')
-rw-r--r--packages/order-utils/src/asset_data_utils.ts29
-rw-r--r--packages/order-utils/src/exchange_transfer_simulator.ts2
-rw-r--r--packages/order-utils/src/index.ts1
3 files changed, 30 insertions, 2 deletions
diff --git a/packages/order-utils/src/asset_data_utils.ts b/packages/order-utils/src/asset_data_utils.ts
index 18c1f93b6..3741a683e 100644
--- a/packages/order-utils/src/asset_data_utils.ts
+++ b/packages/order-utils/src/asset_data_utils.ts
@@ -1,4 +1,11 @@
-import { AssetProxyId, ERC20AssetData, ERC721AssetData, MultiAssetData, SingleAssetData } from '@0x/types';
+import {
+ AssetProxyId,
+ ERC20AssetData,
+ ERC721AssetData,
+ MultiAssetData,
+ MultiAssetDataWithRecursiveDecoding,
+ SingleAssetData,
+} from '@0x/types';
import { AbiEncoder, BigNumber } from '@0x/utils';
import { MethodAbi } from 'ethereum-types';
import * as _ from 'lodash';
@@ -115,6 +122,26 @@ export const assetDataUtils = {
};
},
/**
+ * Decodes a MultiAsset assetData hex string into it's corresponding amounts and decoded nestedAssetData elements (all nested elements are flattened)
+ * @param assetData Hex encoded assetData string to decode
+ * @return An object containing the decoded amounts and nestedAssetData
+ */
+ decodeMultiAssetDataRecursively(assetData: string): MultiAssetDataWithRecursiveDecoding {
+ const decodedAssetData = assetDataUtils.decodeMultiAssetData(assetData);
+ const decodedNestedAssetData = _.map(decodedAssetData.nestedAssetData as string[], nestedAssetDataElement => {
+ const decodedNestedAssetDataElement = assetDataUtils.decodeAssetDataOrThrow(nestedAssetDataElement);
+ return decodedNestedAssetDataElement.assetProxyId === AssetProxyId.MultiAsset
+ ? assetDataUtils.decodeMultiAssetDataRecursively(nestedAssetDataElement).nestedAssetData
+ : (decodedNestedAssetDataElement as SingleAssetData);
+ });
+ const flattenedDecodedNestedAssetData = _.flattenDeep(decodedNestedAssetData);
+ return {
+ assetProxyId: decodedAssetData.assetProxyId,
+ amounts: decodedAssetData.amounts,
+ nestedAssetData: flattenedDecodedNestedAssetData as SingleAssetData[],
+ };
+ },
+ /**
* Decode and return the assetProxyId from the assetData
* @param assetData Hex encoded assetData string to decode
* @return The assetProxyId
diff --git a/packages/order-utils/src/exchange_transfer_simulator.ts b/packages/order-utils/src/exchange_transfer_simulator.ts
index 06621fd9e..0a948fd1f 100644
--- a/packages/order-utils/src/exchange_transfer_simulator.ts
+++ b/packages/order-utils/src/exchange_transfer_simulator.ts
@@ -108,7 +108,7 @@ export class ExchangeTransferSimulator {
const amountsElement = decodedAssetData.amounts[index];
const totalAmount = amountInBaseUnits.times(amountsElement);
await this.transferFromAsync(
- nestedAssetDataElement,
+ nestedAssetDataElement as string,
from,
to,
totalAmount,
diff --git a/packages/order-utils/src/index.ts b/packages/order-utils/src/index.ts
index e098f23c3..398188433 100644
--- a/packages/order-utils/src/index.ts
+++ b/packages/order-utils/src/index.ts
@@ -38,6 +38,7 @@ export {
ERC20AssetData,
ERC721AssetData,
MultiAssetData,
+ MultiAssetDataWithRecursiveDecoding,
AssetProxyId,
SignatureType,
OrderStateValid,