Cherry-pick changes from feat/dev-utils/dydx-bridge-validation

This commit is contained in:
Lawrence Forman
2020-01-31 11:40:31 -05:00
parent 79362b0dba
commit 3e8f9a6b53
104 changed files with 1699 additions and 1434 deletions

View File

@@ -1,4 +1,17 @@
[
{
"version": "3.2.0",
"changes": [
{
"note": "Flip `LibExchangeRichErrorDecoder` to an actual library.",
"pr": 2462
},
{
"note": "Remove dependency on `DevUtils` for asset data encoding/decoding",
"pr": 2462
}
]
},
{
"timestamp": 1580988106,
"version": "3.1.2",

View File

@@ -23,7 +23,7 @@ import "@0x/contracts-exchange-libs/contracts/src/LibExchangeRichErrors.sol";
import "@0x/contracts-utils/contracts/src/LibBytes.sol";
contract LibExchangeRichErrorDecoder {
library LibExchangeRichErrorDecoder {
using LibBytes for bytes;
@@ -33,7 +33,7 @@ contract LibExchangeRichErrorDecoder {
/// @return signerAddress The expected signer of the hash.
/// @return signature The full signature.
function decodeSignatureError(bytes memory encoded)
public
internal
pure
returns (
LibExchangeRichErrors.SignatureErrorCodes errorCode,
@@ -57,7 +57,7 @@ contract LibExchangeRichErrorDecoder {
/// @return signature The full signature bytes.
/// @return errorData The revert data thrown by the validator contract.
function decodeEIP1271SignatureError(bytes memory encoded)
public
internal
pure
returns (
address verifyingContractAddress,
@@ -78,7 +78,7 @@ contract LibExchangeRichErrorDecoder {
/// @return signerAddress The expected signer of the hash.
/// @return validatorAddress The expected validator.
function decodeSignatureValidatorNotApprovedError(bytes memory encoded)
public
internal
pure
returns (
address signerAddress,
@@ -99,7 +99,7 @@ contract LibExchangeRichErrorDecoder {
/// @return signature The full signature bytes.
/// @return errorData The revert data thrown by the validator contract.
function decodeSignatureWalletError(bytes memory encoded)
public
internal
pure
returns (
bytes32 hash,
@@ -120,7 +120,7 @@ contract LibExchangeRichErrorDecoder {
/// @return orderHash The order hash.
/// @return orderStatus The order status.
function decodeOrderStatusError(bytes memory encoded)
public
internal
pure
returns (
bytes32 orderHash,
@@ -142,7 +142,7 @@ contract LibExchangeRichErrorDecoder {
/// @return orderHash The order hash.
/// @return contextAddress The maker, taker, or sender address
function decodeExchangeInvalidContextError(bytes memory encoded)
public
internal
pure
returns (
LibExchangeRichErrors.ExchangeContextErrorCodes errorCode,
@@ -164,7 +164,7 @@ contract LibExchangeRichErrorDecoder {
/// @return errorCode The error code.
/// @return orderHash The order hash.
function decodeFillError(bytes memory encoded)
public
internal
pure
returns (
LibExchangeRichErrors.FillErrorCodes errorCode,
@@ -186,7 +186,7 @@ contract LibExchangeRichErrorDecoder {
/// @return orderSenderAddress The order sender.
/// @return currentEpoch The current epoch for the maker.
function decodeOrderEpochError(bytes memory encoded)
public
internal
pure
returns (
address makerAddress,
@@ -206,7 +206,7 @@ contract LibExchangeRichErrorDecoder {
/// @return assetProxyId Id of asset proxy.
/// @return assetProxyAddress The address of the asset proxy.
function decodeAssetProxyExistsError(bytes memory encoded)
public
internal
pure
returns (
bytes4 assetProxyId, address assetProxyAddress)
@@ -224,7 +224,7 @@ contract LibExchangeRichErrorDecoder {
/// @return orderHash Hash of the order being dispatched.
/// @return assetData Asset data of the order being dispatched.
function decodeAssetProxyDispatchError(bytes memory encoded)
public
internal
pure
returns (
LibExchangeRichErrors.AssetProxyDispatchErrorCodes errorCode,
@@ -247,7 +247,7 @@ contract LibExchangeRichErrorDecoder {
/// @return assetData Asset data of the order being dispatched.
/// @return errorData ABI-encoded revert data from the asset proxy.
function decodeAssetProxyTransferError(bytes memory encoded)
public
internal
pure
returns (
bytes32 orderHash,
@@ -267,7 +267,7 @@ contract LibExchangeRichErrorDecoder {
/// @return leftOrderHash Hash of the left order being matched.
/// @return rightOrderHash Hash of the right order being matched.
function decodeNegativeSpreadError(bytes memory encoded)
public
internal
pure
returns (
bytes32 leftOrderHash,
@@ -286,7 +286,7 @@ contract LibExchangeRichErrorDecoder {
/// @return errorCode The error code.
/// @return transactionHash Hash of the transaction.
function decodeTransactionError(bytes memory encoded)
public
internal
pure
returns (
LibExchangeRichErrors.TransactionErrorCodes errorCode,
@@ -307,7 +307,7 @@ contract LibExchangeRichErrorDecoder {
/// @return transactionHash Hash of the transaction.
/// @return errorData Error thrown by exeucteTransaction().
function decodeTransactionExecutionError(bytes memory encoded)
public
internal
pure
returns (
bytes32 transactionHash,
@@ -325,7 +325,7 @@ contract LibExchangeRichErrorDecoder {
/// @param encoded ABI-encoded revert error.
/// @return orderHash Hash of the order being filled.
function decodeIncompleteFillError(bytes memory encoded)
public
internal
pure
returns (
LibExchangeRichErrors.IncompleteFillErrorCode errorCode,

View File

@@ -22,6 +22,249 @@ import "../src/libs/LibExchangeRichErrorDecoder.sol";
// solhint-disable no-empty-blocks
contract TestLibExchangeRichErrorDecoder is
LibExchangeRichErrorDecoder
{}
contract TestLibExchangeRichErrorDecoder
{
/// @dev Decompose an ABI-encoded SignatureError.
/// @param encoded ABI-encoded revert error.
/// @return errorCode The error code.
/// @return signerAddress The expected signer of the hash.
/// @return signature The full signature.
function decodeSignatureError(bytes memory encoded)
public
pure
returns (
LibExchangeRichErrors.SignatureErrorCodes errorCode,
bytes32 hash,
address signerAddress,
bytes memory signature
)
{
return LibExchangeRichErrorDecoder.decodeSignatureError(encoded);
}
/// @dev Decompose an ABI-encoded SignatureValidatorError.
/// @param encoded ABI-encoded revert error.
/// @return signerAddress The expected signer of the hash.
/// @return signature The full signature bytes.
/// @return errorData The revert data thrown by the validator contract.
function decodeEIP1271SignatureError(bytes memory encoded)
public
pure
returns (
address verifyingContractAddress,
bytes memory data,
bytes memory signature,
bytes memory errorData
)
{
return LibExchangeRichErrorDecoder.decodeEIP1271SignatureError(encoded);
}
/// @dev Decompose an ABI-encoded SignatureValidatorNotApprovedError.
/// @param encoded ABI-encoded revert error.
/// @return signerAddress The expected signer of the hash.
/// @return validatorAddress The expected validator.
function decodeSignatureValidatorNotApprovedError(bytes memory encoded)
public
pure
returns (
address signerAddress,
address validatorAddress
)
{
return LibExchangeRichErrorDecoder.decodeSignatureValidatorNotApprovedError(encoded);
}
/// @dev Decompose an ABI-encoded SignatureWalletError.
/// @param encoded ABI-encoded revert error.
/// @return errorCode The error code.
/// @return signerAddress The expected signer of the hash.
/// @return signature The full signature bytes.
/// @return errorData The revert data thrown by the validator contract.
function decodeSignatureWalletError(bytes memory encoded)
public
pure
returns (
bytes32 hash,
address signerAddress,
bytes memory signature,
bytes memory errorData
)
{
return LibExchangeRichErrorDecoder.decodeSignatureWalletError(encoded);
}
/// @dev Decompose an ABI-encoded OrderStatusError.
/// @param encoded ABI-encoded revert error.
/// @return orderHash The order hash.
/// @return orderStatus The order status.
function decodeOrderStatusError(bytes memory encoded)
public
pure
returns (
bytes32 orderHash,
LibOrder.OrderStatus orderStatus
)
{
return LibExchangeRichErrorDecoder.decodeOrderStatusError(encoded);
}
/// @dev Decompose an ABI-encoded OrderStatusError.
/// @param encoded ABI-encoded revert error.
/// @return errorCode Error code that corresponds to invalid maker, taker, or sender.
/// @return orderHash The order hash.
/// @return contextAddress The maker, taker, or sender address
function decodeExchangeInvalidContextError(bytes memory encoded)
public
pure
returns (
LibExchangeRichErrors.ExchangeContextErrorCodes errorCode,
bytes32 orderHash,
address contextAddress
)
{
return LibExchangeRichErrorDecoder.decodeExchangeInvalidContextError(encoded);
}
/// @dev Decompose an ABI-encoded FillError.
/// @param encoded ABI-encoded revert error.
/// @return errorCode The error code.
/// @return orderHash The order hash.
function decodeFillError(bytes memory encoded)
public
pure
returns (
LibExchangeRichErrors.FillErrorCodes errorCode,
bytes32 orderHash
)
{
return LibExchangeRichErrorDecoder.decodeFillError(encoded);
}
/// @dev Decompose an ABI-encoded OrderEpochError.
/// @param encoded ABI-encoded revert error.
/// @return makerAddress The order maker.
/// @return orderSenderAddress The order sender.
/// @return currentEpoch The current epoch for the maker.
function decodeOrderEpochError(bytes memory encoded)
public
pure
returns (
address makerAddress,
address orderSenderAddress,
uint256 currentEpoch
)
{
return LibExchangeRichErrorDecoder.decodeOrderEpochError(encoded);
}
/// @dev Decompose an ABI-encoded AssetProxyExistsError.
/// @param encoded ABI-encoded revert error.
/// @return assetProxyId Id of asset proxy.
/// @return assetProxyAddress The address of the asset proxy.
function decodeAssetProxyExistsError(bytes memory encoded)
public
pure
returns (
bytes4 assetProxyId, address assetProxyAddress)
{
return LibExchangeRichErrorDecoder.decodeAssetProxyExistsError(encoded);
}
/// @dev Decompose an ABI-encoded AssetProxyDispatchError.
/// @param encoded ABI-encoded revert error.
/// @return errorCode The error code.
/// @return orderHash Hash of the order being dispatched.
/// @return assetData Asset data of the order being dispatched.
function decodeAssetProxyDispatchError(bytes memory encoded)
public
pure
returns (
LibExchangeRichErrors.AssetProxyDispatchErrorCodes errorCode,
bytes32 orderHash,
bytes memory assetData
)
{
return LibExchangeRichErrorDecoder.decodeAssetProxyDispatchError(encoded);
}
/// @dev Decompose an ABI-encoded AssetProxyTransferError.
/// @param encoded ABI-encoded revert error.
/// @return orderHash Hash of the order being dispatched.
/// @return assetData Asset data of the order being dispatched.
/// @return errorData ABI-encoded revert data from the asset proxy.
function decodeAssetProxyTransferError(bytes memory encoded)
public
pure
returns (
bytes32 orderHash,
bytes memory assetData,
bytes memory errorData
)
{
return LibExchangeRichErrorDecoder.decodeAssetProxyTransferError(encoded);
}
/// @dev Decompose an ABI-encoded NegativeSpreadError.
/// @param encoded ABI-encoded revert error.
/// @return leftOrderHash Hash of the left order being matched.
/// @return rightOrderHash Hash of the right order being matched.
function decodeNegativeSpreadError(bytes memory encoded)
public
pure
returns (
bytes32 leftOrderHash,
bytes32 rightOrderHash
)
{
return LibExchangeRichErrorDecoder.decodeNegativeSpreadError(encoded);
}
/// @dev Decompose an ABI-encoded TransactionError.
/// @param encoded ABI-encoded revert error.
/// @return errorCode The error code.
/// @return transactionHash Hash of the transaction.
function decodeTransactionError(bytes memory encoded)
public
pure
returns (
LibExchangeRichErrors.TransactionErrorCodes errorCode,
bytes32 transactionHash
)
{
return LibExchangeRichErrorDecoder.decodeTransactionError(encoded);
}
/// @dev Decompose an ABI-encoded TransactionExecutionError.
/// @param encoded ABI-encoded revert error.
/// @return transactionHash Hash of the transaction.
/// @return errorData Error thrown by exeucteTransaction().
function decodeTransactionExecutionError(bytes memory encoded)
public
pure
returns (
bytes32 transactionHash,
bytes memory errorData
)
{
return LibExchangeRichErrorDecoder.decodeTransactionExecutionError(encoded);
}
/// @dev Decompose an ABI-encoded IncompleteFillError.
/// @param encoded ABI-encoded revert error.
/// @return orderHash Hash of the order being filled.
function decodeIncompleteFillError(bytes memory encoded)
public
pure
returns (
LibExchangeRichErrors.IncompleteFillErrorCode errorCode,
uint256 expectedAssetFillAmount,
uint256 actualAssetFillAmount
)
{
return LibExchangeRichErrorDecoder.decodeIncompleteFillError(encoded);
}
}

View File

@@ -35,6 +35,7 @@ export {
OutputField,
ParamDescription,
EvmBytecodeOutput,
EvmBytecodeOutputLinkReferences,
AbiDefinition,
FunctionAbi,
EventAbi,

View File

@@ -1,11 +1,11 @@
import {
artifacts as proxyArtifacts,
encodeERC20AssetData,
ERC20ProxyContract,
ERC20Wrapper,
ERC721ProxyContract,
ERC721Wrapper,
} from '@0x/contracts-asset-proxy';
import { DevUtilsContract } from '@0x/contracts-dev-utils';
import { DummyERC20TokenContract } from '@0x/contracts-erc20';
import {
chaiSetup,
@@ -47,7 +47,6 @@ describe('AssetProxyDispatcher', () => {
let erc20Wrapper: ERC20Wrapper;
let erc721Wrapper: ERC721Wrapper;
const devUtils = new DevUtilsContract(constants.NULL_ADDRESS, provider);
before(async () => {
await blockchainLifecycle.startAsync();
});
@@ -189,7 +188,7 @@ describe('AssetProxyDispatcher', () => {
from: owner,
});
// Construct metadata for ERC20 proxy
const encodedAssetData = await devUtils.encodeERC20AssetData(erc20TokenA.address).callAsync();
const encodedAssetData = encodeERC20AssetData(erc20TokenA.address);
// Perform a transfer from makerAddress to takerAddress
const erc20Balances = await erc20Wrapper.getBalancesAsync();
@@ -213,7 +212,7 @@ describe('AssetProxyDispatcher', () => {
from: owner,
});
// Construct metadata for ERC20 proxy
const encodedAssetData = await devUtils.encodeERC20AssetData(erc20TokenA.address).callAsync();
const encodedAssetData = encodeERC20AssetData(erc20TokenA.address);
// Perform a transfer from makerAddress to takerAddress
const erc20Balances = await erc20Wrapper.getBalancesAsync();
@@ -228,7 +227,7 @@ describe('AssetProxyDispatcher', () => {
it('should revert if dispatching to unregistered proxy', async () => {
// Construct metadata for ERC20 proxy
const encodedAssetData = await devUtils.encodeERC20AssetData(erc20TokenA.address).callAsync();
const encodedAssetData = encodeERC20AssetData(erc20TokenA.address);
// Perform a transfer from makerAddress to takerAddress
const amount = new BigNumber(10);
@@ -247,7 +246,7 @@ describe('AssetProxyDispatcher', () => {
await assetProxyDispatcher.registerAssetProxy(erc20Proxy.address).awaitTransactionSuccessAsync({
from: owner,
});
const encodedAssetData = (await devUtils.encodeERC20AssetData(erc20TokenA.address).callAsync()).slice(0, 8);
const encodedAssetData = encodeERC20AssetData(erc20TokenA.address).slice(0, 8);
const amount = new BigNumber(1);
const expectedError = new ExchangeRevertErrors.AssetProxyDispatchError(
ExchangeRevertErrors.AssetProxyDispatchErrorCode.InvalidAssetDataLength,
@@ -265,10 +264,7 @@ describe('AssetProxyDispatcher', () => {
from: owner,
});
// Shave off the last byte
const encodedAssetData = (await devUtils.encodeERC20AssetData(erc20TokenA.address).callAsync()).slice(
0,
72,
);
const encodedAssetData = encodeERC20AssetData(erc20TokenA.address).slice(0, 72);
const amount = new BigNumber(1);
const expectedError = new ExchangeRevertErrors.AssetProxyDispatchError(
ExchangeRevertErrors.AssetProxyDispatchErrorCode.InvalidAssetDataLength,
@@ -288,7 +284,7 @@ describe('AssetProxyDispatcher', () => {
await erc20TokenA.approve(erc20Proxy.address, constants.ZERO_AMOUNT).awaitTransactionSuccessAsync({
from: makerAddress,
});
const encodedAssetData = await devUtils.encodeERC20AssetData(erc20TokenA.address).callAsync();
const encodedAssetData = encodeERC20AssetData(erc20TokenA.address);
const amount = new BigNumber(1);
const nestedError = new StringRevertError(RevertReason.TransferFailed).encode();
const expectedError = new ExchangeRevertErrors.AssetProxyTransferError(
@@ -307,8 +303,8 @@ describe('AssetProxyDispatcher', () => {
await assetProxyDispatcher.registerAssetProxy(erc20Proxy.address).awaitTransactionSuccessAsync({
from: owner,
});
const assetDataA = await devUtils.encodeERC20AssetData(erc20TokenA.address).callAsync();
const assetDataB = await devUtils.encodeERC20AssetData(erc20TokenB.address).callAsync();
const assetDataA = encodeERC20AssetData(erc20TokenA.address);
const assetDataB = encodeERC20AssetData(erc20TokenB.address);
await erc20TokenB.approve(erc20Proxy.address, constants.ZERO_AMOUNT).awaitTransactionSuccessAsync({
from: makerAddress,
});
@@ -330,8 +326,8 @@ describe('AssetProxyDispatcher', () => {
return expect(tx).to.revertWith(expectedError);
});
it('should forward the revert reason from the underlying failed transfer', async () => {
const assetDataA = await devUtils.encodeERC20AssetData(erc20TokenA.address).callAsync();
const assetDataB = await devUtils.encodeERC20AssetData(erc20TokenB.address).callAsync();
const assetDataA = encodeERC20AssetData(erc20TokenA.address);
const assetDataB = encodeERC20AssetData(erc20TokenB.address);
const transferIndexAsBytes32 = '0x0000000000000000000000000000000000000000000000000000000000000000';
const expectedError = new ExchangeRevertErrors.AssetProxyDispatchError(
ExchangeRevertErrors.AssetProxyDispatchErrorCode.UnknownAssetProxy,
@@ -352,8 +348,8 @@ describe('AssetProxyDispatcher', () => {
await assetProxyDispatcher.registerAssetProxy(erc20Proxy.address).awaitTransactionSuccessAsync({
from: owner,
});
const assetDataA = await devUtils.encodeERC20AssetData(erc20TokenA.address).callAsync();
const assetDataB = await devUtils.encodeERC20AssetData(erc20TokenB.address).callAsync();
const assetDataA = encodeERC20AssetData(erc20TokenA.address);
const assetDataB = encodeERC20AssetData(erc20TokenB.address);
const tx = assetProxyDispatcher
.simulateDispatchTransferFromCalls(
[assetDataA, assetDataB],
@@ -368,8 +364,8 @@ describe('AssetProxyDispatcher', () => {
await assetProxyDispatcher.registerAssetProxy(erc20Proxy.address).awaitTransactionSuccessAsync({
from: owner,
});
const assetDataA = await devUtils.encodeERC20AssetData(erc20TokenA.address).callAsync();
const assetDataB = await devUtils.encodeERC20AssetData(erc20TokenB.address).callAsync();
const assetDataA = encodeERC20AssetData(erc20TokenA.address);
const assetDataB = encodeERC20AssetData(erc20TokenB.address);
const balances = await erc20Wrapper.getBalancesAsync();
try {
await assetProxyDispatcher

View File

@@ -1,22 +1,17 @@
import { artifacts as assetProxyArtifacts, ERC20ProxyContract } from '@0x/contracts-asset-proxy';
import { DevUtilsContract } from '@0x/contracts-dev-utils';
import { artifacts as assetProxyArtifacts, encodeERC20AssetData, ERC20ProxyContract } from '@0x/contracts-asset-proxy';
import { artifacts as erc20Artifacts, DummyERC20TokenContract, ERC20TokenContract } from '@0x/contracts-erc20';
import { blockchainTests, chaiSetup, constants } from '@0x/contracts-test-utils';
import { blockchainTests, constants, expect } from '@0x/contracts-test-utils';
import { ExchangeContractErrs } from '@0x/types';
import { BigNumber } from '@0x/utils';
import * as chai from 'chai';
import { ExchangeTransferSimulator } from './utils/exchange_transfer_simulator';
import { SimpleERC20BalanceAndProxyAllowanceFetcher } from './utils/simple_erc20_balance_and_proxy_allowance_fetcher';
import { BalanceAndProxyAllowanceLazyStore } from './utils/store/balance_and_proxy_allowance_lazy_store';
import { TradeSide, TransferType } from './utils/types';
chaiSetup.configure();
const expect = chai.expect;
const GAS_LIMIT = 9e6;
blockchainTests('ExchangeTransferSimulator', env => {
blockchainTests.resets('ExchangeTransferSimulator', env => {
const transferAmount = new BigNumber(5);
let userAddresses: string[];
let dummyERC20Token: DummyERC20TokenContract;
@@ -26,7 +21,6 @@ blockchainTests('ExchangeTransferSimulator', env => {
let exampleAssetData: string;
let exchangeTransferSimulator: ExchangeTransferSimulator;
let erc20ProxyAddress: string;
const devUtils = new DevUtilsContract(constants.NULL_ADDRESS, env.provider);
before(async function(): Promise<void> {
const mochaTestTimeoutMs = 20000;
this.timeout(mochaTestTimeoutMs); // tslint:disable-line:no-invalid-this
@@ -39,7 +33,6 @@ blockchainTests('ExchangeTransferSimulator', env => {
from: userAddresses[0],
};
await env.blockchainLifecycle.startAsync();
const erc20Proxy = await ERC20ProxyContract.deployFrom0xArtifactAsync(
assetProxyArtifacts.ERC20Proxy,
env.provider,
@@ -64,16 +57,7 @@ blockchainTests('ExchangeTransferSimulator', env => {
totalSupply,
);
exampleAssetData = await devUtils.encodeERC20AssetData(dummyERC20Token.address).callAsync();
});
beforeEach(async () => {
await env.blockchainLifecycle.startAsync();
});
afterEach(async () => {
await env.blockchainLifecycle.revertAsync();
});
after(async () => {
await env.blockchainLifecycle.revertAsync();
exampleAssetData = encodeERC20AssetData(dummyERC20Token.address);
});
describe('#transferFromAsync', function(): void {
// HACK: For some reason these tests need a slightly longer timeout
@@ -87,7 +71,7 @@ blockchainTests('ExchangeTransferSimulator', env => {
const balanceAndProxyAllowanceLazyStore = new BalanceAndProxyAllowanceLazyStore(
simpleERC20BalanceAndProxyAllowanceFetcher,
);
exchangeTransferSimulator = new ExchangeTransferSimulator(balanceAndProxyAllowanceLazyStore, devUtils);
exchangeTransferSimulator = new ExchangeTransferSimulator(balanceAndProxyAllowanceLazyStore);
});
it("throws if the user doesn't have enough allowance", async () => {
return expect(

View File

@@ -1,5 +1,4 @@
import { DevUtilsContract } from '@0x/contracts-dev-utils';
import { blockchainTests, constants, describe, provider } from '@0x/contracts-test-utils';
import { blockchainTests, describe } from '@0x/contracts-test-utils';
import * as _ from 'lodash';
import {
@@ -49,10 +48,8 @@ const defaultFillScenario = {
blockchainTests.resets('FillOrder Tests', ({ web3Wrapper, txDefaults }) => {
let fillOrderCombinatorialUtils: FillOrderCombinatorialUtils;
let devUtils: DevUtilsContract;
before(async () => {
devUtils = new DevUtilsContract(constants.NULL_ADDRESS, provider);
fillOrderCombinatorialUtils = await fillOrderCombinatorialUtilsFactoryAsync(web3Wrapper, txDefaults);
});
@@ -65,7 +62,7 @@ blockchainTests.resets('FillOrder Tests', ({ web3Wrapper, txDefaults }) => {
takerAssetAmountScenario: OrderAssetAmountScenario.Small,
},
};
await fillOrderCombinatorialUtils.testFillOrderScenarioSuccessAsync(fillScenario, devUtils);
await fillOrderCombinatorialUtils.testFillOrderScenarioSuccessAsync(fillScenario);
});
it('should transfer the correct amounts when makerAssetAmount < takerAssetAmount', async () => {
@@ -76,7 +73,7 @@ blockchainTests.resets('FillOrder Tests', ({ web3Wrapper, txDefaults }) => {
makerAssetAmountScenario: OrderAssetAmountScenario.Small,
},
};
await fillOrderCombinatorialUtils.testFillOrderScenarioSuccessAsync(fillScenario, devUtils);
await fillOrderCombinatorialUtils.testFillOrderScenarioSuccessAsync(fillScenario);
});
it('should transfer the correct amounts when makerAssetAmount < takerAssetAmount with zero decimals', async () => {
@@ -88,7 +85,7 @@ blockchainTests.resets('FillOrder Tests', ({ web3Wrapper, txDefaults }) => {
makerAssetDataScenario: AssetDataScenario.ERC20ZeroDecimals,
},
};
await fillOrderCombinatorialUtils.testFillOrderScenarioSuccessAsync(fillScenario, devUtils);
await fillOrderCombinatorialUtils.testFillOrderScenarioSuccessAsync(fillScenario);
});
it('should transfer the correct amounts when taker is specified and order is claimed by taker', async () => {
@@ -99,7 +96,7 @@ blockchainTests.resets('FillOrder Tests', ({ web3Wrapper, txDefaults }) => {
takerScenario: TakerScenario.CorrectlySpecified,
},
};
await fillOrderCombinatorialUtils.testFillOrderScenarioSuccessAsync(fillScenario, devUtils);
await fillOrderCombinatorialUtils.testFillOrderScenarioSuccessAsync(fillScenario);
});
it('should transfer the correct amounts maker == feeRecipient', async () => {
@@ -110,7 +107,7 @@ blockchainTests.resets('FillOrder Tests', ({ web3Wrapper, txDefaults }) => {
feeRecipientScenario: FeeRecipientAddressScenario.MakerAddress,
},
};
await fillOrderCombinatorialUtils.testFillOrderScenarioSuccessAsync(fillScenario, devUtils);
await fillOrderCombinatorialUtils.testFillOrderScenarioSuccessAsync(fillScenario);
});
it('should transfer the correct amounts maker == feeRecipient and makerFeeAsset == takerAsset', async () => {
@@ -122,7 +119,7 @@ blockchainTests.resets('FillOrder Tests', ({ web3Wrapper, txDefaults }) => {
makerFeeAssetDataScenario: FeeAssetDataScenario.TakerToken,
},
};
await fillOrderCombinatorialUtils.testFillOrderScenarioSuccessAsync(fillScenario, devUtils);
await fillOrderCombinatorialUtils.testFillOrderScenarioSuccessAsync(fillScenario);
});
it('should transfer the correct amounts taker == feeRecipient', async () => {
@@ -133,7 +130,7 @@ blockchainTests.resets('FillOrder Tests', ({ web3Wrapper, txDefaults }) => {
feeRecipientScenario: FeeRecipientAddressScenario.TakerAddress,
},
};
await fillOrderCombinatorialUtils.testFillOrderScenarioSuccessAsync(fillScenario, devUtils);
await fillOrderCombinatorialUtils.testFillOrderScenarioSuccessAsync(fillScenario);
});
it('should transfer the correct amounts taker == feeRecipient and takerFeeAsset == makerAsset', async () => {
@@ -145,7 +142,7 @@ blockchainTests.resets('FillOrder Tests', ({ web3Wrapper, txDefaults }) => {
takerFeeAssetDataScenario: FeeAssetDataScenario.MakerToken,
},
};
await fillOrderCombinatorialUtils.testFillOrderScenarioSuccessAsync(fillScenario, devUtils);
await fillOrderCombinatorialUtils.testFillOrderScenarioSuccessAsync(fillScenario);
});
it('should fill remaining value if takerAssetFillAmount > remaining takerAssetAmount', async () => {
@@ -153,7 +150,7 @@ blockchainTests.resets('FillOrder Tests', ({ web3Wrapper, txDefaults }) => {
...defaultFillScenario,
takerAssetFillAmountScenario: TakerAssetFillAmountScenario.GreaterThanTakerAssetAmount,
};
await fillOrderCombinatorialUtils.testFillOrderScenarioSuccessAsync(fillScenario, devUtils);
await fillOrderCombinatorialUtils.testFillOrderScenarioSuccessAsync(fillScenario);
});
it('should revert when taker is specified and order is claimed by other', async () => {
@@ -164,7 +161,7 @@ blockchainTests.resets('FillOrder Tests', ({ web3Wrapper, txDefaults }) => {
takerScenario: TakerScenario.IncorrectlySpecified,
},
};
await fillOrderCombinatorialUtils.testFillOrderScenarioFailureAsync(fillScenario, devUtils);
await fillOrderCombinatorialUtils.testFillOrderScenarioFailureAsync(fillScenario);
});
it('should revert if makerAssetAmount is 0', async () => {
@@ -176,7 +173,7 @@ blockchainTests.resets('FillOrder Tests', ({ web3Wrapper, txDefaults }) => {
},
takerAssetFillAmountScenario: TakerAssetFillAmountScenario.GreaterThanTakerAssetAmount,
};
await fillOrderCombinatorialUtils.testFillOrderScenarioFailureAsync(fillScenario, devUtils);
await fillOrderCombinatorialUtils.testFillOrderScenarioFailureAsync(fillScenario);
});
it('should revert if takerAssetAmount is 0', async () => {
@@ -188,7 +185,7 @@ blockchainTests.resets('FillOrder Tests', ({ web3Wrapper, txDefaults }) => {
},
takerAssetFillAmountScenario: TakerAssetFillAmountScenario.GreaterThanTakerAssetAmount,
};
await fillOrderCombinatorialUtils.testFillOrderScenarioFailureAsync(fillScenario, devUtils);
await fillOrderCombinatorialUtils.testFillOrderScenarioFailureAsync(fillScenario);
});
it('should revert if an order is expired', async () => {
@@ -199,7 +196,7 @@ blockchainTests.resets('FillOrder Tests', ({ web3Wrapper, txDefaults }) => {
expirationTimeSecondsScenario: ExpirationTimeSecondsScenario.InPast,
},
};
await fillOrderCombinatorialUtils.testFillOrderScenarioFailureAsync(fillScenario, devUtils);
await fillOrderCombinatorialUtils.testFillOrderScenarioFailureAsync(fillScenario);
});
});
@@ -219,7 +216,7 @@ blockchainTests.resets('FillOrder Tests', ({ web3Wrapper, txDefaults }) => {
takerAssetDataScenario: takerAsset,
},
};
await fillOrderCombinatorialUtils.testFillOrderScenarioSuccessAsync(fillScenario, devUtils);
await fillOrderCombinatorialUtils.testFillOrderScenarioSuccessAsync(fillScenario);
});
}
it('should be able to pay maker fee with taker asset', async () => {
@@ -235,7 +232,7 @@ blockchainTests.resets('FillOrder Tests', ({ web3Wrapper, txDefaults }) => {
feeBalance: BalanceAmountScenario.Zero,
},
};
await fillOrderCombinatorialUtils.testFillOrderScenarioSuccessAsync(fillScenario, devUtils);
await fillOrderCombinatorialUtils.testFillOrderScenarioSuccessAsync(fillScenario);
});
it('should be able to pay taker fee with maker asset', async () => {
@@ -251,7 +248,7 @@ blockchainTests.resets('FillOrder Tests', ({ web3Wrapper, txDefaults }) => {
feeBalance: BalanceAmountScenario.Zero,
},
};
await fillOrderCombinatorialUtils.testFillOrderScenarioSuccessAsync(fillScenario, devUtils);
await fillOrderCombinatorialUtils.testFillOrderScenarioSuccessAsync(fillScenario);
});
it('should not be able to pay maker fee with maker asset if none is left over (double-spend)', async () => {
@@ -268,7 +265,7 @@ blockchainTests.resets('FillOrder Tests', ({ web3Wrapper, txDefaults }) => {
feeBalance: BalanceAmountScenario.Zero,
},
};
await fillOrderCombinatorialUtils.testFillOrderScenarioFailureAsync(fillScenario, devUtils);
await fillOrderCombinatorialUtils.testFillOrderScenarioFailureAsync(fillScenario);
});
it('should not be able to pay taker fee with taker asset if none is left over (double-spend)', async () => {
@@ -285,7 +282,7 @@ blockchainTests.resets('FillOrder Tests', ({ web3Wrapper, txDefaults }) => {
feeBalance: BalanceAmountScenario.Zero,
},
};
await fillOrderCombinatorialUtils.testFillOrderScenarioFailureAsync(fillScenario, devUtils);
await fillOrderCombinatorialUtils.testFillOrderScenarioFailureAsync(fillScenario);
});
it('should be able to pay taker fee with maker asset', async () => {
@@ -301,7 +298,7 @@ blockchainTests.resets('FillOrder Tests', ({ web3Wrapper, txDefaults }) => {
feeBalance: BalanceAmountScenario.Zero,
},
};
await fillOrderCombinatorialUtils.testFillOrderScenarioSuccessAsync(fillScenario, devUtils);
await fillOrderCombinatorialUtils.testFillOrderScenarioSuccessAsync(fillScenario);
});
it('should revert if maker balance is too low to fill order', async () => {
@@ -312,7 +309,7 @@ blockchainTests.resets('FillOrder Tests', ({ web3Wrapper, txDefaults }) => {
traderAssetBalance: BalanceAmountScenario.TooLow,
},
};
await fillOrderCombinatorialUtils.testFillOrderScenarioFailureAsync(fillScenario, devUtils);
await fillOrderCombinatorialUtils.testFillOrderScenarioFailureAsync(fillScenario);
});
it('should revert if taker balance is too low to fill order', async () => {
@@ -323,7 +320,7 @@ blockchainTests.resets('FillOrder Tests', ({ web3Wrapper, txDefaults }) => {
traderAssetBalance: BalanceAmountScenario.TooLow,
},
};
await fillOrderCombinatorialUtils.testFillOrderScenarioFailureAsync(fillScenario, devUtils);
await fillOrderCombinatorialUtils.testFillOrderScenarioFailureAsync(fillScenario);
});
it('should revert if maker allowances are too low to fill order', async () => {
@@ -334,7 +331,7 @@ blockchainTests.resets('FillOrder Tests', ({ web3Wrapper, txDefaults }) => {
traderAssetAllowance: AllowanceAmountScenario.TooLow,
},
};
await fillOrderCombinatorialUtils.testFillOrderScenarioFailureAsync(fillScenario, devUtils);
await fillOrderCombinatorialUtils.testFillOrderScenarioFailureAsync(fillScenario);
});
it('should revert if taker allowances are too low to fill order', async () => {
@@ -345,7 +342,7 @@ blockchainTests.resets('FillOrder Tests', ({ web3Wrapper, txDefaults }) => {
traderAssetAllowance: AllowanceAmountScenario.TooLow,
},
};
await fillOrderCombinatorialUtils.testFillOrderScenarioFailureAsync(fillScenario, devUtils);
await fillOrderCombinatorialUtils.testFillOrderScenarioFailureAsync(fillScenario);
});
it('should revert if maker fee balance is too low to fill order', async () => {
@@ -356,7 +353,7 @@ blockchainTests.resets('FillOrder Tests', ({ web3Wrapper, txDefaults }) => {
feeBalance: BalanceAmountScenario.TooLow,
},
};
await fillOrderCombinatorialUtils.testFillOrderScenarioFailureAsync(fillScenario, devUtils);
await fillOrderCombinatorialUtils.testFillOrderScenarioFailureAsync(fillScenario);
});
it('should revert if taker fee balance is too low to fill order', async () => {
@@ -367,7 +364,7 @@ blockchainTests.resets('FillOrder Tests', ({ web3Wrapper, txDefaults }) => {
feeBalance: BalanceAmountScenario.TooLow,
},
};
await fillOrderCombinatorialUtils.testFillOrderScenarioFailureAsync(fillScenario, devUtils);
await fillOrderCombinatorialUtils.testFillOrderScenarioFailureAsync(fillScenario);
});
it('should revert if maker fee allowances are too low to fill order', async () => {
@@ -378,7 +375,7 @@ blockchainTests.resets('FillOrder Tests', ({ web3Wrapper, txDefaults }) => {
feeAllowance: AllowanceAmountScenario.TooLow,
},
};
await fillOrderCombinatorialUtils.testFillOrderScenarioFailureAsync(fillScenario, devUtils);
await fillOrderCombinatorialUtils.testFillOrderScenarioFailureAsync(fillScenario);
});
it('should revert if taker fee allowances are too low to fill order', async () => {
@@ -389,7 +386,7 @@ blockchainTests.resets('FillOrder Tests', ({ web3Wrapper, txDefaults }) => {
feeAllowance: AllowanceAmountScenario.TooLow,
},
};
await fillOrderCombinatorialUtils.testFillOrderScenarioFailureAsync(fillScenario, devUtils);
await fillOrderCombinatorialUtils.testFillOrderScenarioFailureAsync(fillScenario);
});
});
@@ -408,7 +405,7 @@ blockchainTests.resets('FillOrder Tests', ({ web3Wrapper, txDefaults }) => {
feeBalance: BalanceAmountScenario.Zero,
},
};
await fillOrderCombinatorialUtils.testFillOrderScenarioSuccessAsync(fillScenario, devUtils);
await fillOrderCombinatorialUtils.testFillOrderScenarioSuccessAsync(fillScenario);
});
it('should be able to pay taker fee with maker ERC721', async () => {
@@ -425,7 +422,7 @@ blockchainTests.resets('FillOrder Tests', ({ web3Wrapper, txDefaults }) => {
feeBalance: BalanceAmountScenario.Zero,
},
};
await fillOrderCombinatorialUtils.testFillOrderScenarioSuccessAsync(fillScenario, devUtils);
await fillOrderCombinatorialUtils.testFillOrderScenarioSuccessAsync(fillScenario);
});
it('should not be able to pay maker fee with maker ERC721 (double-spend)', async () => {
@@ -442,7 +439,7 @@ blockchainTests.resets('FillOrder Tests', ({ web3Wrapper, txDefaults }) => {
feeBalance: BalanceAmountScenario.Zero,
},
};
await fillOrderCombinatorialUtils.testFillOrderScenarioFailureAsync(fillScenario, devUtils);
await fillOrderCombinatorialUtils.testFillOrderScenarioFailureAsync(fillScenario);
});
it('should be able to pay taker fee with taker ERC721 (double-spend)', async () => {
@@ -459,7 +456,7 @@ blockchainTests.resets('FillOrder Tests', ({ web3Wrapper, txDefaults }) => {
feeBalance: BalanceAmountScenario.Zero,
},
};
await fillOrderCombinatorialUtils.testFillOrderScenarioFailureAsync(fillScenario, devUtils);
await fillOrderCombinatorialUtils.testFillOrderScenarioFailureAsync(fillScenario);
});
});
@@ -481,7 +478,7 @@ blockchainTests.resets('FillOrder Tests', ({ web3Wrapper, txDefaults }) => {
feeBalance: BalanceAmountScenario.Zero,
},
};
await fillOrderCombinatorialUtils.testFillOrderScenarioSuccessAsync(fillScenario, devUtils);
await fillOrderCombinatorialUtils.testFillOrderScenarioSuccessAsync(fillScenario);
});
it('should be able to pay taker fee with maker asset', async () => {
@@ -498,7 +495,7 @@ blockchainTests.resets('FillOrder Tests', ({ web3Wrapper, txDefaults }) => {
feeBalance: BalanceAmountScenario.Zero,
},
};
await fillOrderCombinatorialUtils.testFillOrderScenarioSuccessAsync(fillScenario, devUtils);
await fillOrderCombinatorialUtils.testFillOrderScenarioSuccessAsync(fillScenario);
});
it('should not be able to pay maker fee with maker asset if not enough left (double-spend)', async () => {
@@ -516,7 +513,7 @@ blockchainTests.resets('FillOrder Tests', ({ web3Wrapper, txDefaults }) => {
feeBalance: BalanceAmountScenario.Zero,
},
};
await fillOrderCombinatorialUtils.testFillOrderScenarioFailureAsync(fillScenario, devUtils);
await fillOrderCombinatorialUtils.testFillOrderScenarioFailureAsync(fillScenario);
});
it('should be able to pay taker fee with taker asset if not enough left (double-spend)', async () => {
@@ -534,7 +531,7 @@ blockchainTests.resets('FillOrder Tests', ({ web3Wrapper, txDefaults }) => {
feeBalance: BalanceAmountScenario.Zero,
},
};
await fillOrderCombinatorialUtils.testFillOrderScenarioFailureAsync(fillScenario, devUtils);
await fillOrderCombinatorialUtils.testFillOrderScenarioFailureAsync(fillScenario);
});
});
}
@@ -555,7 +552,7 @@ blockchainTests.resets('FillOrder Tests', ({ web3Wrapper, txDefaults }) => {
feeBalance: BalanceAmountScenario.Zero,
},
};
await fillOrderCombinatorialUtils.testFillOrderScenarioSuccessAsync(fillScenario, devUtils);
await fillOrderCombinatorialUtils.testFillOrderScenarioSuccessAsync(fillScenario);
});
it('should be able to pay taker fee with maker MAP', async () => {
@@ -572,7 +569,7 @@ blockchainTests.resets('FillOrder Tests', ({ web3Wrapper, txDefaults }) => {
feeBalance: BalanceAmountScenario.Zero,
},
};
await fillOrderCombinatorialUtils.testFillOrderScenarioSuccessAsync(fillScenario, devUtils);
await fillOrderCombinatorialUtils.testFillOrderScenarioSuccessAsync(fillScenario);
});
it('should not be able to pay maker fee with maker MAP (double-spend)', async () => {
@@ -589,7 +586,7 @@ blockchainTests.resets('FillOrder Tests', ({ web3Wrapper, txDefaults }) => {
feeBalance: BalanceAmountScenario.Zero,
},
};
await fillOrderCombinatorialUtils.testFillOrderScenarioFailureAsync(fillScenario, devUtils);
await fillOrderCombinatorialUtils.testFillOrderScenarioFailureAsync(fillScenario);
});
it('should be able to pay taker fee with taker MAP (double-spend)', async () => {
@@ -606,7 +603,7 @@ blockchainTests.resets('FillOrder Tests', ({ web3Wrapper, txDefaults }) => {
feeBalance: BalanceAmountScenario.Zero,
},
};
await fillOrderCombinatorialUtils.testFillOrderScenarioFailureAsync(fillScenario, devUtils);
await fillOrderCombinatorialUtils.testFillOrderScenarioFailureAsync(fillScenario);
});
});
@@ -629,7 +626,7 @@ blockchainTests.resets('FillOrder Tests', ({ web3Wrapper, txDefaults }) => {
},
takerAssetFillAmountScenario: TakerAssetFillAmountScenario.ExactlyTakerAssetAmount,
};
await fillOrderCombinatorialUtils.testFillOrderScenarioSuccessAsync(fillScenario, devUtils);
await fillOrderCombinatorialUtils.testFillOrderScenarioSuccessAsync(fillScenario);
});
}
});
@@ -653,7 +650,7 @@ blockchainTests.resets('FillOrder Tests', ({ web3Wrapper, txDefaults }) => {
},
takerAssetFillAmountScenario: TakerAssetFillAmountScenario.ExactlyTakerAssetAmount,
};
await fillOrderCombinatorialUtils.testFillOrderScenarioSuccessAsync(fillScenario, devUtils);
await fillOrderCombinatorialUtils.testFillOrderScenarioSuccessAsync(fillScenario);
});
}
});
@@ -663,7 +660,7 @@ blockchainTests.resets('FillOrder Tests', ({ web3Wrapper, txDefaults }) => {
for (const fillScenario of allFillScenarios) {
const description = `Combinatorial OrderFill: ${JSON.stringify(fillScenario)}`;
it(description, async () => {
await fillOrderCombinatorialUtils.testFillOrderScenarioAsync(fillScenario, devUtils);
await fillOrderCombinatorialUtils.testFillOrderScenarioAsync(fillScenario);
});
}
});

View File

@@ -1,5 +1,4 @@
import { ERC20ProxyContract, ERC20Wrapper } from '@0x/contracts-asset-proxy';
import { DevUtilsContract } from '@0x/contracts-dev-utils';
import { encodeERC20AssetData, ERC20ProxyContract, ERC20Wrapper } from '@0x/contracts-asset-proxy';
import { DummyERC20TokenContract } from '@0x/contracts-erc20';
import {
blockchainTests,
@@ -52,7 +51,6 @@ blockchainTests.resets('MixinSignatureValidator', env => {
let takerAddress: string;
let feeRecipientAddress: 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();
@@ -428,10 +426,10 @@ blockchainTests.resets('MixinSignatureValidator', env => {
...constants.STATIC_ORDER_PARAMS,
makerAddress: signerAddress,
feeRecipientAddress: randomAddress(),
makerAssetData: await devUtils.encodeERC20AssetData(randomAddress()).callAsync(),
takerAssetData: await devUtils.encodeERC20AssetData(randomAddress()).callAsync(),
makerFeeAssetData: await devUtils.encodeERC20AssetData(randomAddress()).callAsync(),
takerFeeAssetData: await devUtils.encodeERC20AssetData(randomAddress()).callAsync(),
makerAssetData: encodeERC20AssetData(randomAddress()),
takerAssetData: encodeERC20AssetData(randomAddress()),
makerFeeAssetData: encodeERC20AssetData(randomAddress()),
takerFeeAssetData: encodeERC20AssetData(randomAddress()),
makerFee: constants.ZERO_AMOUNT,
takerFee: constants.ZERO_AMOUNT,
exchangeAddress: exchange.address,
@@ -1175,10 +1173,10 @@ blockchainTests.resets('MixinSignatureValidator', env => {
...constants.STATIC_ORDER_PARAMS,
makerAddress,
feeRecipientAddress,
makerAssetData: await devUtils.encodeERC20AssetData(defaultMakerAssetAddress).callAsync(),
takerAssetData: await devUtils.encodeERC20AssetData(defaultTakerAssetAddress).callAsync(),
makerFeeAssetData: await devUtils.encodeERC20AssetData(defaultFeeAssetAddress).callAsync(),
takerFeeAssetData: await devUtils.encodeERC20AssetData(defaultFeeAssetAddress).callAsync(),
makerAssetData: encodeERC20AssetData(defaultMakerAssetAddress),
takerAssetData: encodeERC20AssetData(defaultTakerAssetAddress),
makerFeeAssetData: encodeERC20AssetData(defaultFeeAssetAddress),
takerFeeAssetData: encodeERC20AssetData(defaultFeeAssetAddress),
exchangeAddress: exchange.address,
chainId,
};

View File

@@ -1,11 +1,17 @@
import {
decodeERC1155AssetData,
decodeERC721AssetData,
decodeMultiAssetData,
ERC1155ProxyWrapper,
ERC20Wrapper,
ERC721Wrapper,
getAssetDataProxyId,
} from '@0x/contracts-asset-proxy';
import { AbstractAssetWrapper, constants } from '@0x/contracts-test-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;
}
@@ -20,11 +26,7 @@ const ZERO_NFT_UNIT = new BigNumber(0);
export class AssetWrapper {
private readonly _proxyIdToAssetWrappers: ProxyIdToAssetWrappers;
constructor(
assetWrappers: AbstractAssetWrapper[],
private readonly _burnerAddress: string,
private readonly _devUtils: DevUtilsContract,
) {
constructor(assetWrappers: AbstractAssetWrapper[], private readonly _burnerAddress: string) {
this._proxyIdToAssetWrappers = {};
_.each(assetWrappers, assetWrapper => {
const proxyId = assetWrapper.getProxyId();
@@ -32,7 +34,7 @@ export class AssetWrapper {
});
}
public async getBalanceAsync(userAddress: string, assetData: string): Promise<BigNumber> {
const proxyId = await this._devUtils.decodeAssetProxyId(assetData).callAsync();
const proxyId = getAssetDataProxyId(assetData);
switch (proxyId) {
case AssetProxyId.ERC20: {
// tslint:disable-next-line:no-unnecessary-type-assertion
@@ -44,9 +46,7 @@ export class AssetWrapper {
// tslint:disable-next-line:no-unnecessary-type-assertion
const assetWrapper = this._proxyIdToAssetWrappers[proxyId] as ERC721Wrapper;
// tslint:disable-next-line:no-unused-variable
const [assetProxyId, tokenAddress, tokenId] = await this._devUtils
.decodeERC721AssetData(assetData)
.callAsync();
const [tokenAddress, tokenId] = decodeERC721AssetData(assetData);
const isOwner = await assetWrapper.isOwnerAsync(userAddress, tokenAddress, tokenId);
const balance = isOwner ? ONE_NFT_UNIT : ZERO_NFT_UNIT;
return balance;
@@ -56,10 +56,9 @@ export class AssetWrapper {
const assetProxyWrapper = this._proxyIdToAssetWrappers[proxyId] as ERC1155ProxyWrapper;
const [
// tslint:disable-next-line:no-unused-variable
assetProxyAddress,
tokenAddress,
tokenIds,
] = await this._devUtils.decodeERC1155AssetData(assetData).callAsync();
] = decodeERC1155AssetData(assetData);
const assetWrapper = assetProxyWrapper.getContractWrapper(tokenAddress);
const balances = await Promise.all(
_.map(tokenIds).map(tokenId => assetWrapper.getBalanceAsync(userAddress, tokenId)),
@@ -68,9 +67,7 @@ export class AssetWrapper {
}
case AssetProxyId.MultiAsset: {
// tslint:disable-next-line:no-unused-variable
const [assetProxyId, amounts, nestedAssetData] = await this._devUtils
.decodeMultiAssetData(assetData)
.callAsync();
const [amounts, nestedAssetData] = decodeMultiAssetData(assetData);
const nestedBalances = await Promise.all(
nestedAssetData.map(async _nestedAssetData => this.getBalanceAsync(userAddress, _nestedAssetData)),
);
@@ -84,7 +81,7 @@ export class AssetWrapper {
}
}
public async setBalanceAsync(userAddress: string, assetData: string, desiredBalance: BigNumber): Promise<void> {
const proxyId = await this._devUtils.decodeAssetProxyId(assetData).callAsync();
const proxyId = getAssetDataProxyId(assetData);
switch (proxyId) {
case AssetProxyId.ERC20: {
// tslint:disable-next-line:no-unnecessary-type-assertion
@@ -100,9 +97,7 @@ export class AssetWrapper {
// tslint:disable-next-line:no-unnecessary-type-assertion
const erc721Wrapper = this._proxyIdToAssetWrappers[proxyId] as ERC721Wrapper;
// tslint:disable-next-line:no-unused-variable
const [assetProxyId, tokenAddress, tokenId] = await this._devUtils
.decodeERC721AssetData(assetData)
.callAsync();
const [tokenAddress, tokenId] = decodeERC721AssetData(assetData);
const doesTokenExist = erc721Wrapper.doesTokenExistAsync(tokenAddress, tokenId);
if (!doesTokenExist && desiredBalance.gte(1)) {
await erc721Wrapper.mintAsync(tokenAddress, tokenId, userAddress);
@@ -130,11 +125,10 @@ export class AssetWrapper {
const assetProxyWrapper = this._proxyIdToAssetWrappers[proxyId] as ERC1155ProxyWrapper;
const [
// tslint:disable-next-line:no-unused-variable
assetProxyAddress,
tokenAddress,
tokenIds,
tokenValues,
] = await this._devUtils.decodeERC1155AssetData(assetData).callAsync();
] = decodeERC1155AssetData(assetData);
const assetWrapper = assetProxyWrapper.getContractWrapper(tokenAddress);
const tokenValuesSum = BigNumber.sum(...tokenValues);
let tokenValueRatios = tokenValues;
@@ -197,9 +191,7 @@ export class AssetWrapper {
}
case AssetProxyId.MultiAsset: {
// tslint:disable-next-line:no-unused-variable
const [assetProxyId, amounts, nestedAssetData] = await this._devUtils
.decodeMultiAssetData(assetData)
.callAsync();
const [amounts, nestedAssetData] = decodeMultiAssetData(assetData);
const amountsSum = BigNumber.sum(...amounts);
let assetAmountRatios = amounts;
if (!amountsSum.eq(0)) {
@@ -220,7 +212,7 @@ export class AssetWrapper {
assetData: string,
desiredBalance: BigNumber,
): Promise<void> {
const proxyId = await this._devUtils.decodeAssetProxyId(assetData).callAsync();
const proxyId = getAssetDataProxyId(assetData);
switch (proxyId) {
case AssetProxyId.ERC20:
case AssetProxyId.ERC721:
@@ -235,7 +227,7 @@ export class AssetWrapper {
}
}
public async getProxyAllowanceAsync(userAddress: string, assetData: string): Promise<BigNumber> {
const proxyId = await this._devUtils.decodeAssetProxyId(assetData).callAsync();
const proxyId = getAssetDataProxyId(assetData);
switch (proxyId) {
case AssetProxyId.ERC20: {
// tslint:disable-next-line:no-unnecessary-type-assertion
@@ -247,9 +239,7 @@ export class AssetWrapper {
// tslint:disable-next-line:no-unnecessary-type-assertion
const assetWrapper = this._proxyIdToAssetWrappers[proxyId] as ERC721Wrapper;
// tslint:disable-next-line:no-unused-variable
const [assetProxyId, tokenAddress, tokenId] = await this._devUtils
.decodeERC721AssetData(assetData)
.callAsync();
const [tokenAddress, tokenId] = decodeERC721AssetData(assetData);
const isProxyApprovedForAll = await assetWrapper.isProxyApprovedForAllAsync(userAddress, tokenAddress);
if (isProxyApprovedForAll) {
return constants.UNLIMITED_ALLOWANCE_IN_BASE_UNITS;
@@ -263,9 +253,7 @@ export class AssetWrapper {
// tslint:disable-next-line:no-unnecessary-type-assertion
const assetProxyWrapper = this._proxyIdToAssetWrappers[proxyId] as ERC1155ProxyWrapper;
// tslint:disable-next-line:no-unused-variable
const [assetProxyAddress, tokenAddress] = await this._devUtils
.decodeERC1155AssetData(assetData)
.callAsync();
const [tokenAddress] = decodeERC1155AssetData(assetData);
const isApprovedForAll = await assetProxyWrapper.isProxyApprovedForAllAsync(userAddress, tokenAddress);
if (!isApprovedForAll) {
// ERC1155 is all or nothing.
@@ -275,9 +263,7 @@ export class AssetWrapper {
}
case AssetProxyId.MultiAsset: {
// tslint:disable-next-line:no-unused-variable
const [assetProxyId, amounts, nestedAssetData] = await this._devUtils
.decodeMultiAssetData(assetData)
.callAsync();
const [amounts, nestedAssetData] = decodeMultiAssetData(assetData);
const allowances = await Promise.all(
nestedAssetData.map(async _nestedAssetData =>
this.getProxyAllowanceAsync(userAddress, _nestedAssetData),
@@ -294,7 +280,7 @@ export class AssetWrapper {
assetData: string,
desiredAllowance: BigNumber,
): Promise<void> {
const proxyId = await this._devUtils.decodeAssetProxyId(assetData).callAsync();
const proxyId = getAssetDataProxyId(assetData);
switch (proxyId) {
case AssetProxyId.ERC20: {
// tslint:disable-next-line:no-unnecessary-type-assertion
@@ -315,9 +301,7 @@ export class AssetWrapper {
// tslint:disable-next-line:no-unnecessary-type-assertion
const erc721Wrapper = this._proxyIdToAssetWrappers[proxyId] as ERC721Wrapper;
// tslint:disable-next-line:no-unused-variable
const [assetProxyId, tokenAddress, tokenId] = await this._devUtils
.decodeERC721AssetData(assetData)
.callAsync();
const [tokenAddress, tokenId] = decodeERC721AssetData(assetData);
const doesTokenExist = await erc721Wrapper.doesTokenExistAsync(tokenAddress, tokenId);
if (!doesTokenExist) {
@@ -352,9 +336,7 @@ export class AssetWrapper {
// tslint:disable-next-line:no-unnecessary-type-assertion
const assetProxyWrapper = this._proxyIdToAssetWrappers[proxyId] as ERC1155ProxyWrapper;
// tslint:disable-next-line:no-unused-variable
const [assetProxyAddress, tokenAddress] = await this._devUtils
.decodeERC1155AssetData(assetData)
.callAsync();
const [tokenAddress] = decodeERC1155AssetData(assetData);
// ERC1155 allowances are all or nothing.
const shouldApprovedForAll = desiredAllowance.gt(0);
const currentAllowance = await this.getProxyAllowanceAsync(userAddress, assetData);
@@ -369,9 +351,7 @@ export class AssetWrapper {
}
case AssetProxyId.MultiAsset: {
// tslint:disable-next-line:no-unused-variable
const [assetProxyId, amounts, nestedAssetData] = await this._devUtils
.decodeMultiAssetData(assetData)
.callAsync();
const [amounts, nestedAssetData] = decodeMultiAssetData(assetData);
await Promise.all(
nestedAssetData.map(async _nestedAssetData =>
this.setProxyAllowanceAsync(userAddress, _nestedAssetData, desiredAllowance),

View File

@@ -1,4 +1,4 @@
import { DevUtilsContract } from '@0x/contracts-dev-utils';
import { decodeMultiAssetData, getAssetDataProxyId } from '@0x/contracts-asset-proxy';
import { constants } from '@0x/contracts-test-utils';
import { AssetProxyId, ExchangeContractErrs } from '@0x/types';
import { BigNumber } from '@0x/utils';
@@ -40,7 +40,6 @@ const ERR_MSG_MAPPING = {
*/
export class ExchangeTransferSimulator {
private readonly _store: AbstractBalanceAndProxyAllowanceLazyStore;
private readonly _devUtils: DevUtilsContract;
private static _throwValidationError(
failureReason: FailureReason,
tradeSide: TradeSide,
@@ -54,9 +53,8 @@ export class ExchangeTransferSimulator {
* @param store A class that implements AbstractBalanceAndProxyAllowanceLazyStore
* @return an instance of ExchangeTransferSimulator
*/
constructor(store: AbstractBalanceAndProxyAllowanceLazyStore, devUtilsContract: DevUtilsContract) {
constructor(store: AbstractBalanceAndProxyAllowanceLazyStore) {
this._store = store;
this._devUtils = devUtilsContract;
}
/**
* Simulates transferFrom call performed by a proxy
@@ -77,7 +75,7 @@ export class ExchangeTransferSimulator {
tradeSide: TradeSide,
transferType: TransferType,
): Promise<void> {
const assetProxyId = await this._devUtils.decodeAssetProxyId(assetData).callAsync();
const assetProxyId = getAssetDataProxyId(assetData);
switch (assetProxyId) {
case AssetProxyId.ERC1155:
case AssetProxyId.ERC20:
@@ -110,11 +108,11 @@ export class ExchangeTransferSimulator {
break;
}
case AssetProxyId.MultiAsset: {
const decodedAssetData = await this._devUtils.decodeMultiAssetData(assetData).callAsync();
const decodedAssetData = decodeMultiAssetData(assetData);
await this._decreaseBalanceAsync(assetData, from, amountInBaseUnits);
await this._increaseBalanceAsync(assetData, to, amountInBaseUnits);
for (const [index, nestedAssetDataElement] of decodedAssetData[2].entries()) {
const amountsElement = decodedAssetData[1][index];
for (const [index, nestedAssetDataElement] of decodedAssetData[1].entries()) {
const amountsElement = decodedAssetData[0][index];
const totalAmount = amountInBaseUnits.times(amountsElement);
await this.transferFromAsync(
nestedAssetDataElement,

View File

@@ -5,7 +5,6 @@ import {
ERC721Wrapper,
MultiAssetProxyContract,
} from '@0x/contracts-asset-proxy';
import { DevUtilsContract } from '@0x/contracts-dev-utils';
import { constants, expect, LogDecoder, orderHashUtils, orderUtils, signingUtils } from '@0x/contracts-test-utils';
import { FillResults, Order, SignatureType, SignedOrder } from '@0x/types';
import { BigNumber, errorUtils, ExchangeRevertErrors, providerUtils, RevertError, StringRevertError } from '@0x/utils';
@@ -109,8 +108,7 @@ export async function fillOrderCombinatorialUtilsFactoryAsync(
{},
);
const devUtils = new DevUtilsContract(constants.NULL_ADDRESS, provider);
const assetWrapper = new AssetWrapper([erc20Wrapper, erc721Wrapper, erc1155Wrapper], burnerAddress, devUtils);
const assetWrapper = new AssetWrapper([erc20Wrapper, erc721Wrapper, erc1155Wrapper], burnerAddress);
const exchangeContract = await ExchangeContract.deployFrom0xArtifactAsync(
artifacts.Exchange,
@@ -160,7 +158,6 @@ export async function fillOrderCombinatorialUtilsFactoryAsync(
await multiAssetProxy.registerAssetProxy(erc1155Proxy.address).awaitTransactionSuccessAsync({ from: ownerAddress });
const orderFactory = new OrderFactoryFromScenario(
devUtils,
userAddresses,
erc20EighteenDecimalTokens.map(token => token.address),
erc20FiveDecimalTokens.map(token => token.address),
@@ -441,29 +438,24 @@ export class FillOrderCombinatorialUtils {
this.balanceAndProxyAllowanceFetcher = new SimpleAssetBalanceAndProxyAllowanceFetcher(assetWrapper);
}
public async testFillOrderScenarioAsync(fillScenario: FillScenario, devUtils: DevUtilsContract): Promise<void> {
return this._testFillOrderScenarioAsync(fillScenario, TestOutlook.Any, devUtils);
public async testFillOrderScenarioAsync(fillScenario: FillScenario): Promise<void> {
return this._testFillOrderScenarioAsync(fillScenario, TestOutlook.Any);
}
public async testFillOrderScenarioSuccessAsync(
fillScenario: FillScenario,
devUtils: DevUtilsContract,
): Promise<void> {
return this._testFillOrderScenarioAsync(fillScenario, TestOutlook.Success, devUtils);
public async testFillOrderScenarioSuccessAsync(fillScenario: FillScenario): Promise<void> {
return this._testFillOrderScenarioAsync(fillScenario, TestOutlook.Success);
}
public async testFillOrderScenarioFailureAsync(
fillScenario: FillScenario,
devUtils: DevUtilsContract,
fillErrorIfExists?: FillOrderError,
): Promise<void> {
return this._testFillOrderScenarioAsync(fillScenario, TestOutlook.Failure, devUtils, fillErrorIfExists);
return this._testFillOrderScenarioAsync(fillScenario, TestOutlook.Failure, fillErrorIfExists);
}
private async _testFillOrderScenarioAsync(
fillScenario: FillScenario,
expectedTestResult: TestOutlook = TestOutlook.Any,
devUtils: DevUtilsContract,
fillErrorIfExists?: FillOrderError,
): Promise<void> {
const lazyStore = new BalanceAndProxyAllowanceLazyStore(this.balanceAndProxyAllowanceFetcher);
@@ -476,12 +468,7 @@ export class FillOrderCombinatorialUtils {
let _fillErrorIfExists = fillErrorIfExists;
if (expectedTestResult !== TestOutlook.Failure || fillErrorIfExists === undefined) {
try {
expectedFillResults = await this._simulateFillOrderAsync(
signedOrder,
takerAssetFillAmount,
lazyStore,
devUtils,
);
expectedFillResults = await this._simulateFillOrderAsync(signedOrder, takerAssetFillAmount, lazyStore);
} catch (err) {
_fillErrorIfExists = err.message;
if (expectedTestResult === TestOutlook.Success) {
@@ -514,9 +501,8 @@ export class FillOrderCombinatorialUtils {
signedOrder: SignedOrder,
takerAssetFillAmount: BigNumber,
lazyStore: BalanceAndProxyAllowanceLazyStore,
devUtils: DevUtilsContract,
): Promise<FillResults> {
const simulator = new FillOrderSimulator(lazyStore, devUtils);
const simulator = new FillOrderSimulator(lazyStore);
return simulator.simulateFillOrderAsync(signedOrder, this.takerAddress, takerAssetFillAmount);
}

View File

@@ -1,4 +1,3 @@
import { DevUtilsContract } from '@0x/contracts-dev-utils';
import { constants, orderUtils } from '@0x/contracts-test-utils';
import { Order } from '@0x/order-utils';
import { FillResults } from '@0x/types';
@@ -26,9 +25,9 @@ export class FillOrderSimulator {
public readonly lazyStore: LazyStore;
private readonly _transferSimulator: ExchangeTransferSimulator;
constructor(lazyStore: LazyStore, devUtilsContract: DevUtilsContract) {
constructor(lazyStore: LazyStore) {
this.lazyStore = lazyStore;
this._transferSimulator = new ExchangeTransferSimulator(lazyStore, devUtilsContract);
this._transferSimulator = new ExchangeTransferSimulator(lazyStore);
}
public async simulateFillOrderAsync(

View File

@@ -1,4 +1,9 @@
import { DevUtilsContract } from '@0x/contracts-dev-utils';
import {
encodeERC1155AssetData,
encodeERC20AssetData,
encodeERC721AssetData,
encodeMultiAssetData,
} from '@0x/contracts-asset-proxy';
import { constants, ERC1155HoldingsByOwner, ERC721TokenIdsByOwner } from '@0x/contracts-test-utils';
import { generatePseudoRandomSalt } from '@0x/order-utils';
import { Order } from '@0x/types';
@@ -34,7 +39,6 @@ const ZERO_UNITS = new BigNumber(0);
export class OrderFactoryFromScenario {
constructor(
private readonly _devUtils: DevUtilsContract,
private readonly _userAddresses: string[],
private readonly _erc20EighteenDecimalTokenAddresses: string[],
private readonly _erc20FiveDecimalTokenAddresses: string[],
@@ -96,59 +100,41 @@ export class OrderFactoryFromScenario {
switch (orderScenario.makerAssetDataScenario) {
case AssetDataScenario.ERC20EighteenDecimals:
makerAssetData = await this._devUtils
.encodeERC20AssetData(this._erc20EighteenDecimalTokenAddresses[0])
.callAsync();
makerAssetData = encodeERC20AssetData(this._erc20EighteenDecimalTokenAddresses[0]);
break;
case AssetDataScenario.ERC20FiveDecimals:
makerAssetData = await this._devUtils
.encodeERC20AssetData(this._erc20FiveDecimalTokenAddresses[0])
.callAsync();
makerAssetData = encodeERC20AssetData(this._erc20FiveDecimalTokenAddresses[0]);
break;
case AssetDataScenario.ERC721:
makerAssetData = await this._devUtils
.encodeERC721AssetData(this._erc721TokenAddress, erc721MakerAssetIds[0])
.callAsync();
makerAssetData = encodeERC721AssetData(this._erc721TokenAddress, erc721MakerAssetIds[0]);
break;
case AssetDataScenario.ERC20ZeroDecimals:
makerAssetData = await this._devUtils
.encodeERC20AssetData(this._erc20ZeroDecimalTokenAddresses[0])
.callAsync();
makerAssetData = encodeERC20AssetData(this._erc20ZeroDecimalTokenAddresses[0]);
break;
case AssetDataScenario.ERC1155Fungible:
makerAssetData = await this._devUtils
.encodeERC1155AssetData(
this._erc1155TokenAddress,
[erc1155FungibleMakerTokenIds[0]],
[ONE_UNITS_ZERO_DECIMALS],
erc1155CallbackData,
)
.callAsync();
makerAssetData = encodeERC1155AssetData(
this._erc1155TokenAddress,
[erc1155FungibleMakerTokenIds[0]],
[ONE_UNITS_ZERO_DECIMALS],
erc1155CallbackData,
);
break;
case AssetDataScenario.ERC1155NonFungible:
makerAssetData = await this._devUtils
.encodeERC1155AssetData(
this._erc1155TokenAddress,
[erc1155NonFungibleMakerTokenIds[0]],
[ONE_UNITS_ZERO_DECIMALS],
erc1155CallbackData,
)
.callAsync();
makerAssetData = encodeERC1155AssetData(
this._erc1155TokenAddress,
[erc1155NonFungibleMakerTokenIds[0]],
[ONE_UNITS_ZERO_DECIMALS],
erc1155CallbackData,
);
break;
case AssetDataScenario.MultiAssetERC20:
makerAssetData = await this._devUtils
.encodeMultiAssetData(
[ONE_UNITS_EIGHTEEN_DECIMALS, ONE_UNITS_FIVE_DECIMALS],
[
await this._devUtils
.encodeERC20AssetData(this._erc20EighteenDecimalTokenAddresses[0])
.callAsync(),
await this._devUtils
.encodeERC20AssetData(this._erc20FiveDecimalTokenAddresses[0])
.callAsync(),
],
)
.callAsync();
makerAssetData = encodeMultiAssetData(
[ONE_UNITS_EIGHTEEN_DECIMALS, ONE_UNITS_FIVE_DECIMALS],
[
encodeERC20AssetData(this._erc20EighteenDecimalTokenAddresses[0]),
encodeERC20AssetData(this._erc20FiveDecimalTokenAddresses[0]),
],
);
break;
default:
throw errorUtils.spawnSwitchErr('AssetDataScenario', orderScenario.makerAssetDataScenario);
@@ -156,59 +142,41 @@ export class OrderFactoryFromScenario {
switch (orderScenario.takerAssetDataScenario) {
case AssetDataScenario.ERC20EighteenDecimals:
takerAssetData = await this._devUtils
.encodeERC20AssetData(this._erc20EighteenDecimalTokenAddresses[1])
.callAsync();
takerAssetData = encodeERC20AssetData(this._erc20EighteenDecimalTokenAddresses[1]);
break;
case AssetDataScenario.ERC20FiveDecimals:
takerAssetData = await this._devUtils
.encodeERC20AssetData(this._erc20FiveDecimalTokenAddresses[1])
.callAsync();
takerAssetData = encodeERC20AssetData(this._erc20FiveDecimalTokenAddresses[1]);
break;
case AssetDataScenario.ERC721:
takerAssetData = await this._devUtils
.encodeERC721AssetData(this._erc721TokenAddress, erc721TakerAssetIds[0])
.callAsync();
takerAssetData = encodeERC721AssetData(this._erc721TokenAddress, erc721TakerAssetIds[0]);
break;
case AssetDataScenario.ERC20ZeroDecimals:
takerAssetData = await this._devUtils
.encodeERC20AssetData(this._erc20ZeroDecimalTokenAddresses[1])
.callAsync();
takerAssetData = encodeERC20AssetData(this._erc20ZeroDecimalTokenAddresses[1]);
break;
case AssetDataScenario.ERC1155Fungible:
takerAssetData = await this._devUtils
.encodeERC1155AssetData(
this._erc1155TokenAddress,
[erc1155FungibleTakerTokenIds[1]],
[ONE_UNITS_ZERO_DECIMALS],
erc1155CallbackData,
)
.callAsync();
takerAssetData = encodeERC1155AssetData(
this._erc1155TokenAddress,
[erc1155FungibleTakerTokenIds[1]],
[ONE_UNITS_ZERO_DECIMALS],
erc1155CallbackData,
);
break;
case AssetDataScenario.ERC1155NonFungible:
takerAssetData = await this._devUtils
.encodeERC1155AssetData(
this._erc1155TokenAddress,
[erc1155NonFungibleTakerTokenIds[0]],
[ONE_UNITS_ZERO_DECIMALS],
erc1155CallbackData,
)
.callAsync();
takerAssetData = encodeERC1155AssetData(
this._erc1155TokenAddress,
[erc1155NonFungibleTakerTokenIds[0]],
[ONE_UNITS_ZERO_DECIMALS],
erc1155CallbackData,
);
break;
case AssetDataScenario.MultiAssetERC20:
takerAssetData = await this._devUtils
.encodeMultiAssetData(
[ONE_UNITS_EIGHTEEN_DECIMALS, ONE_UNITS_FIVE_DECIMALS],
[
await this._devUtils
.encodeERC20AssetData(this._erc20EighteenDecimalTokenAddresses[1])
.callAsync(),
await this._devUtils
.encodeERC20AssetData(this._erc20FiveDecimalTokenAddresses[1])
.callAsync(),
],
)
.callAsync();
takerAssetData = encodeMultiAssetData(
[ONE_UNITS_EIGHTEEN_DECIMALS, ONE_UNITS_FIVE_DECIMALS],
[
encodeERC20AssetData(this._erc20EighteenDecimalTokenAddresses[1]),
encodeERC20AssetData(this._erc20FiveDecimalTokenAddresses[1]),
],
);
break;
default:
throw errorUtils.spawnSwitchErr('AssetDataScenario', orderScenario.takerAssetDataScenario);
@@ -339,63 +307,43 @@ export class OrderFactoryFromScenario {
case FeeAssetDataScenario.TakerToken:
return [feeAmount, takerAssetData];
case FeeAssetDataScenario.ERC20EighteenDecimals:
return [
feeAmount,
await this._devUtils.encodeERC20AssetData(erc20EighteenDecimalTokenAddress).callAsync(),
];
return [feeAmount, encodeERC20AssetData(erc20EighteenDecimalTokenAddress)];
case FeeAssetDataScenario.ERC20FiveDecimals:
return [
feeAmount,
await this._devUtils.encodeERC20AssetData(erc20FiveDecimalTokenAddress).callAsync(),
];
return [feeAmount, encodeERC20AssetData(erc20FiveDecimalTokenAddress)];
case FeeAssetDataScenario.ERC20ZeroDecimals:
return [
feeAmount,
await this._devUtils.encodeERC20AssetData(erc20ZeroDecimalTokenAddress).callAsync(),
];
return [feeAmount, encodeERC20AssetData(erc20ZeroDecimalTokenAddress)];
case FeeAssetDataScenario.ERC721:
return [
feeAmount,
await this._devUtils.encodeERC721AssetData(this._erc721TokenAddress, erc721AssetId).callAsync(),
];
return [feeAmount, encodeERC721AssetData(this._erc721TokenAddress, erc721AssetId)];
case FeeAssetDataScenario.ERC1155Fungible:
return [
feeAmount,
await this._devUtils
.encodeERC1155AssetData(
this._erc1155TokenAddress,
[erc1155FungibleTokenId],
[ONE_UNITS_ZERO_DECIMALS],
erc1155CallbackData,
)
.callAsync(),
encodeERC1155AssetData(
this._erc1155TokenAddress,
[erc1155FungibleTokenId],
[ONE_UNITS_ZERO_DECIMALS],
erc1155CallbackData,
),
];
case FeeAssetDataScenario.ERC1155NonFungible:
return [
feeAmount,
await this._devUtils
.encodeERC1155AssetData(
this._erc1155TokenAddress,
[erc1155NonFungibleAssetId],
[ONE_UNITS_ZERO_DECIMALS],
erc1155CallbackData,
)
.callAsync(),
encodeERC1155AssetData(
this._erc1155TokenAddress,
[erc1155NonFungibleAssetId],
[ONE_UNITS_ZERO_DECIMALS],
erc1155CallbackData,
),
];
case FeeAssetDataScenario.MultiAssetERC20:
return [
feeAmount,
await this._devUtils
.encodeMultiAssetData(
[POINT_ZERO_FIVE_UNITS_EIGHTEEN_DECIMALS, POINT_ZERO_FIVE_UNITS_FIVE_DECIMALS],
[
await this._devUtils
.encodeERC20AssetData(erc20EighteenDecimalTokenAddress)
.callAsync(),
await this._devUtils.encodeERC20AssetData(erc20FiveDecimalTokenAddress).callAsync(),
],
)
.callAsync(),
encodeMultiAssetData(
[POINT_ZERO_FIVE_UNITS_EIGHTEEN_DECIMALS, POINT_ZERO_FIVE_UNITS_FIVE_DECIMALS],
[
encodeERC20AssetData(erc20EighteenDecimalTokenAddress),
encodeERC20AssetData(erc20FiveDecimalTokenAddress),
],
),
];
default:
throw errorUtils.spawnSwitchErr('FeeAssetDataScenario', feeAssetDataScenario);