Minor fixes to order matching fuzz code
This commit is contained in:
parent
06669594b1
commit
46275a4f43
@ -54,7 +54,6 @@
|
|||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@0x/abi-gen": "^5.0.3",
|
"@0x/abi-gen": "^5.0.3",
|
||||||
"@0x/contracts-gen": "^2.0.3",
|
"@0x/contracts-gen": "^2.0.3",
|
||||||
"@0x/contracts-test-utils": "^5.1.0",
|
|
||||||
"@0x/dev-utils": "^3.1.0",
|
"@0x/dev-utils": "^3.1.0",
|
||||||
"@0x/sol-compiler": "^4.0.3",
|
"@0x/sol-compiler": "^4.0.3",
|
||||||
"@0x/subproviders": "^6.0.3",
|
"@0x/subproviders": "^6.0.3",
|
||||||
@ -82,6 +81,7 @@
|
|||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@0x/base-contract": "^6.0.3",
|
"@0x/base-contract": "^6.0.3",
|
||||||
|
"@0x/contracts-test-utils": "^5.1.0",
|
||||||
"@0x/contracts-utils": "^4.0.3",
|
"@0x/contracts-utils": "^4.0.3",
|
||||||
"@0x/order-utils": "^10.1.0",
|
"@0x/order-utils": "^10.1.0",
|
||||||
"@0x/types": "^3.1.1",
|
"@0x/types": "^3.1.1",
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
|
import { orderHashUtils } from '@0x/contracts-test-utils';
|
||||||
import { ReferenceFunctions } from '@0x/contracts-utils';
|
import { ReferenceFunctions } from '@0x/contracts-utils';
|
||||||
import { FillResults, MatchedFillResults, Order } from '@0x/types';
|
import { FillResults, MatchedFillResults, Order } from '@0x/types';
|
||||||
import { BigNumber, LibMathRevertErrors } from '@0x/utils';
|
import { BigNumber, ExchangeRevertErrors, LibMathRevertErrors } from '@0x/utils';
|
||||||
|
|
||||||
const { safeAdd, safeSub, safeMul, safeDiv } = ReferenceFunctions;
|
const { safeAdd, safeSub, safeMul, safeDiv } = ReferenceFunctions;
|
||||||
|
|
||||||
@ -148,20 +149,19 @@ export function calculateMatchResults(
|
|||||||
.times(rightOrder.makerAssetAmount)
|
.times(rightOrder.makerAssetAmount)
|
||||||
.lt(leftOrder.takerAssetAmount.times(rightOrder.takerAssetAmount))
|
.lt(leftOrder.takerAssetAmount.times(rightOrder.takerAssetAmount))
|
||||||
) {
|
) {
|
||||||
throw new Error(
|
throw new ExchangeRevertErrors.NegativeSpreadError(
|
||||||
`Orders Cannot Be Matched.\nLeft Order: ${JSON.stringify(leftOrder, null, 4)}\Right Order: ${JSON.stringify(
|
orderHashUtils.getOrderHashHex(leftOrder),
|
||||||
rightOrder,
|
orderHashUtils.getOrderHashHex(rightOrder),
|
||||||
null,
|
|
||||||
4,
|
|
||||||
)}`,
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Asset Transfer Amounts
|
// Asset Transfer Amounts
|
||||||
if (leftOrder.takerAssetAmount.gt(rightOrder.makerAssetAmount)) {
|
if (leftOrder.takerAssetAmount.gt(rightOrder.makerAssetAmount)) {
|
||||||
leftFillResults.makerAssetFilledAmount = leftOrder.makerAssetAmount
|
leftFillResults.makerAssetFilledAmount = safeGetPartialAmountFloor(
|
||||||
.multipliedBy(rightOrder.makerAssetAmount)
|
leftOrder.makerAssetAmount,
|
||||||
.dividedToIntegerBy(leftOrder.takerAssetAmount);
|
leftOrder.takerAssetAmount,
|
||||||
|
rightOrder.makerAssetAmount,
|
||||||
|
);
|
||||||
leftFillResults.takerAssetFilledAmount = rightOrder.makerAssetAmount;
|
leftFillResults.takerAssetFilledAmount = rightOrder.makerAssetAmount;
|
||||||
rightFillResults.makerAssetFilledAmount = rightOrder.makerAssetAmount;
|
rightFillResults.makerAssetFilledAmount = rightOrder.makerAssetAmount;
|
||||||
rightFillResults.takerAssetFilledAmount = rightOrder.takerAssetAmount;
|
rightFillResults.takerAssetFilledAmount = rightOrder.takerAssetAmount;
|
||||||
|
@ -99,7 +99,7 @@ export function MakerMixin<TBase extends Constructor>(Base: TBase): TBase & Cons
|
|||||||
);
|
);
|
||||||
|
|
||||||
// Maker and taker set balances/allowances to guarantee that the fill succeeds.
|
// Maker and taker set balances/allowances to guarantee that the fill succeeds.
|
||||||
// Amounts are chosen to be within each actor's balance (divided by 2, in case
|
// Amounts are chosen to be within each actor's balance (divided by 8, in case
|
||||||
// e.g. makerAsset = makerFeeAsset)
|
// e.g. makerAsset = makerFeeAsset)
|
||||||
const [makerAssetAmount, makerFee, takerAssetAmount, takerFee] = await Promise.all(
|
const [makerAssetAmount, makerFee, takerAssetAmount, takerFee] = await Promise.all(
|
||||||
[
|
[
|
||||||
|
@ -79,7 +79,6 @@ export function TakerMixin<TBase extends Constructor>(Base: TBase): TBase & Cons
|
|||||||
.matchOrders(leftOrder, rightOrder, leftOrder.signature, rightOrder.signature)
|
.matchOrders(leftOrder, rightOrder, leftOrder.signature, rightOrder.signature)
|
||||||
.awaitTransactionSuccessAsync({
|
.awaitTransactionSuccessAsync({
|
||||||
from: this.actor.address,
|
from: this.actor.address,
|
||||||
gasPrice: DeploymentManager.gasPrice,
|
|
||||||
value: DeploymentManager.protocolFee,
|
value: DeploymentManager.protocolFee,
|
||||||
...txData,
|
...txData,
|
||||||
});
|
});
|
||||||
@ -97,7 +96,6 @@ export function TakerMixin<TBase extends Constructor>(Base: TBase): TBase & Cons
|
|||||||
.matchOrdersWithMaximalFill(leftOrder, rightOrder, leftOrder.signature, rightOrder.signature)
|
.matchOrdersWithMaximalFill(leftOrder, rightOrder, leftOrder.signature, rightOrder.signature)
|
||||||
.awaitTransactionSuccessAsync({
|
.awaitTransactionSuccessAsync({
|
||||||
from: this.actor.address,
|
from: this.actor.address,
|
||||||
gasPrice: DeploymentManager.gasPrice,
|
|
||||||
value: DeploymentManager.protocolFee,
|
value: DeploymentManager.protocolFee,
|
||||||
...txData,
|
...txData,
|
||||||
});
|
});
|
||||||
|
@ -3,7 +3,6 @@ import { TxData } from 'ethereum-types';
|
|||||||
import * as _ from 'lodash';
|
import * as _ from 'lodash';
|
||||||
|
|
||||||
import { Maker } from '../actors/maker';
|
import { Maker } from '../actors/maker';
|
||||||
import { filterActorsByRole } from '../actors/utils';
|
|
||||||
import { DeploymentManager } from '../deployment_manager';
|
import { DeploymentManager } from '../deployment_manager';
|
||||||
import { SimulationEnvironment } from '../simulation';
|
import { SimulationEnvironment } from '../simulation';
|
||||||
import { assertProtocolFeePaidAsync, getPoolInfoAsync, PoolInfo } from '../utils/assert_protocol_fee';
|
import { assertProtocolFeePaidAsync, getPoolInfoAsync, PoolInfo } from '../utils/assert_protocol_fee';
|
||||||
@ -11,7 +10,7 @@ import { verifyMatchEvents } from '../utils/verify_match_events';
|
|||||||
|
|
||||||
import { FunctionAssertion, FunctionResult } from './function_assertion';
|
import { FunctionAssertion, FunctionResult } from './function_assertion';
|
||||||
|
|
||||||
export const matchOrderRuntimeAssertion = (
|
export const matchOrdersRuntimeAssertion = (
|
||||||
deployment: DeploymentManager,
|
deployment: DeploymentManager,
|
||||||
simulationEnvironment: SimulationEnvironment,
|
simulationEnvironment: SimulationEnvironment,
|
||||||
withMaximalFill: boolean,
|
withMaximalFill: boolean,
|
||||||
@ -22,9 +21,9 @@ export const matchOrderRuntimeAssertion = (
|
|||||||
return {
|
return {
|
||||||
before: async (args: [Order, Order, string, string]) => {
|
before: async (args: [Order, Order, string, string]) => {
|
||||||
const [order] = args;
|
const [order] = args;
|
||||||
const maker = filterActorsByRole(actors, Maker).find(actor => actor.address === order.makerAddress);
|
// tslint:disable-next-line no-unnecessary-type-assertion
|
||||||
// tslint:disable-next-line no-non-null-assertion
|
const maker = actors.find(actor => actor.address === order.makerAddress) as Maker;
|
||||||
const poolInfo = getPoolInfoAsync(maker!, simulationEnvironment, deployment);
|
const poolInfo = getPoolInfoAsync(maker, simulationEnvironment, deployment);
|
||||||
return poolInfo;
|
return poolInfo;
|
||||||
},
|
},
|
||||||
after: async (
|
after: async (
|
||||||
@ -72,7 +71,7 @@ export function validMatchOrdersAssertion(
|
|||||||
return new FunctionAssertion<[Order, Order, string, string], PoolInfo | void, MatchedFillResults>(
|
return new FunctionAssertion<[Order, Order, string, string], PoolInfo | void, MatchedFillResults>(
|
||||||
deployment.exchange,
|
deployment.exchange,
|
||||||
'matchOrders',
|
'matchOrders',
|
||||||
matchOrderRuntimeAssertion(deployment, simulationEnvironment, false),
|
matchOrdersRuntimeAssertion(deployment, simulationEnvironment, false),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
/* tslint:enable:no-non-null-assertion */
|
/* tslint:enable:no-non-null-assertion */
|
||||||
|
@ -6,7 +6,7 @@ import { SimulationEnvironment } from '../simulation';
|
|||||||
import { PoolInfo } from '../utils/assert_protocol_fee';
|
import { PoolInfo } from '../utils/assert_protocol_fee';
|
||||||
|
|
||||||
import { FunctionAssertion } from './function_assertion';
|
import { FunctionAssertion } from './function_assertion';
|
||||||
import { matchOrderRuntimeAssertion } from './matchOrders';
|
import { matchOrdersRuntimeAssertion } from './matchOrders';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A function assertion that verifies that a complete and valid `matchOrdersWithMaximalFill` succeeded and emitted the correct logs.
|
* A function assertion that verifies that a complete and valid `matchOrdersWithMaximalFill` succeeded and emitted the correct logs.
|
||||||
@ -20,7 +20,7 @@ export function validMatchOrdersWithMaximalFillAssertion(
|
|||||||
return new FunctionAssertion<[Order, Order, string, string], PoolInfo | void, MatchedFillResults>(
|
return new FunctionAssertion<[Order, Order, string, string], PoolInfo | void, MatchedFillResults>(
|
||||||
deployment.exchange,
|
deployment.exchange,
|
||||||
'matchOrdersWithMaximalFill',
|
'matchOrdersWithMaximalFill',
|
||||||
matchOrderRuntimeAssertion(deployment, simulationEnvironment, true),
|
matchOrdersRuntimeAssertion(deployment, simulationEnvironment, true),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
/* tslint:enable:no-non-null-assertion */
|
/* tslint:enable:no-non-null-assertion */
|
||||||
|
@ -34,7 +34,7 @@ export async function getPoolInfoAsync(
|
|||||||
): Promise<PoolInfo | undefined> {
|
): Promise<PoolInfo | undefined> {
|
||||||
const { stakingWrapper } = deployment.staking;
|
const { stakingWrapper } = deployment.staking;
|
||||||
// tslint:disable-next-line no-non-null-assertion no-unnecessary-type-assertion
|
// tslint:disable-next-line no-non-null-assertion no-unnecessary-type-assertion
|
||||||
const poolId = maker!.makerPoolId;
|
const poolId = maker.makerPoolId;
|
||||||
const { currentEpoch } = simulationEnvironment;
|
const { currentEpoch } = simulationEnvironment;
|
||||||
if (poolId === undefined) {
|
if (poolId === undefined) {
|
||||||
return;
|
return;
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import { ERC20TokenEvents, ERC20TokenTransferEventArgs } from '@0x/contracts-erc20';
|
import { ERC20TokenEvents, ERC20TokenTransferEventArgs } from '@0x/contracts-erc20';
|
||||||
import { ExchangeEvents, ExchangeFillEventArgs } from '@0x/contracts-exchange';
|
import { ExchangeEvents, ExchangeFillEventArgs } from '@0x/contracts-exchange';
|
||||||
import { ReferenceFunctions } from '@0x/contracts-exchange-libs';
|
import { ReferenceFunctions } from '@0x/contracts-exchange-libs';
|
||||||
import { orderHashUtils, verifyEvents } from '@0x/contracts-test-utils';
|
import { constants, orderHashUtils, verifyEvents } from '@0x/contracts-test-utils';
|
||||||
import { MatchedFillResults, Order } from '@0x/types';
|
import { MatchedFillResults, Order } from '@0x/types';
|
||||||
import { BigNumber } from '@0x/utils';
|
import { BigNumber } from '@0x/utils';
|
||||||
import { TransactionReceiptWithDecodedLogs, TxData } from 'ethereum-types';
|
import { TransactionReceiptWithDecodedLogs, TxData } from 'ethereum-types';
|
||||||
@ -122,7 +122,7 @@ const verifyMatchTransferEvents = (
|
|||||||
_to: deployment.staking.stakingProxy.address,
|
_to: deployment.staking.stakingProxy.address,
|
||||||
_value: value.isLessThan(DeploymentManager.protocolFee.times(2))
|
_value: value.isLessThan(DeploymentManager.protocolFee.times(2))
|
||||||
? DeploymentManager.protocolFee
|
? DeploymentManager.protocolFee
|
||||||
: new BigNumber(0),
|
: constants.ZERO_AMOUNT,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
_from: takerAddress,
|
_from: takerAddress,
|
||||||
@ -134,7 +134,7 @@ const verifyMatchTransferEvents = (
|
|||||||
_to: rightOrder.feeRecipientAddress,
|
_to: rightOrder.feeRecipientAddress,
|
||||||
_value:
|
_value:
|
||||||
leftOrder.feeRecipientAddress === rightOrder.feeRecipientAddress
|
leftOrder.feeRecipientAddress === rightOrder.feeRecipientAddress
|
||||||
? new BigNumber(0)
|
? constants.ZERO_AMOUNT
|
||||||
: matchResults.right.takerFeePaid,
|
: matchResults.right.takerFeePaid,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user