Use enums in pipeline
This commit is contained in:
parent
24564b986d
commit
fd37e88bdb
@ -4,7 +4,7 @@
|
||||
"changes": [
|
||||
{
|
||||
"note":
|
||||
"Export `MultiAssetData`, `MultiAssetDataWithRecursiveDecoding`, `ObjectMap`, and `SingleAssetData` from types. No longer export AssetData.",
|
||||
"Export `MultiAssetData`, `MultiAssetDataWithRecursiveDecoding`, `ObjectMap`, and `SingleAssetData` from types. No longer export `AssetData`.",
|
||||
"pr": 1363
|
||||
}
|
||||
]
|
||||
|
@ -6,7 +6,7 @@
|
||||
"note": "Add support for Trust Wallet signature denial error"
|
||||
},
|
||||
{
|
||||
"note": "Add balance and allowance queries for MultiAssetProxy",
|
||||
"note": "Add balance and allowance queries for `MultiAssetProxy`",
|
||||
"pr": 1363
|
||||
}
|
||||
]
|
||||
|
@ -76,7 +76,7 @@ export const assetDataUtils = {
|
||||
/**
|
||||
* Encodes assetData for multiple AssetProxies into a single hex encoded assetData string, usable in the makerAssetData or
|
||||
* takerAssetData fields in a 0x order.
|
||||
* @param amounts Amounts of each asset that correspond to a ginle unit within an order.
|
||||
* @param amounts Amounts of each asset that correspond to a single unit within an order.
|
||||
* @param nestedAssetData assetData strings that correspond to a valid assetProxyId.
|
||||
* @return The hex encoded assetData string
|
||||
*/
|
||||
|
@ -3,7 +3,7 @@
|
||||
"version": "2.4.0",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Add support for MultiAssetProxy",
|
||||
"note": "Add support for `MultiAssetProxy`",
|
||||
"pr": 1363
|
||||
}
|
||||
]
|
||||
|
@ -487,4 +487,4 @@ export class OrderWatcher {
|
||||
this._callbackIfExists(null, orderState);
|
||||
}
|
||||
}
|
||||
} // tslint:disable:max-file-line-count
|
||||
}
|
||||
|
@ -859,29 +859,29 @@ describe('OrderWatcher', () => {
|
||||
})().catch(done);
|
||||
});
|
||||
// TODO(abandeali1): The following test will fail until the MAP has been deployed and activated.
|
||||
// it('should emit orderStateInvalid when watched order fully filled', (done: DoneCallback) => {
|
||||
// (async () => {
|
||||
// signedOrder = await fillScenarios.createFillableSignedOrderAsync(
|
||||
// makerMultiAssetData,
|
||||
// takerAssetData,
|
||||
// makerAddress,
|
||||
// takerAddress,
|
||||
// fillableAmount,
|
||||
// );
|
||||
// const orderHash = orderHashUtils.getOrderHashHex(signedOrder);
|
||||
// await orderWatcher.addOrderAsync(signedOrder);
|
||||
it.skip('should emit orderStateInvalid when watched order fully filled', (done: DoneCallback) => {
|
||||
(async () => {
|
||||
signedOrder = await fillScenarios.createFillableSignedOrderAsync(
|
||||
makerMultiAssetData,
|
||||
takerAssetData,
|
||||
makerAddress,
|
||||
takerAddress,
|
||||
fillableAmount,
|
||||
);
|
||||
const orderHash = orderHashUtils.getOrderHashHex(signedOrder);
|
||||
await orderWatcher.addOrderAsync(signedOrder);
|
||||
|
||||
// const callback = callbackErrorReporter.reportNodeCallbackErrors(done)((orderState: OrderState) => {
|
||||
// expect(orderState.isValid).to.be.false();
|
||||
// const invalidOrderState = orderState as OrderStateInvalid;
|
||||
// expect(invalidOrderState.orderHash).to.be.equal(orderHash);
|
||||
// expect(invalidOrderState.error).to.be.equal(ExchangeContractErrs.OrderRemainingFillAmountZero);
|
||||
// });
|
||||
// orderWatcher.subscribe(callback);
|
||||
const callback = callbackErrorReporter.reportNodeCallbackErrors(done)((orderState: OrderState) => {
|
||||
expect(orderState.isValid).to.be.false();
|
||||
const invalidOrderState = orderState as OrderStateInvalid;
|
||||
expect(invalidOrderState.orderHash).to.be.equal(orderHash);
|
||||
expect(invalidOrderState.error).to.be.equal(ExchangeContractErrs.OrderRemainingFillAmountZero);
|
||||
});
|
||||
orderWatcher.subscribe(callback);
|
||||
|
||||
// await contractWrappers.exchange.fillOrderAsync(signedOrder, fillableAmount, takerAddress);
|
||||
// })().catch(done);
|
||||
// });
|
||||
await contractWrappers.exchange.fillOrderAsync(signedOrder, fillableAmount, takerAddress);
|
||||
})().catch(done);
|
||||
});
|
||||
});
|
||||
});
|
||||
}); // tslint:disable:max-file-line-count
|
||||
|
@ -1,7 +1,6 @@
|
||||
import { BigNumber } from '@0x/utils';
|
||||
import { Column, Entity, PrimaryColumn } from 'typeorm';
|
||||
|
||||
import { OrderType } from '../types';
|
||||
import { bigNumberTransformer, numberToBigIntTransformer } from '../utils';
|
||||
|
||||
@Entity({ name: 'token_orderbook_snapshots', schema: 'raw' })
|
||||
@ -11,7 +10,7 @@ export class TokenOrderbookSnapshot {
|
||||
@PrimaryColumn({ name: 'source' })
|
||||
public source!: string;
|
||||
@PrimaryColumn({ name: 'order_type' })
|
||||
public orderType!: OrderType;
|
||||
public orderType!: string;
|
||||
@PrimaryColumn({ name: 'price', type: 'numeric', transformer: bigNumberTransformer })
|
||||
public price!: BigNumber;
|
||||
@PrimaryColumn({ name: 'base_asset_symbol' })
|
||||
|
@ -23,8 +23,12 @@ export function parseDdexOrders(
|
||||
): TokenOrder[] {
|
||||
const aggregatedBids = aggregateOrders(ddexOrderbook.bids);
|
||||
const aggregatedAsks = aggregateOrders(ddexOrderbook.asks);
|
||||
const parsedBids = aggregatedBids.map(order => parseDdexOrder(ddexMarket, observedTimestamp, 'bid', source, order));
|
||||
const parsedAsks = aggregatedAsks.map(order => parseDdexOrder(ddexMarket, observedTimestamp, 'ask', source, order));
|
||||
const parsedBids = aggregatedBids.map(order =>
|
||||
parseDdexOrder(ddexMarket, observedTimestamp, OrderType.Bid, source, order),
|
||||
);
|
||||
const parsedAsks = aggregatedAsks.map(order =>
|
||||
parseDdexOrder(ddexMarket, observedTimestamp, OrderType.Ask, source, order),
|
||||
);
|
||||
return parsedBids.concat(parsedAsks);
|
||||
}
|
||||
|
||||
|
@ -2,7 +2,7 @@ import { BigNumber } from '@0x/utils';
|
||||
|
||||
import { aggregateOrders } from '../utils';
|
||||
|
||||
import { IdexOrder, IdexOrderbook, IdexOrderParam } from '../../data_sources/idex';
|
||||
import { IdexOrderbook, IdexOrderParam } from '../../data_sources/idex';
|
||||
import { TokenOrderbookSnapshot as TokenOrder } from '../../entities';
|
||||
import { OrderType } from '../../types';
|
||||
|
||||
@ -21,7 +21,9 @@ export function parseIdexOrders(idexOrderbook: IdexOrderbook, observedTimestamp:
|
||||
const idexBidOrder = idexOrderbook.bids[0];
|
||||
const parsedBids =
|
||||
aggregatedBids.length > 0
|
||||
? aggregatedBids.map(order => parseIdexOrder(idexBidOrder.params, observedTimestamp, 'bid', source, order))
|
||||
? aggregatedBids.map(order =>
|
||||
parseIdexOrder(idexBidOrder.params, observedTimestamp, OrderType.Bid, source, order),
|
||||
)
|
||||
: [];
|
||||
|
||||
const aggregatedAsks = aggregateOrders(idexOrderbook.asks);
|
||||
@ -29,7 +31,9 @@ export function parseIdexOrders(idexOrderbook: IdexOrderbook, observedTimestamp:
|
||||
const idexAskOrder = idexOrderbook.asks[0];
|
||||
const parsedAsks =
|
||||
aggregatedAsks.length > 0
|
||||
? aggregatedAsks.map(order => parseIdexOrder(idexAskOrder.params, observedTimestamp, 'ask', source, order))
|
||||
? aggregatedAsks.map(order =>
|
||||
parseIdexOrder(idexAskOrder.params, observedTimestamp, OrderType.Ask, source, order),
|
||||
)
|
||||
: [];
|
||||
return parsedBids.concat(parsedAsks);
|
||||
}
|
||||
@ -62,7 +66,7 @@ export function parseIdexOrder(
|
||||
tokenOrder.baseVolume = amount;
|
||||
tokenOrder.quoteVolume = price.times(amount);
|
||||
|
||||
if (orderType === 'bid') {
|
||||
if (orderType === OrderType.Bid) {
|
||||
tokenOrder.baseAssetSymbol = idexOrderParam.buySymbol;
|
||||
tokenOrder.baseAssetAddress = idexOrderParam.tokenBuy;
|
||||
tokenOrder.quoteAssetSymbol = idexOrderParam.sellSymbol;
|
||||
|
@ -23,13 +23,13 @@ export function parseOasisOrders(
|
||||
observedTimestamp: number,
|
||||
source: string,
|
||||
): TokenOrder[] {
|
||||
const aggregatedBids = aggregateOrders(R.filter(R.propEq('act', 'bid'), oasisOrderbook));
|
||||
const aggregatedAsks = aggregateOrders(R.filter(R.propEq('act', 'ask'), oasisOrderbook));
|
||||
const aggregatedBids = aggregateOrders(R.filter(R.propEq('act', OrderType.Bid), oasisOrderbook));
|
||||
const aggregatedAsks = aggregateOrders(R.filter(R.propEq('act', OrderType.Ask), oasisOrderbook));
|
||||
const parsedBids = aggregatedBids.map(order =>
|
||||
parseOasisOrder(oasisMarket, observedTimestamp, 'bid', source, order),
|
||||
parseOasisOrder(oasisMarket, observedTimestamp, OrderType.Bid, source, order),
|
||||
);
|
||||
const parsedAsks = aggregatedAsks.map(order =>
|
||||
parseOasisOrder(oasisMarket, observedTimestamp, 'ask', source, order),
|
||||
parseOasisOrder(oasisMarket, observedTimestamp, OrderType.Ask, source, order),
|
||||
);
|
||||
return parsedBids.concat(parsedAsks);
|
||||
}
|
||||
|
@ -21,10 +21,10 @@ export function parseParadexOrders(
|
||||
source: string,
|
||||
): TokenOrder[] {
|
||||
const parsedBids = paradexOrderbookResponse.bids.map(order =>
|
||||
parseParadexOrder(paradexMarket, observedTimestamp, 'bid', source, order),
|
||||
parseParadexOrder(paradexMarket, observedTimestamp, OrderType.Bid, source, order),
|
||||
);
|
||||
const parsedAsks = paradexOrderbookResponse.asks.map(order =>
|
||||
parseParadexOrder(paradexMarket, observedTimestamp, 'ask', source, order),
|
||||
parseParadexOrder(paradexMarket, observedTimestamp, OrderType.Ask, source, order),
|
||||
);
|
||||
return parsedBids.concat(parsedAsks);
|
||||
}
|
||||
|
@ -1,2 +1,9 @@
|
||||
export type AssetType = 'erc20' | 'erc721' | 'multiAsset';
|
||||
export type OrderType = 'bid' | 'ask';
|
||||
export enum AssetType {
|
||||
ERC20 = 'erc20',
|
||||
ERC721 = 'erc721',
|
||||
MultiAsset = 'multiAsset',
|
||||
}
|
||||
export enum OrderType {
|
||||
Bid = 'bid',
|
||||
Ask = 'ask',
|
||||
}
|
||||
|
@ -9,11 +9,11 @@ import { AssetType } from '../../types';
|
||||
export function convertAssetProxyIdToType(assetProxyId: AssetProxyId): AssetType {
|
||||
switch (assetProxyId) {
|
||||
case AssetProxyId.ERC20:
|
||||
return 'erc20';
|
||||
return AssetType.ERC20;
|
||||
case AssetProxyId.ERC721:
|
||||
return 'erc721';
|
||||
return AssetType.ERC721;
|
||||
case AssetProxyId.MultiAsset:
|
||||
return 'multiAsset';
|
||||
return AssetType.MultiAsset;
|
||||
default:
|
||||
throw new Error(`${assetProxyId} not a supported assetProxyId`);
|
||||
}
|
||||
|
@ -31,13 +31,13 @@ describe('ddex_orders', () => {
|
||||
amountDecimals: 0,
|
||||
};
|
||||
const observedTimestamp: number = Date.now();
|
||||
const orderType: OrderType = 'bid';
|
||||
const orderType: OrderType = OrderType.Bid;
|
||||
const source: string = 'ddex';
|
||||
|
||||
const expected = new TokenOrder();
|
||||
expected.source = 'ddex';
|
||||
expected.observedTimestamp = observedTimestamp;
|
||||
expected.orderType = 'bid';
|
||||
expected.orderType = OrderType.Bid;
|
||||
expected.price = new BigNumber(0.5);
|
||||
// ddex currently confuses base and quote assets.
|
||||
// Switch them to maintain our internal consistency.
|
||||
|
@ -6,6 +6,7 @@ import 'mocha';
|
||||
|
||||
import { ExchangeFillEvent } from '../../../src/entities';
|
||||
import { _convertToExchangeFillEvent } from '../../../src/parsers/events/exchange_events';
|
||||
import { AssetType } from '../../../src/types';
|
||||
import { chaiSetup } from '../../utils/chai_setup';
|
||||
|
||||
chaiSetup.configure();
|
||||
@ -62,12 +63,12 @@ describe('exchange_events', () => {
|
||||
expected.takerFeePaid = new BigNumber('12345');
|
||||
expected.orderHash = '0xab12ed2cbaa5615ab690b9da75a46e53ddfcf3f1a68655b5fe0d94c75a1aac4a';
|
||||
expected.rawMakerAssetData = '0xf47261b0000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2';
|
||||
expected.makerAssetType = 'erc20';
|
||||
expected.makerAssetType = AssetType.ERC20;
|
||||
expected.makerAssetProxyId = '0xf47261b0';
|
||||
expected.makerTokenAddress = '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2';
|
||||
expected.makerTokenId = null;
|
||||
expected.rawTakerAssetData = '0xf47261b0000000000000000000000000e41d2489571d322189246dafa5ebde1f4699f498';
|
||||
expected.takerAssetType = 'erc20';
|
||||
expected.takerAssetType = AssetType.ERC20;
|
||||
expected.takerAssetProxyId = '0xf47261b0';
|
||||
expected.takerTokenAddress = '0xe41d2489571d322189246dafa5ebde1f4699f498';
|
||||
expected.takerTokenId = null;
|
||||
|
@ -31,13 +31,13 @@ describe('idex_orders', () => {
|
||||
user: '0x212345667543456435324564345643453453333',
|
||||
};
|
||||
const observedTimestamp: number = Date.now();
|
||||
const orderType: OrderType = 'bid';
|
||||
const orderType: OrderType = OrderType.Bid;
|
||||
const source: string = 'idex';
|
||||
|
||||
const expected = new TokenOrder();
|
||||
expected.source = 'idex';
|
||||
expected.observedTimestamp = observedTimestamp;
|
||||
expected.orderType = 'bid';
|
||||
expected.orderType = OrderType.Bid;
|
||||
expected.price = new BigNumber(0.5);
|
||||
expected.baseAssetSymbol = 'ABC';
|
||||
expected.baseAssetAddress = '0x0000000000000000000000000000000000000000';
|
||||
@ -65,13 +65,13 @@ describe('idex_orders', () => {
|
||||
user: '0x212345667543456435324564345643453453333',
|
||||
};
|
||||
const observedTimestamp: number = Date.now();
|
||||
const orderType: OrderType = 'ask';
|
||||
const orderType: OrderType = OrderType.Ask;
|
||||
const source: string = 'idex';
|
||||
|
||||
const expected = new TokenOrder();
|
||||
expected.source = 'idex';
|
||||
expected.observedTimestamp = observedTimestamp;
|
||||
expected.orderType = 'ask';
|
||||
expected.orderType = OrderType.Ask;
|
||||
expected.price = new BigNumber(0.5);
|
||||
expected.baseAssetSymbol = 'ABC';
|
||||
expected.baseAssetAddress = '0x0000000000000000000000000000000000000000';
|
||||
|
@ -27,13 +27,13 @@ describe('oasis_orders', () => {
|
||||
low: 0,
|
||||
};
|
||||
const observedTimestamp: number = Date.now();
|
||||
const orderType: OrderType = 'bid';
|
||||
const orderType: OrderType = OrderType.Bid;
|
||||
const source: string = 'oasis';
|
||||
|
||||
const expected = new TokenOrder();
|
||||
expected.source = 'oasis';
|
||||
expected.observedTimestamp = observedTimestamp;
|
||||
expected.orderType = 'bid';
|
||||
expected.orderType = OrderType.Bid;
|
||||
expected.price = new BigNumber(0.5);
|
||||
expected.baseAssetSymbol = 'DEF';
|
||||
expected.baseAssetAddress = null;
|
||||
|
@ -32,13 +32,13 @@ describe('paradex_orders', () => {
|
||||
quoteTokenAddress: '0x0000000000000000000000000000000000000000',
|
||||
};
|
||||
const observedTimestamp: number = Date.now();
|
||||
const orderType: OrderType = 'bid';
|
||||
const orderType: OrderType = OrderType.Bid;
|
||||
const source: string = 'paradex';
|
||||
|
||||
const expected = new TokenOrder();
|
||||
expected.source = 'paradex';
|
||||
expected.observedTimestamp = observedTimestamp;
|
||||
expected.orderType = 'bid';
|
||||
expected.orderType = OrderType.Bid;
|
||||
expected.price = new BigNumber(0.1245);
|
||||
expected.baseAssetSymbol = 'DEF';
|
||||
expected.baseAssetAddress = '0xb45df06e38540a675fdb5b598abf2c0dbe9d6b81';
|
||||
|
@ -5,6 +5,7 @@ import 'mocha';
|
||||
|
||||
import { SraOrder } from '../../../src/entities';
|
||||
import { _convertToEntity } from '../../../src/parsers/sra_orders';
|
||||
import { AssetType } from '../../../src/types';
|
||||
import { chaiSetup } from '../../utils/chai_setup';
|
||||
|
||||
chaiSetup.configure();
|
||||
@ -50,12 +51,12 @@ describe('sra_orders', () => {
|
||||
expected.signature =
|
||||
'0x1b5a5d672b0d647b5797387ccbb89d822d5d2e873346b014f4ff816ff0783f2a7a0d2824d2d7042ec8ea375bc7f870963e1cb8248f1db03ddf125e27b5963aa11f03';
|
||||
expected.rawMakerAssetData = '0xf47261b0000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2';
|
||||
expected.makerAssetType = 'erc20';
|
||||
expected.makerAssetType = AssetType.ERC20;
|
||||
expected.makerAssetProxyId = '0xf47261b0';
|
||||
expected.makerTokenAddress = '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2';
|
||||
expected.makerTokenId = null;
|
||||
expected.rawTakerAssetData = '0xf47261b000000000000000000000000042d6622dece394b54999fbd73d108123806f6a18';
|
||||
expected.takerAssetType = 'erc20';
|
||||
expected.takerAssetType = AssetType.ERC20;
|
||||
expected.takerAssetProxyId = '0xf47261b0';
|
||||
expected.takerTokenAddress = '0x42d6622dece394b54999fbd73d108123806f6a18';
|
||||
expected.takerTokenId = null;
|
||||
|
Loading…
x
Reference in New Issue
Block a user