Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use checkpoint CLI from cli package #404

Merged
merged 2 commits into from
Nov 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions packages/erc20-watcher/src/indexer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,11 @@ export class Indexer implements IndexerInterface {
// TODO Implement
}

async processCLICheckpoint (contractAddress: string, blockHash?: string): Promise<string | undefined> {
// TODO Implement
return '';
}

parseEventNameAndArgs (kind: string, logObj: any): any {
let eventName = UNKNOWN_EVENT_NAME;
let eventInfo = {};
Expand Down
35 changes: 6 additions & 29 deletions packages/uni-info-watcher/src/cli/checkpoint-cmds/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -33,21 +28,9 @@ export const builder = {
};

export const handler = async (argv: any): Promise<void> => {
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
Expand All @@ -56,12 +39,6 @@ export const handler = async (argv: any): Promise<void> => {
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();
};
7 changes: 3 additions & 4 deletions packages/uni-info-watcher/src/cli/fill-state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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<string, string[]> = new Map([
[
FACTORY_ADDRESS,
ENTITY_NAMES
entityNames
]
]);

Expand Down
5 changes: 5 additions & 0 deletions packages/uni-watcher/src/indexer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,11 @@ export class Indexer implements IndexerInterface {
// TODO Implement
}

async processCLICheckpoint (contractAddress: string, blockHash?: string): Promise<string | undefined> {
// TODO Implement
return '';
}

parseEventNameAndArgs (kind: string, logObj: any): any {
let eventName = UNKNOWN_EVENT_NAME;
let eventInfo = {};
Expand Down