Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
talentlessguy committed Nov 30, 2024
1 parent 5d65484 commit f3164de
Show file tree
Hide file tree
Showing 10 changed files with 110 additions and 93 deletions.
25 changes: 14 additions & 11 deletions deploy/00_deploy_bulk_renewal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,19 @@ import {
namehash,
toFunctionHash,
} from 'viem'

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

const createInterfaceId = <iface extends Abi>(iface: iface) => {
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++) {
memo[i] = memo[i] ^ bytes[i] // xor
// eslint-disable-next-line no-bitwise, no-param-reassign
memo[i] ^= bytes[i] // xor
}
return memo
}, new Uint8Array(4))
Expand All @@ -38,29 +41,29 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
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 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
const bulkRenewal = await viem.deployContract('BulkRenewal', [registry.address], {
client: deployer,
})

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

console.log('Set default resolver for eth tld to public resolver')
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.write.setInterface(
[namehash('eth'),
const tx2 = await resolver.write.setInterface([
namehash('eth'),
createInterfaceId(bulkRenewal.abi),
bulkRenewal.address,]
)
bulkRenewal.address,
])

console.log('Set interface implementor of eth tld for registrar controller')
const tx3 = await resolver.setInterface(
Expand Down
17 changes: 10 additions & 7 deletions deploy/00_get_registration_gas_values.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

/* 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) {
Expand Down Expand Up @@ -180,12 +180,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
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,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: 'data',
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
1 change: 0 additions & 1 deletion deploy/00_register_legacy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

/* eslint-disable no-await-in-loop */
import cbor from 'cbor'
import { ethers } from 'hardhat'
import { DeployFunction } from 'hardhat-deploy/types'
import { HardhatRuntimeEnvironment } from 'hardhat/types'
import pako from 'pako'
Expand Down
22 changes: 12 additions & 10 deletions deploy/00_register_wrapped.ts
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 { ethers } from 'hardhat'
import { DeployFunction } from 'hardhat-deploy/types'
import { HardhatRuntimeEnvironment } from 'hardhat/types'
import { Address, namehash } from 'viem'
Expand All @@ -15,6 +14,7 @@ import {
} from '@ensdomains/ensjs/utils'

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

type Name = {
name: string
Expand Down Expand Up @@ -148,16 +148,16 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
const { getNamedAccounts, network } = hre
const allNamedAccts = (await getNamedAccounts()) as Record<string, Address>

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

const makeData = ({ namedOwner, customDuration, fuses, name, subnames, ...rest }: Name) => {
const resolverAddress = publicResolver.address as Address
const resolverAddress = publicResolver.address

const secret =
// eslint-disable-next-line no-restricted-syntax
'0x0000000000000000000000000000000000000000000000000000000000000000' as Address
'0x0000000000000000000000000000000000000000000000000000000000000000' as const
const duration = customDuration || 31536000
// 1659467455 is the approximate time of the transaction, this is for keeping block hashes the same
const wrapperExpiry = 1659467455 + duration
Expand Down Expand Up @@ -191,16 +191,18 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
async ({ owner, name, ...rest }: ProcessedNameData, index: number) => {
const commitment = generateCommitment({ owner, name, ...rest })

const _controller = controller.connect(await ethers.getSigner(owner))
const commitTx = await _controller.commit(commitment, { nonce: nonce + index })
console.log(`Commiting commitment for ${name} (tx: ${commitTx.hash})...`)
const commitTx = await controller.write.commit([commitment], {
nonce: nonce + index,
account: owner,
})
console.log(`Commiting commitment for ${name} (tx: ${commitTx})...`)
return 1
}

const makeRegistration =
(nonce: number) =>
async ({ owner, name, duration, label, ...rest }: ProcessedNameData, index: number) => {
const [price] = await controller.rentPrice(label, duration)
const [price] = await controller.read.rentPrice([label, duration])

const _controller = controller.connect(await ethers.getSigner(owner))

Expand Down
13 changes: 6 additions & 7 deletions deploy/00_update_contracts.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
/* eslint-disable import/no-extraneous-dependencies */
import { ethers } from 'hardhat'
import { DeployFunction } from 'hardhat-deploy/types'
import { HardhatRuntimeEnvironment } from 'hardhat/types'

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

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

const dummyOracale = await ethers.getContract('DummyOracle')
const _dummyOracale = dummyOracale.connect(await ethers.getSigner(deployer))
const dummyOracale = (await getContract(hre)('DummyOracle', deployer))!

const txHash = await _dummyOracale['set(int256)']('156058000000')
const txHash = await dummyOracale.write['set(int256)'](['156058000000'], {})

console.log(`Setting dummy oracle to 156058000000 (tx: ${txHash.hash})...`)
console.log(`Setting dummy oracle to 156058000000 (tx: ${txHash})...`)
return true
}

Expand Down
6 changes: 3 additions & 3 deletions deploy/01_get_contract_addresses.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable import/no-extraneous-dependencies */
import { existsSync } from 'fs'
import { mkdir, writeFile } from 'fs/promises'
import { resolve } from 'path'
import { existsSync } from 'node:fs'
import { mkdir, writeFile } from 'node:fs/promises'
import { resolve } from 'node:path'

import { DeployFunction } from 'hardhat-deploy/types'
import { HardhatRuntimeEnvironment } from 'hardhat/types'
Expand Down
71 changes: 46 additions & 25 deletions deploy/utils/viem-hardhat.ts
Original file line number Diff line number Diff line change
@@ -1,35 +1,55 @@
import { HardhatRuntimeEnvironment } from "hardhat/types";
import { HardhatRuntimeEnvironment } from 'hardhat/types'

import 'hardhat-deploy'
import { Account, Address, GetContractReturnType, PublicClient, WalletClient, getAddress, getContract as getViemContract } from "viem";

import {
Account,
Address,
getAddress,
GetContractReturnType,
getContract as getViemContract,
PublicClient,
WalletClient,
} 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;
}
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 contract = getViemContract({
abi: deployment.abi,
address: deployment.address as Address,
client,
})
const client =
client_ ??
({
public: await hre.viem.getPublicClient(),
wallet: await hre.viem.getWalletClients().then(([c]) => c),
} as {
public: PublicClient
wallet: WalletClient
})

if (!contract) throw new Error(`Could not find contract ${contractName}`)
const contract = getViemContract({
abi: deployment.abi,
address: deployment.address as Address,
client,
})

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

return contract
}

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

Expand All @@ -39,6 +59,7 @@ export const getNamedClients = (hre: HardhatRuntimeEnvironment) => async () => {
const clients: Record<string, Client> = {}

for (const [name, address] of Object.entries(namedAccounts)) {
// eslint-disable-next-line no-await-in-loop
const namedClient = await hre.viem.getWalletClient(address as Address)
clients[name] = {
public: publicClient,
Expand All @@ -49,4 +70,4 @@ export const getNamedClients = (hre: HardhatRuntimeEnvironment) => async () => {
}

return clients
}
}
Loading

0 comments on commit f3164de

Please sign in to comment.