@nftgo/gorarity
Version:
An algorithm to calculate rarity of NFT(how special it is), based on Jaccard Distance.
29 lines (28 loc) • 1.01 kB
JavaScript
import { TokenStandard } from '../models';
import { JaccardDistanceScoringHandler } from './handlers';
export class Scorer {
handler;
constructor() {
this.handler = new JaccardDistanceScoringHandler();
}
validateCollection(collection) {
const allowedStandards = [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);
}
}