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

Remove graph-node dependency in uniswap-watcher #414

Merged
merged 2 commits into from
Nov 25, 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
34 changes: 5 additions & 29 deletions packages/erc20-watcher/src/cli/reset-cmds/watcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,11 @@
// Copyright 2021 Vulcanize, Inc.
//

import debug from 'debug';
import assert from 'assert';

import { JobQueue, resetJobs, getConfig, initClients } from '@cerc-io/util';
import { Config } from '@vulcanize/util';
import { ResetWatcherCmd } from '@cerc-io/cli';

import { Database } from '../../database';
import { Indexer } from '../../indexer';

const log = debug('vulcanize:reset-watcher');

export const command = 'watcher';

export const desc = 'Reset watcher to a block number';
Expand All @@ -24,27 +18,9 @@ export const builder = {
};

export const handler = async (argv: any): Promise<void> => {
const config: Config = await getConfig(argv.configFile);
await resetJobs(config);
const { jobQueue: jobQueueConfig } = config;
const { ethClient, ethProvider } = await initClients(config);

// Initialize database.
const db = new Database(config.database);
await db.init();

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 });

const indexer = new Indexer(config.server, db, { ethClient }, ethProvider, jobQueue);

const syncStatus = await indexer.getSyncStatus();
assert(syncStatus, 'Missing syncStatus');
const resetWatcherCmd = new ResetWatcherCmd();
await resetWatcherCmd.init(argv, Database);
await resetWatcherCmd.initIndexer(Indexer);

await indexer.resetWatcherToBlock(argv.blockNumber);
log('Reset watcher successfully');
await resetWatcherCmd.exec();
};
3 changes: 2 additions & 1 deletion packages/erc20-watcher/src/cli/watch-contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ const log = debug('vulcanize:watch-contract');

const main = async (): Promise<void> => {
const watchContractCmd = new WatchContractCmd();
await watchContractCmd.init(Database, Indexer);
await watchContractCmd.init(Database);
await watchContractCmd.initIndexer(Indexer);

await watchContractCmd.exec();
};
Expand Down
3 changes: 2 additions & 1 deletion packages/erc20-watcher/src/fill.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ const log = debug('vulcanize:server');

export const main = async (): Promise<any> => {
const fillCmd = new FillCmd();
await fillCmd.init(Database, Indexer, EventWatcher);
await fillCmd.init(Database);
await fillCmd.initIndexer(Indexer, EventWatcher);

await fillCmd.exec();
};
Expand Down
3 changes: 2 additions & 1 deletion packages/erc20-watcher/src/job-runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ export const main = async (): Promise<any> => {
const jobRunnerCmd = new JobRunnerCmd();

const config: Config = await jobRunnerCmd.initConfig();
await jobRunnerCmd.init(Database, Indexer);
await jobRunnerCmd.init(Database);
await jobRunnerCmd.initIndexer(Indexer);

const jobQueue = jobRunnerCmd.jobQueue;
const indexer = jobRunnerCmd.indexer as Indexer;
Expand Down
3 changes: 2 additions & 1 deletion packages/erc20-watcher/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ const log = debug('vulcanize:server');

export const main = async (): Promise<any> => {
const serverCmd = new ServerCmd();
await serverCmd.init(Database, Indexer, EventWatcher);
await serverCmd.init(Database);
await serverCmd.initIndexer(Indexer, EventWatcher);

return serverCmd.exec(createResolvers, typeDefs);
};
Expand Down
3 changes: 2 additions & 1 deletion packages/uni-info-watcher/src/cli/checkpoint-cmds/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ export const handler = async (argv: any): Promise<void> => {

const uniClient = new UniClient(uniWatcher);
const erc20Client = new ERC20Client(tokenWatcher);
await createCheckpointCmd.init(argv, Database, { uniClient, erc20Client });

await createCheckpointCmd.init(argv, Database, Indexer, { uniClient, erc20Client });
await createCheckpointCmd.initIndexer(Indexer);
await createCheckpointCmd.exec();
};
3 changes: 2 additions & 1 deletion packages/uni-info-watcher/src/cli/export-state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ const main = async (): Promise<void> => {
const uniClient = new UniClient(uniWatcher);
const erc20Client = new ERC20Client(tokenWatcher);

await exportStateCmd.init(Database, Indexer, { uniClient, erc20Client });
await exportStateCmd.init(Database, { uniClient, erc20Client });
await exportStateCmd.initIndexer(Indexer);
await exportStateCmd.exec();
};

Expand Down
3 changes: 2 additions & 1 deletion packages/uni-info-watcher/src/cli/import-state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ export const main = async (): Promise<any> => {
const uniClient = new UniClient(uniWatcher);
const erc20Client = new ERC20Client(tokenWatcher);

await importStateCmd.init(Database, Indexer, EventWatcher, { uniClient, erc20Client });
await importStateCmd.init(Database, { uniClient, erc20Client });
await importStateCmd.initIndexer(Indexer, EventWatcher);
await importStateCmd.exec(State);
};

Expand Down
3 changes: 2 additions & 1 deletion packages/uni-info-watcher/src/cli/inspect-cid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ const main = async (): Promise<void> => {
const uniClient = new UniClient(uniWatcher);
const erc20Client = new ERC20Client(tokenWatcher);

await inspectCIDCmd.init(Database, Indexer, { uniClient, erc20Client });
await inspectCIDCmd.init(Database, { uniClient, erc20Client });
await inspectCIDCmd.initIndexer(Indexer);
await inspectCIDCmd.exec();
};

Expand Down
3 changes: 2 additions & 1 deletion packages/uni-info-watcher/src/cli/reset-cmds/watcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export const handler = async (argv: any): Promise<void> => {
const uniClient = new UniClient(uniWatcher);
const erc20Client = new ERC20Client(tokenWatcher);

await resetWatcherCmd.init(argv, Database, Indexer, { uniClient, erc20Client });
await resetWatcherCmd.init(argv, Database, { uniClient, erc20Client });
await resetWatcherCmd.initIndexer(Indexer);
await resetWatcherCmd.exec();
};
3 changes: 2 additions & 1 deletion packages/uni-info-watcher/src/cli/watch-contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ const main = async (): Promise<void> => {
const uniClient = new UniClient(uniWatcher);
const erc20Client = new ERC20Client(tokenWatcher);

await watchContractCmd.init(Database, Indexer, { uniClient, erc20Client });
await watchContractCmd.init(Database, { uniClient, erc20Client });
await watchContractCmd.initIndexer(Indexer);
await watchContractCmd.exec();
};

Expand Down
5 changes: 3 additions & 2 deletions packages/uni-info-watcher/src/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@ import {
BlockHeight,
QueryOptions,
Where,
ServerConfig
ServerConfig,
GraphDatabase,
ENTITY_QUERY_TYPE
} from '@cerc-io/util';
import { Database as GraphDatabase, ENTITY_QUERY_TYPE } from '@cerc-io/graph-node';

import { Factory } from './entity/Factory';
import { Pool } from './entity/Pool';
Expand Down
2 changes: 1 addition & 1 deletion packages/uni-info-watcher/src/entity/Subscriber.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import { EventSubscriber, EntitySubscriberInterface, InsertEvent, UpdateEvent } from 'typeorm';
import _ from 'lodash';

import { afterEntityInsertOrUpdate } from '@cerc-io/graph-node';
import { afterEntityInsertOrUpdate } from '@cerc-io/util';

import { FrothyEntity } from './FrothyEntity';
import { ENTITIES, ENTITY_TO_LATEST_ENTITY_MAP } from '../database';
Expand Down
3 changes: 2 additions & 1 deletion packages/uni-info-watcher/src/fill.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ export const main = async (): Promise<any> => {
const uniClient = new UniClient(uniWatcher);
const erc20Client = new ERC20Client(tokenWatcher);

await fillCmd.init(Database, Indexer, EventWatcher, { uniClient, erc20Client });
await fillCmd.init(Database, { uniClient, erc20Client });
await fillCmd.initIndexer(Indexer, EventWatcher);

await fillCmd.exec(getContractEntitiesMap());
};
Expand Down
5 changes: 3 additions & 2 deletions packages/uni-info-watcher/src/indexer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,10 @@ import {
JobQueue,
GraphDecimal,
DatabaseInterface,
Clients
Clients,
updateSubgraphState,
dumpSubgraphState
} from '@cerc-io/util';
import { updateSubgraphState, dumpSubgraphState } from '@cerc-io/graph-node';
import { EthClient } from '@cerc-io/ipld-eth-client';
import { StorageLayout, MappingKey } from '@cerc-io/solidity-mapper';

Expand Down
3 changes: 2 additions & 1 deletion packages/uni-info-watcher/src/job-runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ export const main = async (): Promise<any> => {
const uniClient = new UniClient(uniWatcher);
const erc20Client = new ERC20Client(tokenWatcher);

await jobRunnerCmd.init(Database, Indexer, { uniClient, erc20Client });
await jobRunnerCmd.init(Database, { uniClient, erc20Client });
await jobRunnerCmd.initIndexer(Indexer);

const jobQueue = jobRunnerCmd.jobQueue;
const indexer = jobRunnerCmd.indexer as Indexer;
Expand Down
3 changes: 2 additions & 1 deletion packages/uni-info-watcher/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ export const main = async (): Promise<any> => {
const uniClient = new UniClient(uniWatcher);
const erc20Client = new ERC20Client(tokenWatcher);

await serverCmd.init(Database, Indexer, EventWatcher, { uniClient, erc20Client });
await serverCmd.init(Database, { uniClient, erc20Client });
await serverCmd.initIndexer(Indexer, EventWatcher);

return serverCmd.exec(createResolvers, typeDefs);
};
Expand Down
3 changes: 2 additions & 1 deletion packages/uni-watcher/src/cli/reset-cmds/watcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ export const builder = {

export const handler = async (argv: any): Promise<void> => {
const resetWatcherCmd = new ResetWatcherCmd();
await resetWatcherCmd.init(argv, Database, Indexer);
await resetWatcherCmd.init(argv, Database);
await resetWatcherCmd.initIndexer(Indexer);

await resetWatcherCmd.exec();
};
3 changes: 2 additions & 1 deletion packages/uni-watcher/src/cli/watch-contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ const log = debug('vulcanize:watch-contract');

const main = async (): Promise<void> => {
const watchContractCmd = new WatchContractCmd();
await watchContractCmd.init(Database, Indexer);
await watchContractCmd.init(Database);
await watchContractCmd.initIndexer(Indexer);

await watchContractCmd.exec();
};
Expand Down
3 changes: 2 additions & 1 deletion packages/uni-watcher/src/fill.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ const log = debug('vulcanize:server');

export const main = async (): Promise<any> => {
const fillCmd = new FillCmd();
await fillCmd.init(Database, Indexer, EventWatcher);
await fillCmd.init(Database);
await fillCmd.initIndexer(Indexer, EventWatcher);

await fillCmd.exec();
};
Expand Down
3 changes: 2 additions & 1 deletion packages/uni-watcher/src/job-runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ export const main = async (): Promise<any> => {
const jobRunnerCmd = new JobRunnerCmd();

const config: Config = await jobRunnerCmd.initConfig();
await jobRunnerCmd.init(Database, Indexer);
await jobRunnerCmd.init(Database);
await jobRunnerCmd.initIndexer(Indexer);

const jobQueue = jobRunnerCmd.jobQueue;
const indexer = jobRunnerCmd.indexer as Indexer;
Expand Down
3 changes: 2 additions & 1 deletion packages/uni-watcher/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ const log = debug('vulcanize:server');

export const main = async (): Promise<any> => {
const serverCmd = new ServerCmd();
await serverCmd.init(Database, Indexer, EventWatcher);
await serverCmd.init(Database);
await serverCmd.initIndexer(Indexer, EventWatcher);

return serverCmd.exec(createResolvers, typeDefs);
};
Expand Down