Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(contracts): optionally override address book #114

Merged
merged 2 commits into from
Nov 14, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions packages/common-ts/src/contracts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import { L1GraphTokenGateway__factory } from '@graphprotocol/contracts/dist/type
import { BridgeEscrow__factory } from '@graphprotocol/contracts/dist/types/factories/BridgeEscrow__factory'
import { L2GraphToken__factory } from '@graphprotocol/contracts/dist/types/factories/L2GraphToken__factory'
import { L2GraphTokenGateway__factory } from '@graphprotocol/contracts/dist/types/factories/L2GraphTokenGateway__factory'
import { readFileSync } from 'fs'

export const GraphChain = graphChain

Expand Down Expand Up @@ -74,9 +75,13 @@ export interface NetworkContracts {
export const connectContracts = async (
providerOrSigner: providers.Provider | Signer,
chainId: number,
addressBook?: string,
): Promise<NetworkContracts> => {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const deployedContracts = (DEPLOYED_CONTRACTS as any)[`${chainId}`]
const deployedContracts = addressBook
? // eslint-disable-next-line @typescript-eslint/no-explicit-any
JSON.parse(readFileSync(addressBook).toString())[`${chainId}`]
: // eslint-disable-next-line @typescript-eslint/no-explicit-any
(DEPLOYED_CONTRACTS as any)[`${chainId}`]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if I like the fact that a file is read inside connectContracts. Wouldn't it be cleaner to pass in a map and do the file loading outside this function?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

if (!deployedContracts) {
throw new Error(`chainId: '${chainId}' has no deployed contracts`)
}
Expand Down
Loading