Skip to content

Commit

Permalink
Merge pull request #243 from Consensys/chore/script-generate-owner-re…
Browse files Browse the repository at this point in the history
…gister-txs

Chore/script generate owner register txs
  • Loading branch information
Julink-eth authored Sep 13, 2024
2 parents 0b91c24 + 25529f1 commit a55368b
Show file tree
Hide file tree
Showing 3 changed files with 145 additions and 2 deletions.
5 changes: 3 additions & 2 deletions packages/linea-ens-contracts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@
"@openzeppelin/contracts": "^4.1.0",
"axios": "^1.7.4",
"csv-parse": "^5.5.6",
"dns-packet": "^5.3.0"
"dns-packet": "^5.3.0",
"fs": "^0.0.1-security"
},
"directories": {
"test": "test"
Expand All @@ -80,4 +81,4 @@
"volta": {
"node": "16.20.2"
}
}
}
137 changes: 137 additions & 0 deletions packages/linea-ens-contracts/scripts/generateOwnerRegisterTxs.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
import fs from 'fs'
import resolverJson from '../deployments/lineaMainnet/PublicResolver.json'
import { ethers } from 'ethers'
import path from 'path'
import { parse } from 'csv-parse'

const CSV_FILE_PATH = path.resolve(__dirname, './domains.csv')
const RESULT_CSV_FILE_PATH = path.resolve(__dirname, './result.json')

const txs: {
to: string
value: string
data: null
contractMethod: {
inputs: { internalType: string; name: string; type: string }[]
name: string
payable: boolean
}
contractInputsValues: {
name: string
owner: string
duration: string
resolver: string
data: string
ownerControlledFuses: string
reverseRecord: string
}
}[] = []

fs.createReadStream(CSV_FILE_PATH)
.pipe(parse({ columns: true }))
.on('data', (data: { owner: string; domain: string }) =>
processDomain(data.owner, data.domain),
)
.on('end', () => {
// Process the CSV data
const result = {
version: '1.0',
chainId: '59144',
createdAt: 1726144999725,
meta: {
name: 'Transactions Batch',
description: '',
txBuilderVersion: '1.16.5',
createdFromSafeAddress: '0x9280D881b0180a5e2c378f6bb6071c905b070C97',
createdFromOwnerAddress: '',
checksum:
'0x6c503b6f029a7a70f378e6a3629589a2047888c03604463f09fb2c4938a98c3f',
},
transactions: txs,
}

fs.writeFileSync(RESULT_CSV_FILE_PATH, JSON.stringify(result))

console.log('Done, written to', RESULT_CSV_FILE_PATH)
})

const LINEA_COIN_TYPE = 2147542792

const resolverIface = ethers.Contract.getInterface(resolverJson.abi)

function processDomain(owner: string, domain: string) {
console.log(`Domain: ${domain}, Owner: ${owner}`)

const fullDomainName = `${domain}.linea.eth`
const namehash = ethers.utils.namehash(fullDomainName)

const data = [
resolverIface.encodeFunctionData('setAddr(bytes32,address)', [
namehash,
owner,
]),
resolverIface.encodeFunctionData('setAddr(bytes32,uint256,bytes)', [
namehash,
LINEA_COIN_TYPE,
owner,
]),
]

const tx = {
to: '0xDb75Db974B1F2bD3b5916d503036208064D18295',
value: '0',
data: null,
contractMethod: {
inputs: [
{
internalType: 'string',
name: 'name',
type: 'string',
},
{
internalType: 'address',
name: 'owner',
type: 'address',
},
{
internalType: 'uint256',
name: 'duration',
type: 'uint256',
},
{
internalType: 'address',
name: 'resolver',
type: 'address',
},
{
internalType: 'bytes[]',
name: 'data',
type: 'bytes[]',
},
{
internalType: 'uint16',
name: 'ownerControlledFuses',
type: 'uint16',
},
{
internalType: 'bool',
name: 'reverseRecord',
type: 'bool',
},
],
name: 'ownerRegister',
payable: false,
},
contractInputsValues: {
name: domain,
owner: owner,
duration: '3122064000',
resolver: '0x86c5AED9F27837074612288610fB98ccC1733126',
data: JSON.stringify(data),
ownerControlledFuses: '0',
reverseRecord: 'true',
},
}

txs.push(tx)
}
5 changes: 5 additions & 0 deletions packages/linea-ens-contracts/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5267,6 +5267,11 @@ fs.realpath@^1.0.0:
resolved "https://registry.yarnpkg.com/fs.realpath/-/fs.realpath-1.0.0.tgz#1504ad2523158caa40db4a2787cb01411994ea4f"
integrity sha512-OO0pH2lK6a0hZnAdau5ItzHPI6pUlvI7jMVnxUQRtw4owF2wk8lOSabtGDCTP4Ggrg2MbGnWO9X8K1t4+fGMDw==

fs@^0.0.1-security:
version "0.0.1-security"
resolved "https://registry.yarnpkg.com/fs/-/fs-0.0.1-security.tgz#8a7bd37186b6dddf3813f23858b57ecaaf5e41d4"
integrity sha512-3XY9e1pP0CVEUCdj5BmfIZxRBTSDycnbqhIOGec9QYtmVH2fbLpj86CFWkrNOkt/Fvty4KZG5lTglL9j/gJ87w==

fsevents@~2.1.1:
version "2.1.3"
resolved "https://registry.yarnpkg.com/fsevents/-/fsevents-2.1.3.tgz#fb738703ae8d2f9fe900c33836ddebee8b97f23e"
Expand Down

0 comments on commit a55368b

Please sign in to comment.