agentswap 0.1.0

AgentSwap CLI — AI-agent-optimized DEX aggregator
// Shared AgentSwap API route constants used by the standalone CLI.
// Exports: endpoint constants and path-formatting helpers.
// Deps: std formatting only.
#![allow(dead_code)]

pub const QUOTE: &str = "/quote";
pub const QUOTE_LOOKUP: &str = "/quote/:hash";
pub const COMPARE_SIMULATE: &str = "/compare/simulate";
pub const HEALTH: &str = "/health";
pub const LEARN: &str = "/learn";
pub const CHAINS: &str = "/api/chains";
pub const TOKENS: &str = "/api/tokens";
pub const STATUS: &str = "/api/status";
pub const STATS_PAIRS: &str = "/stats/pairs";
pub const STATS_WARMING: &str = "/stats/warming";
pub const STATS_RPC: &str = "/stats/rpc";
pub const BENCHMARK_LATEST: &str = "/benchmark/latest";
pub const DISCOVER_SLOT: &str = "/discover-slot";
pub const LOG_LEVEL: &str = "/admin/log-level";
pub const ADMIN_KEYS: &str = "/admin/keys";
pub const ADMIN_KEYS_ISSUE: &str = "/admin/keys/issue";

// Auth routes
pub const AUTH_CHALLENGE: &str = "/auth/challenge";
pub const AUTH_REGISTER: &str = "/auth/register";
pub const AUTH_KEY_INFO: &str = "/auth/key-info";
pub const AUTH_PRICING: &str = "/auth/pricing";
pub const AUTH_QUOTA_CLAIM: &str = "/auth/quota/claim";

// x402 payment protocol routes
pub const X402_VERIFY: &str = "/x402/verify";
pub const X402_SETTLE: &str = "/x402/settle";
pub const X402_DISCOVERY: &str = "/.well-known/x402";

/// Format admin key action path: /admin/keys/{key}/{action}
pub fn admin_key_action(key: &str, action: &str) -> String {
    format!("/admin/keys/{key}/{action}")
}

/// Format pool debug path: /api/pool/{chain_id}/{address}
pub fn pool(chain_id: u64, address: &str) -> String {
    format!("/api/pool/{chain_id}/{address}")
}

/// Format graph summary path: /api/debug/graph/{chain_id}
pub fn graph_summary(chain_id: u64) -> String {
    format!("/api/debug/graph/{chain_id}")
}

/// Format graph token debug path: /api/debug/graph/{chain_id}/{token}
pub fn graph_token(chain_id: u64, token: &str) -> String {
    format!("/api/debug/graph/{chain_id}/{token}")
}

/// Format token pools debug path: /api/debug/pools/{chain_id}/{token}
pub fn token_pools(chain_id: u64, token: &str) -> String {
    format!("/api/debug/pools/{chain_id}/{token}")
}

/// Format V4 pool lookup path: /api/debug/v4pool/{chain_id}/{pool_id}
pub fn v4_pool(chain_id: u64, pool_id: &str) -> String {
    format!("/api/debug/v4pool/{chain_id}/{pool_id}")
}

/// Format diagnose pair path: /api/debug/diagnose/{chain_id}/{token_a}/{token_b}
pub fn diagnose_pair(chain_id: u64, token_a: &str, token_b: &str) -> String {
    format!("/api/debug/diagnose/{chain_id}/{token_a}/{token_b}")
}

/// Format sync audit path: /api/debug/sync_audit/{chain_id}
pub fn sync_audit(chain_id: u64) -> String {
    format!("/api/debug/sync_audit/{chain_id}")
}

/// Format pool audit path: /api/debug/pool_audit/{chain_id}
pub fn pool_audit(chain_id: u64) -> String {
    format!("/api/debug/pool_audit/{chain_id}")
}

/// Format sync health path: /api/debug/sync_health/{chain_id}
pub fn sync_health(chain_id: u64) -> String {
    format!("/api/debug/sync_health/{chain_id}")
}

/// Format verify quote path: /api/debug/verify_quote/{chain_id}
pub fn verify_quote(chain_id: u64) -> String {
    format!("/api/debug/verify_quote/{chain_id}")
}

/// Format exotic parity path: /api/debug/exotic_parity/{chain_id}
pub fn exotic_parity(chain_id: u64) -> String {
    format!("/api/debug/exotic_parity/{chain_id}")
}

/// Format quote debug path: /api/debug/quote_debug/{chain_id}/{token_in}/{token_out}/{amount_in}
pub fn quote_debug(chain_id: u64, token_in: &str, token_out: &str, amount_in: &str) -> String {
    format!("/api/debug/quote_debug/{chain_id}/{token_in}/{token_out}/{amount_in}")
}

/// Format backrun simulate path: /api/debug/backrun/{chain_id}/{pool}/{token_in}/{token_out}/{amount_in}
pub fn backrun_simulate(
    chain_id: u64,
    pool: &str,
    token_in: &str,
    token_out: &str,
    amount_in: &str,
) -> String {
    format!("/api/debug/backrun/{chain_id}/{pool}/{token_in}/{token_out}/{amount_in}")
}

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

    #[test]
    fn test_route_constants() {
        assert_eq!(QUOTE, "/quote");
        assert_eq!(QUOTE_LOOKUP, "/quote/:hash");
        assert_eq!(COMPARE_SIMULATE, "/compare/simulate");
        assert_eq!(HEALTH, "/health");
        assert_eq!(LEARN, "/learn");
        assert_eq!(CHAINS, "/api/chains");
        assert_eq!(TOKENS, "/api/tokens");
        assert_eq!(STATUS, "/api/status");
        assert_eq!(STATS_PAIRS, "/stats/pairs");
        assert_eq!(STATS_WARMING, "/stats/warming");
        assert_eq!(STATS_RPC, "/stats/rpc");
        assert_eq!(BENCHMARK_LATEST, "/benchmark/latest");
        assert_eq!(DISCOVER_SLOT, "/discover-slot");
        assert_eq!(LOG_LEVEL, "/admin/log-level");
        assert_eq!(ADMIN_KEYS, "/admin/keys");
        assert_eq!(ADMIN_KEYS_ISSUE, "/admin/keys/issue");
        assert_eq!(AUTH_CHALLENGE, "/auth/challenge");
        assert_eq!(AUTH_REGISTER, "/auth/register");
        assert_eq!(AUTH_KEY_INFO, "/auth/key-info");
        assert_eq!(AUTH_PRICING, "/auth/pricing");
        assert_eq!(AUTH_QUOTA_CLAIM, "/auth/quota/claim");
        assert_eq!(X402_VERIFY, "/x402/verify");
        assert_eq!(X402_SETTLE, "/x402/settle");
        assert_eq!(X402_DISCOVERY, "/.well-known/x402");
    }

    #[test]
    fn test_pool_path_formatting() {
        assert_eq!(pool(8453, "0x1234"), "/api/pool/8453/0x1234");
        assert_eq!(pool(1, "0xabcd"), "/api/pool/1/0xabcd");
        assert_eq!(pool(42161, "0xdeadbeef"), "/api/pool/42161/0xdeadbeef");
    }

    #[test]
    fn test_graph_summary_path_formatting() {
        assert_eq!(graph_summary(8453), "/api/debug/graph/8453");
        assert_eq!(graph_summary(1), "/api/debug/graph/1");
        assert_eq!(graph_summary(42161), "/api/debug/graph/42161");
    }

    #[test]
    fn test_graph_token_path_formatting() {
        assert_eq!(graph_token(8453, "0x1234"), "/api/debug/graph/8453/0x1234");
        assert_eq!(graph_token(1, "weth"), "/api/debug/graph/1/weth");
    }

    #[test]
    fn test_token_pools_path_formatting() {
        assert_eq!(token_pools(8453, "0x1234"), "/api/debug/pools/8453/0x1234");
        assert_eq!(token_pools(42161, "usdc"), "/api/debug/pools/42161/usdc");
    }

    #[test]
    fn test_v4_pool_path_formatting() {
        assert_eq!(v4_pool(8453, "0x1234"), "/api/debug/v4pool/8453/0x1234");
    }

    #[test]
    fn test_diagnose_pair_path_formatting() {
        assert_eq!(
            diagnose_pair(42161, "0x1234", "0x5678"),
            "/api/debug/diagnose/42161/0x1234/0x5678"
        );
    }

    #[test]
    fn test_sync_audit_path_formatting() {
        assert_eq!(sync_audit(42161), "/api/debug/sync_audit/42161");
    }

    #[test]
    fn test_pool_audit_path_formatting() {
        assert_eq!(pool_audit(42161), "/api/debug/pool_audit/42161");
    }

    #[test]
    fn test_verify_quote_path_formatting() {
        assert_eq!(verify_quote(42161), "/api/debug/verify_quote/42161");
    }

    #[test]
    fn test_exotic_parity_path_formatting() {
        assert_eq!(exotic_parity(42161), "/api/debug/exotic_parity/42161");
    }

    #[test]
    fn test_sync_health_path_formatting() {
        assert_eq!(sync_health(42161), "/api/debug/sync_health/42161");
    }

    #[test]
    fn test_quote_debug_path_formatting() {
        assert_eq!(
            quote_debug(42161, "0x1234", "0xdead", "100000"),
            "/api/debug/quote_debug/42161/0x1234/0xdead/100000"
        );
    }

    #[test]
    fn test_admin_key_action_path_formatting() {
        assert_eq!(
            admin_key_action("sr_test", "revoke"),
            "/admin/keys/sr_test/revoke"
        );
        assert_eq!(
            admin_key_action("sr_test", "activate"),
            "/admin/keys/sr_test/activate"
        );
    }
}