nautilus_blockchain/events/
pool_created.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 alloy::primitives::{Address, U160};
17use nautilus_model::defi::PoolIdentifier;
18
19/// Represents a liquidity pool creation event from a decentralized exchange.
20///
21// This struct models the data structure of a pool creation event emitted by DEX factory contracts.
22#[derive(Debug, Clone)]
23pub struct PoolCreatedEvent {
24    /// The block number when the pool was created.
25    pub block_number: u64,
26    /// The blockchain address of the first token in the pair.
27    pub token0: Address,
28    /// The blockchain address of the second token in the pair.
29    pub token1: Address,
30    /// The blockchain address of the created liquidity pool contract.
31    /// For V2/V3: the pool contract address
32    /// For V4: the PoolManager contract address
33    pub pool_address: Address,
34    /// The unique identifier for this pool.
35    pub pool_identifier: PoolIdentifier,
36    /// The fee tier of the pool, specified in basis points (e.g., 500 = 0.05%, 3000 = 0.3%).
37    pub fee: Option<u32>,
38    /// The tick spacing parameter that controls the granularity of price ranges.
39    pub tick_spacing: Option<u32>,
40    /// The square root of the price ratio encoded as a fixed point number with 96 fractional bits.
41    pub sqrt_price_x96: Option<U160>,
42    /// The current tick of the pool.
43    pub tick: Option<i32>,
44    /// The hooks contract address for Uniswap V4 pools.
45    pub hooks: Option<Address>,
46}
47
48impl PoolCreatedEvent {
49    /// Creates a new [`PoolCreatedEvent`] instance with the specified parameters.
50    #[must_use]
51    pub fn new(
52        block_number: u64,
53        token0: Address,
54        token1: Address,
55        pool_address: Address,
56        pool_identifier: PoolIdentifier,
57        fee: Option<u32>,
58        tick_spacing: Option<u32>,
59    ) -> Self {
60        Self {
61            block_number,
62            token0,
63            token1,
64            pool_address,
65            pool_identifier,
66            fee,
67            tick_spacing,
68            sqrt_price_x96: None,
69            tick: None,
70            hooks: None,
71        }
72    }
73
74    /// Sets the initialization parameters for the pool after it has been initialized.
75    pub fn set_initialize_params(&mut self, sqrt_price_x96: U160, tick: i32) {
76        self.sqrt_price_x96 = Some(sqrt_price_x96);
77        self.tick = Some(tick);
78    }
79
80    /// Sets the hooks contract address for this pool.
81    ///
82    /// This is typically called for Uniswap V4 pools that have hooks enabled.
83    pub fn set_hooks(&mut self, hooks: Address) {
84        self.hooks = Some(hooks);
85    }
86}