@nexex/cli
Version:
37 lines • 1.39 kB
JavaScript
;
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"));
class Token {
constructor(symbol, addr, decimals) {
this.symbol = symbol;
this.addr = addr;
this.decimals = decimals;
}
static async create(tokenSymbolOrAddr, dex) {
if (tokenSymbolOrAddr.startsWith('0x')) {
const addr = tokenSymbolOrAddr;
const token = (await dex.tokenRegistry.getTokenMetaData(addr)) || {};
return new Token(token.symbol, addr, token.decimals);
}
else {
const token = await dex.tokenRegistry.getTokenBySymbol(tokenSymbolOrAddr.toUpperCase());
if (!token) {
throw new Error(`${tokenSymbolOrAddr} not registered`);
}
return new Token(token.symbol, token.addr, token.decimals);
}
}
toString(showAddr = false) {
if (showAddr) {
return this.symbol ? `${this.symbol}(${chalk_1.default.yellow(this.addr)})` : `${chalk_1.default.yellow(this.addr)}`;
}
else {
return this.symbol ? `${this.symbol}` : `${this.addr}`;
}
}
}
exports.Token = Token;
//# sourceMappingURL=Token.js.map