1
1
import { providers , Signer } from 'ethers'
2
+ import graphChain from './chain'
2
3
3
4
// Contract addresses
4
5
import * as DEPLOYED_CONTRACTS from '@graphprotocol/contracts/addresses.json'
@@ -14,6 +15,15 @@ import { Staking } from '@graphprotocol/contracts/dist/types/Staking'
14
15
import { GraphToken } from '@graphprotocol/contracts/dist/types/GraphToken'
15
16
import { Controller } from '@graphprotocol/contracts/dist/types/Controller'
16
17
import { AllocationExchange } from '@graphprotocol/contracts/dist/types/AllocationExchange'
18
+ import { GraphProxyAdmin } from '@graphprotocol/contracts/dist/types/GraphProxyAdmin'
19
+ import { SubgraphNFT } from '@graphprotocol/contracts/dist/types/SubgraphNFT'
20
+ import { GraphCurationToken } from '@graphprotocol/contracts/dist/types/GraphCurationToken'
21
+ import { L1GraphTokenGateway } from '@graphprotocol/contracts/dist/types/L1GraphTokenGateway'
22
+ import { L1Reservoir } from '@graphprotocol/contracts/dist/types/L1Reservoir'
23
+ import { BridgeEscrow } from '@graphprotocol/contracts/dist/types/BridgeEscrow'
24
+ import { L2GraphToken } from '@graphprotocol/contracts/dist/types/L2GraphToken'
25
+ import { L2GraphTokenGateway } from '@graphprotocol/contracts/dist/types/L2GraphTokenGateway'
26
+ import { L2Reservoir } from '@graphprotocol/contracts/dist/types/L2Reservoir'
17
27
18
28
// Contract factories
19
29
import { Curation__factory } from '@graphprotocol/contracts/dist/types/factories/Curation__factory'
@@ -26,6 +36,17 @@ import { Staking__factory } from '@graphprotocol/contracts/dist/types/factories/
26
36
import { GraphToken__factory } from '@graphprotocol/contracts/dist/types/factories/GraphToken__factory'
27
37
import { Controller__factory } from '@graphprotocol/contracts/dist/types/factories/Controller__factory'
28
38
import { AllocationExchange__factory } from '@graphprotocol/contracts/dist/types/factories/AllocationExchange__factory'
39
+ import { GraphProxyAdmin__factory } from '@graphprotocol/contracts/dist/types/factories/GraphProxyAdmin__factory'
40
+ import { SubgraphNFT__factory } from '@graphprotocol/contracts/dist/types/factories/SubgraphNFT__factory'
41
+ import { GraphCurationToken__factory } from '@graphprotocol/contracts/dist/types/factories/GraphCurationToken__factory'
42
+ import { L1GraphTokenGateway__factory } from '@graphprotocol/contracts/dist/types/factories/L1GraphTokenGateway__factory'
43
+ import { L1Reservoir__factory } from '@graphprotocol/contracts/dist/types/factories/L1Reservoir__factory'
44
+ import { BridgeEscrow__factory } from '@graphprotocol/contracts/dist/types/factories/BridgeEscrow__factory'
45
+ import { L2GraphToken__factory } from '@graphprotocol/contracts/dist/types/factories/L2GraphToken__factory'
46
+ import { L2GraphTokenGateway__factory } from '@graphprotocol/contracts/dist/types/factories/L2GraphTokenGateway__factory'
47
+ import { L2Reservoir__factory } from '@graphprotocol/contracts/dist/types/factories/L2Reservoir__factory'
48
+
49
+ export const GraphChain = graphChain
29
50
30
51
export interface NetworkContracts {
31
52
curation : Curation
@@ -35,9 +56,21 @@ export interface NetworkContracts {
35
56
rewardsManager : RewardsManager
36
57
serviceRegistry : ServiceRegistry
37
58
staking : Staking
38
- token : GraphToken
59
+ token : GraphToken | L2GraphToken
39
60
controller : Controller
40
61
allocationExchange : AllocationExchange
62
+ graphProxyAdmin : GraphProxyAdmin
63
+ subgraphNFT : SubgraphNFT
64
+ graphCurationToken : GraphCurationToken
65
+
66
+ // Only L1
67
+ l1GraphTokenGateway ?: L1GraphTokenGateway
68
+ l1Reservoir ?: L1Reservoir
69
+ bridgeEscrow ?: BridgeEscrow
70
+
71
+ // Only L2
72
+ l2GraphTokenGateway ?: L2GraphTokenGateway
73
+ l2Reservoir ?: L2Reservoir
41
74
}
42
75
43
76
export const connectContracts = async (
@@ -46,7 +79,16 @@ export const connectContracts = async (
46
79
) : Promise < NetworkContracts > => {
47
80
// eslint-disable-next-line @typescript-eslint/no-explicit-any
48
81
const deployedContracts = ( DEPLOYED_CONTRACTS as any ) [ `${ chainId } ` ]
49
- return {
82
+
83
+ const GraphTokenFactory = GraphChain . isL1 ( chainId )
84
+ ? GraphToken__factory
85
+ : L2GraphToken__factory
86
+
87
+ const graphTokenAddress = GraphChain . isL1 ( chainId )
88
+ ? deployedContracts . GraphToken . address
89
+ : deployedContracts . L2GraphToken . address
90
+
91
+ const contracts : NetworkContracts = {
50
92
curation : Curation__factory . connect (
51
93
deployedContracts . Curation . address ,
52
94
providerOrSigner ,
@@ -72,8 +114,8 @@ export const connectContracts = async (
72
114
deployedContracts . Staking . address ,
73
115
providerOrSigner ,
74
116
) ,
75
- token : GraphToken__factory . connect (
76
- deployedContracts . GraphToken . address ,
117
+ token : GraphTokenFactory . connect (
118
+ graphTokenAddress ,
77
119
providerOrSigner ,
78
120
) ,
79
121
controller : Controller__factory . connect (
@@ -84,5 +126,46 @@ export const connectContracts = async (
84
126
deployedContracts . AllocationExchange . address ,
85
127
providerOrSigner ,
86
128
) ,
129
+ graphProxyAdmin : GraphProxyAdmin__factory . connect (
130
+ deployedContracts . GraphProxyAdmin . address ,
131
+ providerOrSigner ,
132
+ ) ,
133
+ subgraphNFT : SubgraphNFT__factory . connect (
134
+ deployedContracts . SubgraphNFT . address ,
135
+ providerOrSigner ,
136
+ ) ,
137
+ graphCurationToken : GraphCurationToken__factory . connect (
138
+ deployedContracts . GraphCurationToken . address ,
139
+ providerOrSigner ,
140
+ ) ,
87
141
}
142
+
143
+ if ( GraphChain . isL1 ( chainId ) ) {
144
+ contracts . l1GraphTokenGateway = L1GraphTokenGateway__factory . connect (
145
+ deployedContracts . L1GraphTokenGateway . address ,
146
+ providerOrSigner ,
147
+ )
148
+ contracts . bridgeEscrow = BridgeEscrow__factory . connect (
149
+ deployedContracts . BridgeEscrow . address ,
150
+ providerOrSigner ,
151
+ )
152
+ // L1Reservoir is not deployed on scratch1
153
+ if ( deployedContracts . L1Reservoir ) {
154
+ contracts . l1Reservoir = L1Reservoir__factory . connect (
155
+ deployedContracts . L1Reservoir . address ,
156
+ providerOrSigner ,
157
+ )
158
+ }
159
+ } else if ( GraphChain . isL2 ( chainId ) ) {
160
+ contracts . l2GraphTokenGateway = L2GraphTokenGateway__factory . connect (
161
+ deployedContracts . L2GraphTokenGateway . address ,
162
+ providerOrSigner ,
163
+ )
164
+ contracts . l2Reservoir = L2Reservoir__factory . connect (
165
+ deployedContracts . L2Reservoir . address ,
166
+ providerOrSigner ,
167
+ )
168
+ }
169
+
170
+ return contracts
88
171
}
0 commit comments