From f89a7a07aaf316d1890529dc25fcb2526219cb95 Mon Sep 17 00:00:00 2001 From: prathamesh0 <42446521+prathamesh0@users.noreply.github.com> Date: Mon, 6 Dec 2021 17:22:09 +0530 Subject: [PATCH] Use eth client for getStorageAt query (#302) --- .../codegen/src/templates/indexer-template.handlebars | 2 +- packages/erc20-watcher/src/indexer.ts | 2 +- packages/uni-info-watcher/src/cli/reset-cmds/state.ts | 4 ++-- packages/uni-info-watcher/src/fill.ts | 3 ++- packages/uni-info-watcher/src/indexer.ts | 6 ++++-- packages/uni-info-watcher/src/job-runner.ts | 10 +++++++++- packages/uni-info-watcher/src/server.ts | 2 +- packages/uni-watcher/src/indexer.ts | 2 +- packages/util/src/indexer.ts | 8 +++++--- 9 files changed, 26 insertions(+), 13 deletions(-) diff --git a/packages/codegen/src/templates/indexer-template.handlebars b/packages/codegen/src/templates/indexer-template.handlebars index 933c381b..f1012283 100644 --- a/packages/codegen/src/templates/indexer-template.handlebars +++ b/packages/codegen/src/templates/indexer-template.handlebars @@ -69,7 +69,7 @@ export class Indexer { this._ethClient = ethClient; this._postgraphileClient = postgraphileClient; this._ethProvider = ethProvider; - this._baseIndexer = new BaseIndexer(this._db, this._postgraphileClient, this._ethProvider); + this._baseIndexer = new BaseIndexer(this._db, this._ethClient, this._postgraphileClient, this._ethProvider); const { abi, storageLayout } = artifacts; diff --git a/packages/erc20-watcher/src/indexer.ts b/packages/erc20-watcher/src/indexer.ts index 6ece8a4e..48915ba9 100644 --- a/packages/erc20-watcher/src/indexer.ts +++ b/packages/erc20-watcher/src/indexer.ts @@ -62,7 +62,7 @@ export class Indexer { this._postgraphileClient = postgraphileClient; this._ethProvider = ethProvider; this._serverMode = serverMode; - this._baseIndexer = new BaseIndexer(this._db, this._postgraphileClient, this._ethProvider); + this._baseIndexer = new BaseIndexer(this._db, this._ethClient, this._postgraphileClient, this._ethProvider); const { abi, storageLayout } = artifacts; diff --git a/packages/uni-info-watcher/src/cli/reset-cmds/state.ts b/packages/uni-info-watcher/src/cli/reset-cmds/state.ts index 0b06b16f..57dcf036 100644 --- a/packages/uni-info-watcher/src/cli/reset-cmds/state.ts +++ b/packages/uni-info-watcher/src/cli/reset-cmds/state.ts @@ -38,7 +38,7 @@ export const builder = { export const handler = async (argv: any): Promise => { const config = await getConfig(argv.configFile); await resetJobs(config); - const { dbConfig, serverConfig, upstreamConfig, postgraphileClient, ethProvider } = await getResetConfig(config); + const { dbConfig, serverConfig, upstreamConfig, ethClient, postgraphileClient, ethProvider } = await getResetConfig(config); // Initialize database. const db = new Database(dbConfig); @@ -52,7 +52,7 @@ export const handler = async (argv: any): Promise => { const uniClient = new UniClient(uniWatcher); const erc20Client = new ERC20Client(tokenWatcher); - const indexer = new Indexer(db, uniClient, erc20Client, postgraphileClient, ethProvider, serverConfig.mode); + const indexer = new Indexer(db, uniClient, erc20Client, ethClient, postgraphileClient, ethProvider, serverConfig.mode); const syncStatus = await indexer.getSyncStatus(); assert(syncStatus, 'Missing syncStatus'); diff --git a/packages/uni-info-watcher/src/fill.ts b/packages/uni-info-watcher/src/fill.ts index e175b80e..79ce104b 100644 --- a/packages/uni-info-watcher/src/fill.ts +++ b/packages/uni-info-watcher/src/fill.ts @@ -63,6 +63,7 @@ export const main = async (): Promise => { assert(gqlPostgraphileEndpoint, 'Missing upstream ethServer.gqlPostgraphileEndpoint'); const cache = await getCache(cacheConfig); + const ethClient = new EthClient({ gqlEndpoint: gqlApiEndpoint, gqlSubscriptionEndpoint: gqlPostgraphileEndpoint, @@ -81,7 +82,7 @@ export const main = async (): Promise => { // Note: In-memory pubsub works fine for now, as each watcher is a single process anyway. // Later: https://www.apollographql.com/docs/apollo-server/data/subscriptions/#production-pubsub-libraries const pubsub = new PubSub(); - const indexer = new Indexer(db, uniClient, erc20Client, postgraphileClient, ethProvider, mode); + const indexer = new Indexer(db, uniClient, erc20Client, ethClient, postgraphileClient, ethProvider, mode); assert(jobQueueConfig, 'Missing job queue config'); const { dbConnectionString, maxCompletionLagInSecs } = jobQueueConfig; diff --git a/packages/uni-info-watcher/src/indexer.ts b/packages/uni-info-watcher/src/indexer.ts index 65569008..1901af5e 100644 --- a/packages/uni-info-watcher/src/indexer.ts +++ b/packages/uni-info-watcher/src/indexer.ts @@ -43,11 +43,12 @@ export class Indexer implements IndexerInterface { _db: Database _uniClient: UniClient _erc20Client: ERC20Client + _ethClient: EthClient _postgraphileClient: EthClient _baseIndexer: BaseIndexer _isDemo: boolean - constructor (db: Database, uniClient: UniClient, erc20Client: ERC20Client, postgraphileClient: EthClient, ethProvider: providers.BaseProvider, mode: string) { + constructor (db: Database, uniClient: UniClient, erc20Client: ERC20Client, ethClient: EthClient, postgraphileClient: EthClient, ethProvider: providers.BaseProvider, mode: string) { assert(db); assert(uniClient); assert(erc20Client); @@ -56,8 +57,9 @@ export class Indexer implements IndexerInterface { this._db = db; this._uniClient = uniClient; this._erc20Client = erc20Client; + this._ethClient = ethClient; this._postgraphileClient = postgraphileClient; - this._baseIndexer = new BaseIndexer(this._db, this._postgraphileClient, ethProvider); + this._baseIndexer = new BaseIndexer(this._db, this._ethClient, this._postgraphileClient, ethProvider); this._isDemo = mode === 'demo'; } diff --git a/packages/uni-info-watcher/src/job-runner.ts b/packages/uni-info-watcher/src/job-runner.ts index ffadaabc..ac4fa153 100644 --- a/packages/uni-info-watcher/src/job-runner.ts +++ b/packages/uni-info-watcher/src/job-runner.ts @@ -101,16 +101,24 @@ export const main = async (): Promise => { tokenWatcher, cache: cacheConfig, ethServer: { + gqlApiEndpoint, gqlPostgraphileEndpoint, rpcProviderEndpoint } } = upstream; + assert(gqlApiEndpoint, 'Missing upstream ethServer.gqlApiEndpoint'); assert(gqlEndpoint, 'Missing upstream uniWatcher.gqlEndpoint'); assert(gqlSubscriptionEndpoint, 'Missing upstream uniWatcher.gqlSubscriptionEndpoint'); const cache = await getCache(cacheConfig); + const ethClient = new EthClient({ + gqlEndpoint: gqlApiEndpoint, + gqlSubscriptionEndpoint: gqlPostgraphileEndpoint, + cache + }); + const postgraphileClient = new EthClient({ gqlEndpoint: gqlPostgraphileEndpoint, cache @@ -124,7 +132,7 @@ export const main = async (): Promise => { const erc20Client = new ERC20Client(tokenWatcher); const ethProvider = getCustomProvider(rpcProviderEndpoint); - const indexer = new Indexer(db, uniClient, erc20Client, postgraphileClient, ethProvider, mode); + const indexer = new Indexer(db, uniClient, erc20Client, ethClient, postgraphileClient, ethProvider, mode); assert(jobQueueConfig, 'Missing job queue config'); diff --git a/packages/uni-info-watcher/src/server.ts b/packages/uni-info-watcher/src/server.ts index fee3fc55..555c5b83 100644 --- a/packages/uni-info-watcher/src/server.ts +++ b/packages/uni-info-watcher/src/server.ts @@ -82,7 +82,7 @@ export const main = async (): Promise => { const uniClient = new UniClient(uniWatcher); const erc20Client = new ERC20Client(tokenWatcher); const ethProvider = getCustomProvider(rpcProviderEndpoint); - const indexer = new Indexer(db, uniClient, erc20Client, postgraphileClient, ethProvider, mode); + const indexer = new Indexer(db, uniClient, erc20Client, ethClient, postgraphileClient, ethProvider, mode); assert(jobQueueConfig, 'Missing job queue config'); diff --git a/packages/uni-watcher/src/indexer.ts b/packages/uni-watcher/src/indexer.ts index a195fe27..e4344ddc 100644 --- a/packages/uni-watcher/src/indexer.ts +++ b/packages/uni-watcher/src/indexer.ts @@ -51,7 +51,7 @@ export class Indexer implements IndexerInterface { this._ethClient = ethClient; this._postgraphileClient = postgraphileClient; this._ethProvider = ethProvider; - this._baseIndexer = new BaseIndexer(this._db, this._postgraphileClient, this._ethProvider); + this._baseIndexer = new BaseIndexer(this._db, this._ethClient, this._postgraphileClient, this._ethProvider); this._factoryContract = new ethers.utils.Interface(factoryABI); this._poolContract = new ethers.utils.Interface(poolABI); diff --git a/packages/util/src/indexer.ts b/packages/util/src/indexer.ts index ce545e6a..47906acf 100644 --- a/packages/util/src/indexer.ts +++ b/packages/util/src/indexer.ts @@ -26,15 +26,17 @@ export interface ValueResult { export class Indexer { _db: DatabaseInterface; + _ethClient: EthClient; _postgraphileClient: EthClient; _getStorageAt: GetStorageAt; _ethProvider: ethers.providers.BaseProvider; - constructor (db: DatabaseInterface, ethClient: EthClient, ethProvider: ethers.providers.BaseProvider) { + constructor (db: DatabaseInterface, ethClient: EthClient, postgraphileClient: EthClient, ethProvider: ethers.providers.BaseProvider) { this._db = db; - this._postgraphileClient = ethClient; + this._ethClient = ethClient; + this._postgraphileClient = postgraphileClient; this._ethProvider = ethProvider; - this._getStorageAt = this._postgraphileClient.getStorageAt.bind(this._postgraphileClient); + this._getStorageAt = this._ethClient.getStorageAt.bind(this._ethClient); } async getSyncStatus (): Promise {