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

feat: optimized and fix ownerRegister script #192

Merged
merged 1 commit into from
Jul 10, 2024
Merged
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
54 changes: 44 additions & 10 deletions packages/linea-ens-contracts/scripts/ownerRegister.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import fs from 'fs'
import { parse } from 'csv-parse'
import 'dotenv/config'
import { Contract } from 'ethers'
import { constants, Contract } from 'ethers'
import path from 'path'
import { HardhatRuntimeEnvironment } from 'hardhat/types'
import axios from 'axios'
Expand Down Expand Up @@ -111,8 +111,10 @@ async function main(hre: HardhatRuntimeEnvironment) {
resolver: Contract,
contractOwner: string,
provider: ethers.providers.JsonRpcProvider,
nonce: number,
) {
const fullDomainName = `${domainName}.${process.env.BASE_DOMAIN}.eth`
const domainNameLowerCase = domainName.toLowerCase()
const fullDomainName = `${domainNameLowerCase}.${process.env.BASE_DOMAIN}.eth`
const namehash = hre.ethers.utils.namehash(fullDomainName)

const data = [
Expand All @@ -122,12 +124,36 @@ async function main(hre: HardhatRuntimeEnvironment) {
]),
]

console.log(`Data for ${domainName}:`, data)
console.log(`Data for ${domainNameLowerCase}:`, data)

try {
const resolverRead = new Contract(
resolver.address,
[
{
inputs: [
{ internalType: 'bytes32', name: 'node', type: 'bytes32' },
],
name: 'addr',
outputs: [
{ internalType: 'address payable', name: '', type: 'address' },
],
stateMutability: 'view',
type: 'function',
},
],
provider,
)
// Does not try to register if the domain is already registered
const resolvedAddr = await resolverRead.addr(namehash)
if (resolvedAddr !== constants.AddressZero) {
console.log(`Domain ${domainNameLowerCase} already registered.`)
return DomainStatuses.Success
}

const estimatedGasLimit =
await registrarController.estimateGas.ownerRegister(
domainName,
domainNameLowerCase,
ownerAddress,
DURATION,
resolver.address,
Expand All @@ -138,14 +164,15 @@ async function main(hre: HardhatRuntimeEnvironment) {
)

console.log(
`Estimated gas limit for ${domainName}: ${estimatedGasLimit.toString()}`,
`Estimated gas limit for ${domainNameLowerCase}: ${estimatedGasLimit.toString()}`,
)

const gasPrice = await provider.getGasPrice()
const nonce = await provider.getTransactionCount(contractOwner)
let gasPrice = await provider.getGasPrice()
// Increase gas price by 20%
gasPrice = gasPrice.add(gasPrice.mul(2).div(10))

const tx = await registrarController.populateTransaction.ownerRegister(
domainName,
domainNameLowerCase,
ownerAddress,
DURATION,
resolver.address,
Expand Down Expand Up @@ -183,10 +210,10 @@ async function main(hre: HardhatRuntimeEnvironment) {

await provider.sendTransaction(serializedSignedTx)

console.log(`Domain ${domainName} registered successfully.`)
console.log(`Domain ${domainNameLowerCase} registered successfully.`)
return DomainStatuses.Success
} catch (error: any) {
console.error(`Failed to register domain ${domainName}:`, error)
console.error(`Failed to register domain ${domainNameLowerCase}:`, error)
if (error?.error?.data) {
const revertReason = hre.ethers.utils.toUtf8String(
'0x' + error.error.data.substr(138),
Expand Down Expand Up @@ -237,6 +264,7 @@ async function main(hre: HardhatRuntimeEnvironment) {
})

async function processDomains(trackingData: Map<string, TrackingData>) {
let nonce = await provider.getTransactionCount(registrarControllerOwner)
for (const [domain, data] of trackingData.entries()) {
if (
data.status === DomainStatuses.NotStarted ||
Expand All @@ -250,7 +278,13 @@ async function main(hre: HardhatRuntimeEnvironment) {
resolver,
registrarControllerOwner,
provider,
nonce,
)
if (status === DomainStatuses.Success) {
nonce++
} else {
nonce = await provider.getTransactionCount(registrarControllerOwner)
}
trackingData.set(domain, { ...data, status })
updateTrackingFile(trackingData)
}
Expand Down