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 3 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"
}
}
90 changes: 49 additions & 41 deletions deploy/00_deploy_bulk_renewal.ts
Original file line number Diff line number Diff line change
@@ -1,77 +1,85 @@
/* 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 = <iface extends Abi>(iface: iface) => {
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) => {
for (let i = 0; i < 4; i++) {
memo[i] = 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()
const tx = await root.write.setSubnodeOwner([labelhash('eth')])

console.log('Set default resolver for eth tld to public resolver')
const tx111 = await registry.setResolver(namehash('eth'), resolver.address)
await tx111.wait()
const tx111 = 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)),
bulkRenewal.address,
const tx2 = 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)),
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),
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)
const tx11 = await root.setSubnodeOwner(labelhash('eth'), registrar.address)
await tx11.wait()

return true
Expand Down
52 changes: 52 additions & 0 deletions deploy/utils/viem-hardhat.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import { HardhatRuntimeEnvironment } from "hardhat/types";
import 'hardhat-deploy'
import { Account, Address, GetContractReturnType, PublicClient, WalletClient, getAddress, getContract as getViemContract } from "viem";
import '@nomicfoundation/hardhat-viem'
import type { KeyedClient } from '@nomicfoundation/hardhat-viem/types.js'
import '@nomicfoundation/hardhat-toolbox-viem'

export const getContract = (hre: HardhatRuntimeEnvironment) => async <contractName extends string>(contractName: contractName, client_?: {
public: PublicClient;
wallet: WalletClient;
}) => {
const deployment = await hre.deployments.getOrNull(contractName)
if (!deployment) return null

const client = client_ ?? {
public: await hre.viem.getPublicClient(),
wallet: await hre.viem.getWalletClients().then(([c]) => c),
} as {
public: PublicClient;
wallet: WalletClient;
}

const contract = getViemContract({
abi: deployment.abi,
address: deployment.address as Address,
client,
})

if (!contract) throw new Error(`Could not find contract ${contractName}`)

return contract
}

type Client = Required<KeyedClient> & { address: Address; account: Account }

export const getNamedClients = (hre: HardhatRuntimeEnvironment) => async () => {
const publicClient = await hre.viem.getPublicClient()
const namedAccounts = await hre.getNamedAccounts()
const clients: Record<string, Client> = {}

for (const [name, address] of Object.entries(namedAccounts)) {
const namedClient = await hre.viem.getWalletClient(address as Address)
clients[name] = {
public: publicClient,
wallet: namedClient,
address: getAddress(address),
account: namedClient.account,
}
}

return clients
}
4 changes: 2 additions & 2 deletions hardhat.config.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/* eslint-disable import/no-extraneous-dependencies */
import '@nomiclabs/hardhat-ethers'

import 'dotenv/config'
import 'hardhat-deploy'

import '@nomicfoundation/hardhat-toolbox-viem'
import { resolve } from 'path'

import { HardhatUserConfig } from 'hardhat/config'
Expand Down
21 changes: 0 additions & 21 deletions loaders/abi-loader.js

This file was deleted.

74 changes: 0 additions & 74 deletions loaders/ethers-loader.js

This file was deleted.

12 changes: 4 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -108,13 +108,11 @@
"@ensdomains/buffer": "^0.1.1",
"@ensdomains/ens-test-env": "^0.5.0-beta.0",
"@ensdomains/headless-web3-provider": "^1.0.8",
"@ethersproject/abi": "^5.4.0",
"@ethersproject/contracts": "^5.4.0",
"@ianvs/prettier-plugin-sort-imports": "^4.1.0",
"@next/bundle-analyzer": "^13.4.19",
"@nomiclabs/hardhat-ethers": "npm:hardhat-deploy-ethers@^0.3.0-beta.13",
"@nomicfoundation/hardhat-toolbox-viem": "^3.0.0",
"@nomicfoundation/hardhat-viem": "^2.0.3",
"@openzeppelin/contracts": "^4.7.3",
"@openzeppelin/test-helpers": "^0.5.16",
"@playwright/test": "^1.36.2",
"@testing-library/jest-dom": "^6.4.2",
"@testing-library/react": "^14.0.0",
Expand Down Expand Up @@ -155,11 +153,10 @@
"eslint-plugin-react-hooks": "^4.6.0",
"eslint-plugin-testing-library": "^6.0.2",
"eslint-plugin-vitest": "^0.4.0",
"ethers": "^5.7.2",
"ganache": "^7.4.1",
"hardhat": "^2.10.2",
"hardhat": "^2.22.9",
"hardhat-dependency-compiler": "^1.1.3",
"hardhat-deploy": "^0.11.12",
"hardhat-deploy": "^0.12.4",
"husky": "^7.0.4",
"isows": "^1.0.3",
"jsdom": "^24.0.0",
Expand Down Expand Up @@ -199,7 +196,6 @@
"overrides": {
"wrtc": "https://registry.npmjs.org/@koush/wrtc/-/wrtc-0.5.2.tgz",
"bn.js": "npm:bn.js@^5.2.0",
"@nomiclabs/hardhat-ethers": "npm:[email protected]",
"@walletconnect/ethereum-provider": "2.11.1",
"@walletconnect/modal": "2.6.2",
"react": "^18.2.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/* eslint-disable import/no-extraneous-dependencies */

/* eslint-disable no-await-in-loop */
// import { toUtf8Bytes } from '@ethersproject/strings/lib/utf8'
import { Hash } from 'viem'

import { RecordOptions } from '@ensdomains/ensjs/utils'
Expand Down
Loading
Loading