@@ -24,6 +24,8 @@ export interface RecommenderMetrics {
24
24
riskScore : number ;
25
25
consistencyScore : number ;
26
26
virtualConfidence : number ;
27
+ lastActiveDate : Date ;
28
+ trustDecay : number ;
27
29
lastUpdated : Date ;
28
30
}
29
31
@@ -41,6 +43,7 @@ export interface TokenPerformance {
41
43
sustainedGrowth : boolean ;
42
44
rapidDump : boolean ;
43
45
suspiciousVolume : boolean ;
46
+ validationTrust : number ;
44
47
lastUpdated : Date ;
45
48
}
46
49
@@ -63,6 +66,7 @@ export interface RecommenderMetricsHistory {
63
66
riskScore : number ;
64
67
consistencyScore : number ;
65
68
virtualConfidence : number ;
69
+ trustDecay : number ;
66
70
recordedAt : Date ;
67
71
}
68
72
@@ -100,6 +104,8 @@ interface RecommenderMetricsRow {
100
104
risk_score : number ;
101
105
consistency_score : number ;
102
106
virtual_confidence : number ;
107
+ last_active_date : Date ;
108
+ trust_decay : number ;
103
109
last_updated : string ;
104
110
}
105
111
@@ -117,6 +123,7 @@ interface TokenPerformanceRow {
117
123
sustained_growth : number ;
118
124
rapid_dump : number ;
119
125
suspicious_volume : number ;
126
+ validation_trust : number ;
120
127
last_updated : string ;
121
128
}
122
129
@@ -165,6 +172,8 @@ export class TrustScoreDatabase {
165
172
risk_score REAL DEFAULT 0,
166
173
consistency_score REAL DEFAULT 0,
167
174
virtual_confidence REAL DEFAULT 0,
175
+ last_active_date DATETIME DEFAULT CURRENT_TIMESTAMP
176
+ trust_decay REAL DEFAULT 0,
168
177
last_updated DATETIME DEFAULT CURRENT_TIMESTAMP,
169
178
FOREIGN KEY (recommender_id) REFERENCES recommenders(id) ON DELETE CASCADE
170
179
);
@@ -186,6 +195,7 @@ export class TrustScoreDatabase {
186
195
sustained_growth BOOLEAN DEFAULT FALSE,
187
196
rapid_dump BOOLEAN DEFAULT FALSE,
188
197
suspicious_volume BOOLEAN DEFAULT FALSE,
198
+ validation_trust REAL DEFAULT 0,
189
199
last_updated DATETIME DEFAULT CURRENT_TIMESTAMP
190
200
);
191
201
` ) ;
@@ -378,6 +388,8 @@ export class TrustScoreDatabase {
378
388
riskScore : row . risk_score ,
379
389
consistencyScore : row . consistency_score ,
380
390
virtualConfidence : row . virtual_confidence ,
391
+ lastActiveDate : row . last_active_date ,
392
+ trustDecay : row . trust_decay ,
381
393
lastUpdated : new Date ( row . last_updated ) ,
382
394
} ;
383
395
}
@@ -407,6 +419,7 @@ export class TrustScoreDatabase {
407
419
riskScore : currentMetrics . riskScore ,
408
420
consistencyScore : currentMetrics . consistencyScore ,
409
421
virtualConfidence : currentMetrics . virtualConfidence ,
422
+ trustDecay : currentMetrics . trustDecay ,
410
423
recordedAt : new Date ( ) , // Current timestamp
411
424
} ;
412
425
@@ -492,6 +505,10 @@ export class TrustScoreDatabase {
492
505
* @param performance TokenPerformance object
493
506
*/
494
507
upsertTokenPerformance ( performance : TokenPerformance ) : boolean {
508
+ const validationTrust = this . calculateValidationTrust (
509
+ performance . tokenAddress
510
+ ) ;
511
+
495
512
const sql = `
496
513
INSERT INTO token_performance (
497
514
token_address,
@@ -507,6 +524,7 @@ export class TrustScoreDatabase {
507
524
sustained_growth,
508
525
rapid_dump,
509
526
suspicious_volume,
527
+ validation_trust,
510
528
last_updated
511
529
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, CURRENT_TIMESTAMP)
512
530
ON CONFLICT(token_address) DO UPDATE SET
@@ -522,6 +540,7 @@ export class TrustScoreDatabase {
522
540
sustained_growth = excluded.sustained_growth,
523
541
rapid_dump = excluded.rapid_dump,
524
542
suspicious_volume = excluded.suspicious_volume,
543
+ validation_trust = excluded.validation_trust,
525
544
last_updated = CURRENT_TIMESTAMP;
526
545
` ;
527
546
try {
@@ -536,7 +555,8 @@ export class TrustScoreDatabase {
536
555
performance . marketCapChange24h ,
537
556
performance . sustainedGrowth ? 1 : 0 ,
538
557
performance . rapidDump ? 1 : 0 ,
539
- performance . suspiciousVolume ? 1 : 0
558
+ performance . suspiciousVolume ? 1 : 0 ,
559
+ validationTrust
540
560
) ;
541
561
console . log (
542
562
`Upserted token performance for ${ performance . tokenAddress } `
@@ -574,12 +594,36 @@ export class TrustScoreDatabase {
574
594
sustainedGrowth : row . sustained_growth === 1 ,
575
595
rapidDump : row . rapid_dump === 1 ,
576
596
suspiciousVolume : row . suspicious_volume === 1 ,
597
+ validationTrust : row . validation_trust ,
577
598
lastUpdated : new Date ( row . last_updated ) ,
578
599
} ;
579
600
}
580
601
581
602
// ----- TokenRecommendations Methods -----
582
603
604
+ /**
605
+ * Calculates the average trust score of all recommenders who have recommended a specific token.
606
+ * @param tokenAddress The address of the token.
607
+ * @returns The average trust score (validationTrust).
608
+ */
609
+ calculateValidationTrust ( tokenAddress : string ) : number {
610
+ const sql = `
611
+ SELECT rm.trust_score
612
+ FROM token_recommendations tr
613
+ JOIN recommender_metrics rm ON tr.recommender_id = rm.recommender_id
614
+ WHERE tr.token_address = ?;
615
+ ` ;
616
+ const rows = this . db . prepare ( sql ) . all ( tokenAddress ) as Array < {
617
+ trust_score : number ;
618
+ } > ;
619
+
620
+ if ( rows . length === 0 ) return 0 ; // No recommendations found
621
+
622
+ const totalTrust = rows . reduce ( ( acc , row ) => acc + row . trust_score , 0 ) ;
623
+ const averageTrust = totalTrust / rows . length ;
624
+ return averageTrust ;
625
+ }
626
+
583
627
/**
584
628
* Adds a new token recommendation.
585
629
* @param recommendation TokenRecommendation object
@@ -735,6 +779,7 @@ export class TrustScoreDatabase {
735
779
risk_score : number ;
736
780
consistency_score : number ;
737
781
virtual_confidence : number ;
782
+ trust_decay : number ;
738
783
recorded_at : string ;
739
784
} > ;
740
785
@@ -748,6 +793,7 @@ export class TrustScoreDatabase {
748
793
riskScore : row . risk_score ,
749
794
consistencyScore : row . consistency_score ,
750
795
virtualConfidence : row . virtual_confidence ,
796
+ trustDecay : row . trust_decay ,
751
797
recordedAt : new Date ( row . recorded_at ) ,
752
798
} ) ) ;
753
799
}
0 commit comments