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