Skip to content

Commit 83537d7

Browse files
committed
Add curation and service registry to yargs CLI
1 parent 34f716c commit 83537d7

File tree

7 files changed

+179
-20
lines changed

7 files changed

+179
-20
lines changed

scripts/cli/cli.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { migrateCommand } from './commands/migrate'
77
import { upgradeCommand } from './commands/upgrade'
88
import { verifyCommand } from './commands/verify'
99
import { protocolCommand } from './commands/protocol'
10+
import { contractsCommand } from './commands/contracts/contracts'
1011
import { cliOpts } from './constants'
1112

1213
dotenv.config()
@@ -21,5 +22,6 @@ yargs
2122
.command(upgradeCommand)
2223
.command(verifyCommand)
2324
.command(protocolCommand)
25+
.command(contractsCommand)
2426
.demandCommand(1, 'Choose a command from the above list')
2527
.help().argv
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import yargs, { Argv } from 'yargs'
2+
3+
import { curationCommand } from './curation'
4+
import { serviceRegistryCommand } from './service-registry'
5+
import { CLIArgs } from '../../env'
6+
7+
export const contractsCommand = {
8+
command: 'contracts',
9+
describe: 'Contract calls for all contracts',
10+
builder: (yargs: Argv): yargs.Argv => {
11+
return yargs.command(curationCommand).command(serviceRegistryCommand)
12+
},
13+
handler: (argv: CLIArgs): void => {
14+
yargs.showHelp()
15+
},
16+
}
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
import consola from 'consola'
2+
import yargs, { Argv } from 'yargs'
3+
import { parseGRT } from '@graphprotocol/common-ts'
4+
5+
import { getContractAt, sendTransaction } from '../../network'
6+
import { loadEnv, CLIArgs, CLIEnvironment } from '../../env'
7+
8+
const logger = consola.create({})
9+
10+
export const mint = async (cli: CLIEnvironment, cliArgs: CLIArgs) => {
11+
const subgraphID = cliArgs.subgraphID
12+
const amount = parseGRT(cliArgs.amount)
13+
14+
const curationEntry = cli.addressBook.getEntry('Curation')
15+
const graphTokenEntry = cli.addressBook.getEntry('GraphToken')
16+
17+
const curation = getContractAt('Curation', curationEntry.address).connect(cli.wallet)
18+
const graphToken = getContractAt('GraphToken', graphTokenEntry.address).connect(cli.wallet)
19+
20+
logger.log('First calling approve() to ensure curation contract can call transferFrom()...')
21+
await sendTransaction(cli.wallet, graphToken, 'approve', ...[curationEntry.address, amount])
22+
logger.log(`Signaling on ${subgraphID} with ${cliArgs.amount} tokens...`)
23+
await sendTransaction(cli.wallet, curation, 'mint', ...[subgraphID, amount])
24+
}
25+
export const burn = async (cli: CLIEnvironment, cliArgs: CLIArgs) => {
26+
const subgraphID = cliArgs.subgraphID
27+
const amount = parseGRT(cliArgs.amount)
28+
29+
const curationEntry = cli.addressBook.getEntry('Curation')
30+
const curation = getContractAt('Curation', curationEntry.address).connect(cli.wallet)
31+
32+
logger.log(`Burning signal on ${subgraphID} with ${cliArgs.amount} tokens...`)
33+
await sendTransaction(cli.wallet, curation, 'burn', ...[subgraphID, amount])
34+
}
35+
36+
export const curationCommand = {
37+
command: 'curation',
38+
describe: 'Curation contract calls',
39+
builder: (yargs: Argv): yargs.Argv => {
40+
return yargs
41+
.command({
42+
command: 'mint',
43+
describe: 'Mint signal for a subgraph deployment',
44+
builder: (yargs: Argv) => {
45+
return yargs
46+
.option('s', {
47+
alias: 'subgraphID',
48+
description: 'The subgraph deployment ID being curated on',
49+
type: 'string',
50+
requiresArg: true,
51+
demandOption: true,
52+
})
53+
.option('amount', {
54+
description: 'Amount of tokens being signaled. CLI converts to a BN with 10^18',
55+
type: 'string',
56+
requiresArg: true,
57+
demandOption: true,
58+
})
59+
},
60+
handler: async (argv: CLIArgs): Promise<void> => {
61+
return mint(await loadEnv(argv), argv)
62+
},
63+
})
64+
.command({
65+
command: 'burn',
66+
describe: 'Burn signal of a subgraph deployment',
67+
builder: (yargs: Argv) => {
68+
return yargs
69+
.option('s', {
70+
alias: 'subgraphID',
71+
description: 'The subgraph deployment ID being curated on',
72+
type: 'string',
73+
requiresArg: true,
74+
demandOption: true,
75+
})
76+
.option('amount', {
77+
description: 'Amount of shares being redeemed. CLI converts to a BN with 10^18',
78+
type: 'string',
79+
requiresArg: true,
80+
demandOption: true,
81+
})
82+
},
83+
handler: async (argv: CLIArgs): Promise<void> => {
84+
return burn(await loadEnv(argv), argv)
85+
},
86+
})
87+
},
88+
handler: (argv: CLIArgs): void => {
89+
yargs.showHelp()
90+
},
91+
}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
import consola from 'consola'
2+
import yargs, { Argv } from 'yargs'
3+
4+
import { getContractAt, sendTransaction } from '../../network'
5+
import { loadEnv, CLIArgs, CLIEnvironment } from '../../env'
6+
7+
const logger = consola.create({})
8+
export const register = async (cli: CLIEnvironment, cliArgs: CLIArgs) => {
9+
const url = cliArgs.url
10+
const geoHash = cliArgs.geoHash
11+
12+
const addressEntry = cli.addressBook.getEntry('ServiceRegistry')
13+
const serviceRegistry = getContractAt('ServiceRegistry', addressEntry.address).connect(cli.wallet)
14+
15+
logger.log(`Registering indexer ${cli.walletAddress} with url ${url} and geoHash ${geoHash}`)
16+
await sendTransaction(cli.wallet, serviceRegistry, 'register', ...[url, geoHash])
17+
}
18+
export const unregister = async (cli: CLIEnvironment, cliArgs: CLIArgs) => {
19+
const addressEntry = cli.addressBook.getEntry('ServiceRegistry')
20+
const serviceRegistry = getContractAt('ServiceRegistry', addressEntry.address).connect(cli.wallet)
21+
22+
logger.log(`Unregistering indexer ${cli.walletAddress}`)
23+
await sendTransaction(cli.wallet, serviceRegistry, 'unregister')
24+
}
25+
26+
export const serviceRegistryCommand = {
27+
command: 'serviceRegistry',
28+
describe: 'Service Registry contract calls',
29+
builder: (yargs: Argv): yargs.Argv => {
30+
return yargs
31+
.command({
32+
command: 'register',
33+
describe: 'Register an indexer in the service registry',
34+
builder: (yargs: Argv) => {
35+
return yargs
36+
.option('u', {
37+
alias: 'url',
38+
description: 'URL of the indexer',
39+
type: 'string',
40+
requiresArg: true,
41+
demandOption: true,
42+
})
43+
.option('g', {
44+
alias: 'geoHash',
45+
description: 'GeoHash of the indexer',
46+
type: 'string',
47+
requiresArg: true,
48+
demandOption: true,
49+
})
50+
},
51+
handler: async (argv: CLIArgs): Promise<void> => {
52+
return register(await loadEnv(argv), argv)
53+
},
54+
})
55+
.command({
56+
command: 'unregister',
57+
describe: 'Unregister an indexer in the service registry',
58+
handler: async (argv: CLIArgs): Promise<void> => {
59+
return unregister(await loadEnv(argv), argv)
60+
},
61+
})
62+
},
63+
handler: (argv: CLIArgs): void => {
64+
yargs.showHelp()
65+
},
66+
}

scripts/contracts/connectedContracts.ts

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,6 @@ class ConnectedCuration extends ConnectedContract {
7979
}
8080
}
8181

82-
// TODO - move away from TestRecord and use the real methods when we move to Rinkeby and mainnet
83-
// We don't use estimate gas here, since registering ENS names won't be part of our front end
8482
class ConnectedENS extends ConnectedContract {
8583
// We just lower case to normalize, but real normalization should follow:
8684
// https://docs.ens.domains/contract-api-reference/name-processing
@@ -96,18 +94,6 @@ class ConnectedENS extends ConnectedContract {
9694
return contracts.testRegistrar.register(label, signerAddress)
9795
}
9896

99-
// TODO - remove, not in use anymore
100-
// setText = async (name: string): Promise<ContractTransaction> => {
101-
// const contracts = await connectContracts(this.configuredWallet, this.network)
102-
// const normalizedName = name.toLowerCase()
103-
// const labelNameFull = `${normalizedName}.${'eth'}`
104-
// const labelHashFull = utils.namehash(labelNameFull)
105-
// console.log(`Setting text name: ${labelNameFull} with node: ${labelHashFull}`)
106-
// const key = 'GRAPH NAME SERVICE'
107-
// const signerAddress = await contracts.publicResolver.signer.getAddress()
108-
// return contracts.publicResolver.setText(labelHashFull, key, signerAddress)
109-
// }
110-
11197
checkOwner = async (name: string): Promise<void> => {
11298
const contracts = await connectContracts(this.configuredWallet, this.network)
11399
try {

scripts/contracts/sendTeamTokens.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,9 @@ const main = async () => {
4444
}
4545
try {
4646
if (func == 'mint') {
47-
for (let i = 0; i < teamAddresses.length; i++) {
48-
console.log(`Minting ${amount} tokens to user ${teamAddresses[i].name}...`)
49-
await executeTransaction(
50-
graphToken.mintWithDecimals(teamAddresses[i].address, amount),
51-
network,
52-
)
47+
for (const member of teamAddresses) {
48+
console.log(`Minting ${amount} tokens to user ${member.name}...`)
49+
await executeTransaction(graphToken.mintWithDecimals(member.address, amount), network)
5350
}
5451
} else {
5552
console.log(`Wrong func name provided`)

scripts/teamAddresses.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,5 @@ export const teamAddresses: Array<TeamMember> = [
1515
{ name: 'dave', address: '0x93606b27cB5e4c780883eC4F6b7Bed5f6572d1dd' },
1616
{ name: 'zac', address: '0xD31bC1e2a214066Bb2258dac5f43Ce75e5542Ab9' },
1717
{ name: 'martin', address: '0x055BCF2c2BC965Ac8EEAe3f95922D65EE45d3366' },
18+
{ name: 'jeff', address: '0xc02624Affa30299fA164e7176A37610835A923A7' },
1819
]

0 commit comments

Comments
 (0)