Skip to content

Commit 0ca43ff

Browse files
committed
feat: add publish and mint to the CLI
1 parent 5e36583 commit 0ca43ff

File tree

1 file changed

+87
-2
lines changed

1 file changed

+87
-2
lines changed

cli/commands/contracts/gns.ts

Lines changed: 87 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { logger } from '../../logging'
55
import { sendTransaction } from '../../network'
66
import { loadEnv, CLIArgs, CLIEnvironment } from '../../env'
77
import { nameToNode } from './ens'
8-
import { IPFS, pinMetadataToIPFS } from '../../helpers'
8+
import { IPFS, pinMetadataToIPFS, buildSubgraphID, ensureGRTAllowance } from '../../helpers'
99

1010
export const setDefaultName = async (cli: CLIEnvironment, cliArgs: CLIArgs): Promise<void> => {
1111
const graphAccount = cliArgs.graphAccount
@@ -102,6 +102,44 @@ export const withdraw = async (cli: CLIEnvironment, cliArgs: CLIArgs): Promise<v
102102
await sendTransaction(cli.wallet, gns, 'withdraw', [subgraphID])
103103
}
104104

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+
105143
export const gnsCommand = {
106144
command: 'gns',
107145
describe: 'GNS contract calls',
@@ -172,7 +210,7 @@ export const gnsCommand = {
172210
})
173211
.command({
174212
command: 'publishNewVersion',
175-
describe: 'Withdraw unlocked GRT',
213+
describe: 'Publish a new subgraph version',
176214
builder: (yargs: Argv) => {
177215
return yargs
178216
.option('subgraphID', {
@@ -307,6 +345,53 @@ export const gnsCommand = {
307345
return withdraw(await loadEnv(argv), argv)
308346
},
309347
})
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+
})
310395
},
311396
handler: (): void => {
312397
yargs.showHelp()

0 commit comments

Comments
 (0)