UNPKG

@nftgo/gorarity

Version:

An algorithm to calculate rarity of NFT(how special it is), based on Jaccard Distance.

32 lines (31 loc) 1.12 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Scorer = void 0; const models_1 = require("../models"); const handlers_1 = require("./handlers"); class Scorer { constructor() { this.handler = new handlers_1.JaccardDistanceScoringHandler(); } validateCollection(collection) { const allowedStandards = [models_1.TokenStandard.ERC721]; if (!collection.tokenStandards().every((val) => allowedStandards.includes(val))) { throw new Error(`GoRarity currently only supports ERC721 standards`); } } /** * @description Calculate the score of each token. * @param collection * @param tokens * @returns The scores of each token, which has the same order with tokens. */ scoreTokens(collection, tokens) { this.validateCollection(collection); return this.handler.scoreTokens(collection, tokens); } scoreCollection(collection) { this.validateCollection(collection); return this.handler.scoreTokens(collection, collection.tokens); } } exports.Scorer = Scorer;