/
index.ts
207 lines (204 loc) · 4.79 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
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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
/* eslint-disable @typescript-eslint/ban-ts-comment */
import yargs from 'yargs';
import {
rebagHandler,
electionScoreHandler,
playgroundHandler,
reapStashHandler,
nominatorThreshHandler,
chillOtherHandler,
stateTrieMigrationHandler,
stakingStatsHandler,
inFrontHandler
} from './handlers';
// Export all of the services so this codebase can be used as a library as well.
export * from './services';
/**
* Sample use of checking bags list but not sending a tx:
* ```
* ts-node ./src/index.ts bags -w wss://kusama-rpc.polkadot.io
* ```
*/
async function main() {
await yargs
.options({
// global options that apply to each command
ws: {
alias: 'w',
description: 'the wss endpoint. It must allow unsafe RPCs.',
default: 'wss://rpc.polkadot.io',
string: true,
demandOption: false,
global: true
},
seed: {
alias: 's',
type: 'string',
description:
'path to a raw text file that contains your raw or mnemonic seed, or its content. Can also be provided using SEED env variable',
required: false,
global: true
}
})
.command(
['in-front'],
'find an account the target account can be put in front of',
// @ts-ignore
(yargs) => {
return yargs.options({
target: {
alias: 't',
description: 'The target account to be checked',
demandOption: true
}
});
},
inFrontHandler
)
.command(
['rebag'],
'check the bags list for rebag operations',
// @ts-ignore
(yargs) => {
return yargs.options({
sendTx: {
alias: 'T',
description: 'Whether or not to send a rebag tx.',
boolean: true,
demandOption: false,
default: false
},
target: {
alias: 't',
description:
'Who to target. Accepted values are "all", a number, or a specific "ss58" account id',
demandOption: false,
default: 'all'
}
});
},
rebagHandler
)
.command(
['chill-other'],
'check and try to submit the chill-other transaction to reduce staking nominators',
// @ts-ignore
(yargs) => {
return yargs.options({
sendTx: {
alias: 'T',
description: 'Whether or not to send a chill other tx.',
boolean: true,
demandOption: false,
default: false
},
count: {
alias: 'c',
description: 'Max amount of stakers to chill.',
number: true,
demandOption: false,
default: -1
},
noDryRun: {
boolean: true,
description:
'do not dry-run the command first. Advised not to set. Only set if you do not have access to local node with this RPC'
}
});
},
chillOtherHandler
)
.command(
['noms-thresh'],
'Get number of stashes below threshold (needs improvement)',
{},
// @ts-ignore
nominatorThreshHandler
)
// @ts-ignore
.command(
['staking-stats'],
'Basic statistics of the staking limits',
// @ts-ignore
(yargs) => {
return yargs.options({
at: {
description: 'Block number at which to run the analysis',
demandOption: false,
default: false,
string: true
}
});
},
stakingStatsHandler
)
.command(
['election-score'],
'Get stats on recent election scores',
{},
// @ts-ignore
electionScoreHandler
)
// @ts-ignore
.command(
['reap-stash'],
'examine how many accounts can go through a reap-stash',
(yargs) => {
return yargs.options({
sendTx: {
alias: 'T',
description: 'Whether or not to send a rebag tx.',
boolean: true,
demandOption: false,
default: false
},
count: {
alias: 'c',
description:
'How many rebag transactions to send. Iteration will stop if provided. All bags are iterated if otherwise.',
number: true,
demandOption: false,
default: -1
}
});
},
reapStashHandler
)
// @ts-ignore
.command(
['state-trie-migration'],
'Try and submit transactions to migrate the state trie version. See https://github.com/paritytech/substrate/pull/10073. This can only work against a node that supports dry-run RPC.',
(yargs) => {
return yargs.options({
count: {
description: 'Total number of transactions to send. Unlimited if not set.',
number: true,
demandOption: false
},
'item-limit': {
description: 'Number of items to try and migrate in each round',
number: true,
demandOption: true
},
'size-limit': {
description: 'size of items to try and migrate in each round',
number: true,
demandOption: true
}
});
},
stateTrieMigrationHandler
)
// @ts-ignore
.command(['playground'], 'random stuff', {}, playgroundHandler)
.parse();
}
main()
.then(() => {
console.info('Exiting ...');
process.exit(0);
})
.catch((err) => {
console.error(err);
process.exit(1);
});