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.ts (renamed from packages/order-utils/src/asset_proxy_utils.ts)49
-rw-r--r--packages/order-utils/src/index.ts2
-rw-r--r--packages/order-utils/test/exchange_transfer_simulator_test.ts4
3 files changed, 18 insertions, 37 deletions
diff --git a/packages/order-utils/src/asset_proxy_utils.ts b/packages/order-utils/src/asset_data_utils.ts
index 8140ad89d..81e34218f 100644
--- a/packages/order-utils/src/asset_proxy_utils.ts
+++ b/packages/order-utils/src/asset_data_utils.ts
@@ -13,36 +13,7 @@ interface EthAbi {
// tslint:disable:no-var-requires
const ethAbi = require('ethereumjs-abi') as EthAbi;
-export const assetProxyUtils = {
- encodeAssetProxyId(assetProxyId: AssetProxyId): Buffer {
- return ethUtil.toBuffer(assetProxyId);
- },
- decodeAssetProxyId(encodedAssetProxyId: Buffer): AssetProxyId {
- const hexString = ethUtil.bufferToHex(encodedAssetProxyId);
- if (hexString === AssetProxyId.ERC20) {
- return AssetProxyId.ERC20;
- }
- if (hexString === AssetProxyId.ERC721) {
- return AssetProxyId.ERC721;
- }
- throw new Error(`Invalid ProxyId: ${hexString}`);
- },
- encodeAddress(address: string): Buffer {
- if (!ethUtil.isValidAddress(address)) {
- throw new Error(`Invalid Address: ${address}`);
- }
- const encodedAddress = ethUtil.toBuffer(address);
- const padded = ethUtil.setLengthLeft(encodedAddress, constants.WORD_LENGTH);
- return padded;
- },
- decodeAddress(encodedAddress: Buffer): string {
- const unpadded = ethUtil.setLengthLeft(encodedAddress, constants.ADDRESS_LENGTH);
- const address = ethUtil.bufferToHex(unpadded);
- if (!ethUtil.isValidAddress(address)) {
- throw new Error(`Invalid Address: ${address}`);
- }
- return address;
- },
+export const assetDataUtils = {
encodeUint256(value: BigNumber): Buffer {
const base = 10;
const formattedValue = new BN(value.toString(base));
@@ -131,20 +102,30 @@ export const assetProxyUtils = {
);
}
const encodedAssetProxyId = encodedAssetData.slice(0, constants.SELECTOR_LENGTH);
- const assetProxyId = assetProxyUtils.decodeAssetProxyId(encodedAssetProxyId);
+ const assetProxyId = assetDataUtils._decodeAssetProxyId(encodedAssetProxyId);
return assetProxyId;
},
decodeAssetData(assetData: string): ERC20AssetData | ERC721AssetData {
- const assetProxyId = assetProxyUtils.decodeAssetDataId(assetData);
+ const assetProxyId = assetDataUtils.decodeAssetDataId(assetData);
switch (assetProxyId) {
case AssetProxyId.ERC20:
- const erc20AssetData = assetProxyUtils.decodeERC20AssetData(assetData);
+ const erc20AssetData = assetDataUtils.decodeERC20AssetData(assetData);
return erc20AssetData;
case AssetProxyId.ERC721:
- const erc721AssetData = assetProxyUtils.decodeERC721AssetData(assetData);
+ const erc721AssetData = assetDataUtils.decodeERC721AssetData(assetData);
return erc721AssetData;
default:
throw new Error(`Unrecognized asset proxy id: ${assetProxyId}`);
}
},
+ _decodeAssetProxyId(encodedAssetProxyId: Buffer): AssetProxyId {
+ const hexString = ethUtil.bufferToHex(encodedAssetProxyId);
+ if (hexString === AssetProxyId.ERC20) {
+ return AssetProxyId.ERC20;
+ }
+ if (hexString === AssetProxyId.ERC721) {
+ return AssetProxyId.ERC721;
+ }
+ throw new Error(`Invalid ProxyId: ${hexString}`);
+ },
};
diff --git a/packages/order-utils/src/index.ts b/packages/order-utils/src/index.ts
index b4a7a6b67..8d748a2dc 100644
--- a/packages/order-utils/src/index.ts
+++ b/packages/order-utils/src/index.ts
@@ -19,7 +19,7 @@ export { AbstractOrderFilledCancelledFetcher } from './abstract/abstract_order_f
export { BalanceAndProxyAllowanceLazyStore } from './store/balance_and_proxy_allowance_lazy_store';
export { RemainingFillableCalculator } from './remaining_fillable_calculator';
export { OrderStateUtils } from './order_state_utils';
-export { assetProxyUtils } from './asset_proxy_utils';
+export { assetDataUtils } from './asset_data_utils';
export { EIP712Utils } from './eip712_utils';
export { OrderValidationUtils } from './order_validation_utils';
export { ExchangeTransferSimulator } from './exchange_transfer_simulator';
diff --git a/packages/order-utils/test/exchange_transfer_simulator_test.ts b/packages/order-utils/test/exchange_transfer_simulator_test.ts
index 37b2bd712..17903669a 100644
--- a/packages/order-utils/test/exchange_transfer_simulator_test.ts
+++ b/packages/order-utils/test/exchange_transfer_simulator_test.ts
@@ -4,7 +4,7 @@ import { BigNumber } from '@0xproject/utils';
import * as chai from 'chai';
import { artifacts } from '../src/artifacts';
-import { assetProxyUtils } from '../src/asset_proxy_utils';
+import { assetDataUtils } from '../src/asset_data_utils';
import { constants } from '../src/constants';
import { ExchangeTransferSimulator } from '../src/exchange_transfer_simulator';
import { DummyERC20TokenContract } from '../src/generated_contract_wrappers/dummy_erc20_token';
@@ -66,7 +66,7 @@ describe('ExchangeTransferSimulator', async () => {
totalSupply,
);
- exampleAssetData = assetProxyUtils.encodeERC20AssetData(dummyERC20Token.address);
+ exampleAssetData = assetDataUtils.encodeERC20AssetData(dummyERC20Token.address);
});
beforeEach(async () => {
await blockchainLifecycle.startAsync();