diff --git a/contracts/integrations/test/internal-integration-tests/match_orders_test.ts b/contracts/integrations/test/internal-integration-tests/match_orders_test.ts index f95771a722..c28852141f 100644 --- a/contracts/integrations/test/internal-integration-tests/match_orders_test.ts +++ b/contracts/integrations/test/internal-integration-tests/match_orders_test.ts @@ -1,8 +1,9 @@ +import { IAssetDataContract } from '@0x/contracts-asset-proxy'; import { DevUtilsContract } from '@0x/contracts-dev-utils'; import { BlockchainBalanceStore, TokenIds } from '@0x/contracts-exchange'; import { ReferenceFunctions as LibReferenceFunctions } from '@0x/contracts-exchange-libs'; import { blockchainTests, constants, expect, toBaseUnitAmount } from '@0x/contracts-test-utils'; -import { assetDataUtils, ExchangeRevertErrors, orderHashUtils } from '@0x/order-utils'; +import { ExchangeRevertErrors, orderHashUtils } from '@0x/order-utils'; import { Order, OrderStatus, SignedOrder } from '@0x/types'; import { BigNumber } from '@0x/utils'; @@ -36,11 +37,12 @@ blockchainTests.resets.only('matchOrders', env => { let deployment: DeploymentManager; let matchOrderTester: MatchOrderTester; - - const devUtils = new DevUtilsContract(constants.NULL_ADDRESS, env.provider, env.txDefaults); let leftId: BigNumber; let rightId: BigNumber; + const assetDataEncoder = new IAssetDataContract(constants.NULL_ADDRESS, env.provider, env.txDefaults); + const devUtils = new DevUtilsContract(constants.NULL_ADDRESS, env.provider, env.txDefaults); + const PROTOCOL_FEE = DeploymentManager.protocolFeeMultiplier.times(constants.DEFAULT_GAS_PRICE); before(async () => { @@ -65,9 +67,9 @@ blockchainTests.resets.only('matchOrders', env => { }); // Encode the asset data. - makerAssetDataLeft = assetDataUtils.encodeERC20AssetData(makerAssetAddressLeft); - makerAssetDataRight = assetDataUtils.encodeERC20AssetData(makerAssetAddressRight); - feeAssetData = assetDataUtils.encodeERC20AssetData(feeAssetAddress); + makerAssetDataLeft = assetDataEncoder.ERC20Token.getABIEncodedTransactionData(makerAssetAddressLeft); + makerAssetDataRight = assetDataEncoder.ERC20Token.getABIEncodedTransactionData(makerAssetAddressRight); + feeAssetData = assetDataEncoder.ERC20Token.getABIEncodedTransactionData(feeAssetAddress); // Create two market makers with compatible orders for matching. makerLeft = new Maker({ @@ -146,9 +148,12 @@ blockchainTests.resets.only('matchOrders', env => { tokenIds, ); - matchOrderTester = new MatchOrderTester(deployment, devUtils, blockchainBalanceStore); + matchOrderTester = new MatchOrderTester(assetDataEncoder, deployment, devUtils, blockchainBalanceStore); }); + /** + * Tests an order matching scenario with both eth and weth protocol fees. + */ async function testMatchOrdersAsync( leftOrder: Partial, rightOrder: Partial, @@ -180,26 +185,6 @@ blockchainTests.resets.only('matchOrders', env => { await env.blockchainLifecycle.revertAsync(); await env.blockchainLifecycle.startAsync(); - await matchOrderTester.matchOrdersAndAssertEffectsAsync( - { - leftOrder: signedOrderLeft, - rightOrder: signedOrderRight, - }, - { - ...expectedTransferAmounts, - leftProtocolFeePaidByTakerInEthAmount: PROTOCOL_FEE, - rightProtocolFeePaidByTakerInEthAmount: constants.ZERO_AMOUNT, - leftProtocolFeePaidByTakerInWethAmount: constants.ZERO_AMOUNT, - rightProtocolFeePaidByTakerInWethAmount: PROTOCOL_FEE, - }, - matcherAddress || matcher.address, - PROTOCOL_FEE, - withMaximalFill, - ); - - await env.blockchainLifecycle.revertAsync(); - await env.blockchainLifecycle.startAsync(); - await matchOrderTester.matchOrdersAndAssertEffectsAsync( { leftOrder: signedOrderLeft, @@ -1097,7 +1082,7 @@ blockchainTests.resets.only('matchOrders', env => { takerAssetAmount: toBaseUnitAmount(10, 18), }); const signedOrderRight = await makerRight.signOrderAsync({ - takerAssetData: await devUtils.encodeERC20AssetData.callAsync(makerAssetAddressRight), + takerAssetData: assetDataEncoder.ERC20Token.getABIEncodedTransactionData(makerAssetAddressRight), makerAssetAmount: toBaseUnitAmount(10, 18), takerAssetAmount: toBaseUnitAmount(2, 18), }); @@ -1132,7 +1117,7 @@ blockchainTests.resets.only('matchOrders', env => { it('should revert if the right maker asset is not equal to the left taker asset', async () => { // Create orders to match const signedOrderLeft = await makerLeft.signOrderAsync({ - takerAssetData: await devUtils.encodeERC20AssetData.callAsync(makerAssetAddressLeft), + takerAssetData: assetDataEncoder.ERC20Token.getABIEncodedTransactionData(makerAssetAddressLeft), makerAssetAmount: toBaseUnitAmount(5, 18), takerAssetAmount: toBaseUnitAmount(10, 18), }); @@ -2010,7 +1995,7 @@ blockchainTests.resets.only('matchOrders', env => { takerAssetAmount: toBaseUnitAmount(10, 18), }); const signedOrderRight = await makerRight.signOrderAsync({ - takerAssetData: await devUtils.encodeERC20AssetData.callAsync(makerAssetAddressRight), + takerAssetData: assetDataEncoder.ERC20Token.getABIEncodedTransactionData(makerAssetAddressRight), makerAssetAmount: toBaseUnitAmount(10, 18), takerAssetAmount: toBaseUnitAmount(2, 18), }); @@ -2043,7 +2028,7 @@ blockchainTests.resets.only('matchOrders', env => { it('should revert if the right maker asset is not equal to the left taker asset', async () => { // Create orders to match const signedOrderLeft = await makerLeft.signOrderAsync({ - takerAssetData: await devUtils.encodeERC20AssetData.callAsync(makerAssetAddressLeft), + takerAssetData: assetDataEncoder.ERC20Token.getABIEncodedTransactionData(makerAssetAddressLeft), makerAssetAmount: toBaseUnitAmount(5, 18), takerAssetAmount: toBaseUnitAmount(10, 18), }); @@ -2229,6 +2214,9 @@ blockchainTests.resets.only('matchOrders', env => { matcherAddress?: string; } + /** + * Tests a batch order matching scenario with both eth and weth protocol fees. + */ async function testBatchMatchOrdersAsync(args: TestBatchMatchOrdersArgs): Promise { const signedLeftOrders = await Promise.all(args.leftOrders.map(async order => makerLeft.signOrderAsync(order))); const signedRightOrders = await Promise.all( @@ -2750,13 +2738,13 @@ blockchainTests.resets.only('matchOrders', env => { describe('token sanity checks', () => { it('should be able to match ERC721 tokens with ERC1155 tokens', async () => { - const leftMakerAssetData = assetDataUtils.encodeERC1155AssetData( + const leftMakerAssetData = assetDataEncoder.ERC1155Assets.getABIEncodedTransactionData( deployment.tokens.erc1155[0].address, [leftId], [new BigNumber(1)], '0x', ); - const rightMakerAssetData = assetDataUtils.encodeERC721AssetData( + const rightMakerAssetData = assetDataEncoder.ERC721Token.getABIEncodedTransactionData( deployment.tokens.erc721[0].address, rightId, ); diff --git a/contracts/integrations/test/utils/match_order_tester.ts b/contracts/integrations/test/utils/match_order_tester.ts index e3d18ffe62..03cb675f43 100644 --- a/contracts/integrations/test/utils/match_order_tester.ts +++ b/contracts/integrations/test/utils/match_order_tester.ts @@ -1,3 +1,4 @@ +import { IAssetDataContract } from '@0x/contracts-asset-proxy'; import { DevUtilsContract } from '@0x/contracts-dev-utils'; import { BlockchainBalanceStore, ExchangeContract, LocalBalanceStore } from '@0x/contracts-exchange'; import { constants, expect, OrderStatus } from '@0x/contracts-test-utils'; @@ -73,9 +74,10 @@ export class MatchOrderTester { * Constructs new MatchOrderTester. */ constructor( - private readonly _deployment: DeploymentManager, - private readonly _devUtils: DevUtilsContract, - private readonly _blockchainBalanceStore: BlockchainBalanceStore, + protected readonly _assetDataEncoder: IAssetDataContract, + protected readonly _deployment: DeploymentManager, + protected readonly _devUtils: DevUtilsContract, + protected readonly _blockchainBalanceStore: BlockchainBalanceStore, ) {} /** @@ -147,7 +149,7 @@ export class MatchOrderTester { localBalanceStore, matchPairs, expectedTransferAmounts, - this._devUtils, + this._assetDataEncoder, ); const expectedResults = convertToBatchMatchResults(expectedBatchMatchResults); @@ -219,7 +221,7 @@ export class MatchOrderTester { takerAddress, this._deployment, toFullMatchTransferAmounts(expectedTransferAmounts), - this._devUtils, + this._assetDataEncoder, this._blockchainBalanceStore, localBalanceStore, ); @@ -300,7 +302,7 @@ async function simulateBatchMatchOrdersAsync( localBalanceStore: LocalBalanceStore, matchPairs: Array<[number, number]>, transferAmounts: Array>, - devUtils: DevUtilsContract, + assetDataEncoder: IAssetDataContract, ): Promise { // Initialize variables let leftIdx = 0; @@ -362,7 +364,7 @@ async function simulateBatchMatchOrdersAsync( takerAddress, deployment, toFullMatchTransferAmounts(transferAmounts[i]), - devUtils, + assetDataEncoder, blockchainBalanceStore, localBalanceStore, ), @@ -425,7 +427,7 @@ async function simulateMatchOrdersAsync( takerAddress: string, deployment: DeploymentManager, transferAmounts: MatchTransferAmounts, - devUtils: DevUtilsContract, + assetDataEncoder: IAssetDataContract, blockchainBalanceStore: BlockchainBalanceStore, localBalanceStore: LocalBalanceStore, ): Promise { @@ -515,7 +517,7 @@ async function simulateMatchOrdersAsync( ); // Protocol Fee - const wethAssetData = await devUtils.encodeERC20AssetData.callAsync(deployment.tokens.weth.address); + const wethAssetData = assetDataEncoder.ERC20Token.getABIEncodedTransactionData(deployment.tokens.weth.address); localBalanceStore.sendEth( takerAddress, deployment.staking.stakingProxy.address,