aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlex Browne <stephenalexbrowne@gmail.com>2018-09-26 07:03:54 +0800
committerFred Carlsen <fred@sjelfull.no>2018-12-06 19:04:24 +0800
commit1ae3592e45d163682d8ef2ca076ee57bc170d7ad (patch)
tree7f7b46fe0deabe8d8f66ecd98ee96e4572111b3d
parentdc04d025af21227d8da4841ccb7e5bd6d69a930f (diff)
downloaddexon-sol-tools-1ae3592e45d163682d8ef2ca076ee57bc170d7ad.tar.gz
dexon-sol-tools-1ae3592e45d163682d8ef2ca076ee57bc170d7ad.tar.zst
dexon-sol-tools-1ae3592e45d163682d8ef2ca076ee57bc170d7ad.zip
Implement scraping and parsing exchange CancelUpTo events
-rw-r--r--packages/pipeline/src/data_types/events/exchange_events.ts30
-rw-r--r--packages/pipeline/src/entities/ExchangeCancelUpToEvent.ts15
-rw-r--r--packages/pipeline/src/index.ts9
3 files changed, 45 insertions, 9 deletions
diff --git a/packages/pipeline/src/data_types/events/exchange_events.ts b/packages/pipeline/src/data_types/events/exchange_events.ts
index cc4332f6f..763a141ea 100644
--- a/packages/pipeline/src/data_types/events/exchange_events.ts
+++ b/packages/pipeline/src/data_types/events/exchange_events.ts
@@ -1,18 +1,24 @@
-import { ExchangeCancelEventArgs, ExchangeEventArgs, ExchangeFillEventArgs } from '@0xproject/contract-wrappers';
+import {
+ ExchangeCancelEventArgs,
+ ExchangeCancelUpToEventArgs,
+ ExchangeEventArgs,
+ ExchangeFillEventArgs,
+} from '@0xproject/contract-wrappers';
import { assetDataUtils } from '@0xproject/order-utils';
import { AssetProxyId, ERC721AssetData } from '@0xproject/types';
import { BigNumber } from '@0xproject/utils';
-import { LogEntry, LogWithDecodedArgs } from 'ethereum-types';
+import { LogWithDecodedArgs } from 'ethereum-types';
import * as R from 'ramda';
import { artifacts } from '../../artifacts';
import { EventsResponse } from '../../data_sources/etherscan';
import { ExchangeCancelEvent } from '../../entities/ExchangeCancelEvent';
+import { ExchangeCancelUpToEvent } from '../../entities/ExchangeCancelUpToEvent';
import { ExchangeFillEvent } from '../../entities/ExchangeFillEvent';
import { convertResponseToLogEntry, decodeLogEntry } from './event_utils';
-export type ExchangeEventEntity = ExchangeFillEvent | ExchangeCancelEvent;
+export type ExchangeEventEntity = ExchangeFillEvent | ExchangeCancelEvent | ExchangeCancelUpToEvent;
const exchangeContractAbi = artifacts.Exchange.compilerOutput.abi;
@@ -27,7 +33,7 @@ export function parseExchangeEvents(rawEventsResponse: EventsResponse): Exchange
}
export function shouldIncludeLogEntry(logEntry: LogWithDecodedArgs<ExchangeEventArgs>): boolean {
- if (!R.contains(logEntry.event, ['Fill', 'Cancel'])) {
+ if (!R.contains(logEntry.event, ['Fill', 'Cancel', 'CancelUpTo'])) {
return false;
} else if (logEntry.logIndex == null || isNaN(logEntry.logIndex)) {
return false;
@@ -41,6 +47,8 @@ export function _convertToEntity(eventLog: LogWithDecodedArgs<ExchangeEventArgs>
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);
}
@@ -109,6 +117,20 @@ export function _convertToExchangeCancelEvent(
return exchangeCancelEvent;
}
+export function _convertToExchangeCancelUpToEvent(
+ eventLog: LogWithDecodedArgs<ExchangeCancelUpToEventArgs>,
+): ExchangeCancelUpToEvent {
+ const exchangeCancelUpToEvent = new ExchangeCancelUpToEvent();
+ exchangeCancelUpToEvent.logIndex = eventLog.logIndex as number;
+ exchangeCancelUpToEvent.address = eventLog.address as string;
+ exchangeCancelUpToEvent.rawData = eventLog.data as string;
+ exchangeCancelUpToEvent.blockNumber = eventLog.blockNumber as number;
+ exchangeCancelUpToEvent.makerAddress = eventLog.args.makerAddress.toString();
+ exchangeCancelUpToEvent.senderAddress = eventLog.args.senderAddress.toString();
+ exchangeCancelUpToEvent.orderEpoch = eventLog.args.orderEpoch.toString();
+ return exchangeCancelUpToEvent;
+}
+
function bigNumbertoStringOrNull(n: BigNumber): string | null {
if (n == null) {
return null;
diff --git a/packages/pipeline/src/entities/ExchangeCancelUpToEvent.ts b/packages/pipeline/src/entities/ExchangeCancelUpToEvent.ts
new file mode 100644
index 000000000..3021f7394
--- /dev/null
+++ b/packages/pipeline/src/entities/ExchangeCancelUpToEvent.ts
@@ -0,0 +1,15 @@
+import { BaseEntity, Column, Entity, PrimaryColumn } from 'typeorm';
+
+@Entity()
+export class ExchangeCancelUpToEvent extends BaseEntity {
+ @PrimaryColumn() public logIndex!: number;
+ @PrimaryColumn() public blockNumber!: number;
+
+ @Column() public address!: string;
+ @Column() public rawData!: string;
+
+ @Column() public makerAddress!: string;
+ @Column() public senderAddress!: string;
+ @Column() public orderEpoch!: string;
+ // TODO(albrow): Include topics?
+}
diff --git a/packages/pipeline/src/index.ts b/packages/pipeline/src/index.ts
index 67b1f6fb2..1a010b6e5 100644
--- a/packages/pipeline/src/index.ts
+++ b/packages/pipeline/src/index.ts
@@ -5,6 +5,7 @@ import { createConnection } from 'typeorm';
import { Etherscan } from './data_sources/etherscan';
import { parseExchangeEvents } from './data_types/events/exchange_events';
import { ExchangeCancelEvent } from './entities/ExchangeCancelEvent';
+import { ExchangeCancelUpToEvent } from './entities/ExchangeCancelUpToEvent';
import { ExchangeFillEvent } from './entities/ExchangeFillEvent';
import { config } from './ormconfig';
@@ -15,14 +16,12 @@ const EXCHANGE_ADDRESS = '0x4f833a24e1f95d70f028921e27040ca56e09ab0b';
const connection = await createConnection(config);
const fillRepository = connection.getRepository(ExchangeFillEvent);
const cancelRepository = connection.getRepository(ExchangeCancelEvent);
- console.log(`found ${await fillRepository.count()} existing fill events`);
- console.log(`found ${await cancelRepository.count()} existing cancel events`);
+ const cancelUpToRepository = connection.getRepository(ExchangeCancelUpToEvent);
+ console.log(`found ${(await fillRepository.count()) + (await cancelRepository.count())} existing events`);
const rawEvents = await etherscan.getContractEventsAsync(EXCHANGE_ADDRESS);
const events = parseExchangeEvents(rawEvents);
- console.log(`got ${events.length} parsed events`);
for (const event of events) {
await event.save();
}
- console.log(`now ${await fillRepository.count()} total fill events`);
- console.log(`now ${await cancelRepository.count()} total cancel events`);
+ console.log(`now there are ${(await fillRepository.count()) + (await cancelRepository.count())} total events`);
})();