riglr-web-tools 0.3.0

Web-based data tools for riglr agents - Twitter, DexScreener, web search, and more
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
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
//! TrenchBot integration for Solana token bundle analysis and risk assessment
//!
//! This module provides tools for accessing TrenchBot API to analyze token bundles,
//! detect potential rug pulls, identify sniper wallets, and assess creator risk.

use crate::{client::WebClient, error::WebToolError};
use riglr_macros::tool;
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
use tracing::{debug, info};

/// Configuration for TrenchBot API access
#[derive(Debug, Clone)]
pub struct TrenchBotConfig {
    /// API base URL (default: https://trench.bot/api)
    pub base_url: String,
    /// Rate limit requests per minute (default: 60)
    pub rate_limit_per_minute: u32,
    /// Timeout for API requests in seconds (default: 30)
    pub request_timeout: u64,
}

impl Default for TrenchBotConfig {
    fn default() -> Self {
        Self {
            base_url: "https://trench.bot/api".to_string(),
            rate_limit_per_minute: 60,
            request_timeout: 30,
        }
    }
}

/// Main bundle response from TrenchBot
#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
pub struct BundleResponse {
    /// Indicates if the bundle is bonded
    pub bonded: Option<bool>,
    /// Collection of bundles, keyed by bundle ID
    pub bundles: Option<HashMap<String, BundleDetails>>,
    /// Analysis of the bundle creator
    pub creator_analysis: Option<CreatorAnalysis>,
    /// Total amount of tokens distributed
    pub distributed_amount: Option<i64>,
    /// Percentage of total tokens distributed
    pub distributed_percentage: Option<f64>,
    /// Number of wallets the token has been distributed to
    pub distributed_wallets: Option<i32>,
    /// Ticker symbol of the token
    pub ticker: Option<String>,
    /// Total number of bundles created for this token
    pub total_bundles: Option<i32>,
    /// Total amount of tokens held in bundles
    pub total_holding_amount: Option<i64>,
    /// Percentage of the total token supply held in bundles
    pub total_holding_percentage: Option<f64>,
    /// Total percentage of tokens that are bundled
    pub total_percentage_bundled: Option<f64>,
    /// Total SOL spent on creating the bundles
    pub total_sol_spent: Option<f64>,
    /// Total number of tokens included in bundles
    pub total_tokens_bundled: Option<i64>,
}

/// Details about a specific bundle
#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
pub struct BundleDetails {
    /// Analysis of the bundle
    pub bundle_analysis: Option<BundleAnalysis>,
    /// Amount of tokens held within the bundle
    pub holding_amount: Option<i64>,
    /// Percentage of total tokens held within the bundle
    pub holding_percentage: Option<f64>,
    /// Percentage of the total token supply within the bundle
    pub token_percentage: Option<f64>,
    /// Total SOL value of the bundle
    pub total_sol: Option<f64>,
    /// Total number of tokens within the bundle
    pub total_tokens: Option<i64>,
    /// Number of unique wallets interacting with the bundle
    pub unique_wallets: Option<i32>,
    /// Categories of wallets (e.g., "sniper", "regular"), keyed by wallet address
    pub wallet_categories: Option<HashMap<String, String>>,
    /// Information about individual wallets, keyed by wallet address
    pub wallet_info: Option<HashMap<String, WalletInfo>>,
}

/// Analysis results for a bundle
#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
pub struct BundleAnalysis {
    /// Breakdown of wallet categories within the bundle
    pub category_breakdown: Option<HashMap<String, i32>>,
    /// Indicates if the interaction is likely part of a bundle
    pub is_likely_bundle: Option<bool>,
    /// Primary category of the bundle (e.g., "regular", "sniper")
    pub primary_category: Option<String>,
}

/// Information about a specific wallet's interaction with a bundle
#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
pub struct WalletInfo {
    /// SOL balance of the wallet associated with this bundle
    pub sol: Option<f64>,
    /// Percentage of total SOL in the bundle represented by this wallet
    pub sol_percentage: Option<f64>,
    /// Percentage of total tokens in the bundle held by this wallet
    pub token_percentage: Option<f64>,
    /// Number of tokens held by this wallet within the bundle
    pub tokens: Option<i64>,
}

/// Analysis of the token creator
#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
pub struct CreatorAnalysis {
    /// Wallet address of the token creator
    pub address: Option<String>,
    /// Creator's current holdings of the token
    pub current_holdings: Option<i64>,
    /// Historical data on the creator's activity
    pub history: Option<CreatorHistory>,
    /// Percentage of the token supply currently held by the creator
    pub holding_percentage: Option<f64>,
    /// Assessed risk level of the creator
    pub risk_level: Option<RiskLevel>,
    /// Warning flags associated with this creator
    pub warning_flags: Option<Vec<String>>,
}

/// Historical data on the creator's activity
#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
pub struct CreatorHistory {
    /// Average market cap of tokens created by this creator
    pub average_market_cap: Option<i64>,
    /// Indicates if the creator is considered high risk
    pub high_risk: Option<bool>,
    /// List of previously created coins
    pub previous_coins: Option<Vec<PreviousCoin>>,
    /// Number of recent rug pulls by the creator
    pub recent_rugs: Option<i64>,
    /// Total number of rug pulls by the creator
    pub rug_count: Option<i64>,
    /// Percentage of the creator's tokens that were rug pulls
    pub rug_percentage: Option<f64>,
    /// Total number of coins created by this creator
    pub total_coins_created: Option<i64>,
}

/// Information about a previously created coin
#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
pub struct PreviousCoin {
    /// Timestamp of when the coin was created
    pub created_at: Option<i64>,
    /// Indicates if the coin was a rug pull
    pub is_rug: Option<bool>,
    /// Market cap of the coin
    pub market_cap: Option<i64>,
    /// Mint address of the coin
    pub mint: Option<String>,
    /// Symbol of the coin
    pub symbol: Option<String>,
}

/// Risk level enumeration
#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
pub enum RiskLevel {
    /// Low risk - Creator has good track record
    #[serde(rename = "LOW")]
    Low,
    /// Medium risk - Some concerning patterns
    #[serde(rename = "MEDIUM")]
    Medium,
    /// High risk - Multiple red flags detected
    #[serde(rename = "HIGH")]
    High,
}

/// Simplified bundle analysis result
#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
pub struct BundleAnalysisResult {
    /// Token address/mint
    pub token: String,
    /// Token ticker symbol
    pub ticker: Option<String>,
    /// Whether the token is likely bundled
    pub is_bundled: bool,
    /// Total percentage of supply bundled
    pub bundle_percentage: f64,
    /// Number of bundles detected
    pub bundle_count: i32,
    /// Total SOL spent on bundles
    pub total_sol_spent: f64,
    /// Number of wallets holding the token
    pub holder_count: i32,
    /// Creator risk assessment
    pub creator_risk: CreatorRiskAssessment,
    /// Wallet category breakdown
    pub wallet_categories: WalletCategoryBreakdown,
    /// Key warning flags
    pub warnings: Vec<String>,
    /// Summary recommendation
    pub recommendation: String,
}

/// Creator risk assessment
#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
pub struct CreatorRiskAssessment {
    /// Creator wallet address
    pub address: Option<String>,
    /// Risk level
    pub risk_level: Option<RiskLevel>,
    /// Percentage of tokens that were rugs
    pub rug_percentage: f64,
    /// Total coins created
    pub total_coins: i64,
    /// Number of rug pulls
    pub rug_count: i64,
    /// Creator's current holding percentage
    pub holding_percentage: f64,
}

/// Wallet category breakdown
#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
pub struct WalletCategoryBreakdown {
    /// Number of sniper wallets
    pub snipers: i32,
    /// Number of regular wallets
    pub regular: i32,
    /// Percentage of tokens held by snipers
    pub sniper_percentage: f64,
    /// Most common wallet category
    pub primary_category: String,
}

/// Get comprehensive bundle information for a Solana token from TrenchBot.
/// This tool analyzes token distribution patterns to detect bundling and assess risk.
#[tool]
pub async fn get_bundle_info(
    _context: &riglr_core::provider::ApplicationContext,
    token: String,
) -> crate::error::Result<BundleResponse> {
    debug!("Fetching bundle info for token: {}", token);

    let config = TrenchBotConfig::default();
    let client = WebClient::default();

    let url = format!("{}/bundle/bundle_advanced/{}", config.base_url, token);

    info!("Requesting bundle info from: {}", url);

    let response_text = client
        .get(&url)
        .await
        .map_err(|e| WebToolError::Network(format!("Failed to fetch bundle info: {}", e)))?;

    let bundle_response: BundleResponse = serde_json::from_str(&response_text)
        .map_err(|e| WebToolError::Parsing(format!("Failed to parse TrenchBot response: {}", e)))?;

    info!(
        "Successfully fetched bundle info for {} - Bundles: {:?}, Bundled: {:?}%",
        token, bundle_response.total_bundles, bundle_response.total_percentage_bundled
    );

    Ok(bundle_response)
}

/// Extract wallet category statistics from bundle data
fn calculate_wallet_categories(
    bundles: &HashMap<String, BundleDetails>,
) -> (i32, i32, f64, String) {
    let mut sniper_count = 0;
    let mut regular_count = 0;
    let mut sniper_tokens = 0i64;
    let mut total_tokens = 0i64;

    for bundle in bundles.values() {
        if let Some(categories) = &bundle.wallet_categories {
            for category in categories.values() {
                match category.as_str() {
                    "sniper" => sniper_count += 1,
                    "regular" => regular_count += 1,
                    _ => {}
                }
            }
        }

        if let Some(wallet_info) = &bundle.wallet_info {
            for (addr, info) in wallet_info {
                if let Some(tokens) = info.tokens {
                    total_tokens += tokens;
                    if let Some(categories) = &bundle.wallet_categories {
                        if categories.get(addr).map_or(false, |c| c == "sniper") {
                            sniper_tokens += tokens;
                        }
                    }
                }
            }
        }
    }

    let sniper_percentage = if total_tokens > 0 {
        (sniper_tokens as f64 / total_tokens as f64) * 100.0
    } else {
        0.0
    };

    let primary_category = if sniper_count > regular_count {
        "sniper".to_string()
    } else {
        "regular".to_string()
    };

    (
        sniper_count,
        regular_count,
        sniper_percentage,
        primary_category,
    )
}

/// Build creator risk assessment from creator analysis data
fn build_creator_risk_assessment(
    creator_analysis: Option<&CreatorAnalysis>,
) -> CreatorRiskAssessment {
    if let Some(creator) = creator_analysis {
        CreatorRiskAssessment {
            address: creator.address.clone(),
            risk_level: creator.risk_level.clone(),
            rug_percentage: creator
                .history
                .as_ref()
                .and_then(|h| h.rug_percentage)
                .unwrap_or(0.0),
            total_coins: creator
                .history
                .as_ref()
                .and_then(|h| h.total_coins_created)
                .unwrap_or(0),
            rug_count: creator
                .history
                .as_ref()
                .and_then(|h| h.rug_count)
                .unwrap_or(0),
            holding_percentage: creator.holding_percentage.unwrap_or(0.0),
        }
    } else {
        CreatorRiskAssessment {
            address: None,
            risk_level: None,
            rug_percentage: 0.0,
            total_coins: 0,
            rug_count: 0,
            holding_percentage: 0.0,
        }
    }
}

/// Collect warning flags based on bundle data and analysis
fn collect_warnings(bundle_data: &BundleResponse, sniper_percentage: f64) -> Vec<String> {
    let mut warnings = Vec::new();

    if bundle_data.total_percentage_bundled.unwrap_or(0.0) > 50.0 {
        warnings.push("High bundle concentration (>50% bundled)".to_string());
    }

    if sniper_percentage > 30.0 {
        warnings.push("High sniper wallet presence".to_string());
    }

    if let Some(creator) = &bundle_data.creator_analysis {
        if let Some(flags) = &creator.warning_flags {
            warnings.extend(flags.clone());
        }

        if matches!(creator.risk_level, Some(RiskLevel::High)) {
            warnings.push("Creator has high risk profile".to_string());
        }

        if creator.holding_percentage.unwrap_or(0.0) > 20.0 {
            warnings.push("Creator holds >20% of supply".to_string());
        }
    }

    warnings
}

/// Generate recommendation based on bundle percentage
fn generate_recommendation(bundle_percentage: f64) -> String {
    if bundle_percentage > 70.0 {
        "EXTREME CAUTION: Very high bundle concentration detected. High risk of coordinated dump."
    } else if bundle_percentage > 50.0 {
        "HIGH RISK: Significant bundling detected. Potential for price manipulation."
    } else if bundle_percentage > 30.0 {
        "MODERATE RISK: Notable bundling present. Monitor closely for unusual activity."
    } else if bundle_percentage > 10.0 {
        "LOW-MODERATE RISK: Some bundling detected but within acceptable range."
    } else {
        "LOW RISK: Minimal bundling detected. Distribution appears organic."
    }
    .to_string()
}

/// Analyze a Solana token for bundling patterns and provide risk assessment.
/// This tool provides a simplified analysis based on TrenchBot data.
#[tool]
pub async fn analyze_token_bundles(
    context: &riglr_core::provider::ApplicationContext,
    token: String,
) -> crate::error::Result<BundleAnalysisResult> {
    debug!("Analyzing token bundles for: {}", token);

    let bundle_data = get_bundle_info(context, token.clone()).await?;

    let (sniper_count, regular_count, sniper_percentage, primary_category) =
        if let Some(bundles) = &bundle_data.bundles {
            calculate_wallet_categories(bundles)
        } else {
            (0, 0, 0.0, "regular".to_string())
        };

    let creator_risk = build_creator_risk_assessment(bundle_data.creator_analysis.as_ref());
    let warnings = collect_warnings(&bundle_data, sniper_percentage);
    let bundle_percentage = bundle_data.total_percentage_bundled.unwrap_or(0.0);
    let recommendation = generate_recommendation(bundle_percentage);

    Ok(BundleAnalysisResult {
        token,
        ticker: bundle_data.ticker,
        is_bundled: bundle_data.total_bundles.unwrap_or(0) > 0,
        bundle_percentage,
        bundle_count: bundle_data.total_bundles.unwrap_or(0),
        total_sol_spent: bundle_data.total_sol_spent.unwrap_or(0.0),
        holder_count: bundle_data.distributed_wallets.unwrap_or(0),
        creator_risk,
        wallet_categories: WalletCategoryBreakdown {
            snipers: sniper_count,
            regular: regular_count,
            sniper_percentage,
            primary_category,
        },
        warnings,
        recommendation,
    })
}

/// Check if a Solana token shows signs of bundling manipulation.
/// Returns a simple assessment of bundling risk.
#[tool]
pub async fn check_bundle_risk(
    context: &riglr_core::provider::ApplicationContext,
    token: String,
) -> crate::error::Result<BundleRiskCheck> {
    debug!("Checking bundle risk for token: {}", token);

    let bundle_data = get_bundle_info(context, token.clone()).await?;

    let bundle_percentage = bundle_data.total_percentage_bundled.unwrap_or(0.0);
    let bundle_count = bundle_data.total_bundles.unwrap_or(0);

    let risk_level = if bundle_percentage > 70.0 {
        "EXTREME"
    } else if bundle_percentage > 50.0 {
        "HIGH"
    } else if bundle_percentage > 30.0 {
        "MODERATE"
    } else if bundle_percentage > 10.0 {
        "LOW-MODERATE"
    } else {
        "LOW"
    };

    let is_high_risk = bundle_percentage > 50.0;

    let message = format!(
        "{} risk: {:.1}% of supply is bundled across {} bundles",
        risk_level, bundle_percentage, bundle_count
    );

    Ok(BundleRiskCheck {
        token,
        is_bundled: bundle_count > 0,
        bundle_percentage,
        bundle_count,
        risk_level: risk_level.to_string(),
        is_high_risk,
        message,
    })
}

/// Simple bundle risk check result
#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
pub struct BundleRiskCheck {
    /// Token address
    pub token: String,
    /// Whether bundling is detected
    pub is_bundled: bool,
    /// Percentage of supply bundled
    pub bundle_percentage: f64,
    /// Number of bundles
    pub bundle_count: i32,
    /// Risk level assessment
    pub risk_level: String,
    /// Whether this represents high risk
    pub is_high_risk: bool,
    /// Summary message
    pub message: String,
}

/// Analyze the creator of a Solana token for historical rug pull activity.
/// Provides detailed creator risk assessment based on their track record.
#[tool]
pub async fn analyze_creator_risk(
    context: &riglr_core::provider::ApplicationContext,
    token: String,
) -> crate::error::Result<CreatorAnalysisResult> {
    debug!("Analyzing creator risk for token: {}", token);

    let bundle_data = get_bundle_info(context, token.clone()).await?;

    if let Some(creator) = bundle_data.creator_analysis {
        let mut red_flags = Vec::new();

        // Check for red flags
        if let Some(history) = &creator.history {
            if history.rug_count.unwrap_or(0) > 0 {
                red_flags.push(format!(
                    "Creator has {} previous rug pulls",
                    history.rug_count.unwrap_or(0)
                ));
            }

            if history.rug_percentage.unwrap_or(0.0) > 20.0 {
                red_flags.push(format!(
                    "{:.1}% of creator's tokens were rugs",
                    history.rug_percentage.unwrap_or(0.0)
                ));
            }

            if history.high_risk.unwrap_or(false) {
                red_flags.push("Creator flagged as high risk".to_string());
            }

            if history.recent_rugs.unwrap_or(0) > 0 {
                red_flags.push(format!(
                    "{} recent rug pulls detected",
                    history.recent_rugs.unwrap_or(0)
                ));
            }
        }

        if creator.holding_percentage.unwrap_or(0.0) > 30.0 {
            red_flags.push(format!(
                "Creator holds {:.1}% of supply",
                creator.holding_percentage.unwrap_or(0.0)
            ));
        }

        let risk_assessment = match &creator.risk_level {
            Some(RiskLevel::High) => "HIGH RISK: Creator has concerning history",
            Some(RiskLevel::Medium) => "MODERATE RISK: Some red flags in creator history",
            Some(RiskLevel::Low) => "LOW RISK: Creator appears legitimate",
            None => "UNKNOWN: Unable to assess creator risk",
        }
        .to_string();

        Ok(CreatorAnalysisResult {
            token,
            creator_address: creator.address,
            risk_level: creator.risk_level,
            current_holdings: creator.current_holdings,
            holding_percentage: creator.holding_percentage.unwrap_or(0.0),
            total_coins_created: creator
                .history
                .as_ref()
                .and_then(|h| h.total_coins_created)
                .unwrap_or(0),
            rug_count: creator
                .history
                .as_ref()
                .and_then(|h| h.rug_count)
                .unwrap_or(0),
            rug_percentage: creator
                .history
                .as_ref()
                .and_then(|h| h.rug_percentage)
                .unwrap_or(0.0),
            average_market_cap: creator.history.as_ref().and_then(|h| h.average_market_cap),
            previous_coins: creator
                .history
                .and_then(|h| h.previous_coins)
                .unwrap_or_default(),
            red_flags,
            risk_assessment,
        })
    } else {
        Ok(CreatorAnalysisResult {
            token,
            creator_address: None,
            risk_level: None,
            current_holdings: None,
            holding_percentage: 0.0,
            total_coins_created: 0,
            rug_count: 0,
            rug_percentage: 0.0,
            average_market_cap: None,
            previous_coins: Vec::new(),
            red_flags: vec!["No creator analysis available".to_string()],
            risk_assessment: "UNKNOWN: Creator information not available".to_string(),
        })
    }
}

/// Creator analysis result
#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
pub struct CreatorAnalysisResult {
    /// Token being analyzed
    pub token: String,
    /// Creator wallet address
    pub creator_address: Option<String>,
    /// Risk level
    pub risk_level: Option<RiskLevel>,
    /// Creator's current token holdings
    pub current_holdings: Option<i64>,
    /// Percentage of supply held by creator
    pub holding_percentage: f64,
    /// Total number of coins created
    pub total_coins_created: i64,
    /// Number of rug pulls
    pub rug_count: i64,
    /// Percentage of tokens that were rugs
    pub rug_percentage: f64,
    /// Average market cap of created tokens
    pub average_market_cap: Option<i64>,
    /// List of previous coins
    pub previous_coins: Vec<PreviousCoin>,
    /// Red flags identified
    pub red_flags: Vec<String>,
    /// Risk assessment summary
    pub risk_assessment: String,
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test_trenchbot_config_default() {
        let config = TrenchBotConfig::default();
        assert_eq!(config.base_url, "https://trench.bot/api");
        assert_eq!(config.rate_limit_per_minute, 60);
        assert_eq!(config.request_timeout, 30);
    }

    #[test]
    fn test_risk_level_serialization() {
        let risk = RiskLevel::High;
        let json = serde_json::to_string(&risk).unwrap();
        assert_eq!(json, "\"HIGH\"");

        let risk: RiskLevel = serde_json::from_str("\"MEDIUM\"").unwrap();
        assert!(matches!(risk, RiskLevel::Medium));
    }

    #[test]
    fn test_bundle_response_deserialization() {
        let json = r#"{
            "bonded": true,
            "ticker": "TEST",
            "total_bundles": 5,
            "total_percentage_bundled": 25.5
        }"#;

        let response: BundleResponse = serde_json::from_str(json).unwrap();
        assert_eq!(response.bonded, Some(true));
        assert_eq!(response.ticker, Some("TEST".to_string()));
        assert_eq!(response.total_bundles, Some(5));
        assert_eq!(response.total_percentage_bundled, Some(25.5));
    }

    #[test]
    fn test_creator_analysis_deserialization() {
        let json = r#"{
            "address": "SomeWalletAddress",
            "risk_level": "HIGH",
            "holding_percentage": 15.5,
            "history": {
                "rug_count": 3,
                "total_coins_created": 10,
                "rug_percentage": 30.0
            }
        }"#;

        let creator: CreatorAnalysis = serde_json::from_str(json).unwrap();
        assert_eq!(creator.address, Some("SomeWalletAddress".to_string()));
        assert!(matches!(creator.risk_level, Some(RiskLevel::High)));
        assert_eq!(creator.holding_percentage, Some(15.5));
        assert!(creator.history.is_some());

        let history = creator.history.unwrap();
        assert_eq!(history.rug_count, Some(3));
        assert_eq!(history.total_coins_created, Some(10));
        assert_eq!(history.rug_percentage, Some(30.0));
    }
}