Skip to content

Commit

Permalink
fix filters for expiryDate and createdAt for getNamesForAddress and g…
Browse files Browse the repository at this point in the history
…etSubname
  • Loading branch information
storywithoutend committed Oct 11, 2024
1 parent 8321b4f commit 553a940
Show file tree
Hide file tree
Showing 10 changed files with 382 additions and 335 deletions.
99 changes: 30 additions & 69 deletions packages/ensjs/deploy/00_register_concurrently.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const {
} = require('../utils/legacyNameGenerator.cjs')
const { makeNonceManager } = require('../utils/nonceManager.cjs')
const { encodeFuses } = require('../dist/cjs/utils/fuses')
const { MAX_DATE_INT } = require('../dist/cjs/utils/consts')

const DURATION = 31556000

Expand All @@ -33,51 +34,16 @@ const DURATION = 31556000
* }[]}
*/

const sameExpiryNames = Array.from({ length: 21 }, (_, index) => ({
label: `same-expiry-legacy-name-${index}`,
type: 'legacy',
namedOwner: 'owner4',
reverseRecord: true,
duration: DURATION / 4,
}))

const expiryNames = Array.from({ length: 42 }, (_, index) => ({
label:
index < 21 ? `expiry-subname-${index}` : `no-expiry-subname-${index - 21}`,
namedOwner: 'owner4',
type: 'wrapped',
expiry: index < 21 ? Math.floor(Date.now() / 1000) + 7200 * (index + 1) : 0,
subnameFuses: encodeFuses({
input: {
parent: {
named: ['PARENT_CANNOT_CONTROL'],
},
child: {
named: ['CANNOT_UNWRAP'],
},
},
}),
}))

const names = [
...sameExpiryNames,
// ...expiryNames,
// {
// label: 'concurrent-legacy-name',
// type: 'legacy',
// namedOwner: 'owner4',
// reverseRecord: true,
// duration: 3600,
// },
// {
// label: 'concurrent-legacy-name-2',
// type: 'legacy',
// namedOwner: 'owner4',
// reverseRecord: true,
// duration: 3600,
// },
{
label: 'concurrent-wrapped-name',
...Array.from({ length: 2 }, (_, index) => ({
label: `concurrent-legacy-name-${index}`,
type: 'legacy',
namedOwner: 'owner4',
reverseRecord: true,
duration: DURATION,
})),
...Array.from({ length: 2 }, (_, index) => ({
label: `concurrent-wrapped-name-${index}`,
type: 'wrapped',
namedOwner: 'owner4',
fuses: encodeFuses({
Expand All @@ -87,10 +53,26 @@ const names = [
},
},
}),
reverseRecord: true,
duration: DURATION * 3,
subnames: [...expiryNames],
},
duration: DURATION,
subnames: [
{
label: `xyz`,
namedOwner: 'owner4',
type: 'wrapped',
expiry: MAX_DATE_INT,
fuses: encodeFuses({
input: {
parent: {
named: ['PARENT_CANNOT_CONTROL'],
},
child: {
named: ['CANNOT_UNWRAP'],
},
},
}),
},
],
})),
]

/**
Expand All @@ -116,14 +98,9 @@ const func = async function (hre) {
data = [],
reverseRecord = false,
fuses = 0,
subnames,
duration = 31536000,
}) => {
console.log(`Committing commitment for ${label}.eth...`)
// console.log(
// `Committing commitment for ${label}.eth (tx: ${commitTx.hash})...`,
// )
let commitTx
if (type === 'legacy')
return legacyNameGenerator.commit({
label,
Expand All @@ -143,14 +120,12 @@ const func = async function (hre) {
)

network.provider.send('evm_mine')
console.log('committing...')
await Promise.all(
commitTxs.map(async (tx) => {
return tx.wait()
}),
)

console.log('committed')
const oldTimestamp = (await ethers.provider.getBlock('latest')).timestamp
await network.provider.send('evm_setNextBlockTimestamp', [oldTimestamp + 60])
await network.provider.send('evm_increaseTime', [300])
Expand All @@ -170,7 +145,6 @@ const func = async function (hre) {
subnames,
duration = 31536000,
}) => {
let registerTx
if (type === 'legacy')
return legacyNameGenerator.register({
label,
Expand Down Expand Up @@ -204,11 +178,7 @@ const func = async function (hre) {
label,
namedOwner,
type,
data = [],
reverseRecord = false,
fuses = 0,
subnames,
duration = 31536000,
} of names) {
if (!subnames) continue
console.log(`Setting subnames for ${label}.eth...`)
Expand Down Expand Up @@ -240,16 +210,7 @@ const func = async function (hre) {
}
}

console.log(
'status after registration',
await network.provider.send('txpool_content'),
)
await network.provider.send('evm_mine')
console.log(
'status after registration',
await network.provider.send('txpool_content'),
)

return true
}

Expand Down
87 changes: 16 additions & 71 deletions packages/ensjs/deploy/00_register_legacy.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -359,81 +359,31 @@ const names = [
namedOwner: 'owner2',
namedAddr: 'owner2',
})),
...Array.from({ length: 2}, (_, i) => ({
label: `nonconcurrent-legacy-name-${i}`,
namedOwner: 'owner4',
namedAddr: 'owner4',
duration: 31536000 / 2,
subnames: [
{
label: `test`,
namedOwner: 'owner4',
},
{
label: `xyz`,
namedOwner: 'owner4',
}
]
}))
]

const makeNameGenerator2 = async (hre) => {
const { getNamedAccounts, network } = hre
const allNamedAccts = await getNamedAccounts()
const controller = await ethers.getContract('LegacyETHRegistrarController')
const publicResolver = await ethers.getContract('LegacyPublicResolver')
const registry = await ethers.getContract('ENSRegistry')

return {
commit: async ({ label, namedOwner, namedAddr }) => {
const secret =
'0x0000000000000000000000000000000000000000000000000000000000000000'
const registrant = allNamedAccts[namedOwner]
const resolver = publicResolver.address
const addr = allNamedAccts[namedAddr]

const commitment = await controller.makeCommitmentWithConfig(
label,
registrant,
secret,
resolver,
addr,
)

const _controller = controller.connect(await ethers.getSigner(registrant))
return _controller.commit(commitment)
},
register: async ({ label, namedOwner, namedAddr, duration = 31536000 }) => {
const secret =
'0x0000000000000000000000000000000000000000000000000000000000000000'
const registrant = allNamedAccts[namedOwner]
const resolver = publicResolver.address
const addr = allNamedAccts[namedAddr]
const price = await controller.rentPrice(label, duration)
const _controller = controller.connect(await ethers.getSigner(registrant))
return _controller.registerWithConfig(
label,
registrant,
duration,
secret,
resolver,
addr,
{
value: price,
},
)
},
subname: async ({ label, namedOwner, subnameLabel, namedSubnameOwner }) => {
console.log(`Setting subnames for ${label}.eth...`)
const resolver = publicResolver.address
const registrant = allNamedAccts[namedOwner]
const owner = allNamedAccts[namedSubnameOwner]
const _registry = registry.connect(await ethers.getSigner(registrant))
return _registry.setSubnodeRecord(
namehash(`${label}.eth`),
labelhash(subnameLabel),
owner,
resolver,
'0',
)
},
setSubnameRecords: async () => {},
configure: async () => {},
}
}

/**
* @type {import('hardhat-deploy/types').DeployFunction}
*/
const func = async function (hre) {
const { getNamedAccounts, network } = hre
const allNamedAccts = await getNamedAccounts()

const controller = await ethers.getContract('LegacyETHRegistrarController')
const publicResolver = await ethers.getContract('LegacyPublicResolver')

await network.provider.send('anvil_setBlockTimestampInterval', [60])
Expand All @@ -448,12 +398,7 @@ const func = async function (hre) {
subnames,
duration = 31536000,
} of names) {
const secret =
'0x0000000000000000000000000000000000000000000000000000000000000000'
const registrant = allNamedAccts[namedOwner]
const resolver = publicResolver.address
const addr = allNamedAccts[namedAddr]

const commitTx = await nameGenerator.commit({
label,
namedOwner,
Expand Down
37 changes: 30 additions & 7 deletions packages/ensjs/deploy/00_register_wrapped.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
// eslint-disable-next-line @typescript-eslint/naming-convention
const { BigNumber } = require('ethers')
const { ethers } = require('hardhat')
const { namehash } = require('viem/ens')
const { MAX_DATE_INT } = require('../dist/cjs/utils/consts')
const { encodeFuses } = require('../dist/cjs/utils/fuses')
const { makeNameGenerator } = require('../utils/wrappedNameGenerator.cjs')
Expand Down Expand Up @@ -99,6 +98,36 @@ const names = [
},
],
},
...Array.from({ length: 2}, (_, index) => ({
label: `nonconcurrent-wrapped-name-${index}`,
namedOwner: 'owner4',
fuses: encodeFuses({
input: {
child: {
named: ['CANNOT_UNWRAP'],
},
},
}),
duration: 31556000 * 2,
subnames: [
{
label: `xyz`,
namedOwner: 'owner4',
expiry: MAX_DATE_INT,
fuses: encodeFuses({
input: {
parent: {
named: ['PARENT_CANNOT_CONTROL'],
},
child: {
named: ['CANNOT_UNWRAP'],
},
},
}),
},
],

}))
]

/**
Expand All @@ -110,7 +139,6 @@ const func = async function (hre) {

const nameGenerator = await makeNameGenerator(hre)

const controller = await ethers.getContract('ETHRegistrarController')
const publicResolver = await ethers.getContract('PublicResolver')

await network.provider.send('anvil_setBlockTimestampInterval', [60])
Expand All @@ -124,11 +152,6 @@ const func = async function (hre) {
subnames,
duration = 31536000,
} of names) {
const secret =
'0x0000000000000000000000000000000000000000000000000000000000000000'
const owner = allNamedAccts[namedOwner]
const resolver = publicResolver.address

const commitTx = await nameGenerator.commit({
label,
namedOwner,
Expand Down
3 changes: 2 additions & 1 deletion packages/ensjs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,8 @@
"dns-packet": "^5.3.1",
"graphql": "^16.3.0",
"graphql-request": "6.1.0",
"pako": "^2.1.0"
"pako": "^2.1.0",
"ts-pattern": "^5.4.0"
},
"devDependencies": {
"@ensdomains/buffer": "^0.0.13",
Expand Down
12 changes: 0 additions & 12 deletions packages/ensjs/src/functions/public/getOwner.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,17 +84,5 @@ describe('getOwner', () => {
}
`)
})

it('should return correct ownership level and values for an expired wrapped name', async () => {
const result = await getOwner(publicClient, {
name: 'concurrent-wrapped-name.eth',
})
expect(result).toMatchInlineSnapshot(`
{
"owner": "0x3C44CdDdB6a900fa2b585dd299e03d12FA4293BC",
"ownershipLevel": "nameWrapper",
}
`)
})
})
})
Loading

0 comments on commit 553a940

Please sign in to comment.