Skip to content

Commit a2fdfd9

Browse files
committed
Add burning nSignal to the curator simulator
1 parent 5248888 commit a2fdfd9

File tree

3 files changed

+99
-19
lines changed

3 files changed

+99
-19
lines changed

cli/commands/simulations/curatorSimulation.ts

Lines changed: 54 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import consola from 'consola'
22
import { parseGRT } from '@graphprotocol/common-ts'
3-
import { Argv } from 'yargs'
3+
import yargs, { Argv } from 'yargs'
44

55
import { sendTransaction } from '../../network'
66
import { loadEnv, CLIArgs, CLIEnvironment } from '../../env'
7-
import { parseSubgraphsCSV, CurateSimulationTransaction } from './parseCSV'
7+
import { parseCreateSubgraphsCSV, CurateSimulationTransaction, parseUnsignalCSV } from './parseCSV'
88
import { pinMetadataToIPFS, IPFS } from '../../helpers'
99

1010
const logger = consola.create({})
@@ -68,33 +68,69 @@ const curateOnSubgraphs = async (
6868
}
6969
}
7070

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)
7373
logger.log(`Running the curation simulator`)
7474
await createSubgraphs(cli, txData)
7575
await curateOnSubgraphs(cli, txData, cliArgs.firstSubgraphNumber)
7676
}
7777

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+
}
7890
export const curatorSimulationCommand = {
7991
command: 'curatorSimulation',
8092
describe: 'Simulates creating multiple subgraphs and then curating on them, from a csv file',
81-
builder: (yargs: Argv) => {
93+
builder: (yargs: Argv): yargs.Argv => {
8294
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+
},
88116
})
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+
},
95131
})
96132
},
97-
handler: async (argv: CLIArgs): Promise<void> => {
98-
return simulation(await loadEnv(argv), argv)
133+
handler: (): void => {
134+
yargs.showHelp()
99135
},
100136
}

cli/commands/simulations/parseCSV.ts

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export interface CurateSimulationTransaction {
1111

1212
// Parses a CSV where the titles are ordered like so:
1313
// displayName,description,subgraphID,signal,codeRepository,image,website
14-
export function parseSubgraphsCSV(path: string) {
14+
export function parseCreateSubgraphsCSV(path: string): Array<CurateSimulationTransaction> {
1515
const data = fs.readFileSync(path, 'utf8')
1616
const subgraphs = data.split('\n').map((e) => e.trim())
1717
const txData: Array<CurateSimulationTransaction> = []
@@ -45,3 +45,28 @@ export function parseSubgraphsCSV(path: string) {
4545
}
4646
return txData
4747
}
48+
49+
export interface UnsignalTransaction {
50+
account: string
51+
subgraphNumber: string
52+
amount: string
53+
}
54+
55+
// Parses a CSV for unsignalling
56+
export function parseUnsignalCSV(path: string): Array<UnsignalTransaction> {
57+
const data = fs.readFileSync(path, 'utf8')
58+
const subgraphs = data.split('\n').map((e) => e.trim())
59+
const txData: Array<UnsignalTransaction> = []
60+
for (let i = 1; i < subgraphs.length; i++) {
61+
// skip the csv title line by starting at 1
62+
const csvData = subgraphs[i]
63+
const [account, subgraphNumber, amount] = csvData.split(',').map((e) => e.trim())
64+
const data: UnsignalTransaction = {
65+
account: account,
66+
subgraphNumber: subgraphNumber,
67+
amount: amount,
68+
}
69+
txData.push(data)
70+
}
71+
return txData
72+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Account,Subgraph Number,Amount
2+
0x90F8bf6A479f320ead074411a4B0e7944Ea8c9C1,0,300000
3+
0x90F8bf6A479f320ead074411a4B0e7944Ea8c9C1,1,100000
4+
0x90F8bf6A479f320ead074411a4B0e7944Ea8c9C1,2,100000
5+
0x90F8bf6A479f320ead074411a4B0e7944Ea8c9C1,3,100000
6+
0x90F8bf6A479f320ead074411a4B0e7944Ea8c9C1,4,100000
7+
0x90F8bf6A479f320ead074411a4B0e7944Ea8c9C1,5,50000
8+
0x90F8bf6A479f320ead074411a4B0e7944Ea8c9C1,6,25000
9+
0x90F8bf6A479f320ead074411a4B0e7944Ea8c9C1,7,80000
10+
0x90F8bf6A479f320ead074411a4B0e7944Ea8c9C1,8,150000
11+
0x90F8bf6A479f320ead074411a4B0e7944Ea8c9C1,9,150000
12+
0x90F8bf6A479f320ead074411a4B0e7944Ea8c9C1,10,150000
13+
0x90F8bf6A479f320ead074411a4B0e7944Ea8c9C1,11,150000
14+
0x90F8bf6A479f320ead074411a4B0e7944Ea8c9C1,12,200000
15+
0x90F8bf6A479f320ead074411a4B0e7944Ea8c9C1,13,200000
16+
0x90F8bf6A479f320ead074411a4B0e7944Ea8c9C1,14,200000
17+
0x90F8bf6A479f320ead074411a4B0e7944Ea8c9C1,15,100000
18+
0x90F8bf6A479f320ead074411a4B0e7944Ea8c9C1,16,200000
19+
0x90F8bf6A479f320ead074411a4B0e7944Ea8c9C1,17,200000

0 commit comments

Comments
 (0)