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 22 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
6 changes: 3 additions & 3 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ jobs:
run: tar -xvf stateless-build.tar

- name: Install playwright
run: npx playwright install chromium
run: pnpm playwright install chromium

- name: Run tests
run: |
Expand Down Expand Up @@ -173,13 +173,13 @@ jobs:
run: tar -xvf stateful-build.tar

- name: Install playwright
run: npx playwright install chromium
run: pnpm playwright install chromium

- name: Run tests
run: |
parallel --lb --halt now,success=1,fail=1 ::: \
"pnpm wrangle" \
"pnpm wait-on http://127.0.0.1:8788 && npx playwright test --shard=${{matrix.shard}}/${{strategy.job-total}} --project=stateful"
"pnpm wait-on http://127.0.0.1:8788 && pnpm playwright test --shard=${{matrix.shard}}/${{strategy.job-total}} --project=stateful"
env:
# NEXT_PUBLIC_GRAPH_URI: https://api.studio.thegraph.com/query/49574/ensholesky/version/latest
SECRET_WORDS: ${{ secrets.SECRET_WORDS }}
Expand Down
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
96 changes: 48 additions & 48 deletions deploy/00_deploy_bulk_renewal.ts
Original file line number Diff line number Diff line change
@@ -1,78 +1,78 @@
/* eslint-disable import/no-extraneous-dependencies */
import { utils } from 'ethers'
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, bytesToHex, hexToBytes, labelhash, namehash, toFunctionHash } from 'viem'

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 { deploy } = deployments
const { deployer, owner } = await getNamedAccounts()
const { deployments, network, viem } = hre

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 viem.getNamedClients()

const root = await viem.getContract('Root', owner)
const registry = await viem.getContract('ENSRegistry', owner)
const resolver = await viem.getContract('PublicResolver', owner)
const registrar = await viem.getContract('BaseRegistrarImplementation')
const controller = await viem.getContract('ETHRegistrarController')
const wrapper = await viem.getContract('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')], { chain: undefined, account: owner.account })

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], {
chain: undefined,
account: owner.account,
})

console.log('Set interface implementor of eth tld for bulk renewal')
const tx2 = await resolver.setInterface(
ethers.utils.namehash('eth'),
computeInterfaceId(new utils.Interface(bulkRenewal.abi)),
bulkRenewal.address,
await resolver.write.setInterface(
[namehash('eth'), createInterfaceId(bulkRenewal.abi), bulkRenewal.address],
{ chain: undefined, account: owner.account },
)
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 utils.Interface(controllerArtifact.abi)),
controller.address,
await resolver.write.setInterface(
[namehash('eth'), createInterfaceId(controllerArtifact.abi), controller.address],
{ chain: undefined, account: owner.account },
)
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),
wrapper.address,
await resolver.write.setInterface(
[namehash('eth'), createInterfaceId(wrapper.abi), wrapper.address],
{ chain: undefined, account: owner.account },
)
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], {
chain: undefined,
account: owner.account,
})

return true
}
Expand Down
3 changes: 2 additions & 1 deletion deploy/00_deploy_multicall.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
/* eslint-disable import/no-extraneous-dependencies */
import { existsSync, mkdirSync } from 'fs'
import { readFile, writeFile } from 'fs/promises'
import { resolve } from 'path'

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

const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
const { getNamedAccounts } = hre
Expand Down
30 changes: 16 additions & 14 deletions deploy/00_get_registration_gas_values.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,20 @@

/* 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'

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

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

let i = 0
let errored = false
Expand Down Expand Up @@ -80,7 +79,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 +89,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 +114,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 +179,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
36 changes: 19 additions & 17 deletions deploy/00_legacy_registry.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,31 @@
/* eslint-disable import/no-extraneous-dependencies, import/extensions */
import { ethers } from 'hardhat'
import { DeployFunction } from 'hardhat-deploy/types'
import { HardhatRuntimeEnvironment } from 'hardhat/types'

import { namehash, labelhash } from 'viem'
import { labelhash, namehash } from 'viem'

const ZERO_HASH = '0x0000000000000000000000000000000000000000000000000000000000000000'

const names = ['legacy']

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

const registry = await ethers.getContract('LegacyENSRegistry', owner)
const registry = await viem.getContract('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 +36,13 @@ 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 { viem } = hre
const { owner } = await viem.getNamedClients()

const registry = await ethers.getContract('LegacyENSRegistry')
const registry = await viem.getContract('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: 2 additions & 4 deletions deploy/00_migrate_legacy_records.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
/* 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'

const names = [
Expand All @@ -29,10 +27,10 @@ const names = [
]

const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
const { getNamedAccounts, network } = hre
const { getNamedAccounts, network, viem } = hre
const allNamedAccts = await getNamedAccounts()

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

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

Expand Down
Loading
Loading