forked from fvictorio/synthetix
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbin.js
executable file
·178 lines (157 loc) · 5.66 KB
/
bin.js
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
#!/usr/bin/env node
'use strict';
const fs = require('fs');
const path = require('path');
const util = require('util');
const { getSuspensionReasons, networks, toBytes32, wrap } = require('./index');
const {
decode,
getAST,
getSource,
getSynths,
getFeeds,
getTarget,
getTokens,
getUsers,
getVersions,
getStakingRewards,
} = wrap({
fs,
path,
});
const commander = require('commander');
const program = new commander.Command();
program
.command('ast <source>')
.description('Get the AST for some source file')
.action(async source => {
console.log(JSON.stringify(getAST({ source, match: /./ }), null, 2));
});
program
.command('bytes32 <key>')
.description('Bytes32 representation of a currency key')
.option('-c, --skip-check', 'Skip the check')
.action(async (key, { skipCheck }) => {
if (
!skipCheck &&
getSynths({ network: 'mainnet' }).filter(({ name }) => name === key).length < 1
) {
throw Error(
`Given key of "${key}" does not exist as a synth in mainnet (case-sensitive). Use --skip-check to skip this check.`
);
}
console.log(toBytes32(key));
});
program
.command('decode <data> [target]')
.description('Decode a data payload from a Synthetix contract')
.option('-n, --network <value>', 'The network to use', x => x.toLowerCase(), 'mainnet')
.option('-z, --use-ovm', 'Target deployment for the OVM (Optimism).')
.action(async (data, target, { network, useOvm }) => {
console.log(util.inspect(decode({ network, data, target, useOvm }), false, null, true));
});
program
.command('networks')
.description('Get networks')
.action(async () => {
console.log(networks);
});
program
.command('rewards')
.description('Get staking rewards for an environment')
.option('-n, --network <value>', 'The network to run off.', x => x.toLowerCase(), 'mainnet')
.option('-z, --use-ovm', 'Target deployment for the OVM (Optimism).')
.action(async ({ network, useOvm }) => {
console.log(JSON.stringify(getStakingRewards({ network, useOvm }), null, 2));
});
program
.command('source')
.description('Get source files for an environment')
.option('-n, --network <value>', 'The network to run off.', x => x.toLowerCase(), 'mainnet')
.option('-c, --contract [value]', 'The name of the contract')
.option('-k, --key [value]', 'A specific key wanted')
.option('-z, --use-ovm', 'Target deployment for the OVM (Optimism).')
.action(async ({ network, useOvm, contract, key }) => {
const source = getSource({ network, useOvm, contract });
console.log(JSON.stringify(key in source ? source[key] : source, null, 2));
});
program
.command('feeds')
.description('Get the price feeds')
.option('-n, --network <value>', 'The network to run off.', x => x.toLowerCase(), 'mainnet')
.option('-z, --use-ovm', 'Target deployment for the OVM (Optimism).')
.action(async ({ network, useOvm }) => {
const feeds = getFeeds({ network, useOvm });
console.log(util.inspect(feeds, false, null, true));
});
program
.command('suspension-reasons')
.description('Get the suspension reason')
.option('-c, --code [value]', 'A specific suspension code')
.action(async ({ code }) => {
const reason = getSuspensionReasons({ code });
console.log(reason);
});
program
.command('synths')
.description('Get the list of synths')
.option('-n, --network <value>', 'The network to run off.', x => x.toLowerCase(), 'mainnet')
.option('-k, --key [value]', 'A specific key wanted')
.option('-z, --use-ovm', 'Target deployment for the OVM (Optimism).')
.action(async ({ network, useOvm, key }) => {
const synthList = getSynths({ network, useOvm });
console.log(
JSON.stringify(
synthList.map(entry => {
return key in entry ? entry[key] : entry;
}),
null,
2
)
);
});
program
.command('target')
.description('Get deployed target files for an environment')
.option('-n, --network <value>', 'The network to run off.', x => x.toLowerCase(), 'mainnet')
.option('-c, --contract [value]', 'The name of the contract')
.option('-k, --key [value]', 'A specific key wanted')
.option('-z, --use-ovm', 'Target deployment for the OVM (Optimism).')
.action(async ({ network, useOvm, contract, key }) => {
const target = getTarget({ network, useOvm, contract });
console.log(JSON.stringify(key in target ? target[key] : target, null, 2));
});
program
.command('tokens')
.description('Get the list of ERC20 tokens in Synthetix')
.option('-n, --network <value>', 'The network to run off.', x => x.toLowerCase(), 'mainnet')
.option('-z, --use-ovm', 'Target deployment for the OVM (Optimism).')
.action(async ({ network, useOvm }) => {
const tokens = getTokens({ network, useOvm });
console.log(JSON.stringify(tokens, null, 2));
});
program
.command('users')
.description('Get the list of system users')
.option('-n, --network <value>', 'The network to run off.', x => x.toLowerCase(), 'mainnet')
.option('-u, --user [value]', 'A specific user wanted')
.option('-z, --use-ovm', 'Target deployment for the OVM (Optimism).')
.action(async ({ network, useOvm, user }) => {
const users = getUsers({ network, useOvm, user });
console.log(JSON.stringify(users, null, 2));
});
program
.command('versions')
.description('Get the list of deployed versions')
.option('-n, --network <value>', 'The network to run off.', x => x.toLowerCase(), 'mainnet')
.option('-b, --by-contract', 'To key off the contract name')
.option('-z, --use-ovm', 'Target deployment for the OVM (Optimism).')
.action(async ({ network, useOvm, byContract }) => {
const versions = getVersions({ network, useOvm, byContract });
console.log(JSON.stringify(versions, null, 2));
});
// perform as CLI tool if args given
if (require.main === module) {
require('pretty-error').start();
program.parse(process.argv);
}