nym-network-defaults 1.22.2

Nym network defaults
Documentation
// Copyright 2021 - Nym Technologies SA <contact@nymtech.net>
// SPDX-License-Identifier: Apache-2.0

#[cfg(feature = "network")]
use crate::{
    ApiUrlConst, ChainDetails, DenomDetails, NymContracts, ValidatorDetails,
    network::v2::dns_fallbacks,
    v2::{NetworkingSpecifics, NymNetworkDetails},
};
#[cfg(feature = "network")]
use std::ops::Not;

pub const NETWORK_NAME: &str = "sandbox";

pub const BECH32_PREFIX: &str = "n";

#[cfg(feature = "network")]
pub const MIX_DENOM: DenomDetails = DenomDetails::new("unym", "nym", 6);
#[cfg(feature = "network")]
pub const STAKE_DENOM: DenomDetails = DenomDetails::new("unyx", "nyx", 6);

// -- Contract addresses --

pub const MIXNET_CONTRACT_ADDRESS: &str =
    "n1xr3rq8yvd7qplsw5yx90ftsr2zdhg4e9z60h5duusgxpv72hud3sjkxkav";
pub const VESTING_CONTRACT_ADDRESS: &str =
    "n1unyuj8qnmygvzuex3dwmg9yzt9alhvyeat0uu0jedg2wj33efl5qackslz";
pub const ECASH_CONTRACT_ADDRESS: &str =
    "n1v3vydvs2ued84yv3khqwtgldmgwn0elljsdh08dr5s2j9x4rc5fs9jlwz9";
pub const GROUP_CONTRACT_ADDRESS: &str =
    "n1ewmwz97xm0h8rdk8sw7h9mwn866qkx9hl9zlmagqfkhuzvwk5hhq844ue9";
pub const MULTISIG_CONTRACT_ADDRESS: &str =
    "n1tz0setr8vkh9udp8xyxgpqc89ns27k4d0jx2h942hr0ax63yjhmqz6xct8";
pub const COCONUT_DKG_CONTRACT_ADDRESS: &str =
    "n1v3n2ly2dp3a9ng3ff6rh26yfkn0pc5hed7w2shc5u9ca5c865utqj5elvh";
pub const NODE_FAMILIES_CONTRACT_ADDRESS: &str =
    "n13clyapdqk5umyynp20kqwf59rxlwlp24yf2ltzasflhsdhrxq7fsahyr6z";
pub const NETWORK_MONITORS_CONTRACT_ADDRESS: &str =
    "n1x5krtvyqklj360x38v62ze42g8s8trfsfqzlv8c9296chcpvqadssqnem5";

pub const PERFORMANCE_CONTRACT_ADDRESS: &str = "";
pub const GEOLOCATION_CONTRACT_ADDRESS: &str = "";
pub const DIRECTORY_CONTRACT_ADDRESS: &str = "";

pub const NYXD_URL: &str = "https://validator-sandbox-1.nymtech.net";
pub const NYXD_WS: &str = "wss://validator-sandbox-1.nymtech.net/websocket";

pub const NYXD_QUERY_LITE: &str = "https://validator-sandbox-1.nymtech.net";
pub const NYXD_WS_LITE: &str = "wss://validator-sandbox-1.nymtech.net/websocket";

pub const UPGRADE_MODE_ATTESTATION_URL: &str =
    "http://upgrade-mode.performance.nymte.ch/.wellknown/sandbox/attestation.json";
pub const UPGRADE_MODE_ATTESTER_ED25519_BS58_PUBKEY: &str =
    "EGwzKXPrqStv8cHF68VT2LbQuEBGDPzhCAixScvybfem";

pub const NYM_VPN_API: &str =
    "https://nym-vpn-api-git-deploy-sandbox-nyx-network-staging.vercel.app/api/";

#[cfg(feature = "network")]
pub const NYM_VPN_APIS: &[ApiUrlConst] = &[
    ApiUrlConst {
        url: NYM_VPN_API,
        front_hosts: Some(&["vercel.app", "vercel.com"]),
    },
    ApiUrlConst {
        url: "https://nym-frontdoor.vercel.app/sandbox/nym-vpn-api/",
        front_hosts: Some(&["vercel.app", "vercel.com"]),
    },
];

#[cfg(feature = "network")]
pub const NYM_APIS: &[ApiUrlConst] = &[
    ApiUrlConst {
        url: "https://sandbox-nym-api1.nymtech.net/api/",
        front_hosts: None,
    },
    ApiUrlConst {
        url: "https://nym-frontdoor.vercel.app/sandbox/nym-api/",
        front_hosts: Some(&["vercel.app", "vercel.com"]),
    },
];

pub const EXIT_POLICY_URL: &str =
    "https://nymtech.net/.wellknown/network-requester/exit-policy.txt";

#[cfg(feature = "network")]
pub fn validators() -> Vec<ValidatorDetails> {
    vec![ValidatorDetails::new(
        "https://validator-sandbox-1.nymtech.net",
        Some("https://sandbox-nym-api1.nymtech.net/api"),
        Some("wss://validator-sandbox-1.nymtech.net/websocket"),
    )]
}

#[cfg(feature = "network")]
pub fn network_details() -> NymNetworkDetails {
    NymNetworkDetails {
        network_name: NETWORK_NAME.into(),
        chain_details: ChainDetails {
            bech32_account_prefix: BECH32_PREFIX.to_string(),
            mix_denom: MIX_DENOM.into(),
            stake_denom: STAKE_DENOM.into(),
        },
        endpoints: validators(),
        contracts: NymContracts {
            mixnet_contract_address: parse_optional_str(MIXNET_CONTRACT_ADDRESS),
            vesting_contract_address: parse_optional_str(VESTING_CONTRACT_ADDRESS),
            performance_contract_address: parse_optional_str(PERFORMANCE_CONTRACT_ADDRESS),
            network_monitors_contract_address: parse_optional_str(
                NETWORK_MONITORS_CONTRACT_ADDRESS,
            ),
            node_families_contract_address: parse_optional_str(NODE_FAMILIES_CONTRACT_ADDRESS),
            directory_contract_address: parse_optional_str(DIRECTORY_CONTRACT_ADDRESS),
            geolocation_contract_address: parse_optional_str(GEOLOCATION_CONTRACT_ADDRESS),
            ecash_contract_address: parse_optional_str(ECASH_CONTRACT_ADDRESS),
            group_contract_address: parse_optional_str(GROUP_CONTRACT_ADDRESS),
            multisig_contract_address: parse_optional_str(MULTISIG_CONTRACT_ADDRESS),
            coconut_dkg_contract_address: parse_optional_str(COCONUT_DKG_CONTRACT_ADDRESS),
        },
        networking: NetworkingSpecifics {
            nym_api_urls: NYM_APIS.iter().copied().map(Into::into).collect(),
            nym_vpn_api_urls: NYM_VPN_APIS.iter().copied().map(Into::into).collect(),
            dns_fallbacks: dns_fallbacks(dns::default_static_addrs()),
        },
    }
}

#[cfg(feature = "network")]
fn parse_optional_str(raw: &str) -> Option<String> {
    raw.is_empty().not().then(|| raw.into())
}

/// Static domain/IP pins used as a DNS fallback when regular resolution of
/// Nym (and Nym-fronting) infrastructure is unavailable or untrustworthy.
#[allow(missing_docs)]
pub mod dns {
    use std::collections::HashMap;
    use std::net::{IpAddr, Ipv4Addr, Ipv6Addr};

    pub const NYM_API_DOMAIN: &str = "sandbox-nym-api1.nymtech.net";
    pub const NYM_API_IPS: &[IpAddr] = &[IpAddr::V4(Ipv4Addr::new(91, 92, 152, 159))];

    pub const NYM_VPN_API_DOMAIN: &str =
        "nym-vpn-api-git-deploy-sandbox-nyx-network-staging.vercel.app";
    pub const NYM_VPN_API_IPS: &[IpAddr] = &[
        IpAddr::V4(Ipv4Addr::new(64, 29, 17, 195)),
        IpAddr::V4(Ipv4Addr::new(216, 198, 79, 195)),
    ];

    pub const NYM_FRONTDOOR_VERCEL_DOMAIN: &str = "nym-frontdoor.vercel.app";
    pub const NYM_FRONTDOOR_VERCEL_IPS: &[IpAddr] = &[
        IpAddr::V4(Ipv4Addr::new(64, 29, 17, 195)),
        IpAddr::V4(Ipv4Addr::new(216, 198, 79, 195)),
    ];

    pub const VERCEL_APP_DOMAIN: &str = "vercel.app";
    pub const VERCEL_APP_IPS: &[IpAddr] = &[
        IpAddr::V4(Ipv4Addr::new(64, 29, 17, 195)),
        IpAddr::V4(Ipv4Addr::new(216, 198, 79, 195)),
    ];

    pub const VERCEL_COM_DOMAIN: &str = "vercel.com";
    pub const VERCEL_COM_IPS: &[IpAddr] = &[
        IpAddr::V4(Ipv4Addr::new(198, 169, 2, 129)),
        IpAddr::V4(Ipv4Addr::new(198, 169, 1, 193)),
    ];

    pub const NYM_COM_DOMAIN: &str = "nym.com";
    pub const NYM_COM_IPS: &[IpAddr] = &[IpAddr::V4(Ipv4Addr::new(76, 76, 21, 22))];

    pub const NYM_STATS_API_DOMAIN: &str = "nym-statistics-api.nymtech.cc";
    pub const NYM_STATS_API_IPS: &[IpAddr] = &[IpAddr::V4(Ipv4Addr::new(185, 19, 29, 32))];

    pub const NYM_RPC_DOMAIN: &str = "validator-sandbox-1.nymtech.net";
    pub const NYM_RPC_IPS: &[IpAddr] = &[
        IpAddr::V4(Ipv4Addr::new(92, 39, 62, 198)),
        IpAddr::V6(Ipv6Addr::new(
            0x2a04, 0xc43, 0xe00, 0x6f28, 0x418, 0x72ff, 0xfe00, 0x1ccc,
        )),
    ];

    #[allow(unused)]
    pub fn empty_static_addrs() -> HashMap<String, Vec<IpAddr>> {
        HashMap::new()
    }

    #[allow(unused)]
    pub fn default_static_addrs() -> HashMap<String, Vec<IpAddr>> {
        let mut m = HashMap::new();
        m.insert(NYM_API_DOMAIN.to_string(), NYM_API_IPS.to_vec());
        m.insert(NYM_VPN_API_DOMAIN.to_string(), NYM_VPN_API_IPS.to_vec());
        m.insert(
            NYM_FRONTDOOR_VERCEL_DOMAIN.to_string(),
            NYM_FRONTDOOR_VERCEL_IPS.to_vec(),
        );
        m.insert(VERCEL_APP_DOMAIN.to_string(), VERCEL_APP_IPS.to_vec());
        m.insert(VERCEL_COM_DOMAIN.to_string(), VERCEL_COM_IPS.to_vec());
        m.insert(NYM_COM_DOMAIN.to_string(), NYM_COM_IPS.to_vec());
        m.insert(NYM_STATS_API_DOMAIN.to_string(), NYM_STATS_API_IPS.to_vec());
        m.insert(NYM_RPC_DOMAIN.to_string(), NYM_RPC_IPS.to_vec());
        m
    }
}