UNPKG

@znode/erc20-tokens

Version:
41 lines (40 loc) 1.31 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getByAddress = exports.getBySymbol = exports.get = void 0; const _1 = require("."); const constants_1 = require("./constants"); const utils_1 = require("./utils"); /** * Get token by symbol or address * * @param symbolOrAddress token symbol or address * @returns Token */ function get(symbolOrAddress) { // Wrapped tokens ETH/BTC if (constants_1.WRAPPED_TOKENS.includes(symbolOrAddress)) { return getBySymbol(`W${symbolOrAddress}`); } // maybe address if (symbolOrAddress.length === constants_1.TOKEN_ADDRESS_STANDARD_LENGTH) { return getByAddress(symbolOrAddress.toLowerCase()); } // without 0x if (symbolOrAddress.length === _1.TOKEN_ADDRESS_WITHOUT_0x_LENGTH) { return getByAddress('0x' + symbolOrAddress.toLowerCase()); } // maybe symbol return getBySymbol(symbolOrAddress); } exports.get = get; function getBySymbol(symbol) { const indexes = utils_1.getIndexSymbols(); const _symbol = symbol.toUpperCase(); return indexes[_symbol] || null; } exports.getBySymbol = getBySymbol; function getByAddress(address) { const indexes = utils_1.getIndexAddresses(); return indexes[address] || null; } exports.getByAddress = getByAddress;