aboutsummaryrefslogtreecommitdiffstats
path: root/packages/contracts/src
diff options
context:
space:
mode:
authorAmir Bandeali <abandeali1@gmail.com>2018-04-22 07:03:58 +0800
committerAmir Bandeali <abandeali1@gmail.com>2018-04-22 08:31:17 +0800
commit1c94ab7cc3819ee991800a3d2439c02e4083a891 (patch)
tree09fc1bfcebb298e6443e1fb4e33e42b6a9b825d5 /packages/contracts/src
parentaa3be5198093c5514d8ce237272e390f8be65d65 (diff)
downloaddexon-0x-contracts-1c94ab7cc3819ee991800a3d2439c02e4083a891.tar.gz
dexon-0x-contracts-1c94ab7cc3819ee991800a3d2439c02e4083a891.tar.zst
dexon-0x-contracts-1c94ab7cc3819ee991800a3d2439c02e4083a891.zip
export proxyUtils instead of individual functions
Diffstat (limited to 'packages/contracts/src')
-rw-r--r--packages/contracts/src/utils/asset_proxy_utils.ts66
1 files changed, 32 insertions, 34 deletions
diff --git a/packages/contracts/src/utils/asset_proxy_utils.ts b/packages/contracts/src/utils/asset_proxy_utils.ts
index da610cbcc..29e50a860 100644
--- a/packages/contracts/src/utils/asset_proxy_utils.ts
+++ b/packages/contracts/src/utils/asset_proxy_utils.ts
@@ -4,37 +4,35 @@ import ethUtil = require('ethereumjs-util');
import { AssetProxyId } from './types';
-export function encodeAssetProxyId(assetProxyId: AssetProxyId): Buffer {
- return ethUtil.toBuffer(assetProxyId);
-}
-
-export function encodeAddress(address: string): Buffer {
- if (!ethUtil.isValidAddress(address)) {
- throw new Error(`Invalid Address: ${address}`);
- }
- const encodedAddress = ethUtil.toBuffer(address);
- return encodedAddress;
-}
-
-export function encodeUint256(value: BigNumber): Buffer {
- const formattedValue = new BN(value.toString(10));
- const encodedValue = ethUtil.toBuffer(formattedValue);
- return encodedValue;
-}
-
-export function encodeERC20ProxyData(tokenAddress: string): string {
- const encodedAssetProxyId = encodeAssetProxyId(AssetProxyId.ERC20);
- const encodedAddress = encodeAddress(tokenAddress);
- const encodedMetadata = Buffer.concat([encodedAssetProxyId, encodedAddress]);
- const encodedMetadataHex = ethUtil.bufferToHex(encodedMetadata);
- return encodedMetadataHex;
-}
-
-export function encodeERC721ProxyData(tokenAddress: string, tokenId: BigNumber): string {
- const encodedAssetProxyId = encodeAssetProxyId(AssetProxyId.ERC721);
- const encodedAddress = encodeAddress(tokenAddress);
- const encodedTokenId = encodeUint256(tokenId);
- const encodedMetadata = Buffer.concat([encodedAssetProxyId, encodedAddress, encodedTokenId]);
- const encodedMetadataHex = ethUtil.bufferToHex(encodedMetadata);
- return encodedMetadataHex;
-}
+export const proxyUtils = {
+ encodeAssetProxyId(assetProxyId: AssetProxyId): Buffer {
+ return ethUtil.toBuffer(assetProxyId);
+ },
+ encodeAddress(address: string): Buffer {
+ if (!ethUtil.isValidAddress(address)) {
+ throw new Error(`Invalid Address: ${address}`);
+ }
+ const encodedAddress = ethUtil.toBuffer(address);
+ return encodedAddress;
+ },
+ encodeUint256(value: BigNumber): Buffer {
+ const formattedValue = new BN(value.toString(10));
+ const encodedValue = ethUtil.toBuffer(formattedValue);
+ return encodedValue;
+ },
+ encodeERC20ProxyData(tokenAddress: string): string {
+ const encodedAssetProxyId = proxyUtils.encodeAssetProxyId(AssetProxyId.ERC20);
+ const encodedAddress = proxyUtils.encodeAddress(tokenAddress);
+ const encodedMetadata = Buffer.concat([encodedAssetProxyId, encodedAddress]);
+ const encodedMetadataHex = ethUtil.bufferToHex(encodedMetadata);
+ return encodedMetadataHex;
+ },
+ encodeERC721ProxyData(tokenAddress: string, tokenId: BigNumber): string {
+ const encodedAssetProxyId = proxyUtils.encodeAssetProxyId(AssetProxyId.ERC721);
+ const encodedAddress = proxyUtils.encodeAddress(tokenAddress);
+ const encodedTokenId = proxyUtils.encodeUint256(tokenId);
+ const encodedMetadata = Buffer.concat([encodedAssetProxyId, encodedAddress, encodedTokenId]);
+ const encodedMetadataHex = ethUtil.bufferToHex(encodedMetadata);
+ return encodedMetadataHex;
+ },
+};