|
| 1 | +import consola from 'consola' |
| 2 | +import yargs, { Argv } from 'yargs' |
| 3 | + |
| 4 | +import { sendTransaction } from '../../network' |
| 5 | +import { loadEnv, CLIArgs, CLIEnvironment } from '../../env' |
| 6 | + |
| 7 | +const logger = consola.create({}) |
| 8 | + |
| 9 | +export const createProposal = async (cli: CLIEnvironment, cliArgs: CLIArgs): Promise<void> => { |
| 10 | + const id = cliArgs.id |
| 11 | + const votes = cliArgs.votes |
| 12 | + const metadata = cliArgs.metadata |
| 13 | + const resolution = cliArgs.resolution |
| 14 | + const governance = cli.contracts.Governance |
| 15 | + |
| 16 | + logger.log(`Creating proposal ${id}...`) |
| 17 | + await sendTransaction(cli.wallet, governance, 'createProposal', [id, votes, metadata, resolution]) |
| 18 | +} |
| 19 | + |
| 20 | +export const upgradeProposal = async (cli: CLIEnvironment, cliArgs: CLIArgs): Promise<void> => { |
| 21 | + const id = cliArgs.id |
| 22 | + const votes = cliArgs.votes |
| 23 | + const metadata = cliArgs.metadata |
| 24 | + const resolution = cliArgs.resolution |
| 25 | + const governance = cli.contracts.Governance |
| 26 | + |
| 27 | + logger.log(`Upgrade proposal ${id}...`) |
| 28 | + await sendTransaction(cli.wallet, governance, 'upgradeProposal', [ |
| 29 | + id, |
| 30 | + votes, |
| 31 | + metadata, |
| 32 | + resolution, |
| 33 | + ]) |
| 34 | +} |
| 35 | + |
| 36 | +export const governanceCommand = { |
| 37 | + command: 'governance', |
| 38 | + describe: 'Graph governance contract calls', |
| 39 | + builder: (yargs: Argv): yargs.Argv => { |
| 40 | + return yargs |
| 41 | + .command({ |
| 42 | + command: 'createProposal', |
| 43 | + describe: 'Create a proposal', |
| 44 | + builder: (yargs: Argv): yargs.Argv => { |
| 45 | + return yargs |
| 46 | + .option('id', { |
| 47 | + description: 'Proposal ID', |
| 48 | + type: 'string', |
| 49 | + requiresArg: true, |
| 50 | + demandOption: true, |
| 51 | + }) |
| 52 | + .option('votes', { |
| 53 | + description: 'IPFS hash in bytes32', |
| 54 | + type: 'string', |
| 55 | + requiresArg: true, |
| 56 | + demandOption: true, |
| 57 | + }) |
| 58 | + .option('metadata', { |
| 59 | + description: 'IPFS hash in bytes32', |
| 60 | + type: 'string', |
| 61 | + requiresArg: true, |
| 62 | + demandOption: true, |
| 63 | + }) |
| 64 | + .option('resolution', { |
| 65 | + description: 'Resolution. 1 = Accepted, 2 = Rejected ', |
| 66 | + type: 'number', |
| 67 | + requiresArg: true, |
| 68 | + demandOption: true, |
| 69 | + }) |
| 70 | + .option('b', { |
| 71 | + alias: 'build-tx', |
| 72 | + description: |
| 73 | + 'Build the acceptProxy tx and print it. Then use tx data with a multisig', |
| 74 | + }) |
| 75 | + }, |
| 76 | + handler: async (argv: CLIArgs): Promise<void> => { |
| 77 | + return createProposal(await loadEnv(argv), argv) |
| 78 | + }, |
| 79 | + }) |
| 80 | + .command({ |
| 81 | + command: 'upgradeProposal', |
| 82 | + describe: 'Upgrade a proposal', |
| 83 | + builder: (yargs: Argv): yargs.Argv => { |
| 84 | + return yargs |
| 85 | + .option('id', { |
| 86 | + description: 'Proposal ID', |
| 87 | + type: 'string', |
| 88 | + requiresArg: true, |
| 89 | + demandOption: true, |
| 90 | + }) |
| 91 | + .option('votes', { |
| 92 | + description: 'IPFS hash in bytes32', |
| 93 | + type: 'string', |
| 94 | + requiresArg: true, |
| 95 | + demandOption: true, |
| 96 | + }) |
| 97 | + .option('metadata', { |
| 98 | + description: 'IPFS hash in bytes32', |
| 99 | + type: 'string', |
| 100 | + requiresArg: true, |
| 101 | + demandOption: true, |
| 102 | + }) |
| 103 | + .option('resolution', { |
| 104 | + description: 'Resolution. 1 = Accepted, 2 = Rejected ', |
| 105 | + type: 'number', |
| 106 | + requiresArg: true, |
| 107 | + demandOption: true, |
| 108 | + }) |
| 109 | + .option('b', { |
| 110 | + alias: 'build-tx', |
| 111 | + description: |
| 112 | + 'Build the acceptProxy tx and print it. Then use tx data with a multisig', |
| 113 | + }) |
| 114 | + }, |
| 115 | + handler: async (argv: CLIArgs): Promise<void> => { |
| 116 | + return upgradeProposal(await loadEnv(argv), argv) |
| 117 | + }, |
| 118 | + }) |
| 119 | + }, |
| 120 | + handler: (): void => { |
| 121 | + yargs.showHelp() |
| 122 | + }, |
| 123 | +} |
0 commit comments