Skip to content

Commit

Permalink
fix bugs with concurrent registration
Browse files Browse the repository at this point in the history
  • Loading branch information
storywithoutend authored and SagiSan committed Sep 19, 2024
1 parent fe8e49c commit 9f03f25
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +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: makeWrappedNameGenerator,
} = require('../utils/wrappedNameGenerator.cjs')
Expand All @@ -32,46 +29,39 @@ const { makeNonceManager } = require('../utils/nonceManager.cjs')
* duration?: number | BigNumber
* }[]}
*/

const names = [
{
label: 'wrappedname',
label: 'concurrent-legacy-name',
type: 'legacy',
namedOwner: 'owner',
namedOwner: 'owner4',
reverseRecord: true,
},
{
label: 'wrappedname-with-subnames',
type: 'legacy',
namedOwner: 'owner',
label: 'concurrent-wrapped-name',
type: 'wrapped',
namedOwner: 'owner4',
reverseRecord: true,
subnames: [
{ label: 'test', namedOwner: 'owner2' },
{ label: 'legacy', namedOwner: 'owner2' },
{ label: 'xyz', namedOwner: 'owner2' },
{ label: 'addr', namedOwner: 'owner2' },
{ label: 'test', namedOwner: 'owner4' },
{ label: 'legacy', namedOwner: 'owner4' },
{ label: 'xyz', namedOwner: 'owner4' },
{ label: 'addr', namedOwner: 'owner4' },
],
},
{
label: 'expired-wrappedname',
type: 'legacy',
namedOwner: 'owner',
subnames: [{ label: 'test', namedOwner: 'owner2' }],
duration: 2419200,
},
]

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

const nonceManager = await makeNonceManager(hre)
const wrappedNameGenerator = await makeWrappedNameGenerator(hre, nonceManager)
const legacyNameGenerator = await makeLegacyNameGenerator(hre, nonceManager)

await network.provider.send('evm_setAutomine', [false])
// await network.provider.send("evm_setIntervalMining", [0]);

// Commit
const commitTxs = await Promise.all(
Expand Down Expand Up @@ -107,18 +97,20 @@ const func = async function (hre) {
fuses,
duration,
})
return commitTx
},
),
await network.provider.send('evm_mine')
)
await network.provider.send('evm_mine')

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 Down Expand Up @@ -221,9 +213,9 @@ const func = async function (hre) {
return true
}

func.id = 'register-wrapped-names'
func.tags = ['register-wrapped-names']
func.dependencies = ['ETHRegistrarController']
func.id = 'register-concurrent-names'
func.tags = ['register-concurrent-names']
func.dependencies = ['ETHRegistrarController', 'register-wrapped-names']
func.runAtTheEnd = true

module.exports = func
1 change: 1 addition & 0 deletions packages/ensjs/hardhat.config.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ const config = {
},
owner2: 2,
owner3: 3,
owner4: 4
},
external: {
contracts: [
Expand Down
12 changes: 12 additions & 0 deletions packages/ensjs/src/functions/public/getOwner.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,5 +84,17 @@ 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",
}
`)
})
})
})
1 change: 1 addition & 0 deletions packages/ensjs/utils/legacyNameGenerator.cjs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable import/no-extraneous-dependencies */
const { namehash, labelhash } = require('viem')

const makeNameGenerator = async (hre, optionalNonceManager ) => {
Expand Down
3 changes: 2 additions & 1 deletion packages/ensjs/utils/nonceManager.cjs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
/* eslint-disable import/no-extraneous-dependencies */
const { hexToNumber, numberToHex} = require('viem')

const makeNonceManager = async (href) => {
const { getNamedAccounts, network } = href
const names = ['owner', 'owner2', 'owner3']
const names = ['owner', 'owner2', 'owner3', 'owner4']
const allNamedAccts = await getNamedAccounts()
const startingNonces = await Promise.all(names.map((name) => network.provider.send('eth_getTransactionCount', [allNamedAccts[name], "latest"]).then(hexToNumber)))
const nonceMap = Object.fromEntries(names.map((name, i) => [name, startingNonces[i]]))
Expand Down
3 changes: 2 additions & 1 deletion packages/ensjs/utils/wrappedNameGenerator.cjs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* eslint-disable import/no-extraneous-dependencies */

const { BigNumber } = require('ethers')
const { parseUnits } = require('ethers/lib/utils')
const { namehash } = require('viem/ens')
Expand Down Expand Up @@ -56,7 +58,6 @@ const makeNameGenerator = async (hre, optionalNonceManager) => {
const [price] = await controller.rentPrice(label, duration)

const priceWithBuffer = BigNumber.from(price).mul(105).div(100)
console.log('price', price.toNumber(), priceWithBuffer.toNumber())
const _controller = controller.connect(await ethers.getSigner(owner))
return _controller.register(
label,
Expand Down

0 comments on commit 9f03f25

Please sign in to comment.