Replace assetDataUtils with DevUtilsContract wherever possible (#2304)

* Replace assetDataUtils with DevUtilsContract wherever possible

Does not replace from @0x/instant and some @0x/order-utils uses

* Add revertIfInvalidAssetData to LibAssetData

This is needed to replace `assetDataUtils.decodeAssetDataOrThrow`.
Because it's used in packages and not only contracts, we should wait
to deploy the updated contract so we can update `@0x/contract-artifacts`,
`@0x/abi-gen-wrappers`, and `@0x/contract-wrappers` first.

* remove usages of signatureUtils

* fix test for  optimised encoding

* refactor @0x/contracts-integrations

* update changelogs

* Move @0x/contracts-dev-utils from devDependencies to dependencies
It is exported as part of the package
This commit is contained in:
Xianny
2019-11-06 19:40:20 -08:00
committed by GitHub
parent ec26cff656
commit 6a852ab0ed
56 changed files with 1408 additions and 970 deletions

View File

@@ -1,4 +1,25 @@
[
{
"version": "2.2.0-beta.1",
"changes": [
{
"note": "LocalBalanceStore.create and constructor now require an instance of DevUtilsContract",
"pr": 2304
},
{
"note": "In LocalBalanceStore, `transferAsset` is now `transferAssetAsync`",
"pr": 2304
},
{
"note": "Test utility classes AssetWrapper, MatchOrderTester, and OrderFactoryFromScenario constructors now require an instance of DevUtilsContract",
"pr": 2304
},
{
"note": "In OrderFactoryFromScenario, `generateOrder` is now `generateOrderAsync`",
"pr": 2304
}
]
},
{
"version": "2.2.0-beta.0",
"changes": [

View File

@@ -76,6 +76,7 @@
"dependencies": {
"@0x/base-contract": "^5.5.0-beta.0",
"@0x/contracts-asset-proxy": "^2.3.0-beta.0",
"@0x/contracts-dev-utils": "^0.1.0-beta.0",
"@0x/contracts-erc1155": "^1.2.0-beta.0",
"@0x/contracts-erc20": "^2.3.0-beta.0",
"@0x/contracts-erc721": "^2.2.0-beta.0",

View File

@@ -1,3 +1,4 @@
import { DevUtilsContract } from '@0x/contracts-dev-utils';
import { ReferenceFunctions as LibReferenceFunctions } from '@0x/contracts-exchange-libs';
import {
constants,
@@ -24,68 +25,8 @@ import {
} from '../../src';
export class FillOrderWrapper {
private readonly _exchange: ExchangeContract;
private readonly _blockchainBalanceStore: BlockchainBalanceStore;
/**
* Locally simulates filling an order.
* @param txReceipt Transaction receipt from the actual fill, needed to update eth balance
* @param signedOrder The order being filled.
* @param takerAddress Address of taker (the address who matched the two orders)
* @param opts Optionally specifies the amount to fill.
* @param initBalanceStore Account balances prior to the fill.
* @return The expected account balances, fill results, and fill events.
*/
public static simulateFillOrder(
txReceipt: TransactionReceiptWithDecodedLogs,
signedOrder: SignedOrder,
takerAddress: string,
initBalanceStore: BalanceStore,
opts: { takerAssetFillAmount?: BigNumber } = {},
): [FillResults, FillEventArgs, BalanceStore] {
const balanceStore = LocalBalanceStore.create(initBalanceStore);
const takerAssetFillAmount =
opts.takerAssetFillAmount !== undefined ? opts.takerAssetFillAmount : signedOrder.takerAssetAmount;
// TODO(jalextowle): Change this if the integration tests take protocol fees into account.
const fillResults = LibReferenceFunctions.calculateFillResults(
signedOrder,
takerAssetFillAmount,
constants.ZERO_AMOUNT,
constants.ZERO_AMOUNT,
);
const fillEvent = FillOrderWrapper.simulateFillEvent(signedOrder, takerAddress, fillResults);
// Taker -> Maker
balanceStore.transferAsset(
takerAddress,
signedOrder.makerAddress,
fillResults.takerAssetFilledAmount,
signedOrder.takerAssetData,
);
// Maker -> Taker
balanceStore.transferAsset(
signedOrder.makerAddress,
takerAddress,
fillResults.makerAssetFilledAmount,
signedOrder.makerAssetData,
);
// Taker -> Fee Recipient
balanceStore.transferAsset(
takerAddress,
signedOrder.feeRecipientAddress,
fillResults.takerFeePaid,
signedOrder.takerFeeAssetData,
);
// Maker -> Fee Recipient
balanceStore.transferAsset(
signedOrder.makerAddress,
signedOrder.feeRecipientAddress,
fillResults.makerFeePaid,
signedOrder.makerFeeAssetData,
);
balanceStore.burnGas(txReceipt.from, constants.DEFAULT_GAS_PRICE * txReceipt.gasUsed);
return [fillResults, fillEvent, balanceStore];
}
/**
* Simulates the event emitted by the exchange contract when an order is filled.
*/
@@ -119,6 +60,65 @@ export class FillOrderWrapper {
return events.map(event => _.pick(event, fieldsOfInterest)) as FillEventArgs[];
}
/**
* Locally simulates filling an order.
* @param txReceipt Transaction receipt from the actual fill, needed to update eth balance
* @param signedOrder The order being filled.
* @param takerAddress Address of taker (the address who matched the two orders)
* @param opts Optionally specifies the amount to fill.
* @param initBalanceStore Account balances prior to the fill.
* @return The expected account balances, fill results, and fill events.
*/
public async simulateFillOrderAsync(
txReceipt: TransactionReceiptWithDecodedLogs,
signedOrder: SignedOrder,
takerAddress: string,
initBalanceStore: BalanceStore,
opts: { takerAssetFillAmount?: BigNumber } = {},
): Promise<[FillResults, FillEventArgs, BalanceStore]> {
const balanceStore = LocalBalanceStore.create(this._devUtils, initBalanceStore);
const takerAssetFillAmount =
opts.takerAssetFillAmount !== undefined ? opts.takerAssetFillAmount : signedOrder.takerAssetAmount;
// TODO(jalextowle): Change this if the integration tests take protocol fees into account.
const fillResults = LibReferenceFunctions.calculateFillResults(
signedOrder,
takerAssetFillAmount,
constants.ZERO_AMOUNT,
constants.ZERO_AMOUNT,
);
const fillEvent = FillOrderWrapper.simulateFillEvent(signedOrder, takerAddress, fillResults);
// Taker -> Maker
await balanceStore.transferAssetAsync(
takerAddress,
signedOrder.makerAddress,
fillResults.takerAssetFilledAmount,
signedOrder.takerAssetData,
);
// Maker -> Taker
await balanceStore.transferAssetAsync(
signedOrder.makerAddress,
takerAddress,
fillResults.makerAssetFilledAmount,
signedOrder.makerAssetData,
);
// Taker -> Fee Recipient
await balanceStore.transferAssetAsync(
takerAddress,
signedOrder.feeRecipientAddress,
fillResults.takerFeePaid,
signedOrder.takerFeeAssetData,
);
// Maker -> Fee Recipient
await balanceStore.transferAssetAsync(
signedOrder.makerAddress,
signedOrder.feeRecipientAddress,
fillResults.makerFeePaid,
signedOrder.makerFeeAssetData,
);
balanceStore.burnGas(txReceipt.from, constants.DEFAULT_GAS_PRICE * txReceipt.gasUsed);
return [fillResults, fillEvent, balanceStore];
}
/**
* Constructor.
* @param exchangeContract Instance of the deployed exchange contract.
@@ -127,12 +127,12 @@ export class FillOrderWrapper {
* @param tokenIds The tokenIds of ERC721 and ERC1155 assets to assert the balances of.
*/
public constructor(
exchangeContract: ExchangeContract,
private readonly _exchange: ExchangeContract,
private readonly _devUtils: DevUtilsContract,
tokenOwnersByName: TokenOwnersByName,
tokenContractsByName: Partial<TokenContractsByName>,
tokenIds: Partial<TokenIds>,
) {
this._exchange = exchangeContract;
this._blockchainBalanceStore = new BlockchainBalanceStore(tokenOwnersByName, tokenContractsByName, tokenIds);
}
@@ -168,7 +168,7 @@ export class FillOrderWrapper {
simulatedFillResults,
simulatedFillEvent,
simulatedFinalBalanceStore,
] = FillOrderWrapper.simulateFillOrder(txReceipt, signedOrder, from, this._blockchainBalanceStore, opts);
] = await this.simulateFillOrderAsync(txReceipt, signedOrder, from, this._blockchainBalanceStore, opts);
// Assert state transition
expect(simulatedFillResults, 'Fill Results').to.be.deep.equal(fillResults);
expect(simulatedFillEvent, 'Fill Events').to.be.deep.equal(fillEvent);

View File

@@ -1,5 +1,5 @@
import { DevUtilsContract } from '@0x/contracts-dev-utils';
import { constants, Numberish } from '@0x/contracts-test-utils';
import { assetDataUtils } from '@0x/order-utils';
import { AssetProxyId } from '@0x/types';
import { BigNumber } from '@0x/utils';
import * as _ from 'lodash';
@@ -12,8 +12,8 @@ export class LocalBalanceStore extends BalanceStore {
* Creates a new balance store based on an existing one.
* @param sourceBalanceStore Existing balance store whose values should be copied.
*/
public static create(sourceBalanceStore?: BalanceStore): LocalBalanceStore {
const localBalanceStore = new LocalBalanceStore();
public static create(devUtils: DevUtilsContract, sourceBalanceStore?: BalanceStore): LocalBalanceStore {
const localBalanceStore = new LocalBalanceStore(devUtils);
if (sourceBalanceStore !== undefined) {
localBalanceStore.cloneFrom(sourceBalanceStore);
}
@@ -26,6 +26,7 @@ export class LocalBalanceStore extends BalanceStore {
* be initialized via `create`.
*/
protected constructor(
private readonly _devUtils: DevUtilsContract,
tokenOwnersByName: TokenOwnersByName = {},
tokenContractsByName: Partial<TokenContractsByName> = {},
) {
@@ -71,27 +72,33 @@ export class LocalBalanceStore extends BalanceStore {
* @param amount Amount of asset(s) to transfer
* @param assetData Asset data of assets being transferred.
*/
public transferAsset(fromAddress: string, toAddress: string, amount: BigNumber, assetData: string): void {
public async transferAssetAsync(
fromAddress: string,
toAddress: string,
amount: BigNumber,
assetData: string,
): Promise<void> {
if (fromAddress === toAddress) {
return;
}
const assetProxyId = assetDataUtils.decodeAssetProxyId(assetData);
const assetProxyId = await this._devUtils.decodeAssetProxyId.callAsync(assetData);
switch (assetProxyId) {
case AssetProxyId.ERC20: {
const erc20AssetData = assetDataUtils.decodeERC20AssetData(assetData);
const assetAddress = erc20AssetData.tokenAddress;
_.update(this._balances.erc20, [fromAddress, assetAddress], balance => balance.minus(amount));
_.update(this._balances.erc20, [toAddress, assetAddress], balance =>
// tslint:disable-next-line:no-unused-variable
const [proxyId, tokenAddress] = await this._devUtils.decodeERC20AssetData.callAsync(assetData);
_.update(this._balances.erc20, [fromAddress, tokenAddress], balance => balance.minus(amount));
_.update(this._balances.erc20, [toAddress, tokenAddress], balance =>
(balance || constants.ZERO_AMOUNT).plus(amount),
);
break;
}
case AssetProxyId.ERC721: {
const erc721AssetData = assetDataUtils.decodeERC721AssetData(assetData);
const assetAddress = erc721AssetData.tokenAddress;
const tokenId = erc721AssetData.tokenId;
const fromTokens = _.get(this._balances.erc721, [fromAddress, assetAddress], []);
const toTokens = _.get(this._balances.erc721, [toAddress, assetAddress], []);
// tslint:disable-next-line:no-unused-variable
const [proxyId, tokenAddress, tokenId] = await this._devUtils.decodeERC721AssetData.callAsync(
assetData,
);
const fromTokens = _.get(this._balances.erc721, [fromAddress, tokenAddress], []);
const toTokens = _.get(this._balances.erc721, [toAddress, tokenAddress], []);
if (amount.gte(1)) {
const tokenIndex = _.findIndex(fromTokens as BigNumber[], t => t.eq(tokenId));
if (tokenIndex !== -1) {
@@ -100,25 +107,29 @@ export class LocalBalanceStore extends BalanceStore {
toTokens.sort();
}
}
_.set(this._balances.erc721, [fromAddress, assetAddress], fromTokens);
_.set(this._balances.erc721, [toAddress, assetAddress], toTokens);
_.set(this._balances.erc721, [fromAddress, tokenAddress], fromTokens);
_.set(this._balances.erc721, [toAddress, tokenAddress], toTokens);
break;
}
case AssetProxyId.ERC1155: {
const erc1155AssetData = assetDataUtils.decodeERC1155AssetData(assetData);
const assetAddress = erc1155AssetData.tokenAddress;
const [
proxyId, // tslint:disable-line:no-unused-variable
tokenAddress,
tokenIds,
tokenValues,
] = await this._devUtils.decodeERC1155AssetData.callAsync(assetData);
const fromBalances = {
// tslint:disable-next-line:no-inferred-empty-object-type
fungible: _.get(this._balances.erc1155, [fromAddress, assetAddress, 'fungible'], {}),
nonFungible: _.get(this._balances.erc1155, [fromAddress, assetAddress, 'nonFungible'], []),
fungible: _.get(this._balances.erc1155, [fromAddress, tokenAddress, 'fungible'], {}),
nonFungible: _.get(this._balances.erc1155, [fromAddress, tokenAddress, 'nonFungible'], []),
};
const toBalances = {
// tslint:disable-next-line:no-inferred-empty-object-type
fungible: _.get(this._balances.erc1155, [toAddress, assetAddress, 'fungible'], {}),
nonFungible: _.get(this._balances.erc1155, [toAddress, assetAddress, 'nonFungible'], []),
fungible: _.get(this._balances.erc1155, [toAddress, tokenAddress, 'fungible'], {}),
nonFungible: _.get(this._balances.erc1155, [toAddress, tokenAddress, 'nonFungible'], []),
};
for (const [i, tokenId] of erc1155AssetData.tokenIds.entries()) {
const tokenValue = erc1155AssetData.tokenValues[i];
for (const [i, tokenId] of tokenIds.entries()) {
const tokenValue = tokenValues[i];
const tokenAmount = amount.times(tokenValue);
if (tokenAmount.gt(0)) {
const tokenIndex = _.findIndex(fromBalances.nonFungible as BigNumber[], t => t.eq(tokenId));
@@ -138,16 +149,18 @@ export class LocalBalanceStore extends BalanceStore {
}
}
}
_.set(this._balances.erc1155, [fromAddress, assetAddress], fromBalances);
_.set(this._balances.erc1155, [toAddress, assetAddress], toBalances);
_.set(this._balances.erc1155, [fromAddress, tokenAddress], fromBalances);
_.set(this._balances.erc1155, [toAddress, tokenAddress], toBalances);
break;
}
case AssetProxyId.MultiAsset: {
const multiAssetData = assetDataUtils.decodeMultiAssetData(assetData);
for (const i of _.times(multiAssetData.amounts.length)) {
const nestedAmount = amount.times(multiAssetData.amounts[i]);
const nestedAssetData = multiAssetData.nestedAssetData[i];
this.transferAsset(fromAddress, toAddress, nestedAmount, nestedAssetData);
// tslint:disable-next-line:no-unused-variable
const [proxyId, amounts, nestedAssetData] = await this._devUtils.decodeMultiAssetData.callAsync(
assetData,
);
for (const [i, amt] of amounts.entries()) {
const nestedAmount = amount.times(amt);
await this.transferAssetAsync(fromAddress, toAddress, nestedAmount, nestedAssetData[i]);
}
break;
}

View File

@@ -10,6 +10,7 @@ import {
StaticCallProxyContract,
TestStaticCallTargetContract,
} from '@0x/contracts-asset-proxy';
import { DevUtilsContract } from '@0x/contracts-dev-utils';
import { ERC1155MintableContract } from '@0x/contracts-erc1155';
import {
artifacts as erc20Artifacts,
@@ -32,7 +33,7 @@ import {
txDefaults,
web3Wrapper,
} from '@0x/contracts-test-utils';
import { assetDataUtils, ExchangeRevertErrors, LibMathRevertErrors, orderHashUtils } from '@0x/order-utils';
import { ExchangeRevertErrors, LibMathRevertErrors, orderHashUtils } from '@0x/order-utils';
import { RevertReason, SignatureType, SignedOrder } from '@0x/types';
import { BigNumber, providerUtils, StringRevertError } from '@0x/utils';
import { Web3Wrapper } from '@0x/web3-wrapper';
@@ -59,6 +60,7 @@ blockchainTests.resets('Exchange core', () => {
let takerAddress: string;
let feeRecipientAddress: string;
let devUtils: DevUtilsContract;
let erc20TokenA: DummyERC20TokenContract;
let erc20TokenB: DummyERC20TokenContract;
let feeToken: DummyERC20TokenContract;
@@ -100,6 +102,7 @@ blockchainTests.resets('Exchange core', () => {
const accounts = await web3Wrapper.getAvailableAddressesAsync();
const usedAddresses = ([owner, makerAddress, takerAddress, feeRecipientAddress] = _.slice(accounts, 0, 4));
devUtils = new DevUtilsContract(constants.NULL_ADDRESS, provider);
erc20Wrapper = new ERC20Wrapper(provider, usedAddresses, owner);
erc721Wrapper = new ERC721Wrapper(provider, usedAddresses, owner);
erc1155ProxyWrapper = new ERC1155ProxyWrapper(provider, usedAddresses, owner);
@@ -213,10 +216,10 @@ blockchainTests.resets('Exchange core', () => {
...constants.STATIC_ORDER_PARAMS,
makerAddress,
feeRecipientAddress,
makerAssetData: assetDataUtils.encodeERC20AssetData(defaultMakerAssetAddress),
takerAssetData: assetDataUtils.encodeERC20AssetData(defaultTakerAssetAddress),
makerFeeAssetData: assetDataUtils.encodeERC20AssetData(defaultFeeAssetAddress),
takerFeeAssetData: assetDataUtils.encodeERC20AssetData(defaultFeeAssetAddress),
makerAssetData: await devUtils.encodeERC20AssetData.callAsync(defaultMakerAssetAddress),
takerAssetData: await devUtils.encodeERC20AssetData.callAsync(defaultTakerAssetAddress),
makerFeeAssetData: await devUtils.encodeERC20AssetData.callAsync(defaultFeeAssetAddress),
takerFeeAssetData: await devUtils.encodeERC20AssetData.callAsync(defaultFeeAssetAddress),
exchangeAddress: exchange.address,
chainId,
};
@@ -239,6 +242,7 @@ blockchainTests.resets('Exchange core', () => {
};
fillOrderWrapper = new FillOrderWrapper(
exchange,
devUtils,
{ makerAddress, takerAddress, feeRecipientAddress },
tokenContracts,
tokenIds,
@@ -421,9 +425,9 @@ blockchainTests.resets('Exchange core', () => {
describe('Fill transfer ordering', () => {
it('should allow the maker to exchange assets received by the taker', async () => {
// Set maker/taker assetData to the same asset
const takerAssetData = assetDataUtils.encodeERC20AssetData(erc20TokenA.address);
const takerAssetData = await devUtils.encodeERC20AssetData.callAsync(erc20TokenA.address);
const takerAssetAmount = new BigNumber(1);
const makerAssetData = assetDataUtils.encodeMultiAssetData([takerAssetAmount], [takerAssetData]);
const makerAssetData = await devUtils.encodeMultiAssetData.callAsync([takerAssetAmount], [takerAssetData]);
signedOrder = await orderFactory.newSignedOrderAsync({
makerAssetData,
takerAssetData,
@@ -439,7 +443,7 @@ blockchainTests.resets('Exchange core', () => {
await fillOrderWrapper.fillOrderAndAssertEffectsAsync(signedOrder, takerAddress);
});
it('should allow the taker to pay fees with an asset that received by the maker', async () => {
const makerAssetData = assetDataUtils.encodeERC20AssetData(erc20TokenA.address);
const makerAssetData = await devUtils.encodeERC20AssetData.callAsync(erc20TokenA.address);
signedOrder = await orderFactory.newSignedOrderAsync({
takerFeeAssetData: makerAssetData,
makerFee: constants.ZERO_AMOUNT,
@@ -452,7 +456,7 @@ blockchainTests.resets('Exchange core', () => {
await fillOrderWrapper.fillOrderAndAssertEffectsAsync(signedOrder, takerAddress);
});
it('should allow the maker to pay fees with an asset that received by the taker', async () => {
const takerAssetData = assetDataUtils.encodeERC20AssetData(erc20TokenB.address);
const takerAssetData = await devUtils.encodeERC20AssetData.callAsync(erc20TokenB.address);
signedOrder = await orderFactory.newSignedOrderAsync({
makerFeeAssetData: takerAssetData,
makerFee: new BigNumber(1),
@@ -479,7 +483,7 @@ blockchainTests.resets('Exchange core', () => {
});
it('should transfer the correct amounts when makerAssetAmount === takerAssetAmount', async () => {
signedOrder = await orderFactory.newSignedOrderAsync({
makerAssetData: assetDataUtils.encodeERC20AssetData(noReturnErc20Token.address),
makerAssetData: await devUtils.encodeERC20AssetData.callAsync(noReturnErc20Token.address),
makerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(100), 18),
takerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(100), 18),
});
@@ -487,7 +491,7 @@ blockchainTests.resets('Exchange core', () => {
});
it('should transfer the correct amounts when makerAssetAmount > takerAssetAmount', async () => {
signedOrder = await orderFactory.newSignedOrderAsync({
makerAssetData: assetDataUtils.encodeERC20AssetData(noReturnErc20Token.address),
makerAssetData: await devUtils.encodeERC20AssetData.callAsync(noReturnErc20Token.address),
makerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(200), 18),
takerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(100), 18),
});
@@ -495,7 +499,7 @@ blockchainTests.resets('Exchange core', () => {
});
it('should transfer the correct amounts when makerAssetAmount < takerAssetAmount', async () => {
signedOrder = await orderFactory.newSignedOrderAsync({
makerAssetData: assetDataUtils.encodeERC20AssetData(noReturnErc20Token.address),
makerAssetData: await devUtils.encodeERC20AssetData.callAsync(noReturnErc20Token.address),
makerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(100), 18),
takerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(200), 18),
});
@@ -672,8 +676,8 @@ blockchainTests.resets('Exchange core', () => {
signedOrder = await orderFactory.newSignedOrderAsync({
makerAssetAmount: new BigNumber(1),
takerAssetAmount: new BigNumber(1),
makerAssetData: assetDataUtils.encodeERC721AssetData(erc721Token.address, makerAssetId),
takerAssetData: assetDataUtils.encodeERC721AssetData(erc721Token.address, takerAssetId),
makerAssetData: await devUtils.encodeERC721AssetData.callAsync(erc721Token.address, makerAssetId),
takerAssetData: await devUtils.encodeERC721AssetData.callAsync(erc721Token.address, takerAssetId),
});
const orderHashHex = orderHashUtils.getOrderHashHex(signedOrder);
// Verify pre-conditions
@@ -699,8 +703,8 @@ blockchainTests.resets('Exchange core', () => {
signedOrder = await orderFactory.newSignedOrderAsync({
makerAssetAmount: new BigNumber(1),
takerAssetAmount: new BigNumber(1),
makerAssetData: assetDataUtils.encodeERC721AssetData(erc721Token.address, makerAssetId),
takerAssetData: assetDataUtils.encodeERC721AssetData(erc721Token.address, takerAssetId),
makerAssetData: await devUtils.encodeERC721AssetData.callAsync(erc721Token.address, makerAssetId),
takerAssetData: await devUtils.encodeERC721AssetData.callAsync(erc721Token.address, takerAssetId),
});
const orderHashHex = orderHashUtils.getOrderHashHex(signedOrder);
// Verify pre-conditions
@@ -726,8 +730,8 @@ blockchainTests.resets('Exchange core', () => {
signedOrder = await orderFactory.newSignedOrderAsync({
makerAssetAmount: new BigNumber(2),
takerAssetAmount: new BigNumber(1),
makerAssetData: assetDataUtils.encodeERC721AssetData(erc721Token.address, makerAssetId),
takerAssetData: assetDataUtils.encodeERC721AssetData(erc721Token.address, takerAssetId),
makerAssetData: await devUtils.encodeERC721AssetData.callAsync(erc721Token.address, makerAssetId),
takerAssetData: await devUtils.encodeERC721AssetData.callAsync(erc721Token.address, takerAssetId),
});
const orderHashHex = orderHashUtils.getOrderHashHex(signedOrder);
// Verify pre-conditions
@@ -753,8 +757,8 @@ blockchainTests.resets('Exchange core', () => {
signedOrder = await orderFactory.newSignedOrderAsync({
makerAssetAmount: new BigNumber(1),
takerAssetAmount: new BigNumber(500),
makerAssetData: assetDataUtils.encodeERC721AssetData(erc721Token.address, makerAssetId),
takerAssetData: assetDataUtils.encodeERC721AssetData(erc721Token.address, takerAssetId),
makerAssetData: await devUtils.encodeERC721AssetData.callAsync(erc721Token.address, makerAssetId),
takerAssetData: await devUtils.encodeERC721AssetData.callAsync(erc721Token.address, takerAssetId),
});
const orderHashHex = orderHashUtils.getOrderHashHex(signedOrder);
// Verify pre-conditions
@@ -779,8 +783,8 @@ blockchainTests.resets('Exchange core', () => {
signedOrder = await orderFactory.newSignedOrderAsync({
makerAssetAmount: new BigNumber(1),
takerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(100), 18),
makerAssetData: assetDataUtils.encodeERC721AssetData(erc721Token.address, makerAssetId),
takerAssetData: assetDataUtils.encodeERC20AssetData(defaultTakerAssetAddress),
makerAssetData: await devUtils.encodeERC721AssetData.callAsync(erc721Token.address, makerAssetId),
takerAssetData: await devUtils.encodeERC20AssetData.callAsync(defaultTakerAssetAddress),
});
// Call Exchange
const takerAssetFillAmount = signedOrder.takerAssetAmount.div(2);
@@ -798,12 +802,12 @@ blockchainTests.resets('Exchange core', () => {
it('should allow multiple assets to be exchanged for a single asset', async () => {
const makerAmounts = [new BigNumber(10), new BigNumber(20)];
const makerNestedAssetData = [
assetDataUtils.encodeERC20AssetData(erc20TokenA.address),
assetDataUtils.encodeERC20AssetData(erc20TokenB.address),
await devUtils.encodeERC20AssetData.callAsync(erc20TokenA.address),
await devUtils.encodeERC20AssetData.callAsync(erc20TokenB.address),
];
const makerAssetData = assetDataUtils.encodeMultiAssetData(makerAmounts, makerNestedAssetData);
const makerAssetData = await devUtils.encodeMultiAssetData.callAsync(makerAmounts, makerNestedAssetData);
const makerAssetAmount = new BigNumber(1);
const takerAssetData = assetDataUtils.encodeERC20AssetData(feeToken.address);
const takerAssetData = await devUtils.encodeERC20AssetData.callAsync(feeToken.address);
const takerAssetAmount = new BigNumber(10);
signedOrder = await orderFactory.newSignedOrderAsync({
makerAssetData,
@@ -818,18 +822,18 @@ blockchainTests.resets('Exchange core', () => {
it('should allow multiple assets to be exchanged for multiple assets', async () => {
const makerAmounts = [new BigNumber(10), new BigNumber(20)];
const makerNestedAssetData = [
assetDataUtils.encodeERC20AssetData(erc20TokenA.address),
assetDataUtils.encodeERC20AssetData(erc20TokenB.address),
await devUtils.encodeERC20AssetData.callAsync(erc20TokenA.address),
await devUtils.encodeERC20AssetData.callAsync(erc20TokenB.address),
];
const makerAssetData = assetDataUtils.encodeMultiAssetData(makerAmounts, makerNestedAssetData);
const makerAssetData = await devUtils.encodeMultiAssetData.callAsync(makerAmounts, makerNestedAssetData);
const makerAssetAmount = new BigNumber(1);
const takerAmounts = [new BigNumber(10), new BigNumber(1)];
const takerAssetId = erc721TakerAssetIds[0];
const takerNestedAssetData = [
assetDataUtils.encodeERC20AssetData(feeToken.address),
assetDataUtils.encodeERC721AssetData(erc721Token.address, takerAssetId),
await devUtils.encodeERC20AssetData.callAsync(feeToken.address),
await devUtils.encodeERC721AssetData.callAsync(erc721Token.address, takerAssetId),
];
const takerAssetData = assetDataUtils.encodeMultiAssetData(takerAmounts, takerNestedAssetData);
const takerAssetData = await devUtils.encodeMultiAssetData.callAsync(takerAmounts, takerNestedAssetData);
const takerAssetAmount = new BigNumber(1);
signedOrder = await orderFactory.newSignedOrderAsync({
makerAssetData,
@@ -844,12 +848,12 @@ blockchainTests.resets('Exchange core', () => {
it('should allow an order selling multiple assets to be partially filled', async () => {
const makerAmounts = [new BigNumber(10), new BigNumber(20)];
const makerNestedAssetData = [
assetDataUtils.encodeERC20AssetData(erc20TokenA.address),
assetDataUtils.encodeERC20AssetData(erc20TokenB.address),
await devUtils.encodeERC20AssetData.callAsync(erc20TokenA.address),
await devUtils.encodeERC20AssetData.callAsync(erc20TokenB.address),
];
const makerAssetData = assetDataUtils.encodeMultiAssetData(makerAmounts, makerNestedAssetData);
const makerAssetData = await devUtils.encodeMultiAssetData.callAsync(makerAmounts, makerNestedAssetData);
const makerAssetAmount = new BigNumber(30);
const takerAssetData = assetDataUtils.encodeERC20AssetData(feeToken.address);
const takerAssetData = await devUtils.encodeERC20AssetData.callAsync(feeToken.address);
const takerAssetAmount = new BigNumber(10);
signedOrder = await orderFactory.newSignedOrderAsync({
makerAssetData,
@@ -866,12 +870,12 @@ blockchainTests.resets('Exchange core', () => {
it('should allow an order buying multiple assets to be partially filled', async () => {
const takerAmounts = [new BigNumber(10), new BigNumber(20)];
const takerNestedAssetData = [
assetDataUtils.encodeERC20AssetData(erc20TokenA.address),
assetDataUtils.encodeERC20AssetData(erc20TokenB.address),
await devUtils.encodeERC20AssetData.callAsync(erc20TokenA.address),
await devUtils.encodeERC20AssetData.callAsync(erc20TokenB.address),
];
const takerAssetData = assetDataUtils.encodeMultiAssetData(takerAmounts, takerNestedAssetData);
const takerAssetData = await devUtils.encodeMultiAssetData.callAsync(takerAmounts, takerNestedAssetData);
const takerAssetAmount = new BigNumber(30);
const makerAssetData = assetDataUtils.encodeERC20AssetData(feeToken.address);
const makerAssetData = await devUtils.encodeERC20AssetData.callAsync(feeToken.address);
const makerAssetAmount = new BigNumber(10);
signedOrder = await orderFactory.newSignedOrderAsync({
makerAssetData,
@@ -897,13 +901,13 @@ blockchainTests.resets('Exchange core', () => {
const makerAssetAmount = new BigNumber(1);
const takerAssetAmount = new BigNumber(1);
const receiverCallbackData = '0x';
const makerAssetData = assetDataUtils.encodeERC1155AssetData(
const makerAssetData = await devUtils.encodeERC1155AssetData.callAsync(
erc1155Contract.address,
makerAssetsToTransfer,
makerValuesToTransfer,
receiverCallbackData,
);
const takerAssetData = assetDataUtils.encodeERC1155AssetData(
const takerAssetData = await devUtils.encodeERC1155AssetData.callAsync(
erc1155Contract.address,
takerAssetsToTransfer,
takerValuesToTransfer,
@@ -932,13 +936,13 @@ blockchainTests.resets('Exchange core', () => {
const makerAssetAmount = new BigNumber(1);
const takerAssetAmount = new BigNumber(1);
const receiverCallbackData = '0x';
const makerAssetData = assetDataUtils.encodeERC1155AssetData(
const makerAssetData = await devUtils.encodeERC1155AssetData.callAsync(
erc1155Contract.address,
makerAssetsToTransfer,
makerValuesToTransfer,
receiverCallbackData,
);
const takerAssetData = assetDataUtils.encodeERC1155AssetData(
const takerAssetData = await devUtils.encodeERC1155AssetData.callAsync(
erc1155Contract.address,
takerAssetsToTransfer,
takerValuesToTransfer,
@@ -966,13 +970,13 @@ blockchainTests.resets('Exchange core', () => {
const makerAssetAmount = new BigNumber(1);
const takerAssetAmount = new BigNumber(1);
const receiverCallbackData = '0x';
const makerAssetData = assetDataUtils.encodeERC1155AssetData(
const makerAssetData = await devUtils.encodeERC1155AssetData.callAsync(
erc1155Contract.address,
makerAssetsToTransfer,
makerValuesToTransfer,
receiverCallbackData,
);
const takerAssetData = assetDataUtils.encodeERC1155AssetData(
const takerAssetData = await devUtils.encodeERC1155AssetData.callAsync(
erc1155Contract.address,
takerAssetsToTransfer,
takerValuesToTransfer,
@@ -1006,13 +1010,13 @@ blockchainTests.resets('Exchange core', () => {
const makerAssetAmount = new BigNumber(1);
const takerAssetAmount = new BigNumber(1);
const receiverCallbackData = '0x';
const makerAssetData = assetDataUtils.encodeERC1155AssetData(
const makerAssetData = await devUtils.encodeERC1155AssetData.callAsync(
erc1155Contract.address,
makerAssetsToTransfer,
makerValuesToTransfer,
receiverCallbackData,
);
const takerAssetData = assetDataUtils.encodeERC1155AssetData(
const takerAssetData = await devUtils.encodeERC1155AssetData.callAsync(
erc1155Contract.address,
takerAssetsToTransfer,
takerValuesToTransfer,
@@ -1051,13 +1055,13 @@ blockchainTests.resets('Exchange core', () => {
const makerAssetAmount = new BigNumber(10);
const takerAssetAmount = new BigNumber(20);
const receiverCallbackData = '0x';
const makerAssetData = assetDataUtils.encodeERC1155AssetData(
const makerAssetData = await devUtils.encodeERC1155AssetData.callAsync(
erc1155Contract.address,
makerAssetsToTransfer,
makerValuesToTransfer,
receiverCallbackData,
);
const takerAssetData = assetDataUtils.encodeERC1155AssetData(
const takerAssetData = await devUtils.encodeERC1155AssetData.callAsync(
erc1155Contract.address,
takerAssetsToTransfer,
takerValuesToTransfer,
@@ -1088,7 +1092,7 @@ blockchainTests.resets('Exchange core', () => {
});
it('should revert if the staticcall is unsuccessful', async () => {
const staticCallData = staticCallTarget.assertEvenNumber.getABIEncodedTransactionData(new BigNumber(1));
const assetData = assetDataUtils.encodeStaticCallAssetData(
const assetData = await devUtils.encodeStaticCallAssetData.callAsync(
staticCallTarget.address,
staticCallData,
constants.KECCAK256_NULL,
@@ -1107,7 +1111,7 @@ blockchainTests.resets('Exchange core', () => {
const staticCallData = staticCallTarget.assertEvenNumber.getABIEncodedTransactionData(
constants.ZERO_AMOUNT,
);
const assetData = assetDataUtils.encodeStaticCallAssetData(
const assetData = await devUtils.encodeStaticCallAssetData.callAsync(
staticCallTarget.address,
staticCallData,
constants.KECCAK256_NULL,
@@ -1117,14 +1121,14 @@ blockchainTests.resets('Exchange core', () => {
});
it('should revert if the staticcall is unsuccessful using the MultiAssetProxy', async () => {
const staticCallData = staticCallTarget.assertEvenNumber.getABIEncodedTransactionData(new BigNumber(1));
const staticCallAssetData = assetDataUtils.encodeStaticCallAssetData(
const staticCallAssetData = await devUtils.encodeStaticCallAssetData.callAsync(
staticCallTarget.address,
staticCallData,
constants.KECCAK256_NULL,
);
const assetData = assetDataUtils.encodeMultiAssetData(
const assetData = await devUtils.encodeMultiAssetData.callAsync(
[new BigNumber(1), new BigNumber(1)],
[assetDataUtils.encodeERC20AssetData(defaultMakerAssetAddress), staticCallAssetData],
[await devUtils.encodeERC20AssetData.callAsync(defaultMakerAssetAddress), staticCallAssetData],
);
signedOrder = await orderFactory.newSignedOrderAsync({ makerAssetData: assetData });
const orderHashHex = orderHashUtils.getOrderHashHex(signedOrder);
@@ -1140,14 +1144,14 @@ blockchainTests.resets('Exchange core', () => {
const staticCallData = staticCallTarget.assertEvenNumber.getABIEncodedTransactionData(
constants.ZERO_AMOUNT,
);
const staticCallAssetData = assetDataUtils.encodeStaticCallAssetData(
const staticCallAssetData = await devUtils.encodeStaticCallAssetData.callAsync(
staticCallTarget.address,
staticCallData,
constants.KECCAK256_NULL,
);
const assetData = assetDataUtils.encodeMultiAssetData(
const assetData = await devUtils.encodeMultiAssetData.callAsync(
[new BigNumber(1), new BigNumber(1)],
[assetDataUtils.encodeERC20AssetData(defaultMakerAssetAddress), staticCallAssetData],
[await devUtils.encodeERC20AssetData.callAsync(defaultMakerAssetAddress), staticCallAssetData],
);
signedOrder = await orderFactory.newSignedOrderAsync({ makerAssetData: assetData });
await fillOrderWrapper.fillOrderAndAssertEffectsAsync(signedOrder, takerAddress);

View File

@@ -5,6 +5,7 @@ import {
ERC721ProxyContract,
ERC721Wrapper,
} from '@0x/contracts-asset-proxy';
import { DevUtilsContract } from '@0x/contracts-dev-utils';
import { DummyERC20TokenContract } from '@0x/contracts-erc20';
import {
chaiSetup,
@@ -16,7 +17,7 @@ import {
web3Wrapper,
} from '@0x/contracts-test-utils';
import { BlockchainLifecycle } from '@0x/dev-utils';
import { assetDataUtils, ExchangeRevertErrors } from '@0x/order-utils';
import { ExchangeRevertErrors } from '@0x/order-utils';
import { AssetProxyId, RevertReason } from '@0x/types';
import { BigNumber, OwnableRevertErrors, StringRevertError } from '@0x/utils';
import * as chai from 'chai';
@@ -50,6 +51,7 @@ describe('AssetProxyDispatcher', () => {
let erc20Wrapper: ERC20Wrapper;
let erc721Wrapper: ERC721Wrapper;
const devUtils = new DevUtilsContract(constants.NULL_ADDRESS, provider);
before(async () => {
await blockchainLifecycle.startAsync();
});
@@ -191,7 +193,7 @@ describe('AssetProxyDispatcher', () => {
from: owner,
});
// Construct metadata for ERC20 proxy
const encodedAssetData = assetDataUtils.encodeERC20AssetData(erc20TokenA.address);
const encodedAssetData = await devUtils.encodeERC20AssetData.callAsync(erc20TokenA.address);
// Perform a transfer from makerAddress to takerAddress
const erc20Balances = await erc20Wrapper.getBalancesAsync();
@@ -220,7 +222,7 @@ describe('AssetProxyDispatcher', () => {
from: owner,
});
// Construct metadata for ERC20 proxy
const encodedAssetData = assetDataUtils.encodeERC20AssetData(erc20TokenA.address);
const encodedAssetData = await devUtils.encodeERC20AssetData.callAsync(erc20TokenA.address);
// Perform a transfer from makerAddress to takerAddress
const erc20Balances = await erc20Wrapper.getBalancesAsync();
@@ -240,7 +242,8 @@ describe('AssetProxyDispatcher', () => {
it('should revert if dispatching to unregistered proxy', async () => {
// Construct metadata for ERC20 proxy
const encodedAssetData = assetDataUtils.encodeERC20AssetData(erc20TokenA.address);
const encodedAssetData = await devUtils.encodeERC20AssetData.callAsync(erc20TokenA.address);
// Perform a transfer from makerAddress to takerAddress
const amount = new BigNumber(10);
const expectedError = new ExchangeRevertErrors.AssetProxyDispatchError(
@@ -263,7 +266,7 @@ describe('AssetProxyDispatcher', () => {
await assetProxyDispatcher.registerAssetProxy.awaitTransactionSuccessAsync(erc20Proxy.address, {
from: owner,
});
const encodedAssetData = assetDataUtils.encodeERC20AssetData(erc20TokenA.address).slice(0, 8);
const encodedAssetData = (await devUtils.encodeERC20AssetData.callAsync(erc20TokenA.address)).slice(0, 8);
const amount = new BigNumber(1);
const expectedError = new ExchangeRevertErrors.AssetProxyDispatchError(
ExchangeRevertErrors.AssetProxyDispatchErrorCode.InvalidAssetDataLength,
@@ -286,7 +289,7 @@ describe('AssetProxyDispatcher', () => {
from: owner,
});
// Shave off the last byte
const encodedAssetData = assetDataUtils.encodeERC20AssetData(erc20TokenA.address).slice(0, 72);
const encodedAssetData = (await devUtils.encodeERC20AssetData.callAsync(erc20TokenA.address)).slice(0, 72);
const amount = new BigNumber(1);
const expectedError = new ExchangeRevertErrors.AssetProxyDispatchError(
ExchangeRevertErrors.AssetProxyDispatchErrorCode.InvalidAssetDataLength,
@@ -311,7 +314,7 @@ describe('AssetProxyDispatcher', () => {
await erc20TokenA.approve.awaitTransactionSuccessAsync(erc20Proxy.address, constants.ZERO_AMOUNT, {
from: makerAddress,
});
const encodedAssetData = assetDataUtils.encodeERC20AssetData(erc20TokenA.address);
const encodedAssetData = await devUtils.encodeERC20AssetData.callAsync(erc20TokenA.address);
const amount = new BigNumber(1);
const nestedError = new StringRevertError(RevertReason.TransferFailed).encode();
const expectedError = new ExchangeRevertErrors.AssetProxyTransferError(
@@ -335,8 +338,8 @@ describe('AssetProxyDispatcher', () => {
await assetProxyDispatcher.registerAssetProxy.awaitTransactionSuccessAsync(erc20Proxy.address, {
from: owner,
});
const assetDataA = assetDataUtils.encodeERC20AssetData(erc20TokenA.address);
const assetDataB = assetDataUtils.encodeERC20AssetData(erc20TokenB.address);
const assetDataA = await devUtils.encodeERC20AssetData.callAsync(erc20TokenA.address);
const assetDataB = await devUtils.encodeERC20AssetData.callAsync(erc20TokenB.address);
await erc20TokenB.approve.awaitTransactionSuccessAsync(erc20Proxy.address, constants.ZERO_AMOUNT, {
from: makerAddress,
});
@@ -356,8 +359,8 @@ describe('AssetProxyDispatcher', () => {
return expect(tx).to.revertWith(expectedError);
});
it('should forward the revert reason from the underlying failed transfer', async () => {
const assetDataA = assetDataUtils.encodeERC20AssetData(erc20TokenA.address);
const assetDataB = assetDataUtils.encodeERC20AssetData(erc20TokenB.address);
const assetDataA = await devUtils.encodeERC20AssetData.callAsync(erc20TokenA.address);
const assetDataB = await devUtils.encodeERC20AssetData.callAsync(erc20TokenB.address);
const transferIndexAsBytes32 = '0x0000000000000000000000000000000000000000000000000000000000000000';
const expectedError = new ExchangeRevertErrors.AssetProxyDispatchError(
ExchangeRevertErrors.AssetProxyDispatchErrorCode.UnknownAssetProxy,
@@ -376,8 +379,8 @@ describe('AssetProxyDispatcher', () => {
await assetProxyDispatcher.registerAssetProxy.awaitTransactionSuccessAsync(erc20Proxy.address, {
from: owner,
});
const assetDataA = assetDataUtils.encodeERC20AssetData(erc20TokenA.address);
const assetDataB = assetDataUtils.encodeERC20AssetData(erc20TokenB.address);
const assetDataA = await devUtils.encodeERC20AssetData.callAsync(erc20TokenA.address);
const assetDataB = await devUtils.encodeERC20AssetData.callAsync(erc20TokenB.address);
const tx = assetProxyDispatcher.simulateDispatchTransferFromCalls.sendTransactionAsync(
[assetDataA, assetDataB],
[makerAddress, makerAddress],
@@ -390,8 +393,8 @@ describe('AssetProxyDispatcher', () => {
await assetProxyDispatcher.registerAssetProxy.awaitTransactionSuccessAsync(erc20Proxy.address, {
from: owner,
});
const assetDataA = assetDataUtils.encodeERC20AssetData(erc20TokenA.address);
const assetDataB = assetDataUtils.encodeERC20AssetData(erc20TokenB.address);
const assetDataA = await devUtils.encodeERC20AssetData.callAsync(erc20TokenA.address);
const assetDataB = await devUtils.encodeERC20AssetData.callAsync(erc20TokenB.address);
const balances = await erc20Wrapper.getBalancesAsync();
try {
await assetProxyDispatcher.simulateDispatchTransferFromCalls.awaitTransactionSuccessAsync(

View File

@@ -8,6 +8,7 @@ import {
ERC721Wrapper,
MultiAssetProxyContract,
} from '@0x/contracts-asset-proxy';
import { DevUtilsContract } from '@0x/contracts-dev-utils';
import { ERC1155Contract as ERC1155TokenContract, Erc1155Wrapper as ERC1155Wrapper } from '@0x/contracts-erc1155';
import { DummyERC20TokenContract } from '@0x/contracts-erc20';
import { DummyERC721TokenContract } from '@0x/contracts-erc721';
@@ -22,7 +23,7 @@ import {
web3Wrapper,
} from '@0x/contracts-test-utils';
import { BlockchainLifecycle } from '@0x/dev-utils';
import { assetDataUtils, ExchangeRevertErrors, orderHashUtils } from '@0x/order-utils';
import { ExchangeRevertErrors, orderHashUtils } from '@0x/order-utils';
import { OrderStatus, SignedOrder } from '@0x/types';
import { BigNumber, providerUtils } from '@0x/utils';
import { Web3Wrapper } from '@0x/web3-wrapper';
@@ -82,6 +83,7 @@ describe('matchOrders', () => {
let matchOrderTester: MatchOrderTester;
const devUtils = new DevUtilsContract(constants.NULL_ADDRESS, provider, txDefaults);
before(async () => {
await blockchainLifecycle.startAsync();
});
@@ -177,10 +179,10 @@ describe('matchOrders', () => {
const defaultOrderParamsLeft = {
...constants.STATIC_ORDER_PARAMS,
makerAddress: makerAddressLeft,
makerAssetData: assetDataUtils.encodeERC20AssetData(defaultERC20MakerAssetAddress),
takerAssetData: assetDataUtils.encodeERC20AssetData(defaultERC20TakerAssetAddress),
makerFeeAssetData: assetDataUtils.encodeERC20AssetData(defaultFeeTokenAddress),
takerFeeAssetData: assetDataUtils.encodeERC20AssetData(defaultFeeTokenAddress),
makerAssetData: await devUtils.encodeERC20AssetData.callAsync(defaultERC20MakerAssetAddress),
takerAssetData: await devUtils.encodeERC20AssetData.callAsync(defaultERC20TakerAssetAddress),
makerFeeAssetData: await devUtils.encodeERC20AssetData.callAsync(defaultFeeTokenAddress),
takerFeeAssetData: await devUtils.encodeERC20AssetData.callAsync(defaultFeeTokenAddress),
feeRecipientAddress: feeRecipientAddressLeft,
exchangeAddress: exchange.address,
chainId,
@@ -188,10 +190,10 @@ describe('matchOrders', () => {
const defaultOrderParamsRight = {
...constants.STATIC_ORDER_PARAMS,
makerAddress: makerAddressRight,
makerAssetData: assetDataUtils.encodeERC20AssetData(defaultERC20TakerAssetAddress),
takerAssetData: assetDataUtils.encodeERC20AssetData(defaultERC20MakerAssetAddress),
makerFeeAssetData: assetDataUtils.encodeERC20AssetData(defaultFeeTokenAddress),
takerFeeAssetData: assetDataUtils.encodeERC20AssetData(defaultFeeTokenAddress),
makerAssetData: await devUtils.encodeERC20AssetData.callAsync(defaultERC20TakerAssetAddress),
takerAssetData: await devUtils.encodeERC20AssetData.callAsync(defaultERC20MakerAssetAddress),
makerFeeAssetData: await devUtils.encodeERC20AssetData.callAsync(defaultFeeTokenAddress),
takerFeeAssetData: await devUtils.encodeERC20AssetData.callAsync(defaultFeeTokenAddress),
feeRecipientAddress: feeRecipientAddressRight,
exchangeAddress: exchange.address,
chainId,
@@ -201,7 +203,13 @@ describe('matchOrders', () => {
const privateKeyRight = constants.TESTRPC_PRIVATE_KEYS[accounts.indexOf(makerAddressRight)];
orderFactoryRight = new OrderFactory(privateKeyRight, defaultOrderParamsRight);
// Create match order tester
matchOrderTester = new MatchOrderTester(exchangeWrapper, erc20Wrapper, erc721Wrapper, erc1155ProxyWrapper);
matchOrderTester = new MatchOrderTester(
exchangeWrapper,
erc20Wrapper,
erc721Wrapper,
erc1155ProxyWrapper,
devUtils,
);
tokenBalances = await matchOrderTester.getBalancesAsync();
});
beforeEach(async () => {
@@ -338,8 +346,8 @@ describe('matchOrders', () => {
});
const signedOrderRight = await orderFactoryRight.newSignedOrderAsync({
makerAddress: makerAddressRight,
makerAssetData: assetDataUtils.encodeERC20AssetData(defaultERC20TakerAssetAddress),
takerAssetData: assetDataUtils.encodeERC20AssetData(defaultERC20MakerAssetAddress),
makerAssetData: await devUtils.encodeERC20AssetData.callAsync(defaultERC20TakerAssetAddress),
takerAssetData: await devUtils.encodeERC20AssetData.callAsync(defaultERC20MakerAssetAddress),
makerAssetAmount: Web3Wrapper.toBaseUnitAmount(83, 0),
takerAssetAmount: Web3Wrapper.toBaseUnitAmount(49, 0),
feeRecipientAddress: feeRecipientAddressRight,
@@ -392,8 +400,8 @@ describe('matchOrders', () => {
});
const signedOrderRight = await orderFactoryRight.newSignedOrderAsync({
makerAddress: makerAddressRight,
makerAssetData: assetDataUtils.encodeERC20AssetData(defaultERC20TakerAssetAddress),
takerAssetData: assetDataUtils.encodeERC20AssetData(defaultERC20MakerAssetAddress),
makerAssetData: await devUtils.encodeERC20AssetData.callAsync(defaultERC20TakerAssetAddress),
takerAssetData: await devUtils.encodeERC20AssetData.callAsync(defaultERC20MakerAssetAddress),
makerAssetAmount: Web3Wrapper.toBaseUnitAmount(89, 0),
takerAssetAmount: Web3Wrapper.toBaseUnitAmount(1, 0),
feeRecipientAddress: feeRecipientAddressRight,
@@ -443,8 +451,8 @@ describe('matchOrders', () => {
});
const signedOrderRight = await orderFactoryRight.newSignedOrderAsync({
makerAddress: makerAddressRight,
makerAssetData: assetDataUtils.encodeERC20AssetData(defaultERC20TakerAssetAddress),
takerAssetData: assetDataUtils.encodeERC20AssetData(defaultERC20MakerAssetAddress),
makerAssetData: await devUtils.encodeERC20AssetData.callAsync(defaultERC20TakerAssetAddress),
takerAssetData: await devUtils.encodeERC20AssetData.callAsync(defaultERC20MakerAssetAddress),
makerAssetAmount: Web3Wrapper.toBaseUnitAmount(83, 0),
takerAssetAmount: Web3Wrapper.toBaseUnitAmount(49, 0),
feeRecipientAddress: feeRecipientAddressRight,
@@ -492,8 +500,8 @@ describe('matchOrders', () => {
});
const signedOrderRight = await orderFactoryRight.newSignedOrderAsync({
makerAddress: makerAddressRight,
makerAssetData: assetDataUtils.encodeERC20AssetData(defaultERC20TakerAssetAddress),
takerAssetData: assetDataUtils.encodeERC20AssetData(defaultERC20MakerAssetAddress),
makerAssetData: await devUtils.encodeERC20AssetData.callAsync(defaultERC20TakerAssetAddress),
takerAssetData: await devUtils.encodeERC20AssetData.callAsync(defaultERC20MakerAssetAddress),
makerAssetAmount: Web3Wrapper.toBaseUnitAmount(89, 0),
takerAssetAmount: Web3Wrapper.toBaseUnitAmount(1, 0),
feeRecipientAddress: feeRecipientAddressRight,
@@ -537,8 +545,8 @@ describe('matchOrders', () => {
});
const signedOrderRight = await orderFactoryRight.newSignedOrderAsync({
makerAddress: makerAddressRight,
makerAssetData: assetDataUtils.encodeERC20AssetData(defaultERC20TakerAssetAddress),
takerAssetData: assetDataUtils.encodeERC20AssetData(defaultERC20MakerAssetAddress),
makerAssetData: await devUtils.encodeERC20AssetData.callAsync(defaultERC20TakerAssetAddress),
takerAssetData: await devUtils.encodeERC20AssetData.callAsync(defaultERC20MakerAssetAddress),
makerAssetAmount: Web3Wrapper.toBaseUnitAmount(2126, 0),
takerAssetAmount: Web3Wrapper.toBaseUnitAmount(1063, 0),
feeRecipientAddress: feeRecipientAddressRight,
@@ -1162,7 +1170,7 @@ describe('matchOrders', () => {
const signedOrderLeft = await orderFactoryLeft.newSignedOrderAsync({
makerAssetAmount: Web3Wrapper.toBaseUnitAmount(5, 18),
takerAssetAmount: Web3Wrapper.toBaseUnitAmount(10, 18),
makerFeeAssetData: assetDataUtils.encodeERC20AssetData(defaultERC20TakerAssetAddress),
makerFeeAssetData: await devUtils.encodeERC20AssetData.callAsync(defaultERC20TakerAssetAddress),
feeRecipientAddress: makerAddressLeft,
});
const signedOrderRight = await orderFactoryRight.newSignedOrderAsync({
@@ -1259,7 +1267,7 @@ describe('matchOrders', () => {
takerAssetAmount: Web3Wrapper.toBaseUnitAmount(10, 18),
});
const signedOrderRight = await orderFactoryRight.newSignedOrderAsync({
takerAssetData: assetDataUtils.encodeERC20AssetData(defaultERC20TakerAssetAddress),
takerAssetData: await devUtils.encodeERC20AssetData.callAsync(defaultERC20TakerAssetAddress),
makerAssetAmount: Web3Wrapper.toBaseUnitAmount(10, 18),
takerAssetAmount: Web3Wrapper.toBaseUnitAmount(2, 18),
});
@@ -1286,7 +1294,7 @@ describe('matchOrders', () => {
it('should revert if the right maker asset is not equal to the left taker asset', async () => {
// Create orders to match
const signedOrderLeft = await orderFactoryLeft.newSignedOrderAsync({
takerAssetData: assetDataUtils.encodeERC20AssetData(defaultERC20MakerAssetAddress),
takerAssetData: await devUtils.encodeERC20AssetData.callAsync(defaultERC20MakerAssetAddress),
makerAssetAmount: Web3Wrapper.toBaseUnitAmount(5, 18),
takerAssetAmount: Web3Wrapper.toBaseUnitAmount(10, 18),
});
@@ -1440,8 +1448,8 @@ describe('matchOrders', () => {
});
const signedOrderRight = await orderFactoryRight.newSignedOrderAsync({
makerAddress: makerAddressRight,
makerAssetData: assetDataUtils.encodeERC20AssetData(defaultERC20TakerAssetAddress),
takerAssetData: assetDataUtils.encodeERC20AssetData(defaultERC20MakerAssetAddress),
makerAssetData: await devUtils.encodeERC20AssetData.callAsync(defaultERC20TakerAssetAddress),
takerAssetData: await devUtils.encodeERC20AssetData.callAsync(defaultERC20MakerAssetAddress),
makerAssetAmount: Web3Wrapper.toBaseUnitAmount(87, 0),
takerAssetAmount: Web3Wrapper.toBaseUnitAmount(48, 0),
feeRecipientAddress: feeRecipientAddressRight,
@@ -1528,8 +1536,8 @@ describe('matchOrders', () => {
});
const signedOrderRight = await orderFactoryRight.newSignedOrderAsync({
makerAddress: makerAddressRight,
makerAssetData: assetDataUtils.encodeERC20AssetData(defaultERC20TakerAssetAddress),
takerAssetData: assetDataUtils.encodeERC20AssetData(defaultERC20MakerAssetAddress),
makerAssetData: await devUtils.encodeERC20AssetData.callAsync(defaultERC20TakerAssetAddress),
takerAssetData: await devUtils.encodeERC20AssetData.callAsync(defaultERC20MakerAssetAddress),
makerAssetAmount: Web3Wrapper.toBaseUnitAmount(89, 0),
takerAssetAmount: Web3Wrapper.toBaseUnitAmount(1, 0),
feeRecipientAddress: feeRecipientAddressRight,
@@ -1579,8 +1587,8 @@ describe('matchOrders', () => {
});
const signedOrderRight = await orderFactoryRight.newSignedOrderAsync({
makerAddress: makerAddressRight,
makerAssetData: assetDataUtils.encodeERC20AssetData(defaultERC20TakerAssetAddress),
takerAssetData: assetDataUtils.encodeERC20AssetData(defaultERC20MakerAssetAddress),
makerAssetData: await devUtils.encodeERC20AssetData.callAsync(defaultERC20TakerAssetAddress),
takerAssetData: await devUtils.encodeERC20AssetData.callAsync(defaultERC20MakerAssetAddress),
makerAssetAmount: Web3Wrapper.toBaseUnitAmount(87, 0),
takerAssetAmount: Web3Wrapper.toBaseUnitAmount(48, 0),
feeRecipientAddress: feeRecipientAddressRight,
@@ -1625,8 +1633,8 @@ describe('matchOrders', () => {
});
const signedOrderRight = await orderFactoryRight.newSignedOrderAsync({
makerAddress: makerAddressRight,
makerAssetData: assetDataUtils.encodeERC20AssetData(defaultERC20TakerAssetAddress),
takerAssetData: assetDataUtils.encodeERC20AssetData(defaultERC20MakerAssetAddress),
makerAssetData: await devUtils.encodeERC20AssetData.callAsync(defaultERC20TakerAssetAddress),
takerAssetData: await devUtils.encodeERC20AssetData.callAsync(defaultERC20MakerAssetAddress),
makerAssetAmount: Web3Wrapper.toBaseUnitAmount(89, 0),
takerAssetAmount: Web3Wrapper.toBaseUnitAmount(1, 0),
feeRecipientAddress: feeRecipientAddressRight,
@@ -1670,8 +1678,8 @@ describe('matchOrders', () => {
});
const signedOrderRight = await orderFactoryRight.newSignedOrderAsync({
makerAddress: makerAddressRight,
makerAssetData: assetDataUtils.encodeERC20AssetData(defaultERC20TakerAssetAddress),
takerAssetData: assetDataUtils.encodeERC20AssetData(defaultERC20MakerAssetAddress),
makerAssetData: await devUtils.encodeERC20AssetData.callAsync(defaultERC20TakerAssetAddress),
takerAssetData: await devUtils.encodeERC20AssetData.callAsync(defaultERC20MakerAssetAddress),
makerAssetAmount: Web3Wrapper.toBaseUnitAmount(89, 0),
takerAssetAmount: Web3Wrapper.toBaseUnitAmount(1, 0),
feeRecipientAddress: feeRecipientAddressRight,
@@ -1789,8 +1797,8 @@ describe('matchOrders', () => {
});
const signedOrderRight = await orderFactoryRight.newSignedOrderAsync({
makerAddress: makerAddressRight,
makerAssetData: assetDataUtils.encodeERC20AssetData(defaultERC20TakerAssetAddress),
takerAssetData: assetDataUtils.encodeERC20AssetData(defaultERC20MakerAssetAddress),
makerAssetData: await devUtils.encodeERC20AssetData.callAsync(defaultERC20TakerAssetAddress),
takerAssetData: await devUtils.encodeERC20AssetData.callAsync(defaultERC20MakerAssetAddress),
makerAssetAmount: Web3Wrapper.toBaseUnitAmount(2126, 0),
takerAssetAmount: Web3Wrapper.toBaseUnitAmount(1063, 0),
feeRecipientAddress: feeRecipientAddressRight,
@@ -2243,7 +2251,7 @@ describe('matchOrders', () => {
const signedOrderLeft = await orderFactoryLeft.newSignedOrderAsync({
makerAssetAmount: Web3Wrapper.toBaseUnitAmount(5, 18),
takerAssetAmount: Web3Wrapper.toBaseUnitAmount(10, 18),
makerFeeAssetData: assetDataUtils.encodeERC20AssetData(defaultERC20TakerAssetAddress),
makerFeeAssetData: await devUtils.encodeERC20AssetData.callAsync(defaultERC20TakerAssetAddress),
feeRecipientAddress: makerAddressLeft,
});
const signedOrderRight = await orderFactoryRight.newSignedOrderAsync({
@@ -2340,7 +2348,7 @@ describe('matchOrders', () => {
takerAssetAmount: Web3Wrapper.toBaseUnitAmount(10, 18),
});
const signedOrderRight = await orderFactoryRight.newSignedOrderAsync({
takerAssetData: assetDataUtils.encodeERC20AssetData(defaultERC20TakerAssetAddress),
takerAssetData: await devUtils.encodeERC20AssetData.callAsync(defaultERC20TakerAssetAddress),
makerAssetAmount: Web3Wrapper.toBaseUnitAmount(10, 18),
takerAssetAmount: Web3Wrapper.toBaseUnitAmount(2, 18),
});
@@ -2367,7 +2375,7 @@ describe('matchOrders', () => {
it('should revert if the right maker asset is not equal to the left taker asset', async () => {
// Create orders to match
const signedOrderLeft = await orderFactoryLeft.newSignedOrderAsync({
takerAssetData: assetDataUtils.encodeERC20AssetData(defaultERC20MakerAssetAddress),
takerAssetData: await devUtils.encodeERC20AssetData.callAsync(defaultERC20MakerAssetAddress),
makerAssetAmount: Web3Wrapper.toBaseUnitAmount(5, 18),
takerAssetAmount: Web3Wrapper.toBaseUnitAmount(10, 18),
});
@@ -2675,11 +2683,11 @@ describe('matchOrders', () => {
let nameToERC1155NonFungibleAsset: { [name: string]: [string, BigNumber] };
let nameToMultiAssetAsset: { [name: string]: [BigNumber[], string[]] };
function getAssetData(assetType: AssetType): string {
const encodeERC20AssetData = assetDataUtils.encodeERC20AssetData;
const encodeERC721AssetData = assetDataUtils.encodeERC721AssetData;
const encodeERC1155AssetData = assetDataUtils.encodeERC1155AssetData;
const encodeMultiAssetData = assetDataUtils.encodeMultiAssetData;
async function getAssetDataAsync(assetType: AssetType): Promise<string> {
const encodeERC20AssetData = await devUtils.encodeERC20AssetData.callAsync;
const encodeERC721AssetData = await devUtils.encodeERC721AssetData.callAsync;
const encodeERC1155AssetData = await devUtils.encodeERC1155AssetData.callAsync;
const encodeMultiAssetData = await devUtils.encodeMultiAssetData.callAsync;
if (nameToERC20Asset[assetType] !== undefined) {
const tokenAddress = nameToERC20Asset[assetType];
return encodeERC20AssetData(tokenAddress);
@@ -2744,8 +2752,8 @@ describe('matchOrders', () => {
MULTI_ASSET_A: [
[ONE, TWO],
[
assetDataUtils.encodeERC20AssetData(erc20Tokens[0].address),
assetDataUtils.encodeERC1155AssetData(
await devUtils.encodeERC20AssetData.callAsync(erc20Tokens[0].address),
await devUtils.encodeERC1155AssetData.callAsync(
defaultERC1155AssetAddress,
[erc1155FungibleTokens[0]],
[ONE],
@@ -2756,8 +2764,8 @@ describe('matchOrders', () => {
MULTI_ASSET_B: [
[ONE, TWO],
[
assetDataUtils.encodeERC20AssetData(erc20Tokens[1].address),
assetDataUtils.encodeERC1155AssetData(
await devUtils.encodeERC20AssetData.callAsync(erc20Tokens[1].address),
await devUtils.encodeERC1155AssetData.callAsync(
defaultERC1155AssetAddress,
[erc1155FungibleTokens[1]],
[ONE],
@@ -2768,8 +2776,8 @@ describe('matchOrders', () => {
MULTI_ASSET_C: [
[ONE, TWO],
[
assetDataUtils.encodeERC20AssetData(erc20Tokens[2].address),
assetDataUtils.encodeERC1155AssetData(
await devUtils.encodeERC20AssetData.callAsync(erc20Tokens[2].address),
await devUtils.encodeERC1155AssetData.callAsync(
defaultERC1155AssetAddress,
[erc1155FungibleTokens[2]],
[ONE],
@@ -2780,8 +2788,8 @@ describe('matchOrders', () => {
MULTI_ASSET_D: [
[ONE, TWO],
[
assetDataUtils.encodeERC20AssetData(erc20Tokens[3].address),
assetDataUtils.encodeERC1155AssetData(
await devUtils.encodeERC20AssetData.callAsync(erc20Tokens[3].address),
await devUtils.encodeERC1155AssetData.callAsync(
erc1155Token.address,
[erc1155FungibleTokens[3]],
[ONE],
@@ -2825,20 +2833,20 @@ describe('matchOrders', () => {
? leftMakerAssetAmount.minus(rightTakerAssetAmount)
: Web3Wrapper.toBaseUnitAmount(0, 0);
const signedOrderLeft = await orderFactoryLeft.newSignedOrderAsync({
makerAssetData: getAssetData(combo.leftMaker),
takerAssetData: getAssetData(combo.rightMaker),
makerFeeAssetData: getAssetData(combo.leftMakerFee),
takerFeeAssetData: getAssetData(combo.leftTakerFee),
makerAssetData: await getAssetDataAsync(combo.leftMaker),
takerAssetData: await getAssetDataAsync(combo.rightMaker),
makerFeeAssetData: await getAssetDataAsync(combo.leftMakerFee),
takerFeeAssetData: await getAssetDataAsync(combo.leftTakerFee),
makerAssetAmount: leftMakerAssetAmount,
takerAssetAmount: leftTakerAssetAmount,
makerFee: leftMakerFeeAssetAmount,
takerFee: leftTakerFeeAssetAmount,
});
const signedOrderRight = await orderFactoryRight.newSignedOrderAsync({
makerAssetData: getAssetData(combo.rightMaker),
takerAssetData: getAssetData(combo.leftMaker),
makerFeeAssetData: getAssetData(combo.rightMakerFee),
takerFeeAssetData: getAssetData(combo.rightTakerFee),
makerAssetData: await getAssetDataAsync(combo.rightMaker),
takerAssetData: await getAssetDataAsync(combo.leftMaker),
makerFeeAssetData: await getAssetDataAsync(combo.rightMakerFee),
takerFeeAssetData: await getAssetDataAsync(combo.rightTakerFee),
makerAssetAmount: rightMakerAssetAmount,
takerAssetAmount: rightTakerAssetAmount,
makerFee: rightMakerFeeAssetAmount,
@@ -2911,20 +2919,20 @@ describe('matchOrders', () => {
? rightMakerAssetAmount.minus(leftTakerAssetAmount)
: Web3Wrapper.toBaseUnitAmount(0, 0);
const signedOrderLeft = await orderFactoryLeft.newSignedOrderAsync({
makerAssetData: getAssetData(combo.leftMaker),
takerAssetData: getAssetData(combo.rightMaker),
makerFeeAssetData: getAssetData(combo.leftMakerFee),
takerFeeAssetData: getAssetData(combo.leftTakerFee),
makerAssetData: await getAssetDataAsync(combo.leftMaker),
takerAssetData: await getAssetDataAsync(combo.rightMaker),
makerFeeAssetData: await getAssetDataAsync(combo.leftMakerFee),
takerFeeAssetData: await getAssetDataAsync(combo.leftTakerFee),
makerAssetAmount: leftMakerAssetAmount,
takerAssetAmount: leftTakerAssetAmount,
makerFee: leftMakerFeeAssetAmount,
takerFee: leftTakerFeeAssetAmount,
});
const signedOrderRight = await orderFactoryRight.newSignedOrderAsync({
makerAssetData: getAssetData(combo.rightMaker),
takerAssetData: getAssetData(combo.leftMaker),
makerFeeAssetData: getAssetData(combo.rightMakerFee),
takerFeeAssetData: getAssetData(combo.rightTakerFee),
makerAssetData: await getAssetDataAsync(combo.rightMaker),
takerAssetData: await getAssetDataAsync(combo.leftMaker),
makerFeeAssetData: await getAssetDataAsync(combo.rightMakerFee),
takerFeeAssetData: await getAssetDataAsync(combo.rightTakerFee),
makerAssetAmount: rightMakerAssetAmount,
takerAssetAmount: rightTakerAssetAmount,
makerFee: rightMakerFeeAssetAmount,

View File

@@ -1,3 +1,4 @@
import { DevUtilsContract } from '@0x/contracts-dev-utils';
import {
blockchainTests,
constants,
@@ -10,13 +11,7 @@ import {
randomAddress,
TransactionFactory,
} from '@0x/contracts-test-utils';
import {
assetDataUtils,
ExchangeRevertErrors,
orderHashUtils,
signatureUtils,
transactionHashUtils,
} from '@0x/order-utils';
import { ExchangeRevertErrors, orderHashUtils, transactionHashUtils } from '@0x/order-utils';
import { SignatureType, SignedOrder, SignedZeroExTransaction } from '@0x/types';
import { BigNumber, StringRevertError } from '@0x/utils';
import { LogWithDecodedArgs } from 'ethereum-types';
@@ -42,6 +37,7 @@ blockchainTests.resets('MixinSignatureValidator', env => {
let signerPrivateKey: Buffer;
let notSignerAddress: string;
const devUtils = new DevUtilsContract(constants.NULL_ADDRESS, env.provider, env.txDefaults);
const eip1271Data = new IEIP1271DataContract(constants.NULL_ADDRESS, env.provider, env.txDefaults);
before(async () => {
chainId = await env.getChainIdAsync();
@@ -174,7 +170,9 @@ blockchainTests.resets('MixinSignatureValidator', env => {
it('should return true when SignatureType=EthSign and signature is valid', async () => {
// Create EthSign signature
const hashHex = getCurrentHashHex();
const orderHashWithEthSignPrefixHex = signatureUtils.addSignedMessagePrefix(hashHex);
const orderHashWithEthSignPrefixHex = ethUtil.bufferToHex(
ethUtil.hashPersonalMessage(ethUtil.toBuffer(hashHex)),
);
const signatureHex = hexConcat(
signDataHex(orderHashWithEthSignPrefixHex, signerPrivateKey),
SignatureType.EthSign,
@@ -429,10 +427,10 @@ blockchainTests.resets('MixinSignatureValidator', env => {
...constants.STATIC_ORDER_PARAMS,
makerAddress,
feeRecipientAddress: randomAddress(),
makerAssetData: assetDataUtils.encodeERC20AssetData(randomAddress()),
takerAssetData: assetDataUtils.encodeERC20AssetData(randomAddress()),
makerFeeAssetData: assetDataUtils.encodeERC20AssetData(randomAddress()),
takerFeeAssetData: assetDataUtils.encodeERC20AssetData(randomAddress()),
makerAssetData: await devUtils.encodeERC20AssetData.callAsync(randomAddress()),
takerAssetData: await devUtils.encodeERC20AssetData.callAsync(randomAddress()),
makerFeeAssetData: await devUtils.encodeERC20AssetData.callAsync(randomAddress()),
takerFeeAssetData: await devUtils.encodeERC20AssetData.callAsync(randomAddress()),
makerFee: constants.ZERO_AMOUNT,
takerFee: constants.ZERO_AMOUNT,
exchangeAddress: signatureValidator.address,

View File

@@ -1,5 +1,6 @@
// tslint:disable: max-file-line-count
import { ERC20ProxyContract, ERC20Wrapper } from '@0x/contracts-asset-proxy';
import { DevUtilsContract } from '@0x/contracts-dev-utils';
import { artifacts as erc20Artifacts, DummyERC20TokenContract } from '@0x/contracts-erc20';
import {
blockchainTests,
@@ -10,7 +11,7 @@ import {
OrderFactory,
TransactionFactory,
} from '@0x/contracts-test-utils';
import { assetDataUtils, ExchangeRevertErrors, orderHashUtils, transactionHashUtils } from '@0x/order-utils';
import { ExchangeRevertErrors, orderHashUtils, transactionHashUtils } from '@0x/order-utils';
import { FillResults, OrderStatus } from '@0x/types';
import { AbiEncoder, BigNumber } from '@0x/utils';
import { LogWithDecodedArgs, MethodAbi } from 'ethereum-types';
@@ -66,6 +67,7 @@ blockchainTests.resets('Exchange transactions', env => {
let takerPrivateKey: Buffer;
let taker2PrivateKey: Buffer;
const devUtils = new DevUtilsContract(constants.NULL_ADDRESS, env.provider, env.txDefaults);
before(async () => {
chainId = await env.getChainIdAsync();
const accounts = await env.getAccountAddressesAsync();
@@ -110,10 +112,10 @@ blockchainTests.resets('Exchange transactions', env => {
...constants.STATIC_ORDER_PARAMS,
makerAddress,
feeRecipientAddress,
makerAssetData: assetDataUtils.encodeERC20AssetData(defaultMakerTokenAddress),
takerAssetData: assetDataUtils.encodeERC20AssetData(defaultTakerTokenAddress),
makerFeeAssetData: assetDataUtils.encodeERC20AssetData(defaultMakerFeeTokenAddress),
takerFeeAssetData: assetDataUtils.encodeERC20AssetData(defaultTakerFeeTokenAddress),
makerAssetData: await devUtils.encodeERC20AssetData.callAsync(defaultMakerTokenAddress),
takerAssetData: await devUtils.encodeERC20AssetData.callAsync(defaultTakerTokenAddress),
makerFeeAssetData: await devUtils.encodeERC20AssetData.callAsync(defaultMakerFeeTokenAddress),
takerFeeAssetData: await devUtils.encodeERC20AssetData.callAsync(defaultTakerFeeTokenAddress),
exchangeAddress: exchangeInstance.address,
chainId,
};

View File

@@ -1,10 +1,10 @@
import { AbstractAssetWrapper, constants } from '@0x/contracts-test-utils';
import { assetDataUtils } from '@0x/order-utils';
import { AssetProxyId } from '@0x/types';
import { BigNumber, errorUtils } from '@0x/utils';
import * as _ from 'lodash';
import { ERC1155ProxyWrapper, ERC20Wrapper, ERC721Wrapper } from '@0x/contracts-asset-proxy';
import { DevUtilsContract } from '@0x/contracts-dev-utils';
interface ProxyIdToAssetWrappers {
[proxyId: string]: AbstractAssetWrapper;
@@ -19,17 +19,20 @@ const ZERO_NFT_UNIT = new BigNumber(0);
*/
export class AssetWrapper {
private readonly _proxyIdToAssetWrappers: ProxyIdToAssetWrappers;
private readonly _burnerAddress: string;
constructor(assetWrappers: AbstractAssetWrapper[], burnerAddress: string) {
constructor(
assetWrappers: AbstractAssetWrapper[],
private readonly _burnerAddress: string,
private readonly _devUtils: DevUtilsContract,
) {
this._proxyIdToAssetWrappers = {};
this._burnerAddress = burnerAddress;
_.each(assetWrappers, assetWrapper => {
const proxyId = assetWrapper.getProxyId();
this._proxyIdToAssetWrappers[proxyId] = assetWrapper;
});
}
public async getBalanceAsync(userAddress: string, assetData: string): Promise<BigNumber> {
const proxyId = assetDataUtils.decodeAssetProxyId(assetData);
const proxyId = await this._devUtils.decodeAssetProxyId.callAsync(assetData);
switch (proxyId) {
case AssetProxyId.ERC20: {
// tslint:disable-next-line:no-unnecessary-type-assertion
@@ -40,33 +43,38 @@ export class AssetWrapper {
case AssetProxyId.ERC721: {
// tslint:disable-next-line:no-unnecessary-type-assertion
const assetWrapper = this._proxyIdToAssetWrappers[proxyId] as ERC721Wrapper;
const assetProxyData = assetDataUtils.decodeERC721AssetData(assetData);
const isOwner = await assetWrapper.isOwnerAsync(
userAddress,
assetProxyData.tokenAddress,
assetProxyData.tokenId,
// tslint:disable-next-line:no-unused-variable
const [assetProxyId, tokenAddress, tokenId] = await this._devUtils.decodeERC721AssetData.callAsync(
assetData,
);
const isOwner = await assetWrapper.isOwnerAsync(userAddress, tokenAddress, tokenId);
const balance = isOwner ? ONE_NFT_UNIT : ZERO_NFT_UNIT;
return balance;
}
case AssetProxyId.ERC1155: {
// tslint:disable-next-line:no-unnecessary-type-assertion
const assetProxyWrapper = this._proxyIdToAssetWrappers[proxyId] as ERC1155ProxyWrapper;
const assetProxyData = assetDataUtils.decodeERC1155AssetData(assetData);
const assetWrapper = assetProxyWrapper.getContractWrapper(assetProxyData.tokenAddress);
const [
// tslint:disable-next-line:no-unused-variable
assetProxyAddress,
tokenAddress,
tokenIds,
] = await this._devUtils.decodeERC1155AssetData.callAsync(assetData);
const assetWrapper = assetProxyWrapper.getContractWrapper(tokenAddress);
const balances = await Promise.all(
_.map(assetProxyData.tokenIds).map(tokenId => assetWrapper.getBalanceAsync(userAddress, tokenId)),
_.map(tokenIds).map(tokenId => assetWrapper.getBalanceAsync(userAddress, tokenId)),
);
return BigNumber.min(...balances);
}
case AssetProxyId.MultiAsset: {
const assetProxyData = assetDataUtils.decodeMultiAssetData(assetData);
const nestedBalances = await Promise.all(
assetProxyData.nestedAssetData.map(async nestedAssetData =>
this.getBalanceAsync(userAddress, nestedAssetData),
),
// tslint:disable-next-line:no-unused-variable
const [assetProxyId, amounts, nestedAssetData] = await this._devUtils.decodeMultiAssetData.callAsync(
assetData,
);
const scaledBalances = _.zip(assetProxyData.amounts, nestedBalances).map(([amount, balance]) =>
const nestedBalances = await Promise.all(
nestedAssetData.map(async _nestedAssetData => this.getBalanceAsync(userAddress, _nestedAssetData)),
);
const scaledBalances = _.zip(amounts, nestedBalances).map(([amount, balance]) =>
(balance as BigNumber).div(amount as BigNumber).integerValue(BigNumber.ROUND_HALF_UP),
);
return BigNumber.min(...scaledBalances);
@@ -76,7 +84,7 @@ export class AssetWrapper {
}
}
public async setBalanceAsync(userAddress: string, assetData: string, desiredBalance: BigNumber): Promise<void> {
const proxyId = assetDataUtils.decodeAssetProxyId(assetData);
const proxyId = await this._devUtils.decodeAssetProxyId.callAsync(assetData);
switch (proxyId) {
case AssetProxyId.ERC20: {
// tslint:disable-next-line:no-unnecessary-type-assertion
@@ -91,36 +99,23 @@ export class AssetWrapper {
case AssetProxyId.ERC721: {
// tslint:disable-next-line:no-unnecessary-type-assertion
const erc721Wrapper = this._proxyIdToAssetWrappers[proxyId] as ERC721Wrapper;
const assetProxyData = assetDataUtils.decodeERC721AssetData(assetData);
const doesTokenExist = erc721Wrapper.doesTokenExistAsync(
assetProxyData.tokenAddress,
assetProxyData.tokenId,
// tslint:disable-next-line:no-unused-variable
const [assetProxyId, tokenAddress, tokenId] = await this._devUtils.decodeERC721AssetData.callAsync(
assetData,
);
const doesTokenExist = erc721Wrapper.doesTokenExistAsync(tokenAddress, tokenId);
if (!doesTokenExist && desiredBalance.gte(1)) {
await erc721Wrapper.mintAsync(assetProxyData.tokenAddress, assetProxyData.tokenId, userAddress);
await erc721Wrapper.mintAsync(tokenAddress, tokenId, userAddress);
return;
} else if (!doesTokenExist && desiredBalance.lt(1)) {
return; // noop
}
const tokenOwner = await erc721Wrapper.ownerOfAsync(
assetProxyData.tokenAddress,
assetProxyData.tokenId,
);
const tokenOwner = await erc721Wrapper.ownerOfAsync(tokenAddress, tokenId);
if (userAddress !== tokenOwner && desiredBalance.gte(1)) {
await erc721Wrapper.transferFromAsync(
assetProxyData.tokenAddress,
assetProxyData.tokenId,
tokenOwner,
userAddress,
);
await erc721Wrapper.transferFromAsync(tokenAddress, tokenId, tokenOwner, userAddress);
} else if (tokenOwner === userAddress && desiredBalance.lt(1)) {
// Burn token
await erc721Wrapper.transferFromAsync(
assetProxyData.tokenAddress,
assetProxyData.tokenId,
tokenOwner,
this._burnerAddress,
);
await erc721Wrapper.transferFromAsync(tokenAddress, tokenId, tokenOwner, this._burnerAddress);
return;
} else if (
(userAddress !== tokenOwner && desiredBalance.lt(1)) ||
@@ -133,15 +128,21 @@ export class AssetWrapper {
case AssetProxyId.ERC1155: {
// tslint:disable-next-line:no-unnecessary-type-assertion
const assetProxyWrapper = this._proxyIdToAssetWrappers[proxyId] as ERC1155ProxyWrapper;
const assetProxyData = assetDataUtils.decodeERC1155AssetData(assetData);
const assetWrapper = assetProxyWrapper.getContractWrapper(assetProxyData.tokenAddress);
const tokenValuesSum = BigNumber.sum(...assetProxyData.tokenValues);
let tokenValueRatios = assetProxyData.tokenValues;
const [
// tslint:disable-next-line:no-unused-variable
assetProxyAddress,
tokenAddress,
tokenIds,
tokenValues,
] = await this._devUtils.decodeERC1155AssetData.callAsync(assetData);
const assetWrapper = assetProxyWrapper.getContractWrapper(tokenAddress);
const tokenValuesSum = BigNumber.sum(...tokenValues);
let tokenValueRatios = tokenValues;
if (!tokenValuesSum.eq(0)) {
tokenValueRatios = assetProxyData.tokenValues.map(v => v.div(tokenValuesSum));
tokenValueRatios = tokenValues.map(v => v.div(tokenValuesSum));
}
for (const i of _.times(assetProxyData.tokenIds.length)) {
const tokenId = assetProxyData.tokenIds[i];
for (const i of _.times(tokenIds.length)) {
const tokenId = tokenIds[i];
const tokenValueRatio = tokenValueRatios[i];
const scaledDesiredBalance = desiredBalance.times(tokenValueRatio);
const isFungible = await assetWrapper.isFungibleItemAsync(tokenId);
@@ -195,16 +196,18 @@ export class AssetWrapper {
break;
}
case AssetProxyId.MultiAsset: {
const assetProxyData = assetDataUtils.decodeMultiAssetData(assetData);
const amountsSum = BigNumber.sum(...assetProxyData.amounts);
let assetAmountRatios = assetProxyData.amounts;
// tslint:disable-next-line:no-unused-variable
const [assetProxyId, amounts, nestedAssetData] = await this._devUtils.decodeMultiAssetData.callAsync(
assetData,
);
const amountsSum = BigNumber.sum(...amounts);
let assetAmountRatios = amounts;
if (!amountsSum.eq(0)) {
assetAmountRatios = assetProxyData.amounts.map(amt => amt.div(amountsSum));
assetAmountRatios = amounts.map(amt => amt.div(amountsSum));
}
for (const i of _.times(assetProxyData.amounts.length)) {
const nestedAssetData = assetProxyData.nestedAssetData[i];
for (const i of _.times(amounts.length)) {
const assetAmountRatio = assetAmountRatios[i];
await this.setBalanceAsync(userAddress, nestedAssetData, desiredBalance.times(assetAmountRatio));
await this.setBalanceAsync(userAddress, nestedAssetData[i], desiredBalance.times(assetAmountRatio));
}
break;
}
@@ -217,7 +220,7 @@ export class AssetWrapper {
assetData: string,
desiredBalance: BigNumber,
): Promise<void> {
const proxyId = assetDataUtils.decodeAssetProxyId(assetData);
const proxyId = await this._devUtils.decodeAssetProxyId.callAsync(assetData);
switch (proxyId) {
case AssetProxyId.ERC20:
case AssetProxyId.ERC721:
@@ -232,7 +235,7 @@ export class AssetWrapper {
}
}
public async getProxyAllowanceAsync(userAddress: string, assetData: string): Promise<BigNumber> {
const proxyId = assetDataUtils.decodeAssetProxyId(assetData);
const proxyId = await this._devUtils.decodeAssetProxyId.callAsync(assetData);
switch (proxyId) {
case AssetProxyId.ERC20: {
// tslint:disable-next-line:no-unnecessary-type-assertion
@@ -243,30 +246,27 @@ export class AssetWrapper {
case AssetProxyId.ERC721: {
// tslint:disable-next-line:no-unnecessary-type-assertion
const assetWrapper = this._proxyIdToAssetWrappers[proxyId] as ERC721Wrapper;
const erc721ProxyData = assetDataUtils.decodeERC721AssetData(assetData);
const isProxyApprovedForAll = await assetWrapper.isProxyApprovedForAllAsync(
userAddress,
erc721ProxyData.tokenAddress,
// tslint:disable-next-line:no-unused-variable
const [assetProxyId, tokenAddress, tokenId] = await this._devUtils.decodeERC721AssetData.callAsync(
assetData,
);
const isProxyApprovedForAll = await assetWrapper.isProxyApprovedForAllAsync(userAddress, tokenAddress);
if (isProxyApprovedForAll) {
return constants.UNLIMITED_ALLOWANCE_IN_BASE_UNITS;
}
const isProxyApproved = await assetWrapper.isProxyApprovedAsync(
erc721ProxyData.tokenAddress,
erc721ProxyData.tokenId,
);
const isProxyApproved = await assetWrapper.isProxyApprovedAsync(tokenAddress, tokenId);
const allowance = isProxyApproved ? ONE_NFT_UNIT : ZERO_NFT_UNIT;
return allowance;
}
case AssetProxyId.ERC1155: {
// tslint:disable-next-line:no-unnecessary-type-assertion
const assetProxyWrapper = this._proxyIdToAssetWrappers[proxyId] as ERC1155ProxyWrapper;
const assetProxyData = assetDataUtils.decodeERC1155AssetData(assetData);
const isApprovedForAll = await assetProxyWrapper.isProxyApprovedForAllAsync(
userAddress,
assetProxyData.tokenAddress,
// tslint:disable-next-line:no-unused-variable
const [assetProxyAddress, tokenAddress] = await this._devUtils.decodeERC1155AssetData.callAsync(
assetData,
);
const isApprovedForAll = await assetProxyWrapper.isProxyApprovedForAllAsync(userAddress, tokenAddress);
if (!isApprovedForAll) {
// ERC1155 is all or nothing.
return constants.ZERO_AMOUNT;
@@ -274,10 +274,13 @@ export class AssetWrapper {
return constants.UNLIMITED_ALLOWANCE_IN_BASE_UNITS;
}
case AssetProxyId.MultiAsset: {
const assetProxyData = assetDataUtils.decodeMultiAssetData(assetData);
// tslint:disable-next-line:no-unused-variable
const [assetProxyId, amounts, nestedAssetData] = await this._devUtils.decodeMultiAssetData.callAsync(
assetData,
);
const allowances = await Promise.all(
assetProxyData.nestedAssetData.map(async nestedAssetData =>
this.getProxyAllowanceAsync(userAddress, nestedAssetData),
nestedAssetData.map(async _nestedAssetData =>
this.getProxyAllowanceAsync(userAddress, _nestedAssetData),
),
);
return BigNumber.min(...allowances);
@@ -291,7 +294,7 @@ export class AssetWrapper {
assetData: string,
desiredAllowance: BigNumber,
): Promise<void> {
const proxyId = assetDataUtils.decodeAssetProxyId(assetData);
const proxyId = await this._devUtils.decodeAssetProxyId.callAsync(assetData);
switch (proxyId) {
case AssetProxyId.ERC20: {
// tslint:disable-next-line:no-unnecessary-type-assertion
@@ -311,46 +314,32 @@ export class AssetWrapper {
}
// tslint:disable-next-line:no-unnecessary-type-assertion
const erc721Wrapper = this._proxyIdToAssetWrappers[proxyId] as ERC721Wrapper;
const assetProxyData = assetDataUtils.decodeERC721AssetData(assetData);
// tslint:disable-next-line:no-unused-variable
const [assetProxyId, tokenAddress, tokenId] = await this._devUtils.decodeERC721AssetData.callAsync(
assetData,
);
const doesTokenExist = await erc721Wrapper.doesTokenExistAsync(
assetProxyData.tokenAddress,
assetProxyData.tokenId,
);
const doesTokenExist = await erc721Wrapper.doesTokenExistAsync(tokenAddress, tokenId);
if (!doesTokenExist) {
throw new Error(
`Cannot setProxyAllowance on non-existent token: ${assetProxyData.tokenAddress} ${
assetProxyData.tokenId
}`,
);
throw new Error(`Cannot setProxyAllowance on non-existent token: ${tokenAddress} ${tokenId}`);
}
const isProxyApprovedForAll = await erc721Wrapper.isProxyApprovedForAllAsync(
userAddress,
assetProxyData.tokenAddress,
);
const isProxyApprovedForAll = await erc721Wrapper.isProxyApprovedForAllAsync(userAddress, tokenAddress);
if (!isProxyApprovedForAll && desiredAllowance.eq(constants.UNLIMITED_ALLOWANCE_IN_BASE_UNITS)) {
const isApproved = true;
await erc721Wrapper.approveProxyForAllAsync(assetProxyData.tokenAddress, userAddress, isApproved);
await erc721Wrapper.approveProxyForAllAsync(tokenAddress, userAddress, isApproved);
} else if (isProxyApprovedForAll && desiredAllowance.eq(0)) {
const isApproved = false;
await erc721Wrapper.approveProxyForAllAsync(assetProxyData.tokenAddress, userAddress, isApproved);
await erc721Wrapper.approveProxyForAllAsync(tokenAddress, userAddress, isApproved);
} else if (isProxyApprovedForAll && desiredAllowance.eq(constants.UNLIMITED_ALLOWANCE_IN_BASE_UNITS)) {
return; // Noop
}
const isProxyApproved = await erc721Wrapper.isProxyApprovedAsync(
assetProxyData.tokenAddress,
assetProxyData.tokenId,
);
const isProxyApproved = await erc721Wrapper.isProxyApprovedAsync(tokenAddress, tokenId);
if (!isProxyApproved && desiredAllowance.eq(1)) {
await erc721Wrapper.approveProxyAsync(assetProxyData.tokenAddress, assetProxyData.tokenId);
await erc721Wrapper.approveProxyAsync(tokenAddress, tokenId);
} else if (isProxyApproved && desiredAllowance.eq(0)) {
// Remove approval
await erc721Wrapper.approveAsync(
constants.NULL_ADDRESS,
assetProxyData.tokenAddress,
assetProxyData.tokenId,
);
await erc721Wrapper.approveAsync(constants.NULL_ADDRESS, tokenAddress, tokenId);
} else if (
(!isProxyApproved && desiredAllowance.eq(0)) ||
(isProxyApproved && desiredAllowance.eq(1))
@@ -362,7 +351,10 @@ export class AssetWrapper {
case AssetProxyId.ERC1155: {
// tslint:disable-next-line:no-unnecessary-type-assertion
const assetProxyWrapper = this._proxyIdToAssetWrappers[proxyId] as ERC1155ProxyWrapper;
const assetProxyData = assetDataUtils.decodeERC1155AssetData(assetData);
// tslint:disable-next-line:no-unused-variable
const [assetProxyAddress, tokenAddress] = await this._devUtils.decodeERC1155AssetData.callAsync(
assetData,
);
// ERC1155 allowances are all or nothing.
const shouldApprovedForAll = desiredAllowance.gt(0);
const currentAllowance = await this.getProxyAllowanceAsync(userAddress, assetData);
@@ -371,19 +363,18 @@ export class AssetWrapper {
} else if (!shouldApprovedForAll && currentAllowance.eq(constants.ZERO_AMOUNT)) {
// Nothing to do.
} else {
assetProxyWrapper.setProxyAllowanceForAllAsync(
userAddress,
assetProxyData.tokenAddress,
shouldApprovedForAll,
);
assetProxyWrapper.setProxyAllowanceForAllAsync(userAddress, tokenAddress, shouldApprovedForAll);
}
break;
}
case AssetProxyId.MultiAsset: {
const assetProxyData = assetDataUtils.decodeMultiAssetData(assetData);
// tslint:disable-next-line:no-unused-variable
const [assetProxyId, amounts, nestedAssetData] = await this._devUtils.decodeMultiAssetData.callAsync(
assetData,
);
await Promise.all(
assetProxyData.nestedAssetData.map(async nestedAssetData =>
this.setProxyAllowanceAsync(userAddress, nestedAssetData, desiredAllowance),
nestedAssetData.map(async _nestedAssetData =>
this.setProxyAllowanceAsync(userAddress, _nestedAssetData, desiredAllowance),
),
);
break;

View File

@@ -5,6 +5,7 @@ import {
ERC721Wrapper,
MultiAssetProxyContract,
} from '@0x/contracts-asset-proxy';
import { DevUtilsContract } from '@0x/contracts-dev-utils';
import { constants, expect, LogDecoder, orderUtils, signingUtils } from '@0x/contracts-test-utils';
import { BalanceAndProxyAllowanceLazyStore, ExchangeRevertErrors, orderHashUtils } from '@0x/order-utils';
import { FillResults, Order, SignatureType, SignedOrder } from '@0x/types';
@@ -106,7 +107,8 @@ export async function fillOrderCombinatorialUtilsFactoryAsync(
{},
);
const assetWrapper = new AssetWrapper([erc20Wrapper, erc721Wrapper, erc1155Wrapper], burnerAddress);
const devUtils = new DevUtilsContract(constants.NULL_ADDRESS, provider);
const assetWrapper = new AssetWrapper([erc20Wrapper, erc721Wrapper, erc1155Wrapper], burnerAddress, devUtils);
const exchangeContract = await ExchangeContract.deployFrom0xArtifactAsync(
artifacts.Exchange,
@@ -156,6 +158,7 @@ export async function fillOrderCombinatorialUtilsFactoryAsync(
await multiAssetProxy.registerAssetProxy.awaitTransactionSuccessAsync(erc1155Proxy.address, { from: ownerAddress });
const orderFactory = new OrderFactoryFromScenario(
devUtils,
userAddresses,
erc20EighteenDecimalTokens.map(token => token.address),
erc20FiveDecimalTokens.map(token => token.address),
@@ -457,7 +460,7 @@ export class FillOrderCombinatorialUtils {
fillErrorIfExists?: FillOrderError,
): Promise<void> {
const lazyStore = new BalanceAndProxyAllowanceLazyStore(this.balanceAndProxyAllowanceFetcher);
const signedOrder = await this._generateSignedOrder(fillScenario.orderScenario);
const signedOrder = await this._generateSignedOrderAsync(fillScenario.orderScenario);
const takerAssetFillAmount = getTakerAssetFillAmount(signedOrder, fillScenario);
await this._modifyTraderStateAsync(fillScenario, signedOrder, takerAssetFillAmount);
@@ -484,8 +487,8 @@ export class FillOrderCombinatorialUtils {
);
}
private _generateSignedOrder(orderScenario: OrderScenario): SignedOrder {
const order = this.orderFactory.generateOrder(orderScenario);
private async _generateSignedOrderAsync(orderScenario: OrderScenario): Promise<SignedOrder> {
const order = await this.orderFactory.generateOrderAsync(orderScenario);
const orderHashBuff = orderHashUtils.getOrderHashBuffer(order);
const signature = signingUtils.signMessage(orderHashBuff, this.makerPrivateKey, SignatureType.EthSign);
const signedOrder = {

View File

@@ -1,6 +1,7 @@
import { ERC1155ProxyWrapper, ERC20Wrapper, ERC721Wrapper } from '@0x/contracts-asset-proxy';
import { DevUtilsContract } from '@0x/contracts-dev-utils';
import { constants, ERC1155HoldingsByOwner, expect, OrderStatus } from '@0x/contracts-test-utils';
import { assetDataUtils, orderHashUtils } from '@0x/order-utils';
import { orderHashUtils } from '@0x/order-utils';
import { AssetProxyId, BatchMatchedFillResults, FillResults, MatchedFillResults, SignedOrder } from '@0x/types';
import { BigNumber } from '@0x/utils';
import { LogWithDecodedArgs, TransactionReceiptWithDecodedLogs } from 'ethereum-types';
@@ -111,14 +112,6 @@ export type MatchOrdersAsyncCall = (
) => Promise<TransactionReceiptWithDecodedLogs>;
export class MatchOrderTester {
public exchangeWrapper: ExchangeWrapper;
public erc20Wrapper: ERC20Wrapper;
public erc721Wrapper: ERC721Wrapper;
public erc1155ProxyWrapper: ERC1155ProxyWrapper;
public batchMatchOrdersCallAsync?: BatchMatchOrdersAsyncCall;
public batchMatchOrdersWithMaximalFillCallAsync?: BatchMatchOrdersAsyncCall;
public matchOrdersCallAsync?: MatchOrdersAsyncCall;
public matchOrdersWithMaximalFillCallAsync?: MatchOrdersAsyncCall;
private readonly _initialTokenBalancesPromise: Promise<TokenBalances>;
/**
@@ -137,23 +130,16 @@ export class MatchOrderTester {
* `ExchangeWrapper.matchOrdersAsync()`.
*/
constructor(
exchangeWrapper: ExchangeWrapper,
erc20Wrapper: ERC20Wrapper,
erc721Wrapper: ERC721Wrapper,
erc1155ProxyWrapper: ERC1155ProxyWrapper,
batchMatchOrdersCallAsync?: BatchMatchOrdersAsyncCall,
batchMatchOrdersWithMaximalFillCallAsync?: BatchMatchOrdersAsyncCall,
matchOrdersCallAsync?: MatchOrdersAsyncCall,
matchOrdersWithMaximalFillCallAsync?: MatchOrdersAsyncCall,
public exchangeWrapper: ExchangeWrapper,
public erc20Wrapper: ERC20Wrapper,
public erc721Wrapper: ERC721Wrapper,
public erc1155ProxyWrapper: ERC1155ProxyWrapper,
protected _devUtils: DevUtilsContract,
public batchMatchOrdersCallAsync?: BatchMatchOrdersAsyncCall,
public batchMatchOrdersWithMaximalFillCallAsync?: BatchMatchOrdersAsyncCall,
public matchOrdersCallAsync?: MatchOrdersAsyncCall,
public matchOrdersWithMaximalFillCallAsync?: MatchOrdersAsyncCall,
) {
this.exchangeWrapper = exchangeWrapper;
this.erc20Wrapper = erc20Wrapper;
this.erc721Wrapper = erc721Wrapper;
this.erc1155ProxyWrapper = erc1155ProxyWrapper;
this.batchMatchOrdersCallAsync = batchMatchOrdersCallAsync;
this.batchMatchOrdersWithMaximalFillCallAsync = batchMatchOrdersWithMaximalFillCallAsync;
this.matchOrdersCallAsync = matchOrdersCallAsync;
this.matchOrdersWithMaximalFillCallAsync = matchOrdersWithMaximalFillCallAsync;
this._initialTokenBalancesPromise = this.getBalancesAsync();
}
@@ -215,12 +201,13 @@ export class MatchOrderTester {
);
}
// Simulate the batch order match.
const expectedBatchMatchResults = simulateBatchMatchOrders(
const expectedBatchMatchResults = await simulateBatchMatchOrdersAsync(
orders,
takerAddress,
_initialTokenBalances,
matchPairs,
expectedTransferAmounts,
this._devUtils,
);
const expectedResults = convertToBatchMatchResults(expectedBatchMatchResults);
expect(actualBatchMatchResults).to.be.eql(expectedResults);
@@ -282,11 +269,12 @@ export class MatchOrderTester {
transactionReceipt = await this._executeMatchOrdersAsync(orders.leftOrder, orders.rightOrder, takerAddress);
}
// Simulate the fill.
const expectedMatchResults = simulateMatchOrders(
const expectedMatchResults = await simulateMatchOrdersAsync(
orders,
takerAddress,
_initialTokenBalances,
toFullMatchTransferAmounts(expectedTransferAmounts),
this._devUtils,
);
const expectedResults = convertToMatchResults(expectedMatchResults);
expect(actualMatchResults).to.be.eql(expectedResults);
@@ -403,13 +391,14 @@ function toFullMatchTransferAmounts(partial: Partial<MatchTransferAmounts>): Mat
* @param transferAmounts Amounts to transfer during the simulation.
* @return The new account balances and fill events that occurred during the match.
*/
function simulateBatchMatchOrders(
async function simulateBatchMatchOrdersAsync(
orders: BatchMatchedOrders,
takerAddress: string,
tokenBalances: TokenBalances,
matchPairs: Array<[number, number]>,
transferAmounts: Array<Partial<MatchTransferAmounts>>,
): BatchMatchResults {
devUtils: DevUtilsContract,
): Promise<BatchMatchResults> {
// Initialize variables
let leftIdx = 0;
let rightIdx = 0;
@@ -465,11 +454,12 @@ function simulateBatchMatchOrders(
// Add the latest match to the batch match results
batchMatchResults.matches.push(
simulateMatchOrders(
await simulateMatchOrdersAsync(
matchedOrders,
takerAddress,
tokenBalances,
toFullMatchTransferAmounts(transferAmounts[i]),
devUtils,
),
);
@@ -525,12 +515,13 @@ function simulateBatchMatchOrders(
* @param transferAmounts Amounts to transfer during the simulation.
* @return The new account balances and fill events that occurred during the match.
*/
function simulateMatchOrders(
async function simulateMatchOrdersAsync(
orders: MatchedOrders,
takerAddress: string,
tokenBalances: TokenBalances,
transferAmounts: MatchTransferAmounts,
): MatchResults {
devUtils: DevUtilsContract,
): Promise<MatchResults> {
// prettier-ignore
const matchResults = {
orders: {
@@ -549,72 +540,80 @@ function simulateMatchOrders(
balances: _.cloneDeep(tokenBalances),
};
// Right maker asset -> left maker
transferAsset(
await transferAssetAsync(
orders.rightOrder.makerAddress,
orders.leftOrder.makerAddress,
transferAmounts.rightMakerAssetBoughtByLeftMakerAmount,
orders.rightOrder.makerAssetData,
matchResults,
devUtils,
);
if (orders.leftOrder.makerAddress !== orders.leftOrder.feeRecipientAddress) {
// Left maker fees
transferAsset(
await transferAssetAsync(
orders.leftOrder.makerAddress,
orders.leftOrder.feeRecipientAddress,
transferAmounts.leftMakerFeeAssetPaidByLeftMakerAmount,
orders.leftOrder.makerFeeAssetData,
matchResults,
devUtils,
);
}
// Left maker asset -> right maker
transferAsset(
await transferAssetAsync(
orders.leftOrder.makerAddress,
orders.rightOrder.makerAddress,
transferAmounts.leftMakerAssetBoughtByRightMakerAmount,
orders.leftOrder.makerAssetData,
matchResults,
devUtils,
);
if (orders.rightOrder.makerAddress !== orders.rightOrder.feeRecipientAddress) {
// Right maker fees
transferAsset(
await transferAssetAsync(
orders.rightOrder.makerAddress,
orders.rightOrder.feeRecipientAddress,
transferAmounts.rightMakerFeeAssetPaidByRightMakerAmount,
orders.rightOrder.makerFeeAssetData,
matchResults,
devUtils,
);
}
// Left taker profit
transferAsset(
await transferAssetAsync(
orders.leftOrder.makerAddress,
takerAddress,
transferAmounts.leftMakerAssetReceivedByTakerAmount,
orders.leftOrder.makerAssetData,
matchResults,
devUtils,
);
// Right taker profit
transferAsset(
await transferAssetAsync(
orders.rightOrder.makerAddress,
takerAddress,
transferAmounts.rightMakerAssetReceivedByTakerAmount,
orders.rightOrder.makerAssetData,
matchResults,
devUtils,
);
// Left taker fees
transferAsset(
await transferAssetAsync(
takerAddress,
orders.leftOrder.feeRecipientAddress,
transferAmounts.leftTakerFeeAssetPaidByTakerAmount,
orders.leftOrder.takerFeeAssetData,
matchResults,
devUtils,
);
// Right taker fees
transferAsset(
await transferAssetAsync(
takerAddress,
orders.rightOrder.feeRecipientAddress,
transferAmounts.rightTakerFeeAssetPaidByTakerAmount,
orders.rightOrder.takerFeeAssetData,
matchResults,
devUtils,
);
return matchResults;
@@ -624,18 +623,19 @@ function simulateMatchOrders(
* Simulates a transfer of assets from `fromAddress` to `toAddress`
* by updating `matchResults`.
*/
function transferAsset(
async function transferAssetAsync(
fromAddress: string,
toAddress: string,
amount: BigNumber,
assetData: string,
matchResults: MatchResults,
): void {
const assetProxyId = assetDataUtils.decodeAssetProxyId(assetData);
devUtils: DevUtilsContract,
): Promise<void> {
const assetProxyId = await devUtils.decodeAssetProxyId.callAsync(assetData);
switch (assetProxyId) {
case AssetProxyId.ERC20: {
const erc20AssetData = assetDataUtils.decodeERC20AssetData(assetData);
const assetAddress = erc20AssetData.tokenAddress;
// tslint:disable-next-line:no-unused-variable
const [proxyId, assetAddress] = await devUtils.decodeERC20AssetData.callAsync(assetData); // tslint:disable-line-no-unused-variable
const fromBalances = matchResults.balances.erc20[fromAddress];
const toBalances = matchResults.balances.erc20[toAddress];
fromBalances[assetAddress] = fromBalances[assetAddress].minus(amount);
@@ -643,9 +643,8 @@ function transferAsset(
break;
}
case AssetProxyId.ERC721: {
const erc721AssetData = assetDataUtils.decodeERC721AssetData(assetData);
const assetAddress = erc721AssetData.tokenAddress;
const tokenId = erc721AssetData.tokenId;
// tslint:disable-next-line:no-unused-variable
const [proxyId, assetAddress, tokenId] = await devUtils.decodeERC721AssetData.callAsync(assetData); // tslint:disable-line-no-unused-variable
const fromTokens = matchResults.balances.erc721[fromAddress][assetAddress];
const toTokens = matchResults.balances.erc721[toAddress][assetAddress];
if (amount.gte(1)) {
@@ -658,13 +657,15 @@ function transferAsset(
break;
}
case AssetProxyId.ERC1155: {
const erc1155AssetData = assetDataUtils.decodeERC1155AssetData(assetData);
const assetAddress = erc1155AssetData.tokenAddress;
// tslint:disable-next-line:no-unused-variable
const [proxyId, assetAddress, tokenIds, tokenValues] = await devUtils.decodeERC1155AssetData.callAsync(
assetData,
);
const fromBalances = matchResults.balances.erc1155[fromAddress][assetAddress];
const toBalances = matchResults.balances.erc1155[toAddress][assetAddress];
for (const i of _.times(erc1155AssetData.tokenIds.length)) {
const tokenId = erc1155AssetData.tokenIds[i];
const tokenValue = erc1155AssetData.tokenValues[i];
for (const i of _.times(tokenIds.length)) {
const tokenId = tokenIds[i];
const tokenValue = tokenValues[i];
const tokenAmount = amount.times(tokenValue);
if (tokenAmount.gt(0)) {
const tokenIndex = _.findIndex(fromBalances.nonFungible, t => t.eq(tokenId));
@@ -683,11 +684,19 @@ function transferAsset(
break;
}
case AssetProxyId.MultiAsset: {
const multiAssetData = assetDataUtils.decodeMultiAssetData(assetData);
for (const i of _.times(multiAssetData.amounts.length)) {
const nestedAmount = amount.times(multiAssetData.amounts[i]);
const nestedAssetData = multiAssetData.nestedAssetData[i];
transferAsset(fromAddress, toAddress, nestedAmount, nestedAssetData, matchResults);
// tslint:disable-next-line:no-unused-variable
const [proxyId, amounts, nestedAssetData] = await devUtils.decodeMultiAssetData.callAsync(assetData); // tslint:disable-line-no-unused-variable
for (const i of _.times(amounts.length)) {
const nestedAmount = amount.times(amounts[i]);
const _nestedAssetData = nestedAssetData[i];
await transferAssetAsync(
fromAddress,
toAddress,
nestedAmount,
_nestedAssetData,
matchResults,
devUtils,
);
}
break;
}

View File

@@ -1,5 +1,6 @@
import { DevUtilsContract } from '@0x/contracts-dev-utils';
import { constants, ERC1155HoldingsByOwner, ERC721TokenIdsByOwner } from '@0x/contracts-test-utils';
import { assetDataUtils, generatePseudoRandomSalt } from '@0x/order-utils';
import { generatePseudoRandomSalt } from '@0x/order-utils';
import { Order } from '@0x/types';
import { BigNumber, errorUtils } from '@0x/utils';
import * as _ from 'lodash';
@@ -32,40 +33,22 @@ const ONE_NFT_UNIT = new BigNumber(1);
const ZERO_UNITS = new BigNumber(0);
export class OrderFactoryFromScenario {
private readonly _userAddresses: string[];
private readonly _erc20EighteenDecimalTokenAddresses: string[];
private readonly _erc20FiveDecimalTokenAddresses: string[];
private readonly _erc20ZeroDecimalTokenAddresses: string[];
private readonly _erc721TokenAddress: string;
private readonly _erc1155TokenAddress: string;
private readonly _erc721Balances: ERC721TokenIdsByOwner;
private readonly _erc1155Holdings: ERC1155HoldingsByOwner;
private readonly _exchangeAddress: string;
private readonly _chainId: number;
constructor(
userAddresses: string[],
erc20EighteenDecimalTokenAddresses: string[],
erc20FiveDecimalTokenAddresses: string[],
erc20ZeroDecimalTokenAddresses: string[],
erc721TokenAddress: string,
erc1155TokenAddress: string,
erc721Balances: ERC721TokenIdsByOwner,
erc1155Holdings: ERC1155HoldingsByOwner,
exchangeAddress: string,
chainId: number,
private readonly _devUtils: DevUtilsContract,
private readonly _userAddresses: string[],
private readonly _erc20EighteenDecimalTokenAddresses: string[],
private readonly _erc20FiveDecimalTokenAddresses: string[],
private readonly _erc20ZeroDecimalTokenAddresses: string[],
private readonly _erc721TokenAddress: string,
private readonly _erc1155TokenAddress: string,
private readonly _erc721Balances: ERC721TokenIdsByOwner,
private readonly _erc1155Holdings: ERC1155HoldingsByOwner,
private readonly _exchangeAddress: string,
private readonly _chainId: number,
) {
this._userAddresses = userAddresses;
this._erc20EighteenDecimalTokenAddresses = erc20EighteenDecimalTokenAddresses;
this._erc20FiveDecimalTokenAddresses = erc20FiveDecimalTokenAddresses;
this._erc20ZeroDecimalTokenAddresses = erc20ZeroDecimalTokenAddresses;
this._erc721TokenAddress = erc721TokenAddress;
this._erc1155TokenAddress = erc1155TokenAddress;
this._erc721Balances = erc721Balances;
this._erc1155Holdings = erc1155Holdings;
this._exchangeAddress = exchangeAddress;
this._chainId = chainId;
return;
}
public generateOrder(orderScenario: OrderScenario): Order {
public async generateOrderAsync(orderScenario: OrderScenario): Promise<Order> {
const makerAddress = this._userAddresses[1];
let takerAddress = this._userAddresses[2];
const erc721MakerAssetIds = this._erc721Balances[makerAddress][this._erc721TokenAddress];
@@ -113,19 +96,28 @@ export class OrderFactoryFromScenario {
switch (orderScenario.makerAssetDataScenario) {
case AssetDataScenario.ERC20EighteenDecimals:
makerAssetData = assetDataUtils.encodeERC20AssetData(this._erc20EighteenDecimalTokenAddresses[0]);
makerAssetData = await this._devUtils.encodeERC20AssetData.callAsync(
this._erc20EighteenDecimalTokenAddresses[0],
);
break;
case AssetDataScenario.ERC20FiveDecimals:
makerAssetData = assetDataUtils.encodeERC20AssetData(this._erc20FiveDecimalTokenAddresses[0]);
makerAssetData = await this._devUtils.encodeERC20AssetData.callAsync(
this._erc20FiveDecimalTokenAddresses[0],
);
break;
case AssetDataScenario.ERC721:
makerAssetData = assetDataUtils.encodeERC721AssetData(this._erc721TokenAddress, erc721MakerAssetIds[0]);
makerAssetData = await this._devUtils.encodeERC721AssetData.callAsync(
this._erc721TokenAddress,
erc721MakerAssetIds[0],
);
break;
case AssetDataScenario.ERC20ZeroDecimals:
makerAssetData = assetDataUtils.encodeERC20AssetData(this._erc20ZeroDecimalTokenAddresses[0]);
makerAssetData = await this._devUtils.encodeERC20AssetData.callAsync(
this._erc20ZeroDecimalTokenAddresses[0],
);
break;
case AssetDataScenario.ERC1155Fungible:
makerAssetData = assetDataUtils.encodeERC1155AssetData(
makerAssetData = await this._devUtils.encodeERC1155AssetData.callAsync(
this._erc1155TokenAddress,
[erc1155FungibleMakerTokenIds[0]],
[ONE_UNITS_ZERO_DECIMALS],
@@ -133,7 +125,7 @@ export class OrderFactoryFromScenario {
);
break;
case AssetDataScenario.ERC1155NonFungible:
makerAssetData = assetDataUtils.encodeERC1155AssetData(
makerAssetData = await this._devUtils.encodeERC1155AssetData.callAsync(
this._erc1155TokenAddress,
[erc1155NonFungibleMakerTokenIds[0]],
[ONE_UNITS_ZERO_DECIMALS],
@@ -141,11 +133,13 @@ export class OrderFactoryFromScenario {
);
break;
case AssetDataScenario.MultiAssetERC20:
makerAssetData = assetDataUtils.encodeMultiAssetData(
makerAssetData = await this._devUtils.encodeMultiAssetData.callAsync(
[ONE_UNITS_EIGHTEEN_DECIMALS, ONE_UNITS_FIVE_DECIMALS],
[
assetDataUtils.encodeERC20AssetData(this._erc20EighteenDecimalTokenAddresses[0]),
assetDataUtils.encodeERC20AssetData(this._erc20FiveDecimalTokenAddresses[0]),
await this._devUtils.encodeERC20AssetData.callAsync(
this._erc20EighteenDecimalTokenAddresses[0],
),
await this._devUtils.encodeERC20AssetData.callAsync(this._erc20FiveDecimalTokenAddresses[0]),
],
);
break;
@@ -155,19 +149,28 @@ export class OrderFactoryFromScenario {
switch (orderScenario.takerAssetDataScenario) {
case AssetDataScenario.ERC20EighteenDecimals:
takerAssetData = assetDataUtils.encodeERC20AssetData(this._erc20EighteenDecimalTokenAddresses[1]);
takerAssetData = await this._devUtils.encodeERC20AssetData.callAsync(
this._erc20EighteenDecimalTokenAddresses[1],
);
break;
case AssetDataScenario.ERC20FiveDecimals:
takerAssetData = assetDataUtils.encodeERC20AssetData(this._erc20FiveDecimalTokenAddresses[1]);
takerAssetData = await this._devUtils.encodeERC20AssetData.callAsync(
this._erc20FiveDecimalTokenAddresses[1],
);
break;
case AssetDataScenario.ERC721:
takerAssetData = assetDataUtils.encodeERC721AssetData(this._erc721TokenAddress, erc721TakerAssetIds[0]);
takerAssetData = await this._devUtils.encodeERC721AssetData.callAsync(
this._erc721TokenAddress,
erc721TakerAssetIds[0],
);
break;
case AssetDataScenario.ERC20ZeroDecimals:
takerAssetData = assetDataUtils.encodeERC20AssetData(this._erc20ZeroDecimalTokenAddresses[1]);
takerAssetData = await this._devUtils.encodeERC20AssetData.callAsync(
this._erc20ZeroDecimalTokenAddresses[1],
);
break;
case AssetDataScenario.ERC1155Fungible:
takerAssetData = assetDataUtils.encodeERC1155AssetData(
takerAssetData = await this._devUtils.encodeERC1155AssetData.callAsync(
this._erc1155TokenAddress,
[erc1155FungibleTakerTokenIds[1]],
[ONE_UNITS_ZERO_DECIMALS],
@@ -175,7 +178,7 @@ export class OrderFactoryFromScenario {
);
break;
case AssetDataScenario.ERC1155NonFungible:
takerAssetData = assetDataUtils.encodeERC1155AssetData(
takerAssetData = await this._devUtils.encodeERC1155AssetData.callAsync(
this._erc1155TokenAddress,
[erc1155NonFungibleTakerTokenIds[0]],
[ONE_UNITS_ZERO_DECIMALS],
@@ -183,11 +186,13 @@ export class OrderFactoryFromScenario {
);
break;
case AssetDataScenario.MultiAssetERC20:
takerAssetData = assetDataUtils.encodeMultiAssetData(
takerAssetData = await this._devUtils.encodeMultiAssetData.callAsync(
[ONE_UNITS_EIGHTEEN_DECIMALS, ONE_UNITS_FIVE_DECIMALS],
[
assetDataUtils.encodeERC20AssetData(this._erc20EighteenDecimalTokenAddresses[1]),
assetDataUtils.encodeERC20AssetData(this._erc20FiveDecimalTokenAddresses[1]),
await this._devUtils.encodeERC20AssetData.callAsync(
this._erc20EighteenDecimalTokenAddresses[1],
),
await this._devUtils.encodeERC20AssetData.callAsync(this._erc20FiveDecimalTokenAddresses[1]),
],
);
break;
@@ -303,7 +308,7 @@ export class OrderFactoryFromScenario {
throw errorUtils.spawnSwitchErr('OrderAssetAmountScenario', orderScenario.takerAssetAmountScenario);
}
const feeFromScenario = (
const feeFromScenario = async (
feeAmountScenario: OrderAssetAmountScenario,
feeAssetDataScenario: FeeAssetDataScenario,
erc20EighteenDecimalTokenAddress: string,
@@ -312,7 +317,7 @@ export class OrderFactoryFromScenario {
erc721AssetId: BigNumber,
erc1155FungibleTokenId: BigNumber,
erc1155NonFungibleAssetId: BigNumber,
): [BigNumber, string] => {
): Promise<[BigNumber, string]> => {
const feeAmount = getFeeAmountFromScenario(orderScenario, feeAssetDataScenario, feeAmountScenario);
switch (feeAssetDataScenario) {
case FeeAssetDataScenario.MakerToken:
@@ -320,17 +325,29 @@ export class OrderFactoryFromScenario {
case FeeAssetDataScenario.TakerToken:
return [feeAmount, takerAssetData];
case FeeAssetDataScenario.ERC20EighteenDecimals:
return [feeAmount, assetDataUtils.encodeERC20AssetData(erc20EighteenDecimalTokenAddress)];
return [
feeAmount,
await this._devUtils.encodeERC20AssetData.callAsync(erc20EighteenDecimalTokenAddress),
];
case FeeAssetDataScenario.ERC20FiveDecimals:
return [feeAmount, assetDataUtils.encodeERC20AssetData(erc20FiveDecimalTokenAddress)];
return [
feeAmount,
await this._devUtils.encodeERC20AssetData.callAsync(erc20FiveDecimalTokenAddress),
];
case FeeAssetDataScenario.ERC20ZeroDecimals:
return [feeAmount, assetDataUtils.encodeERC20AssetData(erc20ZeroDecimalTokenAddress)];
return [
feeAmount,
await this._devUtils.encodeERC20AssetData.callAsync(erc20ZeroDecimalTokenAddress),
];
case FeeAssetDataScenario.ERC721:
return [feeAmount, assetDataUtils.encodeERC721AssetData(this._erc721TokenAddress, erc721AssetId)];
return [
feeAmount,
await this._devUtils.encodeERC721AssetData.callAsync(this._erc721TokenAddress, erc721AssetId),
];
case FeeAssetDataScenario.ERC1155Fungible:
return [
feeAmount,
assetDataUtils.encodeERC1155AssetData(
await this._devUtils.encodeERC1155AssetData.callAsync(
this._erc1155TokenAddress,
[erc1155FungibleTokenId],
[ONE_UNITS_ZERO_DECIMALS],
@@ -340,7 +357,7 @@ export class OrderFactoryFromScenario {
case FeeAssetDataScenario.ERC1155NonFungible:
return [
feeAmount,
assetDataUtils.encodeERC1155AssetData(
await this._devUtils.encodeERC1155AssetData.callAsync(
this._erc1155TokenAddress,
[erc1155NonFungibleAssetId],
[ONE_UNITS_ZERO_DECIMALS],
@@ -350,11 +367,11 @@ export class OrderFactoryFromScenario {
case FeeAssetDataScenario.MultiAssetERC20:
return [
feeAmount,
assetDataUtils.encodeMultiAssetData(
await this._devUtils.encodeMultiAssetData.callAsync(
[POINT_ZERO_FIVE_UNITS_EIGHTEEN_DECIMALS, POINT_ZERO_FIVE_UNITS_FIVE_DECIMALS],
[
assetDataUtils.encodeERC20AssetData(erc20EighteenDecimalTokenAddress),
assetDataUtils.encodeERC20AssetData(erc20FiveDecimalTokenAddress),
await this._devUtils.encodeERC20AssetData.callAsync(erc20EighteenDecimalTokenAddress),
await this._devUtils.encodeERC20AssetData.callAsync(erc20FiveDecimalTokenAddress),
],
),
];
@@ -363,7 +380,7 @@ export class OrderFactoryFromScenario {
}
};
[makerFee, makerFeeAssetData] = feeFromScenario(
[makerFee, makerFeeAssetData] = await feeFromScenario(
orderScenario.makerFeeScenario,
orderScenario.makerFeeAssetDataScenario,
this._erc20EighteenDecimalTokenAddresses[2],
@@ -373,7 +390,7 @@ export class OrderFactoryFromScenario {
erc1155FungibleMakerTokenIds[2],
erc1155NonFungibleMakerTokenIds[1],
);
[takerFee, takerFeeAssetData] = feeFromScenario(
[takerFee, takerFeeAssetData] = await feeFromScenario(
orderScenario.takerFeeScenario,
orderScenario.takerFeeAssetDataScenario,
this._erc20EighteenDecimalTokenAddresses[3],