@xyo-network/crypto-nft-collection-diviner-score-plugin 2.99.5 → 2.99.6

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.
@@ -1,75 +1,55 @@
1
- var __defProp = Object.defineProperty;
2
- var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
-
4
1
  // src/Diviner.ts
5
- import { isNftCollectionInfo, NftCollectionScoreDivinerConfigSchema, NftCollectionScoreSchema } from "@xyo-network/crypto-nft-collection-payload-plugin";
2
+ import {
3
+ isNftCollectionInfo,
4
+ NftCollectionScoreDivinerConfigSchema,
5
+ NftCollectionScoreSchema
6
+ } from "@xyo-network/crypto-nft-collection-payload-plugin";
6
7
  import { AbstractDiviner } from "@xyo-network/diviner-abstract";
7
8
  import { PayloadBuilder } from "@xyo-network/payload-builder";
8
9
 
9
10
  // src/lib/rating/criteria/scoring/metadata/scoreIndividualAttributes.ts
10
11
  import { normalize } from "@xyo-network/crypto-nft-score-model";
11
12
  var maxScore = 10;
12
- var scoreIndividualAttributes = /* @__PURE__ */ __name((info) => {
13
+ var scoreIndividualAttributes = (info) => {
13
14
  const { attributes } = info.metrics.metadata;
14
15
  const entries = Object.entries(attributes);
15
- if (entries.length === 0) return [
16
- 0,
17
- maxScore
18
- ];
16
+ if (entries.length === 0) return [0, maxScore];
19
17
  const scores = Object.entries(attributes).flatMap(([_trait, { values }]) => {
20
18
  return Object.entries(values).map(([_traitValue, metrics]) => {
21
19
  const rarity = Math.min(Math.round((1 - metrics.binomial.p) * maxScore), maxScore);
22
- return [
23
- rarity,
24
- maxScore
25
- ];
20
+ return [rarity, maxScore];
26
21
  });
27
22
  });
28
- const total = scores.reduce(([a, b], [c, d]) => [
29
- a + c,
30
- b + d
31
- ], [
32
- 0,
33
- 0
34
- ]);
23
+ const total = scores.reduce(([a, b], [c, d]) => [a + c, b + d], [0, 0]);
35
24
  return normalize(total, maxScore);
36
- }, "scoreIndividualAttributes");
25
+ };
37
26
 
38
27
  // src/lib/rating/criteria/scoring/metadata/scoreTotalAttributes.ts
39
28
  import { normalize as normalize2 } from "@xyo-network/crypto-nft-score-model";
40
29
  var maxScore2 = 10;
41
30
  var defaultMu = 0.15;
42
31
  var defaultSigma = 0.1;
43
- var gaussianProbabilityDensity = /* @__PURE__ */ __name((x, mu = defaultMu, sigma = defaultSigma) => {
32
+ var gaussianProbabilityDensity = (x, mu = defaultMu, sigma = defaultSigma) => {
44
33
  const sqrtTwoPi = Math.sqrt(2 * Math.PI);
45
34
  const denominator = sigma * sqrtTwoPi;
46
35
  const power = -0.5 * Math.pow((x - mu) / sigma, 2);
47
36
  return 1 / denominator * Math.exp(power);
48
- }, "gaussianProbabilityDensity");
37
+ };
49
38
  var maxProbabilityDensity = gaussianProbabilityDensity(defaultMu);
50
- var scoreTotalAttributes = /* @__PURE__ */ __name((info) => {
39
+ var scoreTotalAttributes = (info) => {
51
40
  const { attributes } = info.metrics.metadata;
52
41
  const jointProbability = Object.entries(attributes).reduce((acc, [_trait, { metrics }]) => {
53
42
  return acc * metrics.binomial.p;
54
43
  }, 1);
55
44
  const probabilityDensity = gaussianProbabilityDensity(jointProbability);
56
- const score = [
57
- probabilityDensity,
58
- maxProbabilityDensity
59
- ];
45
+ const score = [probabilityDensity, maxProbabilityDensity];
60
46
  return normalize2(score, maxScore2);
61
- }, "scoreTotalAttributes");
47
+ };
62
48
 
63
49
  // src/lib/rating/criteria/scoring/metadata/metadata.ts
64
50
  var attributeScoringCriteria = {
65
- "Metadata Attributes Individual": {
66
- score: scoreIndividualAttributes,
67
- weight: 2
68
- },
69
- "Metadata Attributes Total": {
70
- score: scoreTotalAttributes,
71
- weight: 2
72
- }
51
+ "Metadata Attributes Individual": { score: scoreIndividualAttributes, weight: 2 },
52
+ "Metadata Attributes Total": { score: scoreTotalAttributes, weight: 2 }
73
53
  };
74
54
  var scoreMetadata = {
75
55
  ...attributeScoringCriteria
@@ -81,105 +61,78 @@ var median = 810308398217352e-7;
81
61
  var defaultMu2 = Math.log(median);
82
62
  var defaultSigma2 = 3;
83
63
  var mode = Math.exp(defaultMu2 - Math.pow(defaultSigma2, 2));
84
- var logNormalProbabilityDensity = /* @__PURE__ */ __name((x, mu = defaultMu2, sigma = defaultSigma2) => {
64
+ var logNormalProbabilityDensity = (x, mu = defaultMu2, sigma = defaultSigma2) => {
85
65
  if (x <= 0) return 0;
86
66
  const logX = Math.log(x);
87
67
  return 1 / (x * sigma * Math.sqrt(2 * Math.PI)) * Math.exp(-0.5 * Math.pow((logX - mu) / sigma, 2));
88
- }, "logNormalProbabilityDensity");
68
+ };
89
69
  var maxProbabilityDensity2 = logNormalProbabilityDensity(mode);
90
70
  var maxScore3 = 10;
91
- var scoreTotal = /* @__PURE__ */ __name((nft) => {
71
+ var scoreTotal = (nft) => {
92
72
  const density = logNormalProbabilityDensity(nft.total);
93
- const score = [
94
- density,
95
- maxProbabilityDensity2
96
- ];
73
+ const score = [density, maxProbabilityDensity2];
97
74
  return normalize3(score, maxScore3);
98
- }, "scoreTotal");
75
+ };
99
76
 
100
77
  // src/lib/rating/criteria/index.ts
101
78
  var scoringCriteria = {
102
79
  ...scoreMetadata,
103
- Total: {
104
- score: scoreTotal,
105
- weight: 2
106
- }
80
+ Total: { score: scoreTotal, weight: 2 }
107
81
  };
108
82
 
109
83
  // src/lib/rating/analyzeNftCollection.ts
110
- var analyzeNftCollection = /* @__PURE__ */ __name(async (nft) => {
111
- const result = Object.fromEntries(await Promise.all(Object.entries(scoringCriteria).map(async ([key, { score, weight }]) => {
112
- const rawScore = await score(nft);
113
- const weighted = rawScore.map((v) => v * weight);
114
- return [
115
- key,
116
- weighted
117
- ];
118
- })));
84
+ var analyzeNftCollection = async (nft) => {
85
+ const result = Object.fromEntries(
86
+ await Promise.all(
87
+ Object.entries(scoringCriteria).map(async ([key, { score, weight }]) => {
88
+ const rawScore = await score(nft);
89
+ const weighted = rawScore.map((v) => v * weight);
90
+ return [key, weighted];
91
+ })
92
+ )
93
+ );
119
94
  return result;
120
- }, "analyzeNftCollection");
95
+ };
121
96
 
122
97
  // src/Diviner.ts
123
- var toNftCollectionScore = /* @__PURE__ */ __name((nftCollectionInfo, scores) => {
98
+ var toNftCollectionScore = (nftCollectionInfo, scores) => {
124
99
  const { name, symbol, address, chainId, type } = nftCollectionInfo;
125
- const metadata = {
126
- address,
127
- chainId,
128
- name,
129
- symbol,
130
- type
131
- };
132
- return {
133
- ...metadata,
134
- schema: NftCollectionScoreSchema,
135
- scores
136
- };
137
- }, "toNftCollectionScore");
100
+ const metadata = { address, chainId, name, symbol, type };
101
+ return { ...metadata, schema: NftCollectionScoreSchema, scores };
102
+ };
138
103
  var NftCollectionScoreDiviner = class extends AbstractDiviner {
139
- static {
140
- __name(this, "NftCollectionScoreDiviner");
141
- }
142
- static configSchemas = [
143
- ...super.configSchemas,
144
- NftCollectionScoreDivinerConfigSchema
145
- ];
104
+ static configSchemas = [...super.configSchemas, NftCollectionScoreDivinerConfigSchema];
146
105
  static defaultConfigSchema = NftCollectionScoreDivinerConfigSchema;
147
- divineHandler = /* @__PURE__ */ __name(async (payloads) => {
106
+ divineHandler = async (payloads) => {
148
107
  const nftCollectionInfos = payloads?.filter(isNftCollectionInfo) ?? [];
149
- const results = await Promise.all(nftCollectionInfos.map(async (nftCollectionInfo) => {
150
- const [score, sourceHash] = await Promise.all([
151
- // Get score
152
- toNftCollectionScore(nftCollectionInfo, await analyzeNftCollection(nftCollectionInfo)),
153
- // Hash sources
154
- PayloadBuilder.dataHash(nftCollectionInfo)
155
- ]);
156
- return {
157
- ...score,
158
- schema: NftCollectionScoreSchema,
159
- sources: [
160
- sourceHash
161
- ]
162
- };
163
- }));
108
+ const results = await Promise.all(
109
+ nftCollectionInfos.map(async (nftCollectionInfo) => {
110
+ const [score, sourceHash] = await Promise.all([
111
+ // Get score
112
+ toNftCollectionScore(nftCollectionInfo, await analyzeNftCollection(nftCollectionInfo)),
113
+ // Hash sources
114
+ PayloadBuilder.dataHash(nftCollectionInfo)
115
+ ]);
116
+ return { ...score, schema: NftCollectionScoreSchema, sources: [sourceHash] };
117
+ })
118
+ );
164
119
  return results;
165
- }, "divineHandler");
120
+ };
166
121
  };
167
122
 
168
123
  // src/Plugin.ts
169
124
  import { NftSchema } from "@xyo-network/crypto-nft-payload-plugin";
170
125
  import { PayloadSetSchema } from "@xyo-network/payload-model";
171
126
  import { createPayloadSetDivinerPlugin } from "@xyo-network/payloadset-plugin";
172
- var NftCollectionScoreDivinerPlugin = /* @__PURE__ */ __name(() => createPayloadSetDivinerPlugin({
173
- required: {
174
- [NftSchema]: 1
175
- },
176
- schema: PayloadSetSchema
177
- }, {
178
- diviner: /* @__PURE__ */ __name(async (params) => {
179
- const result = await NftCollectionScoreDiviner.create(params);
180
- return result;
181
- }, "diviner")
182
- }), "NftCollectionScoreDivinerPlugin");
127
+ var NftCollectionScoreDivinerPlugin = () => createPayloadSetDivinerPlugin(
128
+ { required: { [NftSchema]: 1 }, schema: PayloadSetSchema },
129
+ {
130
+ diviner: async (params) => {
131
+ const result = await NftCollectionScoreDiviner.create(params);
132
+ return result;
133
+ }
134
+ }
135
+ );
183
136
  export {
184
137
  NftCollectionScoreDiviner,
185
138
  NftCollectionScoreDivinerPlugin,
@@ -1 +1 @@
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 {\n isNftCollectionInfo,\n NftCollectionInfo,\n NftCollectionMetadata,\n NftCollectionScore,\n NftCollectionScoreDivinerConfig,\n NftCollectionScoreDivinerConfigSchema,\n NftCollectionScoreSchema,\n} from '@xyo-network/crypto-nft-collection-payload-plugin'\nimport { AbstractDiviner } from '@xyo-network/diviner-abstract'\nimport { DivinerParams } from '@xyo-network/diviner-model'\nimport { AnyConfigSchema } from '@xyo-network/module-model'\nimport { PayloadBuilder } from '@xyo-network/payload-builder'\nimport { Payload, Schema } from '@xyo-network/payload-model'\n\nimport { analyzeNftCollection, NftCollectionAnalysis } from './lib/index.ts'\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 readonly configSchemas: Schema[] = [...super.configSchemas, NftCollectionScoreDivinerConfigSchema]\n static override readonly defaultConfigSchema: Schema = 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 PayloadBuilder.dataHash(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.ts'\nimport { scoreTotalAttributes } from './scoreTotalAttributes.ts'\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/index.ts'\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/index.ts'\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.ts'\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,SACEA,qBAKAC,uCACAC,gCACK;AACP,SAASC,uBAAuB;AAGhC,SAASC,sBAAsB;;;ACX/B,SAASC,iBAAwB;AAEjC,IAAMC,WAAW;AAEV,IAAMC,4BAA4B,wBAACC,SAAAA;AACxC,QAAM,EAAEC,WAAU,IAAKD,KAAKE,QAAQC;AACpC,QAAMC,UAAUC,OAAOD,QAAQH,UAAAA;AAC/B,MAAIG,QAAQE,WAAW,EAAG,QAAO;IAAC;IAAGR;;AACrC,QAAMS,SAASF,OAAOD,QAAQH,UAAAA,EAAYO,QAAQ,CAAC,CAACC,QAAQ,EAAEC,OAAM,CAAE,MAAC;AACrE,WAAOL,OAAOD,QAAQM,MAAAA,EAAQC,IAAW,CAAC,CAACC,aAAaV,OAAAA,MAAQ;AAC9D,YAAMW,SAASC,KAAKC,IAAID,KAAKE,OAAO,IAAId,QAAQe,SAASC,KAAKpB,QAAAA,GAAWA,QAAAA;AACzE,aAAO;QAACe;QAAQf;;IAClB,CAAA;EACF,CAAA;AAEA,QAAMqB,QAAQZ,OAAOa,OAAc,CAAC,CAACC,GAAGC,CAAAA,GAAI,CAACC,GAAGC,CAAAA,MAAO;IAACH,IAAIE;IAAGD,IAAIE;KAAI;IAAC;IAAG;GAAE;AAC7E,SAAOC,UAAUN,OAAOrB,QAAAA;AAC1B,GAbyC;;;ACJzC,SAAS4B,aAAAA,kBAAwB;AAEjC,IAAMC,YAAW;AAKjB,IAAMC,YAAY;AAKlB,IAAMC,eAAe;AASrB,IAAMC,6BAA6B,wBAACC,GAAWC,KAAaJ,WAAWK,QAAgBJ,iBAAY;AACjG,QAAMK,YAAYC,KAAKC,KAAK,IA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AA;AACzD,YAAM,CAACwB,OAAOC,UAAAA,IAAc,MAAMJ,QAAQC,IAAI;;QAE5CvB,qBAAqBC,mBAAmB,MAAM0B,qBAAqB1B,iBAAAA,CAAAA;;QAEnE2B,eAAeC,SAAS5B,iBAAAA;OACzB;AACD,aAAO;QAAE,GAAGwB;QAAOhB,QAAQC;QAA0BoB,SAAS;UAACJ;;MAAY;IAC7E,CAAA,CAAA;AAEF,WAAOL;EACT,GAdmC;AAerC;;;AO9CA,SAASU,iBAAiB;AAC1B,SAASC,wBAAwB;AACjC,SAASC,qCAAqC;AAIvC,IAAMC,kCAAkC,6BAC7CC,8BACE;EAAEC,UAAU;IAAE,CAACC,SAAAA,GAAY;EAAE;EAAGC,QAAQC;AAAiB,GACzD;EACEC,SAAS,8BAAOC,WAAAA;AACd,UAAMC,SAAS,MAAMC,0BAA0BC,OAAOH,MAAAA;AACtD,WAAOC;EACT,GAHS;AAIX,CAAA,GAR2C;","names":["isNftCollectionInfo","NftCollectionScoreDivinerConfigSchema","NftCollectionScoreSchema","AbstractDiviner","PayloadBuilder","normalize","maxScore","scoreIndividualAttributes","info","attributes","metrics","metadata","entries","Object","length","scores","flatMap","_trait","values","map","_traitValue","rarity","Math","min","round","binomial","p","total","reduce","a","b","c","d","normalize","normalize","maxScore","defaultMu","defaultSigma","gaussianProbabilityDensity","x","mu","sigma","sqrtTwoPi","Math","sqrt","PI","denominator","power","pow","exp","maxProbabilityDensity","scoreTotalAttributes","info","attributes","metrics","metadata","jointProbability","Object","entries","reduce","acc","_trait","binomial","p","probabilityDensity","score","normalize","attributeScoringCriteria","score","scoreIndividualAttributes","weight","scoreTotalAttributes","scoreMetadata","normalize","median","defaultMu","Math","log","defaultSigma","mode","exp","pow","logNormalProbabilityDensity","x","mu","sigma","logX","sqrt","PI","maxProbabilityDensity","maxScore","scoreTotal","nft","density","total","score","normalize","scoringCriteria","scoreMetadata","Total","score","scoreTotal","weight","analyzeNftCollection","nft","result","Object","fromEntries","Promise","all","entries","scoringCriteria","map","key","score","weight","rawScore","weighted","v","toNftCollectionScore","nftCollectionInfo","scores","name","symbol","address","chainId","type","metadata","schema","NftCollectionScoreSchema","NftCollectionScoreDiviner","AbstractDiviner","configSchemas","NftCollectionScoreDivinerConfigSchema","defaultConfigSchema","divineHandler","payloads","nftCollectionInfos","filter","isNftCollectionInfo","results","Promise","all","map","score","sourceHash","analyzeNftCollection","PayloadBuilder","dataHash","sources","NftSchema","PayloadSetSchema","createPayloadSetDivinerPlugin","NftCollectionScoreDivinerPlugin","createPayloadSetDivinerPlugin","required","NftSchema","schema","PayloadSetSchema","diviner","params","result","NftCollectionScoreDiviner","create"]}
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 {\n isNftCollectionInfo,\n NftCollectionInfo,\n NftCollectionMetadata,\n NftCollectionScore,\n NftCollectionScoreDivinerConfig,\n NftCollectionScoreDivinerConfigSchema,\n NftCollectionScoreSchema,\n} from '@xyo-network/crypto-nft-collection-payload-plugin'\nimport { AbstractDiviner } from '@xyo-network/diviner-abstract'\nimport { DivinerParams } from '@xyo-network/diviner-model'\nimport { AnyConfigSchema } from '@xyo-network/module-model'\nimport { PayloadBuilder } from '@xyo-network/payload-builder'\nimport { Payload, Schema } from '@xyo-network/payload-model'\n\nimport { analyzeNftCollection, NftCollectionAnalysis } from './lib/index.ts'\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 readonly configSchemas: Schema[] = [...super.configSchemas, NftCollectionScoreDivinerConfigSchema]\n static override readonly defaultConfigSchema: Schema = 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 PayloadBuilder.dataHash(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.ts'\nimport { scoreTotalAttributes } from './scoreTotalAttributes.ts'\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/index.ts'\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/index.ts'\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.ts'\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,EACE;AAAA,EAKA;AAAA,EACA;AAAA,OACK;AACP,SAAS,uBAAuB;AAGhC,SAAS,sBAAsB;;;ACX/B,SAAS,iBAAwB;AAEjC,IAAM,WAAW;AAEV,IAAM,4BAA4B,CAA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AM,0BAA0B,OAAO,MAAM;AAC5D,aAAO;AAAA,IACT;AAAA,EACF;AACF;","names":["normalize","maxScore","normalize","defaultMu","defaultSigma","maxProbabilityDensity","maxScore"]}
@@ -1,8 +1,8 @@
1
1
  import { NftCollectionScoreDiviner } from './Diviner.ts';
2
2
  export declare const NftCollectionScoreDivinerPlugin: () => import("@xyo-network/payloadset-plugin").PayloadSetDivinerPlugin<NftCollectionScoreDiviner<import("@xylabs/object").BaseParamsFields & {
3
- account?: import("@xyo-network/account-model").AccountInstance | "random";
3
+ account?: import(".store/@xyo-network-account-model-virtual-c593258ccf/package").AccountInstance | "random";
4
4
  addToResolvers?: boolean;
5
- additionalSigners?: import("@xyo-network/account-model").AccountInstance[];
5
+ additionalSigners?: import(".store/@xyo-network-account-model-virtual-c593258ccf/package").AccountInstance[];
6
6
  allowNameResolution?: boolean;
7
7
  config: import("@xyo-network/payload-model").SchemaFields & import("@xyo-network/payload-model").PayloadFields & Omit<import("@xyo-network/module-model").ArchivingModuleConfig & import("@xyo-network/module-model").ModuleConfigFields & import("@xyo-network/payload-model").SchemaFields & import("@xyo-network/payload-model").PayloadFields & Omit<import("@xyo-network/module-model").ArchivingModuleConfig & import("@xyo-network/module-model").ModuleConfigFields & {
8
8
  schema: "network.xyo.crypto.nft.collection.score.diviner.config";
@@ -1,8 +1,8 @@
1
1
  import { NftCollectionScoreDiviner } from './Diviner.ts';
2
2
  export declare const NftCollectionScoreDivinerPlugin: () => import("@xyo-network/payloadset-plugin").PayloadSetDivinerPlugin<NftCollectionScoreDiviner<import("@xylabs/object").BaseParamsFields & {
3
- account?: import("@xyo-network/account-model").AccountInstance | "random";
3
+ account?: import(".store/@xyo-network-account-model-virtual-c593258ccf/package").AccountInstance | "random";
4
4
  addToResolvers?: boolean;
5
- additionalSigners?: import("@xyo-network/account-model").AccountInstance[];
5
+ additionalSigners?: import(".store/@xyo-network-account-model-virtual-c593258ccf/package").AccountInstance[];
6
6
  allowNameResolution?: boolean;
7
7
  config: import("@xyo-network/payload-model").SchemaFields & import("@xyo-network/payload-model").PayloadFields & Omit<import("@xyo-network/module-model").ArchivingModuleConfig & import("@xyo-network/module-model").ModuleConfigFields & import("@xyo-network/payload-model").SchemaFields & import("@xyo-network/payload-model").PayloadFields & Omit<import("@xyo-network/module-model").ArchivingModuleConfig & import("@xyo-network/module-model").ModuleConfigFields & {
8
8
  schema: "network.xyo.crypto.nft.collection.score.diviner.config";
@@ -1,8 +1,8 @@
1
1
  import { NftCollectionScoreDiviner } from './Diviner.ts';
2
2
  export declare const NftCollectionScoreDivinerPlugin: () => import("@xyo-network/payloadset-plugin").PayloadSetDivinerPlugin<NftCollectionScoreDiviner<import("@xylabs/object").BaseParamsFields & {
3
- account?: import("@xyo-network/account-model").AccountInstance | "random";
3
+ account?: import(".store/@xyo-network-account-model-virtual-c593258ccf/package").AccountInstance | "random";
4
4
  addToResolvers?: boolean;
5
- additionalSigners?: import("@xyo-network/account-model").AccountInstance[];
5
+ additionalSigners?: import(".store/@xyo-network-account-model-virtual-c593258ccf/package").AccountInstance[];
6
6
  allowNameResolution?: boolean;
7
7
  config: import("@xyo-network/payload-model").SchemaFields & import("@xyo-network/payload-model").PayloadFields & Omit<import("@xyo-network/module-model").ArchivingModuleConfig & import("@xyo-network/module-model").ModuleConfigFields & import("@xyo-network/payload-model").SchemaFields & import("@xyo-network/payload-model").PayloadFields & Omit<import("@xyo-network/module-model").ArchivingModuleConfig & import("@xyo-network/module-model").ModuleConfigFields & {
8
8
  schema: "network.xyo.crypto.nft.collection.score.diviner.config";
@@ -2,11 +2,7 @@
2
2
  var __defProp = Object.defineProperty;
3
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __getProtoOf = Object.getPrototypeOf;
6
5
  var __hasOwnProp = Object.prototype.hasOwnProperty;
7
- var __reflectGet = Reflect.get;
8
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
9
- var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
10
6
  var __export = (target, all) => {
11
7
  for (var name in all)
12
8
  __defProp(target, name, { get: all[name], enumerable: true });
@@ -20,8 +16,6 @@ var __copyProps = (to, from, except, desc) => {
20
16
  return to;
21
17
  };
22
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
23
- var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
24
- var __superGet = (cls, obj, key) => __reflectGet(__getProtoOf(cls), key, obj);
25
19
 
26
20
  // src/index.ts
27
21
  var src_exports = {};
@@ -42,67 +36,46 @@ var import_payload_builder = require("@xyo-network/payload-builder");
42
36
  // src/lib/rating/criteria/scoring/metadata/scoreIndividualAttributes.ts
43
37
  var import_crypto_nft_score_model = require("@xyo-network/crypto-nft-score-model");
44
38
  var maxScore = 10;
45
- var scoreIndividualAttributes = /* @__PURE__ */ __name((info) => {
39
+ var scoreIndividualAttributes = (info) => {
46
40
  const { attributes } = info.metrics.metadata;
47
41
  const entries = Object.entries(attributes);
48
- if (entries.length === 0) return [
49
- 0,
50
- maxScore
51
- ];
42
+ if (entries.length === 0) return [0, maxScore];
52
43
  const scores = Object.entries(attributes).flatMap(([_trait, { values }]) => {
53
44
  return Object.entries(values).map(([_traitValue, metrics]) => {
54
45
  const rarity = Math.min(Math.round((1 - metrics.binomial.p) * maxScore), maxScore);
55
- return [
56
- rarity,
57
- maxScore
58
- ];
46
+ return [rarity, maxScore];
59
47
  });
60
48
  });
61
- const total = scores.reduce(([a, b], [c, d]) => [
62
- a + c,
63
- b + d
64
- ], [
65
- 0,
66
- 0
67
- ]);
49
+ const total = scores.reduce(([a, b], [c, d]) => [a + c, b + d], [0, 0]);
68
50
  return (0, import_crypto_nft_score_model.normalize)(total, maxScore);
69
- }, "scoreIndividualAttributes");
51
+ };
70
52
 
71
53
  // src/lib/rating/criteria/scoring/metadata/scoreTotalAttributes.ts
72
54
  var import_crypto_nft_score_model2 = require("@xyo-network/crypto-nft-score-model");
73
55
  var maxScore2 = 10;
74
56
  var defaultMu = 0.15;
75
57
  var defaultSigma = 0.1;
76
- var gaussianProbabilityDensity = /* @__PURE__ */ __name((x, mu = defaultMu, sigma = defaultSigma) => {
58
+ var gaussianProbabilityDensity = (x, mu = defaultMu, sigma = defaultSigma) => {
77
59
  const sqrtTwoPi = Math.sqrt(2 * Math.PI);
78
60
  const denominator = sigma * sqrtTwoPi;
79
61
  const power = -0.5 * Math.pow((x - mu) / sigma, 2);
80
62
  return 1 / denominator * Math.exp(power);
81
- }, "gaussianProbabilityDensity");
63
+ };
82
64
  var maxProbabilityDensity = gaussianProbabilityDensity(defaultMu);
83
- var scoreTotalAttributes = /* @__PURE__ */ __name((info) => {
65
+ var scoreTotalAttributes = (info) => {
84
66
  const { attributes } = info.metrics.metadata;
85
67
  const jointProbability = Object.entries(attributes).reduce((acc, [_trait, { metrics }]) => {
86
68
  return acc * metrics.binomial.p;
87
69
  }, 1);
88
70
  const probabilityDensity = gaussianProbabilityDensity(jointProbability);
89
- const score = [
90
- probabilityDensity,
91
- maxProbabilityDensity
92
- ];
71
+ const score = [probabilityDensity, maxProbabilityDensity];
93
72
  return (0, import_crypto_nft_score_model2.normalize)(score, maxScore2);
94
- }, "scoreTotalAttributes");
73
+ };
95
74
 
96
75
  // src/lib/rating/criteria/scoring/metadata/metadata.ts
97
76
  var attributeScoringCriteria = {
98
- "Metadata Attributes Individual": {
99
- score: scoreIndividualAttributes,
100
- weight: 2
101
- },
102
- "Metadata Attributes Total": {
103
- score: scoreTotalAttributes,
104
- weight: 2
105
- }
77
+ "Metadata Attributes Individual": { score: scoreIndividualAttributes, weight: 2 },
78
+ "Metadata Attributes Total": { score: scoreTotalAttributes, weight: 2 }
106
79
  };
107
80
  var scoreMetadata = {
108
81
  ...attributeScoringCriteria
@@ -114,104 +87,78 @@ var median = 810308398217352e-7;
114
87
  var defaultMu2 = Math.log(median);
115
88
  var defaultSigma2 = 3;
116
89
  var mode = Math.exp(defaultMu2 - Math.pow(defaultSigma2, 2));
117
- var logNormalProbabilityDensity = /* @__PURE__ */ __name((x, mu = defaultMu2, sigma = defaultSigma2) => {
90
+ var logNormalProbabilityDensity = (x, mu = defaultMu2, sigma = defaultSigma2) => {
118
91
  if (x <= 0) return 0;
119
92
  const logX = Math.log(x);
120
93
  return 1 / (x * sigma * Math.sqrt(2 * Math.PI)) * Math.exp(-0.5 * Math.pow((logX - mu) / sigma, 2));
121
- }, "logNormalProbabilityDensity");
94
+ };
122
95
  var maxProbabilityDensity2 = logNormalProbabilityDensity(mode);
123
96
  var maxScore3 = 10;
124
- var scoreTotal = /* @__PURE__ */ __name((nft) => {
97
+ var scoreTotal = (nft) => {
125
98
  const density = logNormalProbabilityDensity(nft.total);
126
- const score = [
127
- density,
128
- maxProbabilityDensity2
129
- ];
99
+ const score = [density, maxProbabilityDensity2];
130
100
  return (0, import_crypto_nft_score_model3.normalize)(score, maxScore3);
131
- }, "scoreTotal");
101
+ };
132
102
 
133
103
  // src/lib/rating/criteria/index.ts
134
104
  var scoringCriteria = {
135
105
  ...scoreMetadata,
136
- Total: {
137
- score: scoreTotal,
138
- weight: 2
139
- }
106
+ Total: { score: scoreTotal, weight: 2 }
140
107
  };
141
108
 
142
109
  // src/lib/rating/analyzeNftCollection.ts
143
- var analyzeNftCollection = /* @__PURE__ */ __name(async (nft) => {
144
- const result = Object.fromEntries(await Promise.all(Object.entries(scoringCriteria).map(async ([key, { score, weight }]) => {
145
- const rawScore = await score(nft);
146
- const weighted = rawScore.map((v) => v * weight);
147
- return [
148
- key,
149
- weighted
150
- ];
151
- })));
110
+ var analyzeNftCollection = async (nft) => {
111
+ const result = Object.fromEntries(
112
+ await Promise.all(
113
+ Object.entries(scoringCriteria).map(async ([key, { score, weight }]) => {
114
+ const rawScore = await score(nft);
115
+ const weighted = rawScore.map((v) => v * weight);
116
+ return [key, weighted];
117
+ })
118
+ )
119
+ );
152
120
  return result;
153
- }, "analyzeNftCollection");
121
+ };
154
122
 
155
123
  // src/Diviner.ts
156
- var toNftCollectionScore = /* @__PURE__ */ __name((nftCollectionInfo, scores) => {
124
+ var toNftCollectionScore = (nftCollectionInfo, scores) => {
157
125
  const { name, symbol, address, chainId, type } = nftCollectionInfo;
158
- const metadata = {
159
- address,
160
- chainId,
161
- name,
162
- symbol,
163
- type
164
- };
165
- return {
166
- ...metadata,
167
- schema: import_crypto_nft_collection_payload_plugin.NftCollectionScoreSchema,
168
- scores
169
- };
170
- }, "toNftCollectionScore");
171
- var _NftCollectionScoreDiviner = class _NftCollectionScoreDiviner extends import_diviner_abstract.AbstractDiviner {
172
- divineHandler = /* @__PURE__ */ __name(async (payloads) => {
126
+ const metadata = { address, chainId, name, symbol, type };
127
+ return { ...metadata, schema: import_crypto_nft_collection_payload_plugin.NftCollectionScoreSchema, scores };
128
+ };
129
+ var NftCollectionScoreDiviner = class extends import_diviner_abstract.AbstractDiviner {
130
+ static configSchemas = [...super.configSchemas, import_crypto_nft_collection_payload_plugin.NftCollectionScoreDivinerConfigSchema];
131
+ static defaultConfigSchema = import_crypto_nft_collection_payload_plugin.NftCollectionScoreDivinerConfigSchema;
132
+ divineHandler = async (payloads) => {
173
133
  const nftCollectionInfos = (payloads == null ? void 0 : payloads.filter(import_crypto_nft_collection_payload_plugin.isNftCollectionInfo)) ?? [];
174
- const results = await Promise.all(nftCollectionInfos.map(async (nftCollectionInfo) => {
175
- const [score, sourceHash] = await Promise.all([
176
- // Get score
177
- toNftCollectionScore(nftCollectionInfo, await analyzeNftCollection(nftCollectionInfo)),
178
- // Hash sources
179
- import_payload_builder.PayloadBuilder.dataHash(nftCollectionInfo)
180
- ]);
181
- return {
182
- ...score,
183
- schema: import_crypto_nft_collection_payload_plugin.NftCollectionScoreSchema,
184
- sources: [
185
- sourceHash
186
- ]
187
- };
188
- }));
134
+ const results = await Promise.all(
135
+ nftCollectionInfos.map(async (nftCollectionInfo) => {
136
+ const [score, sourceHash] = await Promise.all([
137
+ // Get score
138
+ toNftCollectionScore(nftCollectionInfo, await analyzeNftCollection(nftCollectionInfo)),
139
+ // Hash sources
140
+ import_payload_builder.PayloadBuilder.dataHash(nftCollectionInfo)
141
+ ]);
142
+ return { ...score, schema: import_crypto_nft_collection_payload_plugin.NftCollectionScoreSchema, sources: [sourceHash] };
143
+ })
144
+ );
189
145
  return results;
190
- }, "divineHandler");
146
+ };
191
147
  };
192
- __name(_NftCollectionScoreDiviner, "NftCollectionScoreDiviner");
193
- __publicField(_NftCollectionScoreDiviner, "configSchemas", [
194
- ...__superGet(_NftCollectionScoreDiviner, _NftCollectionScoreDiviner, "configSchemas"),
195
- import_crypto_nft_collection_payload_plugin.NftCollectionScoreDivinerConfigSchema
196
- ]);
197
- __publicField(_NftCollectionScoreDiviner, "defaultConfigSchema", import_crypto_nft_collection_payload_plugin.NftCollectionScoreDivinerConfigSchema);
198
- var NftCollectionScoreDiviner = _NftCollectionScoreDiviner;
199
148
 
200
149
  // src/Plugin.ts
201
150
  var import_crypto_nft_payload_plugin = require("@xyo-network/crypto-nft-payload-plugin");
202
151
  var import_payload_model = require("@xyo-network/payload-model");
203
152
  var import_payloadset_plugin = require("@xyo-network/payloadset-plugin");
204
- var NftCollectionScoreDivinerPlugin = /* @__PURE__ */ __name(() => (0, import_payloadset_plugin.createPayloadSetDivinerPlugin)({
205
- required: {
206
- [import_crypto_nft_payload_plugin.NftSchema]: 1
207
- },
208
- schema: import_payload_model.PayloadSetSchema
209
- }, {
210
- diviner: /* @__PURE__ */ __name(async (params) => {
211
- const result = await NftCollectionScoreDiviner.create(params);
212
- return result;
213
- }, "diviner")
214
- }), "NftCollectionScoreDivinerPlugin");
153
+ var NftCollectionScoreDivinerPlugin = () => (0, import_payloadset_plugin.createPayloadSetDivinerPlugin)(
154
+ { required: { [import_crypto_nft_payload_plugin.NftSchema]: 1 }, schema: import_payload_model.PayloadSetSchema },
155
+ {
156
+ diviner: async (params) => {
157
+ const result = await NftCollectionScoreDiviner.create(params);
158
+ return result;
159
+ }
160
+ }
161
+ );
215
162
  // Annotate the CommonJS export names for ESM import in node:
216
163
  0 && (module.exports = {
217
164
  NftCollectionScoreDiviner,