From 4cd430bf78cb6674d36d9e28ded70598a96e4237 Mon Sep 17 00:00:00 2001 From: prathamesh0 Date: Wed, 2 Nov 2022 08:50:10 +0530 Subject: [PATCH 1/2] Use checkpoint CLI from cli package --- packages/erc20-watcher/src/indexer.ts | 5 +++ .../src/cli/checkpoint-cmds/create.ts | 35 ++++--------------- packages/uni-watcher/src/indexer.ts | 5 +++ 3 files changed, 16 insertions(+), 29 deletions(-) diff --git a/packages/erc20-watcher/src/indexer.ts b/packages/erc20-watcher/src/indexer.ts index 15a625a3..4f4de2f4 100644 --- a/packages/erc20-watcher/src/indexer.ts +++ b/packages/erc20-watcher/src/indexer.ts @@ -352,6 +352,11 @@ export class Indexer implements IndexerInterface { // TODO Implement } + async processCLICheckpoint (contractAddress: string, blockHash?: string): Promise { + // TODO Implement + return ''; + } + parseEventNameAndArgs (kind: string, logObj: any): any { let eventName = UNKNOWN_EVENT_NAME; let eventInfo = {}; diff --git a/packages/uni-info-watcher/src/cli/checkpoint-cmds/create.ts b/packages/uni-info-watcher/src/cli/checkpoint-cmds/create.ts index 05186089..43974bc9 100644 --- a/packages/uni-info-watcher/src/cli/checkpoint-cmds/create.ts +++ b/packages/uni-info-watcher/src/cli/checkpoint-cmds/create.ts @@ -2,19 +2,14 @@ // Copyright 2022 Vulcanize, Inc. // -import debug from 'debug'; -import assert from 'assert'; - -import { getConfig, initClients, JobQueue } from '@cerc-io/util'; -import { Config } from '@vulcanize/util'; +import { CreateCheckpointCmd } from '@cerc-io/cli'; import { Client as ERC20Client } from '@vulcanize/erc20-watcher'; import { Client as UniClient } from '@vulcanize/uni-watcher'; +import { Config } from '@vulcanize/util'; import { Database } from '../../database'; import { Indexer } from '../../indexer'; -const log = debug('vulcanize:checkpoint-create'); - export const command = 'create'; export const desc = 'Create checkpoint'; @@ -33,21 +28,9 @@ export const builder = { }; export const handler = async (argv: any): Promise => { - const config: Config = await getConfig(argv.configFile); - const { ethClient, ethProvider } = await initClients(config); - - const db = new Database(config.database, config.server); - await db.init(); - - const jobQueueConfig = config.jobQueue; - assert(jobQueueConfig, 'Missing job queue config'); - - const { dbConnectionString, maxCompletionLagInSecs } = jobQueueConfig; - assert(dbConnectionString, 'Missing job queue db connection string'); - - const jobQueue = new JobQueue({ dbConnectionString, maxCompletionLag: maxCompletionLagInSecs }); - await jobQueue.start(); + const createCheckpointCmd = new CreateCheckpointCmd(); + const config: Config = await createCheckpointCmd.initConfig(argv.configFile); const { uniWatcher, tokenWatcher @@ -56,12 +39,6 @@ export const handler = async (argv: any): Promise => { const uniClient = new UniClient(uniWatcher); const erc20Client = new ERC20Client(tokenWatcher); - const indexer = new Indexer(config.server, db, { uniClient, erc20Client, ethClient }, ethProvider, jobQueue); - await indexer.init(); - - const blockHash = await indexer.processCLICheckpoint(argv.address, argv.blockHash); - - log(`Created a checkpoint for contract ${argv.address} at block-hash ${blockHash}`); - - await db.close(); + await createCheckpointCmd.init(argv, Database, Indexer, { uniClient, erc20Client }); + await createCheckpointCmd.exec(); }; diff --git a/packages/uni-watcher/src/indexer.ts b/packages/uni-watcher/src/indexer.ts index aa2ae8c1..d9edb91e 100644 --- a/packages/uni-watcher/src/indexer.ts +++ b/packages/uni-watcher/src/indexer.ts @@ -133,6 +133,11 @@ export class Indexer implements IndexerInterface { // TODO Implement } + async processCLICheckpoint (contractAddress: string, blockHash?: string): Promise { + // TODO Implement + return ''; + } + parseEventNameAndArgs (kind: string, logObj: any): any { let eventName = UNKNOWN_EVENT_NAME; let eventInfo = {}; From 960bdc43882c787d2ecbb8842fdc15c60ccd6040 Mon Sep 17 00:00:00 2001 From: prathamesh0 Date: Mon, 21 Nov 2022 19:23:38 +0530 Subject: [PATCH 2/2] Use existing entity list for fill state CLI --- packages/uni-info-watcher/src/cli/fill-state.ts | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/packages/uni-info-watcher/src/cli/fill-state.ts b/packages/uni-info-watcher/src/cli/fill-state.ts index 6a3589c4..114b2470 100644 --- a/packages/uni-info-watcher/src/cli/fill-state.ts +++ b/packages/uni-info-watcher/src/cli/fill-state.ts @@ -9,13 +9,11 @@ import { Between } from 'typeorm'; import { prepareEntityState } from '@cerc-io/graph-node'; import { Indexer } from '../indexer'; -import { Database } from '../database'; +import { Database, ENTITIES } from '../database'; import { FACTORY_ADDRESS } from '../utils/constants'; const log = debug('vulcanize:fill-state'); -const ENTITY_NAMES = ['Bundle', 'Burn', 'Factory', 'Mint', 'Pool', 'PoolDayData', 'PoolHourData', 'Position', 'PositionSnapshot', 'Swap', 'Tick', 'TickDayData', 'Token', 'TokenDayData', 'TokenHourData', 'Transaction', 'UniswapDayData']; - export const fillState = async ( indexer: Indexer, db: Database, @@ -42,10 +40,11 @@ export const fillState = async ( // Map: contractAddress -> entity names // Using Factory contract to store state for all entities. + const entityNames = [...ENTITIES].map(entity => entity.name); const contractEntitiesMap: Map = new Map([ [ FACTORY_ADDRESS, - ENTITY_NAMES + entityNames ] ]);