Skip to main content

x402/
constants.rs

1//! Chain configuration and well-known constants for the Tempo blockchain.
2//!
3//! Contains the Tempo Moderato chain ID, default token address (pathUSD),
4//! RPC endpoint, and a runtime [`ChainConfig`] struct for multi-chain support.
5
6use alloy::primitives::Address;
7
8/// Tempo Moderato chain ID.
9pub const TEMPO_CHAIN_ID: u64 = 42431;
10
11/// CAIP-2 network identifier for Tempo Moderato.
12pub const TEMPO_NETWORK: &str = "eip155:42431";
13
14/// x402 scheme name for TIP-20 payments on Tempo.
15pub const SCHEME_NAME: &str = "tempo-tip20";
16
17/// pathUSD token address on Tempo Moderato testnet.
18pub const DEFAULT_TOKEN: Address = Address::new([
19    0x20, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
20    0x00, 0x00, 0x00, 0x00,
21]);
22
23/// pathUSD has 6 decimal places.
24pub const TOKEN_DECIMALS: u32 = 6;
25
26/// Default RPC endpoint for Tempo Moderato.
27pub const RPC_URL: &str = "https://rpc.moderato.tempo.xyz";
28
29/// Block explorer base URL.
30pub const EXPLORER_BASE: &str = "https://explore.moderato.tempo.xyz";
31
32/// Runtime chain configuration. Decouples scheme implementations from
33/// compile-time constants, enabling multi-chain support.
34#[derive(Debug, Clone, PartialEq, Eq)]
35pub struct ChainConfig {
36    pub chain_id: u64,
37    pub network: String,
38    pub scheme_name: String,
39    pub default_token: Address,
40    pub token_decimals: u32,
41    pub rpc_url: String,
42    pub explorer_base: String,
43    pub eip712_domain_name: String,
44    pub eip712_domain_version: String,
45}
46
47impl Default for ChainConfig {
48    /// Defaults to Tempo Moderato configuration.
49    fn default() -> Self {
50        Self {
51            chain_id: TEMPO_CHAIN_ID,
52            network: TEMPO_NETWORK.to_string(),
53            scheme_name: SCHEME_NAME.to_string(),
54            default_token: DEFAULT_TOKEN,
55            token_decimals: TOKEN_DECIMALS,
56            rpc_url: RPC_URL.to_string(),
57            explorer_base: EXPLORER_BASE.to_string(),
58            eip712_domain_name: "x402-tempo".to_string(),
59            eip712_domain_version: "1".to_string(),
60        }
61    }
62}