agentswap 0.11.2

AgentSwap CLI for requesting quotes, inspecting tokens and pools, managing intents, and registering an API key against the AgentSwap service.
// Shared AgentSwap API route constants used by the standalone CLI.
// Exports: endpoint constants and path-formatting helpers.
// Deps: std formatting only.
pub const META_ORIGIN: &str = "https://meta-api.agentswap.co";
#[cfg(test)]
pub(crate) static TEST_META_ORIGIN: std::sync::OnceLock<String> = std::sync::OnceLock::new();

pub fn meta_origin() -> &'static str {
    #[cfg(not(test))]
    { META_ORIGIN }
    #[cfg(test)]
    { TEST_META_ORIGIN.get().expect("set a loopback meta origin before calling the entrypoint") }
}

pub const APP_ORIGIN: &str = "https://app.agentswap.co";
#[cfg(test)]
pub(crate) static TEST_APP_ORIGIN: std::sync::OnceLock<String> = std::sync::OnceLock::new();

pub fn app_origin() -> &'static str {
    #[cfg(not(test))]
    { APP_ORIGIN }
    #[cfg(test)]
    { TEST_APP_ORIGIN.get().expect("set a loopback app origin before calling the entrypoint") }
}

pub const QUOTE: &str = "/quote";
pub const QUOTE_LOOKUP: &str = "/quote/:hash";
pub const HEALTH: &str = "/health";
pub const CHAINS: &str = "/api/chains";
pub const TOKENS: &str = "/api/tokens";
pub const STATUS: &str = "/api/status";
pub const INTENT_ANNOUNCE: &str = "/api/intents";

// 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 pool inspection path: /api/pool/{chain_id}/{address}
pub fn pool(chain_id: u64, address: &str) -> String {
    format!("/api/pool/{chain_id}/{address}")
}

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

    #[test]
    #[should_panic(expected = "set a loopback app origin")]
    fn app_origin_requires_a_test_fixture() {
        app_origin();
    }

    #[test]
    fn test_route_constants() {
        assert_eq!(QUOTE, "/quote");
        assert_eq!(QUOTE_LOOKUP, "/quote/:hash");
        assert_eq!(HEALTH, "/health");
        assert_eq!(CHAINS, "/api/chains");
        assert_eq!(TOKENS, "/api/tokens");
        assert_eq!(STATUS, "/api/status");
        assert_eq!(INTENT_ANNOUNCE, "/api/intents");
        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");
    }
}