diff --git a/packages/common-ts/src/contracts/index.test.ts b/packages/common-ts/src/contracts/index.test.ts index 267c509..e6cfde1 100644 --- a/packages/common-ts/src/contracts/index.test.ts +++ b/packages/common-ts/src/contracts/index.test.ts @@ -1,5 +1,6 @@ import { Signer } from 'ethers' import { connectContracts } from '.' +import * as DEPLOYED_CONTRACTS from '@graphprotocol/contracts/addresses.json' jest.mock('ethers') @@ -8,7 +9,7 @@ const mockSigner = jest.fn() as unknown as Signer describe('Contracts', () => { // Test for each supported protocol network test.each([1, 5, 42161, 421613])('Connect contracts [chainId: %p]', chainId => { - const contracts = connectContracts(mockSigner, chainId) + const contracts = connectContracts(mockSigner, chainId, DEPLOYED_CONTRACTS) expect(contracts).toBeDefined() }) }) diff --git a/packages/common-ts/src/contracts/index.ts b/packages/common-ts/src/contracts/index.ts index a43c8af..d0fae50 100644 --- a/packages/common-ts/src/contracts/index.ts +++ b/packages/common-ts/src/contracts/index.ts @@ -1,9 +1,6 @@ import { providers, Signer } from 'ethers' import graphChain from './chain' -// Contract addresses -import * as DEPLOYED_CONTRACTS from '@graphprotocol/contracts/addresses.json' - // Contract ABIs import { Curation } from '@graphprotocol/contracts/dist/types/Curation' import { DisputeManager } from '@graphprotocol/contracts/dist/types/DisputeManager' @@ -71,12 +68,14 @@ export interface NetworkContracts { l2GraphTokenGateway?: L2GraphTokenGateway } +export type AddressBook = { [key: string]: { [key: string]: { address: string } } } + export const connectContracts = async ( providerOrSigner: providers.Provider | Signer, chainId: number, + addressBook: AddressBook, ): Promise => { - // eslint-disable-next-line @typescript-eslint/no-explicit-any - const deployedContracts = (DEPLOYED_CONTRACTS as any)[`${chainId}`] + const deployedContracts = addressBook[`${chainId}`] if (!deployedContracts) { throw new Error(`chainId: '${chainId}' has no deployed contracts`) }