Skip to main content

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