1
- import { ContractTransaction } from 'ethers'
1
+ import { SignerWithAddress } from '@nomiclabs/hardhat-ethers/signers'
2
+ import { Contract , ContractTransaction , ethers } from 'ethers'
2
3
import { task } from 'hardhat/config'
3
4
import { cliOpts } from '../../cli/defaults'
4
5
@@ -13,12 +14,36 @@ task('migrate:ownership', 'Accepts ownership of protocol contracts on behalf of
13
14
console . log ( '> Accepting ownership of contracts' )
14
15
console . log ( `- Governor: ${ governor . address } ` )
15
16
17
+ const governedContracts = [ GraphToken , Controller , GraphProxyAdmin , SubgraphNFT ]
16
18
const txs : ContractTransaction [ ] = [ ]
17
- txs . push ( await GraphToken . connect ( governor ) . acceptOwnership ( ) )
18
- txs . push ( await Controller . connect ( governor ) . acceptOwnership ( ) )
19
- txs . push ( await GraphProxyAdmin . connect ( governor ) . acceptOwnership ( ) )
20
- txs . push ( await SubgraphNFT . connect ( governor ) . acceptOwnership ( ) )
19
+ for ( const contract of governedContracts ) {
20
+ const tx = await acceptOwnershipIfPending ( contract , governor )
21
+ if ( tx ) {
22
+ txs . push ( )
23
+ }
24
+ }
21
25
22
26
await Promise . all ( txs . map ( ( tx ) => tx . wait ( ) ) )
23
27
console . log ( 'Done!' )
24
28
} )
29
+
30
+ async function acceptOwnershipIfPending (
31
+ contract : Contract ,
32
+ signer : SignerWithAddress ,
33
+ ) : Promise < ContractTransaction | undefined > {
34
+ const pendingGovernor = await contract . connect ( signer ) . pendingGovernor ( )
35
+
36
+ if ( pendingGovernor === ethers . constants . AddressZero ) {
37
+ console . log ( `No pending governor for ${ contract . address } ` )
38
+ return
39
+ }
40
+
41
+ if ( pendingGovernor === signer . address ) {
42
+ console . log ( `Accepting ownership of ${ contract . address } ` )
43
+ return contract . connect ( signer ) . acceptOwnership ( )
44
+ } else {
45
+ console . log (
46
+ `Signer ${ signer . address } is not the pending governor of ${ contract . address } , it is ${ pendingGovernor } ` ,
47
+ )
48
+ }
49
+ }
0 commit comments