diff options
author | Alex Browne <stephenalexbrowne@gmail.com> | 2018-09-26 06:03:49 +0800 |
---|---|---|
committer | Alex Browne <stephenalexbrowne@gmail.com> | 2018-12-05 06:24:06 +0800 |
commit | 60bc27c616c411cf67bf89e669fb293135359685 (patch) | |
tree | 04a5e743b5b7a8f793e3942da62be407ca509af5 /packages/pipeline/src/data_types/events/exchange_events.ts | |
parent | 2207f09ce2c8b595f75fce6387256a64c64b23c3 (diff) | |
download | dexon-sol-tools-60bc27c616c411cf67bf89e669fb293135359685.tar dexon-sol-tools-60bc27c616c411cf67bf89e669fb293135359685.tar.gz dexon-sol-tools-60bc27c616c411cf67bf89e669fb293135359685.tar.bz2 dexon-sol-tools-60bc27c616c411cf67bf89e669fb293135359685.tar.lz dexon-sol-tools-60bc27c616c411cf67bf89e669fb293135359685.tar.xz dexon-sol-tools-60bc27c616c411cf67bf89e669fb293135359685.tar.zst dexon-sol-tools-60bc27c616c411cf67bf89e669fb293135359685.zip |
Implement scraping and parsing exchange cancel events
Diffstat (limited to 'packages/pipeline/src/data_types/events/exchange_events.ts')
-rw-r--r-- | packages/pipeline/src/data_types/events/exchange_events.ts | 41 |
1 files changed, 37 insertions, 4 deletions
diff --git a/packages/pipeline/src/data_types/events/exchange_events.ts b/packages/pipeline/src/data_types/events/exchange_events.ts index fb5341b58..3938f3a69 100644 --- a/packages/pipeline/src/data_types/events/exchange_events.ts +++ b/packages/pipeline/src/data_types/events/exchange_events.ts @@ -1,4 +1,4 @@ -import { ExchangeEventArgs, ExchangeFillEventArgs } from '@0xproject/contract-wrappers'; +import { ExchangeCancelEventArgs, ExchangeEventArgs, ExchangeFillEventArgs } from '@0xproject/contract-wrappers'; import { assetDataUtils } from '@0xproject/order-utils'; import { AssetProxyId, ERC721AssetData } from '@0xproject/types'; import { BigNumber } from '@0xproject/utils'; @@ -7,12 +7,12 @@ import * as R from 'ramda'; import { artifacts } from '../../artifacts'; import { EventsResponse } from '../../data_sources/etherscan'; +import { ExchangeCancelEvent } from '../../entities/ExchangeCancelEvent'; import { ExchangeFillEvent } from '../../entities/ExchangeFillEvent'; import { convertResponseToLogEntry, decodeLogEntry } from './event_utils'; -// TODO(albrow): Union with other exchange event entity types -export type ExchangeEventEntity = ExchangeFillEvent; +export type ExchangeEventEntity = ExchangeFillEvent | ExchangeCancelEvent; const exchangeContractAbi = artifacts.Exchange.compilerOutput.abi; @@ -22,7 +22,7 @@ export function parseExchangeEvents(rawEventsResponse: EventsResponse): Exchange eventResponse => decodeLogEntry<ExchangeEventArgs>(exchangeContractAbi, eventResponse), logEntries, ); - const filteredLogEntries = R.filter(logEntry => R.contains(logEntry.event, ['Fill']), decodedLogEntries); + const filteredLogEntries = R.filter(logEntry => R.contains(logEntry.event, ['Fill', 'Cancel']), decodedLogEntries); return R.map(_convertToEntity, filteredLogEntries); } @@ -30,6 +30,8 @@ export function _convertToEntity(eventLog: LogWithDecodedArgs<ExchangeEventArgs> switch (eventLog.event) { case 'Fill': return _convertToExchangeFillEvent(eventLog as LogWithDecodedArgs<ExchangeFillEventArgs>); + case 'Cancel': + return _convertToExchangeCancelEvent(eventLog as LogWithDecodedArgs<ExchangeCancelEventArgs>); default: throw new Error('unexpected eventLog.event type: ' + eventLog.event); } @@ -67,6 +69,37 @@ export function _convertToExchangeFillEvent(eventLog: LogWithDecodedArgs<Exchang return exchangeFillEvent; } +export function _convertToExchangeCancelEvent( + eventLog: LogWithDecodedArgs<ExchangeCancelEventArgs>, +): ExchangeCancelEvent { + const makerAssetData = assetDataUtils.decodeAssetDataOrThrow(eventLog.args.makerAssetData); + const makerAssetType = makerAssetData.assetProxyId === AssetProxyId.ERC20 ? 'erc20' : 'erc721'; + const takerAssetData = assetDataUtils.decodeAssetDataOrThrow(eventLog.args.takerAssetData); + const takerAssetType = takerAssetData.assetProxyId === AssetProxyId.ERC20 ? 'erc20' : 'erc721'; + const exchangeCancelEvent = new ExchangeCancelEvent(); + exchangeCancelEvent.logIndex = eventLog.logIndex as number; + exchangeCancelEvent.address = eventLog.address as string; + exchangeCancelEvent.rawData = eventLog.data as string; + exchangeCancelEvent.blockNumber = eventLog.blockNumber as number; + 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; + exchangeCancelEvent.makerTokenId = bigNumbertoStringOrNull((makerAssetData as ERC721AssetData).tokenId); + exchangeCancelEvent.rawTakerAssetData = eventLog.args.takerAssetData; + exchangeCancelEvent.takerAssetType = takerAssetType; + exchangeCancelEvent.takerAssetProxyId = takerAssetData.assetProxyId; + exchangeCancelEvent.takerTokenAddress = takerAssetData.tokenAddress; + exchangeCancelEvent.takerTokenId = bigNumbertoStringOrNull((takerAssetData as ERC721AssetData).tokenId); + return exchangeCancelEvent; +} + function bigNumbertoStringOrNull(n: BigNumber): string | null { if (n == null) { return null; |