-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcommandLine.js
More file actions
173 lines (164 loc) · 4.76 KB
/
Copy pathcommandLine.js
File metadata and controls
173 lines (164 loc) · 4.76 KB
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
import commandLineUsage from "command-line-usage";
import commandLineArgs from "command-line-args";
import * as readline from "node:readline/promises";
const commandList = [
{
name: "command",
type: String,
defaultOption: true,
defaultValue: "imp",
description:
"The command to run:\n" +
"swaps\tShow liquidity swaps.\n" +
"imp\tShow estimated impermanent loss.\n" +
"xch\tShow the estimated XCH value of current liquidity.\n" +
"names\tSet wallet names from the tibet list.\n" +
"balances\tShow the balance of CAT wallets\n" +
"move\tSend the balance of tibet verified CAT wallets to a single address\n",
},
];
const optionsList = [
{
name: "token",
alias: "n",
type: String,
defaultValue: undefined,
typeLabel: "(token symbol)",
description: "Limit the output to this token.",
},
{
name: "verbose",
alias: "v",
type: Boolean,
defaultValue: false,
description: "Show verbose details.",
},
{
name: "no-prompt",
type: Boolean,
defaultValue: false,
description: "Suppress prompts.",
},
{
name: "include-pair-tokens",
type: Boolean,
defaultValue: false,
description: "Include tibet pair tokens when showing balances.",
},
{
name: "host",
alias: "d",
type: String,
defaultValue: "localhost",
description: "The chia daemon host. (localhost)",
},
{
name: "port",
alias: "p",
type: Number,
defaultValue: 55400,
description: "The chia daemon port. (55400)",
},
{
name: "key_path",
alias: "k",
type: String,
defaultValue: "~/.chia/mainnet/config/ssl/daemon/private_daemon.key",
description: "The path to the daemon private key.",
},
{
name: "cert_path",
alias: "c",
type: String,
defaultValue: "~/.chia/mainnet/config/ssl/daemon/private_daemon.crt",
description: "The path to the daemon certificate.",
},
{
name: "wallet_fingerprints",
multiple: true,
alias: "f",
type: Number,
description: "Optional list of wallet fingerprints.",
},
{
name: "wallet_address",
alias: "w",
type: String,
description: "A wallet address to send CATs to.",
},
{
name: "tibet_api_uri",
alias: "a",
type: String,
defaultValue: "https://api.v2.tibetswap.io",
description: "The uri of the tibet api",
},
{
name: "tibet_analytics_api_uri",
alias: "i",
type: String,
defaultValue: "https://api.info.v2.tibetswap.io",
description: "The uri of the tibet analytics api",
},
{
name: "mintgarden_api_uri",
alias: "m",
type: String,
defaultValue: "https://api.mintgarden.io/",
description: "The uri of the mint garden api",
},
{
name: "timeout_seconds",
alias: "t",
type: Number,
defaultValue: 30,
description: "The timeout for the wallet connection.",
},
{
name: "json",
alias: "j",
type: Boolean,
description: "Return results as json.",
},
{
name: "help",
alias: "h",
type: Boolean,
description: "Display this usage guide.",
},
];
export const options = commandLineArgs(commandList.concat(optionsList));
export function showHelp() {
const usage = commandLineUsage([
{
header: "chia swap-utils",
content:
"Shows summarized swaps and estimated impermanent loss for the given wallet fingerprints. The wallet must be running and unlocked.",
},
{
header: "Commands",
optionList: commandList,
},
{
header: "Options (defaults to Tibet production and localhost chia)",
optionList: optionsList,
},
{
content:
"Project home: {underline https://github.com/dkackman/swap-utils}",
},
]);
console.log(usage);
}
export async function askUserToProceed(options, question) {
if (options["no-prompt"]) {
return true;
}
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
});
const answer = await rl.question(question);
rl.close();
return answer.toLowerCase() === "yes" || answer.toLowerCase() === "y";
}