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

remove ethers completely #371

Merged
merged 1 commit into from
Jul 19, 2024
Merged
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
Binary file modified bun.lockb
Binary file not shown.
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
"abitype": "^1.0.2",
"chai": "^5.1.1",
"dotenv": "^16.4.5",
"ethers": "^5.6.1",
"hardhat": "^2.22.2",
"hardhat-abi-exporter": "^2.9.0",
"hardhat-contract-sizer": "^2.6.1",
Expand Down
8 changes: 4 additions & 4 deletions tasks/accounts.cts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import config = require('hardhat/config')
import { task } from 'hardhat/config.js'

config.task('accounts', 'Prints the list of accounts', async (_, hre) => {
const accounts = await hre.ethers.getSigners()
task('accounts', 'Prints the list of accounts', async (_, hre) => {
const accounts = await hre.viem.getWalletClients()

for (const account of accounts) {
for (const { account } of accounts) {
console.log(account.address)
}
})
218 changes: 104 additions & 114 deletions tasks/seed.ts
Original file line number Diff line number Diff line change
@@ -1,37 +1,35 @@
import { namehash } from 'viem/ens'
import { labelhash, namehash } from 'viem/ens'
import * as dotenv from 'dotenv'
import { task } from 'hardhat/config'
import { task } from 'hardhat/config.js'
import { Address, Hex, hexToBigInt } from 'viem'

const labelhash = (utils: any, label: string) =>
utils.keccak256(utils.toUtf8Bytes(label))

function getOpenSeaUrl(ethers: any, contract: string, namehashedname: string) {
const tokenId = ethers.BigNumber.from(namehashedname).toString()
function getOpenSeaUrl(contract: Address, namehashedname: Hex) {
const tokenId = hexToBigInt(namehashedname).toString()
return `https://testnets.opensea.io/assets/${contract}/${tokenId}`
}

task('seed', 'Creates test subbdomains and wraps them with Namewrapper')
.addPositionalParam('name', 'The ENS label to seed subdomains')
.setAction(async ({ name }, hre) => {
.setAction(async ({ name }: { name: string }, hre) => {
const { parsed: parsedFile, error } = dotenv.config({
path: './.env',
encoding: 'utf8',
})

if (error) throw error
if (!parsedFile) throw new Error('Failed to parse .env')

const ethers = hre.ethers
const [deployer] = await ethers.getSigners()
const [deployer] = await hre.viem.getWalletClients()
const CAN_DO_EVERYTHING = 0
const CANNOT_UNWRAP = 1
const CANNOT_SET_RESOLVER = 8
const firstAddress = deployer.address
const firstAddress = deployer.account.address
const {
REGISTRY_ADDRESS: registryAddress,
REGISTRAR_ADDRESS: registrarAddress,
WRAPPER_ADDRESS: wrapperAddress,
RESOLVER_ADDRESS: resolverAddress,
} = parsedFile
} = parsedFile as Record<string, Address>
if (
!(
registryAddress &&
Expand All @@ -42,7 +40,11 @@ task('seed', 'Creates test subbdomains and wraps them with Namewrapper')
) {
throw 'Set addresses on .env'
}
console.log('Account balance:', (await deployer.getBalance()).toString())
const publicClient = await hre.viem.getPublicClient()
console.log(
'Account balance:',
publicClient.getBalance({ address: deployer.account.address }),
)
console.log({
registryAddress,
registrarAddress,
Expand All @@ -51,137 +53,125 @@ task('seed', 'Creates test subbdomains and wraps them with Namewrapper')
firstAddress,
name,
})
const EnsRegistry = await (
await ethers.getContractFactory('ENSRegistry')
).attach(registryAddress)
const BaseRegistrar = await (
await ethers.getContractFactory('BaseRegistrarImplementation')
).attach(registrarAddress)
const NameWrapper = await (
await ethers.getContractFactory('NameWrapper')
).attach(wrapperAddress)
const Resolver = await (
await ethers.getContractFactory('PublicResolver')
).attach(resolverAddress)
const EnsRegistry = await hre.viem.getContractAt(
'ENSRegistry',
registryAddress,
)

const BaseRegistrar = await hre.viem.getContractAt(
'BaseRegistrarImplementation',
registrarAddress,
)

const NameWrapper = await hre.viem.getContractAt(
'NameWrapper',
wrapperAddress,
)

const Resolver = await hre.viem.getContractAt(
'PublicResolver',
resolverAddress,
)

const domain = `${name}.eth`
const namehashedname = namehash(domain)

await (
await BaseRegistrar.setApprovalForAll(NameWrapper.address, true)
).wait()
await BaseRegistrar.write.setApprovalForAll([NameWrapper.address, true])

console.log('BaseRegistrar setApprovalForAll successful')

await (
await EnsRegistry.setApprovalForAll(NameWrapper.address, true)
).wait()
console.log('EnsRegistry setApprovalForAll successful')

await (
await NameWrapper.wrapETH2LD(
name,
firstAddress,
CAN_DO_EVERYTHING,
0,
resolverAddress,
{
gasLimit: 10000000,
},
)
).wait()
await EnsRegistry.write.setApprovalForAll([NameWrapper.address, true])

await NameWrapper.write.wrapETH2LD(
[name, firstAddress, CAN_DO_EVERYTHING, resolverAddress],
{
gas: 10000000n,
},
)

console.log(
`Wrapped NFT for ${domain} is available at ${getOpenSeaUrl(
ethers,
NameWrapper.address,
namehashedname,
)}`,
)

await (
await NameWrapper.setSubnodeOwner(
namehash(`${name}.eth`),
'sub1',
firstAddress,
CAN_DO_EVERYTHING,
0,
)
).wait()
await NameWrapper.write.setSubnodeOwner([
namehash(`${name}.eth`),
'sub1',
firstAddress,
CAN_DO_EVERYTHING,
0n,
])

console.log('NameWrapper setSubnodeOwner successful for sub1')

await (
await NameWrapper.setSubnodeOwner(
namehash(`${name}.eth`),
'sub2',
firstAddress,
CAN_DO_EVERYTHING,
0,
)
).wait()
await NameWrapper.write.setSubnodeOwner([
namehash(`${name}.eth`),
'sub2',
firstAddress,
CAN_DO_EVERYTHING,
0n,
])

console.log('NameWrapper setSubnodeOwner successful for sub2')

await (
await NameWrapper.setResolver(
namehash(`sub2.${name}.eth`),
resolverAddress,
)
).wait()
await NameWrapper.write.setResolver([
namehash(`sub2.${name}.eth`),
resolverAddress,
])

console.log('NameWrapper setResolver successful for sub2')

await (
await Resolver.setText(
namehash(`sub2.${name}.eth`),
'domains.ens.nft.image',
'',
)
).wait()
await (
await Resolver.setText(
namehash(`sub2.${name}.eth`),
'avatar',
'https://i.imgur.com/1JbxP0P.png',
)
).wait()
await Resolver.write.setText([
namehash(`sub2.${name}.eth`),
'domains.ens.nft.image',
'',
])

await Resolver.write.setText([
namehash(`sub2.${name}.eth`),
'avatar',
'https://i.imgur.com/1JbxP0P.png',
])

console.log(
`Wrapped NFT for sub2.${name}.eth is available at ${getOpenSeaUrl(
ethers,
NameWrapper.address,
namehash(`sub2.${name}.eth`),
)}`,
)

await (
await NameWrapper.setFuses(namehash(`${name}.eth`), CANNOT_UNWRAP, {
gasLimit: 10000000,
})
).wait()
await NameWrapper.write.setFuses([namehash(`${name}.eth`), CANNOT_UNWRAP], {
gas: 10000000n,
})

console.log('NameWrapper set CANNOT_UNWRAP fuse successful for sub2')

await (
await NameWrapper.setFuses(namehash(`sub2.${name}.eth`), CANNOT_UNWRAP, {
gasLimit: 10000000,
})
).wait()
await NameWrapper.write.setFuses(
[namehash(`sub2.${name}.eth`), CANNOT_UNWRAP],
{
gas: 10000000n,
},
)

console.log('NameWrapper set CANNOT_UNWRAP fuse successful for sub2')

await (
await NameWrapper.setFuses(
namehash(`sub2.${name}.eth`),
CANNOT_SET_RESOLVER,
{
gasLimit: 10000000,
},
)
).wait()
await NameWrapper.write.setFuses(
[namehash(`sub2.${name}.eth`), CANNOT_SET_RESOLVER],
{
gas: 10000000n,
},
)

console.log('NameWrapper set CANNOT_SET_RESOLVER fuse successful for sub2')

await (
await NameWrapper.unwrap(
namehash(`${name}.eth`),
labelhash(ethers.utils, 'sub1'),
firstAddress,
{
gasLimit: 10000000,
},
)
).wait()
await NameWrapper.write.unwrap(
[namehash(`${name}.eth`), labelhash('sub1'), firstAddress],
{
gas: 10000000n,
},
)

console.log(`NameWrapper unwrap successful for ${name}`)
})