Skip to content

Commit

Permalink
Add a script call in ens to register name and text in one call (#228)
Browse files Browse the repository at this point in the history
* Add a script call in ens to register name and text in one call

* build: use a version of typechain for ethers-v5 that fixes import issue

Co-authored-by: Ariel Barmat <[email protected]>
  • Loading branch information
davekaj and abarmat authored Jun 22, 2020
1 parent 367ebea commit 9957aa7
Show file tree
Hide file tree
Showing 8 changed files with 85 additions and 67 deletions.
14 changes: 4 additions & 10 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 3 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
"@nomiclabs/buidler-ethers": "^2.0.0-alpha.1",
"@nomiclabs/buidler-waffle": "^2.0.0-alpha.1",
"@openzeppelin/contracts": "3.0.1",
"@typechain/web3-v1": "^1.0.0",
"@types/bs58": "^4.0.1",
"@types/dotenv": "^8.2.0",
"@types/minimist": "^1.2.0",
Expand Down Expand Up @@ -50,15 +49,15 @@
"ts-generator": "0.0.8",
"ts-node": "^8.10.1",
"typechain": "^2.0.0",
"typechain-target-ethers-v5": "^1.2.0",
"typechain-target-abarmat-ethers-v5": "^1.0.0",
"typescript": "^3.9.3",
"yaml": "^1.10.0",
"yargs": "^15.3.1"
},
"scripts": {
"prepublishOnly": "npm run build && rm -rf dist && cp -R build dist",
"build": "npm run compile && npm run flatten && npm run abi:extract && npm run typechain",
"clean": "rm -rf build/ cache/",
"clean": "rm -rf build/ cache/ dist/",
"compile": "buidler compile",
"deploy": "npm run migrate",
"deploy-kovan": "npm run migrate -- --force --network kovan",
Expand All @@ -77,7 +76,7 @@
"prettier:sol": "prettier --write 'contracts/*.sol'",
"flatten": "scripts/flatten.sh",
"abi:extract": "truffle-abi -d ./build/contracts -o ./build/abis/ -v",
"typechain": "typechain --target ethers-v5 --outDir build/typechain/contracts 'build/abis/*.json'"
"typechain": "typechain --target abarmat-ethers-v5 --outDir build/typechain/contracts 'build/abis/*.json'"
},
"lint-staged": {
"contracts/*.sol": [
Expand Down
7 changes: 0 additions & 7 deletions scripts/data/metadata.json

This file was deleted.

56 changes: 35 additions & 21 deletions scripts/ens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ import { contracts, executeTransaction, overrides, checkFuncInputs } from './hel
// Set up the script //
///////////////////////

const { func, name, node } = minimist.default(process.argv.slice(2), {
string: ['func', 'name', 'node'],
const { func, name } = minimist.default(process.argv.slice(2), {
string: ['func', 'name'],
})

if (!func) {
if (!func || !name) {
console.error(
`
Usage: ${path.basename(process.argv[1])}
--func <string> - options: setRecord, setText, checkOwner
--func <string> - options: registerName, setRecord, setText, checkOwner, nameHash
Function arguments:
setRecord
Expand Down Expand Up @@ -58,28 +58,42 @@ Function arguments:
// )
// }

const setTestRecord = async (labelName: string) => {
checkFuncInputs([labelName], ['labelName'], 'setTestRecord')
const node = utils.namehash('test')
const labelNameFull = `${labelName}.${'test'}`
const label = utils.keccak256(utils.toUtf8Bytes(labelName))
console.log(label)
// Must normalize name to lower case to get script to work with ethers namehash
// This is because in setTestRecord() - label uses the normal keccak
// TODO - follow UTS46 in scripts https://docs.ens.domains/contract-api-reference/name-processing
const normalizedName = name.toLowerCase()

const setTestRecord = async () => {
// const node = utils.namehash('test')
// console.log('Namehash node for "test": ', node)
const labelNameFull = `${normalizedName}.${'test'}`
const labelHashFull = utils.namehash(labelNameFull)
const signerAddress = await contracts.ens.signer.getAddress()
const ensOverrides = overrides('ens', 'register')
console.log('Namehash node for "test": ', node)
console.log(`Hash of label ${labelName}: `, label)
console.log(`Namehash for ${labelNameFull}: ${labelHashFull}`)

const signerAddress = await contracts.ens.signer.getAddress()
const ensOverrides = overrides('ens', 'register')
const label = utils.keccak256(utils.toUtf8Bytes(normalizedName))
// console.log(`Hash of label being registered on ens ${name}: `, label)
await executeTransaction(contracts.testRegistrar.register(label, signerAddress, ensOverrides))
}

const setText = async () => {
checkFuncInputs([node], ['node'], 'setText')
const labelNameFull = `${normalizedName}.${'test'}`
const labelHashFull = utils.namehash(labelNameFull)
console.log(`Setting text name: ${labelNameFull} with node: ${labelHashFull}`)

const key = 'GRAPH NAME SERVICE'
const ensOverrides = overrides('ens', 'setText')
const signerAddress = await contracts.publicResolver.signer.getAddress()
await executeTransaction(contracts.publicResolver.setText(node, key, signerAddress, ensOverrides))
await executeTransaction(
contracts.publicResolver.setText(labelHashFull, key, signerAddress, ensOverrides),
)
}

// does everything in one func call
const registerName = async () => {
await setTestRecord()
await setText()
}

const checkOwner = async () => {
Expand All @@ -100,15 +114,15 @@ const checkOwner = async () => {

const main = async () => {
try {
if (func == 'setTestRecord') {
if (func == 'registerName') {
console.log(`Registering ownership and text record for ${name} ...`)
registerName()
} else if (func == 'setTestRecord') {
console.log(`Setting owner for ${name} ...`)
setTestRecord(name)
setTestRecord()
} else if (func == 'setText') {
console.log(`Setting text record of 'GRAPH NAME SERVICE' for caller ...`)
setText()
// } else if (func == 'setEthDomain') { NOT IN USE
// console.log(`Setting '.eth' domain ...`)
// setSubnodeRecord('', 'eth')
} else if (func == 'checkOwner') {
console.log(`Checking owner of ${name} ...`)
checkOwner()
Expand Down
2 changes: 1 addition & 1 deletion scripts/ethereumDIDRegistry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import * as path from 'path'
import * as minimist from 'minimist'
import * as fs from 'fs'

import { contracts, executeTransaction, overrides, IPFS, checkFuncInputs } from './helpers'
import { contracts, executeTransaction, overrides, IPFS } from './helpers'

///////////////////////
// Set up the script //
Expand Down
23 changes: 17 additions & 6 deletions scripts/gns.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,13 +140,24 @@ interface GNSMetadata {

const handleMetadata = async (ipfs: string, path: string): Promise<string> => {
const metadata: GNSMetadata = JSON.parse(fs.readFileSync(__dirname + path).toString())
if (
!metadata.subgraphDescription ||
!metadata.subgraphImage ||
!metadata.subgraphCodeRepository ||
!metadata.subgraphWebsite ||
!metadata.versionDescription ||
!metadata.versionLabel
) {
console.log(`One or more fields for metadata are missing`)
process.exit(1)
}
console.log('Meta data:')
console.log(' Subgraph Description: ', metadata.subgraphDescription || '')
console.log(' Subgraph Image: ', metadata.subgraphImage || '')
console.log(' Subgraph Code Repository: ', metadata.subgraphCodeRepository || '')
console.log(' Subgraph Website: ', metadata.subgraphWebsite || '')
console.log(' Version Description: ', metadata.versionDescription || '')
console.log(' Version Label: ', metadata.versionLabel || '')
console.log(' Subgraph Description: ', metadata.subgraphDescription)
console.log(' Subgraph Image: ', metadata.subgraphImage)
console.log(' Subgraph Code Repository: ', metadata.subgraphCodeRepository)
console.log(' Subgraph Website: ', metadata.subgraphWebsite)
console.log(' Version Description: ', metadata.versionDescription)
console.log(' Version Label: ', metadata.versionLabel)

const ipfsClient = IPFS.createIpfsClient(ipfs)

Expand Down
29 changes: 11 additions & 18 deletions scripts/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,19 @@ import * as fs from 'fs'
import * as path from 'path'
import * as dotenv from 'dotenv'

import { ContractTransaction, ethers, utils, Wallet } from 'ethers'
import { ContractReceipt } from 'ethers/contract'
import { ContractTransaction, ethers, utils, Wallet, ContractReceipt, Overrides } from 'ethers'
import ipfsHttpClient from 'ipfs-http-client'
import * as bs58 from 'bs58'

import { GnsFactory } from '../build/typechain/contracts/GnsFactory'
import { StakingFactory } from '../build/typechain/contracts/StakingFactory'
import { ServiceRegistryFactory } from '../build/typechain/contracts/ServiceRegistryFactory'
import { GraphTokenFactory } from '../build/typechain/contracts/GraphTokenFactory'
import { CurationFactory } from '../build/typechain/contracts/CurationFactory'
import { IensFactory } from '../build/typechain/contracts/IensFactory'
import { IPublicResolverFactory } from '../build/typechain/contracts/IPublicResolverFactory'
import { IEthereumDidRegistryFactory } from '../build/typechain/contracts/IEthereumDidRegistryFactory'
import { ITestRegistrarFactory } from '../build/typechain/contracts/ITestRegistrarFactory'
import { TransactionOverrides } from '../build/typechain/contracts'
import { GnsFactory } from '../build/typechain/contracts/GnsContract'
import { StakingFactory } from '../build/typechain/contracts/StakingContract'
import { ServiceRegistryFactory } from '../build/typechain/contracts/ServiceRegistryContract'
import { GraphTokenFactory } from '../build/typechain/contracts/GraphTokenContract'
import { CurationFactory } from '../build/typechain/contracts/CurationContract'
import { IensFactory } from '../build/typechain/contracts/IensContract'
import { IPublicResolverFactory } from '../build/typechain/contracts/IPublicResolverContract'
import { IEthereumDidRegistryFactory } from '../build/typechain/contracts/IEthereumDidRegistryContract'
import { ITestRegistrarFactory } from '../build/typechain/contracts/ITestRegistrarContract'

dotenv.config()
const addresses = JSON.parse(fs.readFileSync(path.join(__dirname, '..', 'addresses.json'), 'utf-8'))
Expand Down Expand Up @@ -61,12 +59,7 @@ export const executeTransaction = async (
}
}

type Overrides = {
address?: string
topics?: Array<string>
}

export const overrides = (contract: string, func: string): TransactionOverrides => {
export const overrides = (contract: string, func: string): Overrides => {
const gasPrice = utils.parseUnits('25', 'gwei')
const gasLimit = 1000000
// console.log(`\ntx gas price: '${gasPrice}'`);
Expand Down
14 changes: 14 additions & 0 deletions truffle.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Needed for truffle flattener
module.exports = {
compilers: {
solc: {
version: '0.6.4',
settings: {
optimizer: {
enabled: true,
runs: 500,
},
},
},
},
}

0 comments on commit 9957aa7

Please sign in to comment.