-
Notifications
You must be signed in to change notification settings - Fork 0
/
bin.js
executable file
·181 lines (160 loc) · 5.24 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
179
180
181
#!/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 dPassive contract')
.option('-n, --network <value>', 'The network to use', x => x.toLowerCase(), 'mainnet')
.action(async (data, target, { network }) => {
console.log(util.inspect(decode({ network, data, target }), 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')
.action(async ({ network }) => {
console.log(JSON.stringify(getStakingRewards({ network }), 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')
.action(async ({ network, contract, key }) => {
const source = getSource({ network, 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')
.action(async ({ network }) => {
const feeds = getFeeds({ network });
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')
.action(async ({ network, key }) => {
const synthList = getSynths({ network });
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 (ignored when using csv)')
.option('-v, --csv', 'Whether or not to CSV output the results')
.action(async ({ network, contract, key, csv }) => {
const target = getTarget({ network, contract });
if (csv) {
let headerComplete;
for (const entry of Object.values(target)) {
if (!headerComplete) {
console.log(Object.keys(entry).join(','));
headerComplete = true;
}
console.log(Object.values(entry).join(','));
}
} else {
console.log(JSON.stringify(key in target ? target[key] : target, null, 2));
}
});
program
.command('tokens')
.description('Get the list of ERC20 tokens in dPassive')
.option('-n, --network <value>', 'The network to run off.', x => x.toLowerCase(), 'mainnet')
.action(async ({ network }) => {
const tokens = getTokens({ network });
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')
.action(async ({ network, user }) => {
const users = getUsers({ network, 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')
.action(async ({ network, byContract }) => {
const versions = getVersions({ network, 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);
}