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