solana-recover 1.1.3

A comprehensive Solana wallet recovery and account management tool
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
//! # NFT Core Types
//!
//! Comprehensive type definitions for NFT operations with maximum
//! performance, security, and customization in mind.

use crate::nft::errors::{NftError, NftResult, RiskLevel};
use serde::{Deserialize, Serialize};
use solana_sdk::pubkey::Pubkey;
use std::collections::HashMap;
use std::fmt;
use uuid::Uuid;

/// Comprehensive NFT information structure
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct NftInfo {
    /// Unique identifier for this NFT record
    pub id: Uuid,
    
    /// Token mint address
    pub mint_address: String,
    
    /// Token account address
    pub token_account: String,
    
    /// Owner wallet address
    pub owner: String,
    
    /// NFT name from metadata
    pub name: Option<String>,
    
    /// NFT symbol from metadata
    pub symbol: Option<String>,
    
    /// NFT description
    pub description: Option<String>,
    
    /// Metadata URI
    pub metadata_uri: Option<String>,
    
    /// Image URI
    pub image_uri: Option<String>,
    
    /// Animation URI (for animated NFTs)
    pub animation_uri: Option<String>,
    
    /// External URL (project website, etc.)
    pub external_url: Option<String>,
    
    /// Collection information
    pub collection: Option<CollectionInfo>,
    
    /// Creator information
    pub creators: Vec<CreatorInfo>,
    
    /// Attributes/properties
    pub attributes: Vec<NftAttribute>,
    
    /// Token standard (e.g., "non-fungible", "semi-fungible")
    pub token_standard: Option<String>,
    
    /// Whether this is a master edition
    pub master_edition: bool,
    
    /// Edition number if this is a print
    pub edition_number: Option<u64>,
    
    /// Maximum supply for editions
    pub max_supply: Option<u64>,
    
    /// Current estimated value in lamports
    pub estimated_value_lamports: Option<u64>,
    
    /// Last valuation timestamp
    pub last_valuation: Option<chrono::DateTime<chrono::Utc>>,
    
    /// Security assessment
    pub security_assessment: SecurityAssessment,
    
    /// Rarity score (0-100, higher is rarer)
    pub rarity_score: Option<f64>,
    
    /// Quality score (0-100, higher is better quality)
    pub quality_score: Option<f64>,
    
    /// Metadata verification status
    pub metadata_verified: bool,
    
    /// Image verification status
    pub image_verified: bool,
    
    /// When this NFT was first discovered
    pub discovered_at: chrono::DateTime<chrono::Utc>,
    
    /// When this record was last updated
    pub updated_at: chrono::DateTime<chrono::Utc>,
    
    /// Additional metadata not covered by other fields
    pub additional_metadata: HashMap<String, serde_json::Value>,
}

/// Collection information
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct CollectionInfo {
    /// Collection name
    pub name: String,
    
    /// Collection symbol
    pub symbol: Option<String>,
    
    /// Collection description
    pub description: Option<String>,
    
    /// Collection image
    pub image: Option<String>,
    
    /// Collection URI
    pub uri: Option<String>,
    
    /// Whether this collection is verified
    pub verified: bool,
    
    /// Collection mint address if it's a verified collection
    pub collection_mint_address: Option<String>,
    
    /// Collection security assessment
    pub security_assessment: SecurityAssessment,
    
    /// Floor price in lamports
    pub floor_price_lamports: Option<u64>,
    
    /// Total supply in collection
    pub total_supply: Option<u64>,
    
    /// Number of items in collection
    pub item_count: Option<u64>,
}

/// Creator information
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct CreatorInfo {
    /// Creator address
    pub address: String,
    
    /// Creator verified status
    pub verified: bool,
    
    /// Creator share percentage (basis points)
    pub share: u8,
    
    /// Creator name if known
    pub name: Option<String>,
    
    /// Creator Twitter handle if known
    pub twitter: Option<String>,
    
    /// Creator website if known
    pub website: Option<String>,
    
    /// Security assessment for this creator
    pub security_assessment: SecurityAssessment,
}

/// NFT attribute/property
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct NftAttribute {
    /// Attribute trait type
    pub trait_type: String,
    
    /// Attribute value
    pub value: serde_json::Value,
    
    /// Rarity of this attribute (optional)
    pub rarity: Option<f64>,
    
    /// Whether this is a rare attribute
    pub rare: bool,
    
    /// Attribute display type
    pub display_type: Option<String>,
}

/// Security assessment for NFTs, collections, and creators
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SecurityAssessment {
    /// Overall risk level
    pub risk_level: RiskLevel,
    
    /// Security score (0-100, higher is more secure)
    pub security_score: u8,
    
    /// List of security issues found
    pub issues: Vec<SecurityIssue>,
    
    /// Whether this entity is verified
    pub verified: bool,
    
    /// When assessment was performed
    pub assessed_at: chrono::DateTime<chrono::Utc>,
    
    /// Assessment confidence (0-100)
    pub confidence: u8,
}

/// Individual security issue
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SecurityIssue {
    /// Issue type
    pub issue_type: SecurityIssueType,
    
    /// Issue severity
    pub severity: RiskLevel,
    
    /// Issue description
    pub description: String,
    
    /// Recommended action
    pub recommendation: String,
    
    /// Whether issue is confirmed or suspected
    pub confirmed: bool,
    
    /// Additional context
    pub context: Option<String>,
}

/// Types of security issues
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum SecurityIssueType {
    /// Suspicious metadata URI
    SuspiciousMetadata,
    
    /// Malicious image detected
    MaliciousImage,
    
    /// Phishing attempt
    Phishing,
    
    /// Rug pull risk
    RugPullRisk,
    
    /// Copymint (duplicate NFT)
    Copymint,
    
    /// Spam NFT
    Spam,
    
    /// Unauthorized creator
    UnauthorizedCreator,
    
    /// Broken metadata
    BrokenMetadata,
    
    /// Expired domain
    ExpiredDomain,
    
    /// Suspicious contract
    SuspiciousContract,
    
    /// Honeypot
    Honeypot,
    
    /// Other security issue
    Other { issue_type: String },
}

/// NFT portfolio analysis result
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct NftPortfolio {
    /// Portfolio ID
    pub id: Uuid,
    
    /// Wallet address
    pub wallet_address: String,
    
    /// All NFTs in portfolio
    pub nfts: Vec<NftInfo>,
    
    /// Total estimated value in lamports
    pub total_value_lamports: u64,
    
    /// Total number of NFTs
    pub total_count: u32,
    
    /// Number of verified NFTs
    pub verified_count: u32,
    
    /// Number of high-risk NFTs
    pub high_risk_count: u32,
    
    /// Collection breakdown
    pub collection_breakdown: HashMap<String, CollectionBreakdown>,
    
    /// Value distribution
    pub value_distribution: ValueDistribution,
    
    /// Risk distribution
    pub risk_distribution: RiskDistribution,
    
    /// Quality metrics
    pub quality_metrics: PortfolioQualityMetrics,
    
    /// When portfolio was analyzed
    pub analyzed_at: chrono::DateTime<chrono::Utc>,
    
    /// Analysis duration in milliseconds
    pub analysis_duration_ms: u64,
    
    /// Analysis configuration used
    pub analysis_config: String,
}

/// Collection breakdown in portfolio
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct CollectionBreakdown {
    /// Collection name
    pub collection_name: String,
    
    /// Number of NFTs from this collection
    pub count: u32,
    
    /// Total value of NFTs from this collection
    pub total_value_lamports: u64,
    
    /// Average value per NFT in this collection
    pub average_value_lamports: u64,
    
    /// Percentage of portfolio value
    pub portfolio_percentage: f64,
    
    /// Collection verification status
    pub verified: bool,
}

/// Value distribution analysis
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ValueDistribution {
    /// Highest value NFT
    pub highest_value: Option<u64>,
    
    /// Lowest value NFT
    pub lowest_value: Option<u64>,
    
    /// Median value
    pub median_value: Option<u64>,
    
    /// Average value
    pub average_value: f64,
    
    /// Value percentiles (25th, 50th, 75th, 90th, 95th, 99th)
    pub percentiles: HashMap<u8, u64>,
    
    /// Value concentration (Gini coefficient)
    pub concentration: f64,
}

/// Risk distribution analysis
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct RiskDistribution {
    /// Count by risk level
    pub counts: HashMap<RiskLevel, u32>,
    
    /// Value by risk level
    pub value_by_risk: HashMap<RiskLevel, u64>,
    
    /// Percentage by risk level
    pub percentages: HashMap<RiskLevel, f64>,
    
    /// Overall portfolio risk score
    pub overall_risk_score: f64,
}

/// Portfolio quality metrics
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct PortfolioQualityMetrics {
    /// Average rarity score
    pub average_rarity_score: Option<f64>,
    
    /// Average quality score
    pub average_quality_score: Option<f64>,
    
    /// Verification rate (0-100)
    pub verification_rate: f64,
    
    /// Metadata completeness (0-100)
    pub metadata_completeness: f64,
    
    /// Image availability (0-100)
    pub image_availability: f64,
    
    /// Unique collections count
    pub unique_collections: u32,
    
    /// Diversity score (0-100, higher is more diverse)
    pub diversity_score: f64,
}

/// NFT scan configuration
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct NftScanConfig {
    /// Performance mode
    pub performance_mode: PerformanceMode,
    
    /// Maximum concurrent requests
    pub max_concurrent_requests: usize,
    
    /// Request timeout in milliseconds
    pub request_timeout_ms: u64,
    
    /// Whether to fetch metadata
    pub fetch_metadata: bool,
    
    /// Whether to fetch images
    pub fetch_images: bool,
    
    /// Whether to perform security validation
    pub perform_security_validation: bool,
    
    /// Whether to calculate valuation
    pub calculate_valuation: bool,
    
    /// Whether to analyze rarity
    pub analyze_rarity: bool,
    
    /// Maximum NFTs to process per wallet
    pub max_nfts_per_wallet: Option<u32>,
    
    /// Cache configuration
    pub cache_config: CacheConfig,
    
    /// Security configuration
    pub security_config: SecurityConfig,
    
    /// Valuation configuration
    pub valuation_config: ValuationConfig,
}

/// Performance modes for NFT operations
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum PerformanceMode {
    /// Ultra-fast mode - maximum speed, minimal validation
    UltraFast,
    /// Fast mode - good speed with basic validation
    Fast,
    /// Balanced mode - balanced speed and accuracy
    Balanced,
    /// Thorough mode - maximum accuracy, slower speed
    Thorough,
    /// Custom mode with specific settings
    Custom { settings: HashMap<String, serde_json::Value> },
}

/// Cache configuration
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct CacheConfig {
    /// Enable metadata caching
    pub enable_metadata_cache: bool,
    
    /// Enable image caching
    pub enable_image_cache: bool,
    
    /// Enable valuation cache
    pub enable_valuation_cache: bool,
    
    /// Cache TTL in seconds
    pub cache_ttl_seconds: u64,
    
    /// Maximum cache size in MB
    pub max_cache_size_mb: u64,
    
    /// Cache cleanup interval in seconds
    pub cleanup_interval_seconds: u64,
}

/// Security configuration
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SecurityConfig {
    /// Enable security validation
    pub enable_validation: bool,
    
    /// Block high-risk NFTs
    pub block_high_risk: bool,
    
    /// Block unverified collections
    pub block_unverified_collections: bool,
    
    /// Strict validation mode
    pub strict_mode: bool,
    
    /// Custom security rules
    pub custom_rules: Vec<SecurityRule>,
}

/// Custom security rule
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SecurityRule {
    /// Rule name
    pub name: String,
    
    /// Rule description
    pub description: String,
    
    /// Rule condition (JSON expression)
    pub condition: serde_json::Value,
    
    /// Action to take when rule matches
    pub action: SecurityAction,
    
    /// Rule priority
    pub priority: u8,
}

/// Security actions
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum SecurityAction {
    /// Allow the NFT
    Allow,
    /// Block the NFT
    Block,
    /// Flag the NFT with warning
    Flag,
    /// Require additional validation
    RequireValidation,
}

/// Valuation configuration
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ValuationConfig {
    /// Enable valuation
    pub enable_valuation: bool,
    
    /// Valuation methods to use
    pub methods: Vec<ValuationMethod>,
    
    /// Floor price weight in valuation
    pub floor_price_weight: f64,
    
    /// Recent sales weight in valuation
    pub recent_sales_weight: f64,
    
    /// Rarity weight in valuation
    pub rarity_weight: f64,
    
    /// Maximum age of sales data in days
    pub max_sales_age_days: u32,
    
    /// Minimum sales for reliable valuation
    pub min_sales_count: u32,
}

/// Valuation methods
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Hash)]
pub enum ValuationMethod {
    /// Floor price based valuation
    FloorPrice,
    /// Recent sales average
    RecentSales,
    /// Rarity-based valuation
    RarityBased,
    /// Machine learning model
    MlModel,
    /// Custom valuation method
    Custom { method_name: String, config: serde_json::Value },
}

impl Default for NftScanConfig {
    fn default() -> Self {
        Self {
            performance_mode: PerformanceMode::Balanced,
            max_concurrent_requests: 10,
            request_timeout_ms: 30000,
            fetch_metadata: true,
            fetch_images: false,
            perform_security_validation: true,
            calculate_valuation: true,
            analyze_rarity: true,
            max_nfts_per_wallet: None,
            cache_config: CacheConfig::default(),
            security_config: SecurityConfig::default(),
            valuation_config: ValuationConfig::default(),
        }
    }
}

impl Default for CacheConfig {
    fn default() -> Self {
        Self {
            enable_metadata_cache: true,
            enable_image_cache: false,
            enable_valuation_cache: true,
            cache_ttl_seconds: 300, // 5 minutes
            max_cache_size_mb: 100,
            cleanup_interval_seconds: 60,
        }
    }
}

impl Default for SecurityConfig {
    fn default() -> Self {
        Self {
            enable_validation: true,
            block_high_risk: false,
            block_unverified_collections: false,
            strict_mode: false,
            custom_rules: vec![],
        }
    }
}

impl Default for ValuationConfig {
    fn default() -> Self {
        Self {
            enable_valuation: true,
            methods: vec![
                ValuationMethod::FloorPrice,
                ValuationMethod::RecentSales,
            ],
            floor_price_weight: 0.4,
            recent_sales_weight: 0.4,
            rarity_weight: 0.2,
            max_sales_age_days: 30,
            min_sales_count: 3,
        }
    }
}

impl fmt::Display for PerformanceMode {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        match self {
            PerformanceMode::UltraFast => write!(f, "UltraFast"),
            PerformanceMode::Fast => write!(f, "Fast"),
            PerformanceMode::Balanced => write!(f, "Balanced"),
            PerformanceMode::Thorough => write!(f, "Thorough"),
            PerformanceMode::Custom { settings } => write!(f, "Custom({:?})", settings),
        }
    }
}

impl fmt::Display for SecurityIssueType {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        match self {
            SecurityIssueType::SuspiciousMetadata => write!(f, "SuspiciousMetadata"),
            SecurityIssueType::MaliciousImage => write!(f, "MaliciousImage"),
            SecurityIssueType::Phishing => write!(f, "Phishing"),
            SecurityIssueType::RugPullRisk => write!(f, "RugPullRisk"),
            SecurityIssueType::Copymint => write!(f, "Copymint"),
            SecurityIssueType::Spam => write!(f, "Spam"),
            SecurityIssueType::UnauthorizedCreator => write!(f, "UnauthorizedCreator"),
            SecurityIssueType::BrokenMetadata => write!(f, "BrokenMetadata"),
            SecurityIssueType::ExpiredDomain => write!(f, "ExpiredDomain"),
            SecurityIssueType::SuspiciousContract => write!(f, "SuspiciousContract"),
            SecurityIssueType::Honeypot => write!(f, "Honeypot"),
            SecurityIssueType::Other { issue_type } => write!(f, "Other({})", issue_type),
        }
    }
}

impl fmt::Display for SecurityAction {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        match self {
            SecurityAction::Allow => write!(f, "Allow"),
            SecurityAction::Block => write!(f, "Block"),
            SecurityAction::Flag => write!(f, "Flag"),
            SecurityAction::RequireValidation => write!(f, "RequireValidation"),
        }
    }
}

impl fmt::Display for ValuationMethod {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        match self {
            ValuationMethod::FloorPrice => write!(f, "FloorPrice"),
            ValuationMethod::RecentSales => write!(f, "RecentSales"),
            ValuationMethod::RarityBased => write!(f, "RarityBased"),
            ValuationMethod::MlModel => write!(f, "MlModel"),
            ValuationMethod::Custom { method_name, .. } => write!(f, "Custom({})", method_name),
        }
    }
}