UNPKG

@angleprotocol/sdk

Version:
40 lines 1.72 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; const tiny_invariant_1 = __importDefault(require("tiny-invariant")); const utils_1 = require("./utils"); class Token { constructor(chainId, address, decimals, symbol, name, isAgToken = false) { (0, tiny_invariant_1.default)(decimals >= 0 && decimals < 255 && Number.isInteger(decimals), 'DECIMALS'); (0, tiny_invariant_1.default)(Number.isSafeInteger(chainId), 'CHAIN_ID'); this.chainId = chainId; this.address = symbol === 'ETH' && name === 'Ether' ? address : (0, utils_1.validateAndParseAddress)(address); this.decimals = decimals; this.symbol = symbol; this.name = name; this.isAgToken = isAgToken; } static ether(chainId) { return new Token(chainId || 0, '', 18, 'ETH', 'Ether', false); } eq(other) { if (this === other) { return true; } const equivalent = this.chainId === other.chainId && this.address === other.address; if (equivalent) { (0, tiny_invariant_1.default)(this.decimals === other.decimals, 'DECIMALS'); (0, tiny_invariant_1.default)(this.symbol === other.symbol, 'SYMBOL'); if (this.name && other.name) { (0, tiny_invariant_1.default)(this.name === other.name, 'NAME'); } (0, tiny_invariant_1.default)(this.isAgToken === other.isAgToken, 'AGTOKEN'); } return equivalent; } } exports.Token = Token; //# sourceMappingURL=token.js.map