-
Notifications
You must be signed in to change notification settings - Fork 12
/
status.ts
98 lines (91 loc) · 2.92 KB
/
status.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
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 { ethers } from "ethers";
import { cancelled } from "../../lib/prompt";
import * as utils from "../../lib/utils";
import { getWallet } from "../../lib/wallet";
const IERC20 = require("@airswap/utils/build/src/abis/ERC20.json");
export default class RegistryStatus extends Command {
public static description =
"check status of url, protocols, and tokens on registry";
public async run() {
try {
const wallet = await getWallet(this, true);
const chainId = (await wallet.provider.getNetwork()).chainId;
const metadata = await utils.getMetadata(this, chainId);
utils.displayDescription(this, RegistryStatus.description, chainId);
this.log(chalk.white(`Registry ${Registry.getAddress(chainId)}\n`));
const registryContract = Registry.getContract(wallet, chainId);
const stakingTokenContract = new ethers.Contract(
await registryContract.stakingToken(),
IERC20.abi,
wallet,
);
const allowance = await stakingTokenContract.allowance(
wallet.address,
Registry.getAddress(chainId),
);
if (allowance.gt(0)) {
this.log("✅ Registry is approved for staking\n");
} else {
this.log(chalk.yellow("Registry is not approved"));
this.log(
`Enable usage of the registry with ${chalk.bold(
"registry:approve",
)}\n`,
);
}
const url = (
await registryContract.getServerURLsForStakers([wallet.address])
)[0];
if (!url) {
this.log(chalk.yellow("Server URL is not set"));
this.log(`Set your server URL with ${chalk.bold("registry:url")}\n`);
} else {
this.log(chalk.white(`${chalk.bold("Server URL")}: ${url}\n`));
}
const activatedProtocols = await registryContract.getProtocolsForStaker(
wallet.address,
);
if (activatedProtocols.length) {
this.log(`${chalk.bold("Protocols")} activated:\n`);
const result = [];
activatedProtocols.map((id) => {
result.push({
id,
label: protocolNames[id],
});
});
this.log(getTable(result));
} else {
this.log(chalk.yellow("No activated protocols"));
this.log(
`Add protocols you support with ${chalk.bold("protocols:add")}\n`,
);
}
const supportedTokens = await registryContract.getTokensForStaker(
wallet.address,
);
if (supportedTokens.length) {
this.log(`${chalk.bold("Tokens")} activated:\n`);
const result = [];
supportedTokens.map((address) => {
const token = metadata.byAddress[address.toLowerCase()];
result.push({
symbol: token.symbol,
address: token.address,
});
});
this.log(getTable(result));
} else {
this.log(chalk.yellow("No activated tokens"));
this.log(`Add tokens you support with ${chalk.bold("tokens:add")}\n`);
}
} catch (e) {
cancelled(e);
}
}
}