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 | .option('-z, --use-ovm', 'Target deployment for the OVM (Optimism).')
|
59 | .action(async (data, target, { network, useOvm }) => {
|
60 | console.log(util.inspect(decode({ network, data, target, useOvm }), false, null, true));
|
61 | });
|
62 |
|
63 | program
|
64 | .command('networks')
|
65 | .description('Get networks')
|
66 | .action(async () => {
|
67 | console.log(networks);
|
68 | });
|
69 |
|
70 | program
|
71 | .command('rewards')
|
72 | .description('Get staking rewards for an environment')
|
73 | .option('-n, --network <value>', 'The network to run off.', x => x.toLowerCase(), 'mainnet')
|
74 | .option('-z, --use-ovm', 'Target deployment for the OVM (Optimism).')
|
75 | .action(async ({ network, useOvm }) => {
|
76 | console.log(JSON.stringify(getStakingRewards({ network, useOvm }), null, 2));
|
77 | });
|
78 |
|
79 | program
|
80 | .command('source')
|
81 | .description('Get source files for an environment')
|
82 | .option('-n, --network <value>', 'The network to run off.', x => x.toLowerCase(), 'mainnet')
|
83 | .option('-c, --contract [value]', 'The name of the contract')
|
84 | .option('-k, --key [value]', 'A specific key wanted')
|
85 | .option('-z, --use-ovm', 'Target deployment for the OVM (Optimism).')
|
86 | .action(async ({ network, useOvm, contract, key }) => {
|
87 | const source = getSource({ network, useOvm, contract });
|
88 | console.log(JSON.stringify(key in source ? source[key] : source, null, 2));
|
89 | });
|
90 |
|
91 | program
|
92 | .command('feeds')
|
93 | .description('Get the price feeds')
|
94 | .option('-n, --network <value>', 'The network to run off.', x => x.toLowerCase(), 'mainnet')
|
95 | .option('-z, --use-ovm', 'Target deployment for the OVM (Optimism).')
|
96 | .action(async ({ network, useOvm }) => {
|
97 | const feeds = getFeeds({ network, useOvm });
|
98 | console.log(util.inspect(feeds, false, null, true));
|
99 | });
|
100 |
|
101 | program
|
102 | .command('suspension-reasons')
|
103 | .description('Get the suspension reason')
|
104 | .option('-c, --code [value]', 'A specific suspension code')
|
105 | .action(async ({ code }) => {
|
106 | const reason = getSuspensionReasons({ code });
|
107 | console.log(reason);
|
108 | });
|
109 |
|
110 | program
|
111 | .command('synths')
|
112 | .description('Get the list of synths')
|
113 | .option('-n, --network <value>', 'The network to run off.', x => x.toLowerCase(), 'mainnet')
|
114 | .option('-k, --key [value]', 'A specific key wanted')
|
115 | .option('-z, --use-ovm', 'Target deployment for the OVM (Optimism).')
|
116 | .action(async ({ network, useOvm, key }) => {
|
117 | const synthList = getSynths({ network, useOvm });
|
118 | console.log(
|
119 | JSON.stringify(
|
120 | synthList.map(entry => {
|
121 | return key in entry ? entry[key] : entry;
|
122 | }),
|
123 | null,
|
124 | 2
|
125 | )
|
126 | );
|
127 | });
|
128 |
|
129 | program
|
130 | .command('target')
|
131 | .description('Get deployed target files for an environment')
|
132 | .option('-n, --network <value>', 'The network to run off.', x => x.toLowerCase(), 'mainnet')
|
133 | .option('-c, --contract [value]', 'The name of the contract')
|
134 | .option('-k, --key [value]', 'A specific key wanted')
|
135 | .option('-z, --use-ovm', 'Target deployment for the OVM (Optimism).')
|
136 | .action(async ({ network, useOvm, contract, key }) => {
|
137 | const target = getTarget({ network, useOvm, contract });
|
138 | console.log(JSON.stringify(key in target ? target[key] : target, null, 2));
|
139 | });
|
140 |
|
141 | program
|
142 | .command('tokens')
|
143 | .description('Get the list of ERC20 tokens in Synthetix')
|
144 | .option('-n, --network <value>', 'The network to run off.', x => x.toLowerCase(), 'mainnet')
|
145 | .option('-z, --use-ovm', 'Target deployment for the OVM (Optimism).')
|
146 | .action(async ({ network, useOvm }) => {
|
147 | const tokens = getTokens({ network, useOvm });
|
148 | console.log(JSON.stringify(tokens, null, 2));
|
149 | });
|
150 |
|
151 | program
|
152 | .command('users')
|
153 | .description('Get the list of system users')
|
154 | .option('-n, --network <value>', 'The network to run off.', x => x.toLowerCase(), 'mainnet')
|
155 | .option('-u, --user [value]', 'A specific user wanted')
|
156 | .option('-z, --use-ovm', 'Target deployment for the OVM (Optimism).')
|
157 | .action(async ({ network, useOvm, user }) => {
|
158 | const users = getUsers({ network, useOvm, user });
|
159 | console.log(JSON.stringify(users, null, 2));
|
160 | });
|
161 |
|
162 | program
|
163 | .command('versions')
|
164 | .description('Get the list of deployed versions')
|
165 | .option('-n, --network <value>', 'The network to run off.', x => x.toLowerCase(), 'mainnet')
|
166 | .option('-b, --by-contract', 'To key off the contract name')
|
167 | .option('-z, --use-ovm', 'Target deployment for the OVM (Optimism).')
|
168 | .action(async ({ network, useOvm, byContract }) => {
|
169 | const versions = getVersions({ network, useOvm, byContract });
|
170 | console.log(JSON.stringify(versions, null, 2));
|
171 | });
|
172 |
|
173 |
|
174 | if (require.main === module) {
|
175 | require('pretty-error').start();
|
176 |
|
177 | program.parse(process.argv);
|
178 | }
|