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 INTENTSCAN_STREAM_ORIGIN: &str = "https://broadcast.intentscan.net";
pub const INTENTSCAN_DATA_ORIGIN: &str = "https://data.intentscan.net";
#[cfg(test)]
pub(crate) static TEST_INTENTSCAN_ORIGIN: std::sync::OnceLock<String> = std::sync::OnceLock::new();
pub fn intentscan_origins() -> (&'static str, &'static str) {
#[cfg(not(test))]
{ (INTENTSCAN_STREAM_ORIGIN, INTENTSCAN_DATA_ORIGIN) }
#[cfg(test)]
{ let origin = TEST_INTENTSCAN_ORIGIN.get().map_or("http://127.0.0.1:1", String::as_str); (origin, origin) }
}
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";
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";
pub const X402_VERIFY: &str = "/x402/verify";
pub const X402_SETTLE: &str = "/x402/settle";
pub const X402_DISCOVERY: &str = "/.well-known/x402";
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");
assert_eq!((INTENTSCAN_STREAM_ORIGIN, INTENTSCAN_DATA_ORIGIN), ("https://broadcast.intentscan.net", "https://data.intentscan.net"));
assert_eq!(intentscan_origins(), ("http://127.0.0.1:1", "http://127.0.0.1:1"));
}
#[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");
}
}