From f3164de7f9c9a6b6c4206eba85c70d77c01c4e1b Mon Sep 17 00:00:00 2001 From: v1rtl Date: Sat, 30 Nov 2024 11:50:18 +0200 Subject: [PATCH] wip --- deploy/00_deploy_bulk_renewal.ts | 25 +++++---- deploy/00_get_registration_gas_values.ts | 17 +++--- deploy/00_migrate_legacy_records.ts | 6 +- deploy/00_register_contracts.ts | 38 +++++-------- deploy/00_register_legacy.ts | 1 - deploy/00_register_wrapped.ts | 22 ++++---- deploy/00_update_contracts.ts | 13 ++--- deploy/01_get_contract_addresses.ts | 6 +- deploy/utils/viem-hardhat.ts | 71 +++++++++++++++--------- tsconfig.json | 4 +- 10 files changed, 110 insertions(+), 93 deletions(-) diff --git a/deploy/00_deploy_bulk_renewal.ts b/deploy/00_deploy_bulk_renewal.ts index 5419f38d5..7474f987d 100644 --- a/deploy/00_deploy_bulk_renewal.ts +++ b/deploy/00_deploy_bulk_renewal.ts @@ -10,16 +10,19 @@ import { namehash, toFunctionHash, } from 'viem' + import { getContract, getNamedClients } from './utils/viem-hardhat' -const createInterfaceId = (iface: iface) => { +const createInterfaceId = (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)) @@ -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( diff --git a/deploy/00_get_registration_gas_values.ts b/deploy/00_get_registration_gas_values.ts index 02d4665ed..b8e98e60f 100644 --- a/deploy/00_get_registration_gas_values.ts +++ b/deploy/00_get_registration_gas_values.ts @@ -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) { @@ -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())) diff --git a/deploy/00_migrate_legacy_records.ts b/deploy/00_migrate_legacy_records.ts index ae6800dcc..854a4a53d 100644 --- a/deploy/00_migrate_legacy_records.ts +++ b/deploy/00_migrate_legacy_records.ts @@ -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', @@ -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]) diff --git a/deploy/00_register_contracts.ts b/deploy/00_register_contracts.ts index 9b12321e7..00611ebbf 100644 --- a/deploy/00_register_contracts.ts +++ b/deploy/00_register_contracts.ts @@ -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', @@ -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, @@ -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...`) diff --git a/deploy/00_register_legacy.ts b/deploy/00_register_legacy.ts index 886248ac9..c5d868e74 100644 --- a/deploy/00_register_legacy.ts +++ b/deploy/00_register_legacy.ts @@ -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' diff --git a/deploy/00_register_wrapped.ts b/deploy/00_register_wrapped.ts index 87a967d7b..baa804fc7 100644 --- a/deploy/00_register_wrapped.ts +++ b/deploy/00_register_wrapped.ts @@ -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' @@ -15,6 +14,7 @@ import { } from '@ensdomains/ensjs/utils' import { nonceManager } from './.utils/nonceManager' +import { getContract } from './utils/viem-hardhat' type Name = { name: string @@ -148,16 +148,16 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) { const { getNamedAccounts, network } = hre const allNamedAccts = (await getNamedAccounts()) as Record - 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 @@ -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)) diff --git a/deploy/00_update_contracts.ts b/deploy/00_update_contracts.ts index d37a35f88..68ea23e6e 100644 --- a/deploy/00_update_contracts.ts +++ b/deploy/00_update_contracts.ts @@ -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 } diff --git a/deploy/01_get_contract_addresses.ts b/deploy/01_get_contract_addresses.ts index 1b494a5f4..13ea9a679 100644 --- a/deploy/01_get_contract_addresses.ts +++ b/deploy/01_get_contract_addresses.ts @@ -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' diff --git a/deploy/utils/viem-hardhat.ts b/deploy/utils/viem-hardhat.ts index 2c6393d45..adf93bcfc 100644 --- a/deploy/utils/viem-hardhat.ts +++ b/deploy/utils/viem-hardhat.ts @@ -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: 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: 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 & { address: Address; account: Account } @@ -39,6 +59,7 @@ export const getNamedClients = (hre: HardhatRuntimeEnvironment) => async () => { const clients: Record = {} 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, @@ -49,4 +70,4 @@ export const getNamedClients = (hre: HardhatRuntimeEnvironment) => async () => { } return clients -} \ No newline at end of file +} diff --git a/tsconfig.json b/tsconfig.json index f00fa1841..b0996b82c 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -68,8 +68,6 @@ "exclude": [ "**/*.ignore.ts", "**/*.ignore.tsx", - "functions/**/*", - "deploy/**/*", - "hardhat.config.ts" + "functions/**/*" ] } \ No newline at end of file