Move exchange specific types. constants, and utils into exchange package
This commit is contained in:
parent
d373f5488a
commit
72f4b216c1
35
contracts/exchange/test/utils/constants.ts
Normal file
35
contracts/exchange/test/utils/constants.ts
Normal file
@ -0,0 +1,35 @@
|
||||
import { ExchangeFunctionName } from './types';
|
||||
|
||||
export const constants = {
|
||||
FUNCTIONS_WITH_MUTEX: [
|
||||
'FILL_ORDER',
|
||||
'FILL_OR_KILL_ORDER',
|
||||
'BATCH_FILL_ORDERS',
|
||||
'BATCH_FILL_OR_KILL_ORDERS',
|
||||
'MARKET_BUY_ORDERS',
|
||||
'MARKET_SELL_ORDERS',
|
||||
'MATCH_ORDERS',
|
||||
'CANCEL_ORDER',
|
||||
'BATCH_CANCEL_ORDERS',
|
||||
'CANCEL_ORDERS_UP_TO',
|
||||
'PRE_SIGN',
|
||||
'SET_SIGNATURE_VALIDATOR_APPROVAL',
|
||||
'SET_ORDER_VALIDATOR_APPROVAL',
|
||||
],
|
||||
SINGLE_FILL_FN_NAMES: [
|
||||
ExchangeFunctionName.FillOrder,
|
||||
ExchangeFunctionName.FillOrKillOrder,
|
||||
ExchangeFunctionName.FillOrderNoThrow,
|
||||
],
|
||||
BATCH_FILL_FN_NAMES: [
|
||||
ExchangeFunctionName.BatchFillOrders,
|
||||
ExchangeFunctionName.BatchFillOrKillOrders,
|
||||
ExchangeFunctionName.BatchFillOrdersNoThrow,
|
||||
],
|
||||
MARKET_FILL_FN_NAMES: [
|
||||
ExchangeFunctionName.MarketBuyOrders,
|
||||
ExchangeFunctionName.MarketBuyOrdersNoThrow,
|
||||
ExchangeFunctionName.MarketSellOrders,
|
||||
ExchangeFunctionName.MarketSellOrdersNoThrow,
|
||||
],
|
||||
};
|
@ -1,44 +1,56 @@
|
||||
import { IExchangeContract } from '@0x/contracts-exchange';
|
||||
import { constants as devConstants, provider } from '@0x/contracts-test-utils';
|
||||
import { constants, provider } from '@0x/contracts-test-utils';
|
||||
import { orderHashUtils } from '@0x/order-utils';
|
||||
import { SignedOrder } from '@0x/types';
|
||||
|
||||
import { constants, provider } from './index';
|
||||
import { constants as exchangeConstants, ExchangeFunctionName, IExchangeContract } from '../../src';
|
||||
|
||||
export const exchangeDataEncoder = {
|
||||
encodeOrdersToExchangeData(fnName: string, orders: SignedOrder[] = []): string {
|
||||
const exchangeInstance = new IExchangeContract(devConstants.NULL_ADDRESS, provider);
|
||||
const exchangeInstance = new IExchangeContract(constants.NULL_ADDRESS, provider);
|
||||
let data;
|
||||
if (constants.SINGLE_FILL_FN_NAMES.indexOf(fnName) !== -1) {
|
||||
if (exchangeConstants.SINGLE_FILL_FN_NAMES.indexOf(fnName) !== -1) {
|
||||
data = (exchangeInstance as any)[fnName].getABIEncodedTransactionData(
|
||||
orders[0],
|
||||
orders[0].takerAssetAmount,
|
||||
orders[0].signature,
|
||||
);
|
||||
} else if (constants.BATCH_FILL_FN_NAMES.indexOf(fnName) !== -1) {
|
||||
} else if (exchangeConstants.BATCH_FILL_FN_NAMES.indexOf(fnName) !== -1) {
|
||||
data = (exchangeInstance as any)[fnName].getABIEncodedTransactionData(
|
||||
orders,
|
||||
orders.map(order => order.takerAssetAmount),
|
||||
orders.map(order => order.signature),
|
||||
);
|
||||
} else if (constants.MARKET_FILL_FN_NAMES.indexOf(fnName) !== -1) {
|
||||
} else if (exchangeConstants.MARKET_FILL_FN_NAMES.indexOf(fnName) !== -1) {
|
||||
data = (exchangeInstance as any)[fnName].getABIEncodedTransactionData(
|
||||
orders,
|
||||
orders.map(order => order.takerAssetAmount).reduce((prev, curr) => prev.plus(curr)),
|
||||
orders.map(order => order.signature),
|
||||
);
|
||||
} else if (fnName === constants.MATCH_ORDERS) {
|
||||
} else if (fnName === ExchangeFunctionName.MatchOrders) {
|
||||
data = exchangeInstance.matchOrders.getABIEncodedTransactionData(
|
||||
orders[0],
|
||||
orders[1],
|
||||
orders[0].signature,
|
||||
orders[1].signature,
|
||||
);
|
||||
} else if (fnName === constants.CANCEL_ORDER) {
|
||||
} else if (fnName === ExchangeFunctionName.CancelOrder) {
|
||||
data = exchangeInstance.cancelOrder.getABIEncodedTransactionData(orders[0]);
|
||||
} else if (fnName === constants.BATCH_CANCEL_ORDERS) {
|
||||
} else if (fnName === ExchangeFunctionName.BatchCancelOrders) {
|
||||
data = exchangeInstance.batchCancelOrders.getABIEncodedTransactionData(orders);
|
||||
} else if (fnName === constants.CANCEL_ORDERS_UP_TO) {
|
||||
} else if (fnName === ExchangeFunctionName.CancelOrdersUpTo) {
|
||||
data = exchangeInstance.cancelOrdersUpTo.getABIEncodedTransactionData(constants.ZERO_AMOUNT);
|
||||
} else if (fnName === ExchangeFunctionName.PreSign) {
|
||||
data = exchangeInstance.preSign.getABIEncodedTransactionData(orderHashUtils.getOrderHashHex(orders[0]));
|
||||
} else if (fnName === ExchangeFunctionName.SetSignatureValidatorApproval) {
|
||||
data = exchangeInstance.setSignatureValidatorApproval.getABIEncodedTransactionData(
|
||||
constants.NULL_ADDRESS,
|
||||
true,
|
||||
);
|
||||
} else if (fnName === ExchangeFunctionName.SetOrderValidatorApproval) {
|
||||
// data = exchangeInstance.setOrderValidatorApproval.getABIEncodedTransactionData(
|
||||
// constants.NULL_ADDRESS,
|
||||
// true,
|
||||
// );
|
||||
} else {
|
||||
throw new Error(`Error: ${fnName} not a supported function`);
|
||||
}
|
@ -1,3 +1,6 @@
|
||||
export * from './exchange_wrapper';
|
||||
export * from './fill_order_combinatorial_utils';
|
||||
export * from './match_order_tester';
|
||||
export * from './exchange_data_encoder';
|
||||
export * from './types';
|
||||
export * from './constants';
|
||||
|
@ -6,3 +6,23 @@ export interface AbiDecodedFillOrderData {
|
||||
takerAssetFillAmount: BigNumber;
|
||||
signature: string;
|
||||
}
|
||||
|
||||
export enum ExchangeFunctionName {
|
||||
FillOrder = 'fillOrder',
|
||||
FillOrKillOrder = 'fillOrKillOrder',
|
||||
FillOrderNoThrow = 'fillOrderNoThrow',
|
||||
BatchFillOrders = 'batchFillOrders',
|
||||
BatchFillOrKillOrders = 'batchFillOrKillOrders',
|
||||
BatchFillOrdersNoThrow = 'batchFillOrdersNoThrow',
|
||||
MarketBuyOrders = 'marketBuyOrders',
|
||||
MarketBuyOrdersNoThrow = 'marketBuyOrdersNoThrow',
|
||||
MarketSellOrders = 'marketSellOrders',
|
||||
MarketSellOrdersNoThrow = 'marketSellOrdersNoThrow',
|
||||
MatchOrders = 'matchOrders',
|
||||
CancelOrder = 'cancelOrder',
|
||||
BatchCancelOrders = 'batchCancelOrders',
|
||||
CancelOrdersUpTo = 'cancelOrdersUpTo',
|
||||
PreSign = 'preSign',
|
||||
SetSignatureValidatorApproval = 'setSignatureValidatorApproval',
|
||||
SetOrderValidatorApproval = 'setOrderValidatorApproval',
|
||||
}
|
||||
|
@ -57,26 +57,5 @@ export const constants = {
|
||||
WORD_LENGTH: 32,
|
||||
ZERO_AMOUNT: new BigNumber(0),
|
||||
PERCENTAGE_DENOMINATOR: new BigNumber(10).pow(18),
|
||||
FUNCTIONS_WITH_MUTEX: [
|
||||
'FILL_ORDER',
|
||||
'FILL_OR_KILL_ORDER',
|
||||
'BATCH_FILL_ORDERS',
|
||||
'BATCH_FILL_OR_KILL_ORDERS',
|
||||
'MARKET_BUY_ORDERS',
|
||||
'MARKET_SELL_ORDERS',
|
||||
'MATCH_ORDERS',
|
||||
'CANCEL_ORDER',
|
||||
'BATCH_CANCEL_ORDERS',
|
||||
'CANCEL_ORDERS_UP_TO',
|
||||
'SET_SIGNATURE_VALIDATOR_APPROVAL',
|
||||
],
|
||||
KECCAK256_NULL: ethUtil.addHexPrefix(ethUtil.bufferToHex(ethUtil.SHA3_NULL)),
|
||||
SINGLE_FILL_FN_NAMES: ['fillOrder', 'fillOrKillOrder', 'fillOrderNoThrow'],
|
||||
BATCH_FILL_FN_NAMES: ['batchFillOrders', 'batchFillOrKillOrders', 'batchFillOrdersNoThrow'],
|
||||
MARKET_FILL_FN_NAMES: ['marketBuyOrders', 'marketBuyOrdersNoThrow', 'marketSellOrders', 'marketSellOrdersNoThrow'],
|
||||
MATCH_ORDERS: 'matchOrders',
|
||||
CANCEL_ORDER: 'cancelOrder',
|
||||
BATCH_CANCEL_ORDERS: 'batchCancelOrders',
|
||||
CANCEL_ORDERS_UP_TO: 'cancelOrdersUpTo',
|
||||
TIME_BUFFER: new BigNumber(1000),
|
||||
};
|
||||
|
@ -28,7 +28,6 @@ export { OrderFactory } from './order_factory';
|
||||
export { bytes32Values, testCombinatoriallyWithReferenceFuncAsync, uint256Values } from './combinatorial_utils';
|
||||
export { TransactionFactory } from './transaction_factory';
|
||||
export { testWithReferenceFuncAsync } from './test_with_reference';
|
||||
export { exchangeDataEncoder } from './exchange_data_encoder';
|
||||
export {
|
||||
MarketBuyOrders,
|
||||
MarketSellOrders,
|
||||
|
Loading…
x
Reference in New Issue
Block a user