UNPKG

@syncswap/sdk

Version:

SyncSwap TypeScript SDK for building DeFi applications

112 lines 4.66 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.Token = void 0; exports.useTokenIconURI = useTokenIconURI; const tiny_invariant_1 = __importDefault(require("tiny-invariant")); const statestore_1 = require("../statestore/statestore"); const sdkHelper_1 = require("../sdkHelper"); function ensuresTokenName(name) { name = name.toLowerCase(); (0, tiny_invariant_1.default)(!name.includes("onerror=") && !name.includes("javascript:") && !name.includes("data:"), "Illgeal token name"); } /** * Represents an ERC20 token with a unique address and some metadata. */ class Token { constructor(address, decimals, symbol, name, hidden, icon, info, bridgable, imported, metadata, wrapper, baseToken) { const _address = address.toLowerCase(); this.address = _address; this.decimals = decimals; ensuresTokenName(symbol); this.symbol = symbol; ensuresTokenName(name); this.name = name; this.hidden = hidden; this.icon = icon ?? useTokenIconURI(_address); //console.log('token', symbol, icon, this.icon); this.info = info; this.bridgable = bridgable ?? true; this.imported = imported; this.metadata = metadata; this.wrapper = wrapper; this.baseToken = baseToken; } toString() { return this.symbol; } /** * Returns true if the two tokens are equivalent, i.e. have the same chainId and address. * @param other other token to compare */ equals(other) { // short circuit on reference equality if (this === other) { return true; } return this.address === other.address; } /** * Returns true if the address of this token sorts before the address of the other token * @param other other token to compare * @throws if the tokens have the same address * @throws if the tokens are on different chains */ isSorted(other) { (0, tiny_invariant_1.default)(this.address !== other.address, "Found identical addresses"); return this.address.toLowerCase() < other.address.toLowerCase(); } } exports.Token = Token; // Initialize static properties after class definition Token._ETHER = new Token("0x000000000000000000000000000000000000800a", 18, "ETH", "Ethereum", false, undefined, undefined, false, false, { about: "Ethereum is a decentralized blockchain platform that establishes a peer-to-peer network that securely executes and verifies application code, called smart contracts. Ether (ETH) is the native cryptocurrency of the platform and the second-largest cryptocurrency by market capitalization after Bitcoin. ETH is the lifeblood of Ethereum.", links: { website: { name: "ethereum.org", link: "https://ethereum.org/", }, }, }); Token._SOPH = new Token("0x000000000000000000000000000000000000800a", 18, "SOPH", "Sophon", false, useTokenIconURI("soph"), undefined, false, false, { about: "Sophon is a platform built on a validium leveraging ZKsync's Elastic Chain. Sophon's network architecture seamlessly handles high-throughput applications like socialfi and gaming. By weaving crypto rails invisibly into our platform's fabric, we enable users to enjoy on-chain benefits without encountering the typical complexities.", links: { website: { name: "sophon.xyz", link: "https://sophon.xyz/", }, }, }); Token.ETHER = Token._ETHER; function getTokenIconURI(address) { return `https://tokens.syncswap.xyz/tokens/${address}/logo.png`; // vercel for github repo } // `https://raw.githubusercontent.com/syncswap/token-icons/main/tokens/${address}/logo.png`; // TODO This is not really a hook function useTokenIconURI(address) { address = address.toLowerCase(); if (address === "0x5471ea8f739dd37e9b81be9c5c77754d8aa953e4") { // Linea ceAVAX if ((0, statestore_1.stateStore)().network === sdkHelper_1.LINEA_MAINNET) { return getTokenIconURI("avax"); } } if (Token.ETHER && address === Token.ETHER.address) { return Token.ETHER.icon; } /* if ( address === "0xae045de5638162fa134807cb558e15a3f5a7f853" || address === "0x1d17cbcf0d6d143135ae902365d2e5e2a16538d4" ) { // usdc native return getTokenIconURI("usdc"); } */ return getTokenIconURI(address); } //# sourceMappingURL=token.js.map