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