Skip to content

Commit a7ba535

Browse files
committed
fix(task): accept ownership only if pending owner matches
Signed-off-by: Tomás Migone <[email protected]>
1 parent 598ecc3 commit a7ba535

File tree

1 file changed

+30
-5
lines changed

1 file changed

+30
-5
lines changed

tasks/deployment/ownership.ts

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { ContractTransaction } from 'ethers'
1+
import { SignerWithAddress } from '@nomiclabs/hardhat-ethers/signers'
2+
import { Contract, ContractTransaction, ethers } from 'ethers'
23
import { task } from 'hardhat/config'
34
import { cliOpts } from '../../cli/defaults'
45

@@ -13,12 +14,36 @@ task('migrate:ownership', 'Accepts ownership of protocol contracts on behalf of
1314
console.log('> Accepting ownership of contracts')
1415
console.log(`- Governor: ${governor.address}`)
1516

17+
const governedContracts = [GraphToken, Controller, GraphProxyAdmin, SubgraphNFT]
1618
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+
}
2125

2226
await Promise.all(txs.map((tx) => tx.wait()))
2327
console.log('Done!')
2428
})
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

Comments
 (0)