UNPKG

@nexex/cli

Version:
64 lines 2.73 kB
"use strict"; 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 utils_1 = require("ethers/utils"); const js_yaml_1 = __importDefault(require("js-yaml")); const Base_1 = require("../../Base"); const WalletBase_1 = __importDefault(require("../../WalletBase")); class TokenAdd extends WalletBase_1.default { async run() { const { flags, args: { token } } = this.parse(TokenAdd); const { config } = await this.readConfig(); const { tokens = [] } = config; if (tokens.length > 5) { console.log(chalk_1.default.yellow('reach max token limit')); this.exit(1); } let tokenToAdd = token; if (token.startsWith('0x')) { this.dex = await this.initApi(); tokenToAdd = utils_1.getAddress(token); const tokenMeta = await this.dex.tokenRegistry.getTokenMetaData(tokenToAdd); if (tokenMeta) { tokenToAdd = tokenMeta.symbol; } } if (tokens.includes(tokenToAdd) || tokenToAdd === 'WETH') { console.log(chalk_1.default.yellow('duplicate token')); this.exit(1); } tokens.push(tokenToAdd); config.tokens = tokens; await this.saveConfig(js_yaml_1.default.dump(config)); } } TokenAdd.description = 'describe the command here'; TokenAdd.examples = [ `$ nexex-cli hello hello world from ./src/hello.ts! ` ]; TokenAdd.flags = { ...WalletBase_1.default.flags }; TokenAdd.args = [{ name: 'token' }]; __decorate([ Base_1.initDir, __metadata("design:type", Function), __metadata("design:paramtypes", []), __metadata("design:returntype", Promise) ], TokenAdd.prototype, "run", null); exports.default = TokenAdd; //# sourceMappingURL=add.js.map