A plugin for managing trust scores and performance metrics in a secure database, providing recommender tracking and token performance analysis capabilities.
This plugin provides functionality to:
- Track and manage recommender trust scores
- Monitor token performance metrics
- Record and analyze trading performance
- Maintain historical metrics data
- Handle transaction records and validations
npm install @elizaos/plugin-trustdb
The plugin uses SQLite as its database backend and requires proper initialization:
import { TrustScoreDatabase } from "@elizaos/plugin-trustdb";
import Database from "better-sqlite3";
const db = new Database("path/to/database.sqlite");
const trustDB = new TrustScoreDatabase(db);
Import and use the TrustDB functionality in your application:
import { TrustScoreDatabase } from "@elizaos/plugin-trustdb";
// Initialize database
const trustDB = new TrustScoreDatabase(db);
// Add a recommender
const recommender = {
id: "uuid",
address: "wallet-address",
telegramId: "telegram-id",
};
trustDB.addRecommender(recommender);
// Track token performance
const performance = {
tokenAddress: "token-address",
priceChange24h: 10.5,
volumeChange24h: 25.3,
// ... other metrics
};
trustDB.upsertTokenPerformance(performance);
The main database manager providing comprehensive tracking and analysis:
// Get or create a recommender
const recommender = await trustDB.getOrCreateRecommender({
address: "wallet-address",
telegramId: "user-id",
});
// Update recommender metrics
trustDB.updateRecommenderMetrics({
recommenderId: "uuid",
trustScore: 85.5,
totalRecommendations: 10,
// ... other metrics
});
// Add trade performance
trustDB.addTradePerformance(
{
token_address: "address",
recommender_id: "uuid",
buy_price: 1.0,
// ... other trade details
},
false
);
// Get token performance
const tokenMetrics = trustDB.getTokenPerformance("token-address");
npm run build
npm run test
npm run lint
better-sqlite3
: SQLite database interfaceuuid
: Unique identifier generationdompurify
: HTML sanitization- Other standard dependencies listed in package.json
interface Recommender {
id: string;
address: string;
solanaPubkey?: string;
telegramId?: string;
discordId?: string;
twitterId?: string;
ip?: string;
}
interface RecommenderMetrics {
recommenderId: string;
trustScore: number;
totalRecommendations: number;
successfulRecs: number;
avgTokenPerformance: number;
riskScore: number;
consistencyScore: number;
virtualConfidence: number;
lastActiveDate: Date;
trustDecay: number;
lastUpdated: Date;
}
interface TokenPerformance {
tokenAddress: string;
symbol: string;
priceChange24h: number;
volumeChange24h: number;
// ... other performance metrics
}
addRecommender
: Add new recommender to databasegetRecommenderMetrics
: Retrieve recommender performance metricsupdateRecommenderMetrics
: Update recommender metricsupsertTokenPerformance
: Add or update token performancegetTokenPerformance
: Retrieve token performance metrics- Many more specialized methods for tracking and analysis
- Cause: Incorrect database path or permissions
- Solution: Verify database path and file permissions
- Cause: Concurrent database access
- Solution: Use proper transaction handling
- Implement proper database backup procedures
- Use parameterized queries to prevent SQL injection
- Validate all input data before storage
- Maintain regular database maintenance
- Keep dependencies updated for security patches
Contributions are welcome! Please see the CONTRIBUTING.md file for more information.
This plugin integrates with and builds upon several key technologies:
- better-sqlite3: High-performance SQLite3 driver
- uuid: UUID generation
- DOMPurify: HTML sanitization library
Special thanks to:
- The better-sqlite3 team for their excellent database driver
- The UUID.js maintainers for reliable identifier generation
- The DOMPurify team for security-focused sanitization tools
- The Eliza community for their contributions and feedback
For more information about database management and security:
This plugin is part of the Eliza project. See the main project repository for license information.