@@ -5,7 +5,7 @@ import { logger } from '../../logging'
5
5
import { sendTransaction } from '../../network'
6
6
import { loadEnv , CLIArgs , CLIEnvironment } from '../../env'
7
7
import { nameToNode } from './ens'
8
- import { IPFS , pinMetadataToIPFS } from '../../helpers'
8
+ import { IPFS , pinMetadataToIPFS , buildSubgraphID , ensureGRTAllowance } from '../../helpers'
9
9
10
10
export const setDefaultName = async ( cli : CLIEnvironment , cliArgs : CLIArgs ) : Promise < void > => {
11
11
const graphAccount = cliArgs . graphAccount
@@ -102,6 +102,44 @@ export const withdraw = async (cli: CLIEnvironment, cliArgs: CLIArgs): Promise<v
102
102
await sendTransaction ( cli . wallet , gns , 'withdraw' , [ subgraphID ] )
103
103
}
104
104
105
+ export const publishAndSignal = async ( cli : CLIEnvironment , cliArgs : CLIArgs ) : Promise < void > => {
106
+ // parse args
107
+ const ipfs = cliArgs . ipfs
108
+ const subgraphDeploymentID = cliArgs . subgraphDeploymentID
109
+ const versionPath = cliArgs . versionPath
110
+ const subgraphPath = cliArgs . subgraphPath
111
+ const tokens = parseGRT ( cliArgs . tokens )
112
+
113
+ // pin to IPFS
114
+ const subgraphDeploymentIDBytes = IPFS . ipfsHashToBytes32 ( subgraphDeploymentID )
115
+ const versionHashBytes = await pinMetadataToIPFS ( ipfs , 'version' , versionPath )
116
+ const subgraphHashBytes = await pinMetadataToIPFS ( ipfs , 'subgraph' , subgraphPath )
117
+
118
+ // craft transaction
119
+ const GNS = cli . contracts . GNS
120
+
121
+ // build publish tx
122
+ const publishTx = await GNS . populateTransaction . publishNewSubgraph (
123
+ subgraphDeploymentIDBytes ,
124
+ versionHashBytes ,
125
+ subgraphHashBytes ,
126
+ )
127
+
128
+ // build mint tx
129
+ const subgraphID = buildSubgraphID (
130
+ cli . walletAddress ,
131
+ await GNS . nextAccountSeqID ( cli . walletAddress ) ,
132
+ )
133
+ const mintTx = await GNS . populateTransaction . mintSignal ( subgraphID , tokens , 0 )
134
+
135
+ // ensure approval
136
+ await ensureGRTAllowance ( cli . wallet , GNS . address , tokens , cli . contracts . GraphToken )
137
+
138
+ // send multicall transaction
139
+ logger . info ( `Publishing and minting on new subgraph for ${ cli . walletAddress } ...` )
140
+ await sendTransaction ( cli . wallet , GNS , 'multicall' , [ [ publishTx . data , mintTx . data ] ] )
141
+ }
142
+
105
143
export const gnsCommand = {
106
144
command : 'gns' ,
107
145
describe : 'GNS contract calls' ,
@@ -172,7 +210,7 @@ export const gnsCommand = {
172
210
} )
173
211
. command ( {
174
212
command : 'publishNewVersion' ,
175
- describe : 'Withdraw unlocked GRT ' ,
213
+ describe : 'Publish a new subgraph version ' ,
176
214
builder : ( yargs : Argv ) => {
177
215
return yargs
178
216
. option ( 'subgraphID' , {
@@ -307,6 +345,53 @@ export const gnsCommand = {
307
345
return withdraw ( await loadEnv ( argv ) , argv )
308
346
} ,
309
347
} )
348
+ . command ( {
349
+ command : 'publishAndSignal' ,
350
+ describe : 'Publish a new subgraph and add initial signal' ,
351
+ builder : ( yargs : Argv ) => {
352
+ return yargs
353
+ . option ( 'ipfs' , {
354
+ description : 'ipfs endpoint. ex. https://api.thegraph.com/ipfs/' ,
355
+ type : 'string' ,
356
+ requiresArg : true ,
357
+ demandOption : true ,
358
+ } )
359
+ . option ( 'subgraphDeploymentID' , {
360
+ description : 'subgraph deployment ID in base58' ,
361
+ type : 'string' ,
362
+ requiresArg : true ,
363
+ demandOption : true ,
364
+ } )
365
+ . option ( 'versionPath' , {
366
+ description : ` filepath to metadata. With JSON format:\n
367
+ "description": "",
368
+ "label": ""` ,
369
+ type : 'string' ,
370
+ requiresArg : true ,
371
+ demandOption : true ,
372
+ } )
373
+ . option ( 'subgraphPath' , {
374
+ description : ` filepath to metadata. With JSON format:\n
375
+ "description": "",
376
+ "displayName": "",
377
+ "image": "",
378
+ "codeRepository": "",
379
+ "website": "",` ,
380
+ type : 'string' ,
381
+ requiresArg : true ,
382
+ demandOption : true ,
383
+ } )
384
+ . option ( 'tokens' , {
385
+ description : 'Amount of tokens to deposit' ,
386
+ type : 'string' ,
387
+ requiresArg : true ,
388
+ demandOption : true ,
389
+ } )
390
+ } ,
391
+ handler : async ( argv : CLIArgs ) : Promise < void > => {
392
+ return publishAndSignal ( await loadEnv ( argv ) , argv )
393
+ } ,
394
+ } )
310
395
} ,
311
396
handler : ( ) : void => {
312
397
yargs . showHelp ( )
0 commit comments