-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathlist.ts
44 lines (40 loc) · 1.25 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
import { Registry } from "@airswap/libraries";
import { protocolNames } from "@airswap/utils";
import { Command } from "@oclif/command";
import chalk from "chalk";
import { getTable } from "console.table";
import { cancelled } from "../../lib/prompt";
import * as utils from "../../lib/utils";
import { getWallet } from "../../lib/wallet";
export default class ProtocolsList extends Command {
public static description = "list activated protocols";
public async run() {
try {
const wallet = await getWallet(this, true);
const chainId = (await wallet.provider.getNetwork()).chainId;
utils.displayDescription(this, ProtocolsList.description, chainId);
this.log(chalk.white(`Registry ${Registry.getAddress(chainId)}\n`));
const registryContract = Registry.getContract(wallet, chainId);
const protocols = await registryContract.getProtocolsForStaker(
wallet.address,
);
const result = [];
protocols.map((id) => {
result.push({
id,
label: protocolNames[id],
});
});
if (result.length) {
this.log(getTable(result));
} else {
this.log(chalk.yellow("No activated protocols"));
this.log(
`Add protocols you support with ${chalk.bold("protocols:add")}\n`,
);
}
} catch (e) {
cancelled(e);
}
}
}