Remove assetDataUtils everywhere (#2373)

* remove assetDataUtils everywhere

* export IAssetDataContract from @0x/contract-wrappers to allow @0x/instant to decode asset data  synchronously

* export generic function `decodeAssetDataOrThrow` and add ERC20Bridge support

* export `hexUtils` from order-utils instead of contracts-test-utils
This commit is contained in:
Xianny
2019-12-04 13:08:08 -08:00
committed by GitHub
parent b86d19028c
commit fcbcbac889
70 changed files with 1498 additions and 1129 deletions

View File

@@ -11,14 +11,12 @@ import {
constants,
ExchangeFunctionName,
expect,
hexConcat,
hexSlice,
orderHashUtils,
transactionHashUtils,
verifyEvents,
} from '@0x/contracts-test-utils';
import { SignedOrder, SignedZeroExTransaction } from '@0x/types';
import { BigNumber } from '@0x/utils';
import { BigNumber, hexUtils } from '@0x/utils';
import { Actor } from '../framework/actors/base';
import { FeeRecipient } from '../framework/actors/fee_recipient';
@@ -225,10 +223,10 @@ blockchainTests.resets('Coordinator integration tests', env => {
return expect(tx).to.revertWith(expectedError);
});
it(`${fnName} should revert with an invalid approval signature`, async () => {
const approvalSignature = hexConcat(
hexSlice(approval.signature, 0, 2),
const approvalSignature = hexUtils.concat(
hexUtils.slice(approval.signature, 0, 2),
'0xFFFFFFFF',
hexSlice(approval.signature, 6),
hexUtils.slice(approval.signature, 6),
);
const transactionHash = transactionHashUtils.getTransactionHashHex(transaction);
const tx = coordinator
@@ -305,10 +303,10 @@ blockchainTests.resets('Coordinator integration tests', env => {
verifyEvents(txReceipt, orders.map(order => expectedFillEvent(order)), ExchangeEvents.Fill);
});
it(`${fnName} should revert with an invalid approval signature`, async () => {
const approvalSignature = hexConcat(
hexSlice(approval.signature, 0, 2),
const approvalSignature = hexUtils.concat(
hexUtils.slice(approval.signature, 0, 2),
'0xFFFFFFFF',
hexSlice(approval.signature, 6),
hexUtils.slice(approval.signature, 6),
);
const transactionHash = transactionHashUtils.getTransactionHashHex(transaction);
const tx = coordinator

View File

@@ -18,15 +18,13 @@ import {
ExchangeFunctionName,
expect,
getLatestBlockTimestampAsync,
hexConcat,
hexRandom,
orderHashUtils,
randomAddress,
transactionHashUtils,
verifyEventsFromLogs,
} from '@0x/contracts-test-utils';
import { FillResults, OrderStatus, SignatureType, SignedOrder } from '@0x/types';
import { BigNumber } from '@0x/utils';
import { BigNumber, hexUtils } from '@0x/utils';
import { LogWithDecodedArgs } from 'ethereum-types';
import { Actor } from '../framework/actors/base';
@@ -190,7 +188,7 @@ blockchainTests.resets('Transaction integration tests', env => {
const order = await maker.signOrderAsync();
const data = exchangeDataEncoder.encodeOrdersToExchangeData(fnName, [order]);
const transaction = await takers[0].signTransactionAsync({ data });
transaction.signature = hexConcat(hexRandom(65), SignatureType.EthSign);
transaction.signature = hexUtils.concat(hexUtils.random(65), SignatureType.EthSign);
const transactionHashHex = transactionHashUtils.getTransactionHashHex(transaction);
const expectedError = new ExchangeRevertErrors.SignatureError(
ExchangeRevertErrors.SignatureErrorCode.BadTransactionSignature,

View File

@@ -1,16 +1,10 @@
import { IAssetDataContract } from '@0x/contracts-asset-proxy';
import { DummyERC721TokenContract } from '@0x/contracts-erc721';
import { ForwarderContract } from '@0x/contracts-exchange-forwarder';
import {
blockchainTests,
constants,
getLatestBlockTimestampAsync,
hexConcat,
toBaseUnitAmount,
} from '@0x/contracts-test-utils';
import { blockchainTests, constants, getLatestBlockTimestampAsync, toBaseUnitAmount } from '@0x/contracts-test-utils';
import { generatePseudoRandomSalt } from '@0x/order-utils';
import { SignatureType, SignedOrder } from '@0x/types';
import { AbiEncoder, BigNumber, ExchangeForwarderRevertErrors } from '@0x/utils';
import { AbiEncoder, BigNumber, ExchangeForwarderRevertErrors, hexUtils } from '@0x/utils';
import { deployEth2DaiBridgeAsync } from '../bridges/deploy_eth2dai_bridge';
import { deployUniswapBridgeAsync } from '../bridges/deploy_uniswap_bridge';
@@ -111,7 +105,7 @@ blockchainTests.resets('Forwarder <> ERC20Bridge integration tests', env => {
takerFeeAssetData: wethAssetData,
expirationTimeSeconds: new BigNumber(currentBlockTimestamp).plus(fifteenMinutesInSeconds),
salt: generatePseudoRandomSalt(),
signature: hexConcat(SignatureType.Wallet),
signature: hexUtils.concat(SignatureType.Wallet),
};
eth2DaiBridgeOrder = {
...orderDefaults,

View File

@@ -1,16 +1,8 @@
import { IAssetDataContract } from '@0x/contracts-asset-proxy';
import { ForwarderContract } from '@0x/contracts-exchange-forwarder';
import {
constants,
expect,
getPercentageOfValue,
hexSlice,
Numberish,
OrderStatus,
provider,
} from '@0x/contracts-test-utils';
import { constants, expect, getPercentageOfValue, Numberish, OrderStatus, provider } from '@0x/contracts-test-utils';
import { AssetProxyId, OrderInfo, SignedOrder } from '@0x/types';
import { BigNumber, RevertError } from '@0x/utils';
import { BigNumber, hexUtils, RevertError } from '@0x/utils';
import { TransactionReceiptWithDecodedLogs } from 'ethereum-types';
import { FeeRecipient } from '../framework/actors/fee_recipient';
@@ -37,8 +29,8 @@ interface MarketBuyOptions extends MarketSellOptions {
}
function areUnderlyingAssetsEqual(assetData1: string, assetData2: string): boolean {
const assetProxyId1 = hexSlice(assetData1, 0, 4);
const assetProxyId2 = hexSlice(assetData2, 0, 4);
const assetProxyId1 = hexUtils.slice(assetData1, 0, 4);
const assetProxyId2 = hexUtils.slice(assetData2, 0, 4);
if (
(assetProxyId1 === AssetProxyId.ERC20 || assetProxyId1 === AssetProxyId.ERC20Bridge) &&
(assetProxyId2 === AssetProxyId.ERC20 || assetProxyId2 === AssetProxyId.ERC20Bridge)

View File

@@ -1,8 +1,8 @@
import { IAssetDataContract } from '@0x/contracts-asset-proxy';
import { ReferenceFunctions } from '@0x/contracts-exchange-libs';
import { constants, hexSlice, Numberish, provider } from '@0x/contracts-test-utils';
import { constants, Numberish, provider } from '@0x/contracts-test-utils';
import { AssetProxyId, SignedOrder } from '@0x/types';
import { BigNumber } from '@0x/utils';
import { BigNumber, hexUtils } from '@0x/utils';
import { TransactionReceiptWithDecodedLogs } from 'ethereum-types';
import * as _ from 'lodash';
@@ -82,7 +82,7 @@ export class LocalBalanceStore extends BalanceStore {
if (fromAddress === toAddress || amount.isZero()) {
return;
}
const assetProxyId = hexSlice(assetData, 0, 4);
const assetProxyId = hexUtils.slice(assetData, 0, 4);
switch (assetProxyId) {
case AssetProxyId.ERC20: {
const tokenAddress = this._assetDataDecoder.getABIDecodedTransactionData<string>(