diff options
Diffstat (limited to 'packages/contracts/src')
-rw-r--r-- | packages/contracts/src/utils/asset_proxy_utils.ts | 66 |
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; + }, +}; |