use super::constants::NATIVE_ADDRESS;
use ethers_core::types::{Address, U256};
use std::time::{Duration, SystemTime};
pub fn now() -> Duration {
SystemTime::now().duration_since(SystemTime::UNIX_EPOCH).unwrap()
}
pub fn get_deadline(deadline: Option<u64>) -> U256 {
deadline.map(|dl| U256::from(now().as_secs() + dl)).unwrap_or(U256::MAX)
}
pub fn is_native(address: &Address) -> bool {
*address == NATIVE_ADDRESS
}
pub fn is_native_path(path: &[Address]) -> (bool, bool) {
(
path.first().map(is_native).unwrap_or_default(),
path.last().map(is_native).unwrap_or_default(),
)
}
pub fn map_native(path: &mut [Address], weth: Address) {
for a in path.iter_mut() {
if is_native(a) {
*a = weth
}
}
}