Skip to content

Commit

Permalink
added NameWrapper + UniversalResolver deploy scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
TateB committed Mar 18, 2022
1 parent e1bd01d commit 01cc26a
Show file tree
Hide file tree
Showing 9 changed files with 476 additions and 71 deletions.
210 changes: 159 additions & 51 deletions .pnp.cjs

Large diffs are not rendered by default.

Binary file not shown.
9 changes: 2 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,17 @@
"devDependencies": {
"@typescript-eslint/eslint-plugin": "^5.15.0",
"@typescript-eslint/parser": "^5.15.0",
"dotenv": "^16.0.0",
"ens-contracts": "github:ensdomains/ens-contracts#universal",
"eslint": "^8.11.0",
"eslint-config-airbnb": "^19.0.4",
"eslint-config-airbnb-base": "^15.0.0",
"eslint-config-airbnb-typescript": "^16.1.2",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-prettier": "^4.0.0",
"ethers": "^5.6.1",
"prettier": "^2.6.0",
"ts-node": "^10.7.0",
"typescript": "^4.6.2"
},
"dependenciesMeta": {
"[email protected]": {
"unplugged": true
}
"dependencies": {
"ethers": "^5.6.1"
}
}
File renamed without changes.
131 changes: 131 additions & 0 deletions packages/ensjs/deployments/NameWrapper.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
import { ethers } from 'ethers'
import fs from 'fs'
import nModule from 'module'
import path from 'path'
import solc from 'solc'

const pnp = nModule.findPnpApi('./')
const contracts = pnp.resolveToUnqualified(
'ens-contracts-namewrapper/contracts',
'./',
)

const findImports = (ogPath) => (filePath) => {
let newPath = path.resolve(contracts, ogPath, './' + filePath)
if (!fs.existsSync(newPath)) {
newPath = path.resolve(contracts, ogPath, '../' + filePath)
}
if (!fs.existsSync(newPath)) {
newPath = pnp.resolveToUnqualified(filePath, './')
}
return {
contents: fs.readFileSync(newPath, 'utf8'),
}
}

async function compile(name, inputPath) {
const input = JSON.stringify({
language: 'Solidity',
sources: {
[name]: {
content: fs.readFileSync(
path.resolve(contracts, inputPath + name + '.sol'),
'utf8',
),
},
},
settings: {
outputSelection: {
'*': {
'*': ['*'],
},
},
optimizer: {
enabled: true,
runs: 200,
},
},
})
const compiled = solc.compile(input, { import: findImports(inputPath) })
const parsed = JSON.parse(compiled)
return parsed.contracts[name][name]
}

const deployContract = async (InputContract, args) => {
const deployment = await InputContract.deploy(...args, {
gasLimit: 30000000,
})
await deployment.deployTransaction.wait()
return deployment.address
}

export default async (server) => {
let metadataAddress,
wrapperAddress,
resolverAddress,
metadataHost,
wrapperArguments,
resolverArguments,
metadataArguments
;({
METADATA_ADDRESS: metadataAddress,
WRAPPER_ADDRESS: wrapperAddress,
RESOLVER_ADDRESS: resolverAddress,
METADATA_HOST: metadataHost,
} = process.env)

const registryAddress = '0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e'
const registrarAddress = '0x57f1887a8BF19b14fC0dF6Fd9B2acc9Af147eA85'
const controllerAddress = '0x283Af0B28c62C092C9727F1Ee09c02CA627EB7F5'
const reverseRegisrarAddress = '0x084b1c3C81545d370f3634392De611CaaBFf8148'
const metadataUrl = `${metadataHost}/name/0x{id}`

const address = server.provider.getInitialAccounts()
const provider = new ethers.providers.Web3Provider(server.provider)
const deployer = provider.getSigner(Object.keys(address)[0])

console.log('Deploying wrapper with account:', deployer._address)

const CompiledNameWrapper = await compile('NameWrapper', 'wrapper/')
const CompiledStaticMetadataService = await compile(
'StaticMetadataService',
'wrapper/',
)
const CompiledPublicResolver = await compile('PublicResolver', 'resolvers/')

const NameWrapper = ethers.ContractFactory.fromSolidity(
CompiledNameWrapper,
deployer,
)
const StaticMetadataService = ethers.ContractFactory.fromSolidity(
CompiledStaticMetadataService,
deployer,
)
const PublicResolver = ethers.ContractFactory.fromSolidity(
CompiledPublicResolver,
deployer,
)

console.log('Setting metadata service URL to:', metadataUrl)
console.log('Deploying StaticMetadataService...')
metadataAddress = await deployContract(StaticMetadataService, [metadataUrl])
console.log('StaticMetadataService Address:', metadataAddress)

console.log('Deploying NameWrapper...')
wrapperAddress = await deployContract(NameWrapper, [
registryAddress,
registrarAddress,
metadataAddress,
])
console.log('NameWrapper Address:', wrapperAddress)

console.log('Deploying Resolver...')
resolverAddress = await deployContract(PublicResolver, [
registryAddress,
wrapperAddress,
controllerAddress,
reverseRegisrarAddress,
])
console.log('Resolver Address:', resolverAddress)
return
}
83 changes: 83 additions & 0 deletions packages/ensjs/deployments/UniversalResolver.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import { ethers } from 'ethers'
import fs from 'fs'
import nModule from 'module'
import path from 'path'
import solc from 'solc'

const pnp = nModule.findPnpApi('./')
const contracts = pnp.resolveToUnqualified(
'ens-contracts-universal/contracts',
'./',
)

const findImports = (ogPath) => (filePath) => {
let newPath = path.resolve(contracts, ogPath, './' + filePath)
if (!fs.existsSync(newPath)) {
newPath = path.resolve(contracts, ogPath, '../' + filePath)
}
if (!fs.existsSync(newPath)) {
newPath = pnp.resolveToUnqualified(filePath, './')
}
return {
contents: fs.readFileSync(newPath, 'utf8'),
}
}

async function compile(name, inputPath) {
const input = JSON.stringify({
language: 'Solidity',
sources: {
[name]: {
content: fs.readFileSync(
path.resolve(contracts, inputPath + name + '.sol'),
'utf8',
),
},
},
settings: {
outputSelection: {
'*': {
'*': ['*'],
},
},
optimizer: {
enabled: true,
runs: 200,
},
},
})
const compiled = solc.compile(input, { import: findImports(inputPath) })
const parsed = JSON.parse(compiled)
return parsed.contracts[name][name]
}

const deployContract = async (InputContract, args) => {
const deployment = await InputContract.deploy(...args, {
gasLimit: 30000000,
})
await deployment.deployTransaction.wait()
return deployment.address
}

export default async (server) => {
const registryAddress = '0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e'

const address = server.provider.getInitialAccounts()
const provider = new ethers.providers.Web3Provider(server.provider)
const deployer = provider.getSigner(Object.keys(address)[0])

console.log('Deploying UniversalResolver with account:', deployer._address)

const CompiledUniversalResolver = await compile('UniversalResolver', 'utils/')

const UniversalResolver = ethers.ContractFactory.fromSolidity(
CompiledUniversalResolver,
deployer,
)

const universalResolverAddress = await deployContract(UniversalResolver, [
registryAddress,
])
console.log('Universal Resolver Address:', universalResolverAddress)
return
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require('dotenv').config({ path: process.env.PROJECT_CWD + '/.env' })
require('dotenv').config({ path: process.env.INIT_CWD + '/.env' })

module.exports = {
ganache: {
Expand Down
12 changes: 11 additions & 1 deletion packages/ensjs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,17 @@
},
"packageManager": "[email protected]",
"dependencies": {
"@ensdomains/ens-contracts": "^0.0.11"
"@ensdomains/ens-contracts": "^0.0.11",
"ethers": "^5.6.1"
},
"devDependencies": {
"@ensdomains/buffer": "^0.0.13",
"@ensdomains/ens-test-env": "workspace:*",
"@openzeppelin/contracts": "^4.5.0",
"dotenv": "^16.0.0",
"ens-contracts-namewrapper": "github:ensdomains/ens-contracts#commit=9b42c4b57e76aa4041847579c0bd5c3ca3cf6375",
"ens-contracts-universal": "github:ensdomains/ens-contracts#universal",
"solc": "^0.8.13"
},
"peerDependencies": {
"ethers": "*"
Expand Down
Loading

0 comments on commit 01cc26a

Please sign in to comment.