@xyo-network/crypto-nft-collection-diviner-score-plugin 2.85.0 → 2.85.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/browser/Plugin.d.cts +0 -2
- package/dist/browser/Plugin.d.cts.map +1 -1
- package/dist/browser/Plugin.d.mts +0 -2
- package/dist/browser/Plugin.d.mts.map +1 -1
- package/dist/browser/Plugin.d.ts +0 -2
- package/dist/browser/Plugin.d.ts.map +1 -1
- package/dist/browser/index.cjs +6 -11
- package/dist/browser/index.cjs.map +1 -1
- package/dist/browser/index.d.cts +1 -3
- package/dist/browser/index.d.cts.map +1 -1
- package/dist/browser/index.d.mts +1 -3
- package/dist/browser/index.d.mts.map +1 -1
- package/dist/browser/index.d.ts +1 -3
- package/dist/browser/index.d.ts.map +1 -1
- package/dist/browser/index.js +6 -11
- package/dist/browser/index.js.map +1 -1
- package/dist/browser/lib/rating/criteria/scoring/metadata/scoreIndividualAttributes.d.cts.map +1 -1
- package/dist/browser/lib/rating/criteria/scoring/metadata/scoreIndividualAttributes.d.mts.map +1 -1
- package/dist/browser/lib/rating/criteria/scoring/metadata/scoreIndividualAttributes.d.ts.map +1 -1
- package/dist/node/Plugin.d.cts +0 -2
- package/dist/node/Plugin.d.cts.map +1 -1
- package/dist/node/Plugin.d.mts +0 -2
- package/dist/node/Plugin.d.mts.map +1 -1
- package/dist/node/Plugin.d.ts +0 -2
- package/dist/node/Plugin.d.ts.map +1 -1
- package/dist/node/index.cjs +6 -11
- package/dist/node/index.cjs.map +1 -1
- package/dist/node/index.d.cts +1 -3
- package/dist/node/index.d.cts.map +1 -1
- package/dist/node/index.d.mts +1 -3
- package/dist/node/index.d.mts.map +1 -1
- package/dist/node/index.d.ts +1 -3
- package/dist/node/index.d.ts.map +1 -1
- package/dist/node/index.js +6 -11
- package/dist/node/index.js.map +1 -1
- package/dist/node/lib/rating/criteria/scoring/metadata/scoreIndividualAttributes.d.cts.map +1 -1
- package/dist/node/lib/rating/criteria/scoring/metadata/scoreIndividualAttributes.d.mts.map +1 -1
- package/dist/node/lib/rating/criteria/scoring/metadata/scoreIndividualAttributes.d.ts.map +1 -1
- package/package.json +13 -13
- package/src/index.ts +1 -7
- package/src/lib/rating/criteria/scoring/metadata/scoreIndividualAttributes.ts +6 -7
- package/src/lib/rating/criteria/scoring/total.ts +1 -1
|
@@ -2,7 +2,6 @@ import { NftCollectionScoreDiviner } from './Diviner';
|
|
|
2
2
|
export declare const NftCollectionScoreDivinerPlugin: () => import("@xyo-network/payloadset-plugin").PayloadSetDivinerPlugin<NftCollectionScoreDiviner<import("@xyo-network/object").BaseParamsFields & {
|
|
3
3
|
account?: import("@xyo-network/account-model").AccountInstance | "random" | undefined;
|
|
4
4
|
config: import("@xyo-network/payload-model").SchemaFields & object & Omit<{
|
|
5
|
-
accountPath?: string | undefined;
|
|
6
5
|
readonly archivist?: string | undefined;
|
|
7
6
|
readonly labels?: import("@xyo-network/module-model").Labels | undefined;
|
|
8
7
|
readonly name?: string | undefined;
|
|
@@ -19,7 +18,6 @@ export declare const NftCollectionScoreDivinerPlugin: () => import("@xyo-network
|
|
|
19
18
|
readonly storeQueries?: boolean | undefined;
|
|
20
19
|
readonly timestamp?: boolean | undefined;
|
|
21
20
|
} & import("@xyo-network/module-model").ArchivingModuleConfig & import("@xyo-network/payload-model").SchemaFields & object & {
|
|
22
|
-
accountPath?: string | undefined;
|
|
23
21
|
readonly archivist?: string | undefined;
|
|
24
22
|
readonly labels?: import("@xyo-network/module-model").Labels | undefined;
|
|
25
23
|
readonly name?: string | undefined;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Plugin.d.ts","sourceRoot":"","sources":["../../src/Plugin.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,yBAAyB,EAAE,MAAM,WAAW,CAAA;AAErD,eAAO,MAAM,+BAA+B
|
|
1
|
+
{"version":3,"file":"Plugin.d.ts","sourceRoot":"","sources":["../../src/Plugin.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,yBAAyB,EAAE,MAAM,WAAW,CAAA;AAErD,eAAO,MAAM,+BAA+B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GASzC,CAAA"}
|
|
@@ -2,7 +2,6 @@ import { NftCollectionScoreDiviner } from './Diviner';
|
|
|
2
2
|
export declare const NftCollectionScoreDivinerPlugin: () => import("@xyo-network/payloadset-plugin").PayloadSetDivinerPlugin<NftCollectionScoreDiviner<import("@xyo-network/object").BaseParamsFields & {
|
|
3
3
|
account?: import("@xyo-network/account-model").AccountInstance | "random" | undefined;
|
|
4
4
|
config: import("@xyo-network/payload-model").SchemaFields & object & Omit<{
|
|
5
|
-
accountPath?: string | undefined;
|
|
6
5
|
readonly archivist?: string | undefined;
|
|
7
6
|
readonly labels?: import("@xyo-network/module-model").Labels | undefined;
|
|
8
7
|
readonly name?: string | undefined;
|
|
@@ -19,7 +18,6 @@ export declare const NftCollectionScoreDivinerPlugin: () => import("@xyo-network
|
|
|
19
18
|
readonly storeQueries?: boolean | undefined;
|
|
20
19
|
readonly timestamp?: boolean | undefined;
|
|
21
20
|
} & import("@xyo-network/module-model").ArchivingModuleConfig & import("@xyo-network/payload-model").SchemaFields & object & {
|
|
22
|
-
accountPath?: string | undefined;
|
|
23
21
|
readonly archivist?: string | undefined;
|
|
24
22
|
readonly labels?: import("@xyo-network/module-model").Labels | undefined;
|
|
25
23
|
readonly name?: string | undefined;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Plugin.d.ts","sourceRoot":"","sources":["../../src/Plugin.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,yBAAyB,EAAE,MAAM,WAAW,CAAA;AAErD,eAAO,MAAM,+BAA+B
|
|
1
|
+
{"version":3,"file":"Plugin.d.ts","sourceRoot":"","sources":["../../src/Plugin.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,yBAAyB,EAAE,MAAM,WAAW,CAAA;AAErD,eAAO,MAAM,+BAA+B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GASzC,CAAA"}
|
package/dist/browser/Plugin.d.ts
CHANGED
|
@@ -2,7 +2,6 @@ import { NftCollectionScoreDiviner } from './Diviner';
|
|
|
2
2
|
export declare const NftCollectionScoreDivinerPlugin: () => import("@xyo-network/payloadset-plugin").PayloadSetDivinerPlugin<NftCollectionScoreDiviner<import("@xyo-network/object").BaseParamsFields & {
|
|
3
3
|
account?: import("@xyo-network/account-model").AccountInstance | "random" | undefined;
|
|
4
4
|
config: import("@xyo-network/payload-model").SchemaFields & object & Omit<{
|
|
5
|
-
accountPath?: string | undefined;
|
|
6
5
|
readonly archivist?: string | undefined;
|
|
7
6
|
readonly labels?: import("@xyo-network/module-model").Labels | undefined;
|
|
8
7
|
readonly name?: string | undefined;
|
|
@@ -19,7 +18,6 @@ export declare const NftCollectionScoreDivinerPlugin: () => import("@xyo-network
|
|
|
19
18
|
readonly storeQueries?: boolean | undefined;
|
|
20
19
|
readonly timestamp?: boolean | undefined;
|
|
21
20
|
} & import("@xyo-network/module-model").ArchivingModuleConfig & import("@xyo-network/payload-model").SchemaFields & object & {
|
|
22
|
-
accountPath?: string | undefined;
|
|
23
21
|
readonly archivist?: string | undefined;
|
|
24
22
|
readonly labels?: import("@xyo-network/module-model").Labels | undefined;
|
|
25
23
|
readonly name?: string | undefined;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Plugin.d.ts","sourceRoot":"","sources":["../../src/Plugin.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,yBAAyB,EAAE,MAAM,WAAW,CAAA;AAErD,eAAO,MAAM,+BAA+B
|
|
1
|
+
{"version":3,"file":"Plugin.d.ts","sourceRoot":"","sources":["../../src/Plugin.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,yBAAyB,EAAE,MAAM,WAAW,CAAA;AAErD,eAAO,MAAM,+BAA+B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GASzC,CAAA"}
|
package/dist/browser/index.cjs
CHANGED
|
@@ -23,16 +23,11 @@ __export(src_exports, {
|
|
|
23
23
|
NftCollectionScoreDiviner: () => NftCollectionScoreDiviner,
|
|
24
24
|
NftCollectionScoreDivinerPlugin: () => NftCollectionScoreDivinerPlugin,
|
|
25
25
|
analyzeNftCollection: () => analyzeNftCollection,
|
|
26
|
-
default: () =>
|
|
26
|
+
default: () => NftCollectionScoreDivinerPlugin,
|
|
27
27
|
scoringCriteria: () => scoringCriteria
|
|
28
28
|
});
|
|
29
29
|
module.exports = __toCommonJS(src_exports);
|
|
30
30
|
|
|
31
|
-
// src/Plugin.ts
|
|
32
|
-
var import_crypto_nft_payload_plugin = require("@xyo-network/crypto-nft-payload-plugin");
|
|
33
|
-
var import_payload_model = require("@xyo-network/payload-model");
|
|
34
|
-
var import_payloadset_plugin = require("@xyo-network/payloadset-plugin");
|
|
35
|
-
|
|
36
31
|
// src/Diviner.ts
|
|
37
32
|
var import_abstract_diviner = require("@xyo-network/abstract-diviner");
|
|
38
33
|
var import_crypto_nft_collection_payload_plugin = require("@xyo-network/crypto-nft-collection-payload-plugin");
|
|
@@ -46,12 +41,12 @@ var scoreIndividualAttributes = (info) => {
|
|
|
46
41
|
const entries = Object.entries(attributes);
|
|
47
42
|
if (entries.length === 0)
|
|
48
43
|
return [0, maxScore];
|
|
49
|
-
const scores = Object.entries(attributes).
|
|
44
|
+
const scores = Object.entries(attributes).flatMap(([_trait, { values }]) => {
|
|
50
45
|
return Object.entries(values).map(([_traitValue, metrics]) => {
|
|
51
46
|
const rarity = Math.min(Math.round((1 - metrics.binomial.p) * maxScore), maxScore);
|
|
52
47
|
return [rarity, maxScore];
|
|
53
48
|
});
|
|
54
|
-
})
|
|
49
|
+
});
|
|
55
50
|
const total = scores.reduce(([a, b], [c, d]) => [a + c, b + d], [0, 0]);
|
|
56
51
|
return (0, import_crypto_nft_score_model.normalize)(total, maxScore);
|
|
57
52
|
};
|
|
@@ -153,6 +148,9 @@ var NftCollectionScoreDiviner = class extends import_abstract_diviner.AbstractDi
|
|
|
153
148
|
};
|
|
154
149
|
|
|
155
150
|
// src/Plugin.ts
|
|
151
|
+
var import_crypto_nft_payload_plugin = require("@xyo-network/crypto-nft-payload-plugin");
|
|
152
|
+
var import_payload_model = require("@xyo-network/payload-model");
|
|
153
|
+
var import_payloadset_plugin = require("@xyo-network/payloadset-plugin");
|
|
156
154
|
var NftCollectionScoreDivinerPlugin = () => (0, import_payloadset_plugin.createPayloadSetDivinerPlugin)(
|
|
157
155
|
{ required: { [import_crypto_nft_payload_plugin.NftSchema]: 1 }, schema: import_payload_model.PayloadSetSchema },
|
|
158
156
|
{
|
|
@@ -162,7 +160,4 @@ var NftCollectionScoreDivinerPlugin = () => (0, import_payloadset_plugin.createP
|
|
|
162
160
|
}
|
|
163
161
|
}
|
|
164
162
|
);
|
|
165
|
-
|
|
166
|
-
// src/index.ts
|
|
167
|
-
var src_default = NftCollectionScoreDivinerPlugin;
|
|
168
163
|
//# sourceMappingURL=index.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/index.ts","../../src/Plugin.ts","../../src/Diviner.ts","../../src/lib/rating/criteria/scoring/metadata/scoreIndividualAttributes.ts","../../src/lib/rating/criteria/scoring/metadata/scoreTotalAttributes.ts","../../src/lib/rating/criteria/scoring/metadata/metadata.ts","../../src/lib/rating/criteria/scoring/total.ts","../../src/lib/rating/criteria/index.ts","../../src/lib/rating/analyzeNftCollection.ts"],"sourcesContent":["import { NftCollectionScoreDivinerPlugin } from './Plugin'\n\nexport * from './Diviner'\nexport * from './lib'\n\nexport { NftCollectionScoreDivinerPlugin }\n\n// eslint-disable-next-line import/no-default-export\nexport default NftCollectionScoreDivinerPlugin\n","import { NftSchema } from '@xyo-network/crypto-nft-payload-plugin'\nimport { PayloadSetSchema } from '@xyo-network/payload-model'\nimport { createPayloadSetDivinerPlugin } from '@xyo-network/payloadset-plugin'\n\nimport { NftCollectionScoreDiviner } from './Diviner'\n\nexport const NftCollectionScoreDivinerPlugin = () =>\n createPayloadSetDivinerPlugin<NftCollectionScoreDiviner>(\n { required: { [NftSchema]: 1 }, schema: PayloadSetSchema },\n {\n diviner: async (params) => {\n const result = await NftCollectionScoreDiviner.create(params)\n return result\n },\n },\n )\n","import { AbstractDiviner } from '@xyo-network/abstract-diviner'\nimport {\n isNftCollectionInfo,\n NftCollectionInfo,\n NftCollectionMetadata,\n NftCollectionScore,\n NftCollectionScoreDivinerConfig,\n NftCollectionScoreDivinerConfigSchema,\n NftCollectionScoreSchema,\n} from '@xyo-network/crypto-nft-collection-payload-plugin'\nimport { DivinerParams } from '@xyo-network/diviner-model'\nimport { PayloadHasher } from '@xyo-network/hash'\nimport { AnyConfigSchema } from '@xyo-network/module-model'\nimport { Payload } from '@xyo-network/payload-model'\n\nimport { analyzeNftCollection, NftCollectionAnalysis } from './lib'\n\nexport type NftCollectionScoreDivinerParams = DivinerParams<AnyConfigSchema<NftCollectionScoreDivinerConfig>>\n\nconst toNftCollectionScore = (nftCollectionInfo: NftCollectionInfo, scores: NftCollectionAnalysis): NftCollectionScore => {\n const { name, symbol, address, chainId, type } = nftCollectionInfo\n const metadata: NftCollectionMetadata = { address, chainId, name, symbol, type }\n return { ...metadata, schema: NftCollectionScoreSchema, scores }\n}\n\nexport class NftCollectionScoreDiviner<\n TParams extends NftCollectionScoreDivinerParams = NftCollectionScoreDivinerParams,\n> extends AbstractDiviner<TParams> {\n static override configSchemas = [NftCollectionScoreDivinerConfigSchema]\n\n protected override divineHandler = async (payloads?: Payload[]): Promise<Payload[]> => {\n const nftCollectionInfos = payloads?.filter(isNftCollectionInfo) ?? []\n const results = await Promise.all(\n nftCollectionInfos.map<Promise<NftCollectionScore>>(async (nftCollectionInfo) => {\n const [score, sourceHash] = await Promise.all([\n // Get score\n toNftCollectionScore(nftCollectionInfo, await analyzeNftCollection(nftCollectionInfo)),\n // Hash sources\n PayloadHasher.hashAsync(nftCollectionInfo),\n ])\n return { ...score, schema: NftCollectionScoreSchema, sources: [sourceHash] } as NftCollectionScore\n }),\n )\n return results\n }\n}\n","import { NftCollectionAttributeMetrics } from '@xyo-network/crypto-nft-collection-payload-plugin'\nimport { normalize, Score } from '@xyo-network/crypto-nft-score-model'\n\nconst maxScore = 10\n\nexport const scoreIndividualAttributes = (info: NftCollectionAttributeMetrics): Score => {\n const { attributes } = info.metrics.metadata\n const entries = Object.entries(attributes)\n if (entries.length === 0) return [0, maxScore]\n const scores = Object.entries(attributes)\n .map(([_trait, { values }]) => {\n return Object.entries(values).map<Score>(([_traitValue, metrics]) => {\n const rarity = Math.min(Math.round((1 - metrics.binomial.p) * maxScore), maxScore)\n return [rarity, maxScore]\n })\n })\n .flat()\n const total = scores.reduce<Score>(([a, b], [c, d]) => [a + c, b + d], [0, 0])\n return normalize(total, maxScore)\n}\n","import { NftCollectionAttributeMetrics } from '@xyo-network/crypto-nft-collection-payload-plugin'\nimport { normalize, Score } from '@xyo-network/crypto-nft-score-model'\n\nconst maxScore = 10\n\n/**\n * Mean: What value is the distribution centered around\n */\nconst defaultMu = 0.15\n\n/**\n * Standard Deviation: How spread out is the distribution\n */\nconst defaultSigma = 0.1\n\n/**\n * Calculates the Gaussian probability density\n * @param x\n * @param mu Mean\n * @param sigma Standard Deviation\n * @returns\n */\nconst gaussianProbabilityDensity = (x: number, mu: number = defaultMu, sigma: number = defaultSigma): number => {\n const sqrtTwoPi = Math.sqrt(2 * Math.PI)\n const denominator = sigma * sqrtTwoPi\n const power = -0.5 * Math.pow((x - mu) / sigma, 2)\n return (1 / denominator) * Math.exp(power)\n}\n\n/**\n * For a Gaussian distribution, the peak of the distribution is the mean\n */\nconst maxProbabilityDensity = gaussianProbabilityDensity(defaultMu)\n\n/**\n * We're working on some assumptions here:\n *\n * - If you have a 100% chance of getting a trait, everyone get's a trophy\n * - If you have a 50% chance of getting a trait, it's not rare\n * - If you have a 0% chance of getting a trait, it's not fun\n *\n * So we're looking for something Pareto-ish (somewhere between\n * 80/20 or 90/10) as that's a good & sustainable model for the\n * distribution of many traits in real life.\n * However, we also don't want to maximally reward collections\n * that have a lot of single attributes distributed uniformly\n * (basically a 0% trait probably) as that's perfectly entropic\n * but not very interesting (some overlap is desirable).\n * So we're using a Gaussian distribution to model the\n * probability density of the joint probability of all traits\n * centered around 15%.\n * @param info\n * @returns\n */\nexport const scoreTotalAttributes = (info: NftCollectionAttributeMetrics): Score => {\n const { attributes } = info.metrics.metadata\n // This has somewhat of a filtering function by causing anything with 100% probability to\n // add no value to the end score\n const jointProbability = Object.entries(attributes).reduce((acc, [_trait, { metrics }]) => {\n return acc * metrics.binomial.p\n }, 1)\n const probabilityDensity = gaussianProbabilityDensity(jointProbability)\n const score: Score = [probabilityDensity, maxProbabilityDensity]\n return normalize(score, maxScore)\n}\n","import { NftCollectionInfo } from '@xyo-network/crypto-nft-collection-payload-plugin'\nimport { WeightedScoringCriteria } from '@xyo-network/crypto-nft-score-model'\n\nimport { scoreIndividualAttributes } from './scoreIndividualAttributes'\nimport { scoreTotalAttributes } from './scoreTotalAttributes'\n\nexport const attributeScoringCriteria: { [key: string]: WeightedScoringCriteria<NftCollectionInfo> } = {\n 'Metadata Attributes Individual': { score: scoreIndividualAttributes, weight: 2 },\n 'Metadata Attributes Total': { score: scoreTotalAttributes, weight: 2 },\n}\n\nexport const scoreMetadata: { [key: string]: WeightedScoringCriteria<NftCollectionInfo> } = {\n ...attributeScoringCriteria,\n}\n","import { NftCollectionCount } from '@xyo-network/crypto-nft-collection-payload-plugin'\nimport { normalize, Score } from '@xyo-network/crypto-nft-score-model'\n\n/**\n * This \"magic\" value was obtained using Solver in Excel\n * to find the median, with mu/sigma fixed, which maximizes\n * the distribution (the mode for lognormal) at 10,000\n */\nconst median = 81030839.8217352\nconst defaultMu = Math.log(median)\nconst defaultSigma = 3\nconst mode = Math.exp(defaultMu - Math.pow(defaultSigma, 2))\n/**\n * Calculates the log-normal probability density\n * @param x the value at which you want to calculate the probability density\n * @param mu mean of the associated normal distribution\n * @param sigma standard deviation of the associated normal distribution\n * @returns\n */\nconst logNormalProbabilityDensity = (x: number, mu: number = defaultMu, sigma: number = defaultSigma): number => {\n if (x <= 0) return 0\n const logX = Math.log(x)\n return (1 / (x * sigma * Math.sqrt(2 * Math.PI))) * Math.exp(-0.5 * Math.pow((logX - mu) / sigma, 2))\n}\n\n/**\n * For a lognormal distribution, the peak of the distribution is the mode\n */\nconst maxProbabilityDensity = logNormalProbabilityDensity(mode)\n\nconst maxScore = 10\n\n/**\n * We're working on some assumptions here:\n * - If there's < 1000 NFTs in your collection it starts becoming too niche\n * - If there's > 20,000 NFTs in your collection it starts becoming too broad\n * So there's a sweet spot somewhere between 2000 and 10,000\n * where a collection has enough NFTs to be interesting, but\n * not so many that it's teetering on a diluted money grab.\n * To model that we're using a log-normal distribution optimized\n * to maximally reward collections in the aforementioned range\n * @param nft\n * @returns\n */\nexport const scoreTotal = (nft: NftCollectionCount): Score => {\n const density = logNormalProbabilityDensity(nft.total)\n const score: Score = [density, maxProbabilityDensity]\n return normalize(score, maxScore)\n}\n","import { NftCollectionInfo } from '@xyo-network/crypto-nft-collection-payload-plugin'\nimport { WeightedScoringCriteria } from '@xyo-network/crypto-nft-score-model'\n\nimport { scoreMetadata, scoreTotal } from './scoring'\n\nexport const scoringCriteria: { [key: string]: WeightedScoringCriteria<NftCollectionInfo> } = {\n ...scoreMetadata,\n Total: { score: scoreTotal, weight: 2 },\n}\n","import { NftCollectionInfo } from '@xyo-network/crypto-nft-collection-payload-plugin'\nimport { Score } from '@xyo-network/crypto-nft-score-model'\n\nimport { scoringCriteria } from './criteria'\n\nexport type ScoringCriteriaKey = keyof typeof scoringCriteria & PropertyKey\n\nexport type NftCollectionAnalysis = {\n [key in ScoringCriteriaKey]: Score\n}\n\nexport const analyzeNftCollection = async (\n /**\n * The NFT to evaluate\n */\n nft: NftCollectionInfo,\n): Promise<NftCollectionAnalysis> => {\n const result = Object.fromEntries(\n await Promise.all(\n Object.entries(scoringCriteria).map(async ([key, { score, weight }]) => {\n const rawScore = await score(nft)\n const weighted = rawScore.map((v) => v * weight) as Score\n return [key, weighted] as const\n }),\n ),\n ) as NftCollectionAnalysis\n return result\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,uCAA0B;AAC1B,2BAAiC;AACjC,+BAA8C;;;ACF9C,8BAAgC;AAChC,kDAQO;AAEP,kBAA8B;;;ACV9B,oCAAiC;AAEjC,IAAM,WAAW;AAEV,IAAM,4BAA4B,CAAC,SAA+C;AACvF,QAAM,EAAE,WAAW,IAAI,KAAK,QAAQ;AACpC,QAAM,UAAU,OAAO,QAAQ,UAAU;AACzC,MAAI,QAAQ,WAAW;AAAG,WAAO,CAAC,GAAG,QAAQ;AAC7C,QAAM,SAAS,OAAO,QAAQ,UAAU,EACrC,IAAI,CAAC,CAAC,QAAQ,EAAE,OAAO,CAAC,MAAM;AAC7B,WAAO,OAAO,QAAQ,MAAM,EAAE,IAAW,CAAC,CAAC,aAAa,OAAO,MAAM;AACnE,YAAM,SAAS,KAAK,IAAI,KAAK,OAAO,IAAI,QAAQ,SAAS,KAAK,QAAQ,GAAG,QAAQ;AACjF,aAAO,CAAC,QAAQ,QAAQ;AAAA,IAC1B,CAAC;AAAA,EACH,CAAC,EACA,KAAK;AACR,QAAM,QAAQ,OAAO,OAAc,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,GAAG,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;AAC7E,aAAO,yCAAU,OAAO,QAAQ;AAClC;;;AClBA,IAAAA,iCAAiC;AAEjC,IAAMC,YAAW;AAKjB,IAAM,YAAY;AAKlB,IAAM,eAAe;AASrB,IAAM,6BAA6B,CAAC,GAAW,KAAa,WAAW,QAAgB,iBAAyB;AAC9G,QAAM,YAAY,KAAK,KAAK,IAAI,KAAK,EA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G,OAAO,QAAQ,sEAA0B,SAAS,CAAC,UAAU,EAAE;AAAA,MAC7E,CAAC;AAAA,IACH;AACA,WAAO;AAAA,EACT;AACF;;;ADvCO,IAAM,kCAAkC,UAC7C;AAAA,EACE,EAAE,UAAU,EAAE,CAAC,0CAAS,GAAG,EAAE,GAAG,QAAQ,sCAAiB;AAAA,EACzD;AAAA,IACE,SAAS,OAAO,WAAW;AACzB,YAAM,SAAS,MAAM,0BAA0B,OAAO,MAAM;AAC5D,aAAO;AAAA,IACT;AAAA,EACF;AACF;;;ADPF,IAAO,cAAQ;","names":["import_crypto_nft_score_model","maxScore","import_crypto_nft_score_model","defaultMu","defaultSigma","maxProbabilityDensity","maxScore"]}
|
|
1
|
+
{"version":3,"sources":["../../src/index.ts","../../src/Diviner.ts","../../src/lib/rating/criteria/scoring/metadata/scoreIndividualAttributes.ts","../../src/lib/rating/criteria/scoring/metadata/scoreTotalAttributes.ts","../../src/lib/rating/criteria/scoring/metadata/metadata.ts","../../src/lib/rating/criteria/scoring/total.ts","../../src/lib/rating/criteria/index.ts","../../src/lib/rating/analyzeNftCollection.ts","../../src/Plugin.ts"],"sourcesContent":["export * from './Diviner'\nexport * from './lib'\nexport { NftCollectionScoreDivinerPlugin as default, NftCollectionScoreDivinerPlugin } from './Plugin'\n","import { AbstractDiviner } from '@xyo-network/abstract-diviner'\nimport {\n isNftCollectionInfo,\n NftCollectionInfo,\n NftCollectionMetadata,\n NftCollectionScore,\n NftCollectionScoreDivinerConfig,\n NftCollectionScoreDivinerConfigSchema,\n NftCollectionScoreSchema,\n} from '@xyo-network/crypto-nft-collection-payload-plugin'\nimport { DivinerParams } from '@xyo-network/diviner-model'\nimport { PayloadHasher } from '@xyo-network/hash'\nimport { AnyConfigSchema } from '@xyo-network/module-model'\nimport { Payload } from '@xyo-network/payload-model'\n\nimport { analyzeNftCollection, NftCollectionAnalysis } from './lib'\n\nexport type NftCollectionScoreDivinerParams = DivinerParams<AnyConfigSchema<NftCollectionScoreDivinerConfig>>\n\nconst toNftCollectionScore = (nftCollectionInfo: NftCollectionInfo, scores: NftCollectionAnalysis): NftCollectionScore => {\n const { name, symbol, address, chainId, type } = nftCollectionInfo\n const metadata: NftCollectionMetadata = { address, chainId, name, symbol, type }\n return { ...metadata, schema: NftCollectionScoreSchema, scores }\n}\n\nexport class NftCollectionScoreDiviner<\n TParams extends NftCollectionScoreDivinerParams = NftCollectionScoreDivinerParams,\n> extends AbstractDiviner<TParams> {\n static override configSchemas = [NftCollectionScoreDivinerConfigSchema]\n\n protected override divineHandler = async (payloads?: Payload[]): Promise<Payload[]> => {\n const nftCollectionInfos = payloads?.filter(isNftCollectionInfo) ?? []\n const results = await Promise.all(\n nftCollectionInfos.map<Promise<NftCollectionScore>>(async (nftCollectionInfo) => {\n const [score, sourceHash] = await Promise.all([\n // Get score\n toNftCollectionScore(nftCollectionInfo, await analyzeNftCollection(nftCollectionInfo)),\n // Hash sources\n PayloadHasher.hashAsync(nftCollectionInfo),\n ])\n return { ...score, schema: NftCollectionScoreSchema, sources: [sourceHash] } as NftCollectionScore\n }),\n )\n return results\n }\n}\n","import { NftCollectionAttributeMetrics } from '@xyo-network/crypto-nft-collection-payload-plugin'\nimport { normalize, Score } from '@xyo-network/crypto-nft-score-model'\n\nconst maxScore = 10\n\nexport const scoreIndividualAttributes = (info: NftCollectionAttributeMetrics): Score => {\n const { attributes } = info.metrics.metadata\n const entries = Object.entries(attributes)\n if (entries.length === 0) return [0, maxScore]\n const scores = Object.entries(attributes).flatMap(([_trait, { values }]) => {\n return Object.entries(values).map<Score>(([_traitValue, metrics]) => {\n const rarity = Math.min(Math.round((1 - metrics.binomial.p) * maxScore), maxScore)\n return [rarity, maxScore]\n })\n })\n // eslint-disable-next-line unicorn/no-array-reduce\n const total = scores.reduce<Score>(([a, b], [c, d]) => [a + c, b + d], [0, 0])\n return normalize(total, maxScore)\n}\n","import { NftCollectionAttributeMetrics } from '@xyo-network/crypto-nft-collection-payload-plugin'\nimport { normalize, Score } from '@xyo-network/crypto-nft-score-model'\n\nconst maxScore = 10\n\n/**\n * Mean: What value is the distribution centered around\n */\nconst defaultMu = 0.15\n\n/**\n * Standard Deviation: How spread out is the distribution\n */\nconst defaultSigma = 0.1\n\n/**\n * Calculates the Gaussian probability density\n * @param x\n * @param mu Mean\n * @param sigma Standard Deviation\n * @returns\n */\nconst gaussianProbabilityDensity = (x: number, mu: number = defaultMu, sigma: number = defaultSigma): number => {\n const sqrtTwoPi = Math.sqrt(2 * Math.PI)\n const denominator = sigma * sqrtTwoPi\n const power = -0.5 * Math.pow((x - mu) / sigma, 2)\n return (1 / denominator) * Math.exp(power)\n}\n\n/**\n * For a Gaussian distribution, the peak of the distribution is the mean\n */\nconst maxProbabilityDensity = gaussianProbabilityDensity(defaultMu)\n\n/**\n * We're working on some assumptions here:\n *\n * - If you have a 100% chance of getting a trait, everyone get's a trophy\n * - If you have a 50% chance of getting a trait, it's not rare\n * - If you have a 0% chance of getting a trait, it's not fun\n *\n * So we're looking for something Pareto-ish (somewhere between\n * 80/20 or 90/10) as that's a good & sustainable model for the\n * distribution of many traits in real life.\n * However, we also don't want to maximally reward collections\n * that have a lot of single attributes distributed uniformly\n * (basically a 0% trait probably) as that's perfectly entropic\n * but not very interesting (some overlap is desirable).\n * So we're using a Gaussian distribution to model the\n * probability density of the joint probability of all traits\n * centered around 15%.\n * @param info\n * @returns\n */\nexport const scoreTotalAttributes = (info: NftCollectionAttributeMetrics): Score => {\n const { attributes } = info.metrics.metadata\n // This has somewhat of a filtering function by causing anything with 100% probability to\n // add no value to the end score\n const jointProbability = Object.entries(attributes).reduce((acc, [_trait, { metrics }]) => {\n return acc * metrics.binomial.p\n }, 1)\n const probabilityDensity = gaussianProbabilityDensity(jointProbability)\n const score: Score = [probabilityDensity, maxProbabilityDensity]\n return normalize(score, maxScore)\n}\n","import { NftCollectionInfo } from '@xyo-network/crypto-nft-collection-payload-plugin'\nimport { WeightedScoringCriteria } from '@xyo-network/crypto-nft-score-model'\n\nimport { scoreIndividualAttributes } from './scoreIndividualAttributes'\nimport { scoreTotalAttributes } from './scoreTotalAttributes'\n\nexport const attributeScoringCriteria: { [key: string]: WeightedScoringCriteria<NftCollectionInfo> } = {\n 'Metadata Attributes Individual': { score: scoreIndividualAttributes, weight: 2 },\n 'Metadata Attributes Total': { score: scoreTotalAttributes, weight: 2 },\n}\n\nexport const scoreMetadata: { [key: string]: WeightedScoringCriteria<NftCollectionInfo> } = {\n ...attributeScoringCriteria,\n}\n","import { NftCollectionCount } from '@xyo-network/crypto-nft-collection-payload-plugin'\nimport { normalize, Score } from '@xyo-network/crypto-nft-score-model'\n\n/**\n * This \"magic\" value was obtained using Solver in Excel\n * to find the median, with mu/sigma fixed, which maximizes\n * the distribution (the mode for lognormal) at 10,000\n */\nconst median = 81_030_839.821_735_2\nconst defaultMu = Math.log(median)\nconst defaultSigma = 3\nconst mode = Math.exp(defaultMu - Math.pow(defaultSigma, 2))\n/**\n * Calculates the log-normal probability density\n * @param x the value at which you want to calculate the probability density\n * @param mu mean of the associated normal distribution\n * @param sigma standard deviation of the associated normal distribution\n * @returns\n */\nconst logNormalProbabilityDensity = (x: number, mu: number = defaultMu, sigma: number = defaultSigma): number => {\n if (x <= 0) return 0\n const logX = Math.log(x)\n return (1 / (x * sigma * Math.sqrt(2 * Math.PI))) * Math.exp(-0.5 * Math.pow((logX - mu) / sigma, 2))\n}\n\n/**\n * For a lognormal distribution, the peak of the distribution is the mode\n */\nconst maxProbabilityDensity = logNormalProbabilityDensity(mode)\n\nconst maxScore = 10\n\n/**\n * We're working on some assumptions here:\n * - If there's < 1000 NFTs in your collection it starts becoming too niche\n * - If there's > 20,000 NFTs in your collection it starts becoming too broad\n * So there's a sweet spot somewhere between 2000 and 10,000\n * where a collection has enough NFTs to be interesting, but\n * not so many that it's teetering on a diluted money grab.\n * To model that we're using a log-normal distribution optimized\n * to maximally reward collections in the aforementioned range\n * @param nft\n * @returns\n */\nexport const scoreTotal = (nft: NftCollectionCount): Score => {\n const density = logNormalProbabilityDensity(nft.total)\n const score: Score = [density, maxProbabilityDensity]\n return normalize(score, maxScore)\n}\n","import { NftCollectionInfo } from '@xyo-network/crypto-nft-collection-payload-plugin'\nimport { WeightedScoringCriteria } from '@xyo-network/crypto-nft-score-model'\n\nimport { scoreMetadata, scoreTotal } from './scoring'\n\nexport const scoringCriteria: { [key: string]: WeightedScoringCriteria<NftCollectionInfo> } = {\n ...scoreMetadata,\n Total: { score: scoreTotal, weight: 2 },\n}\n","import { NftCollectionInfo } from '@xyo-network/crypto-nft-collection-payload-plugin'\nimport { Score } from '@xyo-network/crypto-nft-score-model'\n\nimport { scoringCriteria } from './criteria'\n\nexport type ScoringCriteriaKey = keyof typeof scoringCriteria & PropertyKey\n\nexport type NftCollectionAnalysis = {\n [key in ScoringCriteriaKey]: Score\n}\n\nexport const analyzeNftCollection = async (\n /**\n * The NFT to evaluate\n */\n nft: NftCollectionInfo,\n): Promise<NftCollectionAnalysis> => {\n const result = Object.fromEntries(\n await Promise.all(\n Object.entries(scoringCriteria).map(async ([key, { score, weight }]) => {\n const rawScore = await score(nft)\n const weighted = rawScore.map((v) => v * weight) as Score\n return [key, weighted] as const\n }),\n ),\n ) as NftCollectionAnalysis\n return result\n}\n","import { NftSchema } from '@xyo-network/crypto-nft-payload-plugin'\nimport { PayloadSetSchema } from '@xyo-network/payload-model'\nimport { createPayloadSetDivinerPlugin } from '@xyo-network/payloadset-plugin'\n\nimport { NftCollectionScoreDiviner } from './Diviner'\n\nexport const NftCollectionScoreDivinerPlugin = () =>\n createPayloadSetDivinerPlugin<NftCollectionScoreDiviner>(\n { required: { [NftSchema]: 1 }, schema: PayloadSetSchema },\n {\n diviner: async (params) => {\n const result = await NftCollectionScoreDiviner.create(params)\n return result\n },\n },\n )\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,8BAAgC;AAChC,kDAQO;AAEP,kBAA8B;;;ACV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,OAAO,MAAM;AAC5D,aAAO;AAAA,IACT;AAAA,EACF;AACF;","names":["import_crypto_nft_score_model","maxScore","import_crypto_nft_score_model","defaultMu","defaultSigma","maxProbabilityDensity","maxScore"]}
|
package/dist/browser/index.d.cts
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
import { NftCollectionScoreDivinerPlugin } from './Plugin';
|
|
2
1
|
export * from './Diviner';
|
|
3
2
|
export * from './lib';
|
|
4
|
-
export { NftCollectionScoreDivinerPlugin };
|
|
5
|
-
export default NftCollectionScoreDivinerPlugin;
|
|
3
|
+
export { NftCollectionScoreDivinerPlugin as default, NftCollectionScoreDivinerPlugin } from './Plugin';
|
|
6
4
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAA;AACzB,cAAc,OAAO,CAAA;AACrB,OAAO,EAAE,+BAA+B,IAAI,OAAO,EAAE,+BAA+B,EAAE,MAAM,UAAU,CAAA"}
|
package/dist/browser/index.d.mts
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
import { NftCollectionScoreDivinerPlugin } from './Plugin';
|
|
2
1
|
export * from './Diviner';
|
|
3
2
|
export * from './lib';
|
|
4
|
-
export { NftCollectionScoreDivinerPlugin };
|
|
5
|
-
export default NftCollectionScoreDivinerPlugin;
|
|
3
|
+
export { NftCollectionScoreDivinerPlugin as default, NftCollectionScoreDivinerPlugin } from './Plugin';
|
|
6
4
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAA;AACzB,cAAc,OAAO,CAAA;AACrB,OAAO,EAAE,+BAA+B,IAAI,OAAO,EAAE,+BAA+B,EAAE,MAAM,UAAU,CAAA"}
|
package/dist/browser/index.d.ts
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
import { NftCollectionScoreDivinerPlugin } from './Plugin';
|
|
2
1
|
export * from './Diviner';
|
|
3
2
|
export * from './lib';
|
|
4
|
-
export { NftCollectionScoreDivinerPlugin };
|
|
5
|
-
export default NftCollectionScoreDivinerPlugin;
|
|
3
|
+
export { NftCollectionScoreDivinerPlugin as default, NftCollectionScoreDivinerPlugin } from './Plugin';
|
|
6
4
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAA;AACzB,cAAc,OAAO,CAAA;AACrB,OAAO,EAAE,+BAA+B,IAAI,OAAO,EAAE,+BAA+B,EAAE,MAAM,UAAU,CAAA"}
|
package/dist/browser/index.js
CHANGED
|
@@ -1,8 +1,3 @@
|
|
|
1
|
-
// src/Plugin.ts
|
|
2
|
-
import { NftSchema } from "@xyo-network/crypto-nft-payload-plugin";
|
|
3
|
-
import { PayloadSetSchema } from "@xyo-network/payload-model";
|
|
4
|
-
import { createPayloadSetDivinerPlugin } from "@xyo-network/payloadset-plugin";
|
|
5
|
-
|
|
6
1
|
// src/Diviner.ts
|
|
7
2
|
import { AbstractDiviner } from "@xyo-network/abstract-diviner";
|
|
8
3
|
import {
|
|
@@ -20,12 +15,12 @@ var scoreIndividualAttributes = (info) => {
|
|
|
20
15
|
const entries = Object.entries(attributes);
|
|
21
16
|
if (entries.length === 0)
|
|
22
17
|
return [0, maxScore];
|
|
23
|
-
const scores = Object.entries(attributes).
|
|
18
|
+
const scores = Object.entries(attributes).flatMap(([_trait, { values }]) => {
|
|
24
19
|
return Object.entries(values).map(([_traitValue, metrics]) => {
|
|
25
20
|
const rarity = Math.min(Math.round((1 - metrics.binomial.p) * maxScore), maxScore);
|
|
26
21
|
return [rarity, maxScore];
|
|
27
22
|
});
|
|
28
|
-
})
|
|
23
|
+
});
|
|
29
24
|
const total = scores.reduce(([a, b], [c, d]) => [a + c, b + d], [0, 0]);
|
|
30
25
|
return normalize(total, maxScore);
|
|
31
26
|
};
|
|
@@ -127,6 +122,9 @@ var NftCollectionScoreDiviner = class extends AbstractDiviner {
|
|
|
127
122
|
};
|
|
128
123
|
|
|
129
124
|
// src/Plugin.ts
|
|
125
|
+
import { NftSchema } from "@xyo-network/crypto-nft-payload-plugin";
|
|
126
|
+
import { PayloadSetSchema } from "@xyo-network/payload-model";
|
|
127
|
+
import { createPayloadSetDivinerPlugin } from "@xyo-network/payloadset-plugin";
|
|
130
128
|
var NftCollectionScoreDivinerPlugin = () => createPayloadSetDivinerPlugin(
|
|
131
129
|
{ required: { [NftSchema]: 1 }, schema: PayloadSetSchema },
|
|
132
130
|
{
|
|
@@ -136,14 +134,11 @@ var NftCollectionScoreDivinerPlugin = () => createPayloadSetDivinerPlugin(
|
|
|
136
134
|
}
|
|
137
135
|
}
|
|
138
136
|
);
|
|
139
|
-
|
|
140
|
-
// src/index.ts
|
|
141
|
-
var src_default = NftCollectionScoreDivinerPlugin;
|
|
142
137
|
export {
|
|
143
138
|
NftCollectionScoreDiviner,
|
|
144
139
|
NftCollectionScoreDivinerPlugin,
|
|
145
140
|
analyzeNftCollection,
|
|
146
|
-
|
|
141
|
+
NftCollectionScoreDivinerPlugin as default,
|
|
147
142
|
scoringCriteria
|
|
148
143
|
};
|
|
149
144
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/Plugin.ts","../../src/Diviner.ts","../../src/lib/rating/criteria/scoring/metadata/scoreIndividualAttributes.ts","../../src/lib/rating/criteria/scoring/metadata/scoreTotalAttributes.ts","../../src/lib/rating/criteria/scoring/metadata/metadata.ts","../../src/lib/rating/criteria/scoring/total.ts","../../src/lib/rating/criteria/index.ts","../../src/lib/rating/analyzeNftCollection.ts","../../src/index.ts"],"sourcesContent":["import { NftSchema } from '@xyo-network/crypto-nft-payload-plugin'\nimport { PayloadSetSchema } from '@xyo-network/payload-model'\nimport { createPayloadSetDivinerPlugin } from '@xyo-network/payloadset-plugin'\n\nimport { NftCollectionScoreDiviner } from './Diviner'\n\nexport const NftCollectionScoreDivinerPlugin = () =>\n createPayloadSetDivinerPlugin<NftCollectionScoreDiviner>(\n { required: { [NftSchema]: 1 }, schema: PayloadSetSchema },\n {\n diviner: async (params) => {\n const result = await NftCollectionScoreDiviner.create(params)\n return result\n },\n },\n )\n","import { AbstractDiviner } from '@xyo-network/abstract-diviner'\nimport {\n isNftCollectionInfo,\n NftCollectionInfo,\n NftCollectionMetadata,\n NftCollectionScore,\n NftCollectionScoreDivinerConfig,\n NftCollectionScoreDivinerConfigSchema,\n NftCollectionScoreSchema,\n} from '@xyo-network/crypto-nft-collection-payload-plugin'\nimport { DivinerParams } from '@xyo-network/diviner-model'\nimport { PayloadHasher } from '@xyo-network/hash'\nimport { AnyConfigSchema } from '@xyo-network/module-model'\nimport { Payload } from '@xyo-network/payload-model'\n\nimport { analyzeNftCollection, NftCollectionAnalysis } from './lib'\n\nexport type NftCollectionScoreDivinerParams = DivinerParams<AnyConfigSchema<NftCollectionScoreDivinerConfig>>\n\nconst toNftCollectionScore = (nftCollectionInfo: NftCollectionInfo, scores: NftCollectionAnalysis): NftCollectionScore => {\n const { name, symbol, address, chainId, type } = nftCollectionInfo\n const metadata: NftCollectionMetadata = { address, chainId, name, symbol, type }\n return { ...metadata, schema: NftCollectionScoreSchema, scores }\n}\n\nexport class NftCollectionScoreDiviner<\n TParams extends NftCollectionScoreDivinerParams = NftCollectionScoreDivinerParams,\n> extends AbstractDiviner<TParams> {\n static override configSchemas = [NftCollectionScoreDivinerConfigSchema]\n\n protected override divineHandler = async (payloads?: Payload[]): Promise<Payload[]> => {\n const nftCollectionInfos = payloads?.filter(isNftCollectionInfo) ?? []\n const results = await Promise.all(\n nftCollectionInfos.map<Promise<NftCollectionScore>>(async (nftCollectionInfo) => {\n const [score, sourceHash] = await Promise.all([\n // Get score\n toNftCollectionScore(nftCollectionInfo, await analyzeNftCollection(nftCollectionInfo)),\n // Hash sources\n PayloadHasher.hashAsync(nftCollectionInfo),\n ])\n return { ...score, schema: NftCollectionScoreSchema, sources: [sourceHash] } as NftCollectionScore\n }),\n )\n return results\n }\n}\n","import { NftCollectionAttributeMetrics } from '@xyo-network/crypto-nft-collection-payload-plugin'\nimport { normalize, Score } from '@xyo-network/crypto-nft-score-model'\n\nconst maxScore = 10\n\nexport const scoreIndividualAttributes = (info: NftCollectionAttributeMetrics): Score => {\n const { attributes } = info.metrics.metadata\n const entries = Object.entries(attributes)\n if (entries.length === 0) return [0, maxScore]\n const scores = Object.entries(attributes)\n .map(([_trait, { values }]) => {\n return Object.entries(values).map<Score>(([_traitValue, metrics]) => {\n const rarity = Math.min(Math.round((1 - metrics.binomial.p) * maxScore), maxScore)\n return [rarity, maxScore]\n })\n })\n .flat()\n const total = scores.reduce<Score>(([a, b], [c, d]) => [a + c, b + d], [0, 0])\n return normalize(total, maxScore)\n}\n","import { NftCollectionAttributeMetrics } from '@xyo-network/crypto-nft-collection-payload-plugin'\nimport { normalize, Score } from '@xyo-network/crypto-nft-score-model'\n\nconst maxScore = 10\n\n/**\n * Mean: What value is the distribution centered around\n */\nconst defaultMu = 0.15\n\n/**\n * Standard Deviation: How spread out is the distribution\n */\nconst defaultSigma = 0.1\n\n/**\n * Calculates the Gaussian probability density\n * @param x\n * @param mu Mean\n * @param sigma Standard Deviation\n * @returns\n */\nconst gaussianProbabilityDensity = (x: number, mu: number = defaultMu, sigma: number = defaultSigma): number => {\n const sqrtTwoPi = Math.sqrt(2 * Math.PI)\n const denominator = sigma * sqrtTwoPi\n const power = -0.5 * Math.pow((x - mu) / sigma, 2)\n return (1 / denominator) * Math.exp(power)\n}\n\n/**\n * For a Gaussian distribution, the peak of the distribution is the mean\n */\nconst maxProbabilityDensity = gaussianProbabilityDensity(defaultMu)\n\n/**\n * We're working on some assumptions here:\n *\n * - If you have a 100% chance of getting a trait, everyone get's a trophy\n * - If you have a 50% chance of getting a trait, it's not rare\n * - If you have a 0% chance of getting a trait, it's not fun\n *\n * So we're looking for something Pareto-ish (somewhere between\n * 80/20 or 90/10) as that's a good & sustainable model for the\n * distribution of many traits in real life.\n * However, we also don't want to maximally reward collections\n * that have a lot of single attributes distributed uniformly\n * (basically a 0% trait probably) as that's perfectly entropic\n * but not very interesting (some overlap is desirable).\n * So we're using a Gaussian distribution to model the\n * probability density of the joint probability of all traits\n * centered around 15%.\n * @param info\n * @returns\n */\nexport const scoreTotalAttributes = (info: NftCollectionAttributeMetrics): Score => {\n const { attributes } = info.metrics.metadata\n // This has somewhat of a filtering function by causing anything with 100% probability to\n // add no value to the end score\n const jointProbability = Object.entries(attributes).reduce((acc, [_trait, { metrics }]) => {\n return acc * metrics.binomial.p\n }, 1)\n const probabilityDensity = gaussianProbabilityDensity(jointProbability)\n const score: Score = [probabilityDensity, maxProbabilityDensity]\n return normalize(score, maxScore)\n}\n","import { NftCollectionInfo } from '@xyo-network/crypto-nft-collection-payload-plugin'\nimport { WeightedScoringCriteria } from '@xyo-network/crypto-nft-score-model'\n\nimport { scoreIndividualAttributes } from './scoreIndividualAttributes'\nimport { scoreTotalAttributes } from './scoreTotalAttributes'\n\nexport const attributeScoringCriteria: { [key: string]: WeightedScoringCriteria<NftCollectionInfo> } = {\n 'Metadata Attributes Individual': { score: scoreIndividualAttributes, weight: 2 },\n 'Metadata Attributes Total': { score: scoreTotalAttributes, weight: 2 },\n}\n\nexport const scoreMetadata: { [key: string]: WeightedScoringCriteria<NftCollectionInfo> } = {\n ...attributeScoringCriteria,\n}\n","import { NftCollectionCount } from '@xyo-network/crypto-nft-collection-payload-plugin'\nimport { normalize, Score } from '@xyo-network/crypto-nft-score-model'\n\n/**\n * This \"magic\" value was obtained using Solver in Excel\n * to find the median, with mu/sigma fixed, which maximizes\n * the distribution (the mode for lognormal) at 10,000\n */\nconst median = 81030839.8217352\nconst defaultMu = Math.log(median)\nconst defaultSigma = 3\nconst mode = Math.exp(defaultMu - Math.pow(defaultSigma, 2))\n/**\n * Calculates the log-normal probability density\n * @param x the value at which you want to calculate the probability density\n * @param mu mean of the associated normal distribution\n * @param sigma standard deviation of the associated normal distribution\n * @returns\n */\nconst logNormalProbabilityDensity = (x: number, mu: number = defaultMu, sigma: number = defaultSigma): number => {\n if (x <= 0) return 0\n const logX = Math.log(x)\n return (1 / (x * sigma * Math.sqrt(2 * Math.PI))) * Math.exp(-0.5 * Math.pow((logX - mu) / sigma, 2))\n}\n\n/**\n * For a lognormal distribution, the peak of the distribution is the mode\n */\nconst maxProbabilityDensity = logNormalProbabilityDensity(mode)\n\nconst maxScore = 10\n\n/**\n * We're working on some assumptions here:\n * - If there's < 1000 NFTs in your collection it starts becoming too niche\n * - If there's > 20,000 NFTs in your collection it starts becoming too broad\n * So there's a sweet spot somewhere between 2000 and 10,000\n * where a collection has enough NFTs to be interesting, but\n * not so many that it's teetering on a diluted money grab.\n * To model that we're using a log-normal distribution optimized\n * to maximally reward collections in the aforementioned range\n * @param nft\n * @returns\n */\nexport const scoreTotal = (nft: NftCollectionCount): Score => {\n const density = logNormalProbabilityDensity(nft.total)\n const score: Score = [density, maxProbabilityDensity]\n return normalize(score, maxScore)\n}\n","import { NftCollectionInfo } from '@xyo-network/crypto-nft-collection-payload-plugin'\nimport { WeightedScoringCriteria } from '@xyo-network/crypto-nft-score-model'\n\nimport { scoreMetadata, scoreTotal } from './scoring'\n\nexport const scoringCriteria: { [key: string]: WeightedScoringCriteria<NftCollectionInfo> } = {\n ...scoreMetadata,\n Total: { score: scoreTotal, weight: 2 },\n}\n","import { NftCollectionInfo } from '@xyo-network/crypto-nft-collection-payload-plugin'\nimport { Score } from '@xyo-network/crypto-nft-score-model'\n\nimport { scoringCriteria } from './criteria'\n\nexport type ScoringCriteriaKey = keyof typeof scoringCriteria & PropertyKey\n\nexport type NftCollectionAnalysis = {\n [key in ScoringCriteriaKey]: Score\n}\n\nexport const analyzeNftCollection = async (\n /**\n * The NFT to evaluate\n */\n nft: NftCollectionInfo,\n): Promise<NftCollectionAnalysis> => {\n const result = Object.fromEntries(\n await Promise.all(\n Object.entries(scoringCriteria).map(async ([key, { score, weight }]) => {\n const rawScore = await score(nft)\n const weighted = rawScore.map((v) => v * weight) as Score\n return [key, weighted] as const\n }),\n ),\n ) as NftCollectionAnalysis\n return result\n}\n","import { NftCollectionScoreDivinerPlugin } from './Plugin'\n\nexport * from './Diviner'\nexport * from './lib'\n\nexport { NftCollectionScoreDivinerPlugin }\n\n// eslint-disable-next-line import/no-default-export\nexport default NftCollectionScoreDivinerPlugin\n"],"mappings":";AAAA,SAAS,iBAAiB;AAC1B,SAAS,wBAAwB;AACjC,SAAS,qCAAqC;;;ACF9C,SAAS,uBAAuB;AAChC;AAAA,EACE;AAAA,EAKA;AAAA,EACA;AAAA,OACK;AAEP,SAAS,qBAAqB;;;ACV9B,SAAS,iBAAwB;AAEjC,IAAM,WAAW;AAEV,IAAM,4BAA4B,CAAC,SAA+C;AACvF,QAAM,EAAE,WAAW,IAAI,KAAK,QAAQ;AACpC,QAAM,UAAU,OAAO,QAAQ,UAAU;AACzC,MAAI,QAAQ,WAAW;AAAG,WAAO,CAAC,GAAG,QAAQ;AAC7C,QAAM,SAAS,OAAO,QAAQ,UAAU,EACrC,IAAI,CAAC,CAAC,QAAQ,EAAE,OAAO,CAAC,MAAM;AAC7B,WAAO,OAAO,QAAQ,MAAM,EAAE,IAAW,CAAC,CAAC,aAAa,OAAO,MAAM;AACnE,YAAM,SAAS,KAAK,IAAI,KAAK,OAAO,IA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,KAAK;AAC/E,SAAO,EAAE,GAAG,UAAU,QAAQ,0BAA0B,OAAO;AACjE;AAEO,IAAM,4BAAN,cAEG,gBAAyB;AAAA,EACjC,OAAgB,gBAAgB,CAAC,qCAAqC;AAAA,EAEnD,gBAAgB,OAAO,aAA6C;AACrF,UAAM,qBAAqB,UAAU,OAAO,mBAAmB,KAAK,CAAC;AACrE,UAAM,UAAU,MAAM,QAAQ;AAAA,MAC5B,mBAAmB,IAAiC,OAAO,sBAAsB;AAC/E,cAAM,CAAC,OAAO,UAAU,IAAI,MAAM,QAAQ,IAAI;AAAA;AAAA,UAE5C,qBAAqB,mBAAmB,MAAM,qBAAqB,iBAAiB,CAAC;AAAA;AAAA,UAErF,cAAc,UAAU,iBAAiB;AAAA,QAC3C,CAAC;AACD,eAAO,EAAE,GAAG,OAAO,QAAQ,0BAA0B,SAAS,CAAC,UAAU,EAAE;AAAA,MAC7E,CAAC;AAAA,IACH;AACA,WAAO;AAAA,EACT;AACF;;;ADvCO,IAAM,kCAAkC,MAC7C;AAAA,EACE,EAAE,UAAU,EAAE,CAAC,SAAS,GAAG,EAAE,GAAG,QAAQ,iBAAiB;AAAA,EACzD;AAAA,IACE,SAAS,OAAO,WAAW;AACzB,YAAM,SAAS,MAAM,0BAA0B,OAAO,MAAM;AAC5D,aAAO;AAAA,IACT;AAAA,EACF;AACF;;;AQPF,IAAO,cAAQ;","names":["normalize","maxScore","normalize","defaultMu","defaultSigma","maxProbabilityDensity","maxScore"]}
|
|
1
|
+
{"version":3,"sources":["../../src/Diviner.ts","../../src/lib/rating/criteria/scoring/metadata/scoreIndividualAttributes.ts","../../src/lib/rating/criteria/scoring/metadata/scoreTotalAttributes.ts","../../src/lib/rating/criteria/scoring/metadata/metadata.ts","../../src/lib/rating/criteria/scoring/total.ts","../../src/lib/rating/criteria/index.ts","../../src/lib/rating/analyzeNftCollection.ts","../../src/Plugin.ts"],"sourcesContent":["import { AbstractDiviner } from '@xyo-network/abstract-diviner'\nimport {\n isNftCollectionInfo,\n NftCollectionInfo,\n NftCollectionMetadata,\n NftCollectionScore,\n NftCollectionScoreDivinerConfig,\n NftCollectionScoreDivinerConfigSchema,\n NftCollectionScoreSchema,\n} from '@xyo-network/crypto-nft-collection-payload-plugin'\nimport { DivinerParams } from '@xyo-network/diviner-model'\nimport { PayloadHasher } from '@xyo-network/hash'\nimport { AnyConfigSchema } from '@xyo-network/module-model'\nimport { Payload } from '@xyo-network/payload-model'\n\nimport { analyzeNftCollection, NftCollectionAnalysis } from './lib'\n\nexport type NftCollectionScoreDivinerParams = DivinerParams<AnyConfigSchema<NftCollectionScoreDivinerConfig>>\n\nconst toNftCollectionScore = (nftCollectionInfo: NftCollectionInfo, scores: NftCollectionAnalysis): NftCollectionScore => {\n const { name, symbol, address, chainId, type } = nftCollectionInfo\n const metadata: NftCollectionMetadata = { address, chainId, name, symbol, type }\n return { ...metadata, schema: NftCollectionScoreSchema, scores }\n}\n\nexport class NftCollectionScoreDiviner<\n TParams extends NftCollectionScoreDivinerParams = NftCollectionScoreDivinerParams,\n> extends AbstractDiviner<TParams> {\n static override configSchemas = [NftCollectionScoreDivinerConfigSchema]\n\n protected override divineHandler = async (payloads?: Payload[]): Promise<Payload[]> => {\n const nftCollectionInfos = payloads?.filter(isNftCollectionInfo) ?? []\n const results = await Promise.all(\n nftCollectionInfos.map<Promise<NftCollectionScore>>(async (nftCollectionInfo) => {\n const [score, sourceHash] = await Promise.all([\n // Get score\n toNftCollectionScore(nftCollectionInfo, await analyzeNftCollection(nftCollectionInfo)),\n // Hash sources\n PayloadHasher.hashAsync(nftCollectionInfo),\n ])\n return { ...score, schema: NftCollectionScoreSchema, sources: [sourceHash] } as NftCollectionScore\n }),\n )\n return results\n }\n}\n","import { NftCollectionAttributeMetrics } from '@xyo-network/crypto-nft-collection-payload-plugin'\nimport { normalize, Score } from '@xyo-network/crypto-nft-score-model'\n\nconst maxScore = 10\n\nexport const scoreIndividualAttributes = (info: NftCollectionAttributeMetrics): Score => {\n const { attributes } = info.metrics.metadata\n const entries = Object.entries(attributes)\n if (entries.length === 0) return [0, maxScore]\n const scores = Object.entries(attributes).flatMap(([_trait, { values }]) => {\n return Object.entries(values).map<Score>(([_traitValue, metrics]) => {\n const rarity = Math.min(Math.round((1 - metrics.binomial.p) * maxScore), maxScore)\n return [rarity, maxScore]\n })\n })\n // eslint-disable-next-line unicorn/no-array-reduce\n const total = scores.reduce<Score>(([a, b], [c, d]) => [a + c, b + d], [0, 0])\n return normalize(total, maxScore)\n}\n","import { NftCollectionAttributeMetrics } from '@xyo-network/crypto-nft-collection-payload-plugin'\nimport { normalize, Score } from '@xyo-network/crypto-nft-score-model'\n\nconst maxScore = 10\n\n/**\n * Mean: What value is the distribution centered around\n */\nconst defaultMu = 0.15\n\n/**\n * Standard Deviation: How spread out is the distribution\n */\nconst defaultSigma = 0.1\n\n/**\n * Calculates the Gaussian probability density\n * @param x\n * @param mu Mean\n * @param sigma Standard Deviation\n * @returns\n */\nconst gaussianProbabilityDensity = (x: number, mu: number = defaultMu, sigma: number = defaultSigma): number => {\n const sqrtTwoPi = Math.sqrt(2 * Math.PI)\n const denominator = sigma * sqrtTwoPi\n const power = -0.5 * Math.pow((x - mu) / sigma, 2)\n return (1 / denominator) * Math.exp(power)\n}\n\n/**\n * For a Gaussian distribution, the peak of the distribution is the mean\n */\nconst maxProbabilityDensity = gaussianProbabilityDensity(defaultMu)\n\n/**\n * We're working on some assumptions here:\n *\n * - If you have a 100% chance of getting a trait, everyone get's a trophy\n * - If you have a 50% chance of getting a trait, it's not rare\n * - If you have a 0% chance of getting a trait, it's not fun\n *\n * So we're looking for something Pareto-ish (somewhere between\n * 80/20 or 90/10) as that's a good & sustainable model for the\n * distribution of many traits in real life.\n * However, we also don't want to maximally reward collections\n * that have a lot of single attributes distributed uniformly\n * (basically a 0% trait probably) as that's perfectly entropic\n * but not very interesting (some overlap is desirable).\n * So we're using a Gaussian distribution to model the\n * probability density of the joint probability of all traits\n * centered around 15%.\n * @param info\n * @returns\n */\nexport const scoreTotalAttributes = (info: NftCollectionAttributeMetrics): Score => {\n const { attributes } = info.metrics.metadata\n // This has somewhat of a filtering function by causing anything with 100% probability to\n // add no value to the end score\n const jointProbability = Object.entries(attributes).reduce((acc, [_trait, { metrics }]) => {\n return acc * metrics.binomial.p\n }, 1)\n const probabilityDensity = gaussianProbabilityDensity(jointProbability)\n const score: Score = [probabilityDensity, maxProbabilityDensity]\n return normalize(score, maxScore)\n}\n","import { NftCollectionInfo } from '@xyo-network/crypto-nft-collection-payload-plugin'\nimport { WeightedScoringCriteria } from '@xyo-network/crypto-nft-score-model'\n\nimport { scoreIndividualAttributes } from './scoreIndividualAttributes'\nimport { scoreTotalAttributes } from './scoreTotalAttributes'\n\nexport const attributeScoringCriteria: { [key: string]: WeightedScoringCriteria<NftCollectionInfo> } = {\n 'Metadata Attributes Individual': { score: scoreIndividualAttributes, weight: 2 },\n 'Metadata Attributes Total': { score: scoreTotalAttributes, weight: 2 },\n}\n\nexport const scoreMetadata: { [key: string]: WeightedScoringCriteria<NftCollectionInfo> } = {\n ...attributeScoringCriteria,\n}\n","import { NftCollectionCount } from '@xyo-network/crypto-nft-collection-payload-plugin'\nimport { normalize, Score } from '@xyo-network/crypto-nft-score-model'\n\n/**\n * This \"magic\" value was obtained using Solver in Excel\n * to find the median, with mu/sigma fixed, which maximizes\n * the distribution (the mode for lognormal) at 10,000\n */\nconst median = 81_030_839.821_735_2\nconst defaultMu = Math.log(median)\nconst defaultSigma = 3\nconst mode = Math.exp(defaultMu - Math.pow(defaultSigma, 2))\n/**\n * Calculates the log-normal probability density\n * @param x the value at which you want to calculate the probability density\n * @param mu mean of the associated normal distribution\n * @param sigma standard deviation of the associated normal distribution\n * @returns\n */\nconst logNormalProbabilityDensity = (x: number, mu: number = defaultMu, sigma: number = defaultSigma): number => {\n if (x <= 0) return 0\n const logX = Math.log(x)\n return (1 / (x * sigma * Math.sqrt(2 * Math.PI))) * Math.exp(-0.5 * Math.pow((logX - mu) / sigma, 2))\n}\n\n/**\n * For a lognormal distribution, the peak of the distribution is the mode\n */\nconst maxProbabilityDensity = logNormalProbabilityDensity(mode)\n\nconst maxScore = 10\n\n/**\n * We're working on some assumptions here:\n * - If there's < 1000 NFTs in your collection it starts becoming too niche\n * - If there's > 20,000 NFTs in your collection it starts becoming too broad\n * So there's a sweet spot somewhere between 2000 and 10,000\n * where a collection has enough NFTs to be interesting, but\n * not so many that it's teetering on a diluted money grab.\n * To model that we're using a log-normal distribution optimized\n * to maximally reward collections in the aforementioned range\n * @param nft\n * @returns\n */\nexport const scoreTotal = (nft: NftCollectionCount): Score => {\n const density = logNormalProbabilityDensity(nft.total)\n const score: Score = [density, maxProbabilityDensity]\n return normalize(score, maxScore)\n}\n","import { NftCollectionInfo } from '@xyo-network/crypto-nft-collection-payload-plugin'\nimport { WeightedScoringCriteria } from '@xyo-network/crypto-nft-score-model'\n\nimport { scoreMetadata, scoreTotal } from './scoring'\n\nexport const scoringCriteria: { [key: string]: WeightedScoringCriteria<NftCollectionInfo> } = {\n ...scoreMetadata,\n Total: { score: scoreTotal, weight: 2 },\n}\n","import { NftCollectionInfo } from '@xyo-network/crypto-nft-collection-payload-plugin'\nimport { Score } from '@xyo-network/crypto-nft-score-model'\n\nimport { scoringCriteria } from './criteria'\n\nexport type ScoringCriteriaKey = keyof typeof scoringCriteria & PropertyKey\n\nexport type NftCollectionAnalysis = {\n [key in ScoringCriteriaKey]: Score\n}\n\nexport const analyzeNftCollection = async (\n /**\n * The NFT to evaluate\n */\n nft: NftCollectionInfo,\n): Promise<NftCollectionAnalysis> => {\n const result = Object.fromEntries(\n await Promise.all(\n Object.entries(scoringCriteria).map(async ([key, { score, weight }]) => {\n const rawScore = await score(nft)\n const weighted = rawScore.map((v) => v * weight) as Score\n return [key, weighted] as const\n }),\n ),\n ) as NftCollectionAnalysis\n return result\n}\n","import { NftSchema } from '@xyo-network/crypto-nft-payload-plugin'\nimport { PayloadSetSchema } from '@xyo-network/payload-model'\nimport { createPayloadSetDivinerPlugin } from '@xyo-network/payloadset-plugin'\n\nimport { NftCollectionScoreDiviner } from './Diviner'\n\nexport const NftCollectionScoreDivinerPlugin = () =>\n createPayloadSetDivinerPlugin<NftCollectionScoreDiviner>(\n { required: { [NftSchema]: 1 }, schema: PayloadSetSchema },\n {\n diviner: async (params) => {\n const result = await NftCollectionScoreDiviner.create(params)\n return result\n },\n },\n )\n"],"mappings":";AAAA,SAAS,uBAAuB;AAChC;AAAA,EACE;AAAA,EAKA;AAAA,EACA;AAAA,OACK;AAEP,SAAS,qBAAqB;;;ACV9B,SAAS,iBAAwB;AAEjC,IAAM,WAAW;AAEV,IAAM,4BAA4B,CAAC,SAA+C;AACvF,QAAM,EAAE,WAAW,IAAI,KAAK,QAAQ;AACpC,QAAM,UAAU,OAAO,QAAQ,UAAU;AACzC,MAAI,QAAQ,WAAW;AAAG,WAAO,CAAC,GAAG,QAAQ;AAC7C,QAAM,SAAS,OAAO,QAAQ,UAAU,EAAE,QAAQ,CAAC,CAAC,QAAQ,EAAE,OAAO,CAAC,MAAM;AAC1E,WAAO,OAAO,QAAQ,MAAM,EAAE,IAAW,CAAC,CAAC,aAAa,OAAO,MAAM;AACnE,YAAM,SAAS,KAAK,IAAI,KAAK,OAAO,IAAI,QAAQ,SAAS,KAAK,QAAQ,GAAG,QAAQ;AACjF,aAAO,CAAC,QAAQ,QAAQ;AAAA,IAC1B,CAAC;AAAA,EACH,CAAC;AAED,QAAM,QAAQ,OAAO,OAAc,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,GAAG,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;AAC7E,SAAO,UAAU,OAAO,QAAQ;AAClC;;;ACjBA,SAAS,aAAAA,kBAAwB;AAEjC,IAAMC,YAAW;AAKjB,IAAM,YAAY;AAKlB,IAAM,eAAe;AASrB,IAAM,6BAA6B,CAAC,GAAW,KAAa,WAAW,QAAgB,iBAAyB;AAC9G,QA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;AAAA,QAC3C,CAAC;AACD,eAAO,EAAE,GAAG,OAAO,QAAQ,0BAA0B,SAAS,CAAC,UAAU,EAAE;AAAA,MAC7E,CAAC;AAAA,IACH;AACA,WAAO;AAAA,EACT;AACF;;;AO7CA,SAAS,iBAAiB;AAC1B,SAAS,wBAAwB;AACjC,SAAS,qCAAqC;AAIvC,IAAM,kCAAkC,MAC7C;AAAA,EACE,EAAE,UAAU,EAAE,CAAC,SAAS,GAAG,EAAE,GAAG,QAAQ,iBAAiB;AAAA,EACzD;AAAA,IACE,SAAS,OAAO,WAAW;AACzB,YAAM,SAAS,MAAM,0BAA0B,OAAO,MAAM;AAC5D,aAAO;AAAA,IACT;AAAA,EACF;AACF;","names":["normalize","maxScore","normalize","defaultMu","defaultSigma","maxProbabilityDensity","maxScore"]}
|
package/dist/browser/lib/rating/criteria/scoring/metadata/scoreIndividualAttributes.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scoreIndividualAttributes.d.ts","sourceRoot":"","sources":["../../../../../../../src/lib/rating/criteria/scoring/metadata/scoreIndividualAttributes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,6BAA6B,EAAE,MAAM,mDAAmD,CAAA;AACjG,OAAO,EAAa,KAAK,EAAE,MAAM,qCAAqC,CAAA;AAItE,eAAO,MAAM,yBAAyB,SAAU,6BAA6B,KAAG,
|
|
1
|
+
{"version":3,"file":"scoreIndividualAttributes.d.ts","sourceRoot":"","sources":["../../../../../../../src/lib/rating/criteria/scoring/metadata/scoreIndividualAttributes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,6BAA6B,EAAE,MAAM,mDAAmD,CAAA;AACjG,OAAO,EAAa,KAAK,EAAE,MAAM,qCAAqC,CAAA;AAItE,eAAO,MAAM,yBAAyB,SAAU,6BAA6B,KAAG,KAa/E,CAAA"}
|
package/dist/browser/lib/rating/criteria/scoring/metadata/scoreIndividualAttributes.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scoreIndividualAttributes.d.ts","sourceRoot":"","sources":["../../../../../../../src/lib/rating/criteria/scoring/metadata/scoreIndividualAttributes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,6BAA6B,EAAE,MAAM,mDAAmD,CAAA;AACjG,OAAO,EAAa,KAAK,EAAE,MAAM,qCAAqC,CAAA;AAItE,eAAO,MAAM,yBAAyB,SAAU,6BAA6B,KAAG,
|
|
1
|
+
{"version":3,"file":"scoreIndividualAttributes.d.ts","sourceRoot":"","sources":["../../../../../../../src/lib/rating/criteria/scoring/metadata/scoreIndividualAttributes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,6BAA6B,EAAE,MAAM,mDAAmD,CAAA;AACjG,OAAO,EAAa,KAAK,EAAE,MAAM,qCAAqC,CAAA;AAItE,eAAO,MAAM,yBAAyB,SAAU,6BAA6B,KAAG,KAa/E,CAAA"}
|
package/dist/browser/lib/rating/criteria/scoring/metadata/scoreIndividualAttributes.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scoreIndividualAttributes.d.ts","sourceRoot":"","sources":["../../../../../../../src/lib/rating/criteria/scoring/metadata/scoreIndividualAttributes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,6BAA6B,EAAE,MAAM,mDAAmD,CAAA;AACjG,OAAO,EAAa,KAAK,EAAE,MAAM,qCAAqC,CAAA;AAItE,eAAO,MAAM,yBAAyB,SAAU,6BAA6B,KAAG,
|
|
1
|
+
{"version":3,"file":"scoreIndividualAttributes.d.ts","sourceRoot":"","sources":["../../../../../../../src/lib/rating/criteria/scoring/metadata/scoreIndividualAttributes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,6BAA6B,EAAE,MAAM,mDAAmD,CAAA;AACjG,OAAO,EAAa,KAAK,EAAE,MAAM,qCAAqC,CAAA;AAItE,eAAO,MAAM,yBAAyB,SAAU,6BAA6B,KAAG,KAa/E,CAAA"}
|
package/dist/node/Plugin.d.cts
CHANGED
|
@@ -2,7 +2,6 @@ import { NftCollectionScoreDiviner } from './Diviner';
|
|
|
2
2
|
export declare const NftCollectionScoreDivinerPlugin: () => import("@xyo-network/payloadset-plugin").PayloadSetDivinerPlugin<NftCollectionScoreDiviner<import("@xyo-network/object").BaseParamsFields & {
|
|
3
3
|
account?: import("@xyo-network/account-model").AccountInstance | "random" | undefined;
|
|
4
4
|
config: import("@xyo-network/payload-model").SchemaFields & object & Omit<{
|
|
5
|
-
accountPath?: string | undefined;
|
|
6
5
|
readonly archivist?: string | undefined;
|
|
7
6
|
readonly labels?: import("@xyo-network/module-model").Labels | undefined;
|
|
8
7
|
readonly name?: string | undefined;
|
|
@@ -19,7 +18,6 @@ export declare const NftCollectionScoreDivinerPlugin: () => import("@xyo-network
|
|
|
19
18
|
readonly storeQueries?: boolean | undefined;
|
|
20
19
|
readonly timestamp?: boolean | undefined;
|
|
21
20
|
} & import("@xyo-network/module-model").ArchivingModuleConfig & import("@xyo-network/payload-model").SchemaFields & object & {
|
|
22
|
-
accountPath?: string | undefined;
|
|
23
21
|
readonly archivist?: string | undefined;
|
|
24
22
|
readonly labels?: import("@xyo-network/module-model").Labels | undefined;
|
|
25
23
|
readonly name?: string | undefined;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Plugin.d.ts","sourceRoot":"","sources":["../../src/Plugin.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,yBAAyB,EAAE,MAAM,WAAW,CAAA;AAErD,eAAO,MAAM,+BAA+B
|
|
1
|
+
{"version":3,"file":"Plugin.d.ts","sourceRoot":"","sources":["../../src/Plugin.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,yBAAyB,EAAE,MAAM,WAAW,CAAA;AAErD,eAAO,MAAM,+BAA+B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GASzC,CAAA"}
|
package/dist/node/Plugin.d.mts
CHANGED
|
@@ -2,7 +2,6 @@ import { NftCollectionScoreDiviner } from './Diviner';
|
|
|
2
2
|
export declare const NftCollectionScoreDivinerPlugin: () => import("@xyo-network/payloadset-plugin").PayloadSetDivinerPlugin<NftCollectionScoreDiviner<import("@xyo-network/object").BaseParamsFields & {
|
|
3
3
|
account?: import("@xyo-network/account-model").AccountInstance | "random" | undefined;
|
|
4
4
|
config: import("@xyo-network/payload-model").SchemaFields & object & Omit<{
|
|
5
|
-
accountPath?: string | undefined;
|
|
6
5
|
readonly archivist?: string | undefined;
|
|
7
6
|
readonly labels?: import("@xyo-network/module-model").Labels | undefined;
|
|
8
7
|
readonly name?: string | undefined;
|
|
@@ -19,7 +18,6 @@ export declare const NftCollectionScoreDivinerPlugin: () => import("@xyo-network
|
|
|
19
18
|
readonly storeQueries?: boolean | undefined;
|
|
20
19
|
readonly timestamp?: boolean | undefined;
|
|
21
20
|
} & import("@xyo-network/module-model").ArchivingModuleConfig & import("@xyo-network/payload-model").SchemaFields & object & {
|
|
22
|
-
accountPath?: string | undefined;
|
|
23
21
|
readonly archivist?: string | undefined;
|
|
24
22
|
readonly labels?: import("@xyo-network/module-model").Labels | undefined;
|
|
25
23
|
readonly name?: string | undefined;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Plugin.d.ts","sourceRoot":"","sources":["../../src/Plugin.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,yBAAyB,EAAE,MAAM,WAAW,CAAA;AAErD,eAAO,MAAM,+BAA+B
|
|
1
|
+
{"version":3,"file":"Plugin.d.ts","sourceRoot":"","sources":["../../src/Plugin.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,yBAAyB,EAAE,MAAM,WAAW,CAAA;AAErD,eAAO,MAAM,+BAA+B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GASzC,CAAA"}
|
package/dist/node/Plugin.d.ts
CHANGED
|
@@ -2,7 +2,6 @@ import { NftCollectionScoreDiviner } from './Diviner';
|
|
|
2
2
|
export declare const NftCollectionScoreDivinerPlugin: () => import("@xyo-network/payloadset-plugin").PayloadSetDivinerPlugin<NftCollectionScoreDiviner<import("@xyo-network/object").BaseParamsFields & {
|
|
3
3
|
account?: import("@xyo-network/account-model").AccountInstance | "random" | undefined;
|
|
4
4
|
config: import("@xyo-network/payload-model").SchemaFields & object & Omit<{
|
|
5
|
-
accountPath?: string | undefined;
|
|
6
5
|
readonly archivist?: string | undefined;
|
|
7
6
|
readonly labels?: import("@xyo-network/module-model").Labels | undefined;
|
|
8
7
|
readonly name?: string | undefined;
|
|
@@ -19,7 +18,6 @@ export declare const NftCollectionScoreDivinerPlugin: () => import("@xyo-network
|
|
|
19
18
|
readonly storeQueries?: boolean | undefined;
|
|
20
19
|
readonly timestamp?: boolean | undefined;
|
|
21
20
|
} & import("@xyo-network/module-model").ArchivingModuleConfig & import("@xyo-network/payload-model").SchemaFields & object & {
|
|
22
|
-
accountPath?: string | undefined;
|
|
23
21
|
readonly archivist?: string | undefined;
|
|
24
22
|
readonly labels?: import("@xyo-network/module-model").Labels | undefined;
|
|
25
23
|
readonly name?: string | undefined;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Plugin.d.ts","sourceRoot":"","sources":["../../src/Plugin.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,yBAAyB,EAAE,MAAM,WAAW,CAAA;AAErD,eAAO,MAAM,+BAA+B
|
|
1
|
+
{"version":3,"file":"Plugin.d.ts","sourceRoot":"","sources":["../../src/Plugin.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,yBAAyB,EAAE,MAAM,WAAW,CAAA;AAErD,eAAO,MAAM,+BAA+B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GASzC,CAAA"}
|
package/dist/node/index.cjs
CHANGED
|
@@ -23,16 +23,11 @@ __export(src_exports, {
|
|
|
23
23
|
NftCollectionScoreDiviner: () => NftCollectionScoreDiviner,
|
|
24
24
|
NftCollectionScoreDivinerPlugin: () => NftCollectionScoreDivinerPlugin,
|
|
25
25
|
analyzeNftCollection: () => analyzeNftCollection,
|
|
26
|
-
default: () =>
|
|
26
|
+
default: () => NftCollectionScoreDivinerPlugin,
|
|
27
27
|
scoringCriteria: () => scoringCriteria
|
|
28
28
|
});
|
|
29
29
|
module.exports = __toCommonJS(src_exports);
|
|
30
30
|
|
|
31
|
-
// src/Plugin.ts
|
|
32
|
-
var import_crypto_nft_payload_plugin = require("@xyo-network/crypto-nft-payload-plugin");
|
|
33
|
-
var import_payload_model = require("@xyo-network/payload-model");
|
|
34
|
-
var import_payloadset_plugin = require("@xyo-network/payloadset-plugin");
|
|
35
|
-
|
|
36
31
|
// src/Diviner.ts
|
|
37
32
|
var import_abstract_diviner = require("@xyo-network/abstract-diviner");
|
|
38
33
|
var import_crypto_nft_collection_payload_plugin = require("@xyo-network/crypto-nft-collection-payload-plugin");
|
|
@@ -46,12 +41,12 @@ var scoreIndividualAttributes = (info) => {
|
|
|
46
41
|
const entries = Object.entries(attributes);
|
|
47
42
|
if (entries.length === 0)
|
|
48
43
|
return [0, maxScore];
|
|
49
|
-
const scores = Object.entries(attributes).
|
|
44
|
+
const scores = Object.entries(attributes).flatMap(([_trait, { values }]) => {
|
|
50
45
|
return Object.entries(values).map(([_traitValue, metrics]) => {
|
|
51
46
|
const rarity = Math.min(Math.round((1 - metrics.binomial.p) * maxScore), maxScore);
|
|
52
47
|
return [rarity, maxScore];
|
|
53
48
|
});
|
|
54
|
-
})
|
|
49
|
+
});
|
|
55
50
|
const total = scores.reduce(([a, b], [c, d]) => [a + c, b + d], [0, 0]);
|
|
56
51
|
return (0, import_crypto_nft_score_model.normalize)(total, maxScore);
|
|
57
52
|
};
|
|
@@ -153,6 +148,9 @@ var NftCollectionScoreDiviner = class extends import_abstract_diviner.AbstractDi
|
|
|
153
148
|
};
|
|
154
149
|
|
|
155
150
|
// src/Plugin.ts
|
|
151
|
+
var import_crypto_nft_payload_plugin = require("@xyo-network/crypto-nft-payload-plugin");
|
|
152
|
+
var import_payload_model = require("@xyo-network/payload-model");
|
|
153
|
+
var import_payloadset_plugin = require("@xyo-network/payloadset-plugin");
|
|
156
154
|
var NftCollectionScoreDivinerPlugin = () => (0, import_payloadset_plugin.createPayloadSetDivinerPlugin)(
|
|
157
155
|
{ required: { [import_crypto_nft_payload_plugin.NftSchema]: 1 }, schema: import_payload_model.PayloadSetSchema },
|
|
158
156
|
{
|
|
@@ -162,9 +160,6 @@ var NftCollectionScoreDivinerPlugin = () => (0, import_payloadset_plugin.createP
|
|
|
162
160
|
}
|
|
163
161
|
}
|
|
164
162
|
);
|
|
165
|
-
|
|
166
|
-
// src/index.ts
|
|
167
|
-
var src_default = NftCollectionScoreDivinerPlugin;
|
|
168
163
|
// Annotate the CommonJS export names for ESM import in node:
|
|
169
164
|
0 && (module.exports = {
|
|
170
165
|
NftCollectionScoreDiviner,
|
package/dist/node/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/index.ts","../../src/Plugin.ts","../../src/Diviner.ts","../../src/lib/rating/criteria/scoring/metadata/scoreIndividualAttributes.ts","../../src/lib/rating/criteria/scoring/metadata/scoreTotalAttributes.ts","../../src/lib/rating/criteria/scoring/metadata/metadata.ts","../../src/lib/rating/criteria/scoring/total.ts","../../src/lib/rating/criteria/index.ts","../../src/lib/rating/analyzeNftCollection.ts"],"sourcesContent":["import { NftCollectionScoreDivinerPlugin } from './Plugin'\n\nexport * from './Diviner'\nexport * from './lib'\n\nexport { NftCollectionScoreDivinerPlugin }\n\n// eslint-disable-next-line import/no-default-export\nexport default NftCollectionScoreDivinerPlugin\n","import { NftSchema } from '@xyo-network/crypto-nft-payload-plugin'\nimport { PayloadSetSchema } from '@xyo-network/payload-model'\nimport { createPayloadSetDivinerPlugin } from '@xyo-network/payloadset-plugin'\n\nimport { NftCollectionScoreDiviner } from './Diviner'\n\nexport const NftCollectionScoreDivinerPlugin = () =>\n createPayloadSetDivinerPlugin<NftCollectionScoreDiviner>(\n { required: { [NftSchema]: 1 }, schema: PayloadSetSchema },\n {\n diviner: async (params) => {\n const result = await NftCollectionScoreDiviner.create(params)\n return result\n },\n },\n )\n","import { AbstractDiviner } from '@xyo-network/abstract-diviner'\nimport {\n isNftCollectionInfo,\n NftCollectionInfo,\n NftCollectionMetadata,\n NftCollectionScore,\n NftCollectionScoreDivinerConfig,\n NftCollectionScoreDivinerConfigSchema,\n NftCollectionScoreSchema,\n} from '@xyo-network/crypto-nft-collection-payload-plugin'\nimport { DivinerParams } from '@xyo-network/diviner-model'\nimport { PayloadHasher } from '@xyo-network/hash'\nimport { AnyConfigSchema } from '@xyo-network/module-model'\nimport { Payload } from '@xyo-network/payload-model'\n\nimport { analyzeNftCollection, NftCollectionAnalysis } from './lib'\n\nexport type NftCollectionScoreDivinerParams = DivinerParams<AnyConfigSchema<NftCollectionScoreDivinerConfig>>\n\nconst toNftCollectionScore = (nftCollectionInfo: NftCollectionInfo, scores: NftCollectionAnalysis): NftCollectionScore => {\n const { name, symbol, address, chainId, type } = nftCollectionInfo\n const metadata: NftCollectionMetadata = { address, chainId, name, symbol, type }\n return { ...metadata, schema: NftCollectionScoreSchema, scores }\n}\n\nexport class NftCollectionScoreDiviner<\n TParams extends NftCollectionScoreDivinerParams = NftCollectionScoreDivinerParams,\n> extends AbstractDiviner<TParams> {\n static override configSchemas = [NftCollectionScoreDivinerConfigSchema]\n\n protected override divineHandler = async (payloads?: Payload[]): Promise<Payload[]> => {\n const nftCollectionInfos = payloads?.filter(isNftCollectionInfo) ?? []\n const results = await Promise.all(\n nftCollectionInfos.map<Promise<NftCollectionScore>>(async (nftCollectionInfo) => {\n const [score, sourceHash] = await Promise.all([\n // Get score\n toNftCollectionScore(nftCollectionInfo, await analyzeNftCollection(nftCollectionInfo)),\n // Hash sources\n PayloadHasher.hashAsync(nftCollectionInfo),\n ])\n return { ...score, schema: NftCollectionScoreSchema, sources: [sourceHash] } as NftCollectionScore\n }),\n )\n return results\n }\n}\n","import { NftCollectionAttributeMetrics } from '@xyo-network/crypto-nft-collection-payload-plugin'\nimport { normalize, Score } from '@xyo-network/crypto-nft-score-model'\n\nconst maxScore = 10\n\nexport const scoreIndividualAttributes = (info: NftCollectionAttributeMetrics): Score => {\n const { attributes } = info.metrics.metadata\n const entries = Object.entries(attributes)\n if (entries.length === 0) return [0, maxScore]\n const scores = Object.entries(attributes)\n .map(([_trait, { values }]) => {\n return Object.entries(values).map<Score>(([_traitValue, metrics]) => {\n const rarity = Math.min(Math.round((1 - metrics.binomial.p) * maxScore), maxScore)\n return [rarity, maxScore]\n })\n })\n .flat()\n const total = scores.reduce<Score>(([a, b], [c, d]) => [a + c, b + d], [0, 0])\n return normalize(total, maxScore)\n}\n","import { NftCollectionAttributeMetrics } from '@xyo-network/crypto-nft-collection-payload-plugin'\nimport { normalize, Score } from '@xyo-network/crypto-nft-score-model'\n\nconst maxScore = 10\n\n/**\n * Mean: What value is the distribution centered around\n */\nconst defaultMu = 0.15\n\n/**\n * Standard Deviation: How spread out is the distribution\n */\nconst defaultSigma = 0.1\n\n/**\n * Calculates the Gaussian probability density\n * @param x\n * @param mu Mean\n * @param sigma Standard Deviation\n * @returns\n */\nconst gaussianProbabilityDensity = (x: number, mu: number = defaultMu, sigma: number = defaultSigma): number => {\n const sqrtTwoPi = Math.sqrt(2 * Math.PI)\n const denominator = sigma * sqrtTwoPi\n const power = -0.5 * Math.pow((x - mu) / sigma, 2)\n return (1 / denominator) * Math.exp(power)\n}\n\n/**\n * For a Gaussian distribution, the peak of the distribution is the mean\n */\nconst maxProbabilityDensity = gaussianProbabilityDensity(defaultMu)\n\n/**\n * We're working on some assumptions here:\n *\n * - If you have a 100% chance of getting a trait, everyone get's a trophy\n * - If you have a 50% chance of getting a trait, it's not rare\n * - If you have a 0% chance of getting a trait, it's not fun\n *\n * So we're looking for something Pareto-ish (somewhere between\n * 80/20 or 90/10) as that's a good & sustainable model for the\n * distribution of many traits in real life.\n * However, we also don't want to maximally reward collections\n * that have a lot of single attributes distributed uniformly\n * (basically a 0% trait probably) as that's perfectly entropic\n * but not very interesting (some overlap is desirable).\n * So we're using a Gaussian distribution to model the\n * probability density of the joint probability of all traits\n * centered around 15%.\n * @param info\n * @returns\n */\nexport const scoreTotalAttributes = (info: NftCollectionAttributeMetrics): Score => {\n const { attributes } = info.metrics.metadata\n // This has somewhat of a filtering function by causing anything with 100% probability to\n // add no value to the end score\n const jointProbability = Object.entries(attributes).reduce((acc, [_trait, { metrics }]) => {\n return acc * metrics.binomial.p\n }, 1)\n const probabilityDensity = gaussianProbabilityDensity(jointProbability)\n const score: Score = [probabilityDensity, maxProbabilityDensity]\n return normalize(score, maxScore)\n}\n","import { NftCollectionInfo } from '@xyo-network/crypto-nft-collection-payload-plugin'\nimport { WeightedScoringCriteria } from '@xyo-network/crypto-nft-score-model'\n\nimport { scoreIndividualAttributes } from './scoreIndividualAttributes'\nimport { scoreTotalAttributes } from './scoreTotalAttributes'\n\nexport const attributeScoringCriteria: { [key: string]: WeightedScoringCriteria<NftCollectionInfo> } = {\n 'Metadata Attributes Individual': { score: scoreIndividualAttributes, weight: 2 },\n 'Metadata Attributes Total': { score: scoreTotalAttributes, weight: 2 },\n}\n\nexport const scoreMetadata: { [key: string]: WeightedScoringCriteria<NftCollectionInfo> } = {\n ...attributeScoringCriteria,\n}\n","import { NftCollectionCount } from '@xyo-network/crypto-nft-collection-payload-plugin'\nimport { normalize, Score } from '@xyo-network/crypto-nft-score-model'\n\n/**\n * This \"magic\" value was obtained using Solver in Excel\n * to find the median, with mu/sigma fixed, which maximizes\n * the distribution (the mode for lognormal) at 10,000\n */\nconst median = 81030839.8217352\nconst defaultMu = Math.log(median)\nconst defaultSigma = 3\nconst mode = Math.exp(defaultMu - Math.pow(defaultSigma, 2))\n/**\n * Calculates the log-normal probability density\n * @param x the value at which you want to calculate the probability density\n * @param mu mean of the associated normal distribution\n * @param sigma standard deviation of the associated normal distribution\n * @returns\n */\nconst logNormalProbabilityDensity = (x: number, mu: number = defaultMu, sigma: number = defaultSigma): number => {\n if (x <= 0) return 0\n const logX = Math.log(x)\n return (1 / (x * sigma * Math.sqrt(2 * Math.PI))) * Math.exp(-0.5 * Math.pow((logX - mu) / sigma, 2))\n}\n\n/**\n * For a lognormal distribution, the peak of the distribution is the mode\n */\nconst maxProbabilityDensity = logNormalProbabilityDensity(mode)\n\nconst maxScore = 10\n\n/**\n * We're working on some assumptions here:\n * - If there's < 1000 NFTs in your collection it starts becoming too niche\n * - If there's > 20,000 NFTs in your collection it starts becoming too broad\n * So there's a sweet spot somewhere between 2000 and 10,000\n * where a collection has enough NFTs to be interesting, but\n * not so many that it's teetering on a diluted money grab.\n * To model that we're using a log-normal distribution optimized\n * to maximally reward collections in the aforementioned range\n * @param nft\n * @returns\n */\nexport const scoreTotal = (nft: NftCollectionCount): Score => {\n const density = logNormalProbabilityDensity(nft.total)\n const score: Score = [density, maxProbabilityDensity]\n return normalize(score, maxScore)\n}\n","import { NftCollectionInfo } from '@xyo-network/crypto-nft-collection-payload-plugin'\nimport { WeightedScoringCriteria } from '@xyo-network/crypto-nft-score-model'\n\nimport { scoreMetadata, scoreTotal } from './scoring'\n\nexport const scoringCriteria: { [key: string]: WeightedScoringCriteria<NftCollectionInfo> } = {\n ...scoreMetadata,\n Total: { score: scoreTotal, weight: 2 },\n}\n","import { NftCollectionInfo } from '@xyo-network/crypto-nft-collection-payload-plugin'\nimport { Score } from '@xyo-network/crypto-nft-score-model'\n\nimport { scoringCriteria } from './criteria'\n\nexport type ScoringCriteriaKey = keyof typeof scoringCriteria & PropertyKey\n\nexport type NftCollectionAnalysis = {\n [key in ScoringCriteriaKey]: Score\n}\n\nexport const analyzeNftCollection = async (\n /**\n * The NFT to evaluate\n */\n nft: NftCollectionInfo,\n): Promise<NftCollectionAnalysis> => {\n const result = Object.fromEntries(\n await Promise.all(\n Object.entries(scoringCriteria).map(async ([key, { score, weight }]) => {\n const rawScore = await score(nft)\n const weighted = rawScore.map((v) => v * weight) as Score\n return [key, weighted] as const\n }),\n ),\n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,IAAM,kCAAkC,UAC7C;AAAA,EACE,EAAE,UAAU,EAAE,CAAC,0CAAS,GAAG,EAAE,GAAG,QAAQ,sCAAiB;AAAA,EACzD;AAAA,IACE,SAAS,OAAO,WAAW;AACzB,YAAM,SAAS,MAAM,0BAA0B,OAAO,MAAM;AAC5D,aAAO;AAAA,IACT;AAAA,EACF;AACF;;;ADPF,IAAO,cAAQ;","names":["import_crypto_nft_score_model","maxScore","import_crypto_nft_score_model","defaultMu","defaultSigma","maxProbabilityDensity","maxScore"]}
|
|
1
|
+
{"version":3,"sources":["../../src/index.ts","../../src/Diviner.ts","../../src/lib/rating/criteria/scoring/metadata/scoreIndividualAttributes.ts","../../src/lib/rating/criteria/scoring/metadata/scoreTotalAttributes.ts","../../src/lib/rating/criteria/scoring/metadata/metadata.ts","../../src/lib/rating/criteria/scoring/total.ts","../../src/lib/rating/criteria/index.ts","../../src/lib/rating/analyzeNftCollection.ts","../../src/Plugin.ts"],"sourcesContent":["export * from './Diviner'\nexport * from './lib'\nexport { NftCollectionScoreDivinerPlugin as default, NftCollectionScoreDivinerPlugin } from './Plugin'\n","import { AbstractDiviner } from '@xyo-network/abstract-diviner'\nimport {\n isNftCollectionInfo,\n NftCollectionInfo,\n NftCollectionMetadata,\n NftCollectionScore,\n NftCollectionScoreDivinerConfig,\n NftCollectionScoreDivinerConfigSchema,\n NftCollectionScoreSchema,\n} from '@xyo-network/crypto-nft-collection-payload-plugin'\nimport { DivinerParams } from '@xyo-network/diviner-model'\nimport { PayloadHasher } from '@xyo-network/hash'\nimport { AnyConfigSchema } from '@xyo-network/module-model'\nimport { Payload } from '@xyo-network/payload-model'\n\nimport { analyzeNftCollection, NftCollectionAnalysis } from './lib'\n\nexport type NftCollectionScoreDivinerParams = DivinerParams<AnyConfigSchema<NftCollectionScoreDivinerConfig>>\n\nconst toNftCollectionScore = (nftCollectionInfo: NftCollectionInfo, scores: NftCollectionAnalysis): NftCollectionScore => {\n const { name, symbol, address, chainId, type } = nftCollectionInfo\n const metadata: NftCollectionMetadata = { address, chainId, name, symbol, type }\n return { ...metadata, schema: NftCollectionScoreSchema, scores }\n}\n\nexport class NftCollectionScoreDiviner<\n TParams extends NftCollectionScoreDivinerParams = NftCollectionScoreDivinerParams,\n> extends AbstractDiviner<TParams> {\n static override configSchemas = [NftCollectionScoreDivinerConfigSchema]\n\n protected override divineHandler = async (payloads?: Payload[]): Promise<Payload[]> => {\n const nftCollectionInfos = payloads?.filter(isNftCollectionInfo) ?? []\n const results = await Promise.all(\n nftCollectionInfos.map<Promise<NftCollectionScore>>(async (nftCollectionInfo) => {\n const [score, sourceHash] = await Promise.all([\n // Get score\n toNftCollectionScore(nftCollectionInfo, await analyzeNftCollection(nftCollectionInfo)),\n // Hash sources\n PayloadHasher.hashAsync(nftCollectionInfo),\n ])\n return { ...score, schema: NftCollectionScoreSchema, sources: [sourceHash] } as NftCollectionScore\n }),\n )\n return results\n }\n}\n","import { NftCollectionAttributeMetrics } from '@xyo-network/crypto-nft-collection-payload-plugin'\nimport { normalize, Score } from '@xyo-network/crypto-nft-score-model'\n\nconst maxScore = 10\n\nexport const scoreIndividualAttributes = (info: NftCollectionAttributeMetrics): Score => {\n const { attributes } = info.metrics.metadata\n const entries = Object.entries(attributes)\n if (entries.length === 0) return [0, maxScore]\n const scores = Object.entries(attributes).flatMap(([_trait, { values }]) => {\n return Object.entries(values).map<Score>(([_traitValue, metrics]) => {\n const rarity = Math.min(Math.round((1 - metrics.binomial.p) * maxScore), maxScore)\n return [rarity, maxScore]\n })\n })\n // eslint-disable-next-line unicorn/no-array-reduce\n const total = scores.reduce<Score>(([a, b], [c, d]) => [a + c, b + d], [0, 0])\n return normalize(total, maxScore)\n}\n","import { NftCollectionAttributeMetrics } from '@xyo-network/crypto-nft-collection-payload-plugin'\nimport { normalize, Score } from '@xyo-network/crypto-nft-score-model'\n\nconst maxScore = 10\n\n/**\n * Mean: What value is the distribution centered around\n */\nconst defaultMu = 0.15\n\n/**\n * Standard Deviation: How spread out is the distribution\n */\nconst defaultSigma = 0.1\n\n/**\n * Calculates the Gaussian probability density\n * @param x\n * @param mu Mean\n * @param sigma Standard Deviation\n * @returns\n */\nconst gaussianProbabilityDensity = (x: number, mu: number = defaultMu, sigma: number = defaultSigma): number => {\n const sqrtTwoPi = Math.sqrt(2 * Math.PI)\n const denominator = sigma * sqrtTwoPi\n const power = -0.5 * Math.pow((x - mu) / sigma, 2)\n return (1 / denominator) * Math.exp(power)\n}\n\n/**\n * For a Gaussian distribution, the peak of the distribution is the mean\n */\nconst maxProbabilityDensity = gaussianProbabilityDensity(defaultMu)\n\n/**\n * We're working on some assumptions here:\n *\n * - If you have a 100% chance of getting a trait, everyone get's a trophy\n * - If you have a 50% chance of getting a trait, it's not rare\n * - If you have a 0% chance of getting a trait, it's not fun\n *\n * So we're looking for something Pareto-ish (somewhere between\n * 80/20 or 90/10) as that's a good & sustainable model for the\n * distribution of many traits in real life.\n * However, we also don't want to maximally reward collections\n * that have a lot of single attributes distributed uniformly\n * (basically a 0% trait probably) as that's perfectly entropic\n * but not very interesting (some overlap is desirable).\n * So we're using a Gaussian distribution to model the\n * probability density of the joint probability of all traits\n * centered around 15%.\n * @param info\n * @returns\n */\nexport const scoreTotalAttributes = (info: NftCollectionAttributeMetrics): Score => {\n const { attributes } = info.metrics.metadata\n // This has somewhat of a filtering function by causing anything with 100% probability to\n // add no value to the end score\n const jointProbability = Object.entries(attributes).reduce((acc, [_trait, { metrics }]) => {\n return acc * metrics.binomial.p\n }, 1)\n const probabilityDensity = gaussianProbabilityDensity(jointProbability)\n const score: Score = [probabilityDensity, maxProbabilityDensity]\n return normalize(score, maxScore)\n}\n","import { NftCollectionInfo } from '@xyo-network/crypto-nft-collection-payload-plugin'\nimport { WeightedScoringCriteria } from '@xyo-network/crypto-nft-score-model'\n\nimport { scoreIndividualAttributes } from './scoreIndividualAttributes'\nimport { scoreTotalAttributes } from './scoreTotalAttributes'\n\nexport const attributeScoringCriteria: { [key: string]: WeightedScoringCriteria<NftCollectionInfo> } = {\n 'Metadata Attributes Individual': { score: scoreIndividualAttributes, weight: 2 },\n 'Metadata Attributes Total': { score: scoreTotalAttributes, weight: 2 },\n}\n\nexport const scoreMetadata: { [key: string]: WeightedScoringCriteria<NftCollectionInfo> } = {\n ...attributeScoringCriteria,\n}\n","import { NftCollectionCount } from '@xyo-network/crypto-nft-collection-payload-plugin'\nimport { normalize, Score } from '@xyo-network/crypto-nft-score-model'\n\n/**\n * This \"magic\" value was obtained using Solver in Excel\n * to find the median, with mu/sigma fixed, which maximizes\n * the distribution (the mode for lognormal) at 10,000\n */\nconst median = 81_030_839.821_735_2\nconst defaultMu = Math.log(median)\nconst defaultSigma = 3\nconst mode = Math.exp(defaultMu - Math.pow(defaultSigma, 2))\n/**\n * Calculates the log-normal probability density\n * @param x the value at which you want to calculate the probability density\n * @param mu mean of the associated normal distribution\n * @param sigma standard deviation of the associated normal distribution\n * @returns\n */\nconst logNormalProbabilityDensity = (x: number, mu: number = defaultMu, sigma: number = defaultSigma): number => {\n if (x <= 0) return 0\n const logX = Math.log(x)\n return (1 / (x * sigma * Math.sqrt(2 * Math.PI))) * Math.exp(-0.5 * Math.pow((logX - mu) / sigma, 2))\n}\n\n/**\n * For a lognormal distribution, the peak of the distribution is the mode\n */\nconst maxProbabilityDensity = logNormalProbabilityDensity(mode)\n\nconst maxScore = 10\n\n/**\n * We're working on some assumptions here:\n * - If there's < 1000 NFTs in your collection it starts becoming too niche\n * - If there's > 20,000 NFTs in your collection it starts becoming too broad\n * So there's a sweet spot somewhere between 2000 and 10,000\n * where a collection has enough NFTs to be interesting, but\n * not so many that it's teetering on a diluted money grab.\n * To model that we're using a log-normal distribution optimized\n * to maximally reward collections in the aforementioned range\n * @param nft\n * @returns\n */\nexport const scoreTotal = (nft: NftCollectionCount): Score => {\n const density = logNormalProbabilityDensity(nft.total)\n const score: Score = [density, maxProbabilityDensity]\n return normalize(score, maxScore)\n}\n","import { NftCollectionInfo } from '@xyo-network/crypto-nft-collection-payload-plugin'\nimport { WeightedScoringCriteria } from '@xyo-network/crypto-nft-score-model'\n\nimport { scoreMetadata, scoreTotal } from './scoring'\n\nexport const scoringCriteria: { [key: string]: WeightedScoringCriteria<NftCollectionInfo> } = {\n ...scoreMetadata,\n Total: { score: scoreTotal, weight: 2 },\n}\n","import { NftCollectionInfo } from '@xyo-network/crypto-nft-collection-payload-plugin'\nimport { Score } from '@xyo-network/crypto-nft-score-model'\n\nimport { scoringCriteria } from './criteria'\n\nexport type ScoringCriteriaKey = keyof typeof scoringCriteria & PropertyKey\n\nexport type NftCollectionAnalysis = {\n [key in ScoringCriteriaKey]: Score\n}\n\nexport const analyzeNftCollection = async (\n /**\n * The NFT to evaluate\n */\n nft: NftCollectionInfo,\n): Promise<NftCollectionAnalysis> => {\n const result = Object.fromEntries(\n await Promise.all(\n Object.entries(scoringCriteria).map(async ([key, { score, weight }]) => {\n const rawScore = await score(nft)\n const weighted = rawScore.map((v) => v * weight) as Score\n return [key, weighted] as const\n }),\n ),\n ) as NftCollectionAnalysis\n return result\n}\n","import { NftSchema } from '@xyo-network/crypto-nft-payload-plugin'\nimport { PayloadSetSchema } from '@xyo-network/payload-model'\nimport { createPayloadSetDivinerPlugin } from '@xyo-network/payloadset-plugin'\n\nimport { NftCollectionScoreDiviner } from './Diviner'\n\nexport const NftCollectionScoreDivinerPlugin = () =>\n createPayloadSetDivinerPlugin<NftCollectionScoreDiviner>(\n { required: { [NftSchema]: 1 }, schema: PayloadSetSchema },\n {\n diviner: async (params) => {\n const result = await NftCollectionScoreDiviner.create(params)\n return result\n },\n },\n )\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,8BAAgC;AAChC,kDAQO;AAEP,kBAA8B;;;ACV9B,oCAAiC;AAEjC,IAAM,WAAW;AAEV,IAAM,4BAA4B,CAAC,SAA+C;AACvF,QAAM,EAAE,WAAW,IAAI,KAAK,QAAQ;AACpC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ityDensity","maxScore"]}
|
package/dist/node/index.d.cts
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
import { NftCollectionScoreDivinerPlugin } from './Plugin';
|
|
2
1
|
export * from './Diviner';
|
|
3
2
|
export * from './lib';
|
|
4
|
-
export { NftCollectionScoreDivinerPlugin };
|
|
5
|
-
export default NftCollectionScoreDivinerPlugin;
|
|
3
|
+
export { NftCollectionScoreDivinerPlugin as default, NftCollectionScoreDivinerPlugin } from './Plugin';
|
|
6
4
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAA;AACzB,cAAc,OAAO,CAAA;AACrB,OAAO,EAAE,+BAA+B,IAAI,OAAO,EAAE,+BAA+B,EAAE,MAAM,UAAU,CAAA"}
|
package/dist/node/index.d.mts
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
import { NftCollectionScoreDivinerPlugin } from './Plugin';
|
|
2
1
|
export * from './Diviner';
|
|
3
2
|
export * from './lib';
|
|
4
|
-
export { NftCollectionScoreDivinerPlugin };
|
|
5
|
-
export default NftCollectionScoreDivinerPlugin;
|
|
3
|
+
export { NftCollectionScoreDivinerPlugin as default, NftCollectionScoreDivinerPlugin } from './Plugin';
|
|
6
4
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAA;AACzB,cAAc,OAAO,CAAA;AACrB,OAAO,EAAE,+BAA+B,IAAI,OAAO,EAAE,+BAA+B,EAAE,MAAM,UAAU,CAAA"}
|
package/dist/node/index.d.ts
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
import { NftCollectionScoreDivinerPlugin } from './Plugin';
|
|
2
1
|
export * from './Diviner';
|
|
3
2
|
export * from './lib';
|
|
4
|
-
export { NftCollectionScoreDivinerPlugin };
|
|
5
|
-
export default NftCollectionScoreDivinerPlugin;
|
|
3
|
+
export { NftCollectionScoreDivinerPlugin as default, NftCollectionScoreDivinerPlugin } from './Plugin';
|
|
6
4
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/node/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAA;AACzB,cAAc,OAAO,CAAA;AACrB,OAAO,EAAE,+BAA+B,IAAI,OAAO,EAAE,+BAA+B,EAAE,MAAM,UAAU,CAAA"}
|
package/dist/node/index.js
CHANGED
|
@@ -1,8 +1,3 @@
|
|
|
1
|
-
// src/Plugin.ts
|
|
2
|
-
import { NftSchema } from "@xyo-network/crypto-nft-payload-plugin";
|
|
3
|
-
import { PayloadSetSchema } from "@xyo-network/payload-model";
|
|
4
|
-
import { createPayloadSetDivinerPlugin } from "@xyo-network/payloadset-plugin";
|
|
5
|
-
|
|
6
1
|
// src/Diviner.ts
|
|
7
2
|
import { AbstractDiviner } from "@xyo-network/abstract-diviner";
|
|
8
3
|
import {
|
|
@@ -20,12 +15,12 @@ var scoreIndividualAttributes = (info) => {
|
|
|
20
15
|
const entries = Object.entries(attributes);
|
|
21
16
|
if (entries.length === 0)
|
|
22
17
|
return [0, maxScore];
|
|
23
|
-
const scores = Object.entries(attributes).
|
|
18
|
+
const scores = Object.entries(attributes).flatMap(([_trait, { values }]) => {
|
|
24
19
|
return Object.entries(values).map(([_traitValue, metrics]) => {
|
|
25
20
|
const rarity = Math.min(Math.round((1 - metrics.binomial.p) * maxScore), maxScore);
|
|
26
21
|
return [rarity, maxScore];
|
|
27
22
|
});
|
|
28
|
-
})
|
|
23
|
+
});
|
|
29
24
|
const total = scores.reduce(([a, b], [c, d]) => [a + c, b + d], [0, 0]);
|
|
30
25
|
return normalize(total, maxScore);
|
|
31
26
|
};
|
|
@@ -127,6 +122,9 @@ var NftCollectionScoreDiviner = class extends AbstractDiviner {
|
|
|
127
122
|
};
|
|
128
123
|
|
|
129
124
|
// src/Plugin.ts
|
|
125
|
+
import { NftSchema } from "@xyo-network/crypto-nft-payload-plugin";
|
|
126
|
+
import { PayloadSetSchema } from "@xyo-network/payload-model";
|
|
127
|
+
import { createPayloadSetDivinerPlugin } from "@xyo-network/payloadset-plugin";
|
|
130
128
|
var NftCollectionScoreDivinerPlugin = () => createPayloadSetDivinerPlugin(
|
|
131
129
|
{ required: { [NftSchema]: 1 }, schema: PayloadSetSchema },
|
|
132
130
|
{
|
|
@@ -136,14 +134,11 @@ var NftCollectionScoreDivinerPlugin = () => createPayloadSetDivinerPlugin(
|
|
|
136
134
|
}
|
|
137
135
|
}
|
|
138
136
|
);
|
|
139
|
-
|
|
140
|
-
// src/index.ts
|
|
141
|
-
var src_default = NftCollectionScoreDivinerPlugin;
|
|
142
137
|
export {
|
|
143
138
|
NftCollectionScoreDiviner,
|
|
144
139
|
NftCollectionScoreDivinerPlugin,
|
|
145
140
|
analyzeNftCollection,
|
|
146
|
-
|
|
141
|
+
NftCollectionScoreDivinerPlugin as default,
|
|
147
142
|
scoringCriteria
|
|
148
143
|
};
|
|
149
144
|
//# sourceMappingURL=index.js.map
|
package/dist/node/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/Plugin.ts","../../src/Diviner.ts","../../src/lib/rating/criteria/scoring/metadata/scoreIndividualAttributes.ts","../../src/lib/rating/criteria/scoring/metadata/scoreTotalAttributes.ts","../../src/lib/rating/criteria/scoring/metadata/metadata.ts","../../src/lib/rating/criteria/scoring/total.ts","../../src/lib/rating/criteria/index.ts","../../src/lib/rating/analyzeNftCollection.ts","../../src/index.ts"],"sourcesContent":["import { NftSchema } from '@xyo-network/crypto-nft-payload-plugin'\nimport { PayloadSetSchema } from '@xyo-network/payload-model'\nimport { createPayloadSetDivinerPlugin } from '@xyo-network/payloadset-plugin'\n\nimport { NftCollectionScoreDiviner } from './Diviner'\n\nexport const NftCollectionScoreDivinerPlugin = () =>\n createPayloadSetDivinerPlugin<NftCollectionScoreDiviner>(\n { required: { [NftSchema]: 1 }, schema: PayloadSetSchema },\n {\n diviner: async (params) => {\n const result = await NftCollectionScoreDiviner.create(params)\n return result\n },\n },\n )\n","import { AbstractDiviner } from '@xyo-network/abstract-diviner'\nimport {\n isNftCollectionInfo,\n NftCollectionInfo,\n NftCollectionMetadata,\n NftCollectionScore,\n NftCollectionScoreDivinerConfig,\n NftCollectionScoreDivinerConfigSchema,\n NftCollectionScoreSchema,\n} from '@xyo-network/crypto-nft-collection-payload-plugin'\nimport { DivinerParams } from '@xyo-network/diviner-model'\nimport { PayloadHasher } from '@xyo-network/hash'\nimport { AnyConfigSchema } from '@xyo-network/module-model'\nimport { Payload } from '@xyo-network/payload-model'\n\nimport { analyzeNftCollection, NftCollectionAnalysis } from './lib'\n\nexport type NftCollectionScoreDivinerParams = DivinerParams<AnyConfigSchema<NftCollectionScoreDivinerConfig>>\n\nconst toNftCollectionScore = (nftCollectionInfo: NftCollectionInfo, scores: NftCollectionAnalysis): NftCollectionScore => {\n const { name, symbol, address, chainId, type } = nftCollectionInfo\n const metadata: NftCollectionMetadata = { address, chainId, name, symbol, type }\n return { ...metadata, schema: NftCollectionScoreSchema, scores }\n}\n\nexport class NftCollectionScoreDiviner<\n TParams extends NftCollectionScoreDivinerParams = NftCollectionScoreDivinerParams,\n> extends AbstractDiviner<TParams> {\n static override configSchemas = [NftCollectionScoreDivinerConfigSchema]\n\n protected override divineHandler = async (payloads?: Payload[]): Promise<Payload[]> => {\n const nftCollectionInfos = payloads?.filter(isNftCollectionInfo) ?? []\n const results = await Promise.all(\n nftCollectionInfos.map<Promise<NftCollectionScore>>(async (nftCollectionInfo) => {\n const [score, sourceHash] = await Promise.all([\n // Get score\n toNftCollectionScore(nftCollectionInfo, await analyzeNftCollection(nftCollectionInfo)),\n // Hash sources\n PayloadHasher.hashAsync(nftCollectionInfo),\n ])\n return { ...score, schema: NftCollectionScoreSchema, sources: [sourceHash] } as NftCollectionScore\n }),\n )\n return results\n }\n}\n","import { NftCollectionAttributeMetrics } from '@xyo-network/crypto-nft-collection-payload-plugin'\nimport { normalize, Score } from '@xyo-network/crypto-nft-score-model'\n\nconst maxScore = 10\n\nexport const scoreIndividualAttributes = (info: NftCollectionAttributeMetrics): Score => {\n const { attributes } = info.metrics.metadata\n const entries = Object.entries(attributes)\n if (entries.length === 0) return [0, maxScore]\n const scores = Object.entries(attributes)\n .map(([_trait, { values }]) => {\n return Object.entries(values).map<Score>(([_traitValue, metrics]) => {\n const rarity = Math.min(Math.round((1 - metrics.binomial.p) * maxScore), maxScore)\n return [rarity, maxScore]\n })\n })\n .flat()\n const total = scores.reduce<Score>(([a, b], [c, d]) => [a + c, b + d], [0, 0])\n return normalize(total, maxScore)\n}\n","import { NftCollectionAttributeMetrics } from '@xyo-network/crypto-nft-collection-payload-plugin'\nimport { normalize, Score } from '@xyo-network/crypto-nft-score-model'\n\nconst maxScore = 10\n\n/**\n * Mean: What value is the distribution centered around\n */\nconst defaultMu = 0.15\n\n/**\n * Standard Deviation: How spread out is the distribution\n */\nconst defaultSigma = 0.1\n\n/**\n * Calculates the Gaussian probability density\n * @param x\n * @param mu Mean\n * @param sigma Standard Deviation\n * @returns\n */\nconst gaussianProbabilityDensity = (x: number, mu: number = defaultMu, sigma: number = defaultSigma): number => {\n const sqrtTwoPi = Math.sqrt(2 * Math.PI)\n const denominator = sigma * sqrtTwoPi\n const power = -0.5 * Math.pow((x - mu) / sigma, 2)\n return (1 / denominator) * Math.exp(power)\n}\n\n/**\n * For a Gaussian distribution, the peak of the distribution is the mean\n */\nconst maxProbabilityDensity = gaussianProbabilityDensity(defaultMu)\n\n/**\n * We're working on some assumptions here:\n *\n * - If you have a 100% chance of getting a trait, everyone get's a trophy\n * - If you have a 50% chance of getting a trait, it's not rare\n * - If you have a 0% chance of getting a trait, it's not fun\n *\n * So we're looking for something Pareto-ish (somewhere between\n * 80/20 or 90/10) as that's a good & sustainable model for the\n * distribution of many traits in real life.\n * However, we also don't want to maximally reward collections\n * that have a lot of single attributes distributed uniformly\n * (basically a 0% trait probably) as that's perfectly entropic\n * but not very interesting (some overlap is desirable).\n * So we're using a Gaussian distribution to model the\n * probability density of the joint probability of all traits\n * centered around 15%.\n * @param info\n * @returns\n */\nexport const scoreTotalAttributes = (info: NftCollectionAttributeMetrics): Score => {\n const { attributes } = info.metrics.metadata\n // This has somewhat of a filtering function by causing anything with 100% probability to\n // add no value to the end score\n const jointProbability = Object.entries(attributes).reduce((acc, [_trait, { metrics }]) => {\n return acc * metrics.binomial.p\n }, 1)\n const probabilityDensity = gaussianProbabilityDensity(jointProbability)\n const score: Score = [probabilityDensity, maxProbabilityDensity]\n return normalize(score, maxScore)\n}\n","import { NftCollectionInfo } from '@xyo-network/crypto-nft-collection-payload-plugin'\nimport { WeightedScoringCriteria } from '@xyo-network/crypto-nft-score-model'\n\nimport { scoreIndividualAttributes } from './scoreIndividualAttributes'\nimport { scoreTotalAttributes } from './scoreTotalAttributes'\n\nexport const attributeScoringCriteria: { [key: string]: WeightedScoringCriteria<NftCollectionInfo> } = {\n 'Metadata Attributes Individual': { score: scoreIndividualAttributes, weight: 2 },\n 'Metadata Attributes Total': { score: scoreTotalAttributes, weight: 2 },\n}\n\nexport const scoreMetadata: { [key: string]: WeightedScoringCriteria<NftCollectionInfo> } = {\n ...attributeScoringCriteria,\n}\n","import { NftCollectionCount } from '@xyo-network/crypto-nft-collection-payload-plugin'\nimport { normalize, Score } from '@xyo-network/crypto-nft-score-model'\n\n/**\n * This \"magic\" value was obtained using Solver in Excel\n * to find the median, with mu/sigma fixed, which maximizes\n * the distribution (the mode for lognormal) at 10,000\n */\nconst median = 81030839.8217352\nconst defaultMu = Math.log(median)\nconst defaultSigma = 3\nconst mode = Math.exp(defaultMu - Math.pow(defaultSigma, 2))\n/**\n * Calculates the log-normal probability density\n * @param x the value at which you want to calculate the probability density\n * @param mu mean of the associated normal distribution\n * @param sigma standard deviation of the associated normal distribution\n * @returns\n */\nconst logNormalProbabilityDensity = (x: number, mu: number = defaultMu, sigma: number = defaultSigma): number => {\n if (x <= 0) return 0\n const logX = Math.log(x)\n return (1 / (x * sigma * Math.sqrt(2 * Math.PI))) * Math.exp(-0.5 * Math.pow((logX - mu) / sigma, 2))\n}\n\n/**\n * For a lognormal distribution, the peak of the distribution is the mode\n */\nconst maxProbabilityDensity = logNormalProbabilityDensity(mode)\n\nconst maxScore = 10\n\n/**\n * We're working on some assumptions here:\n * - If there's < 1000 NFTs in your collection it starts becoming too niche\n * - If there's > 20,000 NFTs in your collection it starts becoming too broad\n * So there's a sweet spot somewhere between 2000 and 10,000\n * where a collection has enough NFTs to be interesting, but\n * not so many that it's teetering on a diluted money grab.\n * To model that we're using a log-normal distribution optimized\n * to maximally reward collections in the aforementioned range\n * @param nft\n * @returns\n */\nexport const scoreTotal = (nft: NftCollectionCount): Score => {\n const density = logNormalProbabilityDensity(nft.total)\n const score: Score = [density, maxProbabilityDensity]\n return normalize(score, maxScore)\n}\n","import { NftCollectionInfo } from '@xyo-network/crypto-nft-collection-payload-plugin'\nimport { WeightedScoringCriteria } from '@xyo-network/crypto-nft-score-model'\n\nimport { scoreMetadata, scoreTotal } from './scoring'\n\nexport const scoringCriteria: { [key: string]: WeightedScoringCriteria<NftCollectionInfo> } = {\n ...scoreMetadata,\n Total: { score: scoreTotal, weight: 2 },\n}\n","import { NftCollectionInfo } from '@xyo-network/crypto-nft-collection-payload-plugin'\nimport { Score } from '@xyo-network/crypto-nft-score-model'\n\nimport { scoringCriteria } from './criteria'\n\nexport type ScoringCriteriaKey = keyof typeof scoringCriteria & PropertyKey\n\nexport type NftCollectionAnalysis = {\n [key in ScoringCriteriaKey]: Score\n}\n\nexport const analyzeNftCollection = async (\n /**\n * The NFT to evaluate\n */\n nft: NftCollectionInfo,\n): Promise<NftCollectionAnalysis> => {\n const result = Object.fromEntries(\n await Promise.all(\n Object.entries(scoringCriteria).map(async ([key, { score, weight }]) => {\n const rawScore = await score(nft)\n const weighted = rawScore.map((v) => v * weight) as Score\n return [key, weighted] as const\n }),\n ),\n ) as NftCollectionAnalysis\n return result\n}\n","import { NftCollectionScoreDivinerPlugin } from './Plugin'\n\nexport * from './Diviner'\nexport * from './lib'\n\nexport { NftCollectionScoreDivinerPlugin }\n\n// eslint-disable-next-line import/no-default-export\nexport default NftCollectionScoreDivinerPlugin\n"],"mappings":";AAAA,SAAS,iBAAiB;AAC1B,SAAS,wBAAwB;AACjC,SAAS,qCAAqC;;;ACF9C,SAAS,uBAAuB;AAChC;AAAA,EACE;AAAA,EAKA;AAAA,EACA;AAAA,OACK;AAEP,SAAS,qBAAqB;;;ACV9B,SAAS,iBAAwB;AAEjC,IAAM,WAAW;AAEV,IAAM,4BAA4B,CAAC,SAA+C;AACvF,QAAM,EAAE,WAAW,IAAI,KAAK,QAAQ;AACpC,QAAM,UAAU,OAAO,QAAQ,UAAU;AACzC,MAAI,QAAQ,WAAW;AAAG,WAAO,CAAC,GAAG,QAAQ;AAC7C,QAAM,SAAS,OAAO,QAAQ,UAAU,EACrC,IAAI,CAAC,CAAC,QAAQ,EAAE,OAAO,CAAC,MAAM;AAC7B,WAAO,OAAO,QAAQ,MAAM,EAAE,IAAW,CAAC,CAAC,aAAa,OAAO,MAAM;AACnE,YAAM,SAAS,KAAK,IAAI,KAAK,OAAO,IAAI,QAAQ,SAAS,KAAK,QAAQ,GAAG,QAAQ;AACjF,aAAO,CAAC,QAAQ,QAAQ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IAAM,4BAAN,cAEG,gBAAyB;AAAA,EACjC,OAAgB,gBAAgB,CAAC,qCAAqC;AAAA,EAEnD,gBAAgB,OAAO,aAA6C;AACrF,UAAM,sBAAqB,qCAAU,OAAO,yBAAwB,CAAC;AACrE,UAAM,UAAU,MAAM,QAAQ;AAAA,MAC5B,mBAAmB,IAAiC,OAAO,sBAAsB;AAC/E,cAAM,CAAC,OAAO,UAAU,IAAI,MAAM,QAAQ,IAAI;AAAA;AAAA,UAE5C,qBAAqB,mBAAmB,MAAM,qBAAqB,iBAAiB,CAAC;AAAA;AAAA,UAErF,cAAc,UAAU,iBAAiB;AAAA,QAC3C,CAAC;AACD,eAAO,EAAE,GAAG,OAAO,QAAQ,0BAA0B,SAAS,CAAC,UAAU,EAAE;AAAA,MAC7E,CAAC;AAAA,IACH;AACA,WAAO;AAAA,EACT;AACF;;;ADvCO,IAAM,kCAAkC,MAC7C;AAAA,EACE,EAAE,UAAU,EAAE,CAAC,SAAS,GAAG,EAAE,GAAG,QAAQ,iBAAiB;AAAA,EACzD;AAAA,IACE,SAAS,OAAO,WAAW;AACzB,YAAM,SAAS,MAAM,0BAA0B,OAAO,MAAM;AAC5D,aAAO;AAAA,IACT;AAAA,EACF;AACF;;;AQPF,IAAO,cAAQ;","names":["normalize","maxScore","normalize","defaultMu","defaultSigma","maxProbabilityDensity","maxScore"]}
|
|
1
|
+
{"version":3,"sources":["../../src/Diviner.ts","../../src/lib/rating/criteria/scoring/metadata/scoreIndividualAttributes.ts","../../src/lib/rating/criteria/scoring/metadata/scoreTotalAttributes.ts","../../src/lib/rating/criteria/scoring/metadata/metadata.ts","../../src/lib/rating/criteria/scoring/total.ts","../../src/lib/rating/criteria/index.ts","../../src/lib/rating/analyzeNftCollection.ts","../../src/Plugin.ts"],"sourcesContent":["import { AbstractDiviner } from '@xyo-network/abstract-diviner'\nimport {\n isNftCollectionInfo,\n NftCollectionInfo,\n NftCollectionMetadata,\n NftCollectionScore,\n NftCollectionScoreDivinerConfig,\n NftCollectionScoreDivinerConfigSchema,\n NftCollectionScoreSchema,\n} from '@xyo-network/crypto-nft-collection-payload-plugin'\nimport { DivinerParams } from '@xyo-network/diviner-model'\nimport { PayloadHasher } from '@xyo-network/hash'\nimport { AnyConfigSchema } from '@xyo-network/module-model'\nimport { Payload } from '@xyo-network/payload-model'\n\nimport { analyzeNftCollection, NftCollectionAnalysis } from './lib'\n\nexport type NftCollectionScoreDivinerParams = DivinerParams<AnyConfigSchema<NftCollectionScoreDivinerConfig>>\n\nconst toNftCollectionScore = (nftCollectionInfo: NftCollectionInfo, scores: NftCollectionAnalysis): NftCollectionScore => {\n const { name, symbol, address, chainId, type } = nftCollectionInfo\n const metadata: NftCollectionMetadata = { address, chainId, name, symbol, type }\n return { ...metadata, schema: NftCollectionScoreSchema, scores }\n}\n\nexport class NftCollectionScoreDiviner<\n TParams extends NftCollectionScoreDivinerParams = NftCollectionScoreDivinerParams,\n> extends AbstractDiviner<TParams> {\n static override configSchemas = [NftCollectionScoreDivinerConfigSchema]\n\n protected override divineHandler = async (payloads?: Payload[]): Promise<Payload[]> => {\n const nftCollectionInfos = payloads?.filter(isNftCollectionInfo) ?? []\n const results = await Promise.all(\n nftCollectionInfos.map<Promise<NftCollectionScore>>(async (nftCollectionInfo) => {\n const [score, sourceHash] = await Promise.all([\n // Get score\n toNftCollectionScore(nftCollectionInfo, await analyzeNftCollection(nftCollectionInfo)),\n // Hash sources\n PayloadHasher.hashAsync(nftCollectionInfo),\n ])\n return { ...score, schema: NftCollectionScoreSchema, sources: [sourceHash] } as NftCollectionScore\n }),\n )\n return results\n }\n}\n","import { NftCollectionAttributeMetrics } from '@xyo-network/crypto-nft-collection-payload-plugin'\nimport { normalize, Score } from '@xyo-network/crypto-nft-score-model'\n\nconst maxScore = 10\n\nexport const scoreIndividualAttributes = (info: NftCollectionAttributeMetrics): Score => {\n const { attributes } = info.metrics.metadata\n const entries = Object.entries(attributes)\n if (entries.length === 0) return [0, maxScore]\n const scores = Object.entries(attributes).flatMap(([_trait, { values }]) => {\n return Object.entries(values).map<Score>(([_traitValue, metrics]) => {\n const rarity = Math.min(Math.round((1 - metrics.binomial.p) * maxScore), maxScore)\n return [rarity, maxScore]\n })\n })\n // eslint-disable-next-line unicorn/no-array-reduce\n const total = scores.reduce<Score>(([a, b], [c, d]) => [a + c, b + d], [0, 0])\n return normalize(total, maxScore)\n}\n","import { NftCollectionAttributeMetrics } from '@xyo-network/crypto-nft-collection-payload-plugin'\nimport { normalize, Score } from '@xyo-network/crypto-nft-score-model'\n\nconst maxScore = 10\n\n/**\n * Mean: What value is the distribution centered around\n */\nconst defaultMu = 0.15\n\n/**\n * Standard Deviation: How spread out is the distribution\n */\nconst defaultSigma = 0.1\n\n/**\n * Calculates the Gaussian probability density\n * @param x\n * @param mu Mean\n * @param sigma Standard Deviation\n * @returns\n */\nconst gaussianProbabilityDensity = (x: number, mu: number = defaultMu, sigma: number = defaultSigma): number => {\n const sqrtTwoPi = Math.sqrt(2 * Math.PI)\n const denominator = sigma * sqrtTwoPi\n const power = -0.5 * Math.pow((x - mu) / sigma, 2)\n return (1 / denominator) * Math.exp(power)\n}\n\n/**\n * For a Gaussian distribution, the peak of the distribution is the mean\n */\nconst maxProbabilityDensity = gaussianProbabilityDensity(defaultMu)\n\n/**\n * We're working on some assumptions here:\n *\n * - If you have a 100% chance of getting a trait, everyone get's a trophy\n * - If you have a 50% chance of getting a trait, it's not rare\n * - If you have a 0% chance of getting a trait, it's not fun\n *\n * So we're looking for something Pareto-ish (somewhere between\n * 80/20 or 90/10) as that's a good & sustainable model for the\n * distribution of many traits in real life.\n * However, we also don't want to maximally reward collections\n * that have a lot of single attributes distributed uniformly\n * (basically a 0% trait probably) as that's perfectly entropic\n * but not very interesting (some overlap is desirable).\n * So we're using a Gaussian distribution to model the\n * probability density of the joint probability of all traits\n * centered around 15%.\n * @param info\n * @returns\n */\nexport const scoreTotalAttributes = (info: NftCollectionAttributeMetrics): Score => {\n const { attributes } = info.metrics.metadata\n // This has somewhat of a filtering function by causing anything with 100% probability to\n // add no value to the end score\n const jointProbability = Object.entries(attributes).reduce((acc, [_trait, { metrics }]) => {\n return acc * metrics.binomial.p\n }, 1)\n const probabilityDensity = gaussianProbabilityDensity(jointProbability)\n const score: Score = [probabilityDensity, maxProbabilityDensity]\n return normalize(score, maxScore)\n}\n","import { NftCollectionInfo } from '@xyo-network/crypto-nft-collection-payload-plugin'\nimport { WeightedScoringCriteria } from '@xyo-network/crypto-nft-score-model'\n\nimport { scoreIndividualAttributes } from './scoreIndividualAttributes'\nimport { scoreTotalAttributes } from './scoreTotalAttributes'\n\nexport const attributeScoringCriteria: { [key: string]: WeightedScoringCriteria<NftCollectionInfo> } = {\n 'Metadata Attributes Individual': { score: scoreIndividualAttributes, weight: 2 },\n 'Metadata Attributes Total': { score: scoreTotalAttributes, weight: 2 },\n}\n\nexport const scoreMetadata: { [key: string]: WeightedScoringCriteria<NftCollectionInfo> } = {\n ...attributeScoringCriteria,\n}\n","import { NftCollectionCount } from '@xyo-network/crypto-nft-collection-payload-plugin'\nimport { normalize, Score } from '@xyo-network/crypto-nft-score-model'\n\n/**\n * This \"magic\" value was obtained using Solver in Excel\n * to find the median, with mu/sigma fixed, which maximizes\n * the distribution (the mode for lognormal) at 10,000\n */\nconst median = 81_030_839.821_735_2\nconst defaultMu = Math.log(median)\nconst defaultSigma = 3\nconst mode = Math.exp(defaultMu - Math.pow(defaultSigma, 2))\n/**\n * Calculates the log-normal probability density\n * @param x the value at which you want to calculate the probability density\n * @param mu mean of the associated normal distribution\n * @param sigma standard deviation of the associated normal distribution\n * @returns\n */\nconst logNormalProbabilityDensity = (x: number, mu: number = defaultMu, sigma: number = defaultSigma): number => {\n if (x <= 0) return 0\n const logX = Math.log(x)\n return (1 / (x * sigma * Math.sqrt(2 * Math.PI))) * Math.exp(-0.5 * Math.pow((logX - mu) / sigma, 2))\n}\n\n/**\n * For a lognormal distribution, the peak of the distribution is the mode\n */\nconst maxProbabilityDensity = logNormalProbabilityDensity(mode)\n\nconst maxScore = 10\n\n/**\n * We're working on some assumptions here:\n * - If there's < 1000 NFTs in your collection it starts becoming too niche\n * - If there's > 20,000 NFTs in your collection it starts becoming too broad\n * So there's a sweet spot somewhere between 2000 and 10,000\n * where a collection has enough NFTs to be interesting, but\n * not so many that it's teetering on a diluted money grab.\n * To model that we're using a log-normal distribution optimized\n * to maximally reward collections in the aforementioned range\n * @param nft\n * @returns\n */\nexport const scoreTotal = (nft: NftCollectionCount): Score => {\n const density = logNormalProbabilityDensity(nft.total)\n const score: Score = [density, maxProbabilityDensity]\n return normalize(score, maxScore)\n}\n","import { NftCollectionInfo } from '@xyo-network/crypto-nft-collection-payload-plugin'\nimport { WeightedScoringCriteria } from '@xyo-network/crypto-nft-score-model'\n\nimport { scoreMetadata, scoreTotal } from './scoring'\n\nexport const scoringCriteria: { [key: string]: WeightedScoringCriteria<NftCollectionInfo> } = {\n ...scoreMetadata,\n Total: { score: scoreTotal, weight: 2 },\n}\n","import { NftCollectionInfo } from '@xyo-network/crypto-nft-collection-payload-plugin'\nimport { Score } from '@xyo-network/crypto-nft-score-model'\n\nimport { scoringCriteria } from './criteria'\n\nexport type ScoringCriteriaKey = keyof typeof scoringCriteria & PropertyKey\n\nexport type NftCollectionAnalysis = {\n [key in ScoringCriteriaKey]: Score\n}\n\nexport const analyzeNftCollection = async (\n /**\n * The NFT to evaluate\n */\n nft: NftCollectionInfo,\n): Promise<NftCollectionAnalysis> => {\n const result = Object.fromEntries(\n await Promise.all(\n Object.entries(scoringCriteria).map(async ([key, { score, weight }]) => {\n const rawScore = await score(nft)\n const weighted = rawScore.map((v) => v * weight) as Score\n return [key, weighted] as const\n }),\n ),\n ) as NftCollectionAnalysis\n return result\n}\n","import { NftSchema } from '@xyo-network/crypto-nft-payload-plugin'\nimport { PayloadSetSchema } from '@xyo-network/payload-model'\nimport { createPayloadSetDivinerPlugin } from '@xyo-network/payloadset-plugin'\n\nimport { NftCollectionScoreDiviner } from './Diviner'\n\nexport const NftCollectionScoreDivinerPlugin = () =>\n createPayloadSetDivinerPlugin<NftCollectionScoreDiviner>(\n { required: { [NftSchema]: 1 }, schema: PayloadSetSchema },\n {\n diviner: async (params) => {\n const result = await NftCollectionScoreDiviner.create(params)\n return result\n },\n },\n )\n"],"mappings":";AAAA,SAAS,uBAAuB;AAChC;AAAA,EACE;AAAA,EAKA;AAAA,EACA;AAAA,OACK;AAEP,SAAS,qBAAqB;;;ACV9B,SAAS,iBAAwB;AAEjC,IAAM,WAAW;AAEV,IAAM,4BAA4B,CAAC,SAA+C;AACvF,QAAM,EAAE,WAAW,IAAI,KAAK,QAAQ;AACpC,QAAM,UAAU,OAAO,QAAQ,UAAU;AACzC,MAAI,QAAQ,WAAW;AAAG,WAAO,CAAC,GAAG,QAAQ;AAC7C,QAAM,SAAS,OAAO,QAAQ,UAAU,EAAE,QAAQ,CAAC,CAAC,QAAQ,EAAE,OAAO,CAAC,MAAM;AAC1E,WAAO,OAAO,QAAQ,MAAM,EAAE,IAAW,CAAC,CAAC,aAAa,OAAO,MAAM;AACnE,YAAM,SAAS,KAAK,IAAI,KAAK,OAAO,IAAI,QAAQ,SAAS,KAAK,QAAQ,GAAG,QAAQ;AACjF,aAAO,CAAC,QAAQ,QAAQ;AAAA,IAC1B,CAAC;AAAA,EACH,CAAC;AAED,QAAM,QAAQ,OAAO,OAAc,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,GAAG,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;AAC7E,SAAO,UAAU,OAAO,QAAQ;AAClC;;;ACjBA,SAAS,aAAAA,kBAAwB;AAEjC,IAAMC,YAAW;AAKjB,IAAM,YAAY;AAKlB,IAAM,eAAe;AASrB,IAAM,6BAA6B,CAAC,GAAW,KAAa,WAAW,QAAgB,iBAAyB;AAC9G,QAAM,YAAY,KAAK,KAAK,IAAI,KAAK,EAAE;AACvC,QAAM,cAAc,QAAQ;AAC5B,QAAM,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EAAE;AAAA,MAC7E,CAAC;AAAA,IACH;AACA,WAAO;AAAA,EACT;AACF;;;AO7CA,SAAS,iBAAiB;AAC1B,SAAS,wBAAwB;AACjC,SAAS,qCAAqC;AAIvC,IAAM,kCAAkC,MAC7C;AAAA,EACE,EAAE,UAAU,EAAE,CAAC,SAAS,GAAG,EAAE,GAAG,QAAQ,iBAAiB;AAAA,EACzD;AAAA,IACE,SAAS,OAAO,WAAW;AACzB,YAAM,SAAS,MAAM,0BAA0B,OAAO,MAAM;AAC5D,aAAO;AAAA,IACT;AAAA,EACF;AACF;","names":["normalize","maxScore","normalize","defaultMu","defaultSigma","maxProbabilityDensity","maxScore"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scoreIndividualAttributes.d.ts","sourceRoot":"","sources":["../../../../../../../src/lib/rating/criteria/scoring/metadata/scoreIndividualAttributes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,6BAA6B,EAAE,MAAM,mDAAmD,CAAA;AACjG,OAAO,EAAa,KAAK,EAAE,MAAM,qCAAqC,CAAA;AAItE,eAAO,MAAM,yBAAyB,SAAU,6BAA6B,KAAG,
|
|
1
|
+
{"version":3,"file":"scoreIndividualAttributes.d.ts","sourceRoot":"","sources":["../../../../../../../src/lib/rating/criteria/scoring/metadata/scoreIndividualAttributes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,6BAA6B,EAAE,MAAM,mDAAmD,CAAA;AACjG,OAAO,EAAa,KAAK,EAAE,MAAM,qCAAqC,CAAA;AAItE,eAAO,MAAM,yBAAyB,SAAU,6BAA6B,KAAG,KAa/E,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scoreIndividualAttributes.d.ts","sourceRoot":"","sources":["../../../../../../../src/lib/rating/criteria/scoring/metadata/scoreIndividualAttributes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,6BAA6B,EAAE,MAAM,mDAAmD,CAAA;AACjG,OAAO,EAAa,KAAK,EAAE,MAAM,qCAAqC,CAAA;AAItE,eAAO,MAAM,yBAAyB,SAAU,6BAA6B,KAAG,
|
|
1
|
+
{"version":3,"file":"scoreIndividualAttributes.d.ts","sourceRoot":"","sources":["../../../../../../../src/lib/rating/criteria/scoring/metadata/scoreIndividualAttributes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,6BAA6B,EAAE,MAAM,mDAAmD,CAAA;AACjG,OAAO,EAAa,KAAK,EAAE,MAAM,qCAAqC,CAAA;AAItE,eAAO,MAAM,yBAAyB,SAAU,6BAA6B,KAAG,KAa/E,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scoreIndividualAttributes.d.ts","sourceRoot":"","sources":["../../../../../../../src/lib/rating/criteria/scoring/metadata/scoreIndividualAttributes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,6BAA6B,EAAE,MAAM,mDAAmD,CAAA;AACjG,OAAO,EAAa,KAAK,EAAE,MAAM,qCAAqC,CAAA;AAItE,eAAO,MAAM,yBAAyB,SAAU,6BAA6B,KAAG,
|
|
1
|
+
{"version":3,"file":"scoreIndividualAttributes.d.ts","sourceRoot":"","sources":["../../../../../../../src/lib/rating/criteria/scoring/metadata/scoreIndividualAttributes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,6BAA6B,EAAE,MAAM,mDAAmD,CAAA;AACjG,OAAO,EAAa,KAAK,EAAE,MAAM,qCAAqC,CAAA;AAItE,eAAO,MAAM,yBAAyB,SAAU,6BAA6B,KAAG,KAa/E,CAAA"}
|
package/package.json
CHANGED
|
@@ -10,22 +10,22 @@
|
|
|
10
10
|
"url": "https://github.com/XYOracleNetwork/plugins/issues"
|
|
11
11
|
},
|
|
12
12
|
"dependencies": {
|
|
13
|
-
"@xyo-network/abstract-diviner": "^2.85.
|
|
14
|
-
"@xyo-network/crypto-nft-collection-payload-plugin": "~2.85.
|
|
15
|
-
"@xyo-network/crypto-nft-payload-plugin": "~2.85.
|
|
16
|
-
"@xyo-network/crypto-nft-score-model": "~2.85.
|
|
17
|
-
"@xyo-network/diviner-model": "^2.85.
|
|
18
|
-
"@xyo-network/hash": "^2.85.
|
|
19
|
-
"@xyo-network/module-model": "^2.85.
|
|
20
|
-
"@xyo-network/payload-model": "^2.85.
|
|
21
|
-
"@xyo-network/payloadset-plugin": "^2.85.
|
|
13
|
+
"@xyo-network/abstract-diviner": "^2.85.3",
|
|
14
|
+
"@xyo-network/crypto-nft-collection-payload-plugin": "~2.85.1",
|
|
15
|
+
"@xyo-network/crypto-nft-payload-plugin": "~2.85.1",
|
|
16
|
+
"@xyo-network/crypto-nft-score-model": "~2.85.1",
|
|
17
|
+
"@xyo-network/diviner-model": "^2.85.3",
|
|
18
|
+
"@xyo-network/hash": "^2.85.3",
|
|
19
|
+
"@xyo-network/module-model": "^2.85.3",
|
|
20
|
+
"@xyo-network/payload-model": "^2.85.3",
|
|
21
|
+
"@xyo-network/payloadset-plugin": "^2.85.3"
|
|
22
22
|
},
|
|
23
23
|
"devDependencies": {
|
|
24
|
-
"@xylabs/jest-helpers": "^2.13.
|
|
24
|
+
"@xylabs/jest-helpers": "^2.13.22",
|
|
25
25
|
"@xylabs/ts-scripts-yarn3": "^3.2.25",
|
|
26
26
|
"@xylabs/tsconfig": "^3.2.25",
|
|
27
|
-
"@xyo-network/account": "^2.85.
|
|
28
|
-
"@xyo-network/payload-wrapper": "^2.85.
|
|
27
|
+
"@xyo-network/account": "^2.85.3",
|
|
28
|
+
"@xyo-network/payload-wrapper": "^2.85.3",
|
|
29
29
|
"ethers": "^6.9.1",
|
|
30
30
|
"jest": "^29.7.0",
|
|
31
31
|
"typescript": "^5.3.3"
|
|
@@ -69,6 +69,6 @@
|
|
|
69
69
|
"url": "https://github.com/XYOracleNetwork/plugins.git"
|
|
70
70
|
},
|
|
71
71
|
"sideEffects": false,
|
|
72
|
-
"version": "2.85.
|
|
72
|
+
"version": "2.85.1",
|
|
73
73
|
"type": "module"
|
|
74
74
|
}
|
package/src/index.ts
CHANGED
|
@@ -1,9 +1,3 @@
|
|
|
1
|
-
import { NftCollectionScoreDivinerPlugin } from './Plugin'
|
|
2
|
-
|
|
3
1
|
export * from './Diviner'
|
|
4
2
|
export * from './lib'
|
|
5
|
-
|
|
6
|
-
export { NftCollectionScoreDivinerPlugin }
|
|
7
|
-
|
|
8
|
-
// eslint-disable-next-line import/no-default-export
|
|
9
|
-
export default NftCollectionScoreDivinerPlugin
|
|
3
|
+
export { NftCollectionScoreDivinerPlugin as default, NftCollectionScoreDivinerPlugin } from './Plugin'
|
|
@@ -7,14 +7,13 @@ export const scoreIndividualAttributes = (info: NftCollectionAttributeMetrics):
|
|
|
7
7
|
const { attributes } = info.metrics.metadata
|
|
8
8
|
const entries = Object.entries(attributes)
|
|
9
9
|
if (entries.length === 0) return [0, maxScore]
|
|
10
|
-
const scores = Object.entries(attributes)
|
|
11
|
-
.map(([
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
return [rarity, maxScore]
|
|
15
|
-
})
|
|
10
|
+
const scores = Object.entries(attributes).flatMap(([_trait, { values }]) => {
|
|
11
|
+
return Object.entries(values).map<Score>(([_traitValue, metrics]) => {
|
|
12
|
+
const rarity = Math.min(Math.round((1 - metrics.binomial.p) * maxScore), maxScore)
|
|
13
|
+
return [rarity, maxScore]
|
|
16
14
|
})
|
|
17
|
-
|
|
15
|
+
})
|
|
16
|
+
// eslint-disable-next-line unicorn/no-array-reduce
|
|
18
17
|
const total = scores.reduce<Score>(([a, b], [c, d]) => [a + c, b + d], [0, 0])
|
|
19
18
|
return normalize(total, maxScore)
|
|
20
19
|
}
|
|
@@ -6,7 +6,7 @@ import { normalize, Score } from '@xyo-network/crypto-nft-score-model'
|
|
|
6
6
|
* to find the median, with mu/sigma fixed, which maximizes
|
|
7
7
|
* the distribution (the mode for lognormal) at 10,000
|
|
8
8
|
*/
|
|
9
|
-
const median =
|
|
9
|
+
const median = 81_030_839.821_735_2
|
|
10
10
|
const defaultMu = Math.log(median)
|
|
11
11
|
const defaultSigma = 3
|
|
12
12
|
const mode = Math.exp(defaultMu - Math.pow(defaultSigma, 2))
|