Skip to content

Commit

Permalink
merge staging into
Browse files Browse the repository at this point in the history
  • Loading branch information
mdtanrikulu committed Aug 22, 2024
2 parents c3a0836 + a6139f0 commit 1445c3f
Show file tree
Hide file tree
Showing 10 changed files with 1,043 additions and 149 deletions.
2 changes: 1 addition & 1 deletion .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

yarn format && git add .
bun run format && git add .
14 changes: 11 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -152,21 +152,29 @@ This repo runs a husky precommit to prettify all contract files to keep them con
```
git clone https://github.com/ensdomains/ens-contracts
cd ens-contracts
yarn
bun i
```

### How to run tests

```
yarn test
bun run test
```

### How to publish

```
yarn pub
bun run pub
```

### Deployment

```
NODE_OPTIONS='--experimental-loader ts-node/esm/transpile-only' bun run hardhat --network <network_name> deploy
```

Full list of available networks for deployment is [here](hardhat.config.cts#L38).

### Release flow

1. Create a `feature` branch from `staging` branch
Expand Down
10 changes: 4 additions & 6 deletions contracts/wrapper/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -442,13 +442,12 @@ RESOLVER_ADDRESS=

### Run deploy script

`yarn deploy:rinkeby` will deploy to rinkeby and verify its source code
`bun run deploy:rinkeby` will deploy to rinkeby and verify its source code

NOTE: If you want to override the default metadata url, set `METADATA_HOST=` to `.env`

```
$yarn deploy:rinkeby
yarn run v1.22.10
$ bun run deploy:rinkeby
$ npx hardhat run --network rinkeby scripts/deploy.js
Deploying contracts to rinkeby with the account:0x97bA55F61345665cF08c4233b9D6E61051A43B18
Account balance: 1934772596667918724 true
Expand All @@ -472,11 +471,10 @@ After running the script it sets addresses to `.env`. If you want to redeploy so

1. Register a name using the account you used to deploy the contract
2. Set the label (`matoken` for `matoken.eth`) to `SEED_NAME=` on `.env`
3. Run `yarn seed:rinkeby`
3. Run `bun run seed:rinkeby`

```
~/.../ens/name-wrapper (seed)$yarn seed:rinkeby
yarn run v1.22.10
~/.../ens/name-wrapper (seed)$ bun run seed:rinkeby
$ npx hardhat run --network rinkeby scripts/seed.js
Account balance: 1925134991223891632
{
Expand Down
446 changes: 446 additions & 0 deletions deployments/mainnet/solcInputs/96d118177ae253bdd3815d2757c11cd9.json

Large diffs are not rendered by default.

39 changes: 23 additions & 16 deletions deployments/sepolia/ExtendedDNSResolver.json

Large diffs are not rendered by default.

446 changes: 446 additions & 0 deletions deployments/sepolia/solcInputs/96d118177ae253bdd3815d2757c11cd9.json

Large diffs are not rendered by default.

7 changes: 3 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@ensdomains/ens-contracts",
"version": "1.0.0",
"version": "1.0.1",
"description": "ENS contracts",
"type": "module",
"scripts": {
Expand All @@ -12,8 +12,8 @@
"lint": "hardhat check",
"build": "rm -rf ./build/deploy ./build/hardhat.config.js && hardhat compile && tsc",
"format": "prettier --write .",
"prepublishOnly": "yarn build",
"pub": "yarn publish --access public",
"prepublishOnly": "bun run build",
"pub": "npm publish --access public",
"prepare": "husky install",
"wikiCheck": "bun ./scripts/wikiCheck.ts",
"postinstall": "bunx patch-package"
Expand All @@ -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}`)
})
Loading

0 comments on commit 1445c3f

Please sign in to comment.