|
| 1 | +import { ethers } from 'hardhat' |
| 2 | +import { DeployFunction } from 'hardhat-deploy/types' |
| 3 | +import { HardhatRuntimeEnvironment } from 'hardhat/types' |
| 4 | + |
| 5 | +const ZERO_HASH = |
| 6 | + '0x0000000000000000000000000000000000000000000000000000000000000000' |
| 7 | + |
| 8 | +const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) { |
| 9 | + const { getNamedAccounts, deployments, network } = hre |
| 10 | + const { deployer, owner } = await getNamedAccounts() |
| 11 | + |
| 12 | + if (!network.tags.use_root) { |
| 13 | + return true |
| 14 | + } |
| 15 | + |
| 16 | + console.log('Running root setup') |
| 17 | + |
| 18 | + const registry = await ethers.getContract('ENSRegistry') |
| 19 | + const root = await ethers.getContract('Root') |
| 20 | + |
| 21 | + const tx1 = await registry.setOwner(ZERO_HASH, root.address) |
| 22 | + console.log( |
| 23 | + `Setting owner of root node to root contract (tx: ${tx1.hash})...`, |
| 24 | + ) |
| 25 | + await tx1.wait() |
| 26 | + |
| 27 | + const rootOwner = await root.owner() |
| 28 | + |
| 29 | + switch (rootOwner) { |
| 30 | + case deployer: |
| 31 | + const tx2 = await root |
| 32 | + .connect(await ethers.getSigner(deployer)) |
| 33 | + .transferOwnership(owner) |
| 34 | + console.log( |
| 35 | + `Transferring root ownership to final owner (tx: ${tx2.hash})...`, |
| 36 | + ) |
| 37 | + await tx2.wait() |
| 38 | + case owner: |
| 39 | + if (!(await root.controllers(owner))) { |
| 40 | + const tx2 = await root |
| 41 | + .connect(await ethers.getSigner(owner)) |
| 42 | + .setController(owner, true) |
| 43 | + console.log( |
| 44 | + `Setting final owner as controller on root contract (tx: ${tx2.hash})...`, |
| 45 | + ) |
| 46 | + await tx2.wait() |
| 47 | + } |
| 48 | + break |
| 49 | + default: |
| 50 | + console.log( |
| 51 | + `WARNING: Root is owned by ${rootOwner}; cannot transfer to owner account`, |
| 52 | + ) |
| 53 | + } |
| 54 | + |
| 55 | + return true |
| 56 | +} |
| 57 | + |
| 58 | +func.id = 'setupRoot' |
| 59 | +func.tags = ['setupRoot'] |
| 60 | +func.dependencies = ['Root'] |
| 61 | + |
| 62 | +export default func |
0 commit comments