@nexex/cli
Version:
79 lines • 3.68 kB
JavaScript
;
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const chalk_1 = __importDefault(require("chalk"));
const cli_table3_1 = __importDefault(require("cli-table3"));
const utils_1 = require("ethers/utils");
const Base_1 = require("../../Base");
const constants_1 = require("../../constants");
const WalletBase_1 = __importDefault(require("../../WalletBase"));
class TokenShow extends WalletBase_1.default {
async run() {
const { flags } = this.parse(TokenShow);
const walletAddr = this.readWalletAddr();
if (!walletAddr) {
console.log(chalk_1.default.yellow('Wallet Not Set'));
this.exit(1);
}
await this.initApi();
const { config: { tokens = [] } } = await this.readConfig();
const queryTokens = await this.tokenToAddr(['WETH', ...tokens]);
const [ethBalance, [wethBalance, ...tokenBalances]] = [
await this.ethBalance(walletAddr),
await Promise.all(queryTokens.map(tokenAddr => this.dex.token.balanceOf(tokenAddr, walletAddr).catch(() => 'Error')))
];
const [wethAllowrance, ...tokenAllowrances] = await Promise.all(queryTokens.map(tokenAddr => this.dex.token.allowanceForGateway(tokenAddr, walletAddr).catch(() => 'Error')));
const table = new cli_table3_1.default({
head: ['Token', 'Balance', 'Unit', 'ApproveStatus']
});
table.push(['ETH', utils_1.commify(utils_1.formatEther(ethBalance)), 'Ether', '']);
table.push([
'WETH',
wethBalance === 'Error' ? 'Error' : utils_1.commify(utils_1.formatEther(wethBalance)),
'Ether',
wethAllowrance === 'Error' ? 'Error' : wethAllowrance.gt(constants_1.TOKEN_ALLOWANCE_THRESHOLD)
]);
tokenBalances.forEach((tokenBalance, idx) => {
table.push([
tokens[idx],
tokenBalance === 'Error' ? 'Error' : utils_1.commify(utils_1.formatEther(tokenBalance)),
'Ether',
tokenAllowrances[idx] === 'Error'
? 'Error'
: tokenAllowrances[idx].gt(constants_1.TOKEN_ALLOWANCE_THRESHOLD)
]);
});
console.log(table.toString());
}
async ethBalance(addr) {
return this.dex.eth.getBalance(addr);
}
}
TokenShow.description = 'describe the command here';
TokenShow.examples = [
`$ nexex-cli hello
hello world from ./src/hello.ts!
`
];
TokenShow.flags = {
...WalletBase_1.default.flags
};
__decorate([
Base_1.initDir,
__metadata("design:type", Function),
__metadata("design:paramtypes", []),
__metadata("design:returntype", Promise)
], TokenShow.prototype, "run", null);
exports.default = TokenShow;
//# sourceMappingURL=show.js.map