1 | #!/usr/bin/env node
|
2 |
|
3 | 'use strict';
|
4 |
|
5 | const fs = require('fs');
|
6 | const path = require('path');
|
7 | const util = require('util');
|
8 |
|
9 | const { getSuspensionReasons, networks, toBytes32, wrap } = require('./index');
|
10 |
|
11 | const {
|
12 | decode,
|
13 | getAST,
|
14 | getSource,
|
15 | getSynths,
|
16 | getFeeds,
|
17 | getTarget,
|
18 | getTokens,
|
19 | getUsers,
|
20 | getVersions,
|
21 | getStakingRewards,
|
22 | } = wrap({
|
23 | fs,
|
24 | path,
|
25 | });
|
26 |
|
27 | const commander = require('commander');
|
28 | const program = new commander.Command();
|
29 |
|
30 | program
|
31 | .command('ast <source>')
|
32 | .description('Get the AST for some source file')
|
33 | .action(async source => {
|
34 | console.log(JSON.stringify(getAST({ source, match: /./ }), null, 2));
|
35 | });
|
36 |
|
37 | program
|
38 | .command('bytes32 <key>')
|
39 | .description('Bytes32 representation of a currency key')
|
40 | .option('-c, --skip-check', 'Skip the check')
|
41 |
|
42 | .action(async (key, { skipCheck }) => {
|
43 | if (
|
44 | !skipCheck &&
|
45 | getSynths({ network: 'mainnet' }).filter(({ name }) => name === key).length < 1
|
46 | ) {
|
47 | throw Error(
|
48 | `Given key of "${key}" does not exist as a synth in mainnet (case-sensitive). Use --skip-check to skip this check.`
|
49 | );
|
50 | }
|
51 | console.log(toBytes32(key));
|
52 | });
|
53 |
|
54 | program
|
55 | .command('decode <data> [target]')
|
56 | .description('Decode a data payload from a Synthetix contract')
|
57 | .option('-n, --network <value>', 'The network to use', x => x.toLowerCase(), 'mainnet')
|
58 | .action(async (data, target, { network }) => {
|
59 | console.log(util.inspect(decode({ network, data, target }), false, null, true));
|
60 | });
|
61 |
|
62 | program
|
63 | .command('networks')
|
64 | .description('Get networks')
|
65 | .action(async () => {
|
66 | console.log(networks);
|
67 | });
|
68 |
|
69 | program
|
70 | .command('rewards')
|
71 | .description('Get staking rewards for an environment')
|
72 | .option('-n, --network <value>', 'The network to run off.', x => x.toLowerCase(), 'mainnet')
|
73 | .action(async ({ network }) => {
|
74 | console.log(JSON.stringify(getStakingRewards({ network }), null, 2));
|
75 | });
|
76 |
|
77 | program
|
78 | .command('source')
|
79 | .description('Get source files for an environment')
|
80 | .option('-n, --network <value>', 'The network to run off.', x => x.toLowerCase(), 'mainnet')
|
81 | .option('-c, --contract [value]', 'The name of the contract')
|
82 | .option('-k, --key [value]', 'A specific key wanted')
|
83 | .action(async ({ network, contract, key }) => {
|
84 | const source = getSource({ network, contract });
|
85 | console.log(JSON.stringify(key in source ? source[key] : source, null, 2));
|
86 | });
|
87 |
|
88 | program
|
89 | .command('feeds')
|
90 | .description('Get the price feeds')
|
91 | .option('-n, --network <value>', 'The network to run off.', x => x.toLowerCase(), 'mainnet')
|
92 | .action(async ({ network }) => {
|
93 | const feeds = getFeeds({ network });
|
94 | console.log(util.inspect(feeds, false, null, true));
|
95 | });
|
96 |
|
97 | program
|
98 | .command('suspension-reasons')
|
99 | .description('Get the suspension reason')
|
100 | .option('-c, --code [value]', 'A specific suspension code')
|
101 | .action(async ({ code }) => {
|
102 | const reason = getSuspensionReasons({ code });
|
103 | console.log(reason);
|
104 | });
|
105 |
|
106 | program
|
107 | .command('synths')
|
108 | .description('Get the list of synths')
|
109 | .option('-n, --network <value>', 'The network to run off.', x => x.toLowerCase(), 'mainnet')
|
110 | .option('-k, --key [value]', 'A specific key wanted')
|
111 | .action(async ({ network, key }) => {
|
112 | const synthList = getSynths({ network });
|
113 | console.log(
|
114 | JSON.stringify(
|
115 | synthList.map(entry => {
|
116 | return key in entry ? entry[key] : entry;
|
117 | }),
|
118 | null,
|
119 | 2
|
120 | )
|
121 | );
|
122 | });
|
123 |
|
124 | program
|
125 | .command('target')
|
126 | .description('Get deployed target files for an environment')
|
127 | .option('-n, --network <value>', 'The network to run off.', x => x.toLowerCase(), 'mainnet')
|
128 | .option('-c, --contract [value]', 'The name of the contract')
|
129 | .option('-k, --key [value]', 'A specific key wanted')
|
130 | .action(async ({ network, contract, key }) => {
|
131 | const target = getTarget({ network, contract });
|
132 | console.log(JSON.stringify(key in target ? target[key] : target, null, 2));
|
133 | });
|
134 |
|
135 | program
|
136 | .command('tokens')
|
137 | .description('Get the list of ERC20 tokens in Synthetix')
|
138 | .option('-n, --network <value>', 'The network to run off.', x => x.toLowerCase(), 'mainnet')
|
139 | .action(async ({ network }) => {
|
140 | const tokens = getTokens({ network });
|
141 | console.log(JSON.stringify(tokens, null, 2));
|
142 | });
|
143 |
|
144 | program
|
145 | .command('users')
|
146 | .description('Get the list of system users')
|
147 | .option('-n, --network <value>', 'The network to run off.', x => x.toLowerCase(), 'mainnet')
|
148 | .option('-u, --user [value]', 'A specific user wanted')
|
149 | .action(async ({ network, user }) => {
|
150 | const users = getUsers({ network, user });
|
151 | console.log(JSON.stringify(users, null, 2));
|
152 | });
|
153 |
|
154 | program
|
155 | .command('versions')
|
156 | .description('Get the list of deployed versions')
|
157 | .option('-n, --network <value>', 'The network to run off.', x => x.toLowerCase(), 'mainnet')
|
158 | .option('-b, --by-contract', 'To key off the contract name')
|
159 | .action(async ({ network, byContract }) => {
|
160 | const versions = getVersions({ network, byContract });
|
161 | console.log(JSON.stringify(versions, null, 2));
|
162 | });
|
163 |
|
164 |
|
165 | if (require.main === module) {
|
166 | require('pretty-error').start();
|
167 |
|
168 | program.parse(process.argv);
|
169 | }
|