diff options
author | Alex Browne <stephenalexbrowne@gmail.com> | 2018-10-18 07:44:07 +0800 |
---|---|---|
committer | Fred Carlsen <fred@sjelfull.no> | 2018-12-13 01:12:30 +0800 |
commit | c52ab47185f3d3a808e0490440d01e21fef61e06 (patch) | |
tree | 75635b4ea599b7a46acf4cdc8ca9f394285a473d /packages/pipeline/src/parsers | |
parent | f082a3f7685b643b6b957cca95a48c5d213328de (diff) | |
download | dexon-sol-tools-c52ab47185f3d3a808e0490440d01e21fef61e06.tar dexon-sol-tools-c52ab47185f3d3a808e0490440d01e21fef61e06.tar.gz dexon-sol-tools-c52ab47185f3d3a808e0490440d01e21fef61e06.tar.bz2 dexon-sol-tools-c52ab47185f3d3a808e0490440d01e21fef61e06.tar.lz dexon-sol-tools-c52ab47185f3d3a808e0490440d01e21fef61e06.tar.xz dexon-sol-tools-c52ab47185f3d3a808e0490440d01e21fef61e06.tar.zst dexon-sol-tools-c52ab47185f3d3a808e0490440d01e21fef61e06.zip |
Update to use ContractWrappers + Infura instead of Etherscan
Diffstat (limited to 'packages/pipeline/src/parsers')
-rw-r--r-- | packages/pipeline/src/parsers/events/index.ts | 104 | ||||
-rw-r--r-- | packages/pipeline/src/parsers/sra_orders/index.ts | 38 |
2 files changed, 56 insertions, 86 deletions
diff --git a/packages/pipeline/src/parsers/events/index.ts b/packages/pipeline/src/parsers/events/index.ts index e18106c75..66f382dda 100644 --- a/packages/pipeline/src/parsers/events/index.ts +++ b/packages/pipeline/src/parsers/events/index.ts @@ -1,43 +1,38 @@ -import { ExchangeCancelEventArgs, ExchangeCancelUpToEventArgs, ExchangeFillEventArgs } from '@0x/contract-wrappers'; -import { assetDataUtils } from '@0x/order-utils'; -import { AssetProxyId, ERC721AssetData } from '@0x/types'; +import { + ExchangeCancelEventArgs, + ExchangeCancelUpToEventArgs, + ExchangeEventArgs, + ExchangeFillEventArgs, +} from '@0xproject/contract-wrappers'; +import { assetDataUtils } from '@0xproject/order-utils'; +import { AssetProxyId, ERC721AssetData } from '@0xproject/types'; import { LogWithDecodedArgs } from 'ethereum-types'; import * as R from 'ramda'; -import { ExchangeCancelEvent, ExchangeCancelUpToEvent, ExchangeFillEvent } from '../../entities'; +import { ExchangeCancelEvent } from '../../entities/ExchangeCancelEvent'; +import { ExchangeCancelUpToEvent } from '../../entities/ExchangeCancelUpToEvent'; +import { ExchangeFillEvent } from '../../entities/ExchangeFillEvent'; import { bigNumbertoStringOrNull } from '../../utils'; -/** - * Parses raw event logs for a fill event and returns an array of - * ExchangeFillEvent entities. - * @param eventLogs Raw event logs (e.g. returned from contract-wrappers). - */ -export const parseExchangeFillEvents: ( - eventLogs: Array<LogWithDecodedArgs<ExchangeFillEventArgs>>, -) => ExchangeFillEvent[] = R.map(_convertToExchangeFillEvent); +export type ExchangeEventEntity = ExchangeFillEvent | ExchangeCancelEvent | ExchangeCancelUpToEvent; -/** - * Parses raw event logs for a cancel event and returns an array of - * ExchangeCancelEvent entities. - * @param eventLogs Raw event logs (e.g. returned from contract-wrappers). - */ -export const parseExchangeCancelEvents: ( - eventLogs: Array<LogWithDecodedArgs<ExchangeCancelEventArgs>>, -) => ExchangeCancelEvent[] = R.map(_convertToExchangeCancelEvent); +export const parseExchangeEvents: ( + eventLogs: Array<LogWithDecodedArgs<ExchangeEventArgs>>, +) => ExchangeEventEntity[] = R.map(_convertToEntity); -/** - * Parses raw event logs for a CancelUpTo event and returns an array of - * ExchangeCancelUpToEvent entities. - * @param eventLogs Raw event logs (e.g. returned from contract-wrappers). - */ -export const parseExchangeCancelUpToEvents: ( - eventLogs: Array<LogWithDecodedArgs<ExchangeCancelUpToEventArgs>>, -) => ExchangeCancelUpToEvent[] = R.map(_convertToExchangeCancelUpToEvent); +export function _convertToEntity(eventLog: LogWithDecodedArgs<ExchangeEventArgs>): ExchangeEventEntity { + switch (eventLog.event) { + case 'Fill': + return _convertToExchangeFillEvent(eventLog as LogWithDecodedArgs<ExchangeFillEventArgs>); + case 'Cancel': + return _convertToExchangeCancelEvent(eventLog as LogWithDecodedArgs<ExchangeCancelEventArgs>); + case 'CancelUpTo': + return _convertToExchangeCancelUpToEvent(eventLog as LogWithDecodedArgs<ExchangeCancelUpToEventArgs>); + default: + throw new Error('unexpected eventLog.event type: ' + eventLog.event); + } +} -/** - * Converts a raw event log for a fill event into an ExchangeFillEvent entity. - * @param eventLog Raw event log (e.g. returned from contract-wrappers). - */ export function _convertToExchangeFillEvent(eventLog: LogWithDecodedArgs<ExchangeFillEventArgs>): ExchangeFillEvent { const makerAssetData = assetDataUtils.decodeAssetDataOrThrow(eventLog.args.makerAssetData); const makerAssetType = makerAssetData.assetProxyId === AssetProxyId.ERC20 ? 'erc20' : 'erc721'; @@ -48,37 +43,28 @@ export function _convertToExchangeFillEvent(eventLog: LogWithDecodedArgs<Exchang exchangeFillEvent.blockNumber = eventLog.blockNumber as number; exchangeFillEvent.logIndex = eventLog.logIndex as number; exchangeFillEvent.rawData = eventLog.data as string; - exchangeFillEvent.transactionHash = eventLog.transactionHash; - exchangeFillEvent.makerAddress = eventLog.args.makerAddress; - exchangeFillEvent.takerAddress = eventLog.args.takerAddress; - exchangeFillEvent.feeRecipientAddress = eventLog.args.feeRecipientAddress; + exchangeFillEvent.makerAddress = eventLog.args.makerAddress.toString(); + exchangeFillEvent.takerAddress = eventLog.args.takerAddress.toString(); + exchangeFillEvent.feeRecepientAddress = eventLog.args.feeRecipientAddress; exchangeFillEvent.senderAddress = eventLog.args.senderAddress; - exchangeFillEvent.makerAssetFilledAmount = eventLog.args.makerAssetFilledAmount; - exchangeFillEvent.takerAssetFilledAmount = eventLog.args.takerAssetFilledAmount; - exchangeFillEvent.makerFeePaid = eventLog.args.makerFeePaid; - exchangeFillEvent.takerFeePaid = eventLog.args.takerFeePaid; + exchangeFillEvent.makerAssetFilledAmount = eventLog.args.makerAssetFilledAmount.toString(); + exchangeFillEvent.takerAssetFilledAmount = eventLog.args.takerAssetFilledAmount.toString(); + exchangeFillEvent.makerFeePaid = eventLog.args.makerFeePaid.toString(); + exchangeFillEvent.takerFeePaid = eventLog.args.takerFeePaid.toString(); exchangeFillEvent.orderHash = eventLog.args.orderHash; exchangeFillEvent.rawMakerAssetData = eventLog.args.makerAssetData; exchangeFillEvent.makerAssetType = makerAssetType; exchangeFillEvent.makerAssetProxyId = makerAssetData.assetProxyId; exchangeFillEvent.makerTokenAddress = makerAssetData.tokenAddress; - // tslint has a false positive here. Type assertion is required. - // tslint:disable-next-line:no-unnecessary-type-assertion exchangeFillEvent.makerTokenId = bigNumbertoStringOrNull((makerAssetData as ERC721AssetData).tokenId); exchangeFillEvent.rawTakerAssetData = eventLog.args.takerAssetData; exchangeFillEvent.takerAssetType = takerAssetType; exchangeFillEvent.takerAssetProxyId = takerAssetData.assetProxyId; exchangeFillEvent.takerTokenAddress = takerAssetData.tokenAddress; - // tslint:disable-next-line:no-unnecessary-type-assertion exchangeFillEvent.takerTokenId = bigNumbertoStringOrNull((takerAssetData as ERC721AssetData).tokenId); return exchangeFillEvent; } -/** - * Converts a raw event log for a cancel event into an ExchangeCancelEvent - * entity. - * @param eventLog Raw event log (e.g. returned from contract-wrappers). - */ export function _convertToExchangeCancelEvent( eventLog: LogWithDecodedArgs<ExchangeCancelEventArgs>, ): ExchangeCancelEvent { @@ -91,32 +77,25 @@ export function _convertToExchangeCancelEvent( exchangeCancelEvent.blockNumber = eventLog.blockNumber as number; exchangeCancelEvent.logIndex = eventLog.logIndex as number; exchangeCancelEvent.rawData = eventLog.data as string; - exchangeCancelEvent.transactionHash = eventLog.transactionHash; - exchangeCancelEvent.makerAddress = eventLog.args.makerAddress; - exchangeCancelEvent.takerAddress = eventLog.args.takerAddress; - exchangeCancelEvent.feeRecipientAddress = eventLog.args.feeRecipientAddress; + exchangeCancelEvent.makerAddress = eventLog.args.makerAddress.toString(); + exchangeCancelEvent.takerAddress = + eventLog.args.takerAddress == null ? null : eventLog.args.takerAddress.toString(); + exchangeCancelEvent.feeRecepientAddress = eventLog.args.feeRecipientAddress; exchangeCancelEvent.senderAddress = eventLog.args.senderAddress; exchangeCancelEvent.orderHash = eventLog.args.orderHash; exchangeCancelEvent.rawMakerAssetData = eventLog.args.makerAssetData; exchangeCancelEvent.makerAssetType = makerAssetType; exchangeCancelEvent.makerAssetProxyId = makerAssetData.assetProxyId; exchangeCancelEvent.makerTokenAddress = makerAssetData.tokenAddress; - // tslint:disable-next-line:no-unnecessary-type-assertion exchangeCancelEvent.makerTokenId = bigNumbertoStringOrNull((makerAssetData as ERC721AssetData).tokenId); exchangeCancelEvent.rawTakerAssetData = eventLog.args.takerAssetData; exchangeCancelEvent.takerAssetType = takerAssetType; exchangeCancelEvent.takerAssetProxyId = takerAssetData.assetProxyId; exchangeCancelEvent.takerTokenAddress = takerAssetData.tokenAddress; - // tslint:disable-next-line:no-unnecessary-type-assertion exchangeCancelEvent.takerTokenId = bigNumbertoStringOrNull((takerAssetData as ERC721AssetData).tokenId); return exchangeCancelEvent; } -/** - * Converts a raw event log for a cancelUpTo event into an - * ExchangeCancelUpToEvent entity. - * @param eventLog Raw event log (e.g. returned from contract-wrappers). - */ export function _convertToExchangeCancelUpToEvent( eventLog: LogWithDecodedArgs<ExchangeCancelUpToEventArgs>, ): ExchangeCancelUpToEvent { @@ -125,9 +104,8 @@ export function _convertToExchangeCancelUpToEvent( exchangeCancelUpToEvent.blockNumber = eventLog.blockNumber as number; exchangeCancelUpToEvent.logIndex = eventLog.logIndex as number; exchangeCancelUpToEvent.rawData = eventLog.data as string; - exchangeCancelUpToEvent.transactionHash = eventLog.transactionHash; - exchangeCancelUpToEvent.makerAddress = eventLog.args.makerAddress; - exchangeCancelUpToEvent.senderAddress = eventLog.args.senderAddress; - exchangeCancelUpToEvent.orderEpoch = eventLog.args.orderEpoch; + exchangeCancelUpToEvent.makerAddress = eventLog.args.makerAddress.toString(); + exchangeCancelUpToEvent.senderAddress = eventLog.args.senderAddress.toString(); + exchangeCancelUpToEvent.orderEpoch = eventLog.args.orderEpoch.toString(); return exchangeCancelUpToEvent; } diff --git a/packages/pipeline/src/parsers/sra_orders/index.ts b/packages/pipeline/src/parsers/sra_orders/index.ts index ef8901e40..fb2b74dfe 100644 --- a/packages/pipeline/src/parsers/sra_orders/index.ts +++ b/packages/pipeline/src/parsers/sra_orders/index.ts @@ -1,24 +1,15 @@ -import { APIOrder, OrdersResponse } from '@0x/connect'; -import { assetDataUtils, orderHashUtils } from '@0x/order-utils'; -import { AssetProxyId, ERC721AssetData } from '@0x/types'; +import { APIOrder, OrdersResponse } from '@0xproject/connect'; +import { assetDataUtils, orderHashUtils } from '@0xproject/order-utils'; +import { AssetProxyId, ERC721AssetData } from '@0xproject/types'; import * as R from 'ramda'; -import { SraOrder } from '../../entities'; +import { SraOrder } from '../../entities/SraOrder'; import { bigNumbertoStringOrNull } from '../../utils'; -/** - * Parses a raw order response from an SRA endpoint and returns an array of - * SraOrder entities. - * @param rawOrdersResponse A raw order response from an SRA endpoint. - */ export function parseSraOrders(rawOrdersResponse: OrdersResponse): SraOrder[] { return R.map(_convertToEntity, rawOrdersResponse.records); } -/** - * Converts a single APIOrder into an SraOrder entity. - * @param apiOrder A single order from the response from an SRA endpoint. - */ export function _convertToEntity(apiOrder: APIOrder): SraOrder { // TODO(albrow): refactor out common asset data decoding code. const makerAssetData = assetDataUtils.decodeAssetDataOrThrow(apiOrder.order.makerAssetData); @@ -30,33 +21,34 @@ export function _convertToEntity(apiOrder: APIOrder): SraOrder { sraOrder.exchangeAddress = apiOrder.order.exchangeAddress; sraOrder.orderHashHex = orderHashUtils.getOrderHashHex(apiOrder.order); + // TODO(albrow): Set these fields to the correct values upstack. + sraOrder.lastUpdatedTimestamp = 0; + sraOrder.firstSeenTimestamp = 0; + sraOrder.makerAddress = apiOrder.order.makerAddress; sraOrder.takerAddress = apiOrder.order.takerAddress; sraOrder.feeRecipientAddress = apiOrder.order.feeRecipientAddress; sraOrder.senderAddress = apiOrder.order.senderAddress; - sraOrder.makerAssetAmount = apiOrder.order.makerAssetAmount; - sraOrder.takerAssetAmount = apiOrder.order.takerAssetAmount; - sraOrder.makerFee = apiOrder.order.makerFee; - sraOrder.takerFee = apiOrder.order.takerFee; - sraOrder.expirationTimeSeconds = apiOrder.order.expirationTimeSeconds; - sraOrder.salt = apiOrder.order.salt; + sraOrder.makerAssetAmount = apiOrder.order.makerAssetAmount.toString(); + sraOrder.takerAssetAmount = apiOrder.order.takerAssetAmount.toString(); + sraOrder.makerFee = apiOrder.order.makerFee.toString(); + sraOrder.takerFee = apiOrder.order.takerFee.toString(); + sraOrder.expirationTimeSeconds = apiOrder.order.expirationTimeSeconds.toString(); + sraOrder.salt = apiOrder.order.salt.toString(); sraOrder.signature = apiOrder.order.signature; sraOrder.rawMakerAssetData = apiOrder.order.makerAssetData; sraOrder.makerAssetType = makerAssetType; sraOrder.makerAssetProxyId = makerAssetData.assetProxyId; sraOrder.makerTokenAddress = makerAssetData.tokenAddress; - // tslint has a false positive here. Type assertion is required. - // tslint:disable-next-line:no-unnecessary-type-assertion sraOrder.makerTokenId = bigNumbertoStringOrNull((makerAssetData as ERC721AssetData).tokenId); sraOrder.rawTakerAssetData = apiOrder.order.takerAssetData; sraOrder.takerAssetType = takerAssetType; sraOrder.takerAssetProxyId = takerAssetData.assetProxyId; sraOrder.takerTokenAddress = takerAssetData.tokenAddress; - // tslint:disable-next-line:no-unnecessary-type-assertion sraOrder.takerTokenId = bigNumbertoStringOrNull((takerAssetData as ERC721AssetData).tokenId); - sraOrder.metadataJson = JSON.stringify(apiOrder.metaData); + sraOrder.metaDataJson = JSON.stringify(apiOrder.metaData); return sraOrder; } |