diff options
author | Alex Browne <stephenalexbrowne@gmail.com> | 2018-10-18 07:44:07 +0800 |
---|---|---|
committer | Fred Carlsen <fred@sjelfull.no> | 2018-12-06 19:04:24 +0800 |
commit | 427c2cd164f841f6b296b059c119fabb113c4e65 (patch) | |
tree | 5a10964c642ac1f313e236429a672fcd6761c7a6 /packages/pipeline/src/index.ts | |
parent | 8c0dfc1936340a08ff627db3c6203bf6836c2992 (diff) | |
download | dexon-sol-tools-427c2cd164f841f6b296b059c119fabb113c4e65.tar.gz dexon-sol-tools-427c2cd164f841f6b296b059c119fabb113c4e65.tar.zst dexon-sol-tools-427c2cd164f841f6b296b059c119fabb113c4e65.zip |
Update to use ContractWrappers + Infura instead of Etherscan
Diffstat (limited to 'packages/pipeline/src/index.ts')
-rw-r--r-- | packages/pipeline/src/index.ts | 43 |
1 files changed, 17 insertions, 26 deletions
diff --git a/packages/pipeline/src/index.ts b/packages/pipeline/src/index.ts index a1dbb35ff..77c92cc34 100644 --- a/packages/pipeline/src/index.ts +++ b/packages/pipeline/src/index.ts @@ -1,52 +1,43 @@ import { HttpClient } from '@0xproject/connect'; +import { web3Factory } from '@0xproject/dev-utils'; import 'reflect-metadata'; import { Connection, createConnection } from 'typeorm'; -import { Etherscan } from './data_sources/etherscan'; -import { parseExchangeEvents } from './data_types/events/exchange_events'; -import { parseSraOrders } from './data_types/sra_orders'; -import { ExchangeCancelEvent } from './entities/ExchangeCancelEvent'; -import { ExchangeCancelUpToEvent } from './entities/ExchangeCancelUpToEvent'; -import { ExchangeFillEvent } from './entities/ExchangeFillEvent'; +import { ExchangeEventsSource } from './data_sources/contract-wrappers/exchange_events'; import { SraOrder } from './entities/SraOrder'; import { config } from './ormconfig'; - -const etherscan = new Etherscan(process.env.ETHERSCAN_API_KEY as string); -const EXCHANGE_ADDRESS = '0x4f833a24e1f95d70f028921e27040ca56e09ab0b'; +import { parseExchangeEvents } from './parsers/events'; +import { parseSraOrders } from './parsers/sra_orders'; let connection: Connection; (async () => { connection = await createConnection(config); await getExchangeEventsAsync(); - await getSraOrdersAsync(); + // await getSraOrdersAsync(); })(); +// TODO(albrow): Separately: Errors do not appear to be handled correctly. If you use the +// wrong rpcUrl it just returns early with no error. async function getExchangeEventsAsync(): Promise<void> { - const fillRepository = connection.getRepository(ExchangeFillEvent); - const cancelRepository = connection.getRepository(ExchangeCancelEvent); - const cancelUpToRepository = connection.getRepository(ExchangeCancelUpToEvent); - console.log( - `found ${(await fillRepository.count()) + - (await cancelRepository.count()) + - (await cancelUpToRepository.count())} existing events`, - ); - const rawEvents = await etherscan.getContractEventsAsync(EXCHANGE_ADDRESS); - const events = parseExchangeEvents(rawEvents); + const provider = web3Factory.getRpcProvider({ + rpcUrl: 'https://mainnet.infura.io', + }); + const exchangeEvents = new ExchangeEventsSource(provider, 1); + const eventLogs = await exchangeEvents.getFillEventsAsync(); + const events = parseExchangeEvents(eventLogs); + console.log('Got events: ' + events.length); for (const event of events) { await event.save(); } - console.log( - `now there are ${(await fillRepository.count()) + - (await cancelRepository.count()) + - (await cancelUpToRepository.count())} total events`, - ); + console.log('Saved events.'); + console.log('Exiting process'); + process.exit(0); } async function getSraOrdersAsync(): Promise<void> { const orderRepository = connection.getRepository(SraOrder); console.log(`found ${await orderRepository.count()} existing orders`); - const sraUrl = 'https://api.radarrelay.com/0x/v2'; const connect = new HttpClient(sraUrl); const rawOrders = await connect.getOrdersAsync(); |