diff --git a/packages/indexer-agent/src/commands/start.ts b/packages/indexer-agent/src/commands/start.ts index 2c8e95162..e8fa64abf 100644 --- a/packages/indexer-agent/src/commands/start.ts +++ b/packages/indexer-agent/src/commands/start.ts @@ -233,6 +233,11 @@ export const start = { default: true, group: 'Cost Models', }) + .option('address-book', { + description: 'Graph contracts address book file path', + type: 'string', + required: false, + }) .option('dai-contract', { description: 'Address of the DAI or USDC contract to use for the --inject-dai conversion rate', @@ -421,6 +426,7 @@ export async function createNetworkSpecification( transactionMonitoring, subgraphs, networkProvider, + addressBook: argv.addressBook, dai, }) } catch (parsingError) { diff --git a/packages/indexer-common/src/network-specification.ts b/packages/indexer-common/src/network-specification.ts index 620c7a39a..1fef4b766 100644 --- a/packages/indexer-common/src/network-specification.ts +++ b/packages/indexer-common/src/network-specification.ts @@ -143,6 +143,7 @@ export const NetworkSpecification = z transactionMonitoring: TransactionMonitoring, subgraphs: ProtocolSubgraphs, networkProvider: NetworkProvider, + addressBook: z.string().optional(), dai: Dai, }) .strict() diff --git a/packages/indexer-common/src/network.ts b/packages/indexer-common/src/network.ts index 0104f8844..7ea861836 100644 --- a/packages/indexer-common/src/network.ts +++ b/packages/indexer-common/src/network.ts @@ -5,6 +5,7 @@ import { SubgraphDeploymentID, connectContracts, Eventual, + AddressBook, } from '@graphprotocol/common-ts' import { INDEXER_ERROR_MESSAGES, @@ -27,6 +28,7 @@ import pRetry from 'p-retry' import { resolveChainId } from './indexer-management' import { monitorEthBalance } from './utils' import { QueryFeeModels } from './query-fees' +import { readFileSync } from 'fs' export class Network { logger: Logger @@ -143,6 +145,7 @@ export class Network { wallet, specification.networkIdentifier, logger, + specification.addressBook, ) // * ----------------------------------------------------------------------- @@ -436,6 +439,7 @@ async function connectToProtocolContracts( wallet: Wallet, networkIdentifier: string, logger: Logger, + addressBook?: string, ): Promise { const numericNetworkId = parseInt(networkIdentifier.split(':')[1]) @@ -450,7 +454,10 @@ async function connectToProtocolContracts( let contracts try { - contracts = await connectContracts(wallet, numericNetworkId, undefined) + const contractAddresses = addressBook + ? (JSON.parse(readFileSync(addressBook).toString()) as AddressBook) + : undefined + contracts = await connectContracts(wallet, numericNetworkId, contractAddresses) } catch (error) { const errorMessage = 'Failed to connect to contracts, please ensure you are using the intended protocol network.' diff --git a/packages/indexer-service/src/commands/start.ts b/packages/indexer-service/src/commands/start.ts index 5bb33ce97..f24fe827d 100644 --- a/packages/indexer-service/src/commands/start.ts +++ b/packages/indexer-service/src/commands/start.ts @@ -6,6 +6,7 @@ import fs from 'fs' import { parse as yaml_parse } from 'yaml' import { + AddressBook, connectContracts, connectDatabase, createLogger, @@ -178,6 +179,11 @@ export default { type: 'string', required: false, }) + .option('address-book', { + description: 'Graph contracts address book file path', + type: 'string', + required: false, + }) .check(argv => { if (!argv['network-subgraph-endpoint'] && !argv['network-subgraph-deployment']) { @@ -337,10 +343,13 @@ export default { let contracts: NetworkContracts | undefined = undefined try { + const addressBook = argv.addressBook + ? (JSON.parse(fs.readFileSync(argv.addressBook).toString()) as AddressBook) + : undefined contracts = await connectContracts( networkProvider, networkIdentifier.chainId, - undefined, + addressBook, ) } catch (error) { logger.error(