nautilus_blockchain/exchanges/
mod.rs1use nautilus_model::defi::{Blockchain, Chain, DexType};
17
18use crate::exchanges::{
19 arbitrum::ARBITRUM_DEX_EXTENDED_MAP, base::BASE_DEX_EXTENDED_MAP,
20 ethereum::ETHEREUM_DEX_EXTENDED_MAP, extended::DexExtended,
21};
22
23pub mod arbitrum;
24pub mod base;
25pub mod ethereum;
26pub mod extended;
27mod parsing;
28
29#[must_use]
31pub fn get_dex_extended(
32 blockchain: Blockchain,
33 dex_type: &DexType,
34) -> Option<&'static DexExtended> {
35 match blockchain {
36 Blockchain::Ethereum => ETHEREUM_DEX_EXTENDED_MAP.get(dex_type).copied(),
37 Blockchain::Base => BASE_DEX_EXTENDED_MAP.get(dex_type).copied(),
38 Blockchain::Arbitrum => ARBITRUM_DEX_EXTENDED_MAP.get(dex_type).copied(),
39 _ => None,
40 }
41}
42
43#[must_use]
45pub fn get_supported_dexes_for_chain(blockchain: Blockchain) -> Vec<String> {
46 let dex_types: Vec<DexType> = match blockchain {
47 Blockchain::Ethereum => ETHEREUM_DEX_EXTENDED_MAP.keys().copied().collect(),
48 Blockchain::Base => BASE_DEX_EXTENDED_MAP.keys().copied().collect(),
49 Blockchain::Arbitrum => ARBITRUM_DEX_EXTENDED_MAP.keys().copied().collect(),
50 _ => vec![],
51 };
52
53 dex_types
54 .into_iter()
55 .map(|dex_type| format!("{dex_type}"))
56 .collect()
57}
58
59pub fn find_dex_type_case_insensitive(dex_name: &str, chain: &Chain) -> Option<DexType> {
61 let supported_dexes = get_supported_dexes_for_chain(chain.name);
62
63 if let Some(dex_type) = DexType::from_dex_name(dex_name) {
65 return Some(dex_type);
66 }
67
68 for supported_dex in supported_dexes {
70 if supported_dex.to_lowercase() == dex_name.to_lowercase() {
71 return DexType::from_dex_name(&supported_dex);
72 }
73 }
74
75 None
76}