nautilus_blockchain/exchanges/arbitrum/
fluid.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 std::sync::LazyLock;
17
18use hypersync_client::simple_types::Log;
19use nautilus_model::defi::{
20    chain::chains,
21    dex::{AmmType, Dex, DexType},
22};
23
24use crate::{
25    events::pool_created::PoolCreatedEvent,
26    exchanges::extended::DexExtended,
27    hypersync::helpers::{
28        extract_address_from_topic, extract_block_number, validate_event_signature_hash,
29    },
30};
31
32const POOL_CREATED_EVENT_SIGNATURE_HASH: &str =
33    "3fecd5f7aca6136a20a999e7d11ff5dcea4bd675cb125f93ccd7d53f98ec57e4";
34
35/// Fluid DEX on Arbitrum.
36pub static FLUID_DEX: LazyLock<DexExtended> = LazyLock::new(|| {
37    let mut dex = DexExtended::new(Dex::new(
38        chains::ARBITRUM.clone(),
39        DexType::FluidDEX,
40        "0x91716C4EDA1Fb55e84Bf8b4c7085f84285c19085",
41        269528370,
42        AmmType::CLAMM,
43        "DexT1Deployed(address,uint256,address,address)",
44        "",
45        "",
46        "",
47        "",
48    ));
49    dex.set_pool_created_event_parsing(parse_fluid_dex_pool_created_event);
50    dex
51});
52
53fn parse_fluid_dex_pool_created_event(log: Log) -> anyhow::Result<PoolCreatedEvent> {
54    validate_event_signature_hash("DexT1Deployed", POOL_CREATED_EVENT_SIGNATURE_HASH, &log)?;
55
56    let block_number = extract_block_number(&log)?;
57    let pool_address = extract_address_from_topic(&log, 1, "pool")?;
58    let supply_token_address = extract_address_from_topic(&log, 2, "supply_token")?;
59    let borrow_token_address = extract_address_from_topic(&log, 3, "borrow_token")?;
60
61    Ok(PoolCreatedEvent::new(
62        block_number,
63        supply_token_address,
64        borrow_token_address,
65        pool_address,
66        None,
67        None,
68    ))
69}