-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.ts
85 lines (82 loc) · 2.48 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import yargs from "yargs";
import {
StakehoundContext,
run_propose,
run_approve,
run_init,
run_force_approve,
run_force_propose,
} from "./src/system";
import { Signer, } from "ethers";
import { fetchContext } from "./src/utils";
import logger from "./src/logger";
const argv = yargs(process.argv.slice(2))
.command("init <config>", "init first rewards", (yargv) =>
yargv.positional("config", {
type: "string",
demandOption: true,
describe: "JSON file to read config",
})
)
.command("propose <config>", "run reward proposer", (yargv) =>
yargv.positional("config", {
type: "string",
demandOption: true,
describe: "JSON file to read config",
})
)
.command("approve <config>", "run reward approver", (yargv) =>
yargv.positional("config", {
type: "string",
demandOption: true,
describe: "JSON file to read config",
})
)
.command("force-propose <config>", "run reward proposer once, don't validate", (yargv) =>
yargv.positional("config", {
type: "string",
demandOption: true,
describe: "JSON file to read config",
})
)
.command("force-approve <config>", "run reward approver once, don't validate", (yargv) =>
yargv.positional("config", {
type: "string",
demandOption: true,
describe: "JSON file to read config",
})
)
.option("logfile", {
type: "string",
demandOption: true,
describe: "logfile",
})
.demandCommand(1).argv;
const run_with_context = (
func: (context: StakehoundContext, signer: Signer) => Promise<void>
) => {
fetchContext(argv.config!)
.then((con) => {
logger.info({
role: argv._[0],
epoch: `${con.epoch / 60} minutes`,
});
return func(con, con.signer);
})
.then(() => process.exit(0))
.catch((error) => {
logger.error(error);
process.exit(1);
});
};
if (argv._[0] === "propose") {
run_with_context(run_propose);
} else if (argv._[0] === "init") {
run_with_context(run_init);
} else if (argv._[0] === "approve") {
run_with_context(run_approve);
} else if (argv._[0] === "force-approve") {
run_with_context(run_force_approve);
} else if (argv._[0] === "force-propose") {
run_with_context(run_force_propose);
}