@@ -9,30 +9,37 @@ import {
9
9
configureGanacheWallet ,
10
10
configureWallet ,
11
11
buildNetworkEndpoint ,
12
+ basicOverrides ,
12
13
} 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'
14
17
15
18
const {
16
19
network,
17
20
func,
18
21
ipfs,
19
22
graphAccount,
20
23
subgraphDeploymentID,
21
- nameIdentifier,
22
24
name,
23
- metadataPath,
25
+ versionPath,
26
+ subgraphPath,
24
27
subgraphNumber,
28
+ tokens,
29
+ nSignal,
25
30
} = minimist . default ( process . argv . slice ( 2 ) , {
26
31
string : [
27
32
'network' ,
28
33
'func' ,
29
34
'ipfs' ,
30
35
'graphAccount' ,
31
36
'subgraphDeploymentID' ,
32
- 'nameIdentifier' ,
33
37
'name' ,
34
- 'metadataPath' ,
38
+ 'versionPath' ,
39
+ 'subgraphPath' ,
35
40
'subgraphNumber' ,
41
+ 'tokens' ,
42
+ 'nSignal' ,
36
43
] ,
37
44
} )
38
45
@@ -41,35 +48,61 @@ if (!network || !func || !graphAccount) {
41
48
`
42
49
Usage: ${ path . basename ( process . argv [ 1 ] ) }
43
50
--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
45
53
46
54
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
+
47
60
publishNewSubgraph
48
61
--ipfs <url> - ex. https://api.thegraph.com/ipfs/
49
- --graphAccount <address> - erc1056 identity, often just the transacting account
62
+ --graphAccount <address> - graph account address
50
63
--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:
54
70
{
55
71
"description": "",
72
+ "displayName": "",
56
73
"image": "",
57
74
"codeRepository": "",
58
75
"website": "",
59
- "description": "",
60
- "label": ""
61
76
}
77
+
62
78
publishVersion
63
79
--ipfs <url> - ex. https://api.thegraph.com/ipfs/
64
- --graphAccount <address> - erc1056 identity, often just the transacting account
80
+ --graphAccount <address> - graph account address
65
81
--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
69
83
--subgraphNumber <number> - numbered subgraph for the graph account
70
84
71
85
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
73
106
--subgraphNumber <number> - numbered subgraph for the graph account
74
107
` ,
75
108
)
@@ -78,64 +111,105 @@ Usage: ${path.basename(process.argv[1])}
78
111
79
112
const main = async ( ) => {
80
113
let gns : ConnectedGNS
114
+ let connectedGT : ConnectedGraphToken
81
115
let provider
116
+ let mnemonicWallet : Wallet
117
+ const networkContracts = await connectContracts ( mnemonicWallet , network )
118
+
82
119
if ( network == 'ganache' ) {
83
120
provider = buildNetworkEndpoint ( network )
121
+ mnemonicWallet = configureWallet ( process . env . MNEMONIC , provider )
84
122
gns = new ConnectedGNS ( network , configureGanacheWallet ( ) )
123
+ connectedGT = new ConnectedGraphToken ( network , configureGanacheWallet ( ) )
85
124
} else {
86
125
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 ) )
88
129
}
89
130
90
131
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
+ }
91
141
if ( func == 'publishNewSubgraph' ) {
92
142
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 ,
96
146
)
97
147
console . log ( `Publishing 1st version of subgraph ${ name } ...` )
98
148
await executeTransaction (
99
149
gns . pinIPFSAndNewSubgraph (
100
150
ipfs ,
101
151
graphAccount ,
102
152
subgraphDeploymentID ,
103
- nameIdentifier ,
104
- name ,
105
- metadataPath ,
153
+ versionPath ,
154
+ subgraphPath ,
106
155
) ,
107
156
network ,
108
157
)
109
158
} else if ( func == 'publishNewVersion' ) {
110
159
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 ,
121
163
)
122
164
console . log ( `Publishing a new version for subgraph ${ name } ...` )
123
165
await executeTransaction (
124
166
gns . pinIPFSAndNewVersion (
125
167
ipfs ,
126
168
graphAccount ,
127
169
subgraphDeploymentID ,
128
- nameIdentifier ,
129
- name ,
130
- metadataPath ,
170
+ versionPath ,
131
171
subgraphNumber ,
132
172
) ,
133
173
network ,
134
174
)
135
175
} else if ( func == 'deprecate' ) {
136
- checkFuncInputs ( [ subgraphNumber ] , [ 'subgraphNumber' ] , 'deprecate' )
176
+ checkFuncInputs ( [ subgraphNumber ] , [ 'subgraphNumber' ] , func )
137
177
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 )
139
213
} else {
140
214
console . log ( `Wrong func name provided` )
141
215
process . exit ( 1 )
0 commit comments