road-runner-common 0.22.0

Shared Rust utilities for exchange ecosystem backend services.
Documentation
//! Defy (getdefy.co) vendor vocabulary shared across services.
//!
//! The single source of truth for translating a chain's native symbol to Defy's
//! `network` identifier, used by both the KYT (cex-tx-risk-manager) and Travel
//! Rule (cex-compliance) integrations. It is vendor vocabulary, not deployment
//! configuration, so a new chain is a code change here rather than an env map.

/// Translates a chain's native symbol (e.g. `ETH`, `TRX`) to Defy's `network`
/// id. `None` for an unknown symbol — callers skip rather than mis-address.
///
/// EVM L2s that share ETH as their native symbol (Arbitrum/Optimism) are not yet
/// distinguishable by symbol alone; add them (keyed additionally on chain id)
/// when they are onboarded.
pub fn defy_network(native_symbol: &str) -> Option<&'static str> {
    Some(match native_symbol.trim().to_ascii_uppercase().as_str() {
        "ETH" => "eth",
        "BNB" => "bsc",
        "MATIC" | "POL" => "polygon",
        "AVAX" => "avalanche",
        "TRX" => "trx",
        "SOL" => "solana",
        "XRP" => "xrp",
        "DOGE" => "doge",
        "SUI" => "sui",
        "BTC" => "bitcoin",
        "ADA" => "ada",
        "LTC" => "litecoin",
        "TON" => "ton",
        "DOT" => "dot",
        "APT" => "apt",
        "ATOM" => "atom",
        "XLM" => "stellar",
        "ALGO" => "algo",
        "VET" => "vet",
        "XTZ" => "xtz",
        "EOS" => "eos",
        _ => return None,
    })
}

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

    #[test]
    fn maps_known_symbols_case_insensitively() {
        assert_eq!(defy_network("eth"), Some("eth"));
        assert_eq!(defy_network(" TRX "), Some("trx"));
        assert_eq!(defy_network("BNB"), Some("bsc"));
        assert_eq!(defy_network("pol"), Some("polygon"));
    }

    #[test]
    fn unknown_symbol_is_none() {
        assert_eq!(defy_network("WAT"), None);
        assert_eq!(defy_network(""), None);
    }
}