@xyo-network/crypto-nft-collection-diviner-score-plugin 2.99.3 → 2.99.5
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 +1 -1
- package/dist/browser/Plugin.d.mts +1 -1
- package/dist/browser/Plugin.d.ts +1 -1
- package/dist/browser/index.cjs +105 -56
- package/dist/browser/index.cjs.map +1 -1
- package/dist/browser/index.d.cts +3 -3
- package/dist/browser/index.d.mts +3 -3
- package/dist/browser/index.d.ts +3 -3
- package/dist/browser/index.mjs +190 -0
- package/dist/browser/{index.js.map → index.mjs.map} +1 -1
- package/dist/browser/lib/index.d.cts +1 -1
- package/dist/browser/lib/index.d.mts +1 -1
- package/dist/browser/lib/index.d.ts +1 -1
- package/dist/browser/lib/rating/analyzeNftCollection.d.cts +1 -1
- package/dist/browser/lib/rating/analyzeNftCollection.d.mts +1 -1
- package/dist/browser/lib/rating/analyzeNftCollection.d.ts +1 -1
- package/dist/browser/lib/rating/criteria/scoring/index.d.cts +2 -2
- package/dist/browser/lib/rating/criteria/scoring/index.d.mts +2 -2
- package/dist/browser/lib/rating/criteria/scoring/index.d.ts +2 -2
- package/dist/browser/lib/rating/criteria/scoring/metadata/index.d.cts +1 -1
- package/dist/browser/lib/rating/criteria/scoring/metadata/index.d.mts +1 -1
- package/dist/browser/lib/rating/criteria/scoring/metadata/index.d.ts +1 -1
- package/dist/browser/lib/rating/index.d.cts +2 -2
- package/dist/browser/lib/rating/index.d.mts +2 -2
- package/dist/browser/lib/rating/index.d.ts +2 -2
- package/dist/neutral/Plugin.d.cts +1 -1
- package/dist/neutral/Plugin.d.mts +1 -1
- package/dist/neutral/Plugin.d.ts +1 -1
- package/dist/neutral/index.cjs +105 -56
- package/dist/neutral/index.cjs.map +1 -1
- package/dist/neutral/index.d.cts +3 -3
- package/dist/neutral/index.d.mts +3 -3
- package/dist/neutral/index.d.ts +3 -3
- package/dist/neutral/index.mjs +190 -0
- package/dist/neutral/{index.js.map → index.mjs.map} +1 -1
- package/dist/neutral/lib/index.d.cts +1 -1
- package/dist/neutral/lib/index.d.mts +1 -1
- package/dist/neutral/lib/index.d.ts +1 -1
- package/dist/neutral/lib/rating/analyzeNftCollection.d.cts +1 -1
- package/dist/neutral/lib/rating/analyzeNftCollection.d.mts +1 -1
- package/dist/neutral/lib/rating/analyzeNftCollection.d.ts +1 -1
- package/dist/neutral/lib/rating/criteria/scoring/index.d.cts +2 -2
- package/dist/neutral/lib/rating/criteria/scoring/index.d.mts +2 -2
- package/dist/neutral/lib/rating/criteria/scoring/index.d.ts +2 -2
- package/dist/neutral/lib/rating/criteria/scoring/metadata/index.d.cts +1 -1
- package/dist/neutral/lib/rating/criteria/scoring/metadata/index.d.mts +1 -1
- package/dist/neutral/lib/rating/criteria/scoring/metadata/index.d.ts +1 -1
- package/dist/neutral/lib/rating/index.d.cts +2 -2
- package/dist/neutral/lib/rating/index.d.mts +2 -2
- package/dist/neutral/lib/rating/index.d.ts +2 -2
- package/dist/node/Plugin.d.cts +1 -1
- package/dist/node/Plugin.d.mts +1 -1
- package/dist/node/Plugin.d.ts +1 -1
- package/dist/node/index.cjs +111 -58
- package/dist/node/index.cjs.map +1 -1
- package/dist/node/index.d.cts +3 -3
- package/dist/node/index.d.mts +3 -3
- package/dist/node/index.d.ts +3 -3
- package/dist/node/index.mjs +194 -0
- package/dist/node/{index.js.map → index.mjs.map} +1 -1
- package/dist/node/lib/index.d.cts +1 -1
- package/dist/node/lib/index.d.mts +1 -1
- package/dist/node/lib/index.d.ts +1 -1
- package/dist/node/lib/rating/analyzeNftCollection.d.cts +1 -1
- package/dist/node/lib/rating/analyzeNftCollection.d.mts +1 -1
- package/dist/node/lib/rating/analyzeNftCollection.d.ts +1 -1
- package/dist/node/lib/rating/criteria/scoring/index.d.cts +2 -2
- package/dist/node/lib/rating/criteria/scoring/index.d.mts +2 -2
- package/dist/node/lib/rating/criteria/scoring/index.d.ts +2 -2
- package/dist/node/lib/rating/criteria/scoring/metadata/index.d.cts +1 -1
- package/dist/node/lib/rating/criteria/scoring/metadata/index.d.mts +1 -1
- package/dist/node/lib/rating/criteria/scoring/metadata/index.d.ts +1 -1
- package/dist/node/lib/rating/index.d.cts +2 -2
- package/dist/node/lib/rating/index.d.mts +2 -2
- package/dist/node/lib/rating/index.d.ts +2 -2
- package/package.json +20 -20
- package/src/Diviner.ts +1 -1
- package/src/Plugin.ts +1 -1
- package/src/index.ts +3 -3
- package/src/lib/index.ts +1 -1
- package/src/lib/rating/analyzeNftCollection.ts +2 -2
- package/src/lib/rating/criteria/index.ts +1 -1
- package/src/lib/rating/criteria/scoring/index.ts +2 -2
- package/src/lib/rating/criteria/scoring/metadata/index.ts +1 -1
- package/src/lib/rating/criteria/scoring/metadata/metadata.ts +2 -2
- package/src/lib/rating/index.ts +2 -2
- package/dist/browser/index.js +0 -143
- package/dist/neutral/index.js +0 -143
- package/dist/node/index.js +0 -143
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from './metadata/index.
|
|
2
|
-
export * from './total.
|
|
1
|
+
export * from './metadata/index.ts'
|
|
2
|
+
export * from './total.ts'
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from './metadata.
|
|
1
|
+
export * from './metadata.ts'
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { NftCollectionInfo } from '@xyo-network/crypto-nft-collection-payload-plugin'
|
|
2
2
|
import { WeightedScoringCriteria } from '@xyo-network/crypto-nft-score-model'
|
|
3
3
|
|
|
4
|
-
import { scoreIndividualAttributes } from './scoreIndividualAttributes.
|
|
5
|
-
import { scoreTotalAttributes } from './scoreTotalAttributes.
|
|
4
|
+
import { scoreIndividualAttributes } from './scoreIndividualAttributes.ts'
|
|
5
|
+
import { scoreTotalAttributes } from './scoreTotalAttributes.ts'
|
|
6
6
|
|
|
7
7
|
export const attributeScoringCriteria: { [key: string]: WeightedScoringCriteria<NftCollectionInfo> } = {
|
|
8
8
|
'Metadata Attributes Individual': { score: scoreIndividualAttributes, weight: 2 },
|
package/src/lib/rating/index.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from './analyzeNftCollection.
|
|
2
|
-
export * from './criteria/index.
|
|
1
|
+
export * from './analyzeNftCollection.ts'
|
|
2
|
+
export * from './criteria/index.ts'
|
package/dist/browser/index.js
DELETED
|
@@ -1,143 +0,0 @@
|
|
|
1
|
-
// src/Diviner.ts
|
|
2
|
-
import {
|
|
3
|
-
isNftCollectionInfo,
|
|
4
|
-
NftCollectionScoreDivinerConfigSchema,
|
|
5
|
-
NftCollectionScoreSchema
|
|
6
|
-
} from "@xyo-network/crypto-nft-collection-payload-plugin";
|
|
7
|
-
import { AbstractDiviner } from "@xyo-network/diviner-abstract";
|
|
8
|
-
import { PayloadBuilder } from "@xyo-network/payload-builder";
|
|
9
|
-
|
|
10
|
-
// src/lib/rating/criteria/scoring/metadata/scoreIndividualAttributes.ts
|
|
11
|
-
import { normalize } from "@xyo-network/crypto-nft-score-model";
|
|
12
|
-
var maxScore = 10;
|
|
13
|
-
var scoreIndividualAttributes = (info) => {
|
|
14
|
-
const { attributes } = info.metrics.metadata;
|
|
15
|
-
const entries = Object.entries(attributes);
|
|
16
|
-
if (entries.length === 0) return [0, maxScore];
|
|
17
|
-
const scores = Object.entries(attributes).flatMap(([_trait, { values }]) => {
|
|
18
|
-
return Object.entries(values).map(([_traitValue, metrics]) => {
|
|
19
|
-
const rarity = Math.min(Math.round((1 - metrics.binomial.p) * maxScore), maxScore);
|
|
20
|
-
return [rarity, maxScore];
|
|
21
|
-
});
|
|
22
|
-
});
|
|
23
|
-
const total = scores.reduce(([a, b], [c, d]) => [a + c, b + d], [0, 0]);
|
|
24
|
-
return normalize(total, maxScore);
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
// src/lib/rating/criteria/scoring/metadata/scoreTotalAttributes.ts
|
|
28
|
-
import { normalize as normalize2 } from "@xyo-network/crypto-nft-score-model";
|
|
29
|
-
var maxScore2 = 10;
|
|
30
|
-
var defaultMu = 0.15;
|
|
31
|
-
var defaultSigma = 0.1;
|
|
32
|
-
var gaussianProbabilityDensity = (x, mu = defaultMu, sigma = defaultSigma) => {
|
|
33
|
-
const sqrtTwoPi = Math.sqrt(2 * Math.PI);
|
|
34
|
-
const denominator = sigma * sqrtTwoPi;
|
|
35
|
-
const power = -0.5 * Math.pow((x - mu) / sigma, 2);
|
|
36
|
-
return 1 / denominator * Math.exp(power);
|
|
37
|
-
};
|
|
38
|
-
var maxProbabilityDensity = gaussianProbabilityDensity(defaultMu);
|
|
39
|
-
var scoreTotalAttributes = (info) => {
|
|
40
|
-
const { attributes } = info.metrics.metadata;
|
|
41
|
-
const jointProbability = Object.entries(attributes).reduce((acc, [_trait, { metrics }]) => {
|
|
42
|
-
return acc * metrics.binomial.p;
|
|
43
|
-
}, 1);
|
|
44
|
-
const probabilityDensity = gaussianProbabilityDensity(jointProbability);
|
|
45
|
-
const score = [probabilityDensity, maxProbabilityDensity];
|
|
46
|
-
return normalize2(score, maxScore2);
|
|
47
|
-
};
|
|
48
|
-
|
|
49
|
-
// src/lib/rating/criteria/scoring/metadata/metadata.ts
|
|
50
|
-
var attributeScoringCriteria = {
|
|
51
|
-
"Metadata Attributes Individual": { score: scoreIndividualAttributes, weight: 2 },
|
|
52
|
-
"Metadata Attributes Total": { score: scoreTotalAttributes, weight: 2 }
|
|
53
|
-
};
|
|
54
|
-
var scoreMetadata = {
|
|
55
|
-
...attributeScoringCriteria
|
|
56
|
-
};
|
|
57
|
-
|
|
58
|
-
// src/lib/rating/criteria/scoring/total.ts
|
|
59
|
-
import { normalize as normalize3 } from "@xyo-network/crypto-nft-score-model";
|
|
60
|
-
var median = 810308398217352e-7;
|
|
61
|
-
var defaultMu2 = Math.log(median);
|
|
62
|
-
var defaultSigma2 = 3;
|
|
63
|
-
var mode = Math.exp(defaultMu2 - Math.pow(defaultSigma2, 2));
|
|
64
|
-
var logNormalProbabilityDensity = (x, mu = defaultMu2, sigma = defaultSigma2) => {
|
|
65
|
-
if (x <= 0) return 0;
|
|
66
|
-
const logX = Math.log(x);
|
|
67
|
-
return 1 / (x * sigma * Math.sqrt(2 * Math.PI)) * Math.exp(-0.5 * Math.pow((logX - mu) / sigma, 2));
|
|
68
|
-
};
|
|
69
|
-
var maxProbabilityDensity2 = logNormalProbabilityDensity(mode);
|
|
70
|
-
var maxScore3 = 10;
|
|
71
|
-
var scoreTotal = (nft) => {
|
|
72
|
-
const density = logNormalProbabilityDensity(nft.total);
|
|
73
|
-
const score = [density, maxProbabilityDensity2];
|
|
74
|
-
return normalize3(score, maxScore3);
|
|
75
|
-
};
|
|
76
|
-
|
|
77
|
-
// src/lib/rating/criteria/index.ts
|
|
78
|
-
var scoringCriteria = {
|
|
79
|
-
...scoreMetadata,
|
|
80
|
-
Total: { score: scoreTotal, weight: 2 }
|
|
81
|
-
};
|
|
82
|
-
|
|
83
|
-
// src/lib/rating/analyzeNftCollection.ts
|
|
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
|
-
);
|
|
94
|
-
return result;
|
|
95
|
-
};
|
|
96
|
-
|
|
97
|
-
// src/Diviner.ts
|
|
98
|
-
var toNftCollectionScore = (nftCollectionInfo, scores) => {
|
|
99
|
-
const { name, symbol, address, chainId, type } = nftCollectionInfo;
|
|
100
|
-
const metadata = { address, chainId, name, symbol, type };
|
|
101
|
-
return { ...metadata, schema: NftCollectionScoreSchema, scores };
|
|
102
|
-
};
|
|
103
|
-
var NftCollectionScoreDiviner = class extends AbstractDiviner {
|
|
104
|
-
static configSchemas = [...super.configSchemas, NftCollectionScoreDivinerConfigSchema];
|
|
105
|
-
static defaultConfigSchema = NftCollectionScoreDivinerConfigSchema;
|
|
106
|
-
divineHandler = async (payloads) => {
|
|
107
|
-
const nftCollectionInfos = payloads?.filter(isNftCollectionInfo) ?? [];
|
|
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
|
-
);
|
|
119
|
-
return results;
|
|
120
|
-
};
|
|
121
|
-
};
|
|
122
|
-
|
|
123
|
-
// src/Plugin.ts
|
|
124
|
-
import { NftSchema } from "@xyo-network/crypto-nft-payload-plugin";
|
|
125
|
-
import { PayloadSetSchema } from "@xyo-network/payload-model";
|
|
126
|
-
import { createPayloadSetDivinerPlugin } from "@xyo-network/payloadset-plugin";
|
|
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
|
-
);
|
|
136
|
-
export {
|
|
137
|
-
NftCollectionScoreDiviner,
|
|
138
|
-
NftCollectionScoreDivinerPlugin,
|
|
139
|
-
analyzeNftCollection,
|
|
140
|
-
NftCollectionScoreDivinerPlugin as default,
|
|
141
|
-
scoringCriteria
|
|
142
|
-
};
|
|
143
|
-
//# sourceMappingURL=index.js.map
|
package/dist/neutral/index.js
DELETED
|
@@ -1,143 +0,0 @@
|
|
|
1
|
-
// src/Diviner.ts
|
|
2
|
-
import {
|
|
3
|
-
isNftCollectionInfo,
|
|
4
|
-
NftCollectionScoreDivinerConfigSchema,
|
|
5
|
-
NftCollectionScoreSchema
|
|
6
|
-
} from "@xyo-network/crypto-nft-collection-payload-plugin";
|
|
7
|
-
import { AbstractDiviner } from "@xyo-network/diviner-abstract";
|
|
8
|
-
import { PayloadBuilder } from "@xyo-network/payload-builder";
|
|
9
|
-
|
|
10
|
-
// src/lib/rating/criteria/scoring/metadata/scoreIndividualAttributes.ts
|
|
11
|
-
import { normalize } from "@xyo-network/crypto-nft-score-model";
|
|
12
|
-
var maxScore = 10;
|
|
13
|
-
var scoreIndividualAttributes = (info) => {
|
|
14
|
-
const { attributes } = info.metrics.metadata;
|
|
15
|
-
const entries = Object.entries(attributes);
|
|
16
|
-
if (entries.length === 0) return [0, maxScore];
|
|
17
|
-
const scores = Object.entries(attributes).flatMap(([_trait, { values }]) => {
|
|
18
|
-
return Object.entries(values).map(([_traitValue, metrics]) => {
|
|
19
|
-
const rarity = Math.min(Math.round((1 - metrics.binomial.p) * maxScore), maxScore);
|
|
20
|
-
return [rarity, maxScore];
|
|
21
|
-
});
|
|
22
|
-
});
|
|
23
|
-
const total = scores.reduce(([a, b], [c, d]) => [a + c, b + d], [0, 0]);
|
|
24
|
-
return normalize(total, maxScore);
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
// src/lib/rating/criteria/scoring/metadata/scoreTotalAttributes.ts
|
|
28
|
-
import { normalize as normalize2 } from "@xyo-network/crypto-nft-score-model";
|
|
29
|
-
var maxScore2 = 10;
|
|
30
|
-
var defaultMu = 0.15;
|
|
31
|
-
var defaultSigma = 0.1;
|
|
32
|
-
var gaussianProbabilityDensity = (x, mu = defaultMu, sigma = defaultSigma) => {
|
|
33
|
-
const sqrtTwoPi = Math.sqrt(2 * Math.PI);
|
|
34
|
-
const denominator = sigma * sqrtTwoPi;
|
|
35
|
-
const power = -0.5 * Math.pow((x - mu) / sigma, 2);
|
|
36
|
-
return 1 / denominator * Math.exp(power);
|
|
37
|
-
};
|
|
38
|
-
var maxProbabilityDensity = gaussianProbabilityDensity(defaultMu);
|
|
39
|
-
var scoreTotalAttributes = (info) => {
|
|
40
|
-
const { attributes } = info.metrics.metadata;
|
|
41
|
-
const jointProbability = Object.entries(attributes).reduce((acc, [_trait, { metrics }]) => {
|
|
42
|
-
return acc * metrics.binomial.p;
|
|
43
|
-
}, 1);
|
|
44
|
-
const probabilityDensity = gaussianProbabilityDensity(jointProbability);
|
|
45
|
-
const score = [probabilityDensity, maxProbabilityDensity];
|
|
46
|
-
return normalize2(score, maxScore2);
|
|
47
|
-
};
|
|
48
|
-
|
|
49
|
-
// src/lib/rating/criteria/scoring/metadata/metadata.ts
|
|
50
|
-
var attributeScoringCriteria = {
|
|
51
|
-
"Metadata Attributes Individual": { score: scoreIndividualAttributes, weight: 2 },
|
|
52
|
-
"Metadata Attributes Total": { score: scoreTotalAttributes, weight: 2 }
|
|
53
|
-
};
|
|
54
|
-
var scoreMetadata = {
|
|
55
|
-
...attributeScoringCriteria
|
|
56
|
-
};
|
|
57
|
-
|
|
58
|
-
// src/lib/rating/criteria/scoring/total.ts
|
|
59
|
-
import { normalize as normalize3 } from "@xyo-network/crypto-nft-score-model";
|
|
60
|
-
var median = 810308398217352e-7;
|
|
61
|
-
var defaultMu2 = Math.log(median);
|
|
62
|
-
var defaultSigma2 = 3;
|
|
63
|
-
var mode = Math.exp(defaultMu2 - Math.pow(defaultSigma2, 2));
|
|
64
|
-
var logNormalProbabilityDensity = (x, mu = defaultMu2, sigma = defaultSigma2) => {
|
|
65
|
-
if (x <= 0) return 0;
|
|
66
|
-
const logX = Math.log(x);
|
|
67
|
-
return 1 / (x * sigma * Math.sqrt(2 * Math.PI)) * Math.exp(-0.5 * Math.pow((logX - mu) / sigma, 2));
|
|
68
|
-
};
|
|
69
|
-
var maxProbabilityDensity2 = logNormalProbabilityDensity(mode);
|
|
70
|
-
var maxScore3 = 10;
|
|
71
|
-
var scoreTotal = (nft) => {
|
|
72
|
-
const density = logNormalProbabilityDensity(nft.total);
|
|
73
|
-
const score = [density, maxProbabilityDensity2];
|
|
74
|
-
return normalize3(score, maxScore3);
|
|
75
|
-
};
|
|
76
|
-
|
|
77
|
-
// src/lib/rating/criteria/index.ts
|
|
78
|
-
var scoringCriteria = {
|
|
79
|
-
...scoreMetadata,
|
|
80
|
-
Total: { score: scoreTotal, weight: 2 }
|
|
81
|
-
};
|
|
82
|
-
|
|
83
|
-
// src/lib/rating/analyzeNftCollection.ts
|
|
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
|
-
);
|
|
94
|
-
return result;
|
|
95
|
-
};
|
|
96
|
-
|
|
97
|
-
// src/Diviner.ts
|
|
98
|
-
var toNftCollectionScore = (nftCollectionInfo, scores) => {
|
|
99
|
-
const { name, symbol, address, chainId, type } = nftCollectionInfo;
|
|
100
|
-
const metadata = { address, chainId, name, symbol, type };
|
|
101
|
-
return { ...metadata, schema: NftCollectionScoreSchema, scores };
|
|
102
|
-
};
|
|
103
|
-
var NftCollectionScoreDiviner = class extends AbstractDiviner {
|
|
104
|
-
static configSchemas = [...super.configSchemas, NftCollectionScoreDivinerConfigSchema];
|
|
105
|
-
static defaultConfigSchema = NftCollectionScoreDivinerConfigSchema;
|
|
106
|
-
divineHandler = async (payloads) => {
|
|
107
|
-
const nftCollectionInfos = payloads?.filter(isNftCollectionInfo) ?? [];
|
|
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
|
-
);
|
|
119
|
-
return results;
|
|
120
|
-
};
|
|
121
|
-
};
|
|
122
|
-
|
|
123
|
-
// src/Plugin.ts
|
|
124
|
-
import { NftSchema } from "@xyo-network/crypto-nft-payload-plugin";
|
|
125
|
-
import { PayloadSetSchema } from "@xyo-network/payload-model";
|
|
126
|
-
import { createPayloadSetDivinerPlugin } from "@xyo-network/payloadset-plugin";
|
|
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
|
-
);
|
|
136
|
-
export {
|
|
137
|
-
NftCollectionScoreDiviner,
|
|
138
|
-
NftCollectionScoreDivinerPlugin,
|
|
139
|
-
analyzeNftCollection,
|
|
140
|
-
NftCollectionScoreDivinerPlugin as default,
|
|
141
|
-
scoringCriteria
|
|
142
|
-
};
|
|
143
|
-
//# sourceMappingURL=index.js.map
|
package/dist/node/index.js
DELETED
|
@@ -1,143 +0,0 @@
|
|
|
1
|
-
// src/Diviner.ts
|
|
2
|
-
import {
|
|
3
|
-
isNftCollectionInfo,
|
|
4
|
-
NftCollectionScoreDivinerConfigSchema,
|
|
5
|
-
NftCollectionScoreSchema
|
|
6
|
-
} from "@xyo-network/crypto-nft-collection-payload-plugin";
|
|
7
|
-
import { AbstractDiviner } from "@xyo-network/diviner-abstract";
|
|
8
|
-
import { PayloadBuilder } from "@xyo-network/payload-builder";
|
|
9
|
-
|
|
10
|
-
// src/lib/rating/criteria/scoring/metadata/scoreIndividualAttributes.ts
|
|
11
|
-
import { normalize } from "@xyo-network/crypto-nft-score-model";
|
|
12
|
-
var maxScore = 10;
|
|
13
|
-
var scoreIndividualAttributes = (info) => {
|
|
14
|
-
const { attributes } = info.metrics.metadata;
|
|
15
|
-
const entries = Object.entries(attributes);
|
|
16
|
-
if (entries.length === 0) return [0, maxScore];
|
|
17
|
-
const scores = Object.entries(attributes).flatMap(([_trait, { values }]) => {
|
|
18
|
-
return Object.entries(values).map(([_traitValue, metrics]) => {
|
|
19
|
-
const rarity = Math.min(Math.round((1 - metrics.binomial.p) * maxScore), maxScore);
|
|
20
|
-
return [rarity, maxScore];
|
|
21
|
-
});
|
|
22
|
-
});
|
|
23
|
-
const total = scores.reduce(([a, b], [c, d]) => [a + c, b + d], [0, 0]);
|
|
24
|
-
return normalize(total, maxScore);
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
// src/lib/rating/criteria/scoring/metadata/scoreTotalAttributes.ts
|
|
28
|
-
import { normalize as normalize2 } from "@xyo-network/crypto-nft-score-model";
|
|
29
|
-
var maxScore2 = 10;
|
|
30
|
-
var defaultMu = 0.15;
|
|
31
|
-
var defaultSigma = 0.1;
|
|
32
|
-
var gaussianProbabilityDensity = (x, mu = defaultMu, sigma = defaultSigma) => {
|
|
33
|
-
const sqrtTwoPi = Math.sqrt(2 * Math.PI);
|
|
34
|
-
const denominator = sigma * sqrtTwoPi;
|
|
35
|
-
const power = -0.5 * Math.pow((x - mu) / sigma, 2);
|
|
36
|
-
return 1 / denominator * Math.exp(power);
|
|
37
|
-
};
|
|
38
|
-
var maxProbabilityDensity = gaussianProbabilityDensity(defaultMu);
|
|
39
|
-
var scoreTotalAttributes = (info) => {
|
|
40
|
-
const { attributes } = info.metrics.metadata;
|
|
41
|
-
const jointProbability = Object.entries(attributes).reduce((acc, [_trait, { metrics }]) => {
|
|
42
|
-
return acc * metrics.binomial.p;
|
|
43
|
-
}, 1);
|
|
44
|
-
const probabilityDensity = gaussianProbabilityDensity(jointProbability);
|
|
45
|
-
const score = [probabilityDensity, maxProbabilityDensity];
|
|
46
|
-
return normalize2(score, maxScore2);
|
|
47
|
-
};
|
|
48
|
-
|
|
49
|
-
// src/lib/rating/criteria/scoring/metadata/metadata.ts
|
|
50
|
-
var attributeScoringCriteria = {
|
|
51
|
-
"Metadata Attributes Individual": { score: scoreIndividualAttributes, weight: 2 },
|
|
52
|
-
"Metadata Attributes Total": { score: scoreTotalAttributes, weight: 2 }
|
|
53
|
-
};
|
|
54
|
-
var scoreMetadata = {
|
|
55
|
-
...attributeScoringCriteria
|
|
56
|
-
};
|
|
57
|
-
|
|
58
|
-
// src/lib/rating/criteria/scoring/total.ts
|
|
59
|
-
import { normalize as normalize3 } from "@xyo-network/crypto-nft-score-model";
|
|
60
|
-
var median = 810308398217352e-7;
|
|
61
|
-
var defaultMu2 = Math.log(median);
|
|
62
|
-
var defaultSigma2 = 3;
|
|
63
|
-
var mode = Math.exp(defaultMu2 - Math.pow(defaultSigma2, 2));
|
|
64
|
-
var logNormalProbabilityDensity = (x, mu = defaultMu2, sigma = defaultSigma2) => {
|
|
65
|
-
if (x <= 0) return 0;
|
|
66
|
-
const logX = Math.log(x);
|
|
67
|
-
return 1 / (x * sigma * Math.sqrt(2 * Math.PI)) * Math.exp(-0.5 * Math.pow((logX - mu) / sigma, 2));
|
|
68
|
-
};
|
|
69
|
-
var maxProbabilityDensity2 = logNormalProbabilityDensity(mode);
|
|
70
|
-
var maxScore3 = 10;
|
|
71
|
-
var scoreTotal = (nft) => {
|
|
72
|
-
const density = logNormalProbabilityDensity(nft.total);
|
|
73
|
-
const score = [density, maxProbabilityDensity2];
|
|
74
|
-
return normalize3(score, maxScore3);
|
|
75
|
-
};
|
|
76
|
-
|
|
77
|
-
// src/lib/rating/criteria/index.ts
|
|
78
|
-
var scoringCriteria = {
|
|
79
|
-
...scoreMetadata,
|
|
80
|
-
Total: { score: scoreTotal, weight: 2 }
|
|
81
|
-
};
|
|
82
|
-
|
|
83
|
-
// src/lib/rating/analyzeNftCollection.ts
|
|
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
|
-
);
|
|
94
|
-
return result;
|
|
95
|
-
};
|
|
96
|
-
|
|
97
|
-
// src/Diviner.ts
|
|
98
|
-
var toNftCollectionScore = (nftCollectionInfo, scores) => {
|
|
99
|
-
const { name, symbol, address, chainId, type } = nftCollectionInfo;
|
|
100
|
-
const metadata = { address, chainId, name, symbol, type };
|
|
101
|
-
return { ...metadata, schema: NftCollectionScoreSchema, scores };
|
|
102
|
-
};
|
|
103
|
-
var NftCollectionScoreDiviner = class extends AbstractDiviner {
|
|
104
|
-
static configSchemas = [...super.configSchemas, NftCollectionScoreDivinerConfigSchema];
|
|
105
|
-
static defaultConfigSchema = NftCollectionScoreDivinerConfigSchema;
|
|
106
|
-
divineHandler = async (payloads) => {
|
|
107
|
-
const nftCollectionInfos = (payloads == null ? void 0 : payloads.filter(isNftCollectionInfo)) ?? [];
|
|
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
|
-
);
|
|
119
|
-
return results;
|
|
120
|
-
};
|
|
121
|
-
};
|
|
122
|
-
|
|
123
|
-
// src/Plugin.ts
|
|
124
|
-
import { NftSchema } from "@xyo-network/crypto-nft-payload-plugin";
|
|
125
|
-
import { PayloadSetSchema } from "@xyo-network/payload-model";
|
|
126
|
-
import { createPayloadSetDivinerPlugin } from "@xyo-network/payloadset-plugin";
|
|
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
|
-
);
|
|
136
|
-
export {
|
|
137
|
-
NftCollectionScoreDiviner,
|
|
138
|
-
NftCollectionScoreDivinerPlugin,
|
|
139
|
-
analyzeNftCollection,
|
|
140
|
-
NftCollectionScoreDivinerPlugin as default,
|
|
141
|
-
scoringCriteria
|
|
142
|
-
};
|
|
143
|
-
//# sourceMappingURL=index.js.map
|