nautilus_blockchain/exchanges/arbitrum/
camelot_v3.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 alloy::primitives::Address;
19use hypersync_client::simple_types::Log;
20use nautilus_model::defi::{
21    chain::chains,
22    dex::{AmmType, Dex, DexType},
23};
24
25use crate::{
26    events::pool_created::PoolCreatedEvent,
27    exchanges::extended::DexExtended,
28    hypersync::helpers::{
29        extract_address_from_topic, extract_block_number, validate_event_signature_hash,
30    },
31};
32
33const POOL_CREATED_EVENT_SIGNATURE_HASH: &str =
34    "91ccaa7a278130b65168c3a0c8d3bcae84cf5e43704342bd3ec0b59e59c036db";
35
36/// Camelot V3 DEX on Arbitrum.
37pub static CAMELOT_V3: LazyLock<DexExtended> = LazyLock::new(|| {
38    let mut dex = DexExtended::new(Dex::new(
39        chains::ARBITRUM.clone(),
40        DexType::CamelotV3,
41        "0x1a3c9B1d2F0529D97f2afC5136Cc23e58f1FD35B",
42        102286676,
43        AmmType::CLAMM,
44        "Pool(address,address,address)",
45        "",
46        "",
47        "",
48        "",
49    ));
50    dex.set_pool_created_event_parsing(parse_camelot_v3_pool_created_event);
51    dex
52});
53
54fn parse_camelot_v3_pool_created_event(log: Log) -> anyhow::Result<PoolCreatedEvent> {
55    validate_event_signature_hash("Pool", POOL_CREATED_EVENT_SIGNATURE_HASH, &log)?;
56
57    let block_number = extract_block_number(&log)?;
58    let token = extract_address_from_topic(&log, 1, "token0")?;
59    let token1 = extract_address_from_topic(&log, 2, "token1")?;
60
61    if let Some(data) = log.data {
62        let data_bytes = data.as_ref();
63
64        // Extract pool address (only 32 bytes)
65        let pool_address = Address::from_slice(&data_bytes[12..32]);
66
67        Ok(PoolCreatedEvent::new(
68            block_number,
69            token,
70            token1,
71            pool_address,
72            None,
73            None,
74        ))
75    } else {
76        anyhow::bail!("Missing data in the pool created event log")
77    }
78}