nautilus_blockchain/exchanges/
mod.rs

1// -------------------------------------------------------------------------------------------------
2//  Copyright (C) 2015-2025 Nautech Systems Pty Ltd. All rights reserved.
3//  https://nautechsystems.io
4//
5//  Licensed under the GNU Lesser General Public License Version 3.0 (the "License");
6//  You may not use this file except in compliance with the License.
7//  You may obtain a copy of the License at https://www.gnu.org/licenses/lgpl-3.0.en.html
8//
9//  Unless required by applicable law or agreed to in writing, software
10//  distributed under the License is distributed on an "AS IS" BASIS,
11//  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12//  See the License for the specific language governing permissions and
13//  limitations under the License.
14// -------------------------------------------------------------------------------------------------
15
16use 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/// Returns a map of all DEX names to Dex instances across all chains
30#[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/// Returns the supported DEX names for a given blockchain.
44#[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
59/// Attempts to match a DEX name in a case-insensitive manner.
60pub 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    // First try exact match (for performance)
64    if let Some(dex_type) = DexType::from_dex_name(dex_name) {
65        return Some(dex_type);
66    }
67
68    // Try case-insensitive match
69    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}