Skip to content

Commit

Permalink
Split out setup scripts to allow registrar to be deployed at nonce 2
Browse files Browse the repository at this point in the history
  • Loading branch information
jefflau committed Jun 16, 2023
1 parent dcd77be commit 86ad942
Show file tree
Hide file tree
Showing 5 changed files with 137 additions and 51 deletions.
21 changes: 2 additions & 19 deletions deploy/ethregistrar/00_deploy_base_registrar_implementation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,14 @@ import { keccak256 } from 'js-sha3'

const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
const { getNamedAccounts, deployments, network } = hre
const { deploy, fetchIfDifferent } = deployments
const { deployer, owner } = await getNamedAccounts()
const { deploy } = deployments
const { deployer } = await getNamedAccounts()

if (!network.tags.use_root) {
return true
}

const registry = await ethers.getContract('ENSRegistry')
const root = await ethers.getContract('Root')

const deployArgs = {
from: deployer,
Expand All @@ -24,22 +23,6 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {

const bri = await deploy('BaseRegistrarImplementation', deployArgs)
if (!bri.newlyDeployed) return

const registrar = await ethers.getContract('BaseRegistrarImplementation')

const tx1 = await registrar.transferOwnership(owner, { from: deployer })
console.log(
`Transferring ownership of registrar to owner (tx: ${tx1.hash})...`,
)
await tx1.wait()

const tx2 = await root
.connect(await ethers.getSigner(owner))
.setSubnodeOwner('0x' + keccak256('eth'), registrar.address)
console.log(
`Setting owner of eth node to registrar on root (tx: ${tx2.hash})...`,
)
await tx2.wait()
}

func.id = 'registrar'
Expand Down
40 changes: 40 additions & 0 deletions deploy/ethregistrar/00_setup_base_registrar.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import namehash from 'eth-ens-namehash'
import { ethers } from 'hardhat'
import { DeployFunction } from 'hardhat-deploy/types'
import { HardhatRuntimeEnvironment } from 'hardhat/types'
import { keccak256 } from 'js-sha3'

const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
const { getNamedAccounts, deployments, network } = hre
const { deployer, owner } = await getNamedAccounts()

if (!network.tags.use_root) {
return true
}

const root = await ethers.getContract('Root')
const registrar = await ethers.getContract('BaseRegistrarImplementation')

console.log('Running base registrar setup')

const tx1 = await registrar.transferOwnership(owner, { from: deployer })
console.log(
`Transferring ownership of registrar to owner (tx: ${tx1.hash})...`,
)
await tx1.wait()

const tx2 = await root
.connect(await ethers.getSigner(owner))
.setSubnodeOwner('0x' + keccak256('eth'), registrar.address)
console.log(
`Setting owner of eth node to registrar on root (tx: ${tx2.hash})...`,
)
await tx2.wait()
}

func.id = 'setupRegistrar'
func.tags = ['ethregistrar', 'BaseRegistrarImplementation']
//Runs after the root is setup
func.dependencies = ['setupRoot']

export default func
62 changes: 31 additions & 31 deletions deploy/root/00_deploy_root.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,39 +24,39 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {

const root = await ethers.getContract('Root')

const tx1 = await registry.setOwner(ZERO_HASH, root.address)
console.log(
`Setting owner of root node to root contract (tx: ${tx1.hash})...`,
)
await tx1.wait()
// const tx1 = await registry.setOwner(ZERO_HASH, root.address)
// console.log(
// `Setting owner of root node to root contract (tx: ${tx1.hash})...`,
// )
// await tx1.wait()

const rootOwner = await root.owner()
// const rootOwner = await root.owner()

switch (rootOwner) {
case deployer:
const tx2 = await root
.connect(await ethers.getSigner(deployer))
.transferOwnership(owner)
console.log(
`Transferring root ownership to final owner (tx: ${tx2.hash})...`,
)
await tx2.wait()
case owner:
if (!(await root.controllers(owner))) {
const tx2 = await root
.connect(await ethers.getSigner(owner))
.setController(owner, true)
console.log(
`Setting final owner as controller on root contract (tx: ${tx2.hash})...`,
)
await tx2.wait()
}
break
default:
console.log(
`WARNING: Root is owned by ${rootOwner}; cannot transfer to owner account`,
)
}
// switch (rootOwner) {
// case deployer:
// const tx2 = await root
// .connect(await ethers.getSigner(deployer))
// .transferOwnership(owner)
// console.log(
// `Transferring root ownership to final owner (tx: ${tx2.hash})...`,
// )
// await tx2.wait()
// case owner:
// if (!(await root.controllers(owner))) {
// const tx2 = await root
// .connect(await ethers.getSigner(owner))
// .setController(owner, true)
// console.log(
// `Setting final owner as controller on root contract (tx: ${tx2.hash})...`,
// )
// await tx2.wait()
// }
// break
// default:
// console.log(
// `WARNING: Root is owned by ${rootOwner}; cannot transfer to owner account`,
// )
// }

return true
}
Expand Down
62 changes: 62 additions & 0 deletions deploy/root/00_setup_root.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import { ethers } from 'hardhat'
import { DeployFunction } from 'hardhat-deploy/types'
import { HardhatRuntimeEnvironment } from 'hardhat/types'

const ZERO_HASH =
'0x0000000000000000000000000000000000000000000000000000000000000000'

const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
const { getNamedAccounts, deployments, network } = hre
const { deployer, owner } = await getNamedAccounts()

if (!network.tags.use_root) {
return true
}

console.log('Running root setup')

const registry = await ethers.getContract('ENSRegistry')
const root = await ethers.getContract('Root')

const tx1 = await registry.setOwner(ZERO_HASH, root.address)
console.log(
`Setting owner of root node to root contract (tx: ${tx1.hash})...`,
)
await tx1.wait()

const rootOwner = await root.owner()

switch (rootOwner) {
case deployer:
const tx2 = await root
.connect(await ethers.getSigner(deployer))
.transferOwnership(owner)
console.log(
`Transferring root ownership to final owner (tx: ${tx2.hash})...`,
)
await tx2.wait()
case owner:
if (!(await root.controllers(owner))) {
const tx2 = await root
.connect(await ethers.getSigner(owner))
.setController(owner, true)
console.log(
`Setting final owner as controller on root contract (tx: ${tx2.hash})...`,
)
await tx2.wait()
}
break
default:
console.log(
`WARNING: Root is owned by ${rootOwner}; cannot transfer to owner account`,
)
}

return true
}

func.id = 'setupRoot'
func.tags = ['setupRoot']
func.dependencies = ['Root']

export default func
3 changes: 2 additions & 1 deletion deploy/wrapper/00_deploy_static_metadata_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {

func.id = 'metadata'
func.tags = ['wrapper', 'StaticMetadataService']
func.dependencies = []
// technically not a dep, but we want to make sure it's deployed first for the consistent address
func.dependencies = ['BaseRegistrarImplementation']

export default func

0 comments on commit 86ad942

Please sign in to comment.