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_proxy_utils.ts66
1 files changed, 33 insertions, 33 deletions
diff --git a/packages/order-utils/src/asset_proxy_utils.ts b/packages/order-utils/src/asset_proxy_utils.ts
index 8255376a1..1f1e49f0f 100644
--- a/packages/order-utils/src/asset_proxy_utils.ts
+++ b/packages/order-utils/src/asset_proxy_utils.ts
@@ -41,7 +41,7 @@ export const assetProxyUtils = {
const value = new BigNumber(formattedValue, 16);
return value;
},
- encodeERC20ProxyData(tokenAddress: string): string {
+ encodeERC20AssetData(tokenAddress: string): string {
const encodedAssetProxyId = assetProxyUtils.encodeAssetProxyId(AssetProxyId.ERC20);
const encodedAddress = assetProxyUtils.encodeAddress(tokenAddress);
const encodedMetadata = Buffer.concat([encodedAddress, encodedAssetProxyId]);
@@ -53,11 +53,11 @@ export const assetProxyUtils = {
if (encodedProxyMetadata.byteLength !== ERC20_PROXY_METADATA_BYTE_LENGTH) {
throw new Error(
`Could not decode ERC20 Proxy Data. Expected length of encoded data to be 21. Got ${
- encodedProxyMetadata.byteLength
+ encodedAssetData.byteLength
}`,
);
}
- const encodedAssetProxyId = encodedProxyMetadata.slice(-1);
+ const encodedAssetProxyId = encodedAssetData.slice(-1);
const assetProxyId = assetProxyUtils.decodeAssetProxyId(encodedAssetProxyId);
if (assetProxyId !== AssetProxyId.ERC20) {
throw new Error(
@@ -69,13 +69,13 @@ export const assetProxyUtils = {
const addressOffset = ERC20_PROXY_METADATA_BYTE_LENGTH - 1;
const encodedTokenAddress = encodedProxyMetadata.slice(0, addressOffset);
const tokenAddress = assetProxyUtils.decodeAddress(encodedTokenAddress);
- const erc20ProxyData = {
+ const erc20AssetData = {
assetProxyId,
tokenAddress,
};
- return erc20ProxyData;
+ return erc20AssetData;
},
- encodeERC721ProxyData(tokenAddress: string, tokenId: BigNumber, data?: string): string {
+ encodeERC721AssetData(tokenAddress: string, tokenId: BigNumber, data?: string): string {
const encodedAssetProxyId = assetProxyUtils.encodeAssetProxyId(AssetProxyId.ERC721);
const encodedAddress = assetProxyUtils.encodeAddress(tokenAddress);
const encodedTokenId = assetProxyUtils.encodeUint256(tokenId);
@@ -89,16 +89,16 @@ export const assetProxyUtils = {
const encodedMetadataHex = ethUtil.bufferToHex(encodedMetadata);
return encodedMetadataHex;
},
- decodeERC721ProxyData(proxyData: string): ERC721ProxyData {
- const encodedProxyMetadata = ethUtil.toBuffer(proxyData);
- if (encodedProxyMetadata.byteLength < ERC721_PROXY_METADATA_BYTE_LENGTH) {
+ decodeERC721AssetData(assetData: string): ERC721AssetData {
+ const encodedAssetData = ethUtil.toBuffer(assetData);
+ if (encodedAssetData.byteLength < ERC721_PROXY_METADATA_BYTE_LENGTH) {
throw new Error(
`Could not decode ERC20 Proxy Data. Expected length of encoded data to be at least 53. Got ${
- encodedProxyMetadata.byteLength
+ encodedAssetData.byteLength
}`,
);
}
- const encodedAssetProxyId = encodedProxyMetadata.slice(-1);
+ const encodedAssetProxyId = encodedAssetData.slice(-1);
const assetProxyId = assetProxyUtils.decodeAssetProxyId(encodedAssetProxyId);
if (assetProxyId !== AssetProxyId.ERC721) {
throw new Error(
@@ -115,57 +115,57 @@ export const assetProxyUtils = {
const tokenId = assetProxyUtils.decodeUint256(encodedTokenId);
const nullData = '0x';
let data = nullData;
- if (encodedProxyMetadata.byteLength > 53) {
- const encodedDataLength = encodedProxyMetadata.slice(53, 85);
+ if (encodedAssetData.byteLength > 53) {
+ const encodedDataLength = encodedAssetData.slice(53, 85);
const dataLength = assetProxyUtils.decodeUint256(encodedDataLength);
- const expectedDataLength = new BigNumber(encodedProxyMetadata.byteLength - 85);
+ const expectedDataLength = new BigNumber(encodedAssetData.byteLength - 85);
if (!dataLength.equals(expectedDataLength)) {
throw new Error(
`Data length (${dataLength}) does not match actual length of data (${expectedDataLength})`,
);
}
- const encodedData = encodedProxyMetadata.slice(85);
+ const encodedData = encodedAssetData.slice(85);
data = ethUtil.bufferToHex(encodedData);
}
- const erc721ProxyData: ERC721ProxyData = {
+ const erc721AssetData: ERC721AssetData = {
assetProxyId,
tokenAddress,
tokenId,
data,
};
- return erc721ProxyData;
+ return erc721AssetData;
},
- decodeProxyDataId(proxyData: string): AssetProxyId {
- const encodedProxyMetadata = ethUtil.toBuffer(proxyData);
- if (encodedProxyMetadata.byteLength < 1) {
+ decodeAssetDataId(assetData: string): AssetProxyId {
+ const encodedAssetData = ethUtil.toBuffer(assetData);
+ if (encodedAssetData.byteLength < 1) {
throw new Error(
`Could not decode Proxy Data. Expected length of encoded data to be at least 1. Got ${
- encodedProxyMetadata.byteLength
+ encodedAssetData.byteLength
}`,
);
}
- const encodedAssetProxyId = encodedProxyMetadata.slice(-1);
+ const encodedAssetProxyId = encodedAssetData.slice(-1);
const assetProxyId = assetProxyUtils.decodeAssetProxyId(encodedAssetProxyId);
return assetProxyId;
},
- decodeProxyData(proxyData: string): ProxyData {
- const assetProxyId = assetProxyUtils.decodeProxyDataId(proxyData);
+ decodeAssetData(assetData: string): AssetData {
+ const assetProxyId = assetProxyUtils.decodeAssetDataId(assetData);
switch (assetProxyId) {
case AssetProxyId.ERC20:
- const erc20ProxyData = assetProxyUtils.decodeERC20ProxyData(proxyData);
- const generalizedERC20ProxyData = {
+ const erc20AssetData = assetProxyUtils.decodeERC20AssetData(assetData);
+ const generalizedERC20AssetData = {
assetProxyId,
- tokenAddress: erc20ProxyData.tokenAddress,
+ tokenAddress: erc20AssetData.tokenAddress,
};
- return generalizedERC20ProxyData;
+ return generalizedERC20AssetData;
case AssetProxyId.ERC721:
- const erc721ProxyData = assetProxyUtils.decodeERC721ProxyData(proxyData);
- const generaliedERC721ProxyData = {
+ const erc721AssetData = assetProxyUtils.decodeERC721AssetData(assetData);
+ const generaliedERC721AssetData = {
assetProxyId,
- tokenAddress: erc721ProxyData.tokenAddress,
- data: erc721ProxyData.tokenId,
+ tokenAddress: erc721AssetData.tokenAddress,
+ data: erc721AssetData.tokenId,
};
- return generaliedERC721ProxyData;
+ return generaliedERC721AssetData;
default:
throw new Error(`Unrecognized asset proxy id: ${assetProxyId}`);
}