Skip to content

Commit 9a17b40

Browse files
committed
Scripts for GNS working for phase1
1 parent 5fc7374 commit 9a17b40

File tree

4 files changed

+140
-57
lines changed

4 files changed

+140
-57
lines changed

scripts/contracts/connectedContracts.ts

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { StakingFactory } from '../../build/typechain/contracts/StakingContract'
99
import { GraphTokenFactory } from '../../build/typechain/contracts/GraphTokenContract'
1010
import { IEthereumDidRegistryFactory } from '../../build/typechain/contracts/IEthereumDidRegistryContract'
1111

12-
import { getNetworkAddresses, IPFS } from './helpers'
12+
import { getNetworkAddresses, IPFS, basicOverrides } from './helpers'
1313
import { connectContracts } from './connectedNetwork'
1414
import {
1515
SubgraphMetadata,
@@ -88,36 +88,41 @@ class ConnectedENS extends ConnectedContract {
8888
setTestRecord = async (name: string): Promise<ContractTransaction> => {
8989
const contracts = await connectContracts(this.configuredWallet, this.network)
9090
const normalizedName = name.toLowerCase()
91-
const labelNameFull = `${normalizedName}.${'test'}`
91+
const labelNameFull = `${normalizedName}.${'eth'}`
9292
const labelHashFull = utils.namehash(labelNameFull)
9393
console.log(`Namehash for ${labelNameFull}: ${labelHashFull}`)
9494
const signerAddress = await contracts.testRegistrar.signer.getAddress()
9595
const label = utils.keccak256(utils.toUtf8Bytes(normalizedName))
9696
return contracts.testRegistrar.register(label, signerAddress)
9797
}
9898

99-
setText = async (name: string): Promise<ContractTransaction> => {
100-
const contracts = await connectContracts(this.configuredWallet, this.network)
101-
const normalizedName = name.toLowerCase()
102-
const labelNameFull = `${normalizedName}.${'test'}`
103-
const labelHashFull = utils.namehash(labelNameFull)
104-
console.log(`Setting text name: ${labelNameFull} with node: ${labelHashFull}`)
105-
const key = 'GRAPH NAME SERVICE'
106-
const signerAddress = await contracts.publicResolver.signer.getAddress()
107-
return contracts.publicResolver.setText(labelHashFull, key, signerAddress)
108-
}
99+
// TODO - remove, not in use anymore
100+
// setText = async (name: string): Promise<ContractTransaction> => {
101+
// const contracts = await connectContracts(this.configuredWallet, this.network)
102+
// const normalizedName = name.toLowerCase()
103+
// const labelNameFull = `${normalizedName}.${'eth'}`
104+
// const labelHashFull = utils.namehash(labelNameFull)
105+
// console.log(`Setting text name: ${labelNameFull} with node: ${labelHashFull}`)
106+
// const key = 'GRAPH NAME SERVICE'
107+
// const signerAddress = await contracts.publicResolver.signer.getAddress()
108+
// return contracts.publicResolver.setText(labelHashFull, key, signerAddress)
109+
// }
109110

110111
checkOwner = async (name: string): Promise<void> => {
111112
const contracts = await connectContracts(this.configuredWallet, this.network)
112113
try {
113-
const node = utils.namehash(`${name}.test`)
114+
const node = utils.namehash(`${name}.eth`)
114115
console.log(`Node: ${node}`)
115116
const res = await contracts.ens.owner(node)
116-
console.log(`Owner of ${name}.test is: ${res}`)
117+
console.log(`Owner of ${name}.eth is: ${res}`)
117118
} catch (e) {
118119
console.log(` ..failed on checkOwner: ${e.message}`)
119120
}
120121
}
122+
123+
getNode = (name: string): string => {
124+
return utils.namehash(`${name}.eth`)
125+
}
121126
}
122127

123128
class ConnectedGraphToken extends ConnectedContract {
@@ -208,7 +213,7 @@ class ConnectedGNS extends ConnectedContract {
208213
ipfs: string,
209214
graphAccount: string,
210215
subgraphDeploymentID: string,
211-
versionMetadata: string | SubgraphMetadata,
216+
versionMetadata: string | VersionMetadata,
212217
subgraphMetadata: string | SubgraphMetadata,
213218
): Promise<ContractTransaction> => {
214219
const subgraphDataHash = await this.handleSubgraphMetadata(ipfs, subgraphMetadata)
@@ -226,7 +231,7 @@ class ConnectedGNS extends ConnectedContract {
226231
ipfs: string,
227232
graphAccount: string,
228233
subgraphDeploymentID: string,
229-
versionMetadata: string | SubgraphMetadata,
234+
versionMetadata: string | VersionMetadata,
230235
subgraphNumber: string,
231236
): Promise<ContractTransaction> => {
232237
const metaHashBytes = await this.handleVersionMetadata(ipfs, versionMetadata)
@@ -236,6 +241,7 @@ class ConnectedGNS extends ConnectedContract {
236241
subgraphNumber,
237242
subgraphDeploymentIDBytes,
238243
metaHashBytes,
244+
basicOverrides(),
239245
)
240246
}
241247

scripts/contracts/ens.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ const main = async () => {
4747
if (func == 'registerName') {
4848
console.log(`Setting owner for ${name} and the text record...`)
4949
await executeTransaction(ens.setTestRecord(name), network)
50-
await executeTransaction(ens.setText(name), network)
50+
// await executeTransaction(ens.setText(name), network)
5151
} else if (func == 'checkOwner') {
5252
console.log(`Checking owner of ${name} ...`)
5353
await ens.checkOwner(name)

scripts/contracts/ethereumDIDRegistry.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,10 @@ const main = async () => {
5353
try {
5454
if (func == 'setAttribute') {
5555
console.log(`Setting attribute on ethereum DID registry ...`)
56-
await executeTransaction(ethereumDIDRegistry.pinIPFSAndSetAttribute(ipfs, metadataPath), network)
56+
await executeTransaction(
57+
ethereumDIDRegistry.pinIPFSAndSetAttribute(ipfs, metadataPath),
58+
network,
59+
)
5760
} else {
5861
console.log(`Wrong func name provided`)
5962
process.exit(1)

scripts/contracts/gns.ts

Lines changed: 113 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -9,30 +9,37 @@ import {
99
configureGanacheWallet,
1010
configureWallet,
1111
buildNetworkEndpoint,
12+
basicOverrides,
1213
} from './helpers'
13-
import { ConnectedGNS } from './connectedContracts'
14+
import { ConnectedGNS, ConnectedENS, ConnectedGraphToken } from './connectedContracts'
15+
import { connectContracts } from './connectedNetwork'
16+
import { Wallet, utils } from 'ethers'
1417

1518
const {
1619
network,
1720
func,
1821
ipfs,
1922
graphAccount,
2023
subgraphDeploymentID,
21-
nameIdentifier,
2224
name,
23-
metadataPath,
25+
versionPath,
26+
subgraphPath,
2427
subgraphNumber,
28+
tokens,
29+
nSignal,
2530
} = minimist.default(process.argv.slice(2), {
2631
string: [
2732
'network',
2833
'func',
2934
'ipfs',
3035
'graphAccount',
3136
'subgraphDeploymentID',
32-
'nameIdentifier',
3337
'name',
34-
'metadataPath',
38+
'versionPath',
39+
'subgraphPath',
3540
'subgraphNumber',
41+
'tokens',
42+
'nSignal',
3643
],
3744
})
3845

@@ -41,35 +48,61 @@ if (!network || !func || !graphAccount) {
4148
`
4249
Usage: ${path.basename(process.argv[1])}
4350
--network <string> - options: ganache, kovan, rinkeby
44-
--func <text> - options: publishNewSubgraph, publishVersion, deprecate
51+
--func <text> - options: setDefaultName, publishNewSubgraph, publishVersion, deprecate,
52+
updateSubgraphMetadata, mintNSignal, burnNSignal, withdrawGRT
4553
4654
Function arguments:
55+
setDefaultName
56+
--graphAccount <address> - graph account address
57+
--nameSystem <number> - 0 = ENS
58+
--name <string> - name that has been registered and is getting set as default
59+
4760
publishNewSubgraph
4861
--ipfs <url> - ex. https://api.thegraph.com/ipfs/
49-
--graphAccount <address> - erc1056 identity, often just the transacting account
62+
--graphAccount <address> - graph account address
5063
--subgraphDeploymentID <base58> - subgraphID in base58
51-
--nameIdentifier <string> - ex. the node value in ENS
52-
--name <string> - name of the subgraph
53-
--metadataPath <path> - filepath to metadata. JSON format:
64+
--versionPath <path> - filepath to metadata. JSON format:
65+
{
66+
"description": "",
67+
"label": ""
68+
}
69+
--subgraphPath <path> - filepath to metadata. JSON format:
5470
{
5571
"description": "",
72+
"displayName": "",
5673
"image": "",
5774
"codeRepository": "",
5875
"website": "",
59-
"description": "",
60-
"label": ""
6176
}
77+
6278
publishVersion
6379
--ipfs <url> - ex. https://api.thegraph.com/ipfs/
64-
--graphAccount <address> - erc1056 identity, often just the transacting account
80+
--graphAccount <address> - graph account address
6581
--subgraphDeploymentID <base58> - subgraphID in base58
66-
--nameIdentifier <string> - ex. the node value in ENS
67-
--name <string> - name of the subgraph
68-
--metadataPath <path> - filepath to metadata. Same format as above
82+
--subgraphPath <path> - filepath to version metadata. Same format as above
6983
--subgraphNumber <number> - numbered subgraph for the graph account
7084
7185
deprecate
72-
--graphAccount <address> - erc1056 identity, often just the transacting account
86+
--graphAccount <address> - graph account address
87+
--subgraphNumber <number> - numbered subgraph for the graph account
88+
89+
updateSubgraphMetadata
90+
--graphAccount <address> - graph account address
91+
--subgraphNumber <number> - numbered subgraph for the graph account
92+
--subgraphPath <path> - filepath to subgraph metadata. Same format as above
93+
94+
mintNSignal
95+
--graphAccount <address> - graph account address
96+
--subgraphNumber <number> - numbered subgraph for the graph account
97+
--tokens <number> - tokens being deposited. Script adds 10^18
98+
99+
burnNSignal
100+
--graphAccount <address> - graph account address
101+
--subgraphNumber <number> - numbered subgraph for the graph account
102+
--nSignal <number> - tokens being burnt. Script adds 10^18
103+
104+
withdrawGRT
105+
--graphAccount <address> - graph account address
73106
--subgraphNumber <number> - numbered subgraph for the graph account
74107
`,
75108
)
@@ -78,64 +111,105 @@ Usage: ${path.basename(process.argv[1])}
78111

79112
const main = async () => {
80113
let gns: ConnectedGNS
114+
let connectedGT: ConnectedGraphToken
81115
let provider
116+
let mnemonicWallet: Wallet
117+
const networkContracts = await connectContracts(mnemonicWallet, network)
118+
82119
if (network == 'ganache') {
83120
provider = buildNetworkEndpoint(network)
121+
mnemonicWallet = configureWallet(process.env.MNEMONIC, provider)
84122
gns = new ConnectedGNS(network, configureGanacheWallet())
123+
connectedGT = new ConnectedGraphToken(network, configureGanacheWallet())
85124
} else {
86125
provider = buildNetworkEndpoint(network, 'infura')
87-
gns = new ConnectedGNS(network, configureWallet(process.env.MNEMONIC, provider))
126+
mnemonicWallet = configureWallet(process.env.MNEMONIC, provider)
127+
gns = new ConnectedGNS(network, mnemonicWallet)
128+
connectedGT = new ConnectedGraphToken(network, configureWallet(process.env.MNEMONIC, provider))
88129
}
89130

90131
try {
132+
if (func == 'setDefaultName') {
133+
checkFuncInputs([name], ['name'], func)
134+
console.log(`Setting default name for ${name}`)
135+
const ens = new ConnectedENS(network, mnemonicWallet)
136+
await executeTransaction(
137+
networkContracts.gns.setDefaultName(graphAccount, 0, ens.getNode(name), name),
138+
network,
139+
)
140+
}
91141
if (func == 'publishNewSubgraph') {
92142
checkFuncInputs(
93-
[ipfs, subgraphDeploymentID, nameIdentifier, name, metadataPath],
94-
['ipfs', 'subgraphDeploymentID', 'nameIdentifier', 'name', 'metadataPath'],
95-
'publishNewSubgraph',
143+
[ipfs, subgraphDeploymentID, versionPath, subgraphPath],
144+
['ipfs', 'subgraphDeploymentID', 'versionPath', 'subgraphPath'],
145+
func,
96146
)
97147
console.log(`Publishing 1st version of subgraph ${name} ...`)
98148
await executeTransaction(
99149
gns.pinIPFSAndNewSubgraph(
100150
ipfs,
101151
graphAccount,
102152
subgraphDeploymentID,
103-
nameIdentifier,
104-
name,
105-
metadataPath,
153+
versionPath,
154+
subgraphPath,
106155
),
107156
network,
108157
)
109158
} else if (func == 'publishNewVersion') {
110159
checkFuncInputs(
111-
[ipfs, subgraphDeploymentID, nameIdentifier, name, metadataPath, subgraphNumber],
112-
[
113-
'ipfs',
114-
'subgraphDeploymentID',
115-
'nameIdentifier',
116-
'name',
117-
'metadataPath',
118-
'subgraphNumber',
119-
],
120-
'publishNewVersion',
160+
[ipfs, subgraphDeploymentID, versionPath, subgraphNumber],
161+
['ipfs', 'subgraphDeploymentID', 'versionPath', 'subgraphNumber'],
162+
func,
121163
)
122164
console.log(`Publishing a new version for subgraph ${name} ...`)
123165
await executeTransaction(
124166
gns.pinIPFSAndNewVersion(
125167
ipfs,
126168
graphAccount,
127169
subgraphDeploymentID,
128-
nameIdentifier,
129-
name,
130-
metadataPath,
170+
versionPath,
131171
subgraphNumber,
132172
),
133173
network,
134174
)
135175
} else if (func == 'deprecate') {
136-
checkFuncInputs([subgraphNumber], ['subgraphNumber'], 'deprecate')
176+
checkFuncInputs([subgraphNumber], ['subgraphNumber'], func)
137177
console.log(`Deprecating subgraph ${graphAccount}-${subgraphNumber}`)
138-
await executeTransaction(gns.gns.deprecate(graphAccount, subgraphNumber), network)
178+
await executeTransaction(gns.gns.deprecateSubgraph(graphAccount, subgraphNumber), network)
179+
} else if (func == 'updateSubgraphMetadata') {
180+
checkFuncInputs([subgraphNumber, subgraphPath], ['subgraphNumber', 'subgraphPath'], func)
181+
console.log(`Updating subgraph metadata for ${graphAccount}-${subgraphNumber}`)
182+
await executeTransaction(
183+
gns.gns.updateSubgraphMetadata(graphAccount, subgraphNumber, subgraphPath),
184+
network,
185+
)
186+
} else if (func == 'mintNSignal') {
187+
checkFuncInputs([subgraphNumber, tokens], ['subgraphNumber', 'tokens'], func)
188+
console.log(
189+
' First calling approve() to ensure curation contract can call transferFrom()...',
190+
)
191+
const tokensWithDecimal = utils.parseUnits(tokens as string, 18).toString()
192+
await executeTransaction(
193+
connectedGT.approveWithDecimals(networkContracts.gns.address, tokensWithDecimal),
194+
network,
195+
)
196+
console.log(`Minting nSignal with ${tokens} on ${graphAccount}-${subgraphNumber}`)
197+
await executeTransaction(
198+
gns.gns.mintNSignal(graphAccount, subgraphNumber, tokensWithDecimal, basicOverrides()),
199+
network,
200+
)
201+
} else if (func == 'burnNSignal') {
202+
checkFuncInputs([subgraphNumber, nSignal], ['subgraphNumber', nSignal], func)
203+
console.log(`Burning ${nSignal} nSignal on ${graphAccount}-${subgraphNumber}`)
204+
const nSignalWithDecimal = utils.parseUnits(nSignal as string, 18).toString()
205+
await executeTransaction(
206+
gns.gns.burnNSignal(graphAccount, subgraphNumber, nSignalWithDecimal),
207+
network,
208+
)
209+
} else if (func == 'withdrawGRT') {
210+
checkFuncInputs([subgraphNumber], ['subgraphNumber'], func)
211+
console.log(`Withdrawing GRT from deprecated subgraph ${graphAccount}-${subgraphNumber}`)
212+
await executeTransaction(gns.gns.withdraw(graphAccount, subgraphNumber), network)
139213
} else {
140214
console.log(`Wrong func name provided`)
141215
process.exit(1)

0 commit comments

Comments
 (0)