@@ -75,81 +75,101 @@ export const connectContracts = async (
75
75
) : Promise < NetworkContracts > => {
76
76
// eslint-disable-next-line @typescript-eslint/no-explicit-any
77
77
const deployedContracts = ( DEPLOYED_CONTRACTS as any ) [ `${ chainId } ` ]
78
+ if ( ! deployedContracts ) {
79
+ throw new Error ( `chainId: '${ chainId } ' has no deployed contracts` )
80
+ }
81
+
82
+ const getContractAddress = ( contractName : string ) => {
83
+ if ( ! deployedContracts [ contractName ] ) {
84
+ throw new Error (
85
+ `Deployed contract '${ contractName } ' is undefined for chainId: '${ chainId } '` ,
86
+ )
87
+ }
88
+ const address = deployedContracts [ contractName ] . address
89
+ if ( ! address ) {
90
+ throw new Error (
91
+ `Deployed contract '${ contractName } ' address is undefined for chainId: '${ chainId } '` ,
92
+ )
93
+ }
94
+ return address
95
+ }
96
+
78
97
const GraphTokenFactory = GraphChain . isL1 ( chainId )
79
98
? GraphToken__factory
80
99
: L2GraphToken__factory
81
100
82
101
const graphTokenAddress = GraphChain . isL1 ( chainId )
83
- ? deployedContracts . GraphToken . address
84
- : deployedContracts . L2GraphToken . address
102
+ ? getContractAddress ( 'GraphToken' )
103
+ : getContractAddress ( 'L2GraphToken' )
104
+
105
+ const staking = GraphChain . isL1 ( chainId )
106
+ ? IL1Staking__factory . connect ( getContractAddress ( 'L1Staking' ) , providerOrSigner )
107
+ : IL2Staking__factory . connect ( getContractAddress ( 'L2Staking' ) , providerOrSigner )
85
108
86
- const staking = GraphChain . isL1 ( chainId )
87
- ? IL1Staking__factory . connect ( deployedContracts . L1Staking . address , providerOrSigner )
88
- : IL2Staking__factory . connect ( deployedContracts . L2Staking . address , providerOrSigner )
109
+ const gns = GraphChain . isL1 ( chainId )
110
+ ? GNS__factory . connect ( getContractAddress ( 'L1GNS' ) , providerOrSigner )
111
+ : GNS__factory . connect ( getContractAddress ( 'L2GNS' ) , providerOrSigner )
89
112
90
113
const contracts : NetworkContracts = {
91
- curation : Curation__factory . connect (
92
- deployedContracts . Curation . address ,
93
- providerOrSigner ,
94
- ) ,
114
+ curation : Curation__factory . connect ( getContractAddress ( 'Curation' ) , providerOrSigner ) ,
95
115
disputeManager : DisputeManager__factory . connect (
96
- deployedContracts . DisputeManager . address ,
116
+ getContractAddress ( ' DisputeManager' ) ,
97
117
providerOrSigner ,
98
118
) ,
99
119
epochManager : EpochManager__factory . connect (
100
- deployedContracts . EpochManager . address ,
120
+ getContractAddress ( ' EpochManager' ) ,
101
121
providerOrSigner ,
102
122
) ,
103
- gns : GNS__factory . connect ( deployedContracts . GNS . address , providerOrSigner ) ,
123
+ gns,
104
124
rewardsManager : RewardsManager__factory . connect (
105
- deployedContracts . RewardsManager . address ,
125
+ getContractAddress ( ' RewardsManager' ) ,
106
126
providerOrSigner ,
107
127
) ,
108
128
serviceRegistry : ServiceRegistry__factory . connect (
109
- deployedContracts . ServiceRegistry . address ,
129
+ getContractAddress ( ' ServiceRegistry' ) ,
110
130
providerOrSigner ,
111
131
) ,
112
- staking : staking ,
132
+ staking,
113
133
token : GraphTokenFactory . connect ( graphTokenAddress , providerOrSigner ) ,
114
134
controller : Controller__factory . connect (
115
- deployedContracts . Controller . address ,
135
+ getContractAddress ( ' Controller' ) ,
116
136
providerOrSigner ,
117
137
) ,
118
138
allocationExchange : AllocationExchange__factory . connect (
119
- deployedContracts . AllocationExchange . address ,
139
+ getContractAddress ( ' AllocationExchange' ) ,
120
140
providerOrSigner ,
121
141
) ,
122
142
graphProxyAdmin : GraphProxyAdmin__factory . connect (
123
- deployedContracts . GraphProxyAdmin . address ,
143
+ getContractAddress ( ' GraphProxyAdmin' ) ,
124
144
providerOrSigner ,
125
145
) ,
126
146
subgraphNFT : SubgraphNFT__factory . connect (
127
- deployedContracts . SubgraphNFT . address ,
147
+ getContractAddress ( ' SubgraphNFT' ) ,
128
148
providerOrSigner ,
129
149
) ,
130
150
graphCurationToken : GraphCurationToken__factory . connect (
131
- deployedContracts . GraphCurationToken . address ,
151
+ getContractAddress ( ' GraphCurationToken' ) ,
132
152
providerOrSigner ,
133
153
) ,
134
154
}
135
155
136
156
if ( GraphChain . isL1 ( chainId ) ) {
137
157
if ( deployedContracts . L1GraphTokenGateway ) {
138
158
contracts . l1GraphTokenGateway = L1GraphTokenGateway__factory . connect (
139
- deployedContracts . L1GraphTokenGateway . address ,
159
+ getContractAddress ( ' L1GraphTokenGateway' ) ,
140
160
providerOrSigner ,
141
161
)
142
162
}
143
163
if ( deployedContracts . BridgeEscrow ) {
144
164
contracts . bridgeEscrow = BridgeEscrow__factory . connect (
145
- deployedContracts . BridgeEscrow . address ,
165
+ getContractAddress ( ' BridgeEscrow' ) ,
146
166
providerOrSigner ,
147
167
)
148
168
}
149
169
} else if ( GraphChain . isL2 ( chainId ) ) {
150
170
if ( deployedContracts . L2GraphTokenGateway ) {
151
171
contracts . l2GraphTokenGateway = L2GraphTokenGateway__factory . connect (
152
- deployedContracts . L2GraphTokenGateway . address ,
172
+ getContractAddress ( ' L2GraphTokenGateway' ) ,
153
173
providerOrSigner ,
154
174
)
155
175
}
0 commit comments