Skip to content

Commit 9957aa7

Browse files
davekay100abarmat
andauthored
Add a script call in ens to register name and text in one call (#228)
* 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]>
1 parent 367ebea commit 9957aa7

File tree

8 files changed

+85
-67
lines changed

8 files changed

+85
-67
lines changed

package-lock.json

Lines changed: 4 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
"@nomiclabs/buidler-ethers": "^2.0.0-alpha.1",
1515
"@nomiclabs/buidler-waffle": "^2.0.0-alpha.1",
1616
"@openzeppelin/contracts": "3.0.1",
17-
"@typechain/web3-v1": "^1.0.0",
1817
"@types/bs58": "^4.0.1",
1918
"@types/dotenv": "^8.2.0",
2019
"@types/minimist": "^1.2.0",
@@ -50,15 +49,15 @@
5049
"ts-generator": "0.0.8",
5150
"ts-node": "^8.10.1",
5251
"typechain": "^2.0.0",
53-
"typechain-target-ethers-v5": "^1.2.0",
52+
"typechain-target-abarmat-ethers-v5": "^1.0.0",
5453
"typescript": "^3.9.3",
5554
"yaml": "^1.10.0",
5655
"yargs": "^15.3.1"
5756
},
5857
"scripts": {
5958
"prepublishOnly": "npm run build && rm -rf dist && cp -R build dist",
6059
"build": "npm run compile && npm run flatten && npm run abi:extract && npm run typechain",
61-
"clean": "rm -rf build/ cache/",
60+
"clean": "rm -rf build/ cache/ dist/",
6261
"compile": "buidler compile",
6362
"deploy": "npm run migrate",
6463
"deploy-kovan": "npm run migrate -- --force --network kovan",
@@ -77,7 +76,7 @@
7776
"prettier:sol": "prettier --write 'contracts/*.sol'",
7877
"flatten": "scripts/flatten.sh",
7978
"abi:extract": "truffle-abi -d ./build/contracts -o ./build/abis/ -v",
80-
"typechain": "typechain --target ethers-v5 --outDir build/typechain/contracts 'build/abis/*.json'"
79+
"typechain": "typechain --target abarmat-ethers-v5 --outDir build/typechain/contracts 'build/abis/*.json'"
8180
},
8281
"lint-staged": {
8382
"contracts/*.sol": [

scripts/data/metadata.json

Lines changed: 0 additions & 7 deletions
This file was deleted.

scripts/ens.ts

Lines changed: 35 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@ import { contracts, executeTransaction, overrides, checkFuncInputs } from './hel
1010
// Set up the script //
1111
///////////////////////
1212

13-
const { func, name, node } = minimist.default(process.argv.slice(2), {
14-
string: ['func', 'name', 'node'],
13+
const { func, name } = minimist.default(process.argv.slice(2), {
14+
string: ['func', 'name'],
1515
})
1616

17-
if (!func) {
17+
if (!func || !name) {
1818
console.error(
1919
`
2020
Usage: ${path.basename(process.argv[1])}
21-
--func <string> - options: setRecord, setText, checkOwner
21+
--func <string> - options: registerName, setRecord, setText, checkOwner, nameHash
2222
2323
Function arguments:
2424
setRecord
@@ -58,28 +58,42 @@ Function arguments:
5858
// )
5959
// }
6060

61-
const setTestRecord = async (labelName: string) => {
62-
checkFuncInputs([labelName], ['labelName'], 'setTestRecord')
63-
const node = utils.namehash('test')
64-
const labelNameFull = `${labelName}.${'test'}`
65-
const label = utils.keccak256(utils.toUtf8Bytes(labelName))
66-
console.log(label)
61+
// Must normalize name to lower case to get script to work with ethers namehash
62+
// This is because in setTestRecord() - label uses the normal keccak
63+
// TODO - follow UTS46 in scripts https://docs.ens.domains/contract-api-reference/name-processing
64+
const normalizedName = name.toLowerCase()
65+
66+
const setTestRecord = async () => {
67+
// const node = utils.namehash('test')
68+
// console.log('Namehash node for "test": ', node)
69+
const labelNameFull = `${normalizedName}.${'test'}`
6770
const labelHashFull = utils.namehash(labelNameFull)
68-
const signerAddress = await contracts.ens.signer.getAddress()
69-
const ensOverrides = overrides('ens', 'register')
70-
console.log('Namehash node for "test": ', node)
71-
console.log(`Hash of label ${labelName}: `, label)
7271
console.log(`Namehash for ${labelNameFull}: ${labelHashFull}`)
7372

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

7780
const setText = async () => {
78-
checkFuncInputs([node], ['node'], 'setText')
81+
const labelNameFull = `${normalizedName}.${'test'}`
82+
const labelHashFull = utils.namehash(labelNameFull)
83+
console.log(`Setting text name: ${labelNameFull} with node: ${labelHashFull}`)
84+
7985
const key = 'GRAPH NAME SERVICE'
8086
const ensOverrides = overrides('ens', 'setText')
8187
const signerAddress = await contracts.publicResolver.signer.getAddress()
82-
await executeTransaction(contracts.publicResolver.setText(node, key, signerAddress, ensOverrides))
88+
await executeTransaction(
89+
contracts.publicResolver.setText(labelHashFull, key, signerAddress, ensOverrides),
90+
)
91+
}
92+
93+
// does everything in one func call
94+
const registerName = async () => {
95+
await setTestRecord()
96+
await setText()
8397
}
8498

8599
const checkOwner = async () => {
@@ -100,15 +114,15 @@ const checkOwner = async () => {
100114

101115
const main = async () => {
102116
try {
103-
if (func == 'setTestRecord') {
117+
if (func == 'registerName') {
118+
console.log(`Registering ownership and text record for ${name} ...`)
119+
registerName()
120+
} else if (func == 'setTestRecord') {
104121
console.log(`Setting owner for ${name} ...`)
105-
setTestRecord(name)
122+
setTestRecord()
106123
} else if (func == 'setText') {
107124
console.log(`Setting text record of 'GRAPH NAME SERVICE' for caller ...`)
108125
setText()
109-
// } else if (func == 'setEthDomain') { NOT IN USE
110-
// console.log(`Setting '.eth' domain ...`)
111-
// setSubnodeRecord('', 'eth')
112126
} else if (func == 'checkOwner') {
113127
console.log(`Checking owner of ${name} ...`)
114128
checkOwner()

scripts/ethereumDIDRegistry.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import * as path from 'path'
44
import * as minimist from 'minimist'
55
import * as fs from 'fs'
66

7-
import { contracts, executeTransaction, overrides, IPFS, checkFuncInputs } from './helpers'
7+
import { contracts, executeTransaction, overrides, IPFS } from './helpers'
88

99
///////////////////////
1010
// Set up the script //

scripts/gns.ts

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -140,13 +140,24 @@ interface GNSMetadata {
140140

141141
const handleMetadata = async (ipfs: string, path: string): Promise<string> => {
142142
const metadata: GNSMetadata = JSON.parse(fs.readFileSync(__dirname + path).toString())
143+
if (
144+
!metadata.subgraphDescription ||
145+
!metadata.subgraphImage ||
146+
!metadata.subgraphCodeRepository ||
147+
!metadata.subgraphWebsite ||
148+
!metadata.versionDescription ||
149+
!metadata.versionLabel
150+
) {
151+
console.log(`One or more fields for metadata are missing`)
152+
process.exit(1)
153+
}
143154
console.log('Meta data:')
144-
console.log(' Subgraph Description: ', metadata.subgraphDescription || '')
145-
console.log(' Subgraph Image: ', metadata.subgraphImage || '')
146-
console.log(' Subgraph Code Repository: ', metadata.subgraphCodeRepository || '')
147-
console.log(' Subgraph Website: ', metadata.subgraphWebsite || '')
148-
console.log(' Version Description: ', metadata.versionDescription || '')
149-
console.log(' Version Label: ', metadata.versionLabel || '')
155+
console.log(' Subgraph Description: ', metadata.subgraphDescription)
156+
console.log(' Subgraph Image: ', metadata.subgraphImage)
157+
console.log(' Subgraph Code Repository: ', metadata.subgraphCodeRepository)
158+
console.log(' Subgraph Website: ', metadata.subgraphWebsite)
159+
console.log(' Version Description: ', metadata.versionDescription)
160+
console.log(' Version Label: ', metadata.versionLabel)
150161

151162
const ipfsClient = IPFS.createIpfsClient(ipfs)
152163

scripts/helpers.ts

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,19 @@ import * as fs from 'fs'
22
import * as path from 'path'
33
import * as dotenv from 'dotenv'
44

5-
import { ContractTransaction, ethers, utils, Wallet } from 'ethers'
6-
import { ContractReceipt } from 'ethers/contract'
5+
import { ContractTransaction, ethers, utils, Wallet, ContractReceipt, Overrides } from 'ethers'
76
import ipfsHttpClient from 'ipfs-http-client'
87
import * as bs58 from 'bs58'
98

10-
import { GnsFactory } from '../build/typechain/contracts/GnsFactory'
11-
import { StakingFactory } from '../build/typechain/contracts/StakingFactory'
12-
import { ServiceRegistryFactory } from '../build/typechain/contracts/ServiceRegistryFactory'
13-
import { GraphTokenFactory } from '../build/typechain/contracts/GraphTokenFactory'
14-
import { CurationFactory } from '../build/typechain/contracts/CurationFactory'
15-
import { IensFactory } from '../build/typechain/contracts/IensFactory'
16-
import { IPublicResolverFactory } from '../build/typechain/contracts/IPublicResolverFactory'
17-
import { IEthereumDidRegistryFactory } from '../build/typechain/contracts/IEthereumDidRegistryFactory'
18-
import { ITestRegistrarFactory } from '../build/typechain/contracts/ITestRegistrarFactory'
19-
import { TransactionOverrides } from '../build/typechain/contracts'
9+
import { GnsFactory } from '../build/typechain/contracts/GnsContract'
10+
import { StakingFactory } from '../build/typechain/contracts/StakingContract'
11+
import { ServiceRegistryFactory } from '../build/typechain/contracts/ServiceRegistryContract'
12+
import { GraphTokenFactory } from '../build/typechain/contracts/GraphTokenContract'
13+
import { CurationFactory } from '../build/typechain/contracts/CurationContract'
14+
import { IensFactory } from '../build/typechain/contracts/IensContract'
15+
import { IPublicResolverFactory } from '../build/typechain/contracts/IPublicResolverContract'
16+
import { IEthereumDidRegistryFactory } from '../build/typechain/contracts/IEthereumDidRegistryContract'
17+
import { ITestRegistrarFactory } from '../build/typechain/contracts/ITestRegistrarContract'
2018

2119
dotenv.config()
2220
const addresses = JSON.parse(fs.readFileSync(path.join(__dirname, '..', 'addresses.json'), 'utf-8'))
@@ -61,12 +59,7 @@ export const executeTransaction = async (
6159
}
6260
}
6361

64-
type Overrides = {
65-
address?: string
66-
topics?: Array<string>
67-
}
68-
69-
export const overrides = (contract: string, func: string): TransactionOverrides => {
62+
export const overrides = (contract: string, func: string): Overrides => {
7063
const gasPrice = utils.parseUnits('25', 'gwei')
7164
const gasLimit = 1000000
7265
// console.log(`\ntx gas price: '${gasPrice}'`);

truffle.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Needed for truffle flattener
2+
module.exports = {
3+
compilers: {
4+
solc: {
5+
version: '0.6.4',
6+
settings: {
7+
optimizer: {
8+
enabled: true,
9+
runs: 500,
10+
},
11+
},
12+
},
13+
},
14+
}

0 commit comments

Comments
 (0)