UNPKG

butterjs-sdk

Version:
44 lines (43 loc) 1.59 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Token = void 0; const addressUtil_1 = require("../utils/addressUtil"); const BaseCurrency_1 = require("./BaseCurrency"); /** * Represents a token with a unique address and some metadata. */ class Token extends BaseCurrency_1.BaseCurrency { constructor(chainId, address, decimals, symbol, name, logo) { super(chainId, decimals, address, symbol, name, logo); this.isNative = false; this.isToken = true; this.address = (0, addressUtil_1.validateAndParseAddressByChainId)(address, chainId); } /** * Returns true if the two tokens are equivalent, i.e. have the same chainId and address. * @param other other token to compare */ equals(other) { return (other.isToken && this.chainId === other.chainId && 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 */ // public sortsBefore(other: Token): boolean { // invariant(this.chainId === other.chainId, 'CHAIN_IDS'); // invariant(this.address !== other.address, 'ADDRESSES'); // return this.address.toLowerCase() < other.address.toLowerCase(); // } /** * Return this token, which does not need to be wrapped */ get wrapped() { return this; } } exports.Token = Token;