-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathlist.ts
69 lines (59 loc) · 1.69 KB
/
list.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
import { Command } from "@oclif/command";
import chalk from "chalk";
import { getTable } from "console.table";
import { cancelled, get } from "../../lib/prompt";
import * as utils from "../../lib/utils";
import { Registry } from "@airswap/libraries";
import { ProtocolIds } from "@airswap/utils";
export default class RegistryList extends Command {
public static description = "get urls from the registry";
public async run() {
try {
const provider = await utils.getProvider(this);
const chainId = (await provider.getNetwork()).chainId;
const metadata = await utils.getMetadata(this, chainId);
utils.displayDescription(this, RegistryList.description, chainId);
this.log(chalk.white(`Registry ${Registry.getAddress(chainId)}\n`));
const { pair }: any = await get({
pair: {
description: "Token pair (e.g. WETH/USDT)",
type: "Pair",
},
});
const [one, two] = pair.split("/");
const first = metadata.bySymbol[one.toUpperCase()];
const second = metadata.bySymbol[two.toUpperCase()];
if (!first) {
throw new Error(`${one.toUpperCase()} not found in metadata.`);
}
if (!second) {
throw new Error(`${two.toUpperCase()} not found in metadata.`);
}
const urls = await Registry.getServerURLs(
provider,
chainId,
ProtocolIds.RequestForQuoteERC20,
first.address,
second.address,
);
const rows = [];
for (let i = 0; i < urls.length; i++) {
rows.push({
Server: urls[i],
});
}
if (rows.length) {
this.log();
this.log(getTable(rows));
} else {
this.log(
chalk.yellow(
`\nNo servers currently support ${pair.toUpperCase()}.\n`,
),
);
}
} catch (e) {
cancelled(e);
}
}
}