renegade_sdk/
util.rs

1//! Utility functions for the renegade-sdk
2use std::time::{SystemTime, UNIX_EPOCH};
3
4use crate::{
5    ARBITRUM_ONE_CHAIN_ID,
6    ARBITRUM_SEPOLIA_CHAIN_ID,
7    BASE_MAINNET_CHAIN_ID,
8    BASE_SEPOLIA_CHAIN_ID,
9    // ETHEREUM_MAINNET_CHAIN_ID,
10    ETHEREUM_SEPOLIA_CHAIN_ID,
11};
12
13// -----------
14// | Helpers |
15// -----------
16
17/// Returns the current unix timestamp in milliseconds, represented as u64
18pub fn get_current_time_millis() -> u64 {
19    SystemTime::now().duration_since(UNIX_EPOCH).expect("negative timestamp").as_millis() as u64
20}
21
22/// Returns the environment-agnostic name of the chain with the given ID
23pub fn get_env_agnostic_chain(chain_id: u64) -> String {
24    match chain_id {
25        ARBITRUM_ONE_CHAIN_ID | ARBITRUM_SEPOLIA_CHAIN_ID => "arbitrum".to_string(),
26        BASE_MAINNET_CHAIN_ID | BASE_SEPOLIA_CHAIN_ID => "base".to_string(),
27        // ETHEREUM_MAINNET_CHAIN_ID |
28        ETHEREUM_SEPOLIA_CHAIN_ID => "ethereum".to_string(),
29        _ => panic!("Unsupported chain ID: {chain_id}"),
30    }
31}