Skip to content

Commit

Permalink
feat: optionally override address book
Browse files Browse the repository at this point in the history
  • Loading branch information
Theodus committed Nov 21, 2023
1 parent dd6fe1b commit 7b7c7d2
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 2 deletions.
6 changes: 6 additions & 0 deletions packages/indexer-agent/src/commands/start.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -421,6 +426,7 @@ export async function createNetworkSpecification(
transactionMonitoring,
subgraphs,
networkProvider,
addressBook: argv.addressBook,
dai,
})
} catch (parsingError) {
Expand Down
1 change: 1 addition & 0 deletions packages/indexer-common/src/network-specification.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ export const NetworkSpecification = z
transactionMonitoring: TransactionMonitoring,
subgraphs: ProtocolSubgraphs,
networkProvider: NetworkProvider,
addressBook: z.string().optional(),
dai: Dai,
})
.strict()
Expand Down
9 changes: 8 additions & 1 deletion packages/indexer-common/src/network.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
SubgraphDeploymentID,
connectContracts,
Eventual,
AddressBook,
} from '@graphprotocol/common-ts'
import {
INDEXER_ERROR_MESSAGES,
Expand All @@ -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
Expand Down Expand Up @@ -143,6 +145,7 @@ export class Network {
wallet,
specification.networkIdentifier,
logger,
specification.addressBook,
)

// * -----------------------------------------------------------------------
Expand Down Expand Up @@ -436,6 +439,7 @@ async function connectToProtocolContracts(
wallet: Wallet,
networkIdentifier: string,
logger: Logger,
addressBook?: string,
): Promise<NetworkContracts> {
const numericNetworkId = parseInt(networkIdentifier.split(':')[1])

Expand All @@ -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.'
Expand Down
11 changes: 10 additions & 1 deletion packages/indexer-service/src/commands/start.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const SUGGESTED_SUBGRAPH_MAX_BLOCK_DISTANCE_ON_L2 =
const DEFAULT_SUBGRAPH_FRESHNESS_SLEEP_MILLISECONDS = 5_000

import {
AddressBook,
connectContracts,
connectDatabase,
createLogger,
Expand Down Expand Up @@ -194,6 +195,11 @@ export default {
default: DEFAULT_SUBGRAPH_FRESHNESS_SLEEP_MILLISECONDS,
group: 'Protocol',
})
.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']) {
Expand Down Expand Up @@ -393,10 +399,13 @@ export default {

let contracts = 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(
Expand Down

0 comments on commit 7b7c7d2

Please sign in to comment.