Skip to content

Commit

Permalink
backwards compat
Browse files Browse the repository at this point in the history
  • Loading branch information
TateB committed Jan 23, 2024
1 parent 8a66dcf commit 6d07cc8
Show file tree
Hide file tree
Showing 10 changed files with 802 additions and 102 deletions.
120 changes: 120 additions & 0 deletions packages/ensjs/deploy/01_legacy_dnsregistrar.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
/* eslint-disable @typescript-eslint/naming-convention */
/* eslint-disable no-await-in-loop */
/* eslint-disable import/no-extraneous-dependencies */
const { readFile } = require('fs/promises')
const { resolve } = require('path')
const { labelhash } = require('viem')

const ensContractsPath = './node_modules/@ensdomains/ens-contracts'
const mainnetArtifactsPath = resolve(ensContractsPath, './deployments/mainnet')

const constructorArgs = [
'0x00002b000100000e1000244a5c080249aac11d7b6f6446702e54a1607371607a1a41855200fd2ce1cdde32f24e8fb500002b000100000e1000244f660802e06d44b80b8f1d39a95c0b0d7c65d08458e880409bbc683457104237c7f8ec8d',
]

/**
* @param {string} name
*/
const getMainnetArtifact = async (name) => {
const deployment = JSON.parse(
await readFile(resolve(mainnetArtifactsPath, `${name}.json`), 'utf8'),
)
const artifact = {
_format: 'hh-sol-artifact-1',
contractName: `Legacy${name}`,
abi: deployment.abi,
bytecode: deployment.bytecode,
deployedBytecode: deployment.deployedBytecode,
linkReferences: {},
deployedLinkReferences: {},
}
return artifact
}

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

const { address: legacyDnssecImplAddress } = await deploy(
'LegacyDNSSECImpl',
{
from: deployer,
args: constructorArgs,
log: true,
contract: await getMainnetArtifact('DNSSECImpl'),
},
)

const dnssec = await hre.ethers.getContract('LegacyDNSSECImpl')

const algorithms = {
5: 'RSASHA1Algorithm',
7: 'RSASHA1Algorithm',
8: 'RSASHA256Algorithm',
13: 'P256SHA256Algorithm',
}
const digests = {
1: 'SHA1Digest',
2: 'SHA256Digest',
}

const transactions = []
for (const [id, alg] of Object.entries(algorithms)) {
const { address } = await deployments.get(alg)
if (address !== (await dnssec.algorithms(id))) {
transactions.push(await dnssec.setAlgorithm(id, address))
}
}

for (const [id, digest] of Object.entries(digests)) {
const { address } = await deployments.get(digest)
if (address !== (await dnssec.digests(id))) {
transactions.push(await dnssec.setDigest(id, address))
}
}

console.log(
`Waiting on ${transactions.length} transactions setting legacy DNSSEC parameters`,
)
await Promise.all(transactions.map((tx) => tx.wait()))

const root = await hre.ethers.getContract('Root')
const { address: registryAddress } = await hre.ethers.getContract(
'ENSRegistry',
)
const { address: publicSuffixListAddress } = await hre.ethers.getContract(
'TLDPublicSuffixList',
)

const { address: legacyDnsRegistrarAddress } = await deploy(
'LegacyDNSRegistrar',
{
from: deployer,
args: [legacyDnssecImplAddress, publicSuffixListAddress, registryAddress],
log: true,
contract: await getMainnetArtifact('DNSRegistrar'),
},
)

const tx = await root
.connect(await hre.ethers.getSigner(owner))
.setController(legacyDnsRegistrarAddress, true)
console.log(
`Setting LegacyDNSRegistrar as controller of Root... (${tx.hash})`,
)
await tx.wait()

const tx2 = await root
.connect(await hre.ethers.getSigner(owner))
.setSubnodeOwner(labelhash('xyz'), legacyDnsRegistrarAddress)
console.log(`Setting LegacyDNSRegistrar as owner of xyz... (${tx2.hash})`)
await tx2.wait()
}

func.dependencies = ['Root']

module.exports = func
28 changes: 22 additions & 6 deletions packages/ensjs/src/contracts/consts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@ export const supportedChains = ['homestead', 'goerli', 'sepolia'] as const
export const supportedContracts = [
'ensBaseRegistrarImplementation',
'ensDnsRegistrar',
'ensLegacyDnsRegistrar',
'ensEthRegistrarController',
'ensNameWrapper',
'ensPublicResolver',
'ensReverseRegistrar',
'ensBulkRenewal',
'ensLegacyDnssecImpl',
'ensDnssecImpl',
'ensUniversalResolver',
'ensRegistry',
Expand All @@ -30,6 +32,11 @@ export const supportedContracts = [
export type SupportedChain = (typeof supportedChains)[number]
export type SupportedContract = (typeof supportedContracts)[number]

type LegacyDnsContracts = 'ensLegacyDnsRegistrar' | 'ensLegacyDnssecImpl'
type DnsContracts = 'ensDnsRegistrar' | 'ensDnssecImpl'
type OptionalContracts = LegacyDnsContracts | DnsContracts
type RequiredContracts = Exclude<SupportedContract, OptionalContracts>

export const addresses = {
homestead: {
ensRegistry: {
Expand All @@ -38,7 +45,7 @@ export const addresses = {
ensBaseRegistrarImplementation: {
address: '0x57f1887a8bf19b14fc0df6fd9b2acc9af147ea85',
},
ensDnsRegistrar: {
ensLegacyDnsRegistrar: {
address: '0x58774Bb8acD458A640aF0B88238369A167546ef2',
},
ensEthRegistrarController: {
Expand All @@ -56,7 +63,7 @@ export const addresses = {
ensBulkRenewal: {
address: '0xa12159e5131b1eEf6B4857EEE3e1954744b5033A',
},
ensDnssecImpl: {
ensLegacyDnssecImpl: {
address: '0x21745FF62108968fBf5aB1E07961CC0FCBeB2364',
},
ensUniversalResolver: {
Expand Down Expand Up @@ -129,7 +136,11 @@ export const addresses = {
},
} as const satisfies Record<
SupportedChain,
Record<SupportedContract, { address: Address }>
Record<RequiredContracts, { address: Address }> &
(
| Record<LegacyDnsContracts, { address: Address }>
| Record<DnsContracts, { address: Address }>
)
>

type Subgraphs = {
Expand Down Expand Up @@ -158,13 +169,15 @@ export const subgraphs = {

type EnsChainContracts = {
ensBaseRegistrarImplementation: ChainContract
ensDnsRegistrar: ChainContract
ensDnsRegistrar?: ChainContract
ensLegacyDnsRegistrar?: ChainContract
ensEthRegistrarController: ChainContract
ensNameWrapper: ChainContract
ensPublicResolver: ChainContract
ensReverseRegistrar: ChainContract
ensBulkRenewal: ChainContract
ensDnssecImpl: ChainContract
ensDnssecImpl?: ChainContract
ensLegacyDnssecImpl?: ChainContract
}

type BaseChainContracts = {
Expand All @@ -173,7 +186,10 @@ type BaseChainContracts = {
ensRegistry: ChainContract
}

export type ChainWithEns<TChain extends Chain = Chain> = TChain & {
export type ChainWithEns<TChain extends Chain = Chain> = Omit<
TChain,
'contracts'
> & {
contracts: BaseChainContracts & EnsChainContracts
subgraphs: Subgraphs
}
Expand Down
13 changes: 9 additions & 4 deletions packages/ensjs/src/contracts/getChainContractAddress.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Chain } from 'viem'
import type { Address, Chain } from 'viem'
import { getChainContractAddress as _getChainContractAddress } from 'viem/utils'

type ExtractContract<TClient> = TClient extends {
Expand All @@ -12,18 +12,23 @@ type ExtractContract<TClient> = TClient extends {
export const getChainContractAddress = <
const TClient extends { chain: Chain },
TContracts extends ExtractContract<TClient> = ExtractContract<TClient>,
TContract extends keyof TContracts = keyof TContracts,
TContractName extends keyof TContracts = keyof TContracts,
TContract extends TContracts[TContractName] = TContracts[TContractName],
>({
blockNumber,
client,
contract,
}: {
blockNumber?: bigint
client: TClient
contract: TContract
contract: TContractName
}) =>
_getChainContractAddress({
blockNumber,
chain: client.chain,
contract: contract as string,
}) as TContracts[TContract]['address']
}) as TContract extends { address: infer A }
? A extends Address
? A
: never
: Address
73 changes: 73 additions & 0 deletions packages/ensjs/src/contracts/legacyDnsRegistrar.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
export const legacyDnsRegistrarProveAndClaimSnippet = [
{
inputs: [
{
name: 'name',
type: 'bytes',
},
{
components: [
{
name: 'rrset',
type: 'bytes',
},
{
name: 'sig',
type: 'bytes',
},
],
name: 'input',
type: 'tuple[]',
},
{
name: 'proof',
type: 'bytes',
},
],
name: 'proveAndClaim',
outputs: [],
stateMutability: 'nonpayable',
type: 'function',
},
] as const

export const legacyDnsRegistrarProveAndClaimWithResolverSnippet = [
{
inputs: [
{
name: 'name',
type: 'bytes',
},
{
components: [
{
name: 'rrset',
type: 'bytes',
},
{
name: 'sig',
type: 'bytes',
},
],
name: 'input',
type: 'tuple[]',
},
{
name: 'proof',
type: 'bytes',
},
{
name: 'resolver',
type: 'address',
},
{
name: 'addr',
type: 'address',
},
],
name: 'proveAndClaimWithResolver',
outputs: [],
stateMutability: 'nonpayable',
type: 'function',
},
] as const
46 changes: 46 additions & 0 deletions packages/ensjs/src/contracts/legacyDnssecImpl.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
export const legacyDnssecImplRrDataSnippet = [
{
inputs: [
{
name: 'dnstype',
type: 'uint16',
},
{
name: 'name',
type: 'bytes',
},
],
name: 'rrdata',
outputs: [
{
name: '',
type: 'uint32',
},
{
name: '',
type: 'uint32',
},
{
name: '',
type: 'bytes20',
},
],
stateMutability: 'view',
type: 'function',
},
] as const

export const legacyDnssecImplAnchorsSnippet = [
{
inputs: [],
name: 'anchors',
outputs: [
{
name: '',
type: 'bytes',
},
],
stateMutability: 'view',
type: 'function',
},
] as const
Loading

0 comments on commit 6d07cc8

Please sign in to comment.