|
1 | 1 | import consola from 'consola'
|
2 | 2 | import { parseGRT } from '@graphprotocol/common-ts'
|
3 |
| -import { Argv } from 'yargs' |
| 3 | +import yargs, { Argv } from 'yargs' |
4 | 4 |
|
5 | 5 | import { sendTransaction } from '../../network'
|
6 | 6 | import { loadEnv, CLIArgs, CLIEnvironment } from '../../env'
|
7 |
| -import { parseSubgraphsCSV, CurateSimulationTransaction } from './parseCSV' |
| 7 | +import { parseCreateSubgraphsCSV, CurateSimulationTransaction, parseUnsignalCSV } from './parseCSV' |
8 | 8 | import { pinMetadataToIPFS, IPFS } from '../../helpers'
|
9 | 9 |
|
10 | 10 | const logger = consola.create({})
|
@@ -68,33 +68,69 @@ const curateOnSubgraphs = async (
|
68 | 68 | }
|
69 | 69 | }
|
70 | 70 |
|
71 |
| -export const simulation = async (cli: CLIEnvironment, cliArgs: CLIArgs): Promise<void> => { |
72 |
| - const txData = parseSubgraphsCSV(__dirname + cliArgs.path) |
| 71 | +const createAndSignal = async (cli: CLIEnvironment, cliArgs: CLIArgs): Promise<void> => { |
| 72 | + const txData = parseCreateSubgraphsCSV(__dirname + cliArgs.path) |
73 | 73 | logger.log(`Running the curation simulator`)
|
74 | 74 | await createSubgraphs(cli, txData)
|
75 | 75 | await curateOnSubgraphs(cli, txData, cliArgs.firstSubgraphNumber)
|
76 | 76 | }
|
77 | 77 |
|
| 78 | +const unsignal = async (cli: CLIEnvironment, cliArgs: CLIArgs): Promise<void> => { |
| 79 | + const txData = parseUnsignalCSV(__dirname + cliArgs.path) |
| 80 | + logger.log(`Burning nSignal for ${txData.length} accounts...`) |
| 81 | + for (let i = 0; i < txData.length; i++) { |
| 82 | + const account = txData[i].account |
| 83 | + const subgraphNumber = txData[i].subgraphNumber |
| 84 | + const nSignal = parseGRT(txData[i].amount) |
| 85 | + const gns = cli.contracts.GNS |
| 86 | + logger.log(`Burning nSignal for ${account}-${subgraphNumber}...`) |
| 87 | + await sendTransaction(cli.wallet, gns, 'burnNSignal', ...[account, subgraphNumber, nSignal]) |
| 88 | + } |
| 89 | +} |
78 | 90 | export const curatorSimulationCommand = {
|
79 | 91 | command: 'curatorSimulation',
|
80 | 92 | describe: 'Simulates creating multiple subgraphs and then curating on them, from a csv file',
|
81 |
| - builder: (yargs: Argv) => { |
| 93 | + builder: (yargs: Argv): yargs.Argv => { |
82 | 94 | return yargs
|
83 |
| - .option('path', { |
84 |
| - description: 'Path of the csv file relative to this folder', |
85 |
| - type: 'string', |
86 |
| - requiresArg: true, |
87 |
| - demandOption: true, |
| 95 | + .command({ |
| 96 | + command: 'createAndSignal', |
| 97 | + describe: 'Create and signal on subgraphs by reading data from a csv file', |
| 98 | + builder: (yargs: Argv) => { |
| 99 | + return yargs |
| 100 | + .option('path', { |
| 101 | + description: 'Path of the csv file relative to this folder', |
| 102 | + type: 'string', |
| 103 | + requiresArg: true, |
| 104 | + demandOption: true, |
| 105 | + }) |
| 106 | + .option('firstSubgraphNumber', { |
| 107 | + description: 'First subgraph to be newly curated', |
| 108 | + type: 'number', |
| 109 | + requiresArg: true, |
| 110 | + demandOption: true, |
| 111 | + }) |
| 112 | + }, |
| 113 | + handler: async (argv: CLIArgs): Promise<void> => { |
| 114 | + return createAndSignal(await loadEnv(argv), argv) |
| 115 | + }, |
88 | 116 | })
|
89 |
| - .option('firstSubgraphNumber', { |
90 |
| - description: |
91 |
| - 'First subgraph to be newly curated. Used so we can curate the right subgraphs', |
92 |
| - type: 'number', |
93 |
| - requiresArg: true, |
94 |
| - demandOption: true, |
| 117 | + .command({ |
| 118 | + command: 'unsignal', |
| 119 | + describe: 'Unsignal on a bunch of subgraphs by reading data from a CSV', |
| 120 | + builder: (yargs: Argv) => { |
| 121 | + return yargs.option('path', { |
| 122 | + description: 'Path of the csv file relative to this folder', |
| 123 | + type: 'string', |
| 124 | + requiresArg: true, |
| 125 | + demandOption: true, |
| 126 | + }) |
| 127 | + }, |
| 128 | + handler: async (argv: CLIArgs): Promise<void> => { |
| 129 | + return unsignal(await loadEnv(argv), argv) |
| 130 | + }, |
95 | 131 | })
|
96 | 132 | },
|
97 |
| - handler: async (argv: CLIArgs): Promise<void> => { |
98 |
| - return simulation(await loadEnv(argv), argv) |
| 133 | + handler: (): void => { |
| 134 | + yargs.showHelp() |
99 | 135 | },
|
100 | 136 | }
|
0 commit comments