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

Add sepolia support #116

Merged
merged 5 commits into from
Nov 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -104,3 +104,6 @@ dist
.tern-port
.npmrc
.yarnrc

# IDE directories
.idea
1 change: 1 addition & 0 deletions packages/common-ts/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
coverage
.idea
1 change: 1 addition & 0 deletions packages/common-ts/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.idea
2 changes: 1 addition & 1 deletion packages/common-ts/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@graphprotocol/common-ts",
"version": "2.0.7",
"version": "2.0.9",
"description": "Common TypeScript library for Graph Protocol components",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
1 change: 1 addition & 0 deletions packages/common-ts/src/contracts/chain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const chainMap = new MapWithGetKey<number>([
[1, 42161], // Ethereum Mainnet - Arbitrum One
[4, 421611], // Ethereum Rinkeby - Arbitrum Rinkeby
[5, 421613], // Ethereum Goerli - Arbitrum Goerli
[11155111, 421614], // Ethereum Sepolia - Arbitrum Sepolia
[1337, 412346], // Localhost - Arbitrum Localhost
])

Expand Down
18 changes: 14 additions & 4 deletions packages/common-ts/src/contracts/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,18 @@ 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, DEPLOYED_CONTRACTS)
expect(contracts).toBeDefined()
})
test.each([1, 5, 42161, 421613, 421614, 11155111])(
'Connect contracts with explicit addressBook provided [chainId: %p]',
chainId => {
const contracts = connectContracts(mockSigner, chainId, DEPLOYED_CONTRACTS)
expect(contracts).toBeDefined()
},
)
test.each([1, 5, 42161, 421613, 421614, 11155111])(
'Connect contracts without explicit addressBook provided [chainId: %p]',
chainId => {
const contracts = connectContracts(mockSigner, chainId, undefined)
expect(contracts).toBeDefined()
},
)
})
10 changes: 8 additions & 2 deletions packages/common-ts/src/contracts/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
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'
Expand Down Expand Up @@ -73,9 +76,12 @@ export type AddressBook = { [key: string]: { [key: string]: { address: string }
export const connectContracts = async (
providerOrSigner: providers.Provider | Signer,
chainId: number,
addressBook: AddressBook,
addressBook: AddressBook | undefined,
): Promise<NetworkContracts> => {
const deployedContracts = addressBook[`${chainId}`]
const deployedContracts = addressBook
? addressBook[`${chainId}`]
: // eslint-disable-next-line @typescript-eslint/no-explicit-any
(DEPLOYED_CONTRACTS as any)[`${chainId}`]
if (!deployedContracts) {
throw new Error(`chainId: '${chainId}' has no deployed contracts`)
}
Expand Down
Loading