Skip to main content

nautilus_blockchain/exchanges/ethereum/
pancakeswap_v3.rs

1// -------------------------------------------------------------------------------------------------
2//  Copyright (C) 2015-2026 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    chain::chains,
20    dex::{AmmType, Dex, DexType},
21};
22
23use crate::exchanges::{
24    extended::DexExtended,
25    parsing::{pancakeswap_v3, uniswap_v3},
26};
27
28/// PancakeSwap V3 DEX on Ethereum.
29pub static PANCAKESWAP_V3: LazyLock<DexExtended> = LazyLock::new(|| {
30    // PancakeSwap V3 is a Uniswap V3 fork; only Swap differs (appended protocolFees, distinct
31    // topic0), so Swap uses the PancakeSwap parser and the rest reuse the Uniswap V3 parsers.
32    let mut dex = Dex::new(
33        chains::ETHEREUM.clone(),
34        DexType::PancakeSwapV3,
35        "0x0BFbCF9fa4f9C56B0F40a671Ad40E0805A091865",
36        16950707,
37        AmmType::CLAMM,
38        "PoolCreated(address,address,uint24,int24,address)",
39        "Swap(address,address,int256,int256,uint160,uint128,int24,uint128,uint128)",
40        "Mint(address,address,int24,int24,uint128,uint256,uint256)",
41        "Burn(address,int24,int24,uint128,uint256,uint256)",
42        "Collect(address,address,int24,int24,uint128,uint128)",
43    );
44    dex.set_initialize_event("Initialize(uint160,int24)");
45    dex.set_flash_event("Flash(address,address,uint256,uint256,uint256,uint256)");
46    let mut dex_extended = DexExtended::new(dex);
47
48    // HyperSync parsers
49    dex_extended.set_pool_created_event_hypersync_parsing(
50        uniswap_v3::pool_created::parse_pool_created_event_hypersync,
51    );
52    dex_extended.set_initialize_event_hypersync_parsing(
53        uniswap_v3::initialize::parse_initialize_event_hypersync,
54    );
55    dex_extended.set_swap_event_hypersync_parsing(pancakeswap_v3::swap::parse_swap_event_hypersync);
56    dex_extended.set_mint_event_hypersync_parsing(uniswap_v3::mint::parse_mint_event_hypersync);
57    dex_extended.set_burn_event_hypersync_parsing(uniswap_v3::burn::parse_burn_event_hypersync);
58    dex_extended
59        .set_collect_event_hypersync_parsing(uniswap_v3::collect::parse_collect_event_hypersync);
60    dex_extended.set_flash_event_hypersync_parsing(uniswap_v3::flash::parse_flash_event_hypersync);
61
62    // RPC parsers
63    dex_extended
64        .set_pool_created_event_rpc_parsing(uniswap_v3::pool_created::parse_pool_created_event_rpc);
65    dex_extended
66        .set_initialize_event_rpc_parsing(uniswap_v3::initialize::parse_initialize_event_rpc);
67    dex_extended.set_swap_event_rpc_parsing(pancakeswap_v3::swap::parse_swap_event_rpc);
68    dex_extended.set_mint_event_rpc_parsing(uniswap_v3::mint::parse_mint_event_rpc);
69    dex_extended.set_burn_event_rpc_parsing(uniswap_v3::burn::parse_burn_event_rpc);
70    dex_extended.set_collect_event_rpc_parsing(uniswap_v3::collect::parse_collect_event_rpc);
71    dex_extended.set_flash_event_rpc_parsing(uniswap_v3::flash::parse_flash_event_rpc);
72
73    dex_extended
74});