Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ditch ethers #826

Draft
wants to merge 8 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,8 @@
"i18n-ally.keystyle": "nested",
"[typescript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[jsonc]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
}
}
6 changes: 0 additions & 6 deletions deploy/.utils/nonceManager.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
import type { ethers as EthersT } from 'ethers'

type Ethers = typeof EthersT & {
provider: EthersT.providers.JsonRpcProvider
}

export const nonceManager =
<T extends object>(
ethers: Ethers,
Expand Down
104 changes: 56 additions & 48 deletions deploy/00_deploy_bulk_renewal.ts
Original file line number Diff line number Diff line change
@@ -1,78 +1,86 @@
/* eslint-disable import/no-extraneous-dependencies */
import { Interface } from '@ethersproject/abi'
import { ethers } from 'hardhat'
import { DeployFunction } from 'hardhat-deploy/types'
import { HardhatRuntimeEnvironment } from 'hardhat/types'
import { namehash } from 'viem'

const { makeInterfaceId } = require('@openzeppelin/test-helpers')

function computeInterfaceId(iface: any): any {
return makeInterfaceId.ERC165(
Object.values(iface.functions).map((frag: any) => frag.format('sighash')),
)
import {
Abi,
AbiFunction,
Address,
bytesToHex,
hexToBytes,
labelhash,
namehash,
toFunctionHash,
} from 'viem'

import { getContract, getNamedClients } from './utils/viem-hardhat'

const createInterfaceId = <I extends Abi>(iface: I) => {
const bytesId = iface
.filter((item): item is AbiFunction => item.type === 'function')
.map((f) => toFunctionHash(f))
.map((h) => hexToBytes(h).slice(0, 4))
.reduce((memo, bytes) => {
// eslint-disable-next-line no-plusplus
for (let i = 0; i < 4; i++) {
// eslint-disable-next-line no-bitwise, no-param-reassign
memo[i] ^= bytes[i] // xor
}
return memo
}, new Uint8Array(4))

return bytesToHex(bytesId)
}

const labelHash = (label: string) => ethers.utils.keccak256(ethers.utils.toUtf8Bytes(label))

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

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

const root = await ethers.getContract('Root', await ethers.getSigner(owner))
const registry = await ethers.getContract('ENSRegistry', await ethers.getSigner(owner))
const resolver = await ethers.getContract('PublicResolver', await ethers.getSigner(owner))
const registrar = await ethers.getContract('BaseRegistrarImplementation')
const controller = await ethers.getContract('ETHRegistrarController')
const wrapper = await ethers.getContract('NameWrapper')
const controllerArtifact = await deployments.getArtifact('IETHRegistrarController')

const bulkRenewal = await deploy('BulkRenewal', {
from: deployer,
args: [registry.address],
log: true,
const { owner, deployer } = await getNamedClients(hre)()

const root = (await getContract(hre)('Root', owner))!
const registry = (await getContract(hre)('ENSRegistry', owner))!
const resolver = (await getContract(hre)('PublicResolver', owner))!
const registrar = (await getContract(hre)('BaseRegistrarImplementation'))!
const controller = (await getContract(hre)('ETHRegistrarController'))!
const wrapper = (await getContract(hre)('NameWrapper'))!
const controllerArtifact = (await deployments.getArtifact('IETHRegistrarController'))!

const bulkRenewal = await viem.deployContract('BulkRenewal', [registry.address], {
client: deployer,
})

console.log('Temporarily setting owner of eth tld to owner ')
const tx = await root.setSubnodeOwner(labelHash('eth'), owner)
await tx.wait()
await root.write.setSubnodeOwner([labelhash('eth')], owner)

console.log('Set default resolver for eth tld to public resolver')
const tx111 = await registry.setResolver(namehash('eth'), resolver.address)
await tx111.wait()
await registry.write.setResolver([namehash('eth'), resolver.address])

console.log('Set interface implementor of eth tld for bulk renewal')
const tx2 = await resolver.setInterface(
ethers.utils.namehash('eth'),
computeInterfaceId(new Interface(bulkRenewal.abi)),
await resolver.write.setInterface([
namehash('eth'),
createInterfaceId(bulkRenewal.abi),
bulkRenewal.address,
)
await tx2.wait()
])

console.log('Set interface implementor of eth tld for registrar controller')
const tx3 = await resolver.setInterface(
ethers.utils.namehash('eth'),
computeInterfaceId(new Interface(controllerArtifact.abi)),
await resolver.write.setInterface([
namehash('eth'),
createInterfaceId(controllerArtifact.abi),
controller.address,
)
await tx3.wait()
])

console.log('Set interface implementor of eth tld for name wrapper')
const tx4 = await resolver.setInterface(
ethers.utils.namehash('eth'),
computeInterfaceId(wrapper.interface),
await resolver.write.setInterface([
namehash('eth'),
createInterfaceId(wrapper.interface),
wrapper.address,
)
await tx4.wait()
])

console.log('Set owner of eth tld back to registrar')
const tx11 = await root.setSubnodeOwner(labelHash('eth'), registrar.address)
await tx11.wait()
await root.write.setSubnodeOwner([labelhash('eth')], registrar.address)

return true
}
Expand Down
30 changes: 17 additions & 13 deletions deploy/00_get_registration_gas_values.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,22 @@

/* eslint-disable no-await-in-loop */
import fs from 'fs/promises'
import { ethers } from 'hardhat'

import { DeployFunction } from 'hardhat-deploy/types'
import { HardhatRuntimeEnvironment } from 'hardhat/types'

import { namehash } from 'viem'

import { getContract } from './utils/viem-hardhat'

const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
if (!hre.network.tags.generate) {
return true
}
const { getUnnamedAccounts, network } = hre
const allUnnamedAccts = await getUnnamedAccounts()

const controller = await ethers.getContract('ETHRegistrarController')
const publicResolver = await ethers.getContract('PublicResolver')
const controller = (await getContract(hre)('ETHRegistrarController'))!
const publicResolver = (await getContract(hre)('PublicResolver'))!

let i = 0
let errored = false
Expand Down Expand Up @@ -80,7 +81,7 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
}: ReturnType<ReturnType<typeof makeData>>,
index: number,
) => {
const commitment = await controller.makeCommitment(
const commitment = await controller.write.makeCommitment([
label,
owner,
duration,
Expand All @@ -90,7 +91,7 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
reverseRecord,
fuses,
wrapperExpiry,
)
])

const _controller = controller.connect(await ethers.getSigner(owner))
const commitTx = await _controller.commit(commitment, { nonce: nonce + index })
Expand All @@ -115,7 +116,7 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
index: number,
) => {
try {
const [price] = await controller.rentPrice(label, duration)
const [price] = await controller.read.rentPrice([label, duration])

const _controller = controller.connect(await ethers.getSigner(owner))
const estimatedTx = await _controller.estimateGas.register(
Expand Down Expand Up @@ -180,12 +181,15 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {

const makeUniques = () =>
gasValues
.reduce((prev, curr, inx) => {
if (prev.find((p) => p[1] === curr)) {
return prev
}
return [...prev, [inx, curr] as [number, number]]
}, [] as [number, number][])
.reduce(
(prev, curr, inx) => {
if (prev.find((p) => p[1] === curr)) {
return prev
}
return [...prev, [inx, curr] as [number, number]]
},
[] as [number, number][],
)
.reverse()

await fs.writeFile('./textRecordGasCosts-1.json', JSON.stringify(makeUniques()))
Expand Down
34 changes: 18 additions & 16 deletions deploy/00_legacy_registry.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,32 @@
/* eslint-disable import/no-extraneous-dependencies, import/extensions */
import { ethers } from 'hardhat'
import { DeployFunction } from 'hardhat-deploy/types'
import { HardhatRuntimeEnvironment } from 'hardhat/types'
import { labelhash, namehash } from 'viem'

import { namehash, labelhash } from 'viem'
import { getContract, getNamedClients } from './utils/viem-hardhat'

const ZERO_HASH = '0x0000000000000000000000000000000000000000000000000000000000000000'

const names = ['legacy']

const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
const { getNamedAccounts } = hre
const { owner } = await getNamedAccounts()
const { owner } = await getNamedClients(hre)()

const registry = await ethers.getContract('LegacyENSRegistry', owner)
const registry = (await getContract(hre)('LegacyENSRegistry', owner))!

const tldTx = await registry.setSubnodeOwner(ZERO_HASH, labelhash('test'), owner)
console.log(`Creating .test TLD (tx: ${tldTx.hash})...`)
await tldTx.wait()
const tldTx = await registry.write.setSubnodeOwner(
[ZERO_HASH, labelhash('test'), owner.address],
{ chain: owner.public.chain, account: owner.account },
)
console.log(`Creating .test TLD (tx: ${tldTx})...`)

await Promise.all(
names.map(async (name) => {
const nameTx = await registry.setSubnodeOwner(namehash('test'), labelhash(name), owner)
console.log(`Creating ${name}.test (tx: ${nameTx.hash})...`)
await nameTx.wait()
const nameTx = await registry.write.setSubnodeOwner(
[namehash('test'), labelhash(name), owner.address],
{ chain: owner.public.chain, account: owner.account },
)
console.log(`Creating ${name}.test (tx: ${nameTx})...`)
}),
)

Expand All @@ -34,13 +37,12 @@ func.id = 'legacy-registry-names'
func.tags = ['legacy-registry-names']
func.dependencies = ['ENSRegistry']
func.skip = async function (hre: HardhatRuntimeEnvironment) {
const { getNamedAccounts } = hre
const { owner } = await getNamedAccounts()
const { owner } = await getNamedClients(hre)()

const registry = await ethers.getContract('LegacyENSRegistry')
const registry = (await getContract(hre)('LegacyENSRegistry', owner))!

const ownerOfTestTld = await registry.owner(namehash('test'))
if (ownerOfTestTld !== owner) {
const ownerOfTestTld = await registry.read.owner([namehash('test')])
if (ownerOfTestTld !== owner.address) {
return false
}
return true
Expand Down
6 changes: 3 additions & 3 deletions deploy/00_migrate_legacy_records.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
/* eslint-disable import/no-extraneous-dependencies */

/* eslint-disable no-await-in-loop */
import { ethers } from 'hardhat'
import { DeployFunction } from 'hardhat-deploy/types'
import { HardhatRuntimeEnvironment } from 'hardhat/types'

import { namehash } from 'viem'

import { getContract } from './utils/viem-hardhat'

const names = [
{
label: 'migrated-resolver-to-be-updated',
Expand All @@ -32,7 +32,7 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
const { getNamedAccounts, network } = hre
const allNamedAccts = await getNamedAccounts()

const publicResolver = await ethers.getContract('PublicResolver')
const publicResolver = await getContract(hre)('PublicResolver')

await network.provider.send('anvil_setBlockTimestampInterval', [60])

Expand Down
38 changes: 15 additions & 23 deletions deploy/00_register_contracts.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/* eslint-disable import/no-extraneous-dependencies */

/* eslint-disable no-await-in-loop */
import { ethers } from 'hardhat'
import { DeployFunction } from 'hardhat-deploy/types'
import { HardhatRuntimeEnvironment } from 'hardhat/types'
import { Address, namehash } from 'viem'

import { namehash } from 'viem'
import { getContract } from './utils/viem-hardhat'

const names = [
{
Expand All @@ -28,19 +28,20 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
const { getNamedAccounts, network } = hre
const allNamedAccts = await getNamedAccounts()

const controller = await ethers.getContract('ETHRegistrarController')
const publicResolver = await ethers.getContract('PublicResolver')
const controller = (await getContract(hre)('ETHRegistrarController'))!
const publicResolver = (await getContract(hre)('PublicResolver'))!

await network.provider.send('anvil_setBlockTimestampInterval', [60])

for (const { label, namedOwner, data, reverseRecord, fuses, subnames } of names) {
// eslint-disable-next-line no-restricted-syntax
const secret = '0x0000000000000000000000000000000000000000000000000000000000000000'
const owner = allNamedAccts[namedOwner]
const owner = allNamedAccts[namedOwner] as Address
const resolver = publicResolver.address
const duration = 31536000
const wrapperExpiry = 1659467455 + duration

const commitment = await controller.makeCommitment(
const commitment = await controller.write.makeCommitment([
label,
owner,
duration,
Expand All @@ -49,32 +50,23 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
data,
reverseRecord,
fuses,
)
])

const _controller = controller.connect(await ethers.getSigner(owner))
const commitTx = await controller.commit(commitment)
console.log(`Commiting commitment for ${label}.eth (tx: ${commitTx.hash})...`)
await commitTx.wait()
const commitTx = await controller.write.commit(commitment)
console.log(`Commiting commitment for ${label}.eth (tx: ${commitTx})...`)

await network.provider.send('evm_mine')

const [price] = await controller.rentPrice(label, duration)
const [price] = await controller.read.rentPrice([label, duration])

const registerTx = await _controller.register(
label,
owner,
duration,
secret,
resolver,
data,
reverseRecord,
fuses,
const registerTx = await controller.write.register(
[label, owner, duration, secret, resolver, data, reverseRecord, fuses],
{
value: price,
account: owner,
},
)
console.log(`Registering name ${label}.eth (tx: ${registerTx.hash})...`)
await registerTx.wait()
console.log(`Registering name ${label}.eth (tx: ${registerTx})...`)

if (subnames) {
console.log(`Setting subnames for ${label}.eth...`)
Expand Down
Loading
Loading