Skip to content

Commit 7b7c7d2

Browse files
committed
feat: optionally override address book
1 parent dd6fe1b commit 7b7c7d2

File tree

4 files changed

+25
-2
lines changed

4 files changed

+25
-2
lines changed

packages/indexer-agent/src/commands/start.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,11 @@ export const start = {
233233
default: true,
234234
group: 'Cost Models',
235235
})
236+
.option('address-book', {
237+
description: 'Graph contracts address book file path',
238+
type: 'string',
239+
required: false,
240+
})
236241
.option('dai-contract', {
237242
description:
238243
'Address of the DAI or USDC contract to use for the --inject-dai conversion rate',
@@ -421,6 +426,7 @@ export async function createNetworkSpecification(
421426
transactionMonitoring,
422427
subgraphs,
423428
networkProvider,
429+
addressBook: argv.addressBook,
424430
dai,
425431
})
426432
} catch (parsingError) {

packages/indexer-common/src/network-specification.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ export const NetworkSpecification = z
143143
transactionMonitoring: TransactionMonitoring,
144144
subgraphs: ProtocolSubgraphs,
145145
networkProvider: NetworkProvider,
146+
addressBook: z.string().optional(),
146147
dai: Dai,
147148
})
148149
.strict()

packages/indexer-common/src/network.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
SubgraphDeploymentID,
66
connectContracts,
77
Eventual,
8+
AddressBook,
89
} from '@graphprotocol/common-ts'
910
import {
1011
INDEXER_ERROR_MESSAGES,
@@ -27,6 +28,7 @@ import pRetry from 'p-retry'
2728
import { resolveChainId } from './indexer-management'
2829
import { monitorEthBalance } from './utils'
2930
import { QueryFeeModels } from './query-fees'
31+
import { readFileSync } from 'fs'
3032

3133
export class Network {
3234
logger: Logger
@@ -143,6 +145,7 @@ export class Network {
143145
wallet,
144146
specification.networkIdentifier,
145147
logger,
148+
specification.addressBook,
146149
)
147150

148151
// * -----------------------------------------------------------------------
@@ -436,6 +439,7 @@ async function connectToProtocolContracts(
436439
wallet: Wallet,
437440
networkIdentifier: string,
438441
logger: Logger,
442+
addressBook?: string,
439443
): Promise<NetworkContracts> {
440444
const numericNetworkId = parseInt(networkIdentifier.split(':')[1])
441445

@@ -450,7 +454,10 @@ async function connectToProtocolContracts(
450454

451455
let contracts
452456
try {
453-
contracts = await connectContracts(wallet, numericNetworkId, undefined)
457+
const contractAddresses = addressBook
458+
? (JSON.parse(readFileSync(addressBook).toString()) as AddressBook)
459+
: undefined
460+
contracts = await connectContracts(wallet, numericNetworkId, contractAddresses)
454461
} catch (error) {
455462
const errorMessage =
456463
'Failed to connect to contracts, please ensure you are using the intended protocol network.'

packages/indexer-service/src/commands/start.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ const SUGGESTED_SUBGRAPH_MAX_BLOCK_DISTANCE_ON_L2 =
1111
const DEFAULT_SUBGRAPH_FRESHNESS_SLEEP_MILLISECONDS = 5_000
1212

1313
import {
14+
AddressBook,
1415
connectContracts,
1516
connectDatabase,
1617
createLogger,
@@ -194,6 +195,11 @@ export default {
194195
default: DEFAULT_SUBGRAPH_FRESHNESS_SLEEP_MILLISECONDS,
195196
group: 'Protocol',
196197
})
198+
.option('address-book', {
199+
description: 'Graph contracts address book file path',
200+
type: 'string',
201+
required: false,
202+
})
197203

198204
.check(argv => {
199205
if (!argv['network-subgraph-endpoint'] && !argv['network-subgraph-deployment']) {
@@ -393,10 +399,13 @@ export default {
393399

394400
let contracts = undefined
395401
try {
402+
const addressBook = argv.addressBook
403+
? (JSON.parse(fs.readFileSync(argv.addressBook).toString()) as AddressBook)
404+
: undefined
396405
contracts = await connectContracts(
397406
networkProvider,
398407
networkIdentifier.chainId,
399-
undefined,
408+
addressBook,
400409
)
401410
} catch (error) {
402411
logger.error(

0 commit comments

Comments
 (0)