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; Swap and SetFeeProtocol differ, while the rest reuse
32    // 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    dex.set_fee_protocol_update_event("SetFeeProtocol(uint32,uint32,uint32,uint32)");
48    dex.set_fee_protocol_collect_event("CollectProtocol(address,address,uint128,uint128)");
49    let mut dex_extended = DexExtended::new(dex);
50
51    // HyperSync parsers
52    dex_extended.set_pool_created_event_hypersync_parsing(
53        uniswap_v3::pool_created::parse_pool_created_event_hypersync,
54    );
55    dex_extended.set_initialize_event_hypersync_parsing(
56        uniswap_v3::initialize::parse_initialize_event_hypersync,
57    );
58    dex_extended.set_swap_event_hypersync_parsing(pancakeswap_v3::swap::parse_swap_event_hypersync);
59    dex_extended.set_mint_event_hypersync_parsing(uniswap_v3::mint::parse_mint_event_hypersync);
60    dex_extended.set_burn_event_hypersync_parsing(uniswap_v3::burn::parse_burn_event_hypersync);
61    dex_extended
62        .set_collect_event_hypersync_parsing(uniswap_v3::collect::parse_collect_event_hypersync);
63    dex_extended.set_flash_event_hypersync_parsing(uniswap_v3::flash::parse_flash_event_hypersync);
64    dex_extended.set_fee_protocol_update_event_hypersync_parsing(
65        pancakeswap_v3::fee_protocol_update::parse_fee_protocol_update_event_hypersync,
66    );
67    dex_extended.set_fee_protocol_collect_event_hypersync_parsing(
68        uniswap_v3::fee_protocol_collect::parse_fee_protocol_collect_event_hypersync,
69    );
70
71    // RPC parsers
72    dex_extended
73        .set_pool_created_event_rpc_parsing(uniswap_v3::pool_created::parse_pool_created_event_rpc);
74    dex_extended
75        .set_initialize_event_rpc_parsing(uniswap_v3::initialize::parse_initialize_event_rpc);
76    dex_extended.set_swap_event_rpc_parsing(pancakeswap_v3::swap::parse_swap_event_rpc);
77    dex_extended.set_mint_event_rpc_parsing(uniswap_v3::mint::parse_mint_event_rpc);
78    dex_extended.set_burn_event_rpc_parsing(uniswap_v3::burn::parse_burn_event_rpc);
79    dex_extended.set_collect_event_rpc_parsing(uniswap_v3::collect::parse_collect_event_rpc);
80    dex_extended.set_flash_event_rpc_parsing(uniswap_v3::flash::parse_flash_event_rpc);
81    dex_extended.set_fee_protocol_update_event_rpc_parsing(
82        pancakeswap_v3::fee_protocol_update::parse_fee_protocol_update_event_rpc,
83    );
84    dex_extended.set_fee_protocol_collect_event_rpc_parsing(
85        uniswap_v3::fee_protocol_collect::parse_fee_protocol_collect_event_rpc,
86    );
87
88    dex_extended
89});