aboutsummaryrefslogtreecommitdiffstats
path: root/packages
diff options
context:
space:
mode:
authorAlex Browne <stephenalexbrowne@gmail.com>2018-09-20 08:30:34 +0800
committerFred Carlsen <fred@sjelfull.no>2018-12-13 01:12:01 +0800
commit90e1028d2fd154b8c637139145a2dc1c6999d585 (patch)
treefca2595ce298b3a69b07e8c510e940bcfd6eb12c /packages
parented3737c1f14182f75815d2d7d761b3c84602a5c6 (diff)
downloaddexon-sol-tools-90e1028d2fd154b8c637139145a2dc1c6999d585.tar
dexon-sol-tools-90e1028d2fd154b8c637139145a2dc1c6999d585.tar.gz
dexon-sol-tools-90e1028d2fd154b8c637139145a2dc1c6999d585.tar.bz2
dexon-sol-tools-90e1028d2fd154b8c637139145a2dc1c6999d585.tar.lz
dexon-sol-tools-90e1028d2fd154b8c637139145a2dc1c6999d585.tar.xz
dexon-sol-tools-90e1028d2fd154b8c637139145a2dc1c6999d585.tar.zst
dexon-sol-tools-90e1028d2fd154b8c637139145a2dc1c6999d585.zip
Add typeorm and begin inserting database records
Diffstat (limited to 'packages')
-rw-r--r--packages/pipeline/src/data-sources/etherscan/events.ts9
-rw-r--r--packages/pipeline/src/entities/ExchangeFillEvent.ts24
-rw-r--r--packages/pipeline/src/index.ts38
3 files changed, 64 insertions, 7 deletions
diff --git a/packages/pipeline/src/data-sources/etherscan/events.ts b/packages/pipeline/src/data-sources/etherscan/events.ts
index 89b3ffac1..edc8cde7b 100644
--- a/packages/pipeline/src/data-sources/etherscan/events.ts
+++ b/packages/pipeline/src/data-sources/etherscan/events.ts
@@ -1,5 +1,6 @@
+import { ExchangeEventArgs } from '@0xproject/contract-wrappers';
import { AbiDecoder } from '@0xproject/utils';
-import { AbiDefinition, DecodedLogArgs, LogEntry, LogWithDecodedArgs } from 'ethereum-types';
+import { AbiDefinition, LogEntry, LogWithDecodedArgs } from 'ethereum-types';
import * as R from 'ramda';
// Raw events response from etherescan.io
@@ -47,12 +48,12 @@ export function _convertResponseToLogEntry(result: EventsResponseResult): LogEnt
// Decodes a LogEntry into a LogWithDecodedArgs
// tslint:disable-next-line:completed-docs
export const _decodeLogEntry = R.curry((contractAbi: AbiDefinition[], log: LogEntry): LogWithDecodedArgs<
- DecodedLogArgs
+ ExchangeEventArgs
> => {
const abiDecoder = new AbiDecoder([contractAbi]);
const logWithDecodedArgs = abiDecoder.tryToDecodeLogOrNoop(log);
// tslint:disable-next-line:no-unnecessary-type-assertion
- return logWithDecodedArgs as LogWithDecodedArgs<DecodedLogArgs>;
+ return logWithDecodedArgs as LogWithDecodedArgs<ExchangeEventArgs>;
});
/**
@@ -64,7 +65,7 @@ export const _decodeLogEntry = R.curry((contractAbi: AbiDefinition[], log: LogEn
export function parseRawEventsResponse(
contractAbi: AbiDefinition[],
rawEventsResponse: EventsResponse,
-): Array<LogWithDecodedArgs<DecodedLogArgs>> {
+): Array<LogWithDecodedArgs<ExchangeEventArgs>> {
return R.pipe(R.map(_convertResponseToLogEntry), R.map(_decodeLogEntry(contractAbi)))(rawEventsResponse.result);
}
diff --git a/packages/pipeline/src/entities/ExchangeFillEvent.ts b/packages/pipeline/src/entities/ExchangeFillEvent.ts
new file mode 100644
index 000000000..1e9e8d986
--- /dev/null
+++ b/packages/pipeline/src/entities/ExchangeFillEvent.ts
@@ -0,0 +1,24 @@
+import { Column, Entity, PrimaryColumn } from 'typeorm';
+
+@Entity()
+export class ExchangeFillEvent {
+ @PrimaryColumn() public logIndex!: number;
+
+ @Column() public address!: string;
+ @Column() public rawData!: string;
+ @Column() public blockNumber!: number;
+
+ @Column() public makerAddress!: string;
+ @Column() public takerAddress!: string;
+ @Column() public feeRecepientAddress!: string;
+ @Column() public senderAddress!: string;
+ @Column() public makerAssetFilledAmount!: string;
+ @Column() public takerAssetFilledAmount!: string;
+ @Column() public makerFeePaid!: string;
+ @Column() public takerFeePaid!: string;
+ @Column() public orderHash!: string;
+ // TODO(albrow): Decode asset data.
+ @Column() public makerAssetData!: string;
+ @Column() public takerAssetData!: string;
+ // TODO(albrow): Include topics?
+}
diff --git a/packages/pipeline/src/index.ts b/packages/pipeline/src/index.ts
index eccb24d18..d70ec3e3e 100644
--- a/packages/pipeline/src/index.ts
+++ b/packages/pipeline/src/index.ts
@@ -1,13 +1,45 @@
-import { Etherscan } from './data-sources/etherscan';
+import { ExchangeFillEventArgs } from '@0xproject/contract-wrappers';
+import { LogWithDecodedArgs } from 'ethereum-types';
+import 'reflect-metadata';
+import { createConnection } from 'typeorm';
import { artifacts } from './artifacts';
+import { Etherscan } from './data-sources/etherscan';
+import { ExchangeFillEvent } from './entities/ExchangeFillEvent';
+import { config } from './ormconfig';
const etherscan = new Etherscan(process.env.ETHERSCAN_API_KEY as string);
(async () => {
- const events = await etherscan.getContractEventsAsync(
+ const connection = await createConnection(config);
+ const repository = connection.getRepository(ExchangeFillEvent);
+ console.log(`found ${await repository.count()} existing fill events`);
+ const eventLogs = await etherscan.getContractEventsAsync(
'0x4f833a24e1f95d70f028921e27040ca56e09ab0b',
artifacts.Exchange.compilerOutput.abi,
);
- console.log(events);
+ for (const eventLog of eventLogs) {
+ if (eventLog.event !== 'Fill') {
+ continue;
+ }
+ const fillEventLog = eventLog as LogWithDecodedArgs<ExchangeFillEventArgs>;
+ const exchangeFillEvent = new ExchangeFillEvent();
+ exchangeFillEvent.logIndex = fillEventLog.logIndex as number;
+ exchangeFillEvent.address = fillEventLog.address as string;
+ exchangeFillEvent.rawData = fillEventLog.data as string;
+ exchangeFillEvent.blockNumber = fillEventLog.blockNumber as number;
+ exchangeFillEvent.makerAddress = fillEventLog.args.makerAddress.toString();
+ exchangeFillEvent.takerAddress = fillEventLog.args.takerAddress.toString();
+ exchangeFillEvent.feeRecepientAddress = fillEventLog.args.feeRecipientAddress;
+ exchangeFillEvent.senderAddress = fillEventLog.args.senderAddress;
+ exchangeFillEvent.makerAssetFilledAmount = fillEventLog.args.makerAssetFilledAmount.toString();
+ exchangeFillEvent.takerAssetFilledAmount = fillEventLog.args.takerAssetFilledAmount.toString();
+ exchangeFillEvent.makerFeePaid = fillEventLog.args.makerFeePaid.toString();
+ exchangeFillEvent.takerFeePaid = fillEventLog.args.takerFeePaid.toString();
+ exchangeFillEvent.orderHash = fillEventLog.args.orderHash;
+ exchangeFillEvent.makerAssetData = fillEventLog.args.makerAssetData;
+ exchangeFillEvent.takerAssetData = fillEventLog.args.takerAssetData;
+ await repository.save(exchangeFillEvent);
+ }
+ console.log(`now ${await repository.count()} total fill events`);
})();