From ed19067096999e3c86f3a67ce8a87a2904ff09ef Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Fri, 20 Jul 2018 00:39:23 +0200 Subject: Move methods in `ZeroEx.assetData` to `ZeroEx` itself --- packages/0x.js/CHANGELOG.json | 8 +++++++ packages/0x.js/src/0x.ts | 55 +++++++++++++++++++++++++++++++++++++++---- 2 files changed, 59 insertions(+), 4 deletions(-) diff --git a/packages/0x.js/CHANGELOG.json b/packages/0x.js/CHANGELOG.json index 020ae0d65..7d6139658 100644 --- a/packages/0x.js/CHANGELOG.json +++ b/packages/0x.js/CHANGELOG.json @@ -1,4 +1,12 @@ [ + { + "version": "1.0.0-rc.2", + "changes": [ + { + "note": "Remove `zeroEx.assetData` and instead re-export it's static functions directly off `ZeroEx`" + } + ] + }, { "version": "1.0.0-rc.1", "changes": [ diff --git a/packages/0x.js/src/0x.ts b/packages/0x.js/src/0x.ts index 7c06a53af..2a2b82f63 100644 --- a/packages/0x.js/src/0x.ts +++ b/packages/0x.js/src/0x.ts @@ -38,10 +38,6 @@ export class ZeroEx { * this constant for your convenience. */ public static NULL_ADDRESS = constants.NULL_ADDRESS; - /** - * A set of methods to easily decode/encode assetData fields found in 0x orders. - */ - public static assetData = assetDataUtils; /** * An instance of the ExchangeWrapper class containing methods for interacting with the 0x Exchange smart contract. */ @@ -125,6 +121,57 @@ export class ZeroEx { const baseUnitAmount = Web3Wrapper.toBaseUnitAmount(amount, decimals); return baseUnitAmount; } + /** + * Encodes an ERC20 token address into a hex encoded assetData string, usable in the makerAssetData or + * takerAssetData fields in a 0x order. + * @param tokenAddress The ERC20 token address to encode + * @return The hex encoded assetData string + */ + public static encodeERC20AssetData(tokenAddress: string): string { + return assetDataUtils.encodeERC20AssetData(tokenAddress); + } + /** + * Decodes an ERC20 assetData hex string into it's corresponding ERC20 tokenAddress & assetProxyId + * @param assetData Hex encoded assetData string to decode + * @return An object containing the decoded tokenAddress & assetProxyId + */ + public static decodeERC20AssetData(assetData: string): ERC20AssetData { + return assetDataUtils.decodeERC20AssetData(assetData); + } + /** + * Encodes an ERC721 token address into a hex encoded assetData string, usable in the makerAssetData or + * takerAssetData fields in a 0x order. + * @param tokenAddress The ERC721 token address to encode + * @param tokenId The ERC721 tokenId to encode + * @return The hex encoded assetData string + */ + public static encodeERC721AssetData(tokenAddress: string, tokenId: BigNumber): string { + return assetDataUtils.encodeERC721AssetData(tokenAddress, tokenId); + } + /** + * Decodes an ERC721 assetData hex string into it's corresponding ERC721 tokenAddress, tokenId & assetProxyId + * @param assetData Hex encoded assetData string to decode + * @return An object containing the decoded tokenAddress, tokenId & assetProxyId + */ + public static decodeERC721AssetData(assetData: string): ERC721AssetData { + return assetDataUtils.decodeERC721AssetData(assetData); + } + /** + * Decode and return the assetProxyId from the assetData + * @param assetData Hex encoded assetData string to decode + * @return The assetProxyId + */ + public static decodeAssetProxyId(assetData: string): AssetProxyId { + return assetDataUtils.decodeAssetProxyId(assetData); + } + /** + * Decode any assetData into it's corresponding assetData object + * @param assetData Hex encoded assetData string to decode + * @return Either a ERC20 or ERC721 assetData object + */ + public static decodeAssetDataOrThrow(assetData: string): ERC20AssetData | ERC721AssetData { + return assetDataUtils.decodeAssetDataOrThrow(assetData); + } /** * Instantiates a new ZeroEx instance that provides the public interface to the 0x.js library. * @param provider The Provider instance you would like the 0x.js library to use for interacting with -- cgit v1.2.3