UNPKG

@dahlia-labs/token-utils

Version:

Token-related math and transaction utilities.

76 lines 1.72 kB
import { chainIdToNetwork, Mainnet } from "@dahlia-labs/celo-contrib"; /** * Token information. */ export class Token { constructor(info) { var _a; this.info = info; this.network = (_a = chainIdToNetwork(info.chainId)) !== null && _a !== void 0 ? _a : Mainnet; } /** * The Base58 string representation of the mint address. */ get address() { return this.info.address; } /** * The chain ID of the token. */ get chainId() { return this.info.chainId; } /** * Number of decimals of the token. */ get decimals() { return this.info.decimals; } /** * The name of the token. */ get name() { return this.info.name; } /** * The symbol of the token. */ get symbol() { return this.info.symbol; } /** * The token's icon to render. */ get icon() { return this.info.logoURI; } equals(other) { return tokensEqual(this, other); } toString() { return `Token[address=${this.address}, decimals=${this.decimals}, chainId=${this.chainId}]`; } toJSON() { return this.info; } /** * Returns true if the given tag is present. * @param tag The tag to check. * @returns */ hasTag(tag) { var _a; return !!((_a = this.info.tags) === null || _a === void 0 ? void 0 : _a.includes(tag)); } } /** * Checks if two tokens are equal. * @param a * @param b * @returns */ export const tokensEqual = (a, b) => a !== undefined && b !== undefined && a.address === b.address && a.network === b.network; //# sourceMappingURL=token.js.map